Skip to content

Commit 9da64df

Browse files
[GR-64664] Fix JFR epoch id.
PullRequest: graal/20691
2 parents f86bce8 + c58343e commit 9da64df

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/traceid/JfrTraceIdEpoch.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.graalvm.nativeimage.Platforms;
3131

3232
import com.oracle.svm.core.Uninterruptible;
33+
import com.oracle.svm.core.thread.Target_java_lang_VirtualThread;
3334
import com.oracle.svm.core.thread.VMOperation;
3435

3536
import jdk.graal.compiler.api.replacements.Fold;
@@ -43,7 +44,12 @@ public class JfrTraceIdEpoch {
4344
private static final long EPOCH_0_BIT = 0b01;
4445
private static final long EPOCH_1_BIT = 0b10;
4546

46-
private long epochId;
47+
/**
48+
* Start the epoch id at 1, so that we can inject fields into JDK classes that store the epoch
49+
* id (see for example {@link Target_java_lang_VirtualThread#jfrEpochId}). This avoids problems
50+
* with uninitialized injected fields that have the value 0 by default.
51+
*/
52+
private long epochId = 1;
4753

4854
@Fold
4955
public static JfrTraceIdEpoch getInstance() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public final class Target_java_lang_VirtualThread {
123123
// Checkstyle: resume
124124

125125
@Inject //
126-
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ResetToMinusOneTransformer.class) //
127-
public long jfrEpochId = -1;
126+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) //
127+
public long jfrEpochId;
128128

129129
@Alias
130130
private static native ForkJoinPool createDefaultScheduler();
@@ -602,10 +602,3 @@ static Thread asThread(Object obj) {
602602
private VirtualThreadHelper() {
603603
}
604604
}
605-
606-
final class ResetToMinusOneTransformer implements FieldValueTransformer {
607-
@Override
608-
public Object transform(Object receiver, Object originalValue) {
609-
return -1L;
610-
}
611-
}

0 commit comments

Comments
 (0)