Skip to content

Commit 983019a

Browse files
Crema: detect caller sensitive methods
1 parent 233b57d commit 983019a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

substratevm/src/com.oracle.svm.interpreter.metadata/src/com/oracle/svm/interpreter/metadata/InterpreterResolvedJavaMethod.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.interpreter.metadata;
2626

27+
import static com.oracle.svm.espresso.classfile.Constants.ACC_CALLER_SENSITIVE;
2728
import static com.oracle.svm.espresso.classfile.Constants.ACC_FINAL;
2829
import static com.oracle.svm.espresso.classfile.Constants.ACC_NATIVE;
2930
import static com.oracle.svm.espresso.classfile.Constants.ACC_SIGNATURE_POLYMORPHIC;
@@ -42,6 +43,7 @@
4243
import java.util.Set;
4344
import java.util.function.Function;
4445

46+
import org.graalvm.nativeimage.AnnotationAccess;
4547
import org.graalvm.nativeimage.Platform;
4648
import org.graalvm.nativeimage.Platforms;
4749

@@ -62,6 +64,7 @@
6264
import com.oracle.svm.espresso.shared.meta.SignaturePolymorphicIntrinsic;
6365
import com.oracle.svm.espresso.shared.vtable.PartialMethod;
6466
import com.oracle.svm.interpreter.metadata.serialization.VisibleForSerialization;
67+
import com.oracle.svm.util.ReflectionUtil;
6568

6669
import jdk.graal.compiler.word.Word;
6770
import jdk.vm.ci.meta.Constant;
@@ -79,6 +82,9 @@
7982
* also abstract methods for vtable calls.
8083
*/
8184
public class InterpreterResolvedJavaMethod implements ResolvedJavaMethod, CremaMethodAccess {
85+
@Platforms(Platform.HOSTED_ONLY.class)//
86+
@SuppressWarnings("unchecked") //
87+
private static final Class<? extends Annotation> CALLER_SENSITIVE_CLASS = (Class<? extends Annotation>) ReflectionUtil.lookupClass("jdk.internal.reflect.CallerSensitive");
8288
/**
8389
* This flag denotes a method that was originally native but was substituted by a non-native
8490
* method.
@@ -304,9 +310,16 @@ private static int createFlags(int modifiers, InterpreterResolvedObjectType decl
304310
if (isSubstitutedNative) {
305311
newModifiers |= ACC_SUBSTITUTED_NATIVE;
306312
}
313+
if (AnnotationAccess.isAnnotationPresent(originalMethod, CALLER_SENSITIVE_CLASS)) {
314+
newModifiers |= ACC_CALLER_SENSITIVE;
315+
}
307316
return newModifiers;
308317
}
309318

319+
public final boolean isCallerSensitive() {
320+
return (flags & ACC_CALLER_SENSITIVE) != 0;
321+
}
322+
310323
@Override
311324
public final boolean isDeclaredSignaturePolymorphic() {
312325
// Note: might not be true for the instantiation of polymorphic signature intrinsics.

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/CremaSupportImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.interpreter;
2626

27+
import static com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives_Constants.MN_CALLER_SENSITIVE;
2728
import static com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives_Constants.MN_IS_CONSTRUCTOR;
2829
import static com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives_Constants.MN_IS_FIELD;
2930
import static com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives_Constants.MN_IS_METHOD;
@@ -850,7 +851,9 @@ private static void plantResolvedMethod(Target_java_lang_invoke_MemberName mn,
850851
private static int getMethodFlags(ResolvedCall<InterpreterResolvedJavaType, InterpreterResolvedJavaMethod, InterpreterResolvedJavaField> resolvedCall) {
851852
InterpreterResolvedJavaMethod resolvedMethod = resolvedCall.getResolvedMethod();
852853
int flags = resolvedMethod.getModifiers();
853-
// MN_CALLER_SENSITIVE should be added for caller-sensitive methods GR-68603
854+
if (resolvedMethod.isCallerSensitive()) {
855+
flags |= MN_CALLER_SENSITIVE;
856+
}
854857
if (resolvedMethod.isConstructor() || resolvedMethod.isClassInitializer()) {
855858
flags |= MN_IS_CONSTRUCTOR;
856859
flags |= (REF_newInvokeSpecial << MN_REFERENCE_KIND_SHIFT);

0 commit comments

Comments
 (0)