# HG changeset patch # User Roland Schatz # Date 1434639000 -7200 # Node ID 9be89636defe8656785c00bc3e55d19b08ea9ca2 # Parent 4ad715543ea24351c6576c0e01cc51439601c8d9 Use dummy ThreadMXBean when ManagementFactory can't be linked. diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java --- a/jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java Thu Jun 18 11:52:22 2015 +0200 +++ b/jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugTimerTest.java Thu Jun 18 16:50:00 2015 +0200 @@ -32,7 +32,12 @@ public class DebugTimerTest { - private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + private static final ThreadMXBean threadMXBean = Management.getThreadMXBean(); + + @Before + public void checkCaps() { + Assume.assumeTrue("skipping management interface test", threadMXBean.isCurrentThreadCpuTimeSupported()); + } /** * Actively spins the current thread for at least a given number of milliseconds in such a way diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Management.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/Management.java Thu Jun 18 16:50:00 2015 +0200 @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.debug; + +import java.lang.management.*; + +import javax.management.*; + +public class Management { + + public static ThreadMXBean getThreadMXBean() { + try { + return ManagementFactory.getThreadMXBean(); + } catch (Error err) { + return new UnimplementedBean(); + } + } + + private static class UnimplementedBean implements ThreadMXBean, com.sun.management.ThreadMXBean { + + public ObjectName getObjectName() { + return null; + } + + public long getThreadAllocatedBytes(long arg0) { + return 0; + } + + public long[] getThreadAllocatedBytes(long[] arg0) { + return null; + } + + public long[] getThreadCpuTime(long[] arg0) { + return null; + } + + public long[] getThreadUserTime(long[] arg0) { + return null; + } + + public boolean isThreadAllocatedMemoryEnabled() { + return false; + } + + public boolean isThreadAllocatedMemorySupported() { + return false; + } + + public void setThreadAllocatedMemoryEnabled(boolean arg0) { + } + + public int getThreadCount() { + return 0; + } + + public int getPeakThreadCount() { + return 0; + } + + public long getTotalStartedThreadCount() { + return 0; + } + + public int getDaemonThreadCount() { + return 0; + } + + public long[] getAllThreadIds() { + return null; + } + + public ThreadInfo getThreadInfo(long id) { + return null; + } + + public ThreadInfo[] getThreadInfo(long[] ids) { + return null; + } + + public ThreadInfo getThreadInfo(long id, int maxDepth) { + return null; + } + + public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) { + return null; + } + + public boolean isThreadContentionMonitoringSupported() { + return false; + } + + public boolean isThreadContentionMonitoringEnabled() { + return false; + } + + public void setThreadContentionMonitoringEnabled(boolean enable) { + } + + public long getCurrentThreadCpuTime() { + return 0; + } + + public long getCurrentThreadUserTime() { + return 0; + } + + public long getThreadCpuTime(long id) { + return 0; + } + + public long getThreadUserTime(long id) { + return 0; + } + + public boolean isThreadCpuTimeSupported() { + return false; + } + + public boolean isCurrentThreadCpuTimeSupported() { + return false; + } + + public boolean isThreadCpuTimeEnabled() { + return false; + } + + public void setThreadCpuTimeEnabled(boolean enable) { + } + + public long[] findMonitorDeadlockedThreads() { + return null; + } + + public void resetPeakThreadCount() { + } + + public long[] findDeadlockedThreads() { + return null; + } + + public boolean isObjectMonitorUsageSupported() { + return false; + } + + public boolean isSynchronizerUsageSupported() { + return false; + } + + public ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors, boolean lockedSynchronizers) { + return null; + } + + public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers) { + return null; + } + } +} diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java --- a/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java Thu Jun 18 11:52:22 2015 +0200 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/MemUseTrackerImpl.java Thu Jun 18 16:50:00 2015 +0200 @@ -25,14 +25,12 @@ import static com.oracle.jvmci.debug.DebugCloseable.*; import static java.lang.Thread.*; -import java.lang.management.*; - import com.oracle.jvmci.debug.*; -import com.sun.management.ThreadMXBean; +import com.sun.management.*; public final class MemUseTrackerImpl extends AccumulatedDebugValue implements DebugMemUseTracker { - private static final ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); + private static final ThreadMXBean threadMXBean = (ThreadMXBean) Management.getThreadMXBean(); /** * The amount of memory allocated by {@link ThreadMXBean#getThreadAllocatedBytes(long)} itself. diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java --- a/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java Thu Jun 18 11:52:22 2015 +0200 +++ b/jvmci/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/TimerImpl.java Thu Jun 18 16:50:00 2015 +0200 @@ -31,7 +31,7 @@ public final class TimerImpl extends AccumulatedDebugValue implements DebugTimer { - private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + private static final ThreadMXBean threadMXBean = Management.getThreadMXBean(); /** * Records the most recent active timer. diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java --- a/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java Thu Jun 18 11:52:22 2015 +0200 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationStatistics.java Thu Jun 18 16:50:00 2015 +0200 @@ -26,12 +26,12 @@ import java.io.*; import java.lang.annotation.*; -import java.lang.management.*; import java.lang.reflect.*; import java.util.*; import java.util.concurrent.*; -import com.sun.management.ThreadMXBean; +import com.oracle.jvmci.debug.*; +import com.sun.management.*; @SuppressWarnings("unused") public final class CompilationStatistics { @@ -64,7 +64,7 @@ private static long zeroTime = System.nanoTime(); private static long getThreadAllocatedBytes() { - ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean(); + ThreadMXBean thread = (ThreadMXBean) Management.getThreadMXBean(); return thread.getThreadAllocatedBytes(currentThread().getId()); } diff -r 4ad715543ea2 -r 9be89636defe jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java --- a/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java Thu Jun 18 11:52:22 2015 +0200 +++ b/jvmci/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilationTask.java Thu Jun 18 16:50:00 2015 +0200 @@ -23,10 +23,9 @@ package com.oracle.jvmci.hotspot; import static com.oracle.jvmci.common.UnsafeAccess.*; +import static com.oracle.jvmci.compiler.Compiler.*; import static com.oracle.jvmci.debug.Debug.*; -import static com.oracle.jvmci.compiler.Compiler.*; -import java.lang.management.*; import java.util.concurrent.*; import com.oracle.jvmci.code.*; @@ -54,14 +53,6 @@ } 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); @@ -79,7 +70,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; + private 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. @@ -150,7 +141,7 @@ TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); final long start = System.currentTimeMillis(); - final long allocatedBytesBefore = threadMXBean == null ? 0 : threadMXBean.getThreadAllocatedBytes(threadId); + final long allocatedBytesBefore = threadMXBean.getThreadAllocatedBytes(threadId); try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { // Begin the compilation event. @@ -171,7 +162,7 @@ if (printAfterCompilation || printCompilation) { final long stop = System.currentTimeMillis(); final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1; - final long allocatedBytesAfter = threadMXBean == null ? 0 : threadMXBean.getThreadAllocatedBytes(threadId); + final long allocatedBytesAfter = threadMXBean.getThreadAllocatedBytes(threadId); final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024; if (printAfterCompilation) {