changeset 15893:839cb35354e8

added timers for Graal runtime initialization steps (enabled with -Dgraal.runtime.TimeInit=true)
author Doug Simon <doug.simon@oracle.com>
date Sun, 25 May 2014 15:55:15 +0200
parents 079229f002a3
children a9810ed7cad2
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java
diffstat 3 files changed, 76 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Sat May 24 10:48:18 2014 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Sun May 25 15:55:15 2014 +0200
@@ -25,6 +25,7 @@
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 import static com.oracle.graal.compiler.common.UnsafeAccess.*;
 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.Options.*;
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.InitTimer.*;
 import static sun.reflect.Reflection.*;
 
 import java.lang.reflect.*;
@@ -41,6 +42,7 @@
 import com.oracle.graal.api.runtime.*;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.target.*;
+import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.bridge.*;
 import com.oracle.graal.hotspot.events.*;
@@ -56,6 +58,37 @@
  */
 public final class HotSpotGraalRuntime implements GraalRuntime, RuntimeProvider, StackIntrospection {
 
+    /**
+     * A facility for timing a step in the initialization sequence for the runtime. This exists
+     * separate from {@link DebugTimer} as it must be independent from all other Graal code so as to
+     * not perturb the initialization sequence.
+     */
+    public static class InitTimer implements AutoCloseable {
+        final String name;
+        final long start;
+
+        private InitTimer(String name) {
+            this.name = name;
+            this.start = System.currentTimeMillis();
+            System.out.println("START INIT: " + name);
+        }
+
+        public void close() {
+            final long end = System.currentTimeMillis();
+            System.out.println(" DONE INIT: " + name + " [" + (end - start) + " ms]");
+        }
+
+        public static InitTimer timer(String name) {
+            return ENABLED ? new InitTimer(name) : null;
+        }
+
+        /**
+         * Specified initialization timing is enabled. This must only be set via a system property
+         * as the timing facility is used to time initialization of {@link HotSpotOptions}.
+         */
+        private static final boolean ENABLED = Boolean.getBoolean("graal.runtime.TimeInit");
+    }
+
     private static final HotSpotGraalRuntime instance;
 
     /**
@@ -64,16 +97,24 @@
     private static native void init(Class<?> compilerToVMClass);
 
     static {
-        init(CompilerToVMImpl.class);
+        try (InitTimer t = timer("initialize natives")) {
+            init(CompilerToVMImpl.class);
+        }
 
-        // The options must be processed before any code using them...
-        HotSpotOptions.initialize();
+        try (InitTimer t = timer("initialize HotSpotOptions")) {
+            // The options must be processed before any code using them...
+            HotSpotOptions.initialize();
+        }
 
-        // ... including code in the constructor
-        instance = new HotSpotGraalRuntime();
+        try (InitTimer t = timer("HotSpotGraalRuntime.<init>")) {
+            // ... including code in the constructor
+            instance = new HotSpotGraalRuntime();
+        }
 
-        // Why deferred initialization? See comment in completeInitialization().
-        instance.completeInitialization();
+        try (InitTimer t = timer("HotSpotGraalRuntime.completeInitialization")) {
+            // Why deferred initialization? See comment in completeInitialization().
+            instance.completeInitialization();
+        }
 
         registerFieldsToFilter(HotSpotGraalRuntime.class, "instance");
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java	Sat May 24 10:48:18 2014 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java	Sun May 25 15:55:15 2014 +0200
@@ -23,6 +23,7 @@
 package com.oracle.graal.hotspot;
 
 import static com.oracle.graal.compiler.common.GraalOptions.*;
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.InitTimer.*;
 
 import java.util.*;
 
@@ -30,6 +31,7 @@
 import com.oracle.graal.compiler.target.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.debug.Debug.Scope;
+import com.oracle.graal.hotspot.HotSpotGraalRuntime.InitTimer;
 import com.oracle.graal.hotspot.meta.*;
 import com.oracle.graal.hotspot.stubs.*;
 import com.oracle.graal.nodes.spi.*;
@@ -65,16 +67,23 @@
         HotSpotVMConfig config = getRuntime().getConfig();
         HotSpotHostForeignCallsProvider foreignCalls = (HotSpotHostForeignCallsProvider) providers.getForeignCalls();
         final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer();
-        foreignCalls.initialize(providers, config);
-        lowerer.initialize(providers, config);
+
+        try (InitTimer st = timer("foreignCalls.initialize")) {
+            foreignCalls.initialize(providers, config);
+        }
+        try (InitTimer st = timer("lowerer.initialize")) {
+            lowerer.initialize(providers, config);
+        }
         HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements();
 
         // Install intrinsics.
         if (Intrinsify.getValue()) {
             try (Scope s = Debug.scope("RegisterReplacements", new DebugDumpScope("RegisterReplacements"))) {
-                ServiceLoader<ReplacementsProvider> sl = ServiceLoader.loadInstalled(ReplacementsProvider.class);
-                for (ReplacementsProvider replacementsProvider : sl) {
-                    replacementsProvider.registerReplacements(providers.getMetaAccess(), lowerer, providers.getSnippetReflection(), replacements, providers.getCodeCache().getTarget());
+                try (InitTimer st = timer("replacementsProviders.registerReplacements")) {
+                    ServiceLoader<ReplacementsProvider> sl = ServiceLoader.loadInstalled(ReplacementsProvider.class);
+                    for (ReplacementsProvider replacementsProvider : sl) {
+                        replacementsProvider.registerReplacements(providers.getMetaAccess(), lowerer, providers.getSnippetReflection(), replacements, providers.getCodeCache().getTarget());
+                    }
                 }
                 if (BootstrapReplacements.getValue()) {
                     for (ResolvedJavaMethod method : replacements.getAllReplacements()) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Sat May 24 10:48:18 2014 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Sun May 25 15:55:15 2014 +0200
@@ -24,6 +24,7 @@
 
 import static com.oracle.graal.compiler.GraalDebugConfig.*;
 import static com.oracle.graal.hotspot.CompileTheWorld.Options.*;
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.InitTimer.*;
 
 import java.io.*;
 import java.lang.reflect.*;
@@ -40,6 +41,7 @@
 import com.oracle.graal.hotspot.*;
 import com.oracle.graal.hotspot.CompilationTask.Enqueueing;
 import com.oracle.graal.hotspot.CompileTheWorld.Config;
+import com.oracle.graal.hotspot.HotSpotGraalRuntime.InitTimer;
 import com.oracle.graal.hotspot.debug.*;
 import com.oracle.graal.hotspot.meta.*;
 import com.oracle.graal.java.*;
@@ -191,10 +193,14 @@
         assert VerifyOptionsPhase.checkOptions(hostProviders.getMetaAccess());
 
         // Complete initialization of backends
-        hostBackend.completeInitialization();
+        try (InitTimer st = timer(hostBackend.getClass().getSimpleName() + ".completeInitialization")) {
+            hostBackend.completeInitialization();
+        }
         for (HotSpotBackend backend : runtime.getBackends().values()) {
             if (backend != hostBackend) {
-                backend.completeInitialization();
+                try (InitTimer st = timer(backend.getClass().getSimpleName() + ".completeInitialization")) {
+                    backend.completeInitialization();
+                }
             }
         }
 
@@ -204,6 +210,12 @@
     }
 
     public void startCompiler(boolean bootstrapEnabled) throws Throwable {
+        try (InitTimer timer = timer("startCompiler")) {
+            startCompiler0(bootstrapEnabled);
+        }
+    }
+
+    private void startCompiler0(boolean bootstrapEnabled) throws Throwable {
 
         bootstrapRunning = bootstrapEnabled;