Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][GR-55709] Adapt fibers changes: use JavaThread::_lock_id as monitor owner. #9366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -276,6 +276,8 @@ public final int arrayOopDescLengthOffset() {
public final int threadCarrierThreadObjectOffset = getFieldOffset("JavaThread::_threadObj", Integer.class, "OopHandle");
public final int threadScopedValueCacheOffset = getFieldOffset("JavaThread::_scopedValueCache", Integer.class, "OopHandle");

public final int javaThreadLockIDOffset = getFieldOffset("JavaThread::_lock_id", Integer.class, "int64_t", -1, JDK >= 24);

public final int threadIsInVTMSTransitionOffset = getFieldOffset("JavaThread::_is_in_VTMS_transition", Integer.class, "bool");
public final int threadIsInTmpVTMSTransitionOffset = getFieldOffset("JavaThread::_is_in_tmp_VTMS_transition", Integer.class, "bool");
public final int threadIsDisableSuspendOffset = getFieldOffset("JavaThread::_is_disable_suspend", Integer.class, "bool", -1, JDK >= 22);
Expand Down Expand Up @@ -351,13 +353,15 @@ public int threadLastJavaFpOffset() {
public final int ageMaskInPlace = getConstant("markWord::age_mask_in_place", Integer.class);
public final int unlockedMask = getConstant("markWord::unlocked_value", Integer.class);
public final int monitorMask = getConstant("markWord::monitor_value", Integer.class);
public final int unusedMark = getConstant("markWord::marked_value", Integer.class);

// This field has no type in vmStructs.cpp
public final int objectMonitorOwner = getFieldOffset("ObjectMonitor::_owner", Integer.class, null);
public final int objectMonitorRecursions = getFieldOffset("ObjectMonitor::_recursions", Integer.class, "intptr_t");
public final int objectMonitorCxq = getFieldOffset("ObjectMonitor::_cxq", Integer.class, "ObjectWaiter*");
public final int objectMonitorEntryList = getFieldOffset("ObjectMonitor::_EntryList", Integer.class, "ObjectWaiter*");
public final int objectMonitorSucc = getFieldOffset("ObjectMonitor::_succ", Integer.class, "JavaThread*");
public final int objectMonitorStackLocker = getFieldOffset("ObjectMonitor::_stack_locker", Integer.class, "BasicLock*");

public final long objectMonitorAnonymousOwner = getConstant("ObjectMonitor::ANONYMOUS_OWNER", Long.class, 1L, JDK >= 22);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static jdk.graal.compiler.hotspot.HotSpotBackend.SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_UNMOUNT;
import static jdk.graal.compiler.hotspot.HotSpotBackend.UPDATE_BYTES_CRC32;
import static jdk.graal.compiler.hotspot.HotSpotBackend.UPDATE_BYTES_CRC32C;
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.JAVA_THREAD_LOCK_ID_LOCATION;
import static jdk.graal.compiler.java.BytecodeParserOptions.InlineDuringParsing;
import static jdk.graal.compiler.nodes.ConstantNode.forBoolean;
import static jdk.graal.compiler.nodes.extended.BranchProbabilityNode.NOT_FREQUENT_PROBABILITY;
Expand Down Expand Up @@ -848,6 +849,22 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
}
});
}

if (JavaVersionUtil.JAVA_SPEC >= 24) {
r.register(new InvocationPlugin("setLockId", Receiver.class, long.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode tid) {
try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) {
ValueNode nonNullReceiver = receiver.get(true);
GraalError.guarantee(config.javaThreadLockIDOffset != -1, "JavaThread::_lock_id is not exported");
CurrentJavaThreadNode javaThread = b.add(new CurrentJavaThreadNode(helper.getWordKind()));
OffsetAddressNode address = b.add(new OffsetAddressNode(javaThread, helper.asWord(config.javaThreadLockIDOffset)));
b.add(new JavaWriteNode(JavaKind.Long, address, JAVA_THREAD_LOCK_ID_LOCATION, tid, BarrierType.NONE, false));
}
return true;
}
});
}
}

