Skip to content

Commit ef5af02

Browse files
committed
Remove System.getSecurityManager calls from java.base and CRIU
Signed-off-by: Theresa Mammarella <[email protected]>
1 parent 63f23a3 commit ef5af02

File tree

7 files changed

+63
-8
lines changed

7 files changed

+63
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
import sun.reflect.annotation.AnnotationType;
6565
import java.util.Arrays;
6666
import com.ibm.oti.vm.VM;
67-
/*[IF JAVA_SPEC_VERSION >= 11]*/
67+
/*[IF (11 <= JAVA_SPEC_VERSION) & (JAVA_SPEC_VERSION < 24)]*/
6868
import static com.ibm.oti.util.Util.doesClassLoaderDescendFrom;
69-
/*[ENDIF] JAVA_SPEC_VERSION >= 11*/
69+
/*[ENDIF] (11 <= JAVA_SPEC_VERSION) & (JAVA_SPEC_VERSION < 24) */
7070

7171
/*[IF JAVA_SPEC_VERSION >= 9]
7272
import jdk.internal.misc.Unsafe;
@@ -5547,9 +5547,11 @@ static byte[] getExecutableTypeAnnotationBytes(Executable exec) {
55475547
/**
55485548
* Answers the host class of the receiver's nest.
55495549
*
5550+
/*[IF JAVA_SPEC_VERSION < 24]
55505551
* @throws SecurityException if nestHost is not same as the current class, a security manager
55515552
* is present, the classloader of the caller is not the same or an ancestor of nestHost
55525553
* class, and checkPackageAccess() denies access
5554+
/*[ENDIF] JAVA_SPEC_VERSION < 24
55535555
* @return the host class of the receiver.
55545556
*/
55555557
@CallerSensitive
@@ -5561,6 +5563,7 @@ public Class<?> getNestHost()
55615563
if (nestHost == null) {
55625564
nestHost = getNestHostImpl();
55635565
}
5566+
/*[IF JAVA_SPEC_VERSION < 24]*/
55645567
/* The specification requires that if:
55655568
* - the returned class is not the current class
55665569
* - a security manager is present
@@ -5582,6 +5585,7 @@ public Class<?> getNestHost()
55825585
}
55835586
}
55845587
}
5588+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
55855589
return nestHost;
55865590
}
55875591

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,21 @@ static final void initializeClassLoaders() {
324324
* Constructs a new instance of this class with the system
325325
* class loader as its parent.
326326
*
327+
/*[IF JAVA_SPEC_VERSION < 24]
327328
* @exception SecurityException
328329
* if a security manager exists and it does not
329330
* allow the creation of new ClassLoaders.
331+
/*[ENDIF] JAVA_SPEC_VERSION < 24
330332
*/
331333
protected ClassLoader() {
334+
/*[IF JAVA_SPEC_VERSION >= 24]*/
335+
this(null, null, applicationClassLoader);
336+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
332337
this(checkSecurityPermission(), null, applicationClassLoader);
338+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
333339
}
334340

341+
/*[IF JAVA_SPEC_VERSION < 24]*/
335342
/**
336343
* This is a static helper method to perform security check earlier such that current ClassLoader object
337344
* can't be resurrected when there is a SecurityException thrown.
@@ -346,6 +353,7 @@ private static Void checkSecurityPermission() {
346353
}
347354
return null;
348355
}
356+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
349357

350358
/**
351359
* Constructs a new instance of this class with the given
@@ -354,12 +362,18 @@ private static Void checkSecurityPermission() {
354362
* @param parentLoader ClassLoader
355363
* the ClassLoader to use as the new class
356364
* loaders parent.
365+
/*[IF JAVA_SPEC_VERSION < 24]
357366
* @exception SecurityException
358367
* if a security manager exists and it does not
359368
* allow the creation of new ClassLoaders.
369+
/*[ENDIF] JAVA_SPEC_VERSION < 24
360370
*/
361371
protected ClassLoader(ClassLoader parentLoader) {
372+
/*[IF JAVA_SPEC_VERSION >= 24]*/
373+
this(null, null, parentLoader);
374+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
362375
this(checkSecurityPermission(), null, parentLoader);
376+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
363377
}
364378

