Skip to content

Commit ff753fe

Browse files
committed
Exclude methods that are no longer used in Java 24
Exclude helper methods related to removing the security manager including: - AccessController.initializeInternal native in acccont.c - native helper methods in java_lang_class - doPriviled*id fields from J9JavaVM struct - unused helper methods in java.security.AccessController - unused helper methods in java.security.AccessControlContext - unused helper methods in java.lang.Class java.security comment update and exclude helper methods Signed-off-by: Theresa Mammarella <[email protected]>
1 parent e6eb7a3 commit ff753fe

File tree

11 files changed

+136
-47
lines changed

11 files changed

+136
-47
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,9 @@ public boolean desiredAssertionStatus() {
32043204
* array of not more than maxDepth Classes representing the classes of
32053205
* running methods on the stack (including native methods). Frames
32063206
* representing the VM implementation of java.lang.reflect are not included
3207-
* in the list. If stopAtPrivileged is true, the walk will terminate at any
3207+
* in the list.
3208+
/*[IF JAVA_SPEC_VERSION < 24]
3209+
* If stopAtPrivileged is true, the walk will terminate at any
32083210
* frame running one of the following methods:
32093211
*
32103212
* <code><ul>
@@ -3215,6 +3217,7 @@ public boolean desiredAssertionStatus() {
32153217
* </ul></code>
32163218
*
32173219
* If one of the doPrivileged methods is found, the walk terminate and that frame is NOT included in the returned array.
3220+
/*[ENDIF] JAVA_SPEC_VERSION < 24
32183221
*
32193222
* Notes: <ul>
32203223
* <li> This method operates on the defining classes of methods on stack.
@@ -3225,7 +3228,11 @@ public boolean desiredAssertionStatus() {
32253228
*</ul>
32263229
*
32273230
* @param maxDepth maximum depth to walk the stack, -1 for the entire stack
3231+
/*[IF JAVA_SPEC_VERSION >= 24]
3232+
* @param stopAtPrivileged has no effect
3233+
/*[ELSE] JAVA_SPEC_VERSION >= 24
32283234
* @param stopAtPrivileged stop at privileged classes
3235+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
32293236
* @return the array of the most recent classes on the stack
32303237
*/
32313238
@CallerSensitive

jcl/src/java.base/share/classes/java/security/AccessControlContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ private boolean debugHelper(Permission perm) {
726726
}
727727

728728
/**
729+
/*[IF JAVA_SPEC_VERSION >= 24]
730+
* Throws java.security.AccessControlException
731+
*
732+
* @param perm is ignored
733+
* @exception java.security.AccessControlException
734+
* is always thrown
735+
/*[ELSE] JAVA_SPEC_VERSION >= 24
729736
* Checks if the permission <code>perm</code> is allowed in this context.
730737
* All ProtectionDomains must grant the permission for it to be granted.
731738
*
@@ -735,6 +742,7 @@ private boolean debugHelper(Permission perm) {
735742
* thrown when perm is not granted.
736743
* @exception NullPointerException
737744
* if perm is null
745+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
738746
*/
739747
public void checkPermission(Permission perm) throws AccessControlException {
740748
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -946,6 +954,7 @@ ProtectionDomain[] getContext() {
946954
return context;
947955
}
948956

957+
/*[IF JAVA_SPEC_VERSION < 24]*/
949958
/*
950959
* Added to resolve: S6907662, CVE-2010-4465: System clipboard should ensure access restrictions
951960
* Called internally from java.security.ProtectionDomain
@@ -959,6 +968,7 @@ ProtectionDomain[] getContext() {
959968
this.domainCombiner = acc.domainCombiner;
960969
}
961970
}
971+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
962972

963973
/*
964974
* Added to resolve: S6907662, CVE-2010-4465: System clipboard should ensure access restrictions

jcl/src/java.base/share/classes/java/security/AccessController.java

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@
4646
@SuppressWarnings("removal")
4747
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
4848
public final class AccessController {
49+
/*[IF JAVA_SPEC_VERSION >= 24]*/
50+
private static final AccessControlContext ACC_NO_PERM = new AccessControlContext(
51+
new ProtectionDomain[] { new ProtectionDomain(null, null) });
52+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
4953
static {
5054
// Initialize vm-internal caches
5155
initializeInternal();
5256
}
5357

54-
/*[IF JAVA_SPEC_VERSION >= 24]*/
55-
private static AccessControlContext ACC_NO_PERM = new AccessControlContext(
56-
new ProtectionDomain[] { new ProtectionDomain(null, null) });
57-
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
58-
5958
static final int OBJS_INDEX_ACC = 0;
6059
static final int OBJS_INDEX_PDS = 1;
6160
static final int OBJS_ARRAY_SIZE = 3;
6261
static final int OBJS_INDEX_PERMS_OR_CACHECHECKED = 2;
6362

64-
private static native void initializeInternal();
63+
private static native void initializeInternal();
6564

66-
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */
67-
static final class DebugRecursionDetection {
68-
private static ThreadLocal<String> tlDebug = new ThreadLocal<>();
69-
static ThreadLocal<String> getTlDebug() {
70-
return tlDebug;
65+
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */
66+
static final class DebugRecursionDetection {
67+
private static ThreadLocal<String> tlDebug = new ThreadLocal<>();
68+
static ThreadLocal<String> getTlDebug() {
69+
return tlDebug;
70+
}
7171
}
72-
}
72+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
7373

7474
/*[PR 1FDIC6B] J9JCL:WIN95 - AccessController missing private no-arg constructor */
7575
/**
@@ -79,6 +79,7 @@ private AccessController() {
7979
super();
8080
}
8181

82+
/*[IF JAVA_SPEC_VERSION < 24]*/
8283
/**
8384
* The object array returned has following format:
8485
*
@@ -155,7 +156,6 @@ private AccessController() {
155156
*/
156157
private static native ProtectionDomain getCallerPD(int depth);
157158

158-
/*[IF JAVA_SPEC_VERSION < 24]*/
159159
/**
160160
* provide debug info according to debug settings before throwing AccessControlException
161161
*
@@ -279,7 +279,6 @@ private static boolean checkPermissionHelper(Permission perm, AccessControlConte
279279
}
280280
return limitedPermImplied;
281281
}
282-
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
283282

284283
/**
285284
* Helper to print debug stack information for checkPermission().
@@ -369,15 +368,23 @@ private static boolean debugHelperJEP140(Object[] objects, Permission perm) {
369368
debugPrintStack(debug, perm);
370369
return debug;
371370
}
371+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
372372

373373
/**
374+
/*[IF JAVA_SPEC_VERSION >= 24]
375+
* Throws AccessControlException
376+
*
377+
* @param perm is ignored
378+
* @exception AccessControlException is always thrown
379+
/*[ELSE] JAVA_SPEC_VERSION >= 24
374380
* Checks whether the running program is allowed to
375381
* access the resource being guarded by the given
376382
* Permission argument.
377383
*
378384
* @param perm the permission to check
379385
* @exception AccessControlException if access is not allowed.
380386
* NullPointerException if perm is null
387+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
381388
*/
382389
public static void checkPermission(Permission perm) throws AccessControlException {
383390
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -441,24 +448,9 @@ public static void checkPermission(Permission perm) throws AccessControlExceptio
441448
}
442449

443450
/**
444-
* Used to keep the context live during doPrivileged().
445-
*
446-
* @param context the context to retain
447-
*
448-
* @see #doPrivileged(PrivilegedAction, AccessControlContext)
449-
*/
450-
private static void keepalive(AccessControlContext context) {
451-
return;
452-
}
453-
454-
/**
455-
* @param perms the permissions to retain
456-
*/
457-
private static void keepalive(Permission... perms) {
458-
return;
459-
}
460-
461-
/**
451+
/*[IF JAVA_SPEC_VERSION >= 24]
452+
* @return an AccessControlContext with no permissions
453+
/*[ELSE] JAVA_SPEC_VERSION >= 24
462454
* Answers the access controller context of the current thread,
463455
* including the inherited ones. It basically retrieves all the
464456
* protection domains from the calling stack and creates an
@@ -467,6 +459,7 @@ private static void keepalive(Permission... perms) {
467459
* @return an AccessControlContext which captures the current state
468460
*
469461
* @see AccessControlContext
462+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
470463
*/
471464
public static AccessControlContext getContext() {
472465
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -476,6 +469,25 @@ public static AccessControlContext getContext() {
476469
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
477470
}
478471

472+
/*[IF JAVA_SPEC_VERSION < 24]*/
473+
/**
474+
* Used to keep the context live during doPrivileged().
475+
*
476+
* @param context the context to retain
477+
*
478+
* @see #doPrivileged(PrivilegedAction, AccessControlContext)
479+
*/
480+
private static void keepalive(AccessControlContext context) {
481+
return;
482+
}
483+
484+
/**
485+
* @param perms the permissions to retain
486+
*/
487+
private static void keepalive(Permission... perms) {
488+
return;
489+
}
490+
479491
/**
480492
* This is a helper method for getContext() and doPrivilegedWithCombiner methods.
481493
* Answers the access controller context of the current thread including the inherited ones.
@@ -624,9 +636,6 @@ private static ProtectionDomain[] generatePDarray(DomainCombiner activeDC, Acces
624636
* @return AccessControlContext.STATE_AUTHORIZED or STATE_NOT_AUTHORIZED (can't be STATE_UNKNOWN)
625637
*/
626638
private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDomain callerPD) {
627-
/*[IF JAVA_SPEC_VERSION >= 24]*/
628-
return AccessControlContext.STATE_AUTHORIZED;
629-
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
630639
int newAuthorizedState;
631640
/*[PR JAZZ 87596] PMR 18839,756,000 - Need to trust AccessControlContext created without active SecurityManager */
632641
if ((null != acc) && (null != System.getSecurityManager())) {
@@ -643,7 +652,6 @@ private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDom
643652
newAuthorizedState = AccessControlContext.STATE_AUTHORIZED;
644653
}
645654
return newAuthorizedState;
646-
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
647655
}
648656

649657
/**
@@ -712,6 +720,7 @@ static ProtectionDomain[] toArrayOfProtectionDomains(Object[] domains, AccessCon
712720

713721
return answer;
714722
}
723+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
715724

716725
/**
717726
* Performs the privileged action specified by <code>action</code>.
@@ -760,10 +769,14 @@ public static <T> T doPrivileged(PrivilegedAction<T> action) {
760769
*/
761770
@CallerSensitive
762771
public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context) {
772+
/*[IF JAVA_SPEC_VERSION >= 24]*/
773+
return action.run();
774+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
763775
T result = action.run();
764776
/*[PR 108112] context is not kept alive*/
765777
keepalive(context);
766778
return result;
779+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
767780
}
768781

769782
/**
@@ -827,10 +840,14 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon
827840
throws PrivilegedActionException
828841
{
829842
try {
843+
/*[IF JAVA_SPEC_VERSION >= 24]*/
844+
return action.run();
845+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
830846
T result = action.run();
831847
/*[PR 108112] context is not kept alive*/
832848
keepalive(context);
833849
return result;
850+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
834851
} catch (RuntimeException ex) {
835852
throw ex;
836853
} catch (Exception ex) {
@@ -857,7 +874,11 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon
857874
*/
858875
@CallerSensitive
859876
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
877+
/*[IF JAVA_SPEC_VERSION >= 24]*/
878+
return doPrivileged(action, null);
879+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
860880
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
881+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
861882
}
862883

863884
/**
@@ -884,9 +905,14 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
884905
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
885906
throws PrivilegedActionException
886907
{
908+
/*[IF JAVA_SPEC_VERSION >= 24]*/
909+
return doPrivileged(action, null);
910+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
887911
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
912+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
888913
}
889914

