Skip to content

Commit 43f5280

Browse files
authored
Merge pull request #21061 from theresa-m/securitymanager_5
JDK 24 remove java.security.AccessController.doPrivileged part 2
2 parents 56b489c + a1a3712 commit 43f5280

File tree

20 files changed

+243
-20
lines changed

20 files changed

+243
-20
lines changed

jcl/src/java.base/share/classes/java/lang/Class.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5655,11 +5655,11 @@ public boolean isNestmateOf(Class<?> that) {
56555655
/**
56565656
* Answers the nest member classes of the receiver's nest host.
56575657
*
5658-
* @throws SecurityException if a SecurityManager is present and package access is not allowed
56595658
/*[IF JAVA_SPEC_VERSION < 15]
56605659
* @throws LinkageError if there is any problem loading or validating a nest member or the nest host
56615660
/*[ENDIF]
56625661
/*[IF JAVA_SPEC_VERSION < 24]
5662+
* @throws SecurityException if a SecurityManager is present and package access is not allowed
56635663
* @throws SecurityException if a returned class is not the current class, a security manager is enabled,
56645664
* the caller's class loader is not the same or an ancestor of that returned class, and the
56655665
* checkPackageAccess() denies access
@@ -5924,7 +5924,9 @@ Object getClassData() {
59245924
*
59255925
* @return array of Class objects if permitted subclasses exist or null if not a sealed class.
59265926
*
5927+
/*[IF JAVA_SPEC_VERSION < 24]
59275928
* @throws SecurityException if access to any of the classes returned in the array is denied
5929+
/*[ENDIF] JAVA_SPEC_VERSION < 24
59285930
*
59295931
* @since 16
59305932
*/

jcl/src/java.base/share/classes/java/lang/System.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,11 @@ private static void initializeSystemProperties(Map<String, String> mapProperties
900900
*
901901
* @param code the return code.
902902
*
903+
/*[IF JAVA_SPEC_VERSION < 24]
903904
* @throws SecurityException if the running thread is not allowed to cause the vm to exit.
904905
*
905906
* @see SecurityManager#checkExit
907+
/*[ENDIF] JAVA_SPEC_VERSION < 24
906908
*/
907909
public static void exit(int code) {
908910
RUNTIME.exit(code);

jcl/src/java.management/share/classes/com/ibm/java/lang/management/internal/ThreadMXBeanImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,9 @@ public MethodHandle run() {
872872
* Wrap a ThreadInfoBase object in a ThreadInfo object.
873873
* @param base container for the ThreadInfo data
874874
* @return ThreadInfo object, or null if base is null
875+
/*[IF JAVA_SPEC_VERSION < 24]
875876
* @note this must be wrapped in a doPrivileged().
877+
/*[ENDIF] JAVA_SPEC_VERSION < 24
876878
*/
877879
private static ThreadInfo makeThreadInfo(ThreadInfoBase base) {
878880
ThreadInfo newThreadInfo = null;

jcl/src/openj9.cuda/share/classes/com/ibm/cuda/Cuda.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
import java.lang.reflect.Method;
2929
import java.nio.ByteBuffer;
3030
import java.nio.ByteOrder;
31+
/*[IF JAVA_SPEC_VERSION < 24]*/
3132
import java.security.AccessController;
3233
import java.security.PrivilegedAction;
34+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
3335
import java.util.Map;
3436
import java.util.concurrent.ConcurrentHashMap;
3537

3638
/**
3739
* The {@code Cuda} class provides general CUDA utilities.
3840
*/
3941
/*[IF JAVA_SPEC_VERSION >= 24]*/
40-
@SuppressWarnings({"removal", "restricted"})
42+
@SuppressWarnings("restricted")
4143
/*[ELSEIF JAVA_SPEC_VERSION >= 17]*/
4244
@SuppressWarnings("removal")
4345
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
@@ -56,11 +58,17 @@ private static final class Cleaner implements Runnable {
5658
static {
5759
instance = new Cleaner();
5860

61+
Thread daemon;
62+
/*[IF JAVA_SPEC_VERSION >= 24]*/
63+
daemon = VM.getVMLangAccess().createThread(instance,
64+
"CUDA pinned buffer cleaner", true, false, true, null); //$NON-NLS-1$
65+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
5966
PrivilegedAction<Thread> createThread = () -> VM.getVMLangAccess().createThread(instance,
6067
"CUDA pinned buffer cleaner", true, false, true, null); //$NON-NLS-1$
6168

6269
// we assert privilege to create the Thread
63-
Thread daemon = AccessController.doPrivileged(createThread);
70+
daemon = AccessController.doPrivileged(createThread);
71+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
6472

6573
daemon.start();
6674
}
@@ -102,10 +110,14 @@ public void run() {
102110
}
103111

104112
static {
113+
/*[IF JAVA_SPEC_VERSION >= 24]*/
114+
System.loadLibrary("cuda4j29"); //$NON-NLS-1$
115+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
105116
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
106117
System.loadLibrary("cuda4j29"); //$NON-NLS-1$
107118
return null;
108119
});
120+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
109121

110122
Method runMethod;
111123

jcl/src/openj9.cuda/share/classes/com/ibm/cuda/CudaDevice.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,21 @@ public boolean canAccessPeer(CudaDevice peerDevice) throws CudaException {
520520
* the peer device
521521
* @throws CudaException
522522
* if a CUDA exception occurs
523+
/*[IF JAVA_SPEC_VERSION < 24]
523524
* @throws SecurityException
524525
* if a security manager exists and the calling thread
525526
* does not have permission to disable peer access
527+
/*[ENDIF] JAVA_SPEC_VERSION < 24
526528
*/
527529
public void disablePeerAccess(CudaDevice peerDevice) throws CudaException {
530+
/*[IF JAVA_SPEC_VERSION < 24]*/
528531
@SuppressWarnings("removal")
529532
SecurityManager security = System.getSecurityManager();
530533

531534
if (security != null) {
532535
security.checkPermission(CudaPermission.DisablePeerAccess);
533536
}
537+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
534538

535539
disablePeerAccess(deviceId, peerDevice.deviceId);
536540
}
@@ -542,17 +546,21 @@ public void disablePeerAccess(CudaDevice peerDevice) throws CudaException {
542546
* the peer device
543547
* @throws CudaException
544548
* if a CUDA exception occurs
549+
/*[IF JAVA_SPEC_VERSION < 24]
545550
* @throws SecurityException
546551
* if a security manager exists and the calling thread
547552
* does not have permission to enable peer access
553+
/*[ENDIF] JAVA_SPEC_VERSION < 24
548554
*/
549555
public void enablePeerAccess(CudaDevice peerDevice) throws CudaException {
556+
/*[IF JAVA_SPEC_VERSION < 24]*/
550557
@SuppressWarnings("removal")
551558
SecurityManager security = System.getSecurityManager();
552559

553560
if (security != null) {
554561
security.checkPermission(CudaPermission.EnablePeerAccess);
555562
}
563+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
556564

557565
enablePeerAccess(deviceId, peerDevice.deviceId);
558566
}
@@ -733,17 +741,21 @@ public int hashCode() {
733741
* the desired cache configuration
734742
* @throws CudaException
735743
* if a CUDA exception occurs
744+
/*[IF JAVA_SPEC_VERSION < 24]
736745
* @throws SecurityException
737746
* if a security manager exists and the calling thread
738747
* does not have permission to set device cache configurations
748+
/*[ENDIF] JAVA_SPEC_VERSION < 24
739749
*/
740750
public void setCacheConfig(CacheConfig config) throws CudaException {
751+
/*[IF JAVA_SPEC_VERSION < 24]*/
741752
@SuppressWarnings("removal")
742753
SecurityManager security = System.getSecurityManager();
743754

744755
if (security != null) {
745756
security.checkPermission(CudaPermission.SetCacheConfig);
746757
}
758+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
747759

748760
setCacheConfig(deviceId, config.nativeValue);
749761
}
@@ -757,17 +769,21 @@ public void setCacheConfig(CacheConfig config) throws CudaException {
757769
* the desired limit value
758770
* @throws CudaException
759771
* if a CUDA exception occurs
772+
/*[IF JAVA_SPEC_VERSION < 24]
760773
* @throws SecurityException
761774
* if a security manager exists and the calling thread
762775
* does not have permission to set device limits
776+
/*[ENDIF] JAVA_SPEC_VERSION < 24
763777
*/
764778
public void setLimit(Limit limit, long value) throws CudaException {
779+
/*[IF JAVA_SPEC_VERSION < 24]*/
765780
@SuppressWarnings("removal")
766781
SecurityManager security = System.getSecurityManager();
767782

768783
if (security != null) {
769784
security.checkPermission(CudaPermission.SetLimit);
770785
}
786+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
771787

772788
setLimit(deviceId, limit.nativeValue, value);
773789
}
@@ -779,17 +795,21 @@ public void setLimit(Limit limit, long value) throws CudaException {
779795
* the desired shared memory configuration
780796
* @throws CudaException
781797
* if a CUDA exception occurs
798+
/*[IF JAVA_SPEC_VERSION < 24]
782799
* @throws SecurityException
783800
* if a security manager exists and the calling thread does
784801
* not have permission to set device shared memory configurations
802+
/*[ENDIF] JAVA_SPEC_VERSION < 24
785803
*/
786804
public void setSharedMemConfig(SharedMemConfig config) throws CudaException {
805+
/*[IF JAVA_SPEC_VERSION < 24]*/
787806
@SuppressWarnings("removal")
788807
SecurityManager security = System.getSecurityManager();
789808

790809
if (security != null) {
791810
security.checkPermission(CudaPermission.SetSharedMemConfig);
792811
}
812+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
793813

794814
setSharedMemConfig(deviceId, config.nativeValue);
795815
}

jcl/src/openj9.cuda/share/classes/com/ibm/cuda/CudaModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ private static native void unload(int deviceId, long moduleHandle)
141141
* the module image
142142
* @throws CudaException
143143
* if a CUDA exception occurs
144+
/*[IF JAVA_SPEC_VERSION < 24]
144145
* @throws SecurityException
145146
* if a security manager exists and the calling thread
146147
* does not have permission to load GPU modules
148+
/*[ENDIF] JAVA_SPEC_VERSION < 24
147149
*/
148150
public CudaModule(CudaDevice device, byte[] image) throws CudaException {
149151
this(device, image, null);
@@ -161,20 +163,24 @@ public CudaModule(CudaDevice device, byte[] image) throws CudaException {
161163
* the desired options
162164
* @throws CudaException
163165
* if a CUDA exception occurs
166+
/*[IF JAVA_SPEC_VERSION < 24]
164167
* @throws SecurityException
165168
* if a security manager exists and the calling thread
166169
* does not have permission to load GPU modules
170+
/*[ENDIF] JAVA_SPEC_VERSION < 24
167171
*/
168172
public CudaModule(CudaDevice device, byte[] image, CudaJitOptions options)
169173
throws CudaException {
170174
super();
171175

176+
/*[IF JAVA_SPEC_VERSION < 24]*/
172177
@SuppressWarnings("removal")
173178
SecurityManager security = System.getSecurityManager();
174179

175180
if (security != null) {
176181
security.checkPermission(CudaPermission.LoadModule);
177182
}
183+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
178184

179185
if (image == null) {
180186
throw new NullPointerException();
@@ -210,9 +216,11 @@ public CudaModule(CudaDevice device, byte[] image, CudaJitOptions options)
210216
* if a CUDA exception occurs
211217
* @throws IOException
212218
* if an I/O error occurs reading {@code input}
219+
/*[IF JAVA_SPEC_VERSION < 24]
213220
* @throws SecurityException
214221
* if a security manager exists and the calling thread
215222
* does not have permission to load GPU modules
223+
/*[ENDIF] JAVA_SPEC_VERSION < 24
216224
*/
217225
public CudaModule(CudaDevice device, InputStream input)
218226
throws CudaException, IOException {
@@ -233,9 +241,11 @@ public CudaModule(CudaDevice device, InputStream input)
233241
* if a CUDA exception occurs
234242
* @throws IOException
235243
* if an I/O error occurs reading {@code input}
244+
/*[IF JAVA_SPEC_VERSION < 24]
236245
* @throws SecurityException
237246
* if a security manager exists and the calling thread
238247
* does not have permission to load GPU modules
248+
/*[ENDIF] JAVA_SPEC_VERSION < 24
239249
*/
240250
public CudaModule(CudaDevice device, InputStream input,
241251
CudaJitOptions options) throws CudaException, IOException {

jcl/src/openj9.cuda/share/classes/com/ibm/cuda/CudaPermission.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*[INCLUDE-IF Sidecar18-SE]*/
1+
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
22
/*
33
* Copyright IBM Corp. and others 2014
44
*
@@ -68,7 +68,14 @@
6868
* See {@link CudaDevice#setLimit(Limit, long)}.</td>
6969
* </tr>
7070
* </table>
71+
*
72+
/*[IF JAVA_SPEC_VERSION >= 24]
73+
* @deprecated Checking permissions is not supported.
74+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
7175
*/
76+
/*[IF JAVA_SPEC_VERSION >= 24]*/
77+
@Deprecated(since = "24", forRemoval = true)
78+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
7279
public final class CudaPermission extends BasicPermission {
7380

7481
private static final long serialVersionUID = 5769765985242116236L;

jcl/src/openj9.gpu/share/classes/com/ibm/gpu/CUDAManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
/*[IF JAVA_SPEC_VERSION < 24]*/
2728
import java.security.AccessController;
2829
import java.security.PrivilegedAction;
30+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
2931
import java.util.ArrayList;
3032
import java.util.Arrays;
3133
import java.util.BitSet;
@@ -60,9 +62,13 @@ private static final class Configuration {
6062
private static final int DEFAULT_THRESHOLD = 30000;
6163

6264
private static void loadProperties(Properties properties, String resourceName) throws IOException {
65+
/*[IF JAVA_SPEC_VERSION >= 24]*/
66+
try (InputStream input = CUDAManager.class.getResourceAsStream(resourceName)) {
67+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
6368
PrivilegedAction<InputStream> action = () -> CUDAManager.class.getResourceAsStream(resourceName);
6469

6570
try (InputStream input = AccessController.doPrivileged(action)) {
71+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
6672
if (input != null) {
6773
properties.load(input);
6874
}
@@ -311,9 +317,13 @@ public static String getOutputHeader() {
311317
}
312318

313319
static String getProperty(String name) {
320+
/*[IF JAVA_SPEC_VERSION >= 24]*/
321+
return System.getProperty(name);
322+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
314323
PrivilegedAction<String> action = () -> System.getProperty(name);
315324

316325
return AccessController.doPrivileged(action);
326+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
317327
}
318328

319329
/**

jcl/src/openj9.gpu/share/classes/com/ibm/gpu/GPUPermission.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*[INCLUDE-IF Sidecar17]*/
1+
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
22
/*
33
* Copyright IBM Corp. and others 2016
44
*
@@ -40,7 +40,14 @@
4040
* See {@link CUDAManager#instance()}.</td>
4141
* </tr>
4242
* </table>
43+
*
44+
/*[IF JAVA_SPEC_VERSION >= 24]
45+
* @deprecated Checking permissions is not supported.
46+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
4347
*/
48+
/*[IF JAVA_SPEC_VERSION >= 24]*/
49+
@Deprecated(since = "24", forRemoval = true)
50+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
4451
public final class GPUPermission extends BasicPermission {
4552

4653
static final Permission Access = new GPUPermission("access"); //$NON-NLS-1$

0 commit comments

Comments
 (0)