# HG changeset patch # User Doug Simon # Date 1401026115 -7200 # Node ID 839cb35354e85663e6f60832a766b0671065d5a9 # Parent 079229f002a32bf2f77ecd27937d13adad3dc44b added timers for Graal runtime initialization steps (enabled with -Dgraal.runtime.TimeInit=true) diff -r 079229f002a3 -r 839cb35354e8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- 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.")) { + // ... 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"); } diff -r 079229f002a3 -r 839cb35354e8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java --- 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 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 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()) { diff -r 079229f002a3 -r 839cb35354e8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- 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;