< prev index next >

src/java.base/share/classes/sun/misc/Perf.java

Print this page




  50  * @see      java.nio.ByteBuffer
  51  */
  52 public final class Perf {
  53 
  54     private static Perf instance;
  55 
  56     private static final int PERF_MODE_RO = 0;
  57     private static final int PERF_MODE_RW = 1;
  58 
  59     private Perf() { }    // prevent instantiation
  60 
  61     /**
  62      * The GetPerfAction class is a convenience class for acquiring access
  63      * to the singleton Perf instance using the
  64      * <code>AccessController.doPrivileged()</code> method.
  65      * <p>
  66      * An instance of this class can be used as the argument to
  67      * <code>AccessController.doPrivileged(PrivilegedAction)</code>.
  68      * <p> Here is a suggested idiom for use of this class:
  69      *
  70      * <blockquote><pre>
  71      * class MyTrustedClass {
  72      *   private static final Perf perf =
  73      *       AccessController.doPrivileged(new Perf.GetPerfAction<Perf>());
  74      *   ...
  75      * }
  76      * </pre></blockquote>
  77      * <p>
  78      * In the presence of a security manager, the <code>MyTrustedClass</code>
  79      * class in the above example will need to be granted the
  80      * <em>"sun.misc.Perf.getPerf"</em> <code>RuntimePermission</code>
  81      * permission in order to successfully acquire the singleton Perf instance.
  82      * <p>
  83      * Please note that the <em>"sun.misc.Perf.getPerf"</em> permission
  84      * is not a JDK specified permission.
  85      *
  86      * @see  java.security.AccessController#doPrivileged(PrivilegedAction)
  87      * @see  java.lang.RuntimePermission
  88      */
  89     public static class GetPerfAction implements PrivilegedAction<Perf>
  90     {
  91         /**
  92          * Run the <code>Perf.getPerf()</code> method in a privileged context.
  93          *
  94          * @see #getPerf
  95          */
  96         public Perf run() {


 154      * the target Java virtual machine.
 155      * <p>
 156      * If the <code>lvmid</code> identifies a Java virtual machine different
 157      * from the one running this method, then the coherency characteristics
 158      * of the buffer are implementation dependent. Implementations that do
 159      * not support named, coherent, shared memory may return a
 160      * <code>ByteBuffer</code> object that contains only a snap shot of the
 161      * data in the instrumentation buffer. Implementations that support named,
 162      * coherent, shared memory, may return a <code>ByteBuffer</code> object
 163      * that will be changing dynamically over time as the target Java virtual
 164      * machine updates its mapping of this buffer.
 165      * <p>
 166      * If the <code>lvmid</code> is 0 or equal to the actual <code>lvmid</code>
 167      * for the Java virtual machine running this method, then the returned
 168      * <code>ByteBuffer</code> object will always be coherent and dynamically
 169      * changing.
 170      * <p>
 171      * The attach mode specifies the access permissions requested for the
 172      * instrumentation buffer of the target virtual machine. The permitted
 173      * access permissions are:
 174      * <p>
 175      * <bl>
 176      * <li>"r"  - Read only access. This Java virtual machine has only
 177      * read access to the instrumentation buffer for the target Java
 178      * virtual machine.
 179      * <li>"rw"  - Read/Write access. This Java virtual machine has read and
 180      * write access to the instrumentation buffer for the target Java virtual
 181      * machine. This mode is currently not supported and is reserved for
 182      * future enhancements.
 183      * </bl>
 184      *
 185      * @param   lvmid            an integer that uniquely identifies the
 186      *                           target local Java virtual machine.
 187      * @param   mode             a string indicating the attach mode.
 188      * @return  ByteBuffer       a direct allocated byte buffer
 189      * @throws  IllegalArgumentException  The lvmid or mode was invalid.
 190      * @throws  IOException      An I/O error occurred while trying to acquire
 191      *                           the instrumentation buffer.
 192      * @throws  OutOfMemoryError The instrumentation buffer could not be mapped
 193      *                           into the virtual machine's address space.
 194      * @see     java.nio.ByteBuffer
 195      */
 196     public ByteBuffer attach(int lvmid, String mode)
 197            throws IllegalArgumentException, IOException
 198     {
 199         if (mode.compareTo("r") == 0) {
 200             return attachImpl(null, lvmid, PERF_MODE_RO);
 201         }
 202         else if (mode.compareTo("rw") == 0) {
 203             return attachImpl(null, lvmid, PERF_MODE_RW);




  50  * @see      java.nio.ByteBuffer
  51  */
  52 public final class Perf {
  53 
  54     private static Perf instance;
  55 
  56     private static final int PERF_MODE_RO = 0;
  57     private static final int PERF_MODE_RW = 1;
  58 
  59     private Perf() { }    // prevent instantiation
  60 
  61     /**
  62      * The GetPerfAction class is a convenience class for acquiring access
  63      * to the singleton Perf instance using the
  64      * <code>AccessController.doPrivileged()</code> method.
  65      * <p>
  66      * An instance of this class can be used as the argument to
  67      * <code>AccessController.doPrivileged(PrivilegedAction)</code>.
  68      * <p> Here is a suggested idiom for use of this class:
  69      *
  70      * <blockquote><pre>{@code
  71      * class MyTrustedClass {
  72      *   private static final Perf perf =
  73      *       AccessController.doPrivileged(new Perf.GetPerfAction<Perf>());
  74      *   ...
  75      * }
  76      * }</pre></blockquote>
  77      * <p>
  78      * In the presence of a security manager, the <code>MyTrustedClass</code>
  79      * class in the above example will need to be granted the
  80      * <em>"sun.misc.Perf.getPerf"</em> <code>RuntimePermission</code>
  81      * permission in order to successfully acquire the singleton Perf instance.
  82      * <p>
  83      * Please note that the <em>"sun.misc.Perf.getPerf"</em> permission
  84      * is not a JDK specified permission.
  85      *
  86      * @see  java.security.AccessController#doPrivileged(PrivilegedAction)
  87      * @see  java.lang.RuntimePermission
  88      */
  89     public static class GetPerfAction implements PrivilegedAction<Perf>
  90     {
  91         /**
  92          * Run the <code>Perf.getPerf()</code> method in a privileged context.
  93          *
  94          * @see #getPerf
  95          */
  96         public Perf run() {


 154      * the target Java virtual machine.
 155      * <p>
 156      * If the <code>lvmid</code> identifies a Java virtual machine different
 157      * from the one running this method, then the coherency characteristics
 158      * of the buffer are implementation dependent. Implementations that do
 159      * not support named, coherent, shared memory may return a
 160      * <code>ByteBuffer</code> object that contains only a snap shot of the
 161      * data in the instrumentation buffer. Implementations that support named,
 162      * coherent, shared memory, may return a <code>ByteBuffer</code> object
 163      * that will be changing dynamically over time as the target Java virtual
 164      * machine updates its mapping of this buffer.
 165      * <p>
 166      * If the <code>lvmid</code> is 0 or equal to the actual <code>lvmid</code>
 167      * for the Java virtual machine running this method, then the returned
 168      * <code>ByteBuffer</code> object will always be coherent and dynamically
 169      * changing.
 170      * <p>
 171      * The attach mode specifies the access permissions requested for the
 172      * instrumentation buffer of the target virtual machine. The permitted
 173      * access permissions are:
 174      * <ul>

 175      * <li>"r"  - Read only access. This Java virtual machine has only
 176      * read access to the instrumentation buffer for the target Java
 177      * virtual machine.
 178      * <li>"rw"  - Read/Write access. This Java virtual machine has read and
 179      * write access to the instrumentation buffer for the target Java virtual
 180      * machine. This mode is currently not supported and is reserved for
 181      * future enhancements.
 182      * </ul>
 183      *
 184      * @param   lvmid            an integer that uniquely identifies the
 185      *                           target local Java virtual machine.
 186      * @param   mode             a string indicating the attach mode.
 187      * @return  ByteBuffer       a direct allocated byte buffer
 188      * @throws  IllegalArgumentException  The lvmid or mode was invalid.
 189      * @throws  IOException      An I/O error occurred while trying to acquire
 190      *                           the instrumentation buffer.
 191      * @throws  OutOfMemoryError The instrumentation buffer could not be mapped
 192      *                           into the virtual machine's address space.
 193      * @see     java.nio.ByteBuffer
 194      */
 195     public ByteBuffer attach(int lvmid, String mode)
 196            throws IllegalArgumentException, IOException
 197     {
 198         if (mode.compareTo("r") == 0) {
 199             return attachImpl(null, lvmid, PERF_MODE_RO);
 200         }
 201         else if (mode.compareTo("rw") == 0) {
 202             return attachImpl(null, lvmid, PERF_MODE_RW);


< prev index next >