< prev index next >

src/java.management/share/classes/sun/management/ThreadImpl.java

Print this page

        

*** 27,36 **** --- 27,37 ---- import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import javax.management.ObjectName; + import java.util.Objects; /** * Implementation for java.lang.management.ThreadMXBean as well as providing the * supporting method for com.sun.management.ThreadMXBean. * The supporting method for com.sun.management.ThreadMXBean can be moved to
*** 110,124 **** "Thread CPU time measurement is not supported"); } return cpuTimeEnabled; } ! protected boolean isThreadAllocatedMemoryEnabled() { if (!isThreadAllocatedMemorySupported()) { throw new UnsupportedOperationException( ! "Thread allocated memory measurement is not supported"); } return allocatedMemoryEnabled; } @Override public long[] getAllThreadIds() { --- 111,129 ---- "Thread CPU time measurement is not supported"); } return cpuTimeEnabled; } ! private void ensureThreadAllocatedMemorySupported() { if (!isThreadAllocatedMemorySupported()) { throw new UnsupportedOperationException( ! "Thread allocated memory measurement is not supported."); ! } } + + protected boolean isThreadAllocatedMemoryEnabled() { + ensureThreadAllocatedMemorySupported(); return allocatedMemoryEnabled; } @Override public long[] getAllThreadIds() {
*** 153,172 **** @Override public ThreadInfo[] getThreadInfo(long[] ids) { return getThreadInfo(ids, 0); } ! private void verifyThreadIds(long[] ids) { ! if (ids == null) { ! throw new NullPointerException("Null ids parameter."); } for (int i = 0; i < ids.length; i++) { ! if (ids[i] <= 0) { ! throw new IllegalArgumentException( ! "Invalid thread ID parameter: " + ids[i]); ! } } } @Override public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) { --- 158,179 ---- @Override public ThreadInfo[] getThreadInfo(long[] ids) { return getThreadInfo(ids, 0); } ! private void verifyThreadId(long id) { ! if (id <= 0) { ! throw new IllegalArgumentException( ! "Invalid thread ID parameter: " + id); ! } } + private void verifyThreadIds(long[] ids) { + Objects.requireNonNull(ids); + for (int i = 0; i < ids.length; i++) { ! verifyThreadId(ids[i]); } } @Override public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
*** 340,369 **** cpuTimeEnabled = enable; } } } ! protected long getThreadAllocatedBytes(long id) { ! long[] ids = new long[1]; ! ids[0] = id; ! final long[] sizes = getThreadAllocatedBytes(ids); ! return sizes[0]; } ! private boolean verifyThreadAllocatedMemory(long[] ids) { ! verifyThreadIds(ids); ! // check if Thread allocated memory measurement is supported. ! if (!isThreadAllocatedMemorySupported()) { ! throw new UnsupportedOperationException( ! "Thread allocated memory measurement is not supported."); } return isThreadAllocatedMemoryEnabled(); } protected long[] getThreadAllocatedBytes(long[] ids) { boolean verified = verifyThreadAllocatedMemory(ids); long[] sizes = new long[ids.length]; java.util.Arrays.fill(sizes, -1); --- 347,391 ---- cpuTimeEnabled = enable; } } } ! protected long getCurrentThreadAllocatedBytes() { ! if (isThreadAllocatedMemoryEnabled()) { ! return getThreadAllocatedMemory0(0); ! } ! return -1; } ! private boolean verifyThreadAllocatedMemory(long id) { ! verifyThreadId(id); ! return isThreadAllocatedMemoryEnabled(); ! } ! protected long getThreadAllocatedBytes(long id) { ! boolean verified = verifyThreadAllocatedMemory(id); ! ! if (verified) { ! return getThreadAllocatedMemory0( ! Thread.currentThread().getId() == id ? 0 : id); ! } ! return -1; } + private boolean verifyThreadAllocatedMemory(long[] ids) { + verifyThreadIds(ids); return isThreadAllocatedMemoryEnabled(); } protected long[] getThreadAllocatedBytes(long[] ids) { + Objects.requireNonNull(ids); + + if (ids.length == 1) { + long size = getThreadAllocatedBytes(ids[0]); + return new long[] { size }; + } + boolean verified = verifyThreadAllocatedMemory(ids); long[] sizes = new long[ids.length]; java.util.Arrays.fill(sizes, -1);
*** 372,385 **** } return sizes; } protected void setThreadAllocatedMemoryEnabled(boolean enable) { ! if (!isThreadAllocatedMemorySupported()) { ! throw new UnsupportedOperationException( ! "Thread allocated memory measurement is not supported."); ! } Util.checkControlAccess(); synchronized (this) { if (allocatedMemoryEnabled != enable) { // notify VM of the state change --- 394,404 ---- } return sizes; } protected void setThreadAllocatedMemoryEnabled(boolean enable) { ! ensureThreadAllocatedMemorySupported(); Util.checkControlAccess(); synchronized (this) { if (allocatedMemoryEnabled != enable) { // notify VM of the state change
*** 509,518 **** --- 528,538 ---- ThreadInfo[] result); private static native long getThreadTotalCpuTime0(long id); private static native void getThreadTotalCpuTime1(long[] ids, long[] result); private static native long getThreadUserCpuTime0(long id); private static native void getThreadUserCpuTime1(long[] ids, long[] result); + private static native long getThreadAllocatedMemory0(long id); private static native void getThreadAllocatedMemory1(long[] ids, long[] result); private static native void setThreadCpuTimeEnabled0(boolean enable); private static native void setThreadAllocatedMemoryEnabled0(boolean enable); private static native void setThreadContentionMonitoringEnabled0(boolean enable); private static native Thread[] findMonitorDeadlockedThreads0();
< prev index next >