changeset 16773:b359f0468128

added AllocSpy-based memory usage benchmarking
author Doug Simon <doug.simon@oracle.com>
date Mon, 11 Aug 2014 16:11:27 +0200
parents 5992012d3bca
children db2ac421649a
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java
diffstat 1 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java	Mon Aug 11 16:10:42 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java	Mon Aug 11 16:11:27 2014 +0200
@@ -127,7 +127,7 @@
         new MemoryUsageBenchmark().run();
     }
 
-    private void doCompilation(String methodName) {
+    private void doCompilation(String methodName, String label) {
         HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) getMetaAccess().lookupJavaMethod(getMethod(methodName));
         HotSpotBackend backend = runtime().getHostBackend();
 
@@ -136,8 +136,28 @@
 
         int id = method.allocateCompileId(INVOCATION_ENTRY_BCI);
         long ctask = 0L;
-        CompilationTask task = new CompilationTask(backend, method, INVOCATION_ENTRY_BCI, ctask, id);
-        task.runCompilation();
+
+        try (MemoryUsageCloseable c = label == null ? null : new MemoryUsageCloseable(label)) {
+            CompilationTask task = new CompilationTask(backend, method, INVOCATION_ENTRY_BCI, ctask, id);
+            task.runCompilation();
+        }
+    }
+
+    private void allocSpyCompilation(String methodName) {
+        if (AllocSpy.isEnabled()) {
+            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;
+            try (AllocSpy as = AllocSpy.open(methodName)) {
+                CompilationTask task = new CompilationTask(backend, method, INVOCATION_ENTRY_BCI, ctask, id);
+                task.runCompilation();
+            }
+        }
     }
 
     private static final boolean verbose = Boolean.getBoolean("verbose");
@@ -149,14 +169,10 @@
 
         // Warm up and initialize compiler phases used by this compilation
         for (int i = 0; i < 10; i++) {
-            try (MemoryUsageCloseable c = verbose ? new MemoryUsageCloseable(methodName + "[warmup-" + i + "]") : null) {
-                doCompilation(methodName);
-            }
+            doCompilation(methodName, verbose ? methodName + "[warmup-" + i + "]" : null);
         }
 
-        try (MemoryUsageCloseable c = new MemoryUsageCloseable(methodName)) {
-            doCompilation(methodName);
-        }
+        doCompilation(methodName, methodName);
     }
 
     public void run() {
@@ -171,5 +187,7 @@
                 e.printStackTrace();
             }
         }
+        allocSpyCompilation("simple");
+        allocSpyCompilation("complex");
     }
 }