# HG changeset patch # User Doug Simon # Date 1407340144 -7200 # Node ID bb030c4a682233b81e0446926e4a4f7d0cb76039 # Parent e6960ff1f0f631f8e06649e44f1384018b693f66 improvements to MemoryUsageBenchmark diff -r e6960ff1f0f6 -r bb030c4a6822 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Wed Aug 06 17:42:29 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Wed Aug 06 17:49:04 2014 +0200 @@ -26,6 +26,7 @@ import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.nodes.StructuredGraph.*; +import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.internal.*; @@ -46,7 +47,7 @@ return a + b; } - public static int complex(CharSequence cs) { + public static synchronized int complex(CharSequence cs) { if (cs instanceof String) { return cs.hashCode(); } @@ -70,6 +71,18 @@ for (int i = 0; i < cs.length(); i++) { res *= cs.charAt(i); } + + // A fixed length loop with some canonicalizable arithmetics will + // activate loop unrolling and more canonicalization + int sum = 0; + for (int i = 0; i < 5; i++) { + sum += i * 2; + } + res += sum; + + // Activates escape-analysis + res += new String("asdf").length(); + return res; } @@ -92,6 +105,10 @@ } public static void main(String[] args) { + // Ensure a Graal runtime is initialized prior to Debug being initialized as the former + // may include processing command line options used by the latter. + Graal.getRuntime(); + // Ensure a debug configuration for this thread is initialized if (Debug.isEnabled() && DebugScope.getConfig() == null) { DebugEnvironment.initialize(System.out); @@ -102,18 +119,23 @@ private void doCompilation(String methodName) { HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) getMetaAccess().lookupJavaMethod(getMethod(methodName)); HotSpotBackend backend = runtime().getHostBackend(); + + // invalidate any existing compiled code + method.reprofile(); + int id = method.allocateCompileId(INVOCATION_ENTRY_BCI); long ctask = 0L; CompilationTask task = new CompilationTask(backend, method, INVOCATION_ENTRY_BCI, ctask, id); task.runCompilation(); - - // invalidate the compiled code - method.reprofile(); } private static final boolean verbose = Boolean.getBoolean("verbose"); private void compileAndTime(String methodName) { + + // Parse in eager mode to resolve methods/fields/classes + parseEager(methodName); + // Warm up and initialize compiler phases used by this compilation for (int i = 0; i < 10; i++) { try (MemoryUsageCloseable c = verbose ? new MemoryUsageCloseable(methodName + "[" + i + "]") : null) {