Skip to content

Commit 36bb03e

Browse files
Crema: detect caller sensitive methods
1 parent 4474cf9 commit 36bb03e

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;
@@ -43,6 +44,7 @@
4344
import java.util.Set;
4445
import java.util.function.Function;
4546

47+
import org.graalvm.nativeimage.AnnotationAccess;
4648
import org.graalvm.nativeimage.Platform;
4749
import org.graalvm.nativeimage.Platforms;
4850

@@ -63,6 +65,7 @@
6365
import com.oracle.svm.espresso.shared.meta.SignaturePolymorphicIntrinsic;
6466
import com.oracle.svm.espresso.shared.vtable.PartialMethod;
6567
import com.oracle.svm.interpreter.metadata.serialization.VisibleForSerialization;
68+
import com.oracle.svm.util.ReflectionUtil;
6669

6770
import jdk.graal.compiler.word.Word;
6871
import jdk.vm.ci.meta.Constant;
@@ -80,6 +83,9 @@
8083
* also abstract methods for vtable calls.
8184
*/
8285
public class InterpreterResolvedJavaMethod implements ResolvedJavaMethod, CremaMethodAccess {
86+
@Platforms(Platform.HOSTED_ONLY.class)//
87+
@SuppressWarnings("unchecked") //
88+
private static final Class<? extends Annotation> CALLER_SENSITIVE_CLASS = (Class<? extends Annotation>) ReflectionUtil.lookupClass("jdk.internal.reflect.CallerSensitive");
8389
/**
8490
* This flag denotes a method that was originally native but was substituted by a non-native
8591
* method.
@@ -319,9 +325,16 @@ private static int createFlags(int modifiers, InterpreterResolvedObjectType decl
319325
if (isSubstitutedNative) {
320326
newModifiers |= ACC_SUBSTITUTED_NATIVE;
321327
}
328+
if (AnnotationAccess.isAnnotationPresent(originalMethod, CALLER_SENSITIVE_CLASS)) {
329+
newModifiers |= ACC_CALLER_SENSITIVE;
330+
}
322331
return newModifiers;
323332
}
324333

334+
public final boolean isCallerSensitive() {
335+
return (flags & ACC_CALLER_SENSITIVE) != 0;
336+
}
337+
325338
@Override
326339
public final boolean isDeclaredSignaturePolymorphic() {
327340
// 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;
@@ -849,7 +850,9 @@ private static void plantResolvedMethod(Target_java_lang_invoke_MemberName mn,
849850
private static int getMethodFlags(ResolvedCall<InterpreterResolvedJavaType, InterpreterResolvedJavaMethod, InterpreterResolvedJavaField> resolvedCall) {
850851
InterpreterResolvedJavaMethod resolvedMethod = resolvedCall.getResolvedMethod();
851852
int flags = resolvedMethod.getModifiers();
852-
// MN_CALLER_SENSITIVE should be added for caller-sensitive methods GR-68603
853+
if (resolvedMethod.isCallerSensitive()) {
854+
flags |= MN_CALLER_SENSITIVE;
855+
}
853856
if (resolvedMethod.isConstructor() || resolvedMethod.isClassInitializer()) {
854857
flags |= MN_IS_CONSTRUCTOR;
855858
flags |= (REF_newInvokeSpecial << MN_REFERENCE_KIND_SHIFT);

0 commit comments

Comments
 (0)