365379
/*[IF JAVA_SPEC_VERSION >= 9]*/
@@ -374,13 +388,19 @@ protected ClassLoader(ClassLoader parentLoader) {
374388
* loaders parent.
375389
* @exception IllegalArgumentException
376390
* if the name of this class loader is empty.
391+
/*[IF JAVA_SPEC_VERSION < 24]
377392
* @exception SecurityException
378393
* if a security manager exists and it does not
379394
* allow the creation of new ClassLoaders.
395+
/*[ENDIF] JAVA_SPEC_VERSION < 24
380396
*@since 9
381397
*/
382398
protected ClassLoader(String classLoaderName, ClassLoader parentLoader) {
399+
/*[IF JAVA_SPEC_VERSION >= 24]*/
400+
this(null, classLoaderName, parentLoader);
401+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
383402
this(checkSecurityPermission(), classLoaderName, parentLoader);
403+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
384404
}
385405
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */
386406

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
/*[ENDIF] JAVA_SPEC_VERSION >= 10 */
2828
import java.lang.module.ModuleDescriptor;
2929
import java.lang.module.ModuleDescriptor.Version;
30+
/*[IF JAVA_SPEC_VERSION < 24]*/
3031
import java.security.Permission;
32+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
3133
import java.util.Collections;
3234
import java.util.List;
3335
import java.util.Objects;
@@ -125,11 +127,13 @@ private StackWalker(
125127
}
126128

127129
if ((flags & J9_RETAIN_CLASS_REFERENCE) != 0) {
130+
/*[IF JAVA_SPEC_VERSION < 24]*/
128131
@SuppressWarnings("removal")
129132
SecurityManager securityMgr = System.getSecurityManager();
130133
if (null != securityMgr) {
131134
securityMgr.checkPermission(PermissionSingleton.perm);
132135
}
136+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
133137
/*[IF JAVA_SPEC_VERSION >= 19]*/
134138
this.retainClassRef = true;
135139
} else {
@@ -166,9 +170,11 @@ public static StackWalker getInstance() {
166170
* @param option
167171
* select the type of information to include
168172
* @return StackWalker instance configured with the value of option
173+
/*[IF JAVA_SPEC_VERSION < 24]
169174
* @throws SecurityException
170175
* if option is RETAIN_CLASS_REFERENCE and the security manager
171176
* check fails
177+
/*[ENDIF] JAVA_SPEC_VERSION < 24
172178
*/
173179
public static StackWalker getInstance(Option option) {
174180
Objects.requireNonNull(option);
@@ -181,9 +187,11 @@ public static StackWalker getInstance(Option option) {
181187
* @param options
182188
* select the types of information to include
183189
* @return StackWalker instance configured with the given options
190+
/*[IF JAVA_SPEC_VERSION < 24]
184191
* @throws SecurityException
185192
* if RETAIN_CLASS_REFERENCE is requested and not permitted by
186193
* the security manager
194+
/*[ENDIF] JAVA_SPEC_VERSION < 24
187195
*/
188196
public static StackWalker getInstance(Set<Option> options) {
189197
return getInstance(options, DEFAULT_BUFFER_SIZE);
@@ -198,9 +206,11 @@ public static StackWalker getInstance(Set<Option> options) {
198206
* hint for the size of buffer to use. Must be 1 or greater
199207
* @return StackWalker instance with the given options specifying the stack
200208
* frame information it can access
209+
/*[IF JAVA_SPEC_VERSION < 24]
201210
* @throws SecurityException
202211
* if RETAIN_CLASS_REFERENCE is requested and not permitted by
203212
* the security manager
213+
/*[ENDIF] JAVA_SPEC_VERSION < 24
204214
*/
205215
public static StackWalker getInstance(Set<Option> options, int estimatedDepth) {
206216
Objects.requireNonNull(options);
@@ -585,8 +595,10 @@ Object[] getMonitors() {
585595
/*[ENDIF] JAVA_SPEC_VERSION >= 21 */
586596
}
587597

598+
/*[IF JAVA_SPEC_VERSION < 24]*/
588599
static final class PermissionSingleton {
589600
static final Permission perm =
590601
new RuntimePermission("getStackWalkerWithClassReference"); //$NON-NLS-1$
591602
}
603+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
592604
}

jcl/src/java.base/share/classes/openj9/internal/criu/CRIUDumpPermission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*[INCLUDE-IF CRIU_SUPPORT]*/
1+
/*[INCLUDE-IF CRIU_SUPPORT & (JAVA_SPEC_VERSION < 24)]*/
22
/*
33
* Copyright IBM Corp. and others 2023
44
*

jcl/src/java.base/share/classes/openj9/internal/criu/InternalCRIUSupport.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
* This API enables the use of CRIU capabilities provided by the OS as well as JVM support for facilitating a successful checkpoint
6565
* and restore in varying environments.
6666
*/
67+
/*[IF 17 <= JAVA_SPEC_VERSION]*/
68+
@SuppressWarnings({ "deprecation", "removal" })
69+
/*[ENDIF] 17 <= JAVA_SPEC_VERSION */
6770
public final class InternalCRIUSupport {
6871
private static final boolean criuSupportEnabled = isCRIUSupportEnabledImpl();
6972
private static long checkpointRestoreNanoTimeDelta;
@@ -210,7 +213,9 @@ public static void runRunnableInNotCheckpointSafeMode(Runnable run) {
210213

211214
@SuppressWarnings("restriction")
212215
private static Unsafe unsafe;
216+
/*[IF JAVA_SPEC_VERSION < 24]*/
213217
private static final CRIUDumpPermission CRIU_DUMP_PERMISSION = new CRIUDumpPermission();
218+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
214219
private static boolean nativeLoaded;
215220
private static boolean initComplete;
216221
private static String errorMsg;
@@ -307,16 +312,19 @@ private static void init() {
307312
* @param imageDir the directory that will hold the dump files as a
308313
* java.nio.file.Path
309314
* @throws NullPointerException if imageDir is null
315+
/*[IF JAVA_SPEC_VERSION < 24]
310316
* @throws SecurityException if no permission to access imageDir or no
311317
* CRIU_DUMP_PERMISSION
318+
/*[ENDIF] JAVA_SPEC_VERSION < 24
312319
* @throws IllegalArgumentException if imageDir is not a valid directory
313320
*/
314321
public InternalCRIUSupport(Path imageDir) {
322+
/*[IF JAVA_SPEC_VERSION < 24]*/
315323
SecurityManager manager = System.getSecurityManager();
316324
if (manager != null) {
317325
manager.checkPermission(CRIU_DUMP_PERMISSION);
318326
}
319-
327+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
320328
setImageDir(imageDir);
321329
}
322330

@@ -431,7 +439,9 @@ public InternalCRIUSupport setGhostFileLimit(long limit) {
431439
* @param imageDir the directory as a java.nio.file.Path
432440
* @return this
433441
* @throws NullPointerException if imageDir is null
442+
/*[IF JAVA_SPEC_VERSION < 24]
434443
* @throws SecurityException if no permission to access imageDir
444+
/*[ENDIF] JAVA_SPEC_VERSION < 24
435445
* @throws IllegalArgumentException if imageDir is not a valid directory
436446
*/
437447
public InternalCRIUSupport setImageDir(Path imageDir) {
@@ -441,10 +451,12 @@ public InternalCRIUSupport setImageDir(Path imageDir) {
441451
}
442452
String dir = imageDir.toAbsolutePath().toString();
443453

454+
/*[IF JAVA_SPEC_VERSION < 24]*/
444455
SecurityManager manager = System.getSecurityManager();
445456
if (manager != null) {
446457
manager.checkWrite(dir);
447458
}
459+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
448460

449461
this.imageDir = dir;
450462
return this;
@@ -592,7 +604,9 @@ public InternalCRIUSupport setTrackMemory(boolean trackMemory) {
592604
* @param workDir the directory as a java.nio.file.Path
593605
* @return this
594606
* @throws NullPointerException if workDir is null
607+
/*[IF JAVA_SPEC_VERSION < 24]
595608
* @throws SecurityException if no permission to access workDir
609+
/*[ENDIF] JAVA_SPEC_VERSION < 24
596610
* @throws IllegalArgumentException if workDir is not a valid directory
597611
*/
598612
public InternalCRIUSupport setWorkDir(Path workDir) {
@@ -602,10 +616,12 @@ public InternalCRIUSupport setWorkDir(Path workDir) {
602616
}
603617
String dir = workDir.toAbsolutePath().toString();
604618

619+
/*[IF JAVA_SPEC_VERSION < 24]*/
605620
SecurityManager manager = System.getSecurityManager();
606621
if (manager != null) {
607622
manager.checkWrite(dir);
608623
}
624+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
609625

610626
this.workDir = dir;
611627
return this;

jcl/src/openj9.criu/share/classes/org/eclipse/openj9/criu/CRIUDumpPermission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*[INCLUDE-IF CRIU_SUPPORT]*/
1+
/*[INCLUDE-IF CRIU_SUPPORT & (JAVA_SPEC_VERSION < 24)]*/
22
/*
33
* Copyright IBM Corp. and others 2021
44
*

jcl/src/openj9.criu/share/classes/org/eclipse/openj9/criu/CRIUSupport.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
* This API enables the use of CRIU capabilities provided by the OS as well as JVM support for facilitating a successful checkpoint
3636
* and restore in varying environments.
3737
*/
38-
/*[IF JAVA_SPEC_VERSION >= 17]*/
39-
@SuppressWarnings({ "deprecation", "removal" })
40-
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
4138
public final class CRIUSupport {
4239

4340
/**
@@ -86,8 +83,10 @@ public static enum HookMode {
8683
* @param imageDir the directory that will hold the dump files as a
8784
* java.nio.file.Path
8885
* @throws NullPointerException if imageDir is null
86+
/*[IF JAVA_SPEC_VERSION < 24]
8987
* @throws SecurityException if no permission to access imageDir or no
9088
* CRIU_DUMP_PERMISSION
89+
/*[ENDIF] JAVA_SPEC_VERSION < 24
9190
* @throws IllegalArgumentException if imageDir is not a valid directory
9291
*/
9392
public CRIUSupport(Path imageDir) {
@@ -141,7 +140,9 @@ public static String getErrorMessage() {
141140
* @param imageDir the directory as a java.nio.file.Path
142141
* @return this
143142
* @throws NullPointerException if imageDir is null
143+
/*[IF JAVA_SPEC_VERSION < 24]
144144
* @throws SecurityException if no permission to access imageDir
145+
/*[ENDIF] JAVA_SPEC_VERSION < 24
145146
* @throws IllegalArgumentException if imageDir is not a valid directory
146147
*/
147148
public CRIUSupport setImageDir(Path imageDir) {
@@ -283,7 +284,9 @@ public CRIUSupport setTrackMemory(boolean trackMemory) {
283284
* @param workDir the directory as a java.nio.file.Path
284285
* @return this
285286
* @throws NullPointerException if workDir is null
287+
/*[IF JAVA_SPEC_VERSION < 24]
286288
* @throws SecurityException if no permission to access workDir
289+
/*[ENDIF] JAVA_SPEC_VERSION < 24
287290
* @throws IllegalArgumentException if workDir is not a valid directory
288291
*/
289292
public CRIUSupport setWorkDir(Path workDir) {

0 commit comments

Comments
 (0)