From 984bce64b685c1f1c7fd9ca799a36aaa26b00989 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 8 May 2023 15:29:32 -0700 Subject: [PATCH] Add support for @Stable annotation --- .../hosted/meta/SharedConstantFieldProvider.java | 13 ++++++++++++- .../hosted/methodhandles/MethodHandleFeature.java | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/SharedConstantFieldProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/SharedConstantFieldProvider.java index 10d74e882bb4..26f83f9c02c8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/SharedConstantFieldProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/SharedConstantFieldProvider.java @@ -70,7 +70,18 @@ public boolean isFinalField(ResolvedJavaField field, ConstantFieldTool tool) @Override public boolean isStableField(ResolvedJavaField field, ConstantFieldTool tool) { - return super.isStableField(field, tool) && allowConstantFolding(field); + boolean stable; + /* + * GR-46030: JVMCI does not provide access yet to the proper "stable" flag that also takes + * the class loader of the using class into account. So we look at the annotation directly + * for now. + */ + if (field.isAnnotationPresent(jdk.internal.vm.annotation.Stable.class)) { + stable = true; + } else { + stable = super.isStableField(field, tool); + } + return stable && allowConstantFolding(field); } private boolean allowConstantFolding(ResolvedJavaField field) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java index 8ec6f279d51c..fd6cf625f0f7 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java @@ -149,7 +149,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { Class mhImplClazz = access.findClassByName("java.lang.invoke.MethodHandleImpl"); access.registerReachabilityHandler(MethodHandleFeature::registerMHImplFunctionsForReflection, - ReflectionUtil.lookupMethod(mhImplClazz, "createFunction", byte.class)); + ReflectionUtil.lookupMethod(mhImplClazz, "getFunction", byte.class)); access.registerReachabilityHandler(MethodHandleFeature::registerMHImplConstantHandlesForReflection, ReflectionUtil.lookupMethod(mhImplClazz, "makeConstantHandle", int.class)); @@ -158,7 +158,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { access.findClassByName("java.lang.invoke.MethodHandleImpl$CountingWrapper")); access.registerReachabilityHandler(MethodHandleFeature::registerInvokersFunctionsForReflection, - ReflectionUtil.lookupMethod(access.findClassByName("java.lang.invoke.Invokers"), "createFunction", byte.class)); + ReflectionUtil.lookupMethod(access.findClassByName("java.lang.invoke.Invokers"), "getFunction", byte.class)); access.registerReachabilityHandler(MethodHandleFeature::registerValueConversionBoxFunctionsForReflection, ReflectionUtil.lookupMethod(ValueConversions.class, "boxExact", Wrapper.class));