changeset 22015:7645c463fb65

only make VM or native calls if the result will actually be used
author Doug Simon <doug.simon@oracle.com>
date Tue, 16 Jun 2015 23:11:26 +0200
parents 35b153c26783
children f2cf8824040b
files jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java	Wed Apr 29 12:23:48 2015 -0700
+++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java	Tue Jun 16 23:11:26 2015 +0200
@@ -66,11 +66,13 @@
      */
     private final boolean installAsDefault;
 
-    /**
-     * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the
-     * current compiler thread, e.g. total allocated bytes.
-     */
-    private static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) Management.getThreadMXBean();
+    static class Lazy {
+        /**
+         * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the
+         * current compiler thread, e.g. total allocated bytes.
+         */
+        static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) Management.getThreadMXBean();
+    }
 
     /**
      * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists.
@@ -135,13 +137,21 @@
         try (DebugCloseable a = CompilationTime.start()) {
             CompilationStatistics stats = CompilationStatistics.create(method, isOSR);
             final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed();
+            final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed();
             if (printCompilation) {
                 TTY.println(getMethodDescription() + "...");
             }
 
             TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method);
-            final long start = System.currentTimeMillis();
-            final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId);
+            final long start;
+            final long allocatedBytesBefore;
+            if (printAfterCompilation || printCompilation) {
+                start = System.currentTimeMillis();
+                allocatedBytesBefore = printAfterCompilation || printCompilation ? Lazy.threadMXBean.getThreadAllocatedBytes(threadId) : 0L;
+            } else {
+                start = 0L;
+                allocatedBytesBefore = 0L;
+            }
 
             try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) {
                 // Begin the compilation event.
@@ -157,12 +167,11 @@
                 compilationEvent.end();
 
                 filter.remove();
-                final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed();
 
                 if (printAfterCompilation || printCompilation) {
                     final long stop = System.currentTimeMillis();
                     final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1;
-                    final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId);
+                    final long allocatedBytesAfter = Lazy.threadMXBean.getThreadAllocatedBytes(threadId);
                     final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024;
 
                     if (printAfterCompilation) {