Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.vm.ci.code.Register;

/** @see ReadReservedRegisterFloatingNode */
@NodeInfo(cycles = NodeCycles.CYCLES_0, size = NodeSize.SIZE_0)
public final class ReadReservedRegisterFixedNode extends FixedWithNextNode implements LIRLowerable {
public static final NodeClass<ReadReservedRegisterFixedNode> TYPE = NodeClass.create(ReadReservedRegisterFixedNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package com.oracle.svm.core.graal.nodes;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.ReservedRegisters;
import com.oracle.svm.core.graal.snippets.CEntryPointSnippets;

import jdk.graal.compiler.core.common.LIRKind;
import jdk.graal.compiler.graph.NodeClass;
Expand All @@ -36,6 +38,22 @@
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.vm.ci.code.Register;

/**
* A floating node to read a reserved register, which is more efficient because it allows value
* numbering of multiple accesses, including floating nodes that use it as an input. This is safe
* without explicit dependencies because reserved registers generally contain the same value
* throughout a method's execution.
*
* However, these floating reads are also used in the methods that initialize reserved registers
* when entering an isolate (see {@link CEntryPointSnippets}). We carefully use separate methods and
* prevent inlining to avoid that the compiler can move register reads before their writes.
*
* Also, these nodes must not be used for deoptimization target methods because there is no proxying
* at deoptimization entry points for them, so deoptimization would not restore the values.
*
* @see ReservedRegisters
* @see ReadReservedRegisterFixedNode
*/
@NodeInfo(cycles = NodeCycles.CYCLES_0, size = NodeSize.SIZE_0)
public final class ReadReservedRegisterFloatingNode extends FloatingNode implements LIRLowerable {
public static final NodeClass<ReadReservedRegisterFloatingNode> TYPE = NodeClass.create(ReadReservedRegisterFloatingNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ public final class CEntryPointSnippets extends SubstrateTemplates implements Sni
public static final SubstrateForeignCallDescriptor FAIL_FATALLY = SnippetRuntime.findForeignCall(CEntryPointSnippets.class, "failFatally", HAS_SIDE_EFFECT, LocationIdentity.any());
public static final SubstrateForeignCallDescriptor VERIFY_ISOLATE_THREAD = SnippetRuntime.findForeignCall(CEntryPointSnippets.class, "verifyIsolateThread", HAS_SIDE_EFFECT,
LocationIdentity.any());
public static final SubstrateForeignCallDescriptor INIT_CODE_BASE = SnippetRuntime.findForeignCall(CEntryPointSnippets.class, "initCodeBase", HAS_SIDE_EFFECT, LocationIdentity.any());

public static final SubstrateForeignCallDescriptor[] FOREIGN_CALLS = {CREATE_ISOLATE, INITIALIZE_ISOLATE, ATTACH_THREAD, ENSURE_JAVA_THREAD, ENTER_BY_ISOLATE,
DETACH_CURRENT_THREAD, REPORT_EXCEPTION, TEAR_DOWN_ISOLATE, IS_ATTACHED, FAIL_FATALLY, VERIFY_ISOLATE_THREAD};
DETACH_CURRENT_THREAD, REPORT_EXCEPTION, TEAR_DOWN_ISOLATE, IS_ATTACHED, FAIL_FATALLY, VERIFY_ISOLATE_THREAD, INIT_CODE_BASE};

@NodeIntrinsic(value = ForeignCallNode.class)
public static native int runtimeCall(@ConstantNodeParameter ForeignCallDescriptor descriptor, CEntryPointCreateIsolateParameters parameters);
Expand All @@ -185,9 +186,6 @@ public final class CEntryPointSnippets extends SubstrateTemplates implements Sni
@NodeIntrinsic(value = ForeignCallNode.class)
public static native int runtimeCallInitializeIsolate(@ConstantNodeParameter ForeignCallDescriptor descriptor, CEntryPointCreateIsolateParameters parameters);

@NodeIntrinsic(value = ForeignCallNode.class)
public static native int runtimeCallTearDownIsolate(@ConstantNodeParameter ForeignCallDescriptor descriptor);

@NodeIntrinsic(value = ForeignCallNode.class)
public static native boolean runtimeCallIsAttached(@ConstantNodeParameter ForeignCallDescriptor descriptor, Isolate isolate);

Expand All @@ -197,6 +195,9 @@ public final class CEntryPointSnippets extends SubstrateTemplates implements Sni
@NodeIntrinsic(value = ForeignCallNode.class)
public static native void runtimeCallFailFatally(@ConstantNodeParameter ForeignCallDescriptor descriptor, int code, CCharPointer message);

@NodeIntrinsic(value = ForeignCallNode.class)
public static native void runtimeCallInitCodeBase(@ConstantNodeParameter ForeignCallDescriptor descriptor);

@Fold
static boolean hasHeapBase() {
return ImageSingletons.lookup(CompressEncoding.class).hasBase();
Expand All @@ -210,8 +211,13 @@ private static void setHeapBase(PointerBase heapBase) {
}
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE)
@NeverInline("Heap base register is set in caller, prevent reads from floating before that.")
/**
* Initializes the code base register, which accesses the heap using the heap base register. To
* prevent the compiler from moving reads from this method to before the heap base register is
* initialized in a caller, this method is a foreign call target that does not get inlined.
*/
@SubstrateForeignCallTarget(stubCallingConvention = false)
@Uninterruptible(reason = "Thread state not yet set up.")
private static void initCodeBase() {
CodePointer codeBase;
if (ImageLayerBuildingSupport.buildingImageLayer()) {
Expand Down Expand Up @@ -243,7 +249,7 @@ public static void earlyInitHeapBase(PointerBase heapBase) {
public static void initBaseRegisters(PointerBase heapBase) {
setHeapBase(heapBase);
if (SubstrateOptions.useRelativeCodePointers()) {
initCodeBase();
runtimeCallInitCodeBase(INIT_CODE_BASE);
}
}

Expand Down Expand Up @@ -683,7 +689,7 @@ private static int detachCurrentThread() {

@Snippet(allowMissingProbabilities = true)
public static int tearDownIsolateSnippet() {
return runtimeCallTearDownIsolate(TEAR_DOWN_ISOLATE);
return runtimeCall(TEAR_DOWN_ISOLATE);
}

@SubstrateForeignCallTarget(stubCallingConvention = false)
Expand Down