915+
/*[IF JAVA_SPEC_VERSION < 24]*/
890916
/**
891917
* Helper method to check if any permission is null
892918
*
@@ -902,6 +928,7 @@ private static void checkPermsNPE(Permission... perms) {
902928
}
903929
}
904930
}
931+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
905932

906933
/**
907934
* Performs the privileged action specified by <code>action</code>.
@@ -930,11 +957,15 @@ private static void checkPermsNPE(Permission... perms) {
930957
public static <T> T doPrivileged(PrivilegedAction<T> action,
931958
AccessControlContext context, Permission... perms)
932959
{
960+
/*[IF JAVA_SPEC_VERSION >= 24]*/
961+
return action.run();
962+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
933963
checkPermsNPE(perms);
934964
T result = action.run();
935965
keepalive(context);
936966
keepalive(perms);
937967
return result;
968+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
938969
}
939970

940971
/**
@@ -962,8 +993,12 @@ public static <T> T doPrivileged(PrivilegedAction<T> action,
962993
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
963994
AccessControlContext context, Permission... perms)
964995
{
996+
/*[IF JAVA_SPEC_VERSION >= 24]*/
997+
return doPrivileged(action, context, perms);
998+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
965999
checkPermsNPE(perms);
9661000
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
1001+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
9671002
}
9681003

