< prev index next >
src/java.management/share/classes/sun/management/ThreadImpl.java
Print this page
*** 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() {
--- 110,128 ----
"Thread CPU time measurement is not supported");
}
return cpuTimeEnabled;
}
! private void throwIfThreadAllocatedMemoryNotSupported() {
if (!isThreadAllocatedMemorySupported()) {
throw new UnsupportedOperationException(
! "Thread allocated memory measurement is not supported.");
! }
}
+
+ protected boolean isThreadAllocatedMemoryEnabled() {
+ throwIfThreadAllocatedMemoryNotSupported();
return allocatedMemoryEnabled;
}
@Override
public long[] getAllThreadIds() {
*** 153,173 ****
@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) {
verifyThreadIds(ids);
--- 157,185 ----
@Override
public ThreadInfo[] getThreadInfo(long[] ids) {
return getThreadInfo(ids, 0);
}
! private void throwIfNullThreadIds(long[] ids) {
if (ids == null) {
throw new NullPointerException("Null ids parameter.");
}
+ }
! private void verifyThreadId(long id) {
! if (id <= 0) {
throw new IllegalArgumentException(
! "Invalid thread ID parameter: " + id);
}
}
+
+ private void verifyThreadIds(long[] ids) {
+ throwIfNullThreadIds(ids);
+
+ for (int i = 0; i < ids.length; i++) {
+ verifyThreadId(ids[i]);
+ }
}
@Override
public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
verifyThreadIds(ids);
*** 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);
--- 352,396 ----
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) {
+ throwIfNullThreadIds(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
--- 399,409 ----
}
return sizes;
}
protected void setThreadAllocatedMemoryEnabled(boolean enable) {
! throwIfThreadAllocatedMemoryNotSupported();
Util.checkControlAccess();
synchronized (this) {
if (allocatedMemoryEnabled != enable) {
// notify VM of the state change
*** 509,518 ****
--- 533,543 ----
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 >