< prev index next >

src/jdk.management/share/classes/com/sun/management/ThreadMXBean.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2013, 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


  44      * in the input array {@code ids} in nanoseconds.
  45      * The returned values are of nanoseconds precision but
  46      * not necessarily nanoseconds accuracy.
  47      * <p>
  48      * This method is equivalent to calling the
  49      * {@link ThreadMXBean#getThreadCpuTime(long)}
  50      * method for each thread ID in the input array {@code ids} and setting the
  51      * returned value in the corresponding element of the returned array.
  52      *
  53      * @param ids an array of thread IDs.
  54      * @return an array of long values, each of which is the amount of CPU
  55      * time the thread whose ID is in the corresponding element of the input
  56      * array of IDs has used,
  57      * if the thread of a specified ID exists, the thread is alive,
  58      * and CPU time measurement is enabled;
  59      * {@code -1} otherwise.
  60      *
  61      * @throws NullPointerException if {@code ids} is {@code null}
  62      * @throws IllegalArgumentException if any element in the input array
  63      *         {@code ids} is {@code <=} {@code 0}.
  64      * @throws java.lang.UnsupportedOperationException if the Java
  65      *         virtual machine implementation does not support CPU time
  66      *         measurement.
  67      *
  68      * @see ThreadMXBean#getThreadCpuTime(long)
  69      * @see #getThreadUserTime
  70      * @see ThreadMXBean#isThreadCpuTimeSupported
  71      * @see ThreadMXBean#isThreadCpuTimeEnabled
  72      * @see ThreadMXBean#setThreadCpuTimeEnabled
  73      */
  74     public long[] getThreadCpuTime(long[] ids);
  75 
  76     /**
  77      * Returns the CPU time that each thread whose ID is in the input array
  78      * {@code ids} has executed in user mode in nanoseconds.
  79      * The returned values are of nanoseconds precision but
  80      * not necessarily nanoseconds accuracy.
  81      * <p>
  82      * This method is equivalent to calling the
  83      * {@link ThreadMXBean#getThreadUserTime(long)}
  84      * method for each thread ID in the input array {@code ids} and setting the
  85      * returned value in the corresponding element of the returned array.
  86      *
  87      * @param ids an array of thread IDs.
  88      * @return an array of long values, each of which is the amount of user
  89      * mode CPU time the thread whose ID is in the corresponding element of
  90      * the input array of IDs has used,
  91      * if the thread of a specified ID exists, the thread is alive,
  92      * and CPU time measurement is enabled;
  93      * {@code -1} otherwise.
  94      *
  95      * @throws NullPointerException if {@code ids} is {@code null}
  96      * @throws IllegalArgumentException if any element in the input array
  97      *         {@code ids} is {@code <=} {@code 0}.
  98      * @throws java.lang.UnsupportedOperationException if the Java
  99      *         virtual machine implementation does not support CPU time
 100      *         measurement.
 101      *
 102      * @see ThreadMXBean#getThreadUserTime(long)
 103      * @see #getThreadCpuTime
 104      * @see ThreadMXBean#isThreadCpuTimeSupported
 105      * @see ThreadMXBean#isThreadCpuTimeEnabled
 106      * @see ThreadMXBean#setThreadCpuTimeEnabled
 107      */
 108     public long[] getThreadUserTime(long[] ids);
 109 
 110     /**
 111      * Returns an approximation of the total amount of memory, in bytes,
 112      * allocated in heap memory for the thread of the specified ID.





































 113      * The returned value is an approximation because some Java virtual machine
 114      * implementations may use object allocation mechanisms that result in a
 115      * delay between the time an object is allocated and the time its size is
 116      * recorded.
 117      * <p>
 118      * If the thread of the specified ID is not alive or does not exist,
 119      * this method returns {@code -1}. If thread memory allocation measurement
 120      * is disabled, this method returns {@code -1}.
 121      * A thread is alive if it has been started and has not yet died.
 122      * <p>
 123      * If thread memory allocation measurement is enabled after the thread has
 124      * started, the Java virtual machine implementation may choose any time up
 125      * to and including the time that the capability is enabled as the point
 126      * where thread memory allocation measurement starts.
 127      *
 128      * @param id the thread ID of a thread
 129      * @return an approximation of the total memory allocated, in bytes, in
 130      * heap memory for a thread of the specified ID
 131      * if the thread of the specified ID exists, the thread is alive,
 132      * and thread memory allocation measurement is enabled;
 133      * {@code -1} otherwise.
 134      *
 135      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
 136      * @throws java.lang.UnsupportedOperationException if the Java virtual
 137      *         machine implementation does not support thread memory allocation
 138      *         measurement.
 139      *
 140      * @see #isThreadAllocatedMemorySupported
 141      * @see #isThreadAllocatedMemoryEnabled
 142      * @see #setThreadAllocatedMemoryEnabled
 143      */
 144     public long getThreadAllocatedBytes(long id);
 145 
 146     /**
 147      * Returns an approximation of the total amount of memory, in bytes,
 148      * allocated in heap memory for each thread whose ID is in the input
 149      * array {@code ids}.
 150      * The returned values are approximations because some Java virtual machine
 151      * implementations may use object allocation mechanisms that result in a
 152      * delay between the time an object is allocated and the time its size is
 153      * recorded.
 154      * <p>
 155      * This method is equivalent to calling the
 156      * {@link #getThreadAllocatedBytes(long)}
 157      * method for each thread ID in the input array {@code ids} and setting the
 158      * returned value in the corresponding element of the returned array.
 159      *
 160      * @param ids an array of thread IDs.
 161      * @return an array of long values, each of which is an approximation of
 162      * the total memory allocated, in bytes, in heap memory for the thread
 163      * whose ID is in the corresponding element of the input array of IDs.
 164      *
 165      * @throws NullPointerException if {@code ids} is {@code null}
 166      * @throws IllegalArgumentException if any element in the input array
 167      *         {@code ids} is {@code <=} {@code 0}.
 168      * @throws java.lang.UnsupportedOperationException if the Java virtual
 169      *         machine implementation does not support thread memory allocation
 170      *         measurement.
 171      *
 172      * @see #getThreadAllocatedBytes(long)
 173      * @see #isThreadAllocatedMemorySupported
 174      * @see #isThreadAllocatedMemoryEnabled
 175      * @see #setThreadAllocatedMemoryEnabled
 176      */
 177     public long[] getThreadAllocatedBytes(long[] ids);
 178 
 179     /**
 180      * Tests if the Java virtual machine implementation supports thread memory
 181      * allocation measurement.
 182      *
 183      * @return
 184      *   {@code true}
 185      *     if the Java virtual machine implementation supports thread memory
 186      *     allocation measurement;
 187      *   {@code false} otherwise.
 188      */
 189     public boolean isThreadAllocatedMemorySupported();
 190 
 191     /**
 192      * Tests if thread memory allocation measurement is enabled.
 193      *
 194      * @return {@code true} if thread memory allocation measurement is enabled;
 195      *         {@code false} otherwise.
 196      *
 197      * @throws java.lang.UnsupportedOperationException if the Java virtual
 198      *         machine does not support thread memory allocation measurement.
 199      *
 200      * @see #isThreadAllocatedMemorySupported
 201      */
 202     public boolean isThreadAllocatedMemoryEnabled();
 203 
 204     /**
 205      * Enables or disables thread memory allocation measurement.  The default
 206      * is platform dependent.
 207      *
 208      * @param enable {@code true} to enable;
 209      *               {@code false} to disable.
 210      *
 211      * @throws java.lang.UnsupportedOperationException if the Java virtual
 212      *         machine does not support thread memory allocation measurement.
 213      *
 214      * @throws java.lang.SecurityException if a security manager
 215      *         exists and the caller does not have
 216      *         ManagementPermission("control").
 217      *
 218      * @see #isThreadAllocatedMemorySupported
 219      */
 220     public void setThreadAllocatedMemoryEnabled(boolean enable);
 221 }
   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


  44      * in the input array {@code ids} in nanoseconds.
  45      * The returned values are of nanoseconds precision but
  46      * not necessarily nanoseconds accuracy.
  47      * <p>
  48      * This method is equivalent to calling the
  49      * {@link ThreadMXBean#getThreadCpuTime(long)}
  50      * method for each thread ID in the input array {@code ids} and setting the
  51      * returned value in the corresponding element of the returned array.
  52      *
  53      * @param ids an array of thread IDs.
  54      * @return an array of long values, each of which is the amount of CPU
  55      * time the thread whose ID is in the corresponding element of the input
  56      * array of IDs has used,
  57      * if the thread of a specified ID exists, the thread is alive,
  58      * and CPU time measurement is enabled;
  59      * {@code -1} otherwise.
  60      *
  61      * @throws NullPointerException if {@code ids} is {@code null}
  62      * @throws IllegalArgumentException if any element in the input array
  63      *         {@code ids} is {@code <=} {@code 0}.
  64      * @throws UnsupportedOperationException if the Java
  65      *         virtual machine implementation does not support CPU time
  66      *         measurement.
  67      *
  68      * @see ThreadMXBean#getThreadCpuTime(long)
  69      * @see #getThreadUserTime
  70      * @see ThreadMXBean#isThreadCpuTimeSupported
  71      * @see ThreadMXBean#isThreadCpuTimeEnabled
  72      * @see ThreadMXBean#setThreadCpuTimeEnabled
  73      */
  74     public long[] getThreadCpuTime(long[] ids);
  75 
  76     /**
  77      * Returns the CPU time that each thread whose ID is in the input array
  78      * {@code ids} has executed in user mode in nanoseconds.
  79      * The returned values are of nanoseconds precision but
  80      * not necessarily nanoseconds accuracy.
  81      * <p>
  82      * This method is equivalent to calling the
  83      * {@link ThreadMXBean#getThreadUserTime(long)}
  84      * method for each thread ID in the input array {@code ids} and setting the
  85      * returned value in the corresponding element of the returned array.
  86      *
  87      * @param ids an array of thread IDs.
  88      * @return an array of long values, each of which is the amount of user
  89      * mode CPU time the thread whose ID is in the corresponding element of
  90      * the input array of IDs has used,
  91      * if the thread of a specified ID exists, the thread is alive,
  92      * and CPU time measurement is enabled;
  93      * {@code -1} otherwise.
  94      *
  95      * @throws NullPointerException if {@code ids} is {@code null}
  96      * @throws IllegalArgumentException if any element in the input array
  97      *         {@code ids} is {@code <=} {@code 0}.
  98      * @throws UnsupportedOperationException if the Java
  99      *         virtual machine implementation does not support CPU time
 100      *         measurement.
 101      *
 102      * @see ThreadMXBean#getThreadUserTime(long)
 103      * @see #getThreadCpuTime
 104      * @see ThreadMXBean#isThreadCpuTimeSupported
 105      * @see ThreadMXBean#isThreadCpuTimeEnabled
 106      * @see ThreadMXBean#setThreadCpuTimeEnabled
 107      */
 108     public long[] getThreadUserTime(long[] ids);
 109 
 110     /**
 111      * Returns an approximation of the total amount of memory, in bytes,
 112      * allocated in heap memory for the current thread.
 113      * The returned value is an approximation because some Java virtual machine
 114      * implementations may use object allocation mechanisms that result in a
 115      * delay between the time an object is allocated and the time its size is
 116      * recorded.
 117      *
 118      * <p>
 119      * This is a convenience method for local management use and is
 120      * equivalent to calling:
 121      * <blockquote><pre>
 122      *   {@link #getThreadAllocatedBytes getThreadAllocatedBytes}(Thread.currentThread().getId());
 123      * </pre></blockquote>
 124      *
 125      * @implSpec The default implementation throws
 126      * {@code UnsupportedOperationException}.
 127      *
 128      * @return an approximation of the total memory allocated, in bytes, in
 129      * heap memory for the current thread
 130      * if thread memory allocation measurement is enabled;
 131      * {@code -1} otherwise.
 132      *
 133      * @throws UnsupportedOperationException if the Java virtual
 134      *         machine implementation does not support thread memory allocation
 135      *         measurement.
 136      *
 137      * @see #isThreadAllocatedMemorySupported
 138      * @see #isThreadAllocatedMemoryEnabled
 139      * @see #setThreadAllocatedMemoryEnabled
 140      *
 141      * @since 14
 142      */
 143     public default long getCurrentThreadAllocatedBytes() {
 144         throw new UnsupportedOperationException();
 145     }
 146 
 147     /**
 148      * Returns an approximation of the total amount of memory, in bytes,
 149      * allocated in heap memory for the thread with the specified ID.
 150      * The returned value is an approximation because some Java virtual machine
 151      * implementations may use object allocation mechanisms that result in a
 152      * delay between the time an object is allocated and the time its size is
 153      * recorded.
 154      * <p>
 155      * If the thread with the specified ID is not alive or does not exist,
 156      * this method returns {@code -1}. If thread memory allocation measurement
 157      * is disabled, this method returns {@code -1}.
 158      * A thread is alive if it has been started and has not yet died.
 159      * <p>
 160      * If thread memory allocation measurement is enabled after the thread has
 161      * started, the Java virtual machine implementation may choose any time up
 162      * to and including the time that the capability is enabled as the point
 163      * where thread memory allocation measurement starts.
 164      *
 165      * @param id the thread ID of a thread
 166      * @return an approximation of the total memory allocated, in bytes, in
 167      * heap memory for the thread with the specified ID
 168      * if the thread with the specified ID exists, the thread is alive,
 169      * and thread memory allocation measurement is enabled;
 170      * {@code -1} otherwise.
 171      *
 172      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
 173      * @throws UnsupportedOperationException if the Java virtual
 174      *         machine implementation does not support thread memory allocation
 175      *         measurement.
 176      *
 177      * @see #isThreadAllocatedMemorySupported
 178      * @see #isThreadAllocatedMemoryEnabled
 179      * @see #setThreadAllocatedMemoryEnabled
 180      */
 181     public long getThreadAllocatedBytes(long id);
 182 
 183     /**
 184      * Returns an approximation of the total amount of memory, in bytes,
 185      * allocated in heap memory for each thread whose ID is in the input
 186      * array {@code ids}.
 187      * The returned values are approximations because some Java virtual machine
 188      * implementations may use object allocation mechanisms that result in a
 189      * delay between the time an object is allocated and the time its size is
 190      * recorded.
 191      * <p>
 192      * This method is equivalent to calling the
 193      * {@link #getThreadAllocatedBytes(long)}
 194      * method for each thread ID in the input array {@code ids} and setting the
 195      * returned value in the corresponding element of the returned array.
 196      *
 197      * @param ids an array of thread IDs.
 198      * @return an array of long values, each of which is an approximation of
 199      * the total memory allocated, in bytes, in heap memory for the thread
 200      * whose ID is in the corresponding element of the input array of IDs.
 201      *
 202      * @throws NullPointerException if {@code ids} is {@code null}
 203      * @throws IllegalArgumentException if any element in the input array
 204      *         {@code ids} is {@code <=} {@code 0}.
 205      * @throws UnsupportedOperationException if the Java virtual
 206      *         machine implementation does not support thread memory allocation
 207      *         measurement.
 208      *
 209      * @see #getThreadAllocatedBytes(long)
 210      * @see #isThreadAllocatedMemorySupported
 211      * @see #isThreadAllocatedMemoryEnabled
 212      * @see #setThreadAllocatedMemoryEnabled
 213      */
 214     public long[] getThreadAllocatedBytes(long[] ids);
 215 
 216     /**
 217      * Tests if the Java virtual machine implementation supports thread memory
 218      * allocation measurement.
 219      *
 220      * @return
 221      *   {@code true}
 222      *     if the Java virtual machine implementation supports thread memory
 223      *     allocation measurement;
 224      *   {@code false} otherwise.
 225      */
 226     public boolean isThreadAllocatedMemorySupported();
 227 
 228     /**
 229      * Tests if thread memory allocation measurement is enabled.
 230      *
 231      * @return {@code true} if thread memory allocation measurement is enabled;
 232      *         {@code false} otherwise.
 233      *
 234      * @throws UnsupportedOperationException if the Java virtual
 235      *         machine does not support thread memory allocation measurement.
 236      *
 237      * @see #isThreadAllocatedMemorySupported
 238      */
 239     public boolean isThreadAllocatedMemoryEnabled();
 240 
 241     /**
 242      * Enables or disables thread memory allocation measurement.  The default
 243      * is platform dependent.
 244      *
 245      * @param enable {@code true} to enable;
 246      *               {@code false} to disable.
 247      *
 248      * @throws UnsupportedOperationException if the Java virtual
 249      *         machine does not support thread memory allocation measurement.
 250      *
 251      * @throws SecurityException if a security manager
 252      *         exists and the caller does not have
 253      *         ManagementPermission("control").
 254      *
 255      * @see #isThreadAllocatedMemorySupported
 256      */
 257     public void setThreadAllocatedMemoryEnabled(boolean enable);
 258 }
< prev index next >