src/jdk.management/share/classes/com/sun/management/ThreadMXBean.java
changeset 58223 778fc2dcbdaa
parent 58208 0f3c23c374a4
child 58348 c29e49148be7
equal deleted inserted replaced
58222:ee37c9b2eb61 58223:778fc2dcbdaa
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    59      * {@code -1} otherwise.
    59      * {@code -1} otherwise.
    60      *
    60      *
    61      * @throws NullPointerException if {@code ids} is {@code null}
    61      * @throws NullPointerException if {@code ids} is {@code null}
    62      * @throws IllegalArgumentException if any element in the input array
    62      * @throws IllegalArgumentException if any element in the input array
    63      *         {@code ids} is {@code <=} {@code 0}.
    63      *         {@code ids} is {@code <=} {@code 0}.
    64      * @throws UnsupportedOperationException if the Java
    64      * @throws java.lang.UnsupportedOperationException if the Java
    65      *         virtual machine implementation does not support CPU time
    65      *         virtual machine implementation does not support CPU time
    66      *         measurement.
    66      *         measurement.
    67      *
    67      *
    68      * @see ThreadMXBean#getThreadCpuTime(long)
    68      * @see ThreadMXBean#getThreadCpuTime(long)
    69      * @see #getThreadUserTime
    69      * @see #getThreadUserTime
    93      * {@code -1} otherwise.
    93      * {@code -1} otherwise.
    94      *
    94      *
    95      * @throws NullPointerException if {@code ids} is {@code null}
    95      * @throws NullPointerException if {@code ids} is {@code null}
    96      * @throws IllegalArgumentException if any element in the input array
    96      * @throws IllegalArgumentException if any element in the input array
    97      *         {@code ids} is {@code <=} {@code 0}.
    97      *         {@code ids} is {@code <=} {@code 0}.
    98      * @throws UnsupportedOperationException if the Java
    98      * @throws java.lang.UnsupportedOperationException if the Java
    99      *         virtual machine implementation does not support CPU time
    99      *         virtual machine implementation does not support CPU time
   100      *         measurement.
   100      *         measurement.
   101      *
   101      *
   102      * @see ThreadMXBean#getThreadUserTime(long)
   102      * @see ThreadMXBean#getThreadUserTime(long)
   103      * @see #getThreadCpuTime
   103      * @see #getThreadCpuTime
   107      */
   107      */
   108     public long[] getThreadUserTime(long[] ids);
   108     public long[] getThreadUserTime(long[] ids);
   109 
   109 
   110     /**
   110     /**
   111      * Returns an approximation of the total amount of memory, in bytes,
   111      * Returns an approximation of the total amount of memory, in bytes,
   112      * allocated in heap memory for the current thread.
   112      * allocated in heap memory for the thread of the specified ID.
   113      * The returned value is an approximation because some Java virtual machine
   113      * The returned value is an approximation because some Java virtual machine
   114      * implementations may use object allocation mechanisms that result in a
   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
   115      * delay between the time an object is allocated and the time its size is
   116      * recorded.
   116      * recorded.
   117      *
   117      * <p>
   118      * <p>
   118      * If the thread of the specified ID is not alive or does not exist,
   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      * @return an approximation of the total memory allocated, in bytes, in
       
   126      * heap memory for the current thread
       
   127      * if thread memory allocation measurement is enabled;
       
   128      * {@code -1} otherwise.
       
   129      *
       
   130      * @throws UnsupportedOperationException if the Java virtual
       
   131      *         machine implementation does not support thread memory allocation
       
   132      *         measurement.
       
   133      *
       
   134      * @see #isThreadAllocatedMemorySupported
       
   135      * @see #isThreadAllocatedMemoryEnabled
       
   136      * @see #setThreadAllocatedMemoryEnabled
       
   137      * @since 14
       
   138      */
       
   139     public long getCurrentThreadAllocatedBytes();
       
   140 
       
   141     /**
       
   142      * Returns an approximation of the total amount of memory, in bytes,
       
   143      * allocated in heap memory for the thread with the specified ID.
       
   144      * The returned value is an approximation because some Java virtual machine
       
   145      * implementations may use object allocation mechanisms that result in a
       
   146      * delay between the time an object is allocated and the time its size is
       
   147      * recorded.
       
   148      * <p>
       
   149      * If the thread with the specified ID is not alive or does not exist,
       
   150      * this method returns {@code -1}. If thread memory allocation measurement
   119      * this method returns {@code -1}. If thread memory allocation measurement
   151      * is disabled, this method returns {@code -1}.
   120      * is disabled, this method returns {@code -1}.
   152      * A thread is alive if it has been started and has not yet died.
   121      * A thread is alive if it has been started and has not yet died.
   153      * <p>
   122      * <p>
   154      * If thread memory allocation measurement is enabled after the thread has
   123      * If thread memory allocation measurement is enabled after the thread has
   156      * to and including the time that the capability is enabled as the point
   125      * to and including the time that the capability is enabled as the point
   157      * where thread memory allocation measurement starts.
   126      * where thread memory allocation measurement starts.
   158      *
   127      *
   159      * @param id the thread ID of a thread
   128      * @param id the thread ID of a thread
   160      * @return an approximation of the total memory allocated, in bytes, in
   129      * @return an approximation of the total memory allocated, in bytes, in
   161      * heap memory for the thread with the specified ID
   130      * heap memory for a thread of the specified ID
   162      * if the thread with the specified ID exists, the thread is alive,
   131      * if the thread of the specified ID exists, the thread is alive,
   163      * and thread memory allocation measurement is enabled;
   132      * and thread memory allocation measurement is enabled;
   164      * {@code -1} otherwise.
   133      * {@code -1} otherwise.
   165      *
   134      *
   166      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
   135      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
   167      * @throws UnsupportedOperationException if the Java virtual
   136      * @throws java.lang.UnsupportedOperationException if the Java virtual
   168      *         machine implementation does not support thread memory allocation
   137      *         machine implementation does not support thread memory allocation
   169      *         measurement.
   138      *         measurement.
   170      *
   139      *
   171      * @see #isThreadAllocatedMemorySupported
   140      * @see #isThreadAllocatedMemorySupported
   172      * @see #isThreadAllocatedMemoryEnabled
   141      * @see #isThreadAllocatedMemoryEnabled
   194      * whose ID is in the corresponding element of the input array of IDs.
   163      * whose ID is in the corresponding element of the input array of IDs.
   195      *
   164      *
   196      * @throws NullPointerException if {@code ids} is {@code null}
   165      * @throws NullPointerException if {@code ids} is {@code null}
   197      * @throws IllegalArgumentException if any element in the input array
   166      * @throws IllegalArgumentException if any element in the input array
   198      *         {@code ids} is {@code <=} {@code 0}.
   167      *         {@code ids} is {@code <=} {@code 0}.
   199      * @throws UnsupportedOperationException if the Java virtual
   168      * @throws java.lang.UnsupportedOperationException if the Java virtual
   200      *         machine implementation does not support thread memory allocation
   169      *         machine implementation does not support thread memory allocation
   201      *         measurement.
   170      *         measurement.
   202      *
   171      *
   203      * @see #getThreadAllocatedBytes(long)
   172      * @see #getThreadAllocatedBytes(long)
   204      * @see #isThreadAllocatedMemorySupported
   173      * @see #isThreadAllocatedMemorySupported
   223      * Tests if thread memory allocation measurement is enabled.
   192      * Tests if thread memory allocation measurement is enabled.
   224      *
   193      *
   225      * @return {@code true} if thread memory allocation measurement is enabled;
   194      * @return {@code true} if thread memory allocation measurement is enabled;
   226      *         {@code false} otherwise.
   195      *         {@code false} otherwise.
   227      *
   196      *
   228      * @throws UnsupportedOperationException if the Java virtual
   197      * @throws java.lang.UnsupportedOperationException if the Java virtual
   229      *         machine does not support thread memory allocation measurement.
   198      *         machine does not support thread memory allocation measurement.
   230      *
   199      *
   231      * @see #isThreadAllocatedMemorySupported
   200      * @see #isThreadAllocatedMemorySupported
   232      */
   201      */
   233     public boolean isThreadAllocatedMemoryEnabled();
   202     public boolean isThreadAllocatedMemoryEnabled();
   237      * is platform dependent.
   206      * is platform dependent.
   238      *
   207      *
   239      * @param enable {@code true} to enable;
   208      * @param enable {@code true} to enable;
   240      *               {@code false} to disable.
   209      *               {@code false} to disable.
   241      *
   210      *
   242      * @throws UnsupportedOperationException if the Java virtual
   211      * @throws java.lang.UnsupportedOperationException if the Java virtual
   243      *         machine does not support thread memory allocation measurement.
   212      *         machine does not support thread memory allocation measurement.
   244      *
   213      *
   245      * @throws SecurityException if a security manager
   214      * @throws java.lang.SecurityException if a security manager
   246      *         exists and the caller does not have
   215      *         exists and the caller does not have
   247      *         ManagementPermission("control").
   216      *         ManagementPermission("control").
   248      *
   217      *
   249      * @see #isThreadAllocatedMemorySupported
   218      * @see #isThreadAllocatedMemorySupported
   250      */
   219      */