8146736: Move sun.misc performance counters to jdk.internal.perf

Reviewed-by: alanb, mchung, rriggs
This commit is contained in:
Chris Hegarty 2016-01-13 14:32:42 +00:00
parent 9884b80330
commit ed581c190a
11 changed files with 51 additions and 38 deletions

View File

@ -50,6 +50,8 @@ import java.util.Vector;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import jdk.internal.perf.PerfCounter;
import sun.misc.Resource; import sun.misc.Resource;
import sun.misc.URLClassPath; import sun.misc.URLClassPath;
import sun.reflect.CallerSensitive; import sun.reflect.CallerSensitive;
@ -423,9 +425,9 @@ public abstract class ClassLoader {
c = findClass(name); c = findClass(name);
// this is the defining class loader; record the stats // this is the defining class loader; record the stats
sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); PerfCounter.getParentDelegationTime().addTime(t1 - t0);
sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
sun.misc.PerfCounter.getFindClasses().increment(); PerfCounter.getFindClasses().increment();
} }
} }
if (resolve) { if (resolve) {

View File

@ -52,6 +52,7 @@ import java.util.jar.Manifest;
import jdk.internal.misc.JavaNetAccess; import jdk.internal.misc.JavaNetAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import jdk.internal.perf.PerfCounter;
import sun.misc.Resource; import sun.misc.Resource;
import sun.misc.URLClassPath; import sun.misc.URLClassPath;
import sun.net.www.ParseUtil; import sun.net.www.ParseUtil;
@ -459,14 +460,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
// Use (direct) ByteBuffer: // Use (direct) ByteBuffer:
CodeSigner[] signers = res.getCodeSigners(); CodeSigner[] signers = res.getCodeSigners();
CodeSource cs = new CodeSource(url, signers); CodeSource cs = new CodeSource(url, signers);
sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0); PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
return defineClass(name, bb, cs); return defineClass(name, bb, cs);
} else { } else {
byte[] b = res.getBytes(); byte[] b = res.getBytes();
// must read certificates AFTER reading bytes. // must read certificates AFTER reading bytes.
CodeSigner[] signers = res.getCodeSigners(); CodeSigner[] signers = res.getCodeSigners();
CodeSource cs = new CodeSource(url, signers); CodeSource cs = new CodeSource(url, signers);
sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0); PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
return defineClass(name, b, 0, b.length, cs); return defineClass(name, b, 0, b.length, cs);
} }
} }

View File

