changeset 22007:4ad715543ea2

Gracefully disable allocation counters when management interface can't be loaded.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 18 Jun 2015 11:52:22 +0200
parents 985f49785f06
children 9be89636defe
files jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java	Thu Jun 18 09:59:29 2015 +0200
+++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java	Thu Jun 18 11:52:22 2015 +0200
@@ -54,6 +54,14 @@
         } else {
             eventProvider = provider;
         }
+
+        com.sun.management.ThreadMXBean bean;
+        try {
+            bean = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean();
+        } catch (UnsatisfiedLinkError err) {
+            bean = null;
+        }
+        threadMXBean = bean;
     }
     private static final Compiler compiler = Services.loadSingle(Compiler.class, true);
 
@@ -71,7 +79,7 @@
      * 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) ManagementFactory.getThreadMXBean();
+    private static final com.sun.management.ThreadMXBean threadMXBean;
 
     /**
      * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists.
@@ -142,7 +150,7 @@
 
             TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method);
             final long start = System.currentTimeMillis();
-            final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId);
+            final long allocatedBytesBefore = threadMXBean == null ? 0 : threadMXBean.getThreadAllocatedBytes(threadId);
 
             try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) {
                 // Begin the compilation event.
@@ -163,7 +171,7 @@
                 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 = threadMXBean == null ? 0 : threadMXBean.getThreadAllocatedBytes(threadId);
                     final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024;
 
                     if (printAfterCompilation) {