author | uvangapally |
Thu, 05 Oct 2017 01:31:53 -0700 | |
changeset 47592 | 68d46cb9be45 |
parent 47216 | 71c04702a3d5 |
child 58208 | 0f3c23c374a4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.management; |
|
27 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
28 |
import java.lang.management.ManagementFactory; |
2 | 29 |
import java.lang.management.ThreadInfo; |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
30 |
import java.lang.management.ThreadMXBean; |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
31 |
import javax.management.ObjectName; |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
32 |
|
2 | 33 |
/** |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
34 |
* Implementation for java.lang.management.ThreadMXBean as well as providing the |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
35 |
* supporting method for com.sun.management.ThreadMXBean. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
36 |
* The supporting method for com.sun.management.ThreadMXBean can be moved to |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
37 |
* jdk.management in the future. |
2 | 38 |
*/ |
39 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
40 |
public class ThreadImpl implements ThreadMXBean { |
2 | 41 |
private final VMManagement jvm; |
42 |
||
43 |
// default for thread contention monitoring is disabled. |
|
44 |
private boolean contentionMonitoringEnabled = false; |
|
45 |
private boolean cpuTimeEnabled; |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
46 |
private boolean allocatedMemoryEnabled; |
2 | 47 |
|
48 |
/** |
|
49 |
* Constructor of ThreadImpl class. |
|
50 |
*/ |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
51 |
protected ThreadImpl(VMManagement vm) { |
2 | 52 |
this.jvm = vm; |
53 |
this.cpuTimeEnabled = jvm.isThreadCpuTimeEnabled(); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
54 |
this.allocatedMemoryEnabled = jvm.isThreadAllocatedMemoryEnabled(); |
2 | 55 |
} |
56 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
57 |
@Override |
2 | 58 |
public int getThreadCount() { |
59 |
return jvm.getLiveThreadCount(); |
|
60 |
} |
|
61 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
62 |
@Override |
2 | 63 |
public int getPeakThreadCount() { |
64 |
return jvm.getPeakThreadCount(); |
|
65 |
} |
|
66 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
67 |
@Override |
2 | 68 |
public long getTotalStartedThreadCount() { |
69 |
return jvm.getTotalThreadCount(); |
|
70 |
} |
|
71 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
72 |
@Override |
2 | 73 |
public int getDaemonThreadCount() { |
74 |
return jvm.getDaemonThreadCount(); |
|
75 |
} |
|
76 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
77 |
@Override |
2 | 78 |
public boolean isThreadContentionMonitoringSupported() { |
79 |
return jvm.isThreadContentionMonitoringSupported(); |
|
80 |
} |
|
81 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
82 |
@Override |
2 | 83 |
public synchronized boolean isThreadContentionMonitoringEnabled() { |
84 |
if (!isThreadContentionMonitoringSupported()) { |
|
85 |
throw new UnsupportedOperationException( |
|
86 |
"Thread contention monitoring is not supported."); |
|
87 |
} |
|
88 |
return contentionMonitoringEnabled; |
|
89 |
} |
|
90 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
91 |
@Override |
2 | 92 |
public boolean isThreadCpuTimeSupported() { |
93 |
return jvm.isOtherThreadCpuTimeSupported(); |
|
94 |
} |
|
95 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
96 |
@Override |
2 | 97 |
public boolean isCurrentThreadCpuTimeSupported() { |
98 |
return jvm.isCurrentThreadCpuTimeSupported(); |
|
99 |
} |
|
100 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
101 |
protected boolean isThreadAllocatedMemorySupported() { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
102 |
return jvm.isThreadAllocatedMemorySupported(); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
103 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
104 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
105 |
@Override |
2 | 106 |
public boolean isThreadCpuTimeEnabled() { |
107 |
if (!isThreadCpuTimeSupported() && |
|
108 |
!isCurrentThreadCpuTimeSupported()) { |
|
109 |
throw new UnsupportedOperationException( |
|
110 |
"Thread CPU time measurement is not supported"); |
|
111 |
} |
|
112 |
return cpuTimeEnabled; |
|
113 |
} |
|
114 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
115 |
protected boolean isThreadAllocatedMemoryEnabled() { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
116 |
if (!isThreadAllocatedMemorySupported()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
117 |
throw new UnsupportedOperationException( |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
118 |
"Thread allocated memory measurement is not supported"); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
119 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
120 |
return allocatedMemoryEnabled; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
121 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
122 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
123 |
@Override |
2 | 124 |
public long[] getAllThreadIds() { |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
125 |
Util.checkMonitorAccess(); |
2 | 126 |
|
127 |
Thread[] threads = getThreads(); |
|
128 |
int length = threads.length; |
|
129 |
long[] ids = new long[length]; |
|
130 |
for (int i = 0; i < length; i++) { |
|
131 |
Thread t = threads[i]; |
|
132 |
ids[i] = t.getId(); |
|
133 |
} |
|
134 |
return ids; |
|
135 |
} |
|
136 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
137 |
@Override |
2 | 138 |
public ThreadInfo getThreadInfo(long id) { |
139 |
long[] ids = new long[1]; |
|
140 |
ids[0] = id; |
|
141 |
final ThreadInfo[] infos = getThreadInfo(ids, 0); |
|
142 |
return infos[0]; |
|
143 |
} |
|
144 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
145 |
@Override |
2 | 146 |
public ThreadInfo getThreadInfo(long id, int maxDepth) { |
147 |
long[] ids = new long[1]; |
|
148 |
ids[0] = id; |
|
149 |
final ThreadInfo[] infos = getThreadInfo(ids, maxDepth); |
|
150 |
return infos[0]; |
|
151 |
} |
|
152 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
153 |
@Override |
2 | 154 |
public ThreadInfo[] getThreadInfo(long[] ids) { |
155 |
return getThreadInfo(ids, 0); |
|
156 |
} |
|
157 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
158 |
private void verifyThreadIds(long[] ids) { |
2 | 159 |
if (ids == null) { |
160 |
throw new NullPointerException("Null ids parameter."); |
|
161 |
} |
|
162 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
163 |
for (int i = 0; i < ids.length; i++) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
164 |
if (ids[i] <= 0) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
165 |
throw new IllegalArgumentException( |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
166 |
"Invalid thread ID parameter: " + ids[i]); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
167 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
168 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
169 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
170 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
171 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
172 |
public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
173 |
verifyThreadIds(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
174 |
|
2 | 175 |
if (maxDepth < 0) { |
176 |
throw new IllegalArgumentException( |
|
177 |
"Invalid maxDepth parameter: " + maxDepth); |
|
178 |
} |
|
179 |
||
30348
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
180 |
// ids has been verified to be non-null |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
181 |
// an empty array of ids should return an empty array of ThreadInfos |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
182 |
if (ids.length == 0) return new ThreadInfo[0]; |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
183 |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
184 |
Util.checkMonitorAccess(); |
2 | 185 |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
186 |
ThreadInfo[] infos = new ThreadInfo[ids.length]; // nulls |
2 | 187 |
if (maxDepth == Integer.MAX_VALUE) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
188 |
getThreadInfo1(ids, -1, infos); |
2 | 189 |
} else { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
190 |
getThreadInfo1(ids, maxDepth, infos); |
2 | 191 |
} |
192 |
return infos; |
|
193 |
} |
|
194 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
195 |
@Override |
2 | 196 |
public void setThreadContentionMonitoringEnabled(boolean enable) { |
197 |
if (!isThreadContentionMonitoringSupported()) { |
|
198 |
throw new UnsupportedOperationException( |
|
199 |
"Thread contention monitoring is not supported"); |
|
200 |
} |
|
201 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
202 |
Util.checkControlAccess(); |
2 | 203 |
|
204 |
synchronized (this) { |
|
205 |
if (contentionMonitoringEnabled != enable) { |
|
206 |
if (enable) { |
|
207 |
// if reeabled, reset contention time statistics |
|
208 |
// for all threads |
|
209 |
resetContentionTimes0(0); |
|
210 |
} |
|
211 |
||
212 |
// update the VM of the state change |
|
213 |
setThreadContentionMonitoringEnabled0(enable); |
|
214 |
||
215 |
contentionMonitoringEnabled = enable; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
220 |
private boolean verifyCurrentThreadCpuTime() { |
2 | 221 |
// check if Thread CPU time measurement is supported. |
222 |
if (!isCurrentThreadCpuTimeSupported()) { |
|
223 |
throw new UnsupportedOperationException( |
|
224 |
"Current thread CPU time measurement is not supported."); |
|
225 |
} |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
226 |
return isThreadCpuTimeEnabled(); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
227 |
} |
2 | 228 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
229 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
230 |
public long getCurrentThreadCpuTime() { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
231 |
if (verifyCurrentThreadCpuTime()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
232 |
return getThreadTotalCpuTime0(0); |
2 | 233 |
} |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
234 |
return -1; |
2 | 235 |
} |
236 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
237 |
@Override |
2 | 238 |
public long getThreadCpuTime(long id) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
239 |
long[] ids = new long[1]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
240 |
ids[0] = id; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
241 |
final long[] times = getThreadCpuTime(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
242 |
return times[0]; |
2 | 243 |
} |
244 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
245 |
private boolean verifyThreadCpuTime(long[] ids) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
246 |
verifyThreadIds(ids); |
2 | 247 |
|
248 |
// check if Thread CPU time measurement is supported. |
|
249 |
if (!isThreadCpuTimeSupported() && |
|
250 |
!isCurrentThreadCpuTimeSupported()) { |
|
251 |
throw new UnsupportedOperationException( |
|
252 |
"Thread CPU time measurement is not supported."); |
|
253 |
} |
|
254 |
||
255 |
if (!isThreadCpuTimeSupported()) { |
|
256 |
// support current thread only |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
257 |
for (int i = 0; i < ids.length; i++) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
258 |
if (ids[i] != Thread.currentThread().getId()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
259 |
throw new UnsupportedOperationException( |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
260 |
"Thread CPU time measurement is only supported" + |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
261 |
" for the current thread."); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
262 |
} |
2 | 263 |
} |
264 |
} |
|
265 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
266 |
return isThreadCpuTimeEnabled(); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
267 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
268 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
269 |
protected long[] getThreadCpuTime(long[] ids) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
270 |
boolean verified = verifyThreadCpuTime(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
271 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
272 |
int length = ids.length; |
8003 | 273 |
long[] times = new long[length]; |
274 |
java.util.Arrays.fill(times, -1); |
|
2 | 275 |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
276 |
if (verified) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
277 |
if (length == 1) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
278 |
long id = ids[0]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
279 |
if (id == Thread.currentThread().getId()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
280 |
id = 0; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
281 |
} |
8002
5d022b92fbef
7013682: two test checking cpuTime filed java/lang/management/ThreadMXBean
phh
parents:
8001
diff
changeset
|
282 |
times[0] = getThreadTotalCpuTime0(id); |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
283 |
} else { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
284 |
getThreadTotalCpuTime1(ids, times); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
285 |
} |
2 | 286 |
} |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
287 |
return times; |
2 | 288 |
} |
289 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
290 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
291 |
public long getCurrentThreadUserTime() { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
292 |
if (verifyCurrentThreadCpuTime()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
293 |
return getThreadUserCpuTime0(0); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
294 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
295 |
return -1; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
296 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
297 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
298 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
299 |
public long getThreadUserTime(long id) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
300 |
long[] ids = new long[1]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
301 |
ids[0] = id; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
302 |
final long[] times = getThreadUserTime(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
303 |
return times[0]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
304 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
305 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
306 |
protected long[] getThreadUserTime(long[] ids) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
307 |
boolean verified = verifyThreadCpuTime(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
308 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
309 |
int length = ids.length; |
8003 | 310 |
long[] times = new long[length]; |
311 |
java.util.Arrays.fill(times, -1); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
312 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
313 |
if (verified) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
314 |
if (length == 1) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
315 |
long id = ids[0]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
316 |
if (id == Thread.currentThread().getId()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
317 |
id = 0; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
318 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
319 |
times[0] = getThreadUserCpuTime0(id); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
320 |
} else { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
321 |
getThreadUserCpuTime1(ids, times); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
322 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
323 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
324 |
return times; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
325 |
} |
2 | 326 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
327 |
@Override |
2 | 328 |
public void setThreadCpuTimeEnabled(boolean enable) { |
329 |
if (!isThreadCpuTimeSupported() && |
|
330 |
!isCurrentThreadCpuTimeSupported()) { |
|
331 |
throw new UnsupportedOperationException( |
|
332 |
"Thread CPU time measurement is not supported"); |
|
333 |
} |
|
334 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
335 |
Util.checkControlAccess(); |
2 | 336 |
synchronized (this) { |
337 |
if (cpuTimeEnabled != enable) { |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
338 |
// notify VM of the state change |
2 | 339 |
setThreadCpuTimeEnabled0(enable); |
340 |
cpuTimeEnabled = enable; |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
345 |
protected long getThreadAllocatedBytes(long id) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
346 |
long[] ids = new long[1]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
347 |
ids[0] = id; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
348 |
final long[] sizes = getThreadAllocatedBytes(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
349 |
return sizes[0]; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
350 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
351 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
352 |
private boolean verifyThreadAllocatedMemory(long[] ids) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
353 |
verifyThreadIds(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
354 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
355 |
// check if Thread allocated memory measurement is supported. |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
356 |
if (!isThreadAllocatedMemorySupported()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
357 |
throw new UnsupportedOperationException( |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
358 |
"Thread allocated memory measurement is not supported."); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
359 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
360 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
361 |
return isThreadAllocatedMemoryEnabled(); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
362 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
363 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
364 |
protected long[] getThreadAllocatedBytes(long[] ids) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
365 |
boolean verified = verifyThreadAllocatedMemory(ids); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
366 |
|
8003 | 367 |
long[] sizes = new long[ids.length]; |
368 |
java.util.Arrays.fill(sizes, -1); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
369 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
370 |
if (verified) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
371 |
getThreadAllocatedMemory1(ids, sizes); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
372 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
373 |
return sizes; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
374 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
375 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
376 |
protected void setThreadAllocatedMemoryEnabled(boolean enable) { |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
377 |
if (!isThreadAllocatedMemorySupported()) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
378 |
throw new UnsupportedOperationException( |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
379 |
"Thread allocated memory measurement is not supported."); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
380 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
381 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
382 |
Util.checkControlAccess(); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
383 |
synchronized (this) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
384 |
if (allocatedMemoryEnabled != enable) { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
385 |
// notify VM of the state change |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
386 |
setThreadAllocatedMemoryEnabled0(enable); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
387 |
allocatedMemoryEnabled = enable; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
388 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
389 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
390 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
391 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
392 |
@Override |
2 | 393 |
public long[] findMonitorDeadlockedThreads() { |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
394 |
Util.checkMonitorAccess(); |
2 | 395 |
|
396 |
Thread[] threads = findMonitorDeadlockedThreads0(); |
|
397 |
if (threads == null) { |
|
398 |
return null; |
|
399 |
} |
|
400 |
||
401 |
long[] ids = new long[threads.length]; |
|
402 |
for (int i = 0; i < threads.length; i++) { |
|
403 |
Thread t = threads[i]; |
|
404 |
ids[i] = t.getId(); |
|
405 |
} |
|
406 |
return ids; |
|
407 |
} |
|
408 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
409 |
@Override |
2 | 410 |
public long[] findDeadlockedThreads() { |
411 |
if (!isSynchronizerUsageSupported()) { |
|
412 |
throw new UnsupportedOperationException( |
|
413 |
"Monitoring of Synchronizer Usage is not supported."); |
|
414 |
} |
|
415 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
416 |
Util.checkMonitorAccess(); |
2 | 417 |
|
418 |
Thread[] threads = findDeadlockedThreads0(); |
|
419 |
if (threads == null) { |
|
420 |
return null; |
|
421 |
} |
|
422 |
||
423 |
long[] ids = new long[threads.length]; |
|
424 |
for (int i = 0; i < threads.length; i++) { |
|
425 |
Thread t = threads[i]; |
|
426 |
ids[i] = t.getId(); |
|
427 |
} |
|
428 |
return ids; |
|
429 |
} |
|
430 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
431 |
@Override |
2 | 432 |
public void resetPeakThreadCount() { |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
433 |
Util.checkControlAccess(); |
2 | 434 |
resetPeakThreadCount0(); |
435 |
} |
|
436 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
437 |
@Override |
2 | 438 |
public boolean isObjectMonitorUsageSupported() { |
439 |
return jvm.isObjectMonitorUsageSupported(); |
|
440 |
} |
|
441 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
442 |
@Override |
2 | 443 |
public boolean isSynchronizerUsageSupported() { |
444 |
return jvm.isSynchronizerUsageSupported(); |
|
445 |
} |
|
446 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
447 |
private void verifyDumpThreads(boolean lockedMonitors, |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
448 |
boolean lockedSynchronizers) { |
2 | 449 |
if (lockedMonitors && !isObjectMonitorUsageSupported()) { |
450 |
throw new UnsupportedOperationException( |
|
451 |
"Monitoring of Object Monitor Usage is not supported."); |
|
452 |
} |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
453 |
|
2 | 454 |
if (lockedSynchronizers && !isSynchronizerUsageSupported()) { |
455 |
throw new UnsupportedOperationException( |
|
456 |
"Monitoring of Synchronizer Usage is not supported."); |
|
457 |
} |
|
458 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
459 |
Util.checkMonitorAccess(); |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
460 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
461 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
462 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
463 |
public ThreadInfo[] getThreadInfo(long[] ids, |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
464 |
boolean lockedMonitors, |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
465 |
boolean lockedSynchronizers) { |
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
466 |
return dumpThreads0(ids, lockedMonitors, lockedSynchronizers, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
467 |
Integer.MAX_VALUE); |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
468 |
} |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
469 |
|
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
470 |
public ThreadInfo[] getThreadInfo(long[] ids, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
471 |
boolean lockedMonitors, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
472 |
boolean lockedSynchronizers, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
473 |
int maxDepth) { |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
474 |
if (maxDepth < 0) { |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
475 |
throw new IllegalArgumentException( |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
476 |
"Invalid maxDepth parameter: " + maxDepth); |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
477 |
} |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
478 |
verifyThreadIds(ids); |
30348
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
479 |
// ids has been verified to be non-null |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
480 |
// an empty array of ids should return an empty array of ThreadInfos |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
481 |
if (ids.length == 0) return new ThreadInfo[0]; |
9a9e6c13ab1d
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
jbachorik
parents:
25859
diff
changeset
|
482 |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
483 |
verifyDumpThreads(lockedMonitors, lockedSynchronizers); |
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
484 |
return dumpThreads0(ids, lockedMonitors, lockedSynchronizers, maxDepth); |
2 | 485 |
} |
486 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
487 |
@Override |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
488 |
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
489 |
boolean lockedSynchronizers) { |
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
490 |
return dumpAllThreads(lockedMonitors, lockedSynchronizers, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
491 |
Integer.MAX_VALUE); |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
492 |
} |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
493 |
|
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
494 |
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
495 |
boolean lockedSynchronizers, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
496 |
int maxDepth) { |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
497 |
if (maxDepth < 0) { |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
498 |
throw new IllegalArgumentException( |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
499 |
"Invalid maxDepth parameter: " + maxDepth); |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
500 |
} |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
501 |
verifyDumpThreads(lockedMonitors, lockedSynchronizers); |
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
502 |
return dumpThreads0(null, lockedMonitors, lockedSynchronizers, maxDepth); |
2 | 503 |
} |
504 |
||
505 |
// VM support where maxDepth == -1 to request entire stack dump |
|
506 |
private static native Thread[] getThreads(); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
507 |
private static native void getThreadInfo1(long[] ids, |
2 | 508 |
int maxDepth, |
509 |
ThreadInfo[] result); |
|
510 |
private static native long getThreadTotalCpuTime0(long id); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
511 |
private static native void getThreadTotalCpuTime1(long[] ids, long[] result); |
2 | 512 |
private static native long getThreadUserCpuTime0(long id); |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
513 |
private static native void getThreadUserCpuTime1(long[] ids, long[] result); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
514 |
private static native void getThreadAllocatedMemory1(long[] ids, long[] result); |
2 | 515 |
private static native void setThreadCpuTimeEnabled0(boolean enable); |
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
516 |
private static native void setThreadAllocatedMemoryEnabled0(boolean enable); |
2 | 517 |
private static native void setThreadContentionMonitoringEnabled0(boolean enable); |
518 |
private static native Thread[] findMonitorDeadlockedThreads0(); |
|
519 |
private static native Thread[] findDeadlockedThreads0(); |
|
520 |
private static native void resetPeakThreadCount0(); |
|
521 |
private static native ThreadInfo[] dumpThreads0(long[] ids, |
|
522 |
boolean lockedMonitors, |
|
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
523 |
boolean lockedSynchronizers, |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
524 |
int maxDepth); |
2 | 525 |
|
526 |
// tid == 0 to reset contention times for all threads |
|
527 |
private static native void resetContentionTimes0(long tid); |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
528 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
30348
diff
changeset
|
529 |
@Override |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
530 |
public ObjectName getObjectName() { |
4156 | 531 |
return Util.newObjectName(ManagementFactory.THREAD_MXBEAN_NAME); |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
532 |
} |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
533 |
|
2 | 534 |
} |