@ -54,6 +54,7 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import jdk.internal.misc.JavaUtilZipFileAccess; import jdk.internal.misc.JavaUtilZipFileAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import jdk.internal.perf.PerfCounter;
import static java.util.zip.ZipConstants.*; import static java.util.zip.ZipConstants.*;
import static java.util.zip.ZipConstants64.*; import static java.util.zip.ZipConstants64.*;
@ -210,8 +211,8 @@ class ZipFile implements ZipConstants, Closeable {
this.name = name; this.name = name;
long t0 = System.nanoTime(); long t0 = System.nanoTime();
this.zsrc = Source.get(file, (mode & OPEN_DELETE) != 0); this.zsrc = Source.get(file, (mode & OPEN_DELETE) != 0);
sun.misc.PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0); PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
sun.misc.PerfCounter.getZipFileCount().increment(); PerfCounter.getZipFileCount().increment();
} }
/** /**

View File

@ -22,13 +22,14 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package sun.misc; package jdk.internal.perf;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.Permission; import java.security.Permission;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import jdk.internal.ref.CleanerFactory;
/** /**
* The Perf class provides the ability to attach to an instrumentation * The Perf class provides the ability to attach to an instrumentation
@ -46,7 +47,7 @@ import java.io.UnsupportedEncodingException;
* @author Brian Doherty * @author Brian Doherty
* @since 1.4.2 * @since 1.4.2
* @see #getPerf * @see #getPerf
* @see sun.misc.Perf$GetPerfAction * @see jdk.internal.perf.Perf.GetPerfAction
* @see java.nio.ByteBuffer * @see java.nio.ByteBuffer
*/ */
public final class Perf { public final class Perf {
@ -124,9 +125,9 @@ public final class Perf {
* is not a JDK specified permission. * is not a JDK specified permission.
* *
* @return A reference to the singleton Perf instance. * @return A reference to the singleton Perf instance.
* @throws AccessControlException if a security manager exists and * @throws SecurityException if a security manager exists and its
* its <code>checkPermission</code> method doesn't allow * <code>checkPermission</code> method doesn't allow access
* access to the <em>"sun.misc.Perf.getPerf"</em> target. * to the <em>"jdk.internal.perf.Perf.getPerf""</em> target.
* @see java.lang.RuntimePermission * @see java.lang.RuntimePermission
* @see #attach * @see #attach
*/ */
@ -134,7 +135,7 @@ public final class Perf {
{ {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
if (security != null) { if (security != null) {
Permission perm = new RuntimePermission("sun.misc.Perf.getPerf"); Permission perm = new RuntimePermission("jdk.internal.perf.Perf.getPerf");
security.checkPermission(perm); security.checkPermission(perm);
} }
@ -277,25 +278,33 @@ public final class Perf {
// This is an instrumentation buffer for another Java virtual // This is an instrumentation buffer for another Java virtual
// machine with native resources that need to be managed. We // machine with native resources that need to be managed. We
// create a duplicate of the native ByteBuffer and manage it // create a duplicate of the native ByteBuffer and manage it
// with a Cleaner object (PhantomReference). When the duplicate // with a Cleaner. When the duplicate becomes phantom reachable,
// becomes only phantomly reachable, the native resources will // the native resources will be released.
// be released.
final ByteBuffer dup = b.duplicate(); final ByteBuffer dup = b.duplicate();
Cleaner.create(dup, new Runnable() {
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() { public void run() {
try { try {
instance.detach(b); perf.detach(bb);
} } catch (Throwable th) {
catch (Throwable th) {
// avoid crashing the reference handler thread, // avoid crashing the reference handler thread,
// but provide for some diagnosability // but provide for some diagnosability
assert false : th.toString(); assert false : th.toString();
} }
} }
});
return dup;
}
} }
/** /**
@ -341,7 +350,7 @@ public final class Perf {
* machine running this method (lvmid=0, for example), then the detach * machine running this method (lvmid=0, for example), then the detach
* request is silently ignored. * request is silently ignored.
* *
* @param ByteBuffer A direct allocated byte buffer created by the * @param bb A direct allocated byte buffer created by the
* <code>attach</code> method. * <code>attach</code> method.
* @see java.nio.ByteBuffer * @see java.nio.ByteBuffer
* @see #attach * @see #attach

View File

@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.misc; package jdk.internal.perf;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;

View File

@ -38,6 +38,7 @@ import java.awt.event.WindowListener;
import java.awt.peer.WindowPeer; import java.awt.peer.WindowPeer;
import java.util.ArrayList; import java.util.ArrayList;
import jdk.internal.perf.PerfCounter;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.ComponentAccessor; import sun.awt.AWTAccessor.ComponentAccessor;
import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsDevice;
@ -69,9 +70,9 @@ public class D3DGraphicsDevice extends Win32GraphicsDevice {
if (d3dAvailable) { if (d3dAvailable) {
// we don't use pixel formats for the d3d pipeline // we don't use pixel formats for the d3d pipeline
pfDisabled = true; pfDisabled = true;
sun.misc.PerfCounter.getD3DAvailable().set(1); PerfCounter.getD3DAvailable().set(1);
} else { } else {
sun.misc.PerfCounter.getD3DAvailable().set(0); PerfCounter.getD3DAvailable().set(0);
} }
} }

View File

@ -34,7 +34,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import sun.misc.Perf; import jdk.internal.perf.Perf;
import sun.management.counter.Units; import sun.management.counter.Units;
import sun.management.counter.Counter; import sun.management.counter.Counter;
import sun.management.counter.perf.PerfInstrumentation; import sun.management.counter.perf.PerfInstrumentation;

View File

@ -25,7 +25,7 @@
package sun.management; package sun.management;
import sun.misc.Perf; import jdk.internal.perf.Perf;
import sun.management.counter.*; import sun.management.counter.*;
import sun.management.counter.perf.*; import sun.management.counter.perf.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -95,7 +95,7 @@ public abstract class AbstractMonitoredVm implements BufferedMonitoredVm {
public void detach() { public void detach() {
/* /*
* no default action required because the detach operation for the * no default action required because the detach operation for the
* native byte buffer is managed by the sun.misc.Perf class. * native byte buffer is managed by the Perf class.
*/ */
} }

View File

@ -25,7 +25,6 @@
package sun.jvmstat.perfdata.monitor; package sun.jvmstat.perfdata.monitor;
import sun.misc.Perf;
import sun.jvmstat.monitor.*; import sun.jvmstat.monitor.*;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;

View File

@ -25,7 +25,7 @@
package sun.jvmstat.perfdata.monitor.protocol.local; package sun.jvmstat.perfdata.monitor.protocol.local;
import sun.misc.Perf; import jdk.internal.perf.Perf;
import sun.jvmstat.monitor.*; import sun.jvmstat.monitor.*;
import sun.jvmstat.perfdata.monitor.*; import sun.jvmstat.perfdata.monitor.*;
import java.util.*; import java.util.*;