8144944: JVMCI compiler initialization can happen on different thread than JVMCI initialization
Reviewed-by: twisti
This commit is contained in:
parent
4d4c7ad974
commit
bbc34efe26
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package jdk.vm.ci.inittimer;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A facility for timing a step in the runtime initialization sequence. This is independent from all
|
||||
* other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the
|
||||
@ -32,18 +34,26 @@ public final class InitTimer implements AutoCloseable {
|
||||
final long start;
|
||||
|
||||
private InitTimer(String name) {
|
||||
int n = nesting.getAndIncrement();
|
||||
if (n == 0) {
|
||||
initializingThread = Thread.currentThread();
|
||||
System.out.println("INITIALIZING THREAD: " + initializingThread);
|
||||
} else {
|
||||
assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
|
||||
}
|
||||
this.name = name;
|
||||
this.start = System.currentTimeMillis();
|
||||
System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name);
|
||||
assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
|
||||
timerDepth++;
|
||||
System.out.println("START: " + SPACES.substring(0, n * 2) + name);
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field")
|
||||
public void close() {
|
||||
final long end = System.currentTimeMillis();
|
||||
timerDepth--;
|
||||
System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]");
|
||||
int n = nesting.decrementAndGet();
|
||||
System.out.println(" DONE: " + SPACES.substring(0, n * 2) + name + " [" + (end - start) + " ms]");
|
||||
if (n == 0) {
|
||||
initializingThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static InitTimer timer(String name) {
|
||||
@ -59,19 +69,11 @@ public final class InitTimer implements AutoCloseable {
|
||||
*/
|
||||
private static final boolean ENABLED = Boolean.getBoolean("jvmci.inittimer") || Boolean.getBoolean("jvmci.runtime.TimeInit");
|
||||
|
||||
public static int timerDepth = 0;
|
||||
public static final AtomicInteger nesting = ENABLED ? new AtomicInteger() : null;
|
||||
public static final String SPACES = " ";
|
||||
|
||||
/**
|
||||
* Used to assert the invariant that all initialization happens on the same thread.
|
||||
* Used to assert the invariant that all related initialization happens on the same thread.
|
||||
*/
|
||||
public static final Thread initializingThread;
|
||||
static {
|
||||
if (ENABLED) {
|
||||
initializingThread = Thread.currentThread();
|
||||
System.out.println("INITIALIZING THREAD: " + initializingThread);
|
||||
} else {
|
||||
initializingThread = null;
|
||||
}
|
||||
}
|
||||
public static Thread initializingThread;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user