diff --git a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
index 76cdd25dcd7..1bb15800454 100644
--- a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
@@ -50,6 +50,8 @@ import java.util.Vector;
import java.util.Hashtable;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
+
+import jdk.internal.perf.PerfCounter;
import sun.misc.Resource;
import sun.misc.URLClassPath;
import sun.reflect.CallerSensitive;
@@ -423,9 +425,9 @@ public abstract class ClassLoader {
c = findClass(name);
// this is the defining class loader; record the stats
- sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
- sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
- sun.misc.PerfCounter.getFindClasses().increment();
+ PerfCounter.getParentDelegationTime().addTime(t1 - t0);
+ PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
+ PerfCounter.getFindClasses().increment();
}
}
if (resolve) {
diff --git a/jdk/src/java.base/share/classes/java/net/URLClassLoader.java b/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
index 05ebeed39a5..1cf064d1afa 100644
--- a/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
@@ -52,6 +52,7 @@ import java.util.jar.Manifest;
import jdk.internal.misc.JavaNetAccess;
import jdk.internal.misc.SharedSecrets;
+import jdk.internal.perf.PerfCounter;
import sun.misc.Resource;
import sun.misc.URLClassPath;
import sun.net.www.ParseUtil;
@@ -459,14 +460,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
// Use (direct) ByteBuffer:
CodeSigner[] signers = res.getCodeSigners();
CodeSource cs = new CodeSource(url, signers);
- sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
+ PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
return defineClass(name, bb, cs);
} else {
byte[] b = res.getBytes();
// must read certificates AFTER reading bytes.
CodeSigner[] signers = res.getCodeSigners();
CodeSource cs = new CodeSource(url, signers);
- sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
+ PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
return defineClass(name, b, 0, b.length, cs);
}
}
diff --git a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
index 31ff8eaf329..1cba038d6e5 100644
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
@@ -54,6 +54,7 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.misc.JavaUtilZipFileAccess;
import jdk.internal.misc.SharedSecrets;
+import jdk.internal.perf.PerfCounter;
import static java.util.zip.ZipConstants.*;
import static java.util.zip.ZipConstants64.*;
@@ -210,8 +211,8 @@ class ZipFile implements ZipConstants, Closeable {
this.name = name;
long t0 = System.nanoTime();
this.zsrc = Source.get(file, (mode & OPEN_DELETE) != 0);
- sun.misc.PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
- sun.misc.PerfCounter.getZipFileCount().increment();
+ PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
+ PerfCounter.getZipFileCount().increment();
}
/**
diff --git a/jdk/src/java.base/share/classes/sun/misc/Perf.java b/jdk/src/java.base/share/classes/jdk/internal/perf/Perf.java
similarity index 94%
rename from jdk/src/java.base/share/classes/sun/misc/Perf.java
rename to jdk/src/java.base/share/classes/jdk/internal/perf/Perf.java
index 311e92c8f64..e660cdf3ebe 100644
--- a/jdk/src/java.base/share/classes/sun/misc/Perf.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/perf/Perf.java
@@ -22,13 +22,14 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-package sun.misc;
+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
@@ -46,7 +47,7 @@ import java.io.UnsupportedEncodingException;
* @author Brian Doherty
* @since 1.4.2
* @see #getPerf
- * @see sun.misc.Perf$GetPerfAction
+ * @see jdk.internal.perf.Perf.GetPerfAction
* @see java.nio.ByteBuffer
*/
public final class Perf {
@@ -123,10 +124,10 @@ public final class Perf {
* Please note that the "sun.misc.Perf.getPerf" permission
* is not a JDK specified permission.
*
- * @return A reference to the singleton Perf instance.
- * @throws AccessControlException if a security manager exists and
- * its checkPermission
method doesn't allow
- * access to the "sun.misc.Perf.getPerf" target.
+ * @return A reference to the singleton Perf instance.
+ * @throws SecurityException if a security manager exists and its
+ * checkPermission
method doesn't allow access
+ * to the "jdk.internal.perf.Perf.getPerf"" target.
* @see java.lang.RuntimePermission
* @see #attach
*/
@@ -134,7 +135,7 @@ public final class Perf {
{
SecurityManager security = System.getSecurityManager();
if (security != null) {
- Permission perm = new RuntimePermission("sun.misc.Perf.getPerf");
+ Permission perm = new RuntimePermission("jdk.internal.perf.Perf.getPerf");
security.checkPermission(perm);
}
@@ -277,27 +278,35 @@ public final class Perf {
// 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.
+ // with a Cleaner. When the duplicate becomes phantom 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();
- }
- }
- });
+
+ 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.
*
@@ -341,7 +350,7 @@ public final class Perf {
* 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
+ * @param bb A direct allocated byte buffer created by the
* attach
method.
* @see java.nio.ByteBuffer
* @see #attach
diff --git a/jdk/src/java.base/share/classes/sun/misc/PerfCounter.java b/jdk/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java
similarity index 99%
rename from jdk/src/java.base/share/classes/sun/misc/PerfCounter.java
rename to jdk/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java
index aa054707937..1c0d0a1f341 100644
--- a/jdk/src/java.base/share/classes/sun/misc/PerfCounter.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java
@@ -23,7 +23,7 @@
* questions.
*/
-package sun.misc;
+package jdk.internal.perf;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
diff --git a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java
index 794746c12a9..8f110fe8c72 100644
--- a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java
+++ b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java
@@ -38,6 +38,7 @@ import java.awt.event.WindowListener;
import java.awt.peer.WindowPeer;
import java.util.ArrayList;
+import jdk.internal.perf.PerfCounter;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.ComponentAccessor;
import sun.awt.Win32GraphicsDevice;
@@ -69,9 +70,9 @@ public class D3DGraphicsDevice extends Win32GraphicsDevice {
if (d3dAvailable) {
// we don't use pixel formats for the d3d pipeline
pfDisabled = true;
- sun.misc.PerfCounter.getD3DAvailable().set(1);
+ PerfCounter.getD3DAvailable().set(1);
} else {
- sun.misc.PerfCounter.getD3DAvailable().set(0);
+ PerfCounter.getD3DAvailable().set(0);
}
}
diff --git a/jdk/src/java.management/share/classes/sun/management/ConnectorAddressLink.java b/jdk/src/java.management/share/classes/sun/management/ConnectorAddressLink.java
index 4ec5ec799cc..b1bd0f311d1 100644
--- a/jdk/src/java.management/share/classes/sun/management/ConnectorAddressLink.java
+++ b/jdk/src/java.management/share/classes/sun/management/ConnectorAddressLink.java
@@ -34,7 +34,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
-import sun.misc.Perf;
+import jdk.internal.perf.Perf;
import sun.management.counter.Units;
import sun.management.counter.Counter;
import sun.management.counter.perf.PerfInstrumentation;
diff --git a/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java b/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java
index d9e8d64b9aa..0600a7aeee0 100644
--- a/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java
+++ b/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java
@@ -25,7 +25,7 @@
package sun.management;
-import sun.misc.Perf;
+import jdk.internal.perf.Perf;
import sun.management.counter.*;
import sun.management.counter.perf.*;
import java.nio.ByteBuffer;
diff --git a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractMonitoredVm.java b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractMonitoredVm.java
index 8df13ca7f30..fc93d5c678e 100644
--- a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractMonitoredVm.java
+++ b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractMonitoredVm.java
@@ -95,7 +95,7 @@ public abstract class AbstractMonitoredVm implements BufferedMonitoredVm {
public void detach() {
/*
* 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.
*/
}
diff --git a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractPerfDataBuffer.java b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractPerfDataBuffer.java
index 7a5e9998bc9..a2d3ad4c2a4 100644
--- a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractPerfDataBuffer.java
+++ b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractPerfDataBuffer.java
@@ -25,7 +25,6 @@
package sun.jvmstat.perfdata.monitor;
-import sun.misc.Perf;
import sun.jvmstat.monitor.*;
import java.util.*;
import java.io.*;
diff --git a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataBuffer.java b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataBuffer.java
index 5932312d1ab..0ab643e106a 100644
--- a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataBuffer.java
+++ b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/PerfDataBuffer.java
@@ -25,7 +25,7 @@
package sun.jvmstat.perfdata.monitor.protocol.local;
-import sun.misc.Perf;
+import jdk.internal.perf.Perf;
import sun.jvmstat.monitor.*;
import sun.jvmstat.perfdata.monitor.*;
import java.util.*;