提交 aafb7ceb 编写于 作者: A alanb

6844054: (bf) Eliminate dependency on javax.management.ObjectName

Reviewed-by: mchung
上级 2f6c346f
......@@ -34,7 +34,6 @@ import java.util.logging.LoggingMXBean;
import java.util.logging.LogManager;
import java.nio.BufferPoolMXBean;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import com.sun.management.HotSpotDiagnosticMXBean;
......@@ -198,10 +197,7 @@ enum PlatformComponent {
"java.nio", "BufferPool", keyProperties("name"),
new MXBeanFetcher<BufferPoolMXBean>() {
public List<BufferPoolMXBean> getMXBeans() {
List<BufferPoolMXBean> pools = new ArrayList<BufferPoolMXBean>(2);
pools.add( sun.misc.SharedSecrets.getJavaNioAccess().getDirectBufferPoolMXBean() );
pools.add( sun.nio.ch.FileChannelImpl.getMappedBufferPoolMXBean() );
return pools;
return ManagementFactoryHelper.getBufferPoolMXBeans();
}
}),
......
......@@ -26,11 +26,8 @@
package java.nio;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.misc.Unsafe;
import sun.misc.VM;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
/**
* Access to bits, native and otherwise.
......@@ -676,55 +673,34 @@ class Bits { // package-private
}
}
// -- Management interface for monitoring of direct buffer usage --
// -- Monitoring of direct buffer usage --
static {
// setup access to this package in SharedSecrets
sun.misc.SharedSecrets.setJavaNioAccess(
new sun.misc.JavaNioAccess() {
@Override
public BufferPoolMXBean getDirectBufferPoolMXBean() {
return LazyInitialization.directBufferPoolMXBean;
public sun.misc.JavaNioAccess.BufferPool getDirectBufferPool() {
return new sun.misc.JavaNioAccess.BufferPool() {
@Override
public String getName() {
return "direct";
}
@Override
public long getCount() {
return Bits.count;
}
@Override
public long getTotalCapacity() {
return Bits.usedMemory;
}
@Override
public long getMemoryUsed() {
return Bits.reservedMemory;
}
};
}
}
);
}
// Lazy initialization of management interface
private static class LazyInitialization {
static final BufferPoolMXBean directBufferPoolMXBean = directBufferPoolMXBean();
private static BufferPoolMXBean directBufferPoolMXBean() {
final String pool = "direct";
final ObjectName obj;
try {
obj = new ObjectName("java.nio:type=BufferPool,name=" + pool);
} catch (MalformedObjectNameException x) {
throw new AssertionError(x);
}
return new BufferPoolMXBean() {
@Override
public ObjectName getObjectName() {
return obj;
}
@Override
public String getName() {
return pool;
}
@Override
public long getCount() {
return Bits.count;
}
@Override
public long getTotalCapacity() {
return Bits.usedMemory;
}
@Override
public long getMemoryUsed() {
return Bits.reservedMemory;
}
};
}
});
}
// -- Bulk get/put acceleration --
......
......@@ -30,7 +30,6 @@ package java.nio;
import sun.misc.Cleaner;
import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;
import sun.nio.ch.FileChannelImpl;
class Direct$Type$Buffer$RW$$BO$
......
......@@ -26,22 +26,15 @@
package sun.management;
import java.lang.management.*;
import java.util.logging.LogManager;
import javax.management.DynamicMBean;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MBeanInfo;
import javax.management.NotificationEmitter;
import javax.management.ObjectName;
import javax.management.ObjectInstance;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.NotCompliantMBeanException;
import javax.management.RuntimeOperationsException;
import javax.management.StandardEmitterMBean;
import javax.management.StandardMBean;
import java.nio.BufferPoolMXBean;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
......@@ -49,11 +42,6 @@ import sun.security.action.LoadLibraryAction;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import java.util.ListIterator;
import com.sun.management.OSMBeanFactory;
import com.sun.management.HotSpotDiagnosticMXBean;
......@@ -68,7 +56,6 @@ public class ManagementFactoryHelper {
private static VMManagement jvm;
private static boolean mbeansCreated = false;
private static ClassLoadingImpl classMBean = null;
private static MemoryImpl memoryMBean = null;
private static ThreadImpl threadMBean = null;
......@@ -148,6 +135,58 @@ public class ManagementFactoryHelper {
return result;
}
public static List<BufferPoolMXBean> getBufferPoolMXBeans() {
List<BufferPoolMXBean> pools = new ArrayList<BufferPoolMXBean>(2);
pools.add(createBufferPoolMXBean(sun.misc.SharedSecrets.getJavaNioAccess()
.getDirectBufferPool()));
pools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl
.getMappedBufferPool()));
return pools;
}
private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool";
/**
* Creates management interface for the given buffer pool.
*/
private static BufferPoolMXBean
createBufferPoolMXBean(final sun.misc.JavaNioAccess.BufferPool pool)
{
return new BufferPoolMXBean() {
private volatile ObjectName objname; // created lazily
@Override
public ObjectName getObjectName() {
ObjectName result = objname;
if (result == null) {
synchronized (this) {
if (objname == null) {
result = ObjectName.valueOf(BUFFER_POOL_MXBEAN_NAME +
",name=" + pool.getName());
objname = result;
}
}
}
return result;
}
@Override
public String getName() {
return pool.getName();
}
@Override
public long getCount() {
return pool.getCount();
}
@Override
public long getTotalCapacity() {
return pool.getTotalCapacity();
}
@Override
public long getMemoryUsed() {
return pool.getMemoryUsed();
}
};
}
private static HotSpotDiagnostic hsDiagMBean = null;
private static HotspotRuntime hsRuntimeMBean = null;
private static HotspotClassLoading hsClassMBean = null;
......@@ -162,8 +201,6 @@ public class ManagementFactoryHelper {
return hsDiagMBean;
}
/**
/**
* This method is for testing only.
*/
......
......@@ -25,8 +25,15 @@
package sun.misc;
import java.nio.BufferPoolMXBean;
public interface JavaNioAccess {
BufferPoolMXBean getDirectBufferPoolMXBean();
/**
* Provides access to information on buffer usage.
*/
interface BufferPool {
String getName();
long getCount();
long getTotalCapacity();
long getMemoryUsed();
}
BufferPool getDirectBufferPool();
}
......@@ -29,13 +29,10 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.BufferPoolMXBean;
import java.nio.channels.*;
import java.util.ArrayList;
import java.util.List;
import java.security.AccessController;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import sun.misc.Cleaner;
import sun.security.action.GetPropertyAction;
......@@ -805,47 +802,28 @@ public class FileChannelImpl
}
/**
* Returns the management interface for mapped buffers
* Invoked by sun.management.ManagementFactoryHelper to create the management
* interface for mapped buffers.
*/
public static BufferPoolMXBean getMappedBufferPoolMXBean() {
return LazyInitialization.mappedBufferPoolMXBean;
}
// Lazy initialization of management interface
private static class LazyInitialization {
static final BufferPoolMXBean mappedBufferPoolMXBean = mappedBufferPoolMXBean();
private static BufferPoolMXBean mappedBufferPoolMXBean() {
final String pool = "mapped";
final ObjectName obj;
try {
obj = new ObjectName("java.nio:type=BufferPool,name=" + pool);
} catch (MalformedObjectNameException x) {
throw new AssertionError(x);
public static sun.misc.JavaNioAccess.BufferPool getMappedBufferPool() {
return new sun.misc.JavaNioAccess.BufferPool() {
@Override
public String getName() {
return "mapped";
}
return new BufferPoolMXBean() {
@Override
public ObjectName getObjectName() {
return obj;
}
@Override
public String getName() {
return pool;
}
@Override
public long getCount() {
return Unmapper.count;
}
@Override
public long getTotalCapacity() {
return Unmapper.totalCapacity;
}
@Override
public long getMemoryUsed() {
return Unmapper.totalSize;
}
};
}
@Override
public long getCount() {
return Unmapper.count;
}
@Override
public long getTotalCapacity() {
return Unmapper.totalCapacity;
}
@Override
public long getMemoryUsed() {
return Unmapper.totalSize;
}
};
}
// -- Locks --
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册