src/java.base/share/classes/jdk/internal/perf/Perf.java

Print this page

        

*** 20,36 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package sun.misc; import java.nio.ByteBuffer; import java.security.Permission; import java.security.PrivilegedAction; import java.io.IOException; import java.io.UnsupportedEncodingException; /** * The Perf class provides the ability to attach to an instrumentation * buffer maintained by a Java virtual machine. The instrumentation * buffer may be for the Java virtual machine running the methods of --- 20,37 ---- * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package jdk.internal.perf; import java.nio.ByteBuffer; import java.security.Permission; import java.security.PrivilegedAction; import java.io.IOException; import java.io.UnsupportedEncodingException; + import jdk.internal.ref.CleanerFactory; /** * The Perf class provides the ability to attach to an instrumentation * buffer maintained by a Java virtual machine. The instrumentation * buffer may be for the Java virtual machine running the methods of
*** 44,54 **** * stamp and interval measurement purposes. * * @author Brian Doherty * @since 1.4.2 * @see #getPerf ! * @see sun.misc.Perf$GetPerfAction * @see java.nio.ByteBuffer */ public final class Perf { private static Perf instance; --- 45,55 ---- * stamp and interval measurement purposes. * * @author Brian Doherty * @since 1.4.2 * @see #getPerf ! * @see jdk.internal.perf.Perf.GetPerfAction * @see java.nio.ByteBuffer */ public final class Perf { private static Perf instance;
*** 122,142 **** * <p> * Please note that the <em>"sun.misc.Perf.getPerf"</em> permission * is not a JDK specified permission. * * @return A reference to the singleton Perf instance. ! * @throws AccessControlException if a security manager exists and ! * its <code>checkPermission</code> method doesn't allow ! * access to the <em>"sun.misc.Perf.getPerf"</em> target. * @see java.lang.RuntimePermission * @see #attach */ public static Perf getPerf() { SecurityManager security = System.getSecurityManager(); if (security != null) { ! Permission perm = new RuntimePermission("sun.misc.Perf.getPerf"); security.checkPermission(perm); } return instance; } --- 123,143 ---- * <p> * Please note that the <em>"sun.misc.Perf.getPerf"</em> permission * is not a JDK specified permission. * * @return A reference to the singleton Perf instance. ! * @throws SecurityException if a security manager exists and its ! * <code>checkPermission</code> method doesn't allow access ! * to the <em>"jdk.internal.perf.Perf.getPerf""</em> target. * @see java.lang.RuntimePermission * @see #attach */ public static Perf getPerf() { SecurityManager security = System.getSecurityManager(); if (security != null) { ! Permission perm = new RuntimePermission("jdk.internal.perf.Perf.getPerf"); security.checkPermission(perm); } return instance; }
*** 275,303 **** } else { // This is an instrumentation buffer for another Java virtual // machine with native resources that need to be managed. We // create a duplicate of the native ByteBuffer and manage it ! // with a Cleaner object (PhantomReference). When the duplicate ! // becomes only phantomly reachable, the native resources will ! // be released. final ByteBuffer dup = b.duplicate(); ! Cleaner.create(dup, new Runnable() { public void run() { try { ! instance.detach(b); ! } ! catch (Throwable th) { // avoid crashing the reference handler thread, // but provide for some diagnosability assert false : th.toString(); } } - }); - return dup; - } } /** * Native method to perform the implementation specific attach mechanism. * <p> --- 276,312 ---- } else { // This is an instrumentation buffer for another Java virtual // machine with native resources that need to be managed. We // create a duplicate of the native ByteBuffer and manage it ! // with a Cleaner. When the duplicate becomes phantom reachable, ! // the native resources will be released. final ByteBuffer dup = b.duplicate(); ! ! CleanerFactory.cleaner() ! .register(dup, new CleanerAction(instance, b)); ! return dup; ! } ! } ! ! private static class CleanerAction implements Runnable { ! private final ByteBuffer bb; ! private final Perf perf; ! CleanerAction(Perf perf, ByteBuffer bb) { ! this.perf = perf; ! this.bb = bb; ! } public void run() { try { ! perf.detach(bb); ! } catch (Throwable th) { // avoid crashing the reference handler thread, // but provide for some diagnosability assert false : th.toString(); } } } /** * Native method to perform the implementation specific attach mechanism. * <p>
*** 339,349 **** * If this method is passed a <code>ByteBuffer</code> object created * by the <code>attach</code> method with a lvmid for the Java virtual * machine running this method (lvmid=0, for example), then the detach * request is silently ignored. * ! * @param ByteBuffer A direct allocated byte buffer created by the * <code>attach</code> method. * @see java.nio.ByteBuffer * @see #attach */ private native void detach(ByteBuffer bb); --- 348,358 ---- * If this method is passed a <code>ByteBuffer</code> object created * by the <code>attach</code> method with a lvmid for the Java virtual * machine running this method (lvmid=0, for example), then the detach * request is silently ignored. * ! * @param bb A direct allocated byte buffer created by the * <code>attach</code> method. * @see java.nio.ByteBuffer * @see #attach */ private native void detach(ByteBuffer bb);