Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/management/ThreadMXBean.java
38831 views
1
/*
2
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package com.sun.management;
27
28
import java.lang.management.ThreadInfo;
29
import java.util.Map;
30
31
/**
32
* Platform-specific management interface for the thread system
33
* of the Java virtual machine.
34
* <p>
35
* This platform extension is only available to a thread
36
* implementation that supports this extension.
37
*
38
* @author Paul Hohensee
39
* @since 6u25
40
*/
41
42
@jdk.Exported
43
public interface ThreadMXBean extends java.lang.management.ThreadMXBean {
44
/**
45
* Returns the total CPU time for each thread whose ID is
46
* in the input array {@code ids} in nanoseconds.
47
* The returned values are of nanoseconds precision but
48
* not necessarily nanoseconds accuracy.
49
* <p>
50
* This method is equivalent to calling the
51
* {@link ThreadMXBean#getThreadCpuTime(long)}
52
* method for each thread ID in the input array {@code ids} and setting the
53
* returned value in the corresponding element of the returned array.
54
*
55
* @param ids an array of thread IDs.
56
* @return an array of long values, each of which is the amount of CPU
57
* time the thread whose ID is in the corresponding element of the input
58
* array of IDs has used,
59
* if the thread of a specified ID exists, the thread is alive,
60
* and CPU time measurement is enabled;
61
* {@code -1} otherwise.
62
*
63
* @throws NullPointerException if {@code ids} is {@code null}
64
* @throws IllegalArgumentException if any element in the input array
65
* {@code ids} is {@code <=} {@code 0}.
66
* @throws UnsupportedOperationException if the Java
67
* virtual machine implementation does not support CPU time
68
* measurement.
69
*
70
* @see ThreadMXBean#getThreadCpuTime(long)
71
* @see #getThreadUserTime
72
* @see ThreadMXBean#isThreadCpuTimeSupported
73
* @see ThreadMXBean#isThreadCpuTimeEnabled
74
* @see ThreadMXBean#setThreadCpuTimeEnabled
75
*/
76
public long[] getThreadCpuTime(long[] ids);
77
78
/**
79
* Returns the CPU time that each thread whose ID is in the input array
80
* {@code ids} has executed in user mode in nanoseconds.
81
* The returned values are of nanoseconds precision but
82
* not necessarily nanoseconds accuracy.
83
* <p>
84
* This method is equivalent to calling the
85
* {@link ThreadMXBean#getThreadUserTime(long)}
86
* method for each thread ID in the input array {@code ids} and setting the
87
* returned value in the corresponding element of the returned array.
88
*
89
* @param ids an array of thread IDs.
90
* @return an array of long values, each of which is the amount of user
91
* mode CPU time the thread whose ID is in the corresponding element of
92
* the input array of IDs has used,
93
* if the thread of a specified ID exists, the thread is alive,
94
* and CPU time measurement is enabled;
95
* {@code -1} otherwise.
96
*
97
* @throws NullPointerException if {@code ids} is {@code null}
98
* @throws IllegalArgumentException if any element in the input array
99
* {@code ids} is {@code <=} {@code 0}.
100
* @throws UnsupportedOperationException if the Java
101
* virtual machine implementation does not support CPU time
102
* measurement.
103
*
104
* @see ThreadMXBean#getThreadUserTime(long)
105
* @see #getThreadCpuTime
106
* @see ThreadMXBean#isThreadCpuTimeSupported
107
* @see ThreadMXBean#isThreadCpuTimeEnabled
108
* @see ThreadMXBean#setThreadCpuTimeEnabled
109
*/
110
public long[] getThreadUserTime(long[] ids);
111
112
/**
113
* Returns an approximation of the total amount of memory, in bytes,
114
* allocated in heap memory for the current thread.
115
* The returned value is an approximation because some Java virtual machine
116
* implementations may use object allocation mechanisms that result in a
117
* delay between the time an object is allocated and the time its size is
118
* recorded.
119
*
120
* <p>
121
* This is a convenience method for local management use and is
122
* equivalent to calling:
123
* <blockquote><pre>
124
* {@link #getThreadAllocatedBytes getThreadAllocatedBytes}(Thread.currentThread().getId());
125
* </pre></blockquote>
126
*
127
* @return an approximation of the total memory allocated, in bytes, in
128
* heap memory for the current thread
129
* if thread memory allocation measurement is enabled;
130
* {@code -1} otherwise.
131
*
132
* @throws UnsupportedOperationException if the Java virtual
133
* machine implementation does not support thread memory allocation
134
* measurement.
135
*
136
* @see #isThreadAllocatedMemorySupported
137
* @see #isThreadAllocatedMemoryEnabled
138
* @see #setThreadAllocatedMemoryEnabled
139
*
140
* @since 8u282
141
*/
142
public default long getCurrentThreadAllocatedBytes() {
143
return getThreadAllocatedBytes(Thread.currentThread().getId());
144
}
145
146
/**
147
* Returns an approximation of the total amount of memory, in bytes,
148
* allocated in heap memory for the thread with the specified ID.
149
* The returned value is an approximation because some Java virtual machine
150
* implementations may use object allocation mechanisms that result in a
151
* delay between the time an object is allocated and the time its size is
152
* recorded.
153
* <p>
154
* If the thread with the specified ID is not alive or does not exist,
155
* this method returns {@code -1}. If thread memory allocation measurement
156
* is disabled, this method returns {@code -1}.
157
* A thread is alive if it has been started and has not yet died.
158
* <p>
159
* If thread memory allocation measurement is enabled after the thread has
160
* started, the Java virtual machine implementation may choose any time up
161
* to and including the time that the capability is enabled as the point
162
* where thread memory allocation measurement starts.
163
*
164
* @param id the thread ID of a thread
165
* @return an approximation of the total memory allocated, in bytes, in
166
* heap memory for the thread with the specified ID
167
* if the thread with the specified ID exists, the thread is alive,
168
* and thread memory allocation measurement is enabled;
169
* {@code -1} otherwise.
170
*
171
* @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
172
* @throws UnsupportedOperationException if the Java virtual
173
* machine implementation does not support thread memory allocation
174
* measurement.
175
*
176
* @see #isThreadAllocatedMemorySupported
177
* @see #isThreadAllocatedMemoryEnabled
178
* @see #setThreadAllocatedMemoryEnabled
179
*/
180
public long getThreadAllocatedBytes(long id);
181
182
/**
183
* Returns an approximation of the total amount of memory, in bytes,
184
* allocated in heap memory for each thread whose ID is in the input
185
* array {@code ids}.
186
* The returned values are approximations because some Java virtual machine
187
* implementations may use object allocation mechanisms that result in a
188
* delay between the time an object is allocated and the time its size is
189
* recorded.
190
* <p>
191
* This method is equivalent to calling the
192
* {@link #getThreadAllocatedBytes(long)}
193
* method for each thread ID in the input array {@code ids} and setting the
194
* returned value in the corresponding element of the returned array.
195
*
196
* @param ids an array of thread IDs.
197
* @return an array of long values, each of which is an approximation of
198
* the total memory allocated, in bytes, in heap memory for the thread
199
* whose ID is in the corresponding element of the input array of IDs.
200
*
201
* @throws NullPointerException if {@code ids} is {@code null}
202
* @throws IllegalArgumentException if any element in the input array
203
* {@code ids} is {@code <=} {@code 0}.
204
* @throws UnsupportedOperationException if the Java virtual
205
* machine implementation does not support thread memory allocation
206
* measurement.
207
*
208
* @see #getThreadAllocatedBytes(long)
209
* @see #isThreadAllocatedMemorySupported
210
* @see #isThreadAllocatedMemoryEnabled
211
* @see #setThreadAllocatedMemoryEnabled
212
*/
213
public long[] getThreadAllocatedBytes(long[] ids);
214
215
/**
216
* Tests if the Java virtual machine implementation supports thread memory
217
* allocation measurement.
218
*
219
* @return
220
* {@code true}
221
* if the Java virtual machine implementation supports thread memory
222
* allocation measurement;
223
* {@code false} otherwise.
224
*/
225
public boolean isThreadAllocatedMemorySupported();
226
227
/**
228
* Tests if thread memory allocation measurement is enabled.
229
*
230
* @return {@code true} if thread memory allocation measurement is enabled;
231
* {@code false} otherwise.
232
*
233
* @throws UnsupportedOperationException if the Java virtual
234
* machine does not support thread memory allocation measurement.
235
*
236
* @see #isThreadAllocatedMemorySupported
237
*/
238
public boolean isThreadAllocatedMemoryEnabled();
239
240
/**
241
* Enables or disables thread memory allocation measurement. The default
242
* is platform dependent.
243
*
244
* @param enable {@code true} to enable;
245
* {@code false} to disable.
246
*
247
* @throws UnsupportedOperationException if the Java virtual
248
* machine does not support thread memory allocation measurement.
249
*
250
* @throws SecurityException if a security manager
251
* exists and the caller does not have
252
* ManagementPermission("control").
253
*
254
* @see #isThreadAllocatedMemorySupported
255
*/
256
public void setThreadAllocatedMemoryEnabled(boolean enable);
257
258
/**
259
* Returns the thread info for each thread whose ID
260
* is in the input array <tt>ids</tt>,
261
* with stack trace of the specified maximum number of elements
262
* and synchronization information.
263
* If <tt>maxDepth == 0</tt>, no stack trace of the thread
264
* will be dumped.
265
*
266
* <p>
267
* This method obtains a snapshot of the thread information
268
* for each thread including:
269
* <ul>
270
* <li>stack trace of the specified maximum number of elements,</li>
271
* <li>the object monitors currently locked by the thread
272
* if <tt>lockedMonitors</tt> is <tt>true</tt>, and</li>
273
* <li>the <a href="{@docRoot}/../api/java/lang/management/LockInfo.html#OwnableSynchronizer">
274
* ownable synchronizers</a> currently locked by the thread
275
* if <tt>lockedSynchronizers</tt> is <tt>true</tt>.</li>
276
* </ul>
277
* <p>
278
* This method returns an array of the <tt>ThreadInfo</tt> objects,
279
* each is the thread information about the thread with the same index
280
* as in the <tt>ids</tt> array.
281
* If a thread of the given ID is not alive or does not exist,
282
* <tt>null</tt> will be set in the corresponding element
283
* in the returned array. A thread is alive if
284
* it has been started and has not yet died.
285
* <p>
286
* If a thread does not lock any object monitor or <tt>lockedMonitors</tt>
287
* is <tt>false</tt>, the returned <tt>ThreadInfo</tt> object will have an
288
* empty <tt>MonitorInfo</tt> array. Similarly, if a thread does not
289
* lock any synchronizer or <tt>lockedSynchronizers</tt> is <tt>false</tt>,
290
* the returned <tt>ThreadInfo</tt> object
291
* will have an empty <tt>LockInfo</tt> array.
292
*
293
* <p>
294
* When both <tt>lockedMonitors</tt> and <tt>lockedSynchronizers</tt>
295
* parameters are <tt>false</tt>, it is equivalent to calling:
296
* <blockquote><pre>
297
* {@link #getThreadInfo(long[], int) getThreadInfo(ids, maxDepth)}
298
* </pre></blockquote>
299
*
300
* <p>
301
* This method is designed for troubleshooting use, but not for
302
* synchronization control. It might be an expensive operation.
303
*
304
* <p>
305
* <b>MBeanServer access</b>:<br>
306
* The mapped type of <tt>ThreadInfo</tt> is
307
* <tt>CompositeData</tt> with attributes as specified in the
308
* {@link ThreadInfo#from ThreadInfo.from} method.
309
*
310
* @implSpec The default implementation throws
311
* <tt>UnsupportedOperationException</tt>.
312
*
313
* @param ids an array of thread IDs.
314
* @param lockedMonitors if <tt>true</tt>, retrieves all locked monitors.
315
* @param lockedSynchronizers if <tt>true</tt>, retrieves all locked
316
* ownable synchronizers.
317
* @param maxDepth indicates the maximum number of
318
* {@link StackTraceElement} to be retrieved from the stack trace.
319
*
320
* @return an array of the {@link ThreadInfo} objects, each containing
321
* information about a thread whose ID is in the corresponding
322
* element of the input array of IDs.
323
*
324
* @throws IllegalArgumentException if <tt>maxDepth</tt> is negative.
325
* @throws java.lang.SecurityException if a security manager
326
* exists and the caller does not have
327
* ManagementPermission("monitor").
328
* @throws java.lang.UnsupportedOperationException
329
* <ul>
330
* <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
331
* the Java virtual machine does not support monitoring
332
* of {@linkplain #isObjectMonitorUsageSupported
333
* object monitor usage}; or</li>
334
* <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
335
* the Java virtual machine does not support monitoring
336
* of {@linkplain #isSynchronizerUsageSupported
337
* ownable synchronizer usage}.</li>
338
* </ul>
339
*
340
* @see #isObjectMonitorUsageSupported
341
* @see #isSynchronizerUsageSupported
342
*
343
* @since 8u282
344
*/
345
346
public default ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
347
boolean lockedSynchronizers, int maxDepth) {
348
throw new UnsupportedOperationException();
349
}
350
351
/**
352
* Returns the thread info for all live threads
353
* with stack trace of the specified maximum number of elements
354
* and synchronization information.
355
* if <tt>maxDepth == 0</tt>, no stack trace of the thread
356
* will be dumped.
357
* Some threads included in the returned array
358
* may have been terminated when this method returns.
359
*
360
* <p>
361
* This method returns an array of {@link ThreadInfo} objects
362
* as specified in the {@link #getThreadInfo(long[], boolean, boolean, int)}
363
* method.
364
*
365
* @implSpec The default implementation throws
366
* <tt>UnsupportedOperationException</tt>.
367
*
368
* @param lockedMonitors if <tt>true</tt>, dump all locked monitors.
369
* @param lockedSynchronizers if <tt>true</tt>, dump all locked
370
* ownable synchronizers.
371
* @param maxDepth indicates the maximum number of
372
* {@link StackTraceElement} to be retrieved from the stack trace.
373
*
374
* @return an array of {@link ThreadInfo} for all live threads.
375
*
376
* @throws IllegalArgumentException if <tt>maxDepth</tt> is negative.
377
* @throws java.lang.SecurityException if a security manager
378
* exists and the caller does not have
379
* ManagementPermission("monitor").
380
* @throws java.lang.UnsupportedOperationException
381
* <ul>
382
* <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
383
* the Java virtual machine does not support monitoring
384
* of {@linkplain #isObjectMonitorUsageSupported
385
* object monitor usage}; or</li>
386
* <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
387
* the Java virtual machine does not support monitoring
388
* of {@linkplain #isSynchronizerUsageSupported
389
* ownable synchronizer usage}.</li>
390
* </ul>
391
*
392
* @see #isObjectMonitorUsageSupported
393
* @see #isSynchronizerUsageSupported
394
*
395
* @since 8u282
396
*/
397
public default ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
398
boolean lockedSynchronizers, int maxDepth) {
399
throw new UnsupportedOperationException();
400
}
401
}
402
403