diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/CGlobalDataNonConstantRegistry.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/CGlobalDataNonConstantRegistry.java index 97f95d797859..921f158da57d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/CGlobalDataNonConstantRegistry.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/CGlobalDataNonConstantRegistry.java @@ -32,6 +32,7 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.svm.core.annotate.NeverInline; import com.oracle.svm.core.graal.code.CGlobalDataInfo; import com.oracle.svm.core.util.ImageHeapMap; @@ -50,6 +51,7 @@ public class CGlobalDataNonConstantRegistry { /** * Invoked at runtime via com.oracle.svm.hosted.c.CGlobalDataFeature#getCGlobalDataInfoMethod. */ + @NeverInline("CGlobalDataFeature expects that this call is not inlined") public CGlobalDataInfo getCGlobalDataInfo(CGlobalDataImpl cGlobalData) { return cGlobalDataInfos.get(cGlobalData); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index aee511c32f06..7492e11b08c1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -59,6 +59,10 @@ public final class Target_java_lang_Thread { // Checkstyle: stop @Alias // static StackTraceElement[] EMPTY_STACK_TRACE; + + @Alias // + @TargetElement(onlyWith = JDK19OrLater.class) // + static int NO_INHERIT_THREAD_LOCALS; // Checkstyle: resume /** This field is initialized when the thread actually starts executing. */ @@ -333,9 +337,11 @@ private Target_java_lang_Thread( /* Injected Target_java_lang_Thread instance field initialization. */ this.threadData = new ThreadData(); - // TODO: derive from characteristics bitset - boolean inheritThreadLocals = false; - /* Initialize the rest of the Thread object, ignoring `characteristics`. */ + boolean inheritThreadLocals = (characteristics & NO_INHERIT_THREAD_LOCALS) == 0; + /* + * Initialize the rest of the Thread object, ignoring `characteristics` except for inherit + * thread locals. + */ String nameLocal = (name != null) ? name : genThreadName(); JavaThreads.initializeNewThread(this, g, target, nameLocal, stackSize, acc, inheritThreadLocals); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java index 8daa889656cc..9595bee5ad43 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java @@ -59,10 +59,13 @@ import org.graalvm.compiler.nodes.java.InstanceOfNode; import org.graalvm.compiler.nodes.java.LoadFieldNode; import org.graalvm.compiler.replacements.nodes.MacroNode.MacroParams; +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.hosted.Feature; import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException; +import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.meta.HostedProviders; +import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.SubstrateAnnotationInvocationHandler; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.graal.jdk.SubstrateObjectCloneWithExceptionNode; @@ -585,12 +588,25 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins()); graph.start().setStateAfter(state.create(0, graph.start())); - String returnValue = "@" + annotationInterfaceType.toJavaName(true); + String returnValue; + if (JavaVersionUtil.JAVA_SPEC >= 19) { + /* + * In JDK 19, annotations use Class.getCanonicalName() instead of Class.getName(). + * See JDK-8281462. + */ + returnValue = "@" + getJavaClass(annotationInterfaceType).getCanonicalName(); + } else { + returnValue = "@" + annotationInterfaceType.toJavaName(true); + } ValueNode returnConstant = kit.unique(ConstantNode.forConstant(SubstrateObjectConstant.forObject(returnValue), providers.getMetaAccess())); kit.append(new ReturnNode(returnConstant)); return kit.finalizeGraph(); } + + private static Class getJavaClass(ResolvedJavaType type) { + return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), type); + } } /* diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/SecurityServiceTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/SecurityServiceTest.java index 271ca5b1a0ac..58af9f98a86a 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/SecurityServiceTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/SecurityServiceTest.java @@ -28,7 +28,6 @@ import java.security.Provider; import java.security.Security; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -36,6 +35,9 @@ import org.junit.Assert; import org.junit.Test; +import com.oracle.svm.util.ModuleSupport; +import com.oracle.svm.util.ReflectionUtil; + import sun.security.jca.GetInstance; /** @@ -48,6 +50,8 @@ public void afterRegistration(AfterRegistrationAccess access) { // register the providers Security.addProvider(new NoOpProvider()); Security.addProvider(new NoOpProviderTwo()); + // open sun.security.jca.GetInstance + ModuleSupport.accessModuleByClass(ModuleSupport.Access.EXPORT, JCACompliantNoOpService.class, ReflectionUtil.lookupClass(false, "sun.security.jca.GetInstance")); } @Override @@ -81,15 +85,12 @@ public void testUnknownSecurityServices() throws Exception { @Test public void testAutomaticSecurityServiceRegistration() { - if (JavaVersionUtil.JAVA_SPEC < 19) { - // Does not work on JDK 19 for yet unknown reasons (GR-39827) - try { - JCACompliantNoOpService service = JCACompliantNoOpService.getInstance("no-op-algo-two"); - Assert.assertNotNull("No service instance was created", service); - Assert.assertThat("Unexpected service implementtation class", service, CoreMatchers.instanceOf(JcaCompliantNoOpServiceImpl.class)); - } catch (NoSuchAlgorithmException e) { - Assert.fail("Failed to fetch noop service with exception: " + e); - } + try { + JCACompliantNoOpService service = JCACompliantNoOpService.getInstance("no-op-algo-two"); + Assert.assertNotNull("No service instance was created", service); + Assert.assertThat("Unexpected service implementation class", service, CoreMatchers.instanceOf(JcaCompliantNoOpServiceImpl.class)); + } catch (NoSuchAlgorithmException e) { + Assert.fail("Failed to fetch noop service with exception: " + e); } }