Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JEP416] Add caller sensitive adapter method in java.lang.ClassLoader #14177

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 1998, 2021 IBM Corp. and others
* Copyright (c) 1998, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -68,6 +68,10 @@
import jdk.internal.loader.NativeLibrary;
/*[ENDIF] JAVA_SPEC_VERSION >= 15 */

/*[IF JAVA_SPEC_VERSION >= 18]*/
import jdk.internal.reflect.CallerSensitiveAdapter;
/*[ENDIF] JAVA_SPEC_VERSION >= 18 */

/**
* ClassLoaders are used to dynamically load, link and install
* classes into a running image.
Expand Down Expand Up @@ -1400,6 +1404,13 @@ Class<?> loadClassHelper(final String className, boolean resolveClass, boolean d
protected static boolean registerAsParallelCapable() {
final Class<?> callerCls = System.getCallerClass();

/*[IF JAVA_SPEC_VERSION >= 18]*/
return registerAsParallelCapable(callerCls);
}

@CallerSensitiveAdapter
private static boolean registerAsParallelCapable(Class<?> callerCls) {
/*[ENDIF] JAVA_SPEC_VERSION >= 18 */
if (parallelCapableCollection.containsKey(callerCls)) {
return true;
}
Expand Down
13 changes: 12 additions & 1 deletion runtime/bcutil/ClassFileOracle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2021 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -51,6 +51,11 @@ ClassFileOracle::KnownAnnotation ClassFileOracle::_knownAnnotations[] = {
#define JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE "Ljdk/internal/reflect/CallerSensitive;"
{JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE, sizeof(JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE)},
#undef JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE
#if JAVA_SPEC_VERSION >= 18
#define JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE "Ljdk/internal/reflect/CallerSensitiveAdapter;"
{JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE, sizeof(JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE)},
babsingh marked this conversation as resolved.
Show resolved Hide resolved
#undef JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE
#endif /* JAVA_SPEC_VERSION >= 18 */
#define JAVA8_CONTENDED_SIGNATURE "Lsun/misc/Contended;" /* TODO remove this if VM does not support Java 8 */
{JAVA8_CONTENDED_SIGNATURE, sizeof(JAVA8_CONTENDED_SIGNATURE)},
#undef JAVA8_CONTENDED_SIGNATURE
Expand Down Expand Up @@ -923,6 +928,9 @@ ClassFileOracle::walkMethodAttributes(U_16 methodIndex)
knownAnnotations = addAnnotationBit(knownAnnotations, FRAMEITERATORSKIP_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, SUN_REFLECT_CALLERSENSITIVE_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVE_ANNOTATION);
#if JAVA_SPEC_VERSION >= 18
knownAnnotations = addAnnotationBit(knownAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_ANNOTATION);
#endif /* JAVA_SPEC_VERSION >= 18*/
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
knownAnnotations = addAnnotationBit(knownAnnotations, HIDDEN_ANNOTATION);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
Expand All @@ -935,6 +943,9 @@ ClassFileOracle::walkMethodAttributes(U_16 methodIndex)
UDATA foundAnnotations = walkAnnotations(attribAnnotations->numberOfAnnotations, attribAnnotations->annotations, knownAnnotations);
if (containsKnownAnnotation(foundAnnotations, SUN_REFLECT_CALLERSENSITIVE_ANNOTATION)
|| containsKnownAnnotation(foundAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVE_ANNOTATION)
#if JAVA_SPEC_VERSION >= 18
|| containsKnownAnnotation(foundAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_ANNOTATION)
#endif /* JAVA_SPEC_VERSION >= 18*/
) {
_methodsInfo[methodIndex].modifiers |= J9AccMethodCallerSensitive;
}
Expand Down
5 changes: 4 additions & 1 deletion runtime/bcutil/ClassFileOracle.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2021 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1053,6 +1053,9 @@ class RecordComponentIterator
FRAMEITERATORSKIP_ANNOTATION,
SUN_REFLECT_CALLERSENSITIVE_ANNOTATION,
JDK_INTERNAL_REFLECT_CALLERSENSITIVE_ANNOTATION,
#if JAVA_SPEC_VERSION >= 18
JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_ANNOTATION,
#endif /* JAVA_SPEC_VERSION >= 18*/
JAVA8_CONTENDED_ANNOTATION,
CONTENDED_ANNOTATION,
UNMODIFIABLE_ANNOTATION,
Expand Down