private static ResolvedJavaType resolveTypeAESCrypt(ResolvedJavaType context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import jdk.graal.compiler.nodes.type.StampTool;
import jdk.graal.compiler.replacements.ReplacementsUtil;
import jdk.graal.compiler.replacements.nodes.ReadRegisterNode;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.graal.compiler.word.Word;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
Expand Down Expand Up @@ -296,6 +297,8 @@ public static Object getPendingException(Word thread) {

public static final LocationIdentity JAVA_THREAD_CARRIER_THREAD_OBJECT_LOCATION = NamedLocationIdentity.mutable("JavaThread::_threadObj");

public static final LocationIdentity JAVA_THREAD_LOCK_ID_LOCATION = NamedLocationIdentity.mutable("JavaThread::_lock_id");

public static final LocationIdentity JAVA_THREAD_OSTHREAD_LOCATION = NamedLocationIdentity.mutable("JavaThread::_osthread");

public static final LocationIdentity JAVA_THREAD_HOLD_MONITOR_COUNT_LOCATION = NamedLocationIdentity.mutable("JavaThread::_held_monitor_count");
Expand Down Expand Up @@ -353,6 +356,11 @@ public ValueNode canonicalizeRead(ValueNode read, ValueNode object, ValueNode lo
}
};

@Fold
public static boolean isJDK21() {
return JavaVersionUtil.JAVA_SPEC == 21;
}

@Fold
public static int allocatePrefetchStyle(@InjectedParameter GraalHotSpotVMConfig config) {
return config.allocatePrefetchStyle;
Expand Down Expand Up @@ -490,6 +498,11 @@ public static int monitorMask(@InjectedParameter GraalHotSpotVMConfig config) {
return config.monitorMask;
}

@Fold
public static int unusedMark(@InjectedParameter GraalHotSpotVMConfig config) {
return config.unusedMark;
}

@Fold
public static int objectMonitorOwnerOffset(@InjectedParameter GraalHotSpotVMConfig config) {
return config.objectMonitorOwner;
Expand Down Expand Up @@ -520,6 +533,11 @@ public static int objectMonitorSuccOffset(@InjectedParameter GraalHotSpotVMConfi
return config.objectMonitorSucc;
}

@Fold
public static int objectMonitorStackLockerOffset(@InjectedParameter GraalHotSpotVMConfig config) {
return config.objectMonitorStackLocker;
}

/**
* Mask for a biasable, locked or unlocked mark word. It is the least significant 3 bits prior
* to Java 18 (1 bit for biased locking and 2 bits for stack locking or heavy locking), and 2
Expand Down Expand Up @@ -665,6 +683,8 @@ public static int secondarySupersOffset(@InjectedParameter GraalHotSpotVMConfig

public static final LocationIdentity OBJECT_MONITOR_SUCC_LOCATION = NamedLocationIdentity.mutable("ObjectMonitor::_succ");

public static final LocationIdentity OBJECT_MONITOR_STACK_LOCKER_LOCATION = NamedLocationIdentity.mutable("ObjectMonitor::_stack_locker");

@Fold
public static int lockDisplacedMarkOffset(@InjectedParameter GraalHotSpotVMConfig config) {
return config.basicLockDisplacedHeaderOffset;
Expand All @@ -675,6 +695,11 @@ static int heldMonitorCountOffset(@InjectedParameter GraalHotSpotVMConfig config
return config.threadHeldMonitorCountOffset;
}

@Fold
static int javaThreadLockIDOffset(@InjectedParameter GraalHotSpotVMConfig config) {
return config.javaThreadLockIDOffset;
}

@Fold
static int javaThreadLockStackTopOffset(@InjectedParameter GraalHotSpotVMConfig config) {
return config.threadLockStackOffset + config.lockStackTopOffset;
Expand Down
Loading
Loading