9691004
/**
@@ -997,11 +1032,15 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
9971032
throws PrivilegedActionException
9981033
{
9991034
try {
1035+
/*[IF JAVA_SPEC_VERSION >= 24]*/
1036+
return action.run();
1037+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
10001038
checkPermsNPE(perms);
10011039
T result = action.run();
10021040
keepalive(context);
10031041
keepalive(perms);
10041042
return result;
1043+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
10051044
} catch (RuntimeException ex) {
10061045
throw ex;
10071046
} catch (Exception ex) {
@@ -1037,10 +1076,15 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action
10371076
AccessControlContext context, Permission... perms)
10381077
throws PrivilegedActionException
10391078
{
1079+
/*[IF JAVA_SPEC_VERSION >= 24]*/
1080+
return doPrivileged(action, context, perms);
1081+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
10401082
checkPermsNPE(perms);
10411083
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
1084+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
10421085
}
10431086

1087+
/*[IF JAVA_SPEC_VERSION < 24]*/
10441088
/**
10451089
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods.
10461090
*
@@ -1060,5 +1104,6 @@ private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControl
10601104
}
10611105
return fixedContext;
10621106
}
1107+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
10631108

10641109
}

runtime/jcl/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ target_link_libraries(jclse
106106

107107
target_sources(jclse
108108
PRIVATE
109-
${CMAKE_CURRENT_SOURCE_DIR}/common/acccont.c
110109
${CMAKE_CURRENT_SOURCE_DIR}/common/annparser.c
111110
${CMAKE_CURRENT_SOURCE_DIR}/common/attach.c
112111
${CMAKE_CURRENT_SOURCE_DIR}/common/bootstrp.c
@@ -238,6 +237,10 @@ if(NOT JAVA_SPEC_VERSION LESS 19)
238237
)
239238
endif()
240239

240+
if(JAVA_SPEC_VERSION LESS 24)
241+
target_sources(jclse PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/common/acccont.c)
242+
endif()
243+
241244
if(J9VM_OPT_JFR)
242245
# JFR sources
243246
if(JAVA_SPEC_VERSION EQUAL 11)

0 commit comments

Comments
 (0)