changeset 35104:8c21f17b63e0

8144944: JVMCI compiler initialization can happen on different thread than JVMCI initialization Reviewed-by: twisti
author dnsimon
date Wed, 09 Dec 2015 22:57:52 +0100
parents d19354bcbfa6
children dd35f17e611d
files hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.inittimer/src/jdk/vm/ci/inittimer/InitTimer.java
diffstat 1 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.inittimer/src/jdk/vm/ci/inittimer/InitTimer.java	Wed Dec 09 14:54:40 2015 +0100
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.inittimer/src/jdk/vm/ci/inittimer/InitTimer.java	Wed Dec 09 22:57:52 2015 +0100
@@ -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 @@
     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 @@
      */
     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;
 }