6844054: (bf) Eliminate dependency on javax.management.ObjectName
Reviewed-by: mchung
This commit is contained in:
parent
212565afd7
commit
9b6fcc28d2
@ -34,7 +34,6 @@ import java.util.logging.LoggingMXBean;
|
|||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import java.nio.BufferPoolMXBean;
|
import java.nio.BufferPoolMXBean;
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import com.sun.management.HotSpotDiagnosticMXBean;
|
import com.sun.management.HotSpotDiagnosticMXBean;
|
||||||
@ -198,10 +197,7 @@ enum PlatformComponent {
|
|||||||
"java.nio", "BufferPool", keyProperties("name"),
|
"java.nio", "BufferPool", keyProperties("name"),
|
||||||
new MXBeanFetcher<BufferPoolMXBean>() {
|
new MXBeanFetcher<BufferPoolMXBean>() {
|
||||||
public List<BufferPoolMXBean> getMXBeans() {
|
public List<BufferPoolMXBean> getMXBeans() {
|
||||||
List<BufferPoolMXBean> pools = new ArrayList<BufferPoolMXBean>(2);
|
return ManagementFactoryHelper.getBufferPoolMXBeans();
|
||||||
pools.add( sun.misc.SharedSecrets.getJavaNioAccess().getDirectBufferPoolMXBean() );
|
|
||||||
pools.add( sun.nio.ch.FileChannelImpl.getMappedBufferPoolMXBean() );
|
|
||||||
return pools;
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -26,11 +26,8 @@
|
|||||||
package java.nio;
|
package java.nio;
|
||||||
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
import sun.misc.VM;
|
import sun.misc.VM;
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access to bits, native and otherwise.
|
* 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 {
|
static {
|
||||||
// setup access to this package in SharedSecrets
|
// setup access to this package in SharedSecrets
|
||||||
sun.misc.SharedSecrets.setJavaNioAccess(
|
sun.misc.SharedSecrets.setJavaNioAccess(
|
||||||
new sun.misc.JavaNioAccess() {
|
new sun.misc.JavaNioAccess() {
|
||||||
@Override
|
@Override
|
||||||
public BufferPoolMXBean getDirectBufferPoolMXBean() {
|
public sun.misc.JavaNioAccess.BufferPool getDirectBufferPool() {
|
||||||
return LazyInitialization.directBufferPoolMXBean;
|
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 --
|
// -- Bulk get/put acceleration --
|
||||||
|
@ -30,7 +30,6 @@ package java.nio;
|
|||||||
import sun.misc.Cleaner;
|
import sun.misc.Cleaner;
|
||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
import sun.nio.ch.DirectBuffer;
|
import sun.nio.ch.DirectBuffer;
|
||||||
import sun.nio.ch.FileChannelImpl;
|
|
||||||
|
|
||||||
|
|
||||||
class Direct$Type$Buffer$RW$$BO$
|
class Direct$Type$Buffer$RW$$BO$
|
||||||
|
@ -26,22 +26,15 @@
|
|||||||
package sun.management;
|
package sun.management;
|
||||||
|
|
||||||
import java.lang.management.*;
|
import java.lang.management.*;
|
||||||
import java.util.logging.LogManager;
|
|
||||||
|
|
||||||
import javax.management.DynamicMBean;
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
|
||||||
import javax.management.MBeanInfo;
|
|
||||||
import javax.management.NotificationEmitter;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.ObjectInstance;
|
|
||||||
import javax.management.InstanceAlreadyExistsException;
|
import javax.management.InstanceAlreadyExistsException;
|
||||||
import javax.management.InstanceNotFoundException;
|
import javax.management.InstanceNotFoundException;
|
||||||
import javax.management.MBeanRegistrationException;
|
import javax.management.MBeanRegistrationException;
|
||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
import javax.management.RuntimeOperationsException;
|
import javax.management.RuntimeOperationsException;
|
||||||
import javax.management.StandardEmitterMBean;
|
import java.nio.BufferPoolMXBean;
|
||||||
import javax.management.StandardMBean;
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedActionException;
|
import java.security.PrivilegedActionException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
@ -49,11 +42,6 @@ import sun.security.action.LoadLibraryAction;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.OSMBeanFactory;
|
||||||
import com.sun.management.HotSpotDiagnosticMXBean;
|
import com.sun.management.HotSpotDiagnosticMXBean;
|
||||||
|
|
||||||
@ -68,7 +56,6 @@ public class ManagementFactoryHelper {
|
|||||||
|
|
||||||
private static VMManagement jvm;
|
private static VMManagement jvm;
|
||||||
|
|
||||||
private static boolean mbeansCreated = false;
|
|
||||||
private static ClassLoadingImpl classMBean = null;
|
private static ClassLoadingImpl classMBean = null;
|
||||||
private static MemoryImpl memoryMBean = null;
|
private static MemoryImpl memoryMBean = null;
|
||||||
private static ThreadImpl threadMBean = null;
|
private static ThreadImpl threadMBean = null;
|
||||||
@ -148,6 +135,58 @@ public class ManagementFactoryHelper {
|
|||||||
return result;
|
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 HotSpotDiagnostic hsDiagMBean = null;
|
||||||
private static HotspotRuntime hsRuntimeMBean = null;
|
private static HotspotRuntime hsRuntimeMBean = null;
|
||||||
private static HotspotClassLoading hsClassMBean = null;
|
private static HotspotClassLoading hsClassMBean = null;
|
||||||
@ -162,8 +201,6 @@ public class ManagementFactoryHelper {
|
|||||||
return hsDiagMBean;
|
return hsDiagMBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is for testing only.
|
* This method is for testing only.
|
||||||
*/
|
*/
|
||||||
|
@ -25,8 +25,15 @@
|
|||||||
|
|
||||||
package sun.misc;
|
package sun.misc;
|
||||||
|
|
||||||
import java.nio.BufferPoolMXBean;
|
|
||||||
|
|
||||||
public interface JavaNioAccess {
|
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.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.MappedByteBuffer;
|
import java.nio.MappedByteBuffer;
|
||||||
import java.nio.BufferPoolMXBean;
|
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import sun.misc.Cleaner;
|
import sun.misc.Cleaner;
|
||||||
import sun.security.action.GetPropertyAction;
|
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() {
|
public static sun.misc.JavaNioAccess.BufferPool getMappedBufferPool() {
|
||||||
return LazyInitialization.mappedBufferPoolMXBean;
|
return new sun.misc.JavaNioAccess.BufferPool() {
|
||||||
}
|
@Override
|
||||||
|
public String getName() {
|
||||||
// Lazy initialization of management interface
|
return "mapped";
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return new BufferPoolMXBean() {
|
@Override
|
||||||
@Override
|
public long getCount() {
|
||||||
public ObjectName getObjectName() {
|
return Unmapper.count;
|
||||||
return obj;
|
}
|
||||||
}
|
@Override
|
||||||
@Override
|
public long getTotalCapacity() {
|
||||||
public String getName() {
|
return Unmapper.totalCapacity;
|
||||||
return pool;
|
}
|
||||||
}
|
@Override
|
||||||
@Override
|
public long getMemoryUsed() {
|
||||||
public long getCount() {
|
return Unmapper.totalSize;
|
||||||
return Unmapper.count;
|
}
|
||||||
}
|
};
|
||||||
@Override
|
|
||||||
public long getTotalCapacity() {
|
|
||||||
return Unmapper.totalCapacity;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public long getMemoryUsed() {
|
|
||||||
return Unmapper.totalSize;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Locks --
|
// -- Locks --
|
||||||
|
Loading…
x
Reference in New Issue
Block a user