diff --git a/compiler/src/jdk.compiler.graal/src/jdk/compiler/graal/nodes/ValuePhiNode.java b/compiler/src/jdk.compiler.graal/src/jdk/compiler/graal/nodes/ValuePhiNode.java index d1b4d3e92801..739b02ebea71 100644 --- a/compiler/src/jdk.compiler.graal/src/jdk/compiler/graal/nodes/ValuePhiNode.java +++ b/compiler/src/jdk.compiler.graal/src/jdk/compiler/graal/nodes/ValuePhiNode.java @@ -34,6 +34,7 @@ import jdk.compiler.graal.graph.NodeInputList; import jdk.compiler.graal.nodeinfo.InputType; import jdk.compiler.graal.nodeinfo.NodeInfo; +import jdk.compiler.graal.nodes.spi.LimitedValueProxy; import jdk.compiler.graal.nodes.type.StampTool; import jdk.compiler.graal.util.CollectionsUtil; @@ -129,7 +130,7 @@ public boolean inferStamp() { */ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) { if (isAlive() && isLoopPhi() && valuesStamp.isPointerStamp()) { - Stamp firstValueStamp = firstValue().stamp(NodeView.DEFAULT); + Stamp firstValueStamp = stripProxies(firstValue()).stamp(NodeView.DEFAULT); if (firstValueStamp.meet(valuesStamp).equals(firstValueStamp)) { /* * Even the first value's stamp is not more precise than the current stamp, we won't @@ -137,14 +138,14 @@ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) { */ return valuesStamp; } - boolean hasDirectPhiOrProxyInput = false; + boolean hasDirectPhiInput = false; for (ValueNode value : values()) { - if (value instanceof ValuePhiNode || value instanceof ValueProxyNode) { - hasDirectPhiOrProxyInput = true; + if (stripProxies(value) instanceof ValuePhiNode) { + hasDirectPhiInput = true; break; } } - if (!hasDirectPhiOrProxyInput) { + if (!hasDirectPhiInput) { // Nothing to recurse over. return valuesStamp; } @@ -153,13 +154,12 @@ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) { NodeFlood flood = new NodeFlood(graph()); flood.addAll(values()); for (Node node : flood) { - if (node == this) { + Node unproxifiedNode = stripProxies(node); + if (unproxifiedNode == this) { // Don't use this value's stamp as that is what we are computing. - } else if (node instanceof ValuePhiNode phi) { + } else if (unproxifiedNode instanceof ValuePhiNode phi) { flood.addAll(phi.values()); - } else if (node instanceof ValueProxyNode proxy) { - flood.add(proxy.value()); - } else if (node instanceof ValueNode value) { + } else if (unproxifiedNode instanceof ValueNode value) { currentStamp = currentStamp.meet(value.stamp(NodeView.DEFAULT)); if (currentStamp.equals(valuesStamp)) { // We won't become more precise. @@ -175,6 +175,25 @@ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) { return valuesStamp; } + private static Node stripProxies(Node n) { + if (n instanceof ValueNode value) { + return stripProxies(value); + } + return n; + } + + /** + * Proxies with the same stamp as the original node should be ignored when trying to infer a + * loop stamp. + */ + private static ValueNode stripProxies(ValueNode v) { + ValueNode result = v; + while (result instanceof LimitedValueProxy proxy && proxy.getOriginalNode().stamp(NodeView.DEFAULT).equals(result.stamp(NodeView.DEFAULT))) { + result = proxy.getOriginalNode(); + } + return result; + } + @Override public boolean verify() { Stamp s = null; diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 98401406a52d..317857af9e0f 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1357,6 +1357,7 @@ "requiresConcealed": { "jdk.internal.vm.ci": [ "jdk.vm.ci.meta", + "jdk.vm.ci.code", "jdk.vm.ci.common", ] }, diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java index 9e1c718c4c4b..e9dc80ad1065 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java @@ -34,8 +34,42 @@ import java.util.Map; import java.util.Optional; +import org.graalvm.nativeimage.AnnotationAccess; + +import com.oracle.graal.pointsto.AbstractAnalysisEngine; +import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan; +import com.oracle.graal.pointsto.PointsToAnalysis; +import com.oracle.graal.pointsto.api.PointstoOptions; +import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow; +import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow; +import com.oracle.graal.pointsto.flow.MethodFlowsGraph.GraphKind; +import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow; +import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow; +import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow; +import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow; +import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow; +import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow; +import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow; +import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow; +import com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder; +import com.oracle.graal.pointsto.flow.builder.TypeFlowGraphBuilder; +import com.oracle.graal.pointsto.meta.AnalysisField; +import com.oracle.graal.pointsto.meta.AnalysisMethod; +import com.oracle.graal.pointsto.meta.AnalysisType; +import com.oracle.graal.pointsto.meta.HostedProviders; +import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod; +import com.oracle.graal.pointsto.nodes.UnsafePartitionLoadNode; +import com.oracle.graal.pointsto.nodes.UnsafePartitionStoreNode; +import com.oracle.graal.pointsto.phases.InlineBeforeAnalysis; +import com.oracle.graal.pointsto.results.StaticAnalysisResultsBuilder; +import com.oracle.graal.pointsto.results.StrengthenGraphs; +import com.oracle.graal.pointsto.typestate.TypeState; +import com.oracle.graal.pointsto.util.AnalysisError; +import com.oracle.svm.common.meta.MultiMethod; + import jdk.compiler.graal.core.common.spi.ForeignCallDescriptor; import jdk.compiler.graal.core.common.spi.ForeignCallsProvider; +import jdk.compiler.graal.core.common.type.AbstractObjectStamp; import jdk.compiler.graal.core.common.type.ObjectStamp; import jdk.compiler.graal.core.common.type.TypeReference; import jdk.compiler.graal.debug.DebugContext; @@ -110,39 +144,6 @@ import jdk.compiler.graal.replacements.nodes.ObjectClone; import jdk.compiler.graal.replacements.nodes.UnaryMathIntrinsicNode; import jdk.compiler.graal.virtual.phases.ea.PartialEscapePhase; -import org.graalvm.nativeimage.AnnotationAccess; - -import com.oracle.graal.pointsto.AbstractAnalysisEngine; -import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan; -import com.oracle.graal.pointsto.PointsToAnalysis; -import com.oracle.graal.pointsto.api.PointstoOptions; -import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow; -import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow; -import com.oracle.graal.pointsto.flow.MethodFlowsGraph.GraphKind; -import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow; -import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow; -import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow; -import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow; -import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow; -import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow; -import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow; -import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow; -import com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder; -import com.oracle.graal.pointsto.flow.builder.TypeFlowGraphBuilder; -import com.oracle.graal.pointsto.meta.AnalysisField; -import com.oracle.graal.pointsto.meta.AnalysisMethod; -import com.oracle.graal.pointsto.meta.AnalysisType; -import com.oracle.graal.pointsto.meta.HostedProviders; -import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod; -import com.oracle.graal.pointsto.nodes.UnsafePartitionLoadNode; -import com.oracle.graal.pointsto.nodes.UnsafePartitionStoreNode; -import com.oracle.graal.pointsto.phases.InlineBeforeAnalysis; -import com.oracle.graal.pointsto.results.StaticAnalysisResultsBuilder; -import com.oracle.graal.pointsto.results.StrengthenGraphs; -import com.oracle.graal.pointsto.typestate.TypeState; -import com.oracle.graal.pointsto.util.AnalysisError; -import com.oracle.svm.common.meta.MultiMethod; - import jdk.vm.ci.code.BytecodePosition; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.JavaConstant; @@ -1041,8 +1042,7 @@ protected void node(FixedNode n) { state.add(node, newArrayBuilder); - } else if (n instanceof LoadFieldNode) { // value = object.field - LoadFieldNode node = (LoadFieldNode) n; + } else if (n instanceof LoadFieldNode node) { // value = object.field AnalysisField field = (AnalysisField) node.field(); assert field.isAccessed() : field; if (node.getStackKind() == JavaKind.Object) { @@ -1069,12 +1069,17 @@ protected void node(FixedNode n) { } state.add(node, loadFieldBuilder); } + if (node.object() != null) { + processImplicitNonNull(node.object(), state); + } - } else if (n instanceof StoreFieldNode) { // object.field = value - processStoreField((StoreFieldNode) n, state); + } else if (n instanceof StoreFieldNode node) { // object.field = value + processStoreField(node, state); + if (node.object() != null) { + processImplicitNonNull(node.object(), state); + } - } else if (n instanceof LoadIndexedNode) { - LoadIndexedNode node = (LoadIndexedNode) n; + } else if (n instanceof LoadIndexedNode node) { TypeFlowBuilder arrayBuilder = state.lookup(node.array()); if (node.getStackKind() == JavaKind.Object) { AnalysisType type = (AnalysisType) StampTool.typeOrNull(node.array(), bb.getMetaAccess()); @@ -1092,9 +1097,11 @@ protected void node(FixedNode n) { loadIndexedBuilder.addObserverDependency(arrayBuilder); state.add(node, loadIndexedBuilder); } + processImplicitNonNull(node.array(), state); - } else if (n instanceof StoreIndexedNode) { - processStoreIndexed((StoreIndexedNode) n, state); + } else if (n instanceof StoreIndexedNode node) { + processStoreIndexed(node, state); + processImplicitNonNull(node.array(), state); } else if (n instanceof UnsafePartitionLoadNode) { UnsafePartitionLoadNode node = (UnsafePartitionLoadNode) n; @@ -1309,13 +1316,17 @@ protected void node(FixedNode n) { } else if (n instanceof InvokeNode || n instanceof InvokeWithExceptionNode) { Invoke invoke = (Invoke) n; - if (invoke.callTarget() instanceof MethodCallTargetNode) { + if (invoke.callTarget() instanceof MethodCallTargetNode target) { guarantee(bb.strengthenGraalGraphs() || invoke.stateAfter().outerFrameState() == null, "Outer FrameState of %s must be null, but was %s. A non-null outer FrameState indicates that a method inlining has happened, but inlining should only happen after analysis.", invoke.stateAfter(), invoke.stateAfter().outerFrameState()); - MethodCallTargetNode target = (MethodCallTargetNode) invoke.callTarget(); - processMethodInvocation(state, invoke, target.invokeKind(), (PointsToAnalysisMethod) target.targetMethod(), target.arguments()); + var arguments = target.arguments(); + processMethodInvocation(state, invoke, target.invokeKind(), (PointsToAnalysisMethod) target.targetMethod(), arguments); + + if (target.invokeKind().hasReceiver()) { + processImplicitNonNull(arguments.get(0), invoke.asNode(), state); + } } } else if (n instanceof ObjectClone) { @@ -1342,7 +1353,7 @@ protected void node(FixedNode n) { monitorEntryBuilder.addUseDependency(objectBuilder); /* Monitor enters must not be removed. */ typeFlowGraphBuilder.registerSinkBuilder(monitorEntryBuilder); - } else if (n instanceof MacroInvokable) { + } else if (n instanceof MacroInvokable node) { /* * Macro nodes can either be constant folded during compilation, or lowered back to * invocations if constant folding is not possible. So the static analysis needs to @@ -1351,8 +1362,10 @@ protected void node(FixedNode n) { * Note that some macro nodes, like for object cloning, are handled separately * above. */ - MacroInvokable node = (MacroInvokable) n; processMacroInvokable(state, node, true); + if (node.getInvokeKind().hasReceiver()) { + processImplicitNonNull(node.getArgument(0), node.asNode(), state); + } } } @@ -1763,4 +1776,27 @@ private void processStoreIndexed(ValueNode node, ValueNode array, ValueNode valu /** Hook for unsafe offset value checks. */ protected void checkUnsafeOffset(@SuppressWarnings("unused") ValueNode base, @SuppressWarnings("unused") ValueNode offset) { } + + private void processImplicitNonNull(ValueNode node, TypeFlowsOfNodes state) { + processImplicitNonNull(node, node, state); + } + + protected void processImplicitNonNull(ValueNode node, ValueNode source, TypeFlowsOfNodes state) { + assert node.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp : node; + if (!StampTool.isPointerNonNull(node)) { + TypeFlowBuilder inputBuilder = state.lookup(node); + TypeFlowBuilder nullCheckBuilder = TypeFlowBuilder.create(bb, source, NullCheckTypeFlow.class, () -> { + var inputFlow = inputBuilder.get(); + if (inputFlow instanceof NullCheckTypeFlow nullCheck && nullCheck.isBlockingNull()) { + // unnecessary to create redundant null type check + return nullCheck; + } + NullCheckTypeFlow nullCheckFlow = new NullCheckTypeFlow(AbstractAnalysisEngine.sourcePosition(source), inputFlow.getDeclaredType(), true); + flowsGraph.addMiscEntryFlow(nullCheckFlow); + return nullCheckFlow; + }); + nullCheckBuilder.addUseDependency(inputBuilder); + state.update(node, nullCheckBuilder); + } + } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/HostedProviders.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/HostedProviders.java index bf59d5ec56d9..4ec055a81f4e 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/HostedProviders.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/HostedProviders.java @@ -61,21 +61,21 @@ public void setGraphBuilderPlugins(GraphBuilderConfiguration.Plugins graphBuilde } @Override - public Providers copyWith(ConstantReflectionProvider substitution) { + public HostedProviders copyWith(ConstantReflectionProvider substitution) { assert this.getClass() == HostedProviders.class : "must override in " + getClass(); return new HostedProviders(getMetaAccess(), getCodeCache(), substitution, getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getStampProvider(), getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider()); } @Override - public Providers copyWith(ConstantFieldProvider substitution) { + public HostedProviders copyWith(ConstantFieldProvider substitution) { assert this.getClass() == HostedProviders.class : "must override in " + getClass(); return new HostedProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), substitution, getForeignCalls(), getLowerer(), getReplacements(), getStampProvider(), getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider()); } @Override - public Providers copyWith(Replacements substitution) { + public HostedProviders copyWith(Replacements substitution) { assert this.getClass() == HostedProviders.class : "must override in " + getClass(); return new HostedProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), substitution, getStampProvider(), getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider()); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java index 1c27f3931935..2c123a36acd3 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java @@ -67,7 +67,7 @@ import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; import com.oracle.svm.core.stack.StackOverflowCheck; -import com.oracle.svm.core.thread.Continuation; +import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.thread.VMThreads; import com.oracle.svm.core.threadlocal.FastThreadLocal; @@ -375,7 +375,7 @@ private static Object allocateLargeArrayLikeObjectInNewTlab(DynamicHub hub, int @Uninterruptible(reason = "Holds uninitialized memory") private static Object formatArrayLikeObject(Pointer memory, DynamicHub hub, int length, boolean unaligned, FillContent fillContent, byte[] podReferenceMap) { Class clazz = DynamicHub.toClass(hub); - if (Continuation.isSupported() && clazz == StoredContinuation.class) { + if (ContinuationSupport.isSupported() && clazz == StoredContinuation.class) { return FormatStoredContinuationNode.formatStoredContinuation(memory, clazz, length, false, unaligned, true); } else if (Pod.RuntimeSupport.isPresent() && podReferenceMap != null) { return FormatPodNode.formatPod(memory, clazz, length, podReferenceMap, false, unaligned, fillContent, true); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSnippets.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSnippets.java index 247f6d6f6d3c..000c85080d58 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSnippets.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSnippets.java @@ -58,7 +58,6 @@ import com.oracle.svm.core.heap.Pod; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.hub.LayoutEncoding; -import com.oracle.svm.core.thread.Continuation; import com.oracle.svm.core.thread.ContinuationSupport; import jdk.vm.ci.meta.JavaKind; @@ -130,7 +129,7 @@ public Templates(OptionValues options, Providers providers, SubstrateAllocationS this.baseTemplates = baseTemplates; formatObject = snippet(providers, GenScavengeAllocationSnippets.class, "formatObjectSnippet"); formatArray = snippet(providers, GenScavengeAllocationSnippets.class, "formatArraySnippet"); - formatStoredContinuation = Continuation.isSupported() ? snippet(providers, GenScavengeAllocationSnippets.class, "formatStoredContinuation") : null; + formatStoredContinuation = ContinuationSupport.isSupported() ? snippet(providers, GenScavengeAllocationSnippets.class, "formatStoredContinuation") : null; formatPod = Pod.RuntimeSupport.isPresent() ? snippet(providers, GenScavengeAllocationSnippets.class, "formatPodSnippet", @@ -141,7 +140,7 @@ public Templates(OptionValues options, Providers providers, SubstrateAllocationS public void registerLowering(Map, NodeLoweringProvider> lowerings) { lowerings.put(FormatObjectNode.class, new FormatObjectLowering()); lowerings.put(FormatArrayNode.class, new FormatArrayLowering()); - if (Continuation.isSupported()) { + if (ContinuationSupport.isSupported()) { lowerings.put(FormatStoredContinuationNode.class, new FormatStoredContinuationLowering()); } if (Pod.RuntimeSupport.isPresent()) { diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSupport.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSupport.java index 5af97cbc22e5..f99a080c56a8 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSupport.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSupport.java @@ -24,18 +24,19 @@ */ package com.oracle.svm.core.genscavenge.graal; -import com.oracle.svm.core.heap.Pod; -import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor; -import com.oracle.svm.core.thread.Continuation; -import jdk.compiler.graal.core.common.spi.ForeignCallDescriptor; -import jdk.compiler.graal.word.Word; import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.genscavenge.HeapParameters; import com.oracle.svm.core.genscavenge.ThreadLocalAllocation; import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider; import com.oracle.svm.core.graal.snippets.GCAllocationSupport; +import com.oracle.svm.core.heap.Pod; import com.oracle.svm.core.snippets.SnippetRuntime; +import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor; +import com.oracle.svm.core.thread.ContinuationSupport; + +import jdk.compiler.graal.core.common.spi.ForeignCallDescriptor; +import jdk.compiler.graal.word.Word; public class GenScavengeAllocationSupport implements GCAllocationSupport { private static final SubstrateForeignCallDescriptor SLOW_NEW_INSTANCE = SnippetRuntime.findForeignCall(ThreadLocalAllocation.class, "slowPathNewInstance", true); @@ -46,7 +47,7 @@ public class GenScavengeAllocationSupport implements GCAllocationSupport { public static void registerForeignCalls(SubstrateForeignCallsProvider foreignCalls) { foreignCalls.register(UNCONDITIONAL_FOREIGN_CALLS); - if (Continuation.isSupported()) { + if (ContinuationSupport.isSupported()) { foreignCalls.register(SLOW_NEW_STORED_CONTINUATION); } if (Pod.RuntimeSupport.isPresent()) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java index c723a428a5cf..f13625d036df 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java @@ -29,7 +29,6 @@ import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; -import com.oracle.svm.core.hub.PredefinedClassesSupport; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunctionPointer; @@ -38,10 +37,12 @@ import com.oracle.svm.core.FunctionPointerHolder; import com.oracle.svm.core.c.InvokeJavaFunctionPointer; import com.oracle.svm.core.hub.DynamicHub; +import com.oracle.svm.core.hub.PredefinedClassesSupport; import com.oracle.svm.core.jdk.InternalVMMethod; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; +import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.thread.JavaThreads; -import com.oracle.svm.core.thread.VirtualThreads; +import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.core.util.VMError; import jdk.internal.misc.Unsafe; @@ -263,16 +264,16 @@ private static void initialize(ClassInitializationInfo info, DynamicHub hub) { } boolean pinned = false; - if (VirtualThreads.isSupported() && JavaThreads.isCurrentThreadVirtual()) { + if (ContinuationSupport.isSupported() && JavaThreads.isCurrentThreadVirtual()) { // See comment on field `initThread` - VirtualThreads.singleton().pinCurrent(); + Target_jdk_internal_vm_Continuation.pin(); pinned = true; } try { doInitialize(info, hub); } finally { if (pinned) { - VirtualThreads.singleton().unpinCurrent(); + Target_jdk_internal_vm_Continuation.unpin(); } } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java index 92f9ecb66bb6..fd21e9fc6637 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java @@ -410,8 +410,7 @@ public void lower(FixedNode node, LoweringTool tool) { hub = graph.unique(new LoadHubNode(runtimeConfig.getProviders().getStampProvider(), graph.addOrUnique(PiNode.create(receiver, nullCheck)))); AddressNode address = graph.unique(new OffsetAddressNode(hub, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), vtableEntryOffset, graph))); ReadNode entry = graph.add(new ReadNode(address, SubstrateBackend.getVTableIdentity(), FrameAccess.getWordStamp(), BarrierType.NONE, MemoryOrderMode.PLAIN)); - loweredCallTarget = graph.add( - new IndirectCallTargetNode(entry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, method, callType, invokeKind)); + loweredCallTarget = createIndirectCall(graph, callTarget, parameters, method, signature, callType, invokeKind, entry); graph.addBeforeFixed(node, entry); } @@ -435,6 +434,11 @@ protected LoweredCallTargetNode createDirectCall(StructuredGraph graph, MethodCa callTarget.returnStamp(), signature, targetMethod, callType, invokeKind)); } + protected IndirectCallTargetNode createIndirectCall(StructuredGraph graph, MethodCallTargetNode callTarget, NodeInputList parameters, SharedMethod method, JavaType[] signature, + CallingConvention.Type callType, InvokeKind invokeKind, ReadNode entry) { + return graph.add(new IndirectCallTargetNode(entry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, method, callType, invokeKind)); + } + private static CallTargetNode createUnreachableCallTarget(LoweringTool tool, FixedNode node, NodeInputList parameters, StampPair returnStamp, JavaType[] signature, SharedMethod method, CallingConvention.Type callType, InvokeKind invokeKind) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java index f3fa72e27dc1..1755d04ffd69 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java @@ -102,7 +102,6 @@ import com.oracle.svm.core.snippets.SnippetRuntime; import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; -import com.oracle.svm.core.thread.Continuation; import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.util.VMError; @@ -600,7 +599,7 @@ public Templates(OptionValues options, Providers providers, SubstrateAllocationS ALLOCATION_LOCATIONS); SnippetInfo allocateStoredContinuationSnippet = null; - if (Continuation.isSupported()) { + if (ContinuationSupport.isSupported()) { allocateStoredContinuationSnippet = snippet(providers, SubstrateAllocationSnippets.class, "allocateStoredContinuation", @@ -634,7 +633,7 @@ public void registerLowering(Map, NodeLoweringProvider> lowerings.put(NewMultiArrayNode.class, new NewMultiArrayLowering()); lowerings.put(ValidateNewInstanceClassNode.class, new ValidateNewInstanceClassLowering()); - if (Continuation.isSupported()) { + if (ContinuationSupport.isSupported()) { lowerings.put(NewStoredContinuationNode.class, new NewStoredContinuationLowering()); } if (Pod.RuntimeSupport.isPresent()) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/stackvalue/StackValueNode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/stackvalue/StackValueNode.java index f7d9c8454a4c..8c2785c164ed 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/stackvalue/StackValueNode.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/stackvalue/StackValueNode.java @@ -46,7 +46,6 @@ import com.oracle.svm.core.FrameAccess; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.config.ConfigurationValues; -import com.oracle.svm.core.thread.VirtualThreads; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -153,7 +152,7 @@ public static StackValueNode create(int sizeInBytes, ResolvedJavaMethod method, * around in a caller, but these are difficult to ensure across multiple callers and * callees. */ - boolean checkVirtualThread = disallowVirtualThread && VirtualThreads.isSupported() && !Uninterruptible.Utils.isUninterruptible(method); + boolean checkVirtualThread = disallowVirtualThread && !Uninterruptible.Utils.isUninterruptible(method); return create(sizeInBytes, slotIdentity, checkVirtualThread); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuationAccess.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuationAccess.java index e8da66702ef1..76d50221e126 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuationAccess.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuationAccess.java @@ -30,7 +30,6 @@ import jdk.compiler.graal.nodes.java.ArrayLengthNode; import jdk.compiler.graal.word.Word; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.function.CodePointer; import org.graalvm.nativeimage.c.struct.RawStructure; @@ -39,9 +38,9 @@ import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; -import com.oracle.svm.core.UnmanagedMemoryUtil; import com.oracle.svm.core.AlwaysInline; import com.oracle.svm.core.Uninterruptible; +import com.oracle.svm.core.UnmanagedMemoryUtil; import com.oracle.svm.core.c.NonmovableArray; import com.oracle.svm.core.code.CodeInfo; import com.oracle.svm.core.code.CodeInfoAccess; @@ -58,9 +57,10 @@ import com.oracle.svm.core.stack.JavaStackWalk; import com.oracle.svm.core.stack.JavaStackWalker; import com.oracle.svm.core.stack.StackFrameVisitor; -import com.oracle.svm.core.thread.Continuation; +import com.oracle.svm.core.thread.ContinuationInternals; import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.thread.Safepoint; +import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.core.util.UnsignedUtils; import com.oracle.svm.core.util.VMError; @@ -107,39 +107,14 @@ public static CodePointer getIP(StoredContinuation s) { return s.ip; } - public static int allocateToYield(Continuation c, Pointer baseSp, Pointer sp, CodePointer ip) { - assert sp.isNonNull() && ip.isNonNull(); - return allocateFromStack(c, baseSp, sp, ip, WordFactory.nullPointer()); - } - - public static int allocateToPreempt(Continuation c, Pointer baseSp, IsolateThread targetThread) { - return allocateFromStack(c, baseSp, WordFactory.nullPointer(), WordFactory.nullPointer(), targetThread); - } - - private static int allocateFromStack(Continuation cont, Pointer baseSp, Pointer sp, CodePointer ip, IsolateThread targetThread) { - boolean yield = sp.isNonNull(); - assert yield == ip.isNonNull() && yield == targetThread.isNull(); - assert baseSp.isNonNull(); - - Pointer startSp = sp; - CodePointer startIp = ip; - if (!yield) { - PreemptVisitor visitor = new PreemptVisitor(baseSp); - JavaStackWalker.walkThread(targetThread, visitor); - if (visitor.preemptStatus != Continuation.FREEZE_OK) { - return visitor.preemptStatus; - } - startSp = visitor.leafSP; - startIp = visitor.leafIP; - } - - VMError.guarantee(startSp.isNonNull()); + public static int allocateToYield(Target_jdk_internal_vm_Continuation c, Pointer baseSp, Pointer sp, CodePointer ip) { + assert baseSp.isNonNull() && sp.isNonNull() && ip.isNonNull(); - int framesSize = UnsignedUtils.safeToInt(baseSp.subtract(startSp)); + int framesSize = UnsignedUtils.safeToInt(baseSp.subtract(sp)); StoredContinuation instance = allocate(framesSize); - fillUninterruptibly(instance, startIp, startSp, framesSize); - cont.stored = instance; - return Continuation.FREEZE_OK; + fillUninterruptibly(instance, ip, sp, framesSize); + ContinuationInternals.setStoredContinuation(c, instance); + return ContinuationSupport.FREEZE_OK; } @Uninterruptible(reason = "Prevent modifications to the stack while initializing instance and copying frames.") @@ -300,7 +275,7 @@ private static final class PreemptVisitor extends StackFrameVisitor { Pointer leafSP; CodePointer leafIP; - int preemptStatus = Continuation.FREEZE_OK; + int preemptStatus = ContinuationSupport.FREEZE_OK; PreemptVisitor(Pointer endSP) { this.endSP = endSP; @@ -315,7 +290,7 @@ protected boolean visitFrame(Pointer sp, CodePointer ip, CodeInfo codeInfo, Deop FrameInfoQueryResult frameInfo = CodeInfoTable.lookupCodeInfoQueryResult(codeInfo, ip).getFrameInfo(); if (frameInfo.getSourceClass().equals(StoredContinuationAccess.class) && frameInfo.getSourceMethodName().equals("allocateToYield")) { // Continuation is already in the process of yielding, cancel preemption. - preemptStatus = Continuation.YIELDING; + preemptStatus = ContinuationSupport.FREEZE_YIELDING; return false; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java index cc7a03916128..25c128eaf93a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java @@ -43,7 +43,7 @@ import com.oracle.svm.core.heap.PodReferenceMapDecoder; import com.oracle.svm.core.heap.ReferenceAccess; import com.oracle.svm.core.heap.StoredContinuationAccess; -import com.oracle.svm.core.thread.Continuation; +import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.util.VMError; /** @@ -130,7 +130,7 @@ private static boolean walkPod(Object obj, ObjectReferenceVisitor visitor, Dynam @AlwaysInline("Performance critical version") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static boolean walkStoredContinuation(Object obj, ObjectReferenceVisitor visitor) { - if (!Continuation.isSupported()) { + if (!ContinuationSupport.isSupported()) { throw VMError.shouldNotReachHere("Stored continuation objects cannot be in the heap if the continuation support is disabled."); } return StoredContinuationAccess.walkReferences(obj, visitor); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/DisallowedImageHeapObjects.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/DisallowedImageHeapObjects.java index 125efc0dba22..b6ccc67d8976 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/DisallowedImageHeapObjects.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/DisallowedImageHeapObjects.java @@ -37,7 +37,6 @@ import java.util.concurrent.ThreadLocalRandom; import com.oracle.svm.core.SubstrateUtil; -import com.oracle.svm.core.thread.VirtualThreads; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -52,20 +51,12 @@ public interface DisallowedObjectReporter { RuntimeException raise(String msg, Object obj, String initializerAction); } - private static final Class CANCELLABLE_CLASS; - private static final Class JDK_VIRTUAL_THREAD_CLASS; - private static final Class CONTINUATION_CLASS; - private static final Method CONTINUATION_IS_STARTED_METHOD; - private static final Class CLEANER_CLEANABLE_CLASS; - private static final Class LEGACY_CLEANER_CLASS; - static { - CANCELLABLE_CLASS = ReflectionUtil.lookupClass(false, "sun.nio.fs.Cancellable"); - JDK_VIRTUAL_THREAD_CLASS = ReflectionUtil.lookupClass(true, "java.lang.VirtualThread"); - CONTINUATION_CLASS = ReflectionUtil.lookupClass(true, "jdk.internal.vm.Continuation"); - CONTINUATION_IS_STARTED_METHOD = (CONTINUATION_CLASS == null) ? null : ReflectionUtil.lookupMethod(CONTINUATION_CLASS, "isStarted"); - CLEANER_CLEANABLE_CLASS = ReflectionUtil.lookupClass(false, "jdk.internal.ref.CleanerImpl$CleanerCleanable"); - LEGACY_CLEANER_CLASS = ReflectionUtil.lookupClass(false, "jdk.internal.ref.Cleaner"); - } + private static final Class CANCELLABLE_CLASS = ReflectionUtil.lookupClass(false, "sun.nio.fs.Cancellable"); + private static final Class VIRTUAL_THREAD_CLASS = ReflectionUtil.lookupClass(false, "java.lang.VirtualThread"); + private static final Class CONTINUATION_CLASS = ReflectionUtil.lookupClass(false, "jdk.internal.vm.Continuation"); + private static final Method CONTINUATION_IS_STARTED_METHOD = ReflectionUtil.lookupMethod(CONTINUATION_CLASS, "isStarted"); + private static final Class CLEANER_CLEANABLE_CLASS = ReflectionUtil.lookupClass(false, "jdk.internal.ref.CleanerImpl$CleanerCleanable"); + private static final Class LEGACY_CLEANER_CLASS = ReflectionUtil.lookupClass(false, "jdk.internal.ref.Cleaner"); public static void check(Object obj, DisallowedObjectReporter reporter) { if (((obj instanceof Random) && !(obj instanceof ThreadLocalRandom)) || obj instanceof SplittableRandom) { @@ -75,9 +66,8 @@ public static void check(Object obj, DisallowedObjectReporter reporter) { } /* Started platform threads */ - if (obj instanceof Thread) { - final Thread asThread = (Thread) obj; - if (VirtualThreads.isSupported() && (VirtualThreads.singleton().isVirtual(asThread) || (JDK_VIRTUAL_THREAD_CLASS != null && JDK_VIRTUAL_THREAD_CLASS.isInstance(asThread)))) { + if (obj instanceof Thread asThread) { + if (VIRTUAL_THREAD_CLASS.isInstance(asThread)) { // allowed unless the thread is mounted, in which case it references its carrier // thread and fails } else if (asThread.getState() != Thread.State.NEW && asThread.getState() != Thread.State.TERMINATED) { @@ -86,7 +76,7 @@ public static void check(Object obj, DisallowedObjectReporter reporter) { asThread, "Prevent threads from starting during image generation, or a started thread from being included in the image."); } } - if (SubstrateUtil.HOSTED && CONTINUATION_CLASS != null && CONTINUATION_CLASS.isInstance(obj)) { + if (SubstrateUtil.HOSTED && CONTINUATION_CLASS.isInstance(obj)) { boolean isStarted; try { isStarted = (Boolean) CONTINUATION_IS_STARTED_METHOD.invoke(obj); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsNotSupported.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsNotSupported.java deleted file mode 100644 index 070f91430ff9..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsNotSupported.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import com.oracle.svm.core.thread.Continuation; - -public class ContinuationsNotSupported implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return !Continuation.isSupported(); - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsSupported.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsSupported.java deleted file mode 100644 index 58e6fbf190ce..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ContinuationsSupported.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import com.oracle.svm.core.thread.Continuation; - -public class ContinuationsSupported implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return Continuation.isSupported(); - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LoomJDK.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LoomJDK.java deleted file mode 100644 index 308577de3d72..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LoomJDK.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import com.oracle.svm.core.thread.LoomSupport; - -public class LoomJDK implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return LoomSupport.isEnabled(); - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NotLoomJDK.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NotLoomJDK.java deleted file mode 100644 index 3107a626cad7..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NotLoomJDK.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import com.oracle.svm.core.thread.LoomSupport; - -public class NotLoomJDK implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return !LoomSupport.isEnabled(); - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java index 308f01da0ec7..38cc6bf04a62 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java @@ -61,11 +61,8 @@ import com.oracle.svm.core.stack.StackFrameVisitor; import com.oracle.svm.core.thread.JavaThreads; import com.oracle.svm.core.thread.JavaVMOperation; -import com.oracle.svm.core.thread.LoomSupport; -import com.oracle.svm.core.thread.PlatformThreads; import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.core.thread.VMOperation; -import com.oracle.svm.core.thread.VirtualThreads; import com.oracle.svm.core.util.VMError; import jdk.vm.ci.meta.MetaAccessProvider; @@ -104,10 +101,7 @@ public static void visitCurrentThreadStackFrames(Pointer startSP, Pointer endSP, @NeverInline("Potentially starting a stack walk in the caller frame") public static StackTraceElement[] getStackTraceAtSafepoint(Thread thread) { assert VMOperation.isInProgressAtSafepoint(); - if (VirtualThreads.isSupported()) { // NOTE: also for platform threads! - return VirtualThreads.singleton().getVirtualOrPlatformThreadStackTraceAtSafepoint(thread, readCallerStackPointer()); - } - return PlatformThreads.getStackTraceAtSafepoint(thread, readCallerStackPointer()); + return JavaThreads.getStackTraceAtSafepoint(thread, readCallerStackPointer()); } public static StackTraceElement[] getThreadStackTraceAtSafepoint(IsolateThread isolateThread, Pointer endSP) { @@ -186,7 +180,7 @@ public static boolean shouldShowFrame(FrameInfoQueryResult frameInfo, boolean sh return false; } - if (LoomSupport.isEnabled() && clazz == Target_jdk_internal_vm_Continuation.class) { + if (clazz == Target_jdk_internal_vm_Continuation.class) { String name = frameInfo.getSourceMethodName(); if (name.startsWith("enter") || name.startsWith("yield")) { return false; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java index e6aed227bf14..033ed3539304 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java @@ -48,7 +48,6 @@ import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.code.CodeInfo; import com.oracle.svm.core.code.CodeInfoAccess; import com.oracle.svm.core.code.CodeInfoTable; @@ -64,9 +63,9 @@ import com.oracle.svm.core.stack.JavaStackFrameVisitor; import com.oracle.svm.core.stack.JavaStackWalk; import com.oracle.svm.core.stack.JavaStackWalker; -import com.oracle.svm.core.thread.Continuation; +import com.oracle.svm.core.thread.ContinuationInternals; +import com.oracle.svm.core.thread.ContinuationSupport; import com.oracle.svm.core.thread.JavaThreads; -import com.oracle.svm.core.thread.LoomSupport; import com.oracle.svm.core.thread.Target_java_lang_VirtualThread; import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.core.thread.Target_jdk_internal_vm_ContinuationScope; @@ -79,13 +78,13 @@ final class Target_java_lang_StackWalker { /** * Current continuation that the stack walker is on. */ - @Alias @TargetElement(onlyWith = LoomJDK.class)// + @Alias // Target_jdk_internal_vm_Continuation continuation; /** * Target continuation scope if we're iterating a {@link Target_jdk_internal_vm_Continuation}. */ - @Alias @TargetElement(onlyWith = LoomJDK.class)// + @Alias // Target_jdk_internal_vm_ContinuationScope contScope; @Alias Set