8042901: Allow com.sun.management to be in a different module to java.lang.management

Reviewed-by: mchung, dfuchs, erikj, jbachorik
This commit is contained in:
Shanliang Jiang 2015-04-17 09:40:02 +02:00
parent cf90c844eb
commit b705686a86
58 changed files with 1207 additions and 545 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -30,28 +30,14 @@ $(eval $(call IncludeCustomExtension, jdk, lib/Lib-java.management.gmk))
################################################################################
BUILD_LIBMANAGEMENT_SRC += $(JDK_TOPDIR)/src/java.management/share/native/libmanagement \
LIBMANAGEMENT_SRC += $(JDK_TOPDIR)/src/java.management/share/native/libmanagement \
$(JDK_TOPDIR)/src/java.management/$(OPENJDK_TARGET_OS_TYPE)/native/libmanagement
BUILD_LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/include \
$(addprefix -I,$(BUILD_LIBMANAGEMENT_SRC)) \
LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/include \
$(addprefix -I,$(LIBMANAGEMENT_SRC)) \
-I$(SUPPORT_OUTPUTDIR)/headers/java.management \
$(LIBJAVA_HEADER_FLAGS) \
#
BUILD_LIBMANAGEMENT_EXCLUDES :=
ifneq ($(OPENJDK_TARGET_OS), solaris)
BUILD_LIBMANAGEMENT_EXCLUDES += SolarisOperatingSystem.c
endif
ifneq ($(OPENJDK_TARGET_OS), linux)
BUILD_LIBMANAGEMENT_EXCLUDES += LinuxOperatingSystem.c
endif
ifneq ($(OPENJDK_TARGET_OS), macosx)
BUILD_LIBMANAGEMENT_EXCLUDES += MacosxOperatingSystem.c
endif
LIBMANAGEMENT_OPTIMIZATION := HIGH
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
@ -59,18 +45,14 @@ ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
endif
endif
# Make it possible to override this variable
LIBMANAGEMENT_MAPFILE ?= $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers
$(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT, \
LIBRARY := management, \
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
SRC := $(BUILD_LIBMANAGEMENT_SRC), \
EXCLUDE_FILES := $(BUILD_LIBMANAGEMENT_EXCLUDES), \
SRC := $(LIBMANAGEMENT_SRC), \
LANG := C, \
OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(BUILD_LIBMANAGEMENT_CFLAGS), \
MAPFILE := $(LIBMANAGEMENT_MAPFILE), \
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(LIBMANAGEMENT_CFLAGS), \
MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LDFLAGS_solaris := -lkstat, \

View File

@ -0,0 +1,75 @@
#
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# 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.
#
include LibCommon.gmk
# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, jdk, lib/Lib-jdk.management.gmk))
################################################################################
LIBMANAGEMENT_EXT_SRC += $(JDK_TOPDIR)/src/jdk.management/share/native/libmanagement_ext \
$(JDK_TOPDIR)/src/jdk.management/$(OPENJDK_TARGET_OS_TYPE)/native/libmanagement_ext \
$(JDK_TOPDIR)/src/jdk.management/$(OPENJDK_TARGET_OS)/native/libmanagement_ext
LIBMANAGEMENT_EXT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/include \
$(addprefix -I,$(LIBMANAGEMENT_EXT_SRC)) \
-I$(SUPPORT_OUTPUTDIR)/headers/jdk.management \
$(LIBJAVA_HEADER_FLAGS) \
#
LIBMANAGEMENT_EXT_OPTIMIZATION := HIGH
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
LIBMANAGEMENT_EXT_OPTIMIZATION := LOW
endif
endif
$(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT_EXT, \
LIBRARY := management_ext, \
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
SRC := $(LIBMANAGEMENT_EXT_SRC), \
LANG := C, \
OPTIMIZATION := $(LIBMANAGEMENT_EXT_OPTIMIZATION), \
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(LIBMANAGEMENT_EXT_CFLAGS), \
MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libmanagement_ext/mapfile-vers, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LDFLAGS_solaris := -lkstat, \
LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
LDFLAGS_SUFFIX_windows := jvm.lib psapi.lib $(WIN_JAVA_LIB) advapi32.lib, \
LDFLAGS_SUFFIX_aix := -lperfstat,\
VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
RC_FLAGS := $(RC_FLAGS) \
-D "JDK_FNAME=management_ext.dll" \
-D "JDK_INTERNAL_NAME=management_ext" \
-D "JDK_FTYPE=0x2L", \
OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libmanagement_ext, \
DEBUG_SYMBOLS := true))
$(BUILD_LIBMANAGEMENT_EXT): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBMANAGEMENT_EXT)
################################################################################

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -27,37 +27,10 @@
SUNWprivate_1.1 {
global:
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0;
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0;
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0;
Java_sun_management_OperatingSystemImpl_getMaxFileDescriptorCount0;
Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0;
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0;
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0;
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0;
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0;
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0;
Java_sun_management_OperatingSystemImpl_initialize0;
Java_sun_management_ClassLoadingImpl_setVerboseClass;
Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand;
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommands;
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo;
Java_sun_management_DiagnosticCommandImpl_setNotificationEnabled;
Java_sun_management_FileSystemImpl_isAccessUserOnly0;
Java_sun_management_Flag_getAllFlagNames;
Java_sun_management_Flag_getFlags;
Java_sun_management_Flag_getInternalFlagCount;
Java_sun_management_Flag_initialize;
Java_sun_management_Flag_setLongValue;
Java_sun_management_Flag_setBooleanValue;
Java_sun_management_Flag_setStringValue;
Java_sun_management_GarbageCollectorImpl_getCollectionCount;
Java_sun_management_FileSystemImpl_isAccessUserOnly0;
Java_sun_management_GarbageCollectorImpl_getCollectionCount;
Java_sun_management_GarbageCollectorImpl_getCollectionTime;
Java_sun_management_GarbageCollectorImpl_setNotificationEnabled;
Java_sun_management_GcInfoBuilder_fillGcAttributeInfo;
Java_sun_management_GcInfoBuilder_getLastGcInfo0;
Java_sun_management_GcInfoBuilder_getNumGcExtAttributes;
Java_sun_management_HotSpotDiagnostic_dumpHeap0;
Java_sun_management_HotspotThread_getInternalThreadCount;
Java_sun_management_HotspotThread_getInternalThreadTimes0;
Java_sun_management_MemoryImpl_getMemoryManagers0;

View File

@ -0,0 +1,60 @@
#
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# 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.
#
# Define library interface.
SUNWprivate_1.1 {
global:
Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0;
Java_com_sun_management_internal_OperatingSystemImpl_getFreePhysicalMemorySize0;
Java_com_sun_management_internal_OperatingSystemImpl_getFreeSwapSpaceSize0;
Java_com_sun_management_internal_OperatingSystemImpl_getMaxFileDescriptorCount0;
Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0;
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0;
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuTime0;
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0;
Java_com_sun_management_internal_OperatingSystemImpl_getTotalPhysicalMemorySize0;
Java_com_sun_management_internal_OperatingSystemImpl_getTotalSwapSpaceSize0;
Java_com_sun_management_internal_OperatingSystemImpl_initialize0;
Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand;
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands;
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo;
Java_com_sun_management_internal_DiagnosticCommandImpl_setNotificationEnabled;
Java_com_sun_management_internal_Flag_getAllFlagNames;
Java_com_sun_management_internal_Flag_getFlags;
Java_com_sun_management_internal_Flag_getInternalFlagCount;
Java_com_sun_management_internal_Flag_initialize;
Java_com_sun_management_internal_Flag_setLongValue;
Java_com_sun_management_internal_Flag_setBooleanValue;
Java_com_sun_management_internal_Flag_setStringValue;
Java_com_sun_management_internal_GarbageCollectorExtImpl_setNotificationEnabled;
Java_com_sun_management_internal_GcInfoBuilder_fillGcAttributeInfo;
Java_com_sun_management_internal_GcInfoBuilder_getLastGcInfo0;
Java_com_sun_management_internal_GcInfoBuilder_getNumGcExtAttributes;
Java_com_sun_management_internal_HotSpotDiagnostic_dumpHeap0;
JNI_OnLoad;
local:
*;
};

View File

@ -22,6 +22,7 @@ jdk.deploy.osx
jdk.hprof.agent
jdk.httpserver
jdk.jfr
jdk.management
jdk.management.cmm
jdk.naming.rmi
jdk.sctp

View File

@ -33,7 +33,6 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.management.DynamicMBean;
import javax.management.ObjectName;
import sun.management.ManagementFactoryHelper;
import sun.management.spi.PlatformMBeanProvider;
@ -162,8 +161,7 @@ class DefaultPlatformMBeanProvider extends PlatformMBeanProvider {
@Override
public Set<Class<? extends MemoryManagerMXBean>> mbeanInterfaces() {
return Stream.of(MemoryManagerMXBean.class,
GarbageCollectorMXBean.class,
com.sun.management.GarbageCollectorMXBean.class).collect(Collectors.toSet());
GarbageCollectorMXBean.class).collect(Collectors.toSet());
}
@Override
@ -464,39 +462,6 @@ class DefaultPlatformMBeanProvider extends PlatformMBeanProvider {
});
/**
* DynamicMBean
*/
HashMap<ObjectName, DynamicMBean> dynmbeans
= ManagementFactoryHelper.getPlatformDynamicMBeans();
final Set<String> dynamicMBeanInterfaceNames =
Collections.unmodifiableSet(Collections.singleton("javax.management.DynamicMBean"));
for (Map.Entry<ObjectName, DynamicMBean> e : dynmbeans.entrySet()) {
initMBeanList.add(new PlatformComponent<DynamicMBean>() {
@Override
public Set<Class<? extends DynamicMBean>> mbeanInterfaces() {
return Collections.emptySet();
}
@Override
public Set<String> mbeanInterfaceNames() {
return dynamicMBeanInterfaceNames;
}
@Override
public String getObjectNamePattern() {
return e.getKey().getCanonicalName();
}
@Override
public Map<String, DynamicMBean> nameToMBeanMap() {
return Collections.<String, DynamicMBean>singletonMap(
e.getKey().getCanonicalName(),
e.getValue());
}
});
}
initMBeanList.trimToSize();
return initMBeanList;
}

View File

@ -582,7 +582,7 @@ public class ManagementFactory {
final Class<?> cls = mxbeanInterface;
ClassLoader loader =
AccessController.doPrivileged(
(PrivilegedAction<ClassLoader>) () -> cls.getClassLoader());
(PrivilegedAction<ClassLoader>) () -> cls.getClassLoader());
if (!sun.misc.VM.isSystemDomainLoader(loader)) {
throw new IllegalArgumentException(mxbeanName +
" is not a platform MXBean");
@ -883,7 +883,7 @@ public class ManagementFactory {
all.add(new DefaultPlatformMBeanProvider());
return all;
}, null, new FilePermission("<<ALL FILES>>", "read"),
new RuntimePermission("sun.management.spi.PlatformMBeanProvider"));
new RuntimePermission("sun.management.spi.PlatformMBeanProvider.subclass"));
// load all platform components into a map
componentMap = providers.stream()
@ -970,4 +970,11 @@ public class ManagementFactory {
return singleton;
}
}
static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("management");
return null;
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,168 +25,31 @@
package sun.management;
import com.sun.management.GarbageCollectorMXBean;
import com.sun.management.GarbageCollectionNotificationInfo;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import com.sun.management.GcInfo;
import javax.management.openmbean.CompositeData;
import javax.management.MBeanInfo;
import javax.management.MBeanAttributeInfo;
import javax.management.ObjectName;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ListenerNotFoundException;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
* Implementation class for the garbage collector.
* Standard and committed hotspot-specific metrics if any.
*
* ManagementFactory.getGarbageCollectorMXBeans() returns a list
* of instances of this class.
*/
class GarbageCollectorImpl extends MemoryManagerImpl
public class GarbageCollectorImpl extends MemoryManagerImpl
implements GarbageCollectorMXBean {
GarbageCollectorImpl(String name) {
protected GarbageCollectorImpl(String name) {
super(name);
}
@Override
public native long getCollectionCount();
@Override
public native long getCollectionTime();
// The memory pools are static and won't be changed.
// TODO: If the hotspot implementation begins to have pools
// dynamically created and removed, this needs to be modified.
private String[] poolNames = null;
synchronized String[] getAllPoolNames() {
if (poolNames == null) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
poolNames = new String[pools.size()];
int i = 0;
for (MemoryPoolMXBean m : pools) {
poolNames[i++] = m.getName();
}
}
return poolNames;
}
// Sun JDK extension
private GcInfoBuilder gcInfoBuilder;
private synchronized GcInfoBuilder getGcInfoBuilder() {
if(gcInfoBuilder == null) {
gcInfoBuilder = new GcInfoBuilder(this, getAllPoolNames());
}
return gcInfoBuilder;
}
public GcInfo getLastGcInfo() {
GcInfo info = getGcInfoBuilder().getLastGcInfo();
return info;
}
private final static String notifName =
"javax.management.Notification";
private final static String[] gcNotifTypes = {
GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION
};
private MBeanNotificationInfo[] notifInfo = null;
public MBeanNotificationInfo[] getNotificationInfo() {
synchronized (this) {
if (notifInfo == null) {
notifInfo = new MBeanNotificationInfo[1];
notifInfo[0] = new MBeanNotificationInfo(gcNotifTypes,
notifName,
"GC Notification");
}
}
return notifInfo;
}
private static long seqNumber = 0;
private static long getNextSeqNumber() {
return ++seqNumber;
}
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
public synchronized void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
{
boolean before = hasListeners();
super.addNotificationListener(listener, filter, handback);
boolean after = hasListeners();
if (!before && after) {
setNotificationEnabled(this, true);
}
}
public synchronized void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
boolean before = hasListeners();
super.removeNotificationListener(listener);
boolean after = hasListeners();
if (before && !after) {
setNotificationEnabled(this,false);
}
}
public synchronized void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException
{
boolean before = hasListeners();
super.removeNotificationListener(listener,filter,handback);
boolean after = hasListeners();
if (before && !after) {
setNotificationEnabled(this,false);
}
}
@Override
public ObjectName getObjectName() {
return Util.newObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, getName());
}
native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -115,28 +115,28 @@ public abstract class LazyCompositeData
protected abstract CompositeData getCompositeData();
// Helper methods
static String getString(CompositeData cd, String itemName) {
public static String getString(CompositeData cd, String itemName) {
if (cd == null)
throw new IllegalArgumentException("Null CompositeData");
return (String) cd.get(itemName);
}
static boolean getBoolean(CompositeData cd, String itemName) {
public static boolean getBoolean(CompositeData cd, String itemName) {
if (cd == null)
throw new IllegalArgumentException("Null CompositeData");
return ((Boolean) cd.get(itemName)).booleanValue();
}
static long getLong(CompositeData cd, String itemName) {
public static long getLong(CompositeData cd, String itemName) {
if (cd == null)
throw new IllegalArgumentException("Null CompositeData");
return ((Long) cd.get(itemName)).longValue();
}
static int getInt(CompositeData cd, String itemName) {
public static int getInt(CompositeData cd, String itemName) {
if (cd == null)
throw new IllegalArgumentException("Null CompositeData");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,8 +26,6 @@
package sun.management;
import java.lang.management.*;
import javax.management.DynamicMBean;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
@ -38,30 +36,35 @@ import javax.management.RuntimeOperationsException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import sun.util.logging.LoggingSupport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.sun.management.DiagnosticCommandMBean;
import com.sun.management.HotSpotDiagnosticMXBean;
/**
* ManagementFactoryHelper provides static factory methods to create
* instances of the management interface.
*/
public class ManagementFactoryHelper {
static {
// make sure that the management lib is loaded within
// java.lang.management.ManagementFactory
sun.misc.Unsafe.getUnsafe().ensureClassInitialized(ManagementFactory.class);
}
private static final VMManagement jvm = new VMManagementImpl();
private ManagementFactoryHelper() {};
private static VMManagement jvm;
public static VMManagement getVMManagement() {
return jvm;
}
private static ClassLoadingImpl classMBean = null;
private static MemoryImpl memoryMBean = null;
private static ThreadImpl threadMBean = null;
private static RuntimeImpl runtimeMBean = null;
private static CompilationImpl compileMBean = null;
private static OperatingSystemImpl osMBean = null;
private static BaseOperatingSystemImpl osMBean = null;
public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
if (classMBean == null) {
@ -100,7 +103,7 @@ public class ManagementFactoryHelper {
public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
if (osMBean == null) {
osMBean = new OperatingSystemImpl(jvm);
osMBean = new BaseOperatingSystemImpl(jvm);
}
return osMBean;
}
@ -123,7 +126,7 @@ public class ManagementFactoryHelper {
return result;
}
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers();
List<GarbageCollectorMXBean> result = new ArrayList<>(mgrs.length);
for (MemoryManagerMXBean m : mgrs) {
@ -257,20 +260,11 @@ public class ManagementFactoryHelper {
};
}
private static HotSpotDiagnostic hsDiagMBean = null;
private static HotspotRuntime hsRuntimeMBean = null;
private static HotspotClassLoading hsClassMBean = null;
private static HotspotThread hsThreadMBean = null;
private static HotspotCompilation hsCompileMBean = null;
private static HotspotMemory hsMemoryMBean = null;
private static DiagnosticCommandImpl hsDiagCommandMBean = null;
public static synchronized HotSpotDiagnosticMXBean getDiagnosticMXBean() {
if (hsDiagMBean == null) {
hsDiagMBean = new HotSpotDiagnostic();
}
return hsDiagMBean;
}
/**
* This method is for testing only.
@ -312,14 +306,6 @@ public class ManagementFactoryHelper {
return hsMemoryMBean;
}
public static synchronized DiagnosticCommandMBean getDiagnosticCommandMBean() {
// Remote Diagnostic Commands may not be supported
if (hsDiagCommandMBean == null && jvm.isRemoteDiagnosticCommandsSupported()) {
hsDiagCommandMBean = new DiagnosticCommandImpl(jvm);
}
return hsDiagCommandMBean;
}
/**
* This method is for testing only.
*/
@ -374,18 +360,6 @@ public class ManagementFactoryHelper {
private final static String HOTSPOT_THREAD_MBEAN_NAME =
"sun.management:type=HotspotThreading";
final static String HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME =
"com.sun.management:type=DiagnosticCommand";
public static HashMap<ObjectName, DynamicMBean> getPlatformDynamicMBeans() {
HashMap<ObjectName, DynamicMBean> map = new HashMap<>();
DiagnosticCommandMBean diagMBean = getDiagnosticCommandMBean();
if (diagMBean != null) {
map.put(Util.newObjectName(HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME), diagMBean);
}
return map;
}
static void registerInternalMBeans(MBeanServer mbs) {
// register all internal MBeans if not registered
// No exception is thrown if a MBean with that object name
@ -441,17 +415,6 @@ public class ManagementFactoryHelper {
}
}
static {
AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("management");
return null;
}
});
jvm = new VMManagementImpl();
}
public static boolean isThreadSuspended(int state) {
return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0);
}
@ -471,4 +434,20 @@ public class ManagementFactoryHelper {
private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;
private static final int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000;
// Invoked by the VM
private static MemoryPoolMXBean createMemoryPool
(String name, boolean isHeap, long uThreshold, long gcThreshold) {
return new MemoryPoolImpl(name, isHeap, uThreshold, gcThreshold);
}
private static MemoryManagerMXBean createMemoryManager(String name) {
return new MemoryManagerImpl(name);
}
private static GarbageCollectorMXBean
createGarbageCollector(String name, String type) {
// ignore type parameter which is for future extension
return new GarbageCollectorImpl(name);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,10 +38,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.management.*;
import javax.management.openmbean.*;
import static javax.management.openmbean.SimpleType.*;
import com.sun.management.VMOption;
/**
* A mapped mxbean type maps a Java type to an open type.
@ -113,7 +111,7 @@ public abstract class MappedMXBeanType {
return mt;
}
static synchronized MappedMXBeanType getMappedType(Type t)
public static synchronized MappedMXBeanType getMappedType(Type t)
throws OpenDataException {
MappedMXBeanType mt = convertedTypes.get(t);
if (mt == null) {
@ -152,7 +150,7 @@ public abstract class MappedMXBeanType {
}
// Return the mapped open type
OpenType<?> getOpenType() {
public OpenType<?> getOpenType() {
return openType;
}
@ -177,10 +175,10 @@ public abstract class MappedMXBeanType {
// return name of the class or the generic type
abstract String getName();
abstract Object toOpenTypeData(Object javaTypeData)
public abstract Object toOpenTypeData(Object javaTypeData)
throws OpenDataException;
abstract Object toJavaTypeData(Object openTypeData)
public abstract Object toJavaTypeData(Object openTypeData)
throws OpenDataException, InvalidObjectException;
// Basic Types - Classes that do not require data conversion
@ -208,11 +206,11 @@ public abstract class MappedMXBeanType {
return basicType.getName();
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
return data;
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
return data;
@ -243,11 +241,11 @@ public abstract class MappedMXBeanType {
return enumClass.getName();
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
return ((Enum) data).name();
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
try {
@ -315,7 +313,7 @@ public abstract class MappedMXBeanType {
return arrayClass.getName();
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
// If the base element type is a basic type
// return the data as no conversion is needed.
// Primitive types are not converted to wrappers.
@ -340,7 +338,7 @@ public abstract class MappedMXBeanType {
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
// If the base element type is a basic type
@ -457,7 +455,7 @@ public abstract class MappedMXBeanType {
return typeName;
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
final List<Object> list = (List<Object>) data;
final Object[] openArray = (Object[])
@ -470,7 +468,7 @@ public abstract class MappedMXBeanType {
return openArray;
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final Object[] openArray = (Object[]) data;
@ -538,7 +536,7 @@ public abstract class MappedMXBeanType {
return typeName;
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
final Map<Object,Object> map = (Map<Object,Object>) data;
final TabularType tabularType = (TabularType) openType;
final TabularData table = new TabularDataSupport(tabularType);
@ -556,7 +554,7 @@ public abstract class MappedMXBeanType {
return table;
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final TabularData td = (TabularData) data;
@ -605,8 +603,9 @@ public abstract class MappedMXBeanType {
//
static class CompositeDataMXBeanType extends MappedMXBeanType {
final Class<?> javaClass;
final boolean isCompositeData;
boolean isCompositeData = false;
Method fromMethod = null;
Method toMethod = null;
CompositeDataMXBeanType(Class<?> c) throws OpenDataException {
this.javaClass = c;
@ -624,6 +623,26 @@ public abstract class MappedMXBeanType {
// that has no from method to be embeded in another class.
}
// check if a static "toCompositeData" method exists
try {
toMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
public Method run() throws NoSuchMethodException {
Method m = javaClass.getDeclaredMethod("toCompositeData", javaClass);
if (m != null
&& CompositeData.class.isAssignableFrom(m.getReturnType())
&& Modifier.isStatic(m.getModifiers())) {
m.setAccessible(true);
return m;
} else {
return null;
}
}
});
} catch (PrivilegedActionException e) {
// ignore NoSuchMethodException since we allow classes
// that has no from method to be embeded in another class.
}
if (COMPOSITE_DATA_CLASS.isAssignableFrom(c)) {
// c implements CompositeData - set openType to null
// defer generating the CompositeType
@ -636,16 +655,16 @@ public abstract class MappedMXBeanType {
// Make a CompositeData containing all the getters
final Method[] methods =
AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
public Method[] run() {
return javaClass.getMethods();
}
});
public Method[] run() {
return javaClass.getMethods();
}
});
final List<String> names = new ArrayList<>();
final List<OpenType<?>> types = new ArrayList<>();
/* Select public methods that look like "T getX()" or "boolean
isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */
isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */
for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final String name = method.getName();
@ -676,10 +695,10 @@ public abstract class MappedMXBeanType {
final String[] nameArray = names.toArray(new String[0]);
openType = new CompositeType(c.getName(),
c.getName(),
nameArray, // field names
nameArray, // field descriptions
types.toArray(new OpenType<?>[0]));
c.getName(),
nameArray, // field names
nameArray, // field descriptions
types.toArray(new OpenType<?>[0]));
}
}
@ -691,7 +710,23 @@ public abstract class MappedMXBeanType {
return javaClass.getName();
}
Object toOpenTypeData(Object data) throws OpenDataException {
public Object toOpenTypeData(Object data) throws OpenDataException {
if (toMethod != null) {
try {
return toMethod.invoke(null, data);
} catch (IllegalAccessException e) {
// should never reach here
throw new AssertionError(e);
} catch (InvocationTargetException e) {
final OpenDataException ode
= new OpenDataException("Failed to invoke "
+ toMethod.getName() + " to convert " + javaClass.getName()
+ " to CompositeData");
ode.initCause(e);
throw ode;
}
}
if (data instanceof MemoryUsage) {
return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
}
@ -712,10 +747,6 @@ public abstract class MappedMXBeanType {
toCompositeData((MemoryNotificationInfo) data);
}
if (data instanceof VMOption) {
return VMOptionCompositeData.toCompositeData((VMOption) data);
}
if (isCompositeData) {
// Classes that implement CompositeData
//
@ -732,7 +763,7 @@ public abstract class MappedMXBeanType {
" is not supported for platform MXBeans");
}
Object toJavaTypeData(Object data)
public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
if (fromMethod == null) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,13 +34,12 @@ import javax.management.NotificationListener;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Collections;
/**
* Abstract helper class for notification emitter support.
*/
abstract class NotificationEmitterSupport implements NotificationEmitter {
public abstract class NotificationEmitterSupport implements NotificationEmitter {
protected NotificationEmitterSupport() {
}
@ -135,7 +134,7 @@ abstract class NotificationEmitterSupport implements NotificationEmitter {
}
}
void sendNotification(Notification notification) {
public void sendNotification(Notification notification) {
if (notification == null) {
return;
@ -162,7 +161,7 @@ abstract class NotificationEmitterSupport implements NotificationEmitter {
}
}
boolean hasListeners() {
public boolean hasListeners() {
synchronized (listenerLock) {
return !listenerList.isEmpty();
}

View File

@ -26,20 +26,18 @@
package sun.management;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import javax.management.ObjectName;
/**
* Implementation class for the thread subsystem.
* Standard and committed hotspot-specific metrics if any.
*
* ManagementFactory.getThreadMXBean() returns an instance
* of this class.
* Implementation for java.lang.management.ThreadMXBean as well as providing the
* supporting method for com.sun.management.ThreadMXBean.
* The supporting method for com.sun.management.ThreadMXBean can be moved to
* jdk.management in the future.
*/
class ThreadImpl implements com.sun.management.ThreadMXBean {
public class ThreadImpl implements ThreadMXBean {
private final VMManagement jvm;
// default for thread contention monitoring is disabled.
@ -50,32 +48,38 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
/**
* Constructor of ThreadImpl class.
*/
ThreadImpl(VMManagement vm) {
protected ThreadImpl(VMManagement vm) {
this.jvm = vm;
this.cpuTimeEnabled = jvm.isThreadCpuTimeEnabled();
this.allocatedMemoryEnabled = jvm.isThreadAllocatedMemoryEnabled();
}
@Override
public int getThreadCount() {
return jvm.getLiveThreadCount();
}
@Override
public int getPeakThreadCount() {
return jvm.getPeakThreadCount();
}
@Override
public long getTotalStartedThreadCount() {
return jvm.getTotalThreadCount();
}
@Override
public int getDaemonThreadCount() {
return jvm.getDaemonThreadCount();
}
@Override
public boolean isThreadContentionMonitoringSupported() {
return jvm.isThreadContentionMonitoringSupported();
}
@Override
public synchronized boolean isThreadContentionMonitoringEnabled() {
if (!isThreadContentionMonitoringSupported()) {
throw new UnsupportedOperationException(
@ -84,18 +88,21 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return contentionMonitoringEnabled;
}
@Override
public boolean isThreadCpuTimeSupported() {
return jvm.isOtherThreadCpuTimeSupported();
}
@Override
public boolean isCurrentThreadCpuTimeSupported() {
return jvm.isCurrentThreadCpuTimeSupported();
}
public boolean isThreadAllocatedMemorySupported() {
protected boolean isThreadAllocatedMemorySupported() {
return jvm.isThreadAllocatedMemorySupported();
}
@Override
public boolean isThreadCpuTimeEnabled() {
if (!isThreadCpuTimeSupported() &&
!isCurrentThreadCpuTimeSupported()) {
@ -105,7 +112,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return cpuTimeEnabled;
}
public boolean isThreadAllocatedMemoryEnabled() {
protected boolean isThreadAllocatedMemoryEnabled() {
if (!isThreadAllocatedMemorySupported()) {
throw new UnsupportedOperationException(
"Thread allocated memory measurement is not supported");
@ -113,6 +120,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return allocatedMemoryEnabled;
}
@Override
public long[] getAllThreadIds() {
Util.checkMonitorAccess();
@ -126,6 +134,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids;
}
@Override
public ThreadInfo getThreadInfo(long id) {
long[] ids = new long[1];
ids[0] = id;
@ -133,6 +142,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos[0];
}
@Override
public ThreadInfo getThreadInfo(long id, int maxDepth) {
long[] ids = new long[1];
ids[0] = id;
@ -140,6 +150,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos[0];
}
@Override
public ThreadInfo[] getThreadInfo(long[] ids) {
return getThreadInfo(ids, 0);
}
@ -157,6 +168,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
}
}
@Override
public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
verifyThreadIds(ids);
@ -180,6 +192,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos;
}
@Override
public void setThreadContentionMonitoringEnabled(boolean enable) {
if (!isThreadContentionMonitoringSupported()) {
throw new UnsupportedOperationException(
@ -213,6 +226,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadCpuTimeEnabled();
}
@Override
public long getCurrentThreadCpuTime() {
if (verifyCurrentThreadCpuTime()) {
return getThreadTotalCpuTime0(0);
@ -220,6 +234,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return -1;
}
@Override
public long getThreadCpuTime(long id) {
long[] ids = new long[1];
ids[0] = id;
@ -251,7 +266,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadCpuTimeEnabled();
}
public long[] getThreadCpuTime(long[] ids) {
protected long[] getThreadCpuTime(long[] ids) {
boolean verified = verifyThreadCpuTime(ids);
int length = ids.length;
@ -272,6 +287,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times;
}
@Override
public long getCurrentThreadUserTime() {
if (verifyCurrentThreadCpuTime()) {
return getThreadUserCpuTime0(0);
@ -279,6 +295,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return -1;
}
@Override
public long getThreadUserTime(long id) {
long[] ids = new long[1];
ids[0] = id;
@ -286,7 +303,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times[0];
}
public long[] getThreadUserTime(long[] ids) {
protected long[] getThreadUserTime(long[] ids) {
boolean verified = verifyThreadCpuTime(ids);
int length = ids.length;
@ -307,6 +324,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times;
}
@Override
public void setThreadCpuTimeEnabled(boolean enable) {
if (!isThreadCpuTimeSupported() &&
!isCurrentThreadCpuTimeSupported()) {
@ -324,7 +342,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
}
}
public long getThreadAllocatedBytes(long id) {
protected long getThreadAllocatedBytes(long id) {
long[] ids = new long[1];
ids[0] = id;
final long[] sizes = getThreadAllocatedBytes(ids);
@ -343,7 +361,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadAllocatedMemoryEnabled();
}
public long[] getThreadAllocatedBytes(long[] ids) {
protected long[] getThreadAllocatedBytes(long[] ids) {
boolean verified = verifyThreadAllocatedMemory(ids);
long[] sizes = new long[ids.length];
@ -355,7 +373,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return sizes;
}
public void setThreadAllocatedMemoryEnabled(boolean enable) {
protected void setThreadAllocatedMemoryEnabled(boolean enable) {
if (!isThreadAllocatedMemorySupported()) {
throw new UnsupportedOperationException(
"Thread allocated memory measurement is not supported.");
@ -371,6 +389,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
}
}
@Override
public long[] findMonitorDeadlockedThreads() {
Util.checkMonitorAccess();
@ -387,6 +406,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids;
}
@Override
public long[] findDeadlockedThreads() {
if (!isSynchronizerUsageSupported()) {
throw new UnsupportedOperationException(
@ -408,15 +428,18 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids;
}
@Override
public void resetPeakThreadCount() {
Util.checkControlAccess();
resetPeakThreadCount0();
}
@Override
public boolean isObjectMonitorUsageSupported() {
return jvm.isObjectMonitorUsageSupported();
}
@Override
public boolean isSynchronizerUsageSupported() {
return jvm.isSynchronizerUsageSupported();
}
@ -436,6 +459,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
Util.checkMonitorAccess();
}
@Override
public ThreadInfo[] getThreadInfo(long[] ids,
boolean lockedMonitors,
boolean lockedSynchronizers) {
@ -448,6 +472,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return dumpThreads0(ids, lockedMonitors, lockedSynchronizers);
}
@Override
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
boolean lockedSynchronizers) {
verifyDumpThreads(lockedMonitors, lockedSynchronizers);
@ -477,6 +502,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
// tid == 0 to reset contention times for all threads
private static native void resetContentionTimes0(long tid);
@Override
public ObjectName getObjectName() {
return Util.newObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -81,7 +81,7 @@ public class Util {
static void checkMonitorAccess() throws SecurityException {
checkAccess(monitorPermission);
}
static void checkControlAccess() throws SecurityException {
public static void checkControlAccess() throws SecurityException {
checkAccess(controlPermission);
}
}

View File

@ -205,7 +205,7 @@ public abstract class PlatformMBeanProvider {
* Instantiates a new PlatformMBeanProvider.
*
* @throws SecurityException if the subclass (and calling code) does not
* have {@code RuntimePermission("sun.management.spi.PlatformMBeanProvider", "subclass")}
* have {@code RuntimePermission("sun.management.spi.PlatformMBeanProvider.subclass")}
*/
protected PlatformMBeanProvider () {
this(checkSubclassPermission());
@ -226,7 +226,7 @@ public abstract class PlatformMBeanProvider {
private static Void checkSubclassPermission() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission(PlatformMBeanProvider.class.getName(), "subclass"));
sm.checkPermission(new RuntimePermission(PlatformMBeanProvider.class.getName()+".subclass"));
}
return null;
}

View File

@ -36,17 +36,3 @@ JNIEXPORT jlong JNICALL Java_sun_management_GarbageCollectorImpl_getCollectionTi
(JNIEnv *env, jobject mgr) {
return jmm_interface->GetLongAttribute(env, mgr, JMM_GC_TIME_MS);
}
JNIEXPORT void JNICALL Java_sun_management_GarbageCollectorImpl_setNotificationEnabled
(JNIEnv *env, jobject dummy, jobject gc,jboolean enabled) {
if (gc == NULL) {
JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean");
return;
}
if((jmm_version > JMM_VERSION_1_2)
|| (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=1))) {
jmm_interface->SetGCNotificationEnabled(env, gc, enabled);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@
#include <dlfcn.h>
#include <pthread.h>
#include <inttypes.h>
#include "sun_management_OperatingSystemImpl.h"
#include "com_sun_management_internal_OperatingSystemImpl.h"
struct ticks {
uint64_t used;
@ -311,7 +311,7 @@ double get_process_load() {
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy)
{
if(perfInit() == 0) {
@ -322,7 +322,7 @@ Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy)
{
if(perfInit() == 0) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
#include "sun_management_OperatingSystemImpl.h"
#include "com_sun_management_internal_OperatingSystemImpl.h"
#include <sys/time.h>
#include <mach/mach.h>
@ -32,7 +32,7 @@
#include "jvm.h"
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy)
{
// This code is influenced by the darwin top source
@ -84,7 +84,7 @@ Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy)
{
// This code is influenced by the darwin top source

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,10 @@
package com.sun.management;
import javax.management.Notification;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataView;
import javax.management.openmbean.CompositeType;
import java.util.Collection;
import java.util.Collections;
import sun.management.GarbageCollectionNotifInfoCompositeData;
import com.sun.management.internal.GarbageCollectionNotifInfoCompositeData;
/**
* The information about a garbage collection

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,9 +33,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import sun.management.GcInfoCompositeData;
import sun.management.GcInfoBuilder;
import com.sun.management.internal.GcInfoCompositeData;
import com.sun.management.internal.GcInfoBuilder;
/**
* Garbage collection information. It contains the following

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package com.sun.management;
import sun.management.VMOptionCompositeData;
import com.sun.management.internal.VMOptionCompositeData;
import javax.management.openmbean.CompositeData;
/**
@ -241,5 +241,8 @@ public class VMOption {
}
// for sun.management.MappedMXBeanType
static CompositeData toCompositeData(VMOption option) {
return VMOptionCompositeData.toCompositeData(option);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
/**
* Diagnostic Command Argument information. It contains the description

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,21 +23,41 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import com.sun.management.DiagnosticCommandMBean;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.Permission;
import java.util.*;
import javax.management.*;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.Descriptor;
import javax.management.ImmutableDescriptor;
import javax.management.InvalidAttributeValueException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import sun.management.ManagementFactoryHelper;
import sun.management.NotificationEmitterSupport;
import sun.management.VMManagement;
/**
* Implementation class for the diagnostic commands subsystem.
*
* @since 1.8
*/
class DiagnosticCommandImpl extends NotificationEmitterSupport
public class DiagnosticCommandImpl extends NotificationEmitterSupport
implements DiagnosticCommandMBean {
private final VMManagement jvm;
@ -45,6 +65,17 @@ class DiagnosticCommandImpl extends NotificationEmitterSupport
private static final String strClassName = "".getClass().getName();
private static final String strArrayClassName = String[].class.getName();
private final boolean isSupported;
private static DiagnosticCommandImpl diagCommandMBean = null;
static synchronized DiagnosticCommandMBean getDiagnosticCommandMBean() {
VMManagement jvm = ManagementFactoryHelper.getVMManagement();
// Remote Diagnostic Commands may not be supported
if (diagCommandMBean == null && jvm.isRemoteDiagnosticCommandsSupported()) {
diagCommandMBean = new DiagnosticCommandImpl(jvm);
}
return diagCommandMBean;
}
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException,
@ -327,7 +358,7 @@ class DiagnosticCommandImpl extends NotificationEmitterSupport
}
ObjectName on = null;
try {
on = ObjectName.getInstance(ManagementFactoryHelper.HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME);
on = ObjectName.getInstance(PlatformMBeanProviderImpl.DIAGNOSTIC_COMMAND_MBEAN_NAME);
} catch (MalformedObjectNameException e) { }
Notification notif = new Notification("jmx.mbean.info.changed",
on,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import java.util.List;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import java.util.*;
import com.sun.management.VMOption;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,10 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import com.sun.management.GarbageCollectionNotificationInfo;
import com.sun.management.GcInfo;
import java.lang.reflect.Method;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeDataSupport;
@ -38,6 +37,9 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.lang.reflect.Field;
import java.util.HashMap;
import sun.management.LazyCompositeData;
import static sun.management.LazyCompositeData.getString;
import sun.management.Util;
/**
* A CompositeData for GarbageCollectionNotificationInfo for the local management support.
@ -95,7 +97,7 @@ public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
compositeTypeByBuilder.put(builder,gict);
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
throw new RuntimeException(e);
}
}
}
@ -205,7 +207,7 @@ public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
baseGcNotifInfoItemTypes);
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
throw new RuntimeException(e);
}
}
return baseGcNotifInfoCompositeType;

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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 com.sun.management.internal;
import com.sun.management.GarbageCollectionNotificationInfo;
import com.sun.management.GarbageCollectorMXBean;
import com.sun.management.GcInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.openmbean.CompositeData;
import sun.management.GarbageCollectorImpl;
/**
* Implementation class for the garbage collector.
* Standard and committed hotspot-specific metrics if any.
*
* ManagementFactory.getGarbageCollectorMXBeans() returns a list
* of instances of this class.
*/
public class GarbageCollectorExtImpl extends GarbageCollectorImpl
implements GarbageCollectorMXBean {
public GarbageCollectorExtImpl(String name) {
super(name);
}
// The memory pools are static and won't be changed.
// TODO: If the hotspot implementation begins to have pools
// dynamically created and removed, this needs to be modified.
private String[] poolNames = null;
private synchronized String[] getAllPoolNames() {
if (poolNames == null) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
poolNames = new String[pools.size()];
int i = 0;
for (MemoryPoolMXBean m : pools) {
poolNames[i++] = m.getName();
}
}
return poolNames;
}
public GcInfo getLastGcInfo() {
GcInfo info = getGcInfoBuilder().getLastGcInfo();
return info;
}
private final static String notifName =
"javax.management.Notification";
private final static String[] gcNotifTypes = {
GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION
};
private MBeanNotificationInfo[] notifInfo = null;
public MBeanNotificationInfo[] getNotificationInfo() {
synchronized (this) {
if (notifInfo == null) {
notifInfo = new MBeanNotificationInfo[1];
notifInfo[0] = new MBeanNotificationInfo(gcNotifTypes,
notifName,
"GC Notification");
}
}
return notifInfo;
}
private static long seqNumber = 0;
private static long getNextSeqNumber() {
return ++seqNumber;
}
protected void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
public synchronized void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
{
boolean before = hasListeners();
super.addNotificationListener(listener, filter, handback);
boolean after = hasListeners();
if (!before && after) {
setNotificationEnabled(this, true);
}
}
public synchronized void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
boolean before = hasListeners();
super.removeNotificationListener(listener);
boolean after = hasListeners();
if (before && !after) {
setNotificationEnabled(this,false);
}
}
public synchronized void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException
{
boolean before = hasListeners();
super.removeNotificationListener(listener,filter,handback);
boolean after = hasListeners();
if (before && !after) {
setNotificationEnabled(this,false);
}
}
private GcInfoBuilder gcInfoBuilder;
// Invoked also by the VM
private synchronized GcInfoBuilder getGcInfoBuilder() {
if(gcInfoBuilder == null) {
gcInfoBuilder = new GcInfoBuilder(this, getAllPoolNames());
}
return gcInfoBuilder;
}
private native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
// Invoked by the VM
private static java.lang.management.GarbageCollectorMXBean
createGarbageCollector(String name, String type) {
return new GarbageCollectorExtImpl(name);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,20 +22,16 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management;
package com.sun.management.internal;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.MemoryUsage;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularType;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
import com.sun.management.GcInfo;
import sun.management.Util;
/**
* Helper class to build composite data.
@ -164,7 +160,7 @@ public class GcInfoBuilder {
allItemTypes);
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
throw new RuntimeException(e);
}
gcInfoCompositeType = gict;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,12 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import java.lang.management.MemoryUsage;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;
import java.io.InvalidObjectException;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
@ -42,9 +38,12 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.OpenDataException;
import com.sun.management.GcInfo;
import com.sun.management.GarbageCollectionNotificationInfo;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.management.LazyCompositeData;
import static sun.management.LazyCompositeData.getLong;
import sun.management.MappedMXBeanType;
import sun.management.Util;
/**
* A CompositeData for GcInfo for the local management support.
@ -266,7 +265,7 @@ public class GcInfoCompositeData extends LazyCompositeData {
getBaseGcInfoItemTypes());
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
throw new RuntimeException(e);
}
}
return baseGcInfoCompositeType;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import java.io.IOException;
import java.util.ArrayList;
@ -32,6 +32,7 @@ import javax.management.ObjectName;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.Util;
/**
* Implementation of the diagnostic MBean for Hotspot VM.

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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 com.sun.management.internal;
import com.sun.management.ThreadMXBean;
import sun.management.ManagementFactoryHelper;
import sun.management.ThreadImpl;
import sun.management.VMManagement;
/**
*
*/
public class HotSpotThreadImpl extends ThreadImpl implements ThreadMXBean {
public HotSpotThreadImpl(VMManagement vm) {
super(ManagementFactoryHelper.getVMManagement());
}
@Override
public boolean isThreadAllocatedMemorySupported() {
return super.isThreadAllocatedMemorySupported();
}
@Override
public boolean isThreadAllocatedMemoryEnabled() {
return super.isThreadAllocatedMemoryEnabled();
}
@Override
public long[] getThreadCpuTime(long[] ids) {
return super.getThreadCpuTime(ids);
}
@Override
public long[] getThreadUserTime(long[] ids) {
return super.getThreadUserTime(ids);
}
@Override
public long getThreadAllocatedBytes(long id) {
return super.getThreadAllocatedBytes(id);
}
@Override
public long[] getThreadAllocatedBytes(long[] ids) {
return super.getThreadAllocatedBytes(ids);
}
@Override
public void setThreadAllocatedMemoryEnabled(boolean enable) {
super.setThreadAllocatedMemoryEnabled(enable);
}
}

View File

@ -24,7 +24,14 @@
*/
package com.sun.management.internal;
import com.sun.management.DiagnosticCommandMBean;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.ThreadMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.OperatingSystemMXBean;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -34,12 +41,23 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.management.DynamicMBean;
import javax.management.ObjectName;
import sun.management.ManagementFactoryHelper;
import sun.management.spi.PlatformMBeanProvider;
public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
final static String DIAGNOSTIC_COMMAND_MBEAN_NAME =
"com.sun.management:type=DiagnosticCommand";
private final List<PlatformComponent<?>> mxbeanList;
private static HotSpotDiagnostic hsDiagMBean = null;
private static OperatingSystemMXBean osMBean = null;
static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("management_ext");
return null;
});
}
public PlatformMBeanProviderImpl() {
mxbeanList = Collections.unmodifiableList(init());
@ -55,7 +73,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
/**
* Garbage Collector in the Java virtual machine.
*/
initMBeanList.add(new PlatformComponent<java.lang.management.MemoryManagerMXBean>() {
initMBeanList.add(new PlatformComponent<MemoryManagerMXBean>() {
private final Set<String> garbageCollectorMXBeanInterfaceNames
= Collections.unmodifiableSet(
Stream.of("java.lang.management.MemoryManagerMXBean",
@ -64,8 +82,8 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
.collect(Collectors.toSet()));
@Override
public Set<Class<? extends java.lang.management.MemoryManagerMXBean>> mbeanInterfaces() {
return Stream.of(java.lang.management.MemoryManagerMXBean.class,
public Set<Class<? extends MemoryManagerMXBean>> mbeanInterfaces() {
return Stream.of(MemoryManagerMXBean.class,
java.lang.management.GarbageCollectorMXBean.class,
com.sun.management.GarbageCollectorMXBean.class)
.collect(Collectors.toSet());
@ -87,27 +105,67 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
}
@Override
public Map<String, java.lang.management.MemoryManagerMXBean> nameToMBeanMap() {
public Map<String, MemoryManagerMXBean> nameToMBeanMap() {
List<java.lang.management.GarbageCollectorMXBean> list
= ManagementFactoryHelper.getGarbageCollectorMXBeans();;
Map<String, java.lang.management.MemoryManagerMXBean> map;
= ManagementFactoryHelper.getGarbageCollectorMXBeans();
Map<String, MemoryManagerMXBean> map;
if (list.isEmpty()) {
map = Collections.<String, java.lang.management.MemoryManagerMXBean>emptyMap();
map = Collections.emptyMap();
} else {
map = new HashMap<>(list.size());
for (java.lang.management.MemoryManagerMXBean gcm : list) {
for (MemoryManagerMXBean gcm : list) {
map.put(gcm.getObjectName().getCanonicalName(),
gcm);
}
}
return map;
}
});
/**
* Threading system of the Java virtual machine.
*/
initMBeanList.add(new PlatformComponent<java.lang.management.ThreadMXBean>() {
private final Set<String> threadMXBeanInterfaceNames
= Collections.unmodifiableSet(
Stream.of("java.lang.management.ThreadMXBean",
"com.sun.management.ThreadMXBean")
.collect(Collectors.toSet()));
private ThreadMXBean threadMBean = null;
@Override
public Set<Class<? extends java.lang.management.ThreadMXBean>> mbeanInterfaces() {
return Stream.of(java.lang.management.ThreadMXBean.class,
com.sun.management.ThreadMXBean.class)
.collect(Collectors.toSet());
}
@Override
public Set<String> mbeanInterfaceNames() {
return threadMXBeanInterfaceNames;
}
@Override
public String getObjectNamePattern() {
return ManagementFactory.THREAD_MXBEAN_NAME;
}
@Override
public synchronized Map<String, java.lang.management.ThreadMXBean> nameToMBeanMap() {
if (threadMBean == null) {
threadMBean = new HotSpotThreadImpl(ManagementFactoryHelper.getVMManagement());
}
return Collections.singletonMap(
ManagementFactory.THREAD_MXBEAN_NAME,
threadMBean);
}
});
/**
* OperatingSystemMXBean
*/
initMBeanList.add(new PlatformComponent<java.lang.management.OperatingSystemMXBean>() {
initMBeanList.add(new PlatformComponent<OperatingSystemMXBean>() {
private final Set<String> operatingSystemMXBeanInterfaceNames
= Collections.unmodifiableSet(
Stream.of("java.lang.management.OperatingSystemMXBean",
@ -116,7 +174,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
.collect(Collectors.toSet()));
@Override
public Set<Class<? extends java.lang.management.OperatingSystemMXBean>> mbeanInterfaces() {
public Set<Class<? extends OperatingSystemMXBean>> mbeanInterfaces() {
return Stream.of(java.lang.management.OperatingSystemMXBean.class,
com.sun.management.OperatingSystemMXBean.class,
com.sun.management.UnixOperatingSystemMXBean.class)
@ -137,7 +195,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
public Map<String, java.lang.management.OperatingSystemMXBean> nameToMBeanMap() {
return Collections.<String, java.lang.management.OperatingSystemMXBean>singletonMap(
ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
ManagementFactoryHelper.getOperatingSystemMXBean());
getOperatingSystemMXBean());
}
});
@ -146,7 +204,8 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
*/
initMBeanList.add(new PlatformComponent<com.sun.management.HotSpotDiagnosticMXBean>() {
private final Set<String> hotSpotDiagnosticMXBeanInterfaceNames =
Collections.unmodifiableSet(Collections.<String>singleton("com.sun.management.HotSpotDiagnosticMXBean"));
Collections.unmodifiableSet(Collections.<String>singleton(
"com.sun.management.HotSpotDiagnosticMXBean"));
@Override
public Set<Class<? extends com.sun.management.HotSpotDiagnosticMXBean>> mbeanInterfaces() {
@ -167,19 +226,20 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
public Map<String, com.sun.management.HotSpotDiagnosticMXBean> nameToMBeanMap() {
return Collections.<String, com.sun.management.HotSpotDiagnosticMXBean>singletonMap(
"com.sun.management:type=HotSpotDiagnostic",
ManagementFactoryHelper.getDiagnosticMXBean());
getDiagnosticMXBean());
}
});
/**
* DynamicMBean
* Diagnostic command MBean
*/
HashMap<ObjectName, DynamicMBean> dynmbeans
= ManagementFactoryHelper.getPlatformDynamicMBeans();
final Set<String> dynamicMBeanInterfaceNames =
Collections.unmodifiableSet(Collections.<String>singleton("javax.management.DynamicMBean"));
for (Map.Entry<ObjectName, DynamicMBean> e : dynmbeans.entrySet()) {
DiagnosticCommandMBean diagMBean = DiagnosticCommandImpl.getDiagnosticCommandMBean();
if (diagMBean != null) {
initMBeanList.add(new PlatformComponent<DynamicMBean>() {
final Set<String> dynamicMBeanInterfaceNames
= Collections.unmodifiableSet(Collections.<String>singleton(
"javax.management.DynamicMBean"));
@Override
public Set<String> mbeanInterfaceNames() {
return dynamicMBeanInterfaceNames;
@ -187,23 +247,39 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
@Override
public Set<Class<? extends DynamicMBean>> mbeanInterfaces() {
return Collections.emptySet(); // DynamicMBean cannot be used to find an MBean by ManagementFactory
// DynamicMBean cannot be used to find an MBean by ManagementFactory
return Collections.emptySet();
}
@Override
public String getObjectNamePattern() {
return e.getKey().getCanonicalName();
return DIAGNOSTIC_COMMAND_MBEAN_NAME;
}
@Override
public Map<String, DynamicMBean> nameToMBeanMap() {
return Collections.<String, DynamicMBean>singletonMap(
e.getKey().getCanonicalName(),
e.getValue());
DIAGNOSTIC_COMMAND_MBEAN_NAME,
diagMBean);
}
});
}
initMBeanList.trimToSize();
return initMBeanList;
}
private static synchronized HotSpotDiagnosticMXBean getDiagnosticMXBean() {
if (hsDiagMBean == null) {
hsDiagMBean = new HotSpotDiagnostic();
}
return hsDiagMBean;
}
private static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
if (osMBean == null) {
osMBean = new OperatingSystemImpl(ManagementFactoryHelper.getVMManagement());
}
return osMBean;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import com.sun.management.VMOption;
import com.sun.management.VMOption.Origin;
@ -31,6 +31,8 @@ import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
import sun.management.LazyCompositeData;
import sun.management.MappedMXBeanType;
/**
* A CompositeData for VMOption for the local management support.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,10 @@
#include <stdlib.h>
#include <jni.h>
#include "management.h"
#include "sun_management_DiagnosticCommandImpl.h"
#include "management_ext.h"
#include "com_sun_management_internal_DiagnosticCommandImpl.h"
JNIEXPORT void JNICALL Java_sun_management_DiagnosticCommandImpl_setNotificationEnabled
JNIEXPORT void JNICALL Java_com_sun_management_internal_DiagnosticCommandImpl_setNotificationEnabled
(JNIEnv *env, jobject dummy, jboolean enabled) {
if (jmm_version <= JMM_VERSION_1_2_2) {
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
@ -39,7 +39,7 @@ JNIEXPORT void JNICALL Java_sun_management_DiagnosticCommandImpl_setNotification
}
JNIEXPORT jobjectArray JNICALL
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommands
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands
(JNIEnv *env, jobject dummy)
{
return jmm_interface->GetDiagnosticCommands(env);
@ -64,7 +64,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
dcmd_arg_info_array);
dcmdArgInfoCls = (*env)->FindClass(env,
"sun/management/DiagnosticCommandArgumentInfo");
"com/sun/management/internal/DiagnosticCommandArgumentInfo");
if ((*env)->ExceptionCheck(env)) {
free(dcmd_arg_info_array);
return NULL;
@ -77,7 +77,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
}
for (i=0; i<num_arg; i++) {
obj = JNU_NewObjectByName(env,
"sun/management/DiagnosticCommandArgumentInfo",
"com/sun/management/internal/DiagnosticCommandArgumentInfo",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V",
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].name),
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].description),
@ -113,7 +113,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
* passed in argument is not supported by the JVM
*/
JNIEXPORT jobjectArray JNICALL
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo
(JNIEnv *env, jobject dummy, jobjectArray commands)
{
int i;
@ -132,7 +132,7 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
}
num_commands = (*env)->GetArrayLength(env, commands);
dcmdInfoCls = (*env)->FindClass(env,
"sun/management/DiagnosticCommandInfo");
"com/sun/management/internal/DiagnosticCommandInfo");
if ((*env)->ExceptionCheck(env)) {
return NULL;
}
@ -163,7 +163,7 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
return NULL;
}
obj = JNU_NewObjectByName(env,
"sun/management/DiagnosticCommandInfo",
"com/sun/management/internal/DiagnosticCommandInfo",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V",
(*env)->NewStringUTF(env,dcmd_info_array[i].name),
(*env)->NewStringUTF(env,dcmd_info_array[i].description),
@ -188,7 +188,7 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
* passed in argument is not supported by the JVM
*/
JNIEXPORT jstring JNICALL
Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand
Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand
(JNIEnv *env, jobject dummy, jstring command) {
return jmm_interface->ExecuteDiagnosticCommand(env, command);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include "management.h"
#include "sun_management_Flag.h"
#include "management_ext.h"
#include "com_sun_management_internal_Flag.h"
static jobject default_origin = NULL;
static jobject vm_creation_origin = NULL;
@ -40,7 +40,7 @@ static jobject attach_origin = NULL;
static jobject other_origin = NULL;
JNIEXPORT jint JNICALL
Java_sun_management_Flag_getInternalFlagCount
Java_com_sun_management_internal_Flag_getInternalFlagCount
(JNIEnv *env, jclass cls)
{
jlong count = jmm_interface->GetLongAttribute(env, NULL,
@ -49,7 +49,7 @@ Java_sun_management_Flag_getInternalFlagCount
}
JNIEXPORT jobjectArray JNICALL
Java_sun_management_Flag_getAllFlagNames
Java_com_sun_management_internal_Flag_getAllFlagNames
(JNIEnv *env, jclass cls)
{
return jmm_interface->GetVMGlobalNames(env);
@ -66,7 +66,7 @@ static jobject find_origin_constant(JNIEnv* env, const char* enum_name) {
}
JNIEXPORT void JNICALL
Java_sun_management_Flag_initialize
Java_com_sun_management_internal_Flag_initialize
(JNIEnv *env, jclass cls)
{
default_origin = find_origin_constant(env, "DEFAULT");
@ -80,13 +80,13 @@ Java_sun_management_Flag_initialize
}
JNIEXPORT jint JNICALL
Java_sun_management_Flag_getFlags
Java_com_sun_management_internal_Flag_getFlags
(JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count)
{
jint num_flags, i, index;
jmmVMGlobal* globals;
size_t gsize;
const char* class_name = "sun/management/Flag";
const char* class_name = "com/sun/management/internal/Flag";
const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V";
jobject origin;
jobject valueObj;
@ -196,7 +196,7 @@ Java_sun_management_Flag_getFlags
}
JNIEXPORT void JNICALL
Java_sun_management_Flag_setLongValue
Java_com_sun_management_internal_Flag_setLongValue
(JNIEnv *env, jclass cls, jstring name, jlong value)
{
jvalue v;
@ -206,7 +206,7 @@ Java_sun_management_Flag_setLongValue
}
JNIEXPORT void JNICALL
Java_sun_management_Flag_setDoubleValue
Java_com_sun_management_internal_Flag_setDoubleValue
(JNIEnv *env, jclass cls, jstring name, jdouble value)
{
jvalue v;
@ -216,7 +216,7 @@ Java_sun_management_Flag_setDoubleValue
}
JNIEXPORT void JNICALL
Java_sun_management_Flag_setBooleanValue
Java_com_sun_management_internal_Flag_setBooleanValue
(JNIEnv *env, jclass cls, jstring name, jboolean value)
{
jvalue v;
@ -226,7 +226,7 @@ Java_sun_management_Flag_setBooleanValue
}
JNIEXPORT void JNICALL
Java_sun_management_Flag_setStringValue
Java_com_sun_management_internal_Flag_setStringValue
(JNIEnv *env, jclass cls, jstring name, jstring value)
{
jvalue v;

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
#include <jni.h>
#include "management_ext.h"
#include "com_sun_management_internal_GarbageCollectorExtImpl.h"
JNIEXPORT void JNICALL Java_com_sun_management_internal_GarbageCollectorExtImpl_setNotificationEnabled
(JNIEnv *env, jobject dummy, jobject gc,jboolean enabled) {
if (gc == NULL) {
JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean");
return;
}
if((jmm_version > JMM_VERSION_1_2)
|| (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=1))) {
jmm_interface->SetGCNotificationEnabled(env, gc, enabled);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,10 +26,10 @@
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
#include "management.h"
#include "sun_management_GcInfoBuilder.h"
#include "management_ext.h"
#include "com_sun_management_internal_GcInfoBuilder.h"
JNIEXPORT jint JNICALL Java_sun_management_GcInfoBuilder_getNumGcExtAttributes
JNIEXPORT jint JNICALL Java_com_sun_management_internal_GcInfoBuilder_getNumGcExtAttributes
(JNIEnv *env, jobject dummy, jobject gc) {
jlong value;
@ -42,7 +42,7 @@ JNIEXPORT jint JNICALL Java_sun_management_GcInfoBuilder_getNumGcExtAttributes
return (jint) value;
}
JNIEXPORT void JNICALL Java_sun_management_GcInfoBuilder_fillGcAttributeInfo
JNIEXPORT void JNICALL Java_com_sun_management_internal_GcInfoBuilder_fillGcAttributeInfo
(JNIEnv *env, jobject dummy, jobject gc,
jint num_attributes, jobjectArray attributeNames,
jcharArray types, jobjectArray descriptions) {
@ -173,7 +173,7 @@ static void setCharValueAtObjectArray(JNIEnv *env, jobjectArray array,
(*env)->SetObjectArrayElement(env, array, index, obj);
}
JNIEXPORT jobject JNICALL Java_sun_management_GcInfoBuilder_getLastGcInfo0
JNIEXPORT jobject JNICALL Java_com_sun_management_internal_GcInfoBuilder_getLastGcInfo0
(JNIEnv *env, jobject builder, jobject gc,
jint ext_att_count, jobjectArray ext_att_values, jcharArray ext_att_types,
jobjectArray usageBeforeGC, jobjectArray usageAfterGC) {
@ -273,7 +273,7 @@ JNIEXPORT jobject JNICALL Java_sun_management_GcInfoBuilder_getLastGcInfo0
return JNU_NewObjectByName(env,
"com/sun/management/GcInfo",
"(Lsun/management/GcInfoBuilder;JJJ[Ljava/lang/management/MemoryUsage;[Ljava/lang/management/MemoryUsage;[Ljava/lang/Object;)V",
"(Lcom/sun/management/internal/GcInfoBuilder;JJJ[Ljava/lang/management/MemoryUsage;[Ljava/lang/management/MemoryUsage;[Ljava/lang/Object;)V",
builder,
gc_stat.gc_index,
gc_stat.start_time,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
#include <jni.h>
#include "jvm.h"
#include "management.h"
#include "sun_management_HotSpotDiagnostic.h"
#include "management_ext.h"
#include "com_sun_management_internal_HotSpotDiagnostic.h"
JNIEXPORT void JNICALL
Java_sun_management_HotSpotDiagnostic_dumpHeap0
Java_com_sun_management_internal_HotSpotDiagnostic_dumpHeap0
(JNIEnv *env, jobject dummy, jstring outputfile, jboolean live)
{
jmm_interface->DumpHeap0(env, outputfile, live);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,33 +23,39 @@
* questions.
*/
package sun.management;
#include <stdio.h>
#include <jni.h>
#include "jvm.h"
#include "management_ext.h"
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.GarbageCollectorMXBean;
#define ERR_MSG_SIZE 128
/**
* ManagementFactory class provides the methods that the HotSpot VM
* will invoke. So the class and method names cannot be renamed.
*/
class ManagementFactory {
private ManagementFactory() {};
const JmmInterface* jmm_interface = NULL;
JavaVM* jvm = NULL;
jint jmm_version = 0;
// Invoked by the VM
private static MemoryPoolMXBean createMemoryPool
(String name, boolean isHeap, long uThreshold, long gcThreshold) {
return new MemoryPoolImpl(name, isHeap, uThreshold, gcThreshold);
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv* env;
jvm = vm;
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_2) != JNI_OK) {
return JNI_ERR;
}
private static MemoryManagerMXBean createMemoryManager(String name) {
return new MemoryManagerImpl(name);
jmm_interface = (JmmInterface*) JVM_GetManagement(JMM_VERSION_1_0);
if (jmm_interface == NULL) {
JNU_ThrowInternalError(env, "Unsupported Management version");
return JNI_ERR;
}
private static GarbageCollectorMXBean
createGarbageCollector(String name, String type) {
// ignore type parameter which is for future extension
return new GarbageCollectorImpl(name);
}
jmm_version = jmm_interface->GetVersion(env);
return (*env)->GetVersion(env);
}
void throw_internal_error(JNIEnv* env, const char* msg) {
char errmsg[128];
sprintf(errmsg, "errno: %d error: %s\n", errno, msg);
JNU_ThrowInternalError(env, errmsg);
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
#include <jni.h>
#include "jni_util.h"
#include "jmm.h"
#ifndef _MANAGEMENT_EXT_H_
#define _MANAGEMENT_EXT_H_
extern const JmmInterface* jmm_interface;
extern jint jmm_version;
extern void throw_internal_error(JNIEnv* env, const char* msg);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,7 +38,7 @@
#include <sys/loadavg.h>
#include <jni.h>
#include "jvm.h"
#include "sun_management_OperatingSystemImpl.h"
#include "com_sun_management_internal_OperatingSystemImpl.h"
typedef struct {
kstat_t *kstat;
@ -226,14 +226,14 @@ double get_process_load(void) {
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy)
{
return get_cpu_load(-1);
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy)
{
return get_process_load();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,10 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import sun.management.BaseOperatingSystemImpl;
import sun.management.VMManagement;
/**
* Implementation class for the operating system.
* Standard and committed hotspot-specific metrics if any.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "management.h"
#include "sun_management_OperatingSystemImpl.h"
#include "management_ext.h"
#include "com_sun_management_internal_OperatingSystemImpl.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -179,14 +179,14 @@ static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean availa
}
JNIEXPORT void JNICALL
Java_sun_management_OperatingSystemImpl_initialize0
Java_com_sun_management_internal_OperatingSystemImpl_initialize0
(JNIEnv *env, jclass cls)
{
page_size = sysconf(_SC_PAGESIZE);
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean)
{
#ifdef __solaris__
@ -256,21 +256,21 @@ Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0
Java_com_sun_management_internal_OperatingSystemImpl_getTotalSwapSpaceSize0
(JNIEnv *env, jobject mbean)
{
return get_total_or_available_swap_space_size(env, JNI_FALSE);
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0
Java_com_sun_management_internal_OperatingSystemImpl_getFreeSwapSpaceSize0
(JNIEnv *env, jobject mbean)
{
return get_total_or_available_swap_space_size(env, JNI_TRUE);
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuTime0
(JNIEnv *env, jobject mbean)
{
#ifdef __APPLE__
@ -312,7 +312,7 @@ Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getFreePhysicalMemorySize0
(JNIEnv *env, jobject mbean)
{
#ifdef __APPLE__
@ -346,7 +346,7 @@ Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getTotalPhysicalMemorySize0
(JNIEnv *env, jobject mbean)
{
#ifdef _ALLBSD_SOURCE
@ -377,7 +377,7 @@ Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0
Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0
(JNIEnv *env, jobject mbean)
{
#ifdef __APPLE__
@ -466,7 +466,7 @@ Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getMaxFileDescriptorCount0
Java_com_sun_management_internal_OperatingSystemImpl_getMaxFileDescriptorCount0
(JNIEnv *env, jobject mbean)
{
struct rlimit rlp;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,9 +23,11 @@
* questions.
*/
package sun.management;
package com.sun.management.internal;
import com.sun.management.OperatingSystemMXBean;
import sun.management.BaseOperatingSystemImpl;
import sun.management.VMManagement;
/**
* Implementation class for the operating system.
@ -45,36 +47,44 @@ class OperatingSystemImpl extends BaseOperatingSystemImpl
super(vm);
}
@Override
public long getCommittedVirtualMemorySize() {
synchronized (psapiLock) {
return getCommittedVirtualMemorySize0();
}
}
@Override
public long getTotalSwapSpaceSize() {
return getTotalSwapSpaceSize0();
}
@Override
public long getFreeSwapSpaceSize() {
return getFreeSwapSpaceSize0();
}
@Override
public long getProcessCpuTime() {
return getProcessCpuTime0();
}
@Override
public long getFreePhysicalMemorySize() {
return getFreePhysicalMemorySize0();
}
@Override
public long getTotalPhysicalMemorySize() {
return getTotalPhysicalMemorySize0();
}
@Override
public double getSystemCpuLoad() {
return getSystemCpuLoad0();
}
@Override
public double getProcessCpuLoad() {
return getProcessCpuLoad0();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "management.h"
#include "sun_management_OperatingSystemImpl.h"
#include "management_ext.h"
#include "com_sun_management_internal_OperatingSystemImpl.h"
#include <psapi.h>
#include <errno.h>
@ -75,7 +75,7 @@ static HANDLE main_process;
static void perfInit(void);
JNIEXPORT void JNICALL
Java_sun_management_OperatingSystemImpl_initialize0
Java_com_sun_management_internal_OperatingSystemImpl_initialize0
(JNIEnv *env, jclass cls)
{
main_process = GetCurrentProcess();
@ -83,7 +83,7 @@ Java_sun_management_OperatingSystemImpl_initialize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean)
{
PROCESS_MEMORY_COUNTERS pmc;
@ -95,7 +95,7 @@ Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0
Java_com_sun_management_internal_OperatingSystemImpl_getTotalSwapSpaceSize0
(JNIEnv *env, jobject mbean)
{
MEMORYSTATUSEX ms;
@ -105,7 +105,7 @@ Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0
Java_com_sun_management_internal_OperatingSystemImpl_getFreeSwapSpaceSize0
(JNIEnv *env, jobject mbean)
{
MEMORYSTATUSEX ms;
@ -115,7 +115,7 @@ Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuTime0
(JNIEnv *env, jobject mbean)
{
@ -134,7 +134,7 @@ Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getFreePhysicalMemorySize0
(JNIEnv *env, jobject mbean)
{
MEMORYSTATUSEX ms;
@ -144,7 +144,7 @@ Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
}
JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0
Java_com_sun_management_internal_OperatingSystemImpl_getTotalPhysicalMemorySize0
(JNIEnv *env, jobject mbean)
{
MEMORYSTATUSEX ms;
@ -1349,14 +1349,14 @@ perfGetCPULoad(int which) {
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy)
{
return perfGetCPULoad(-1);
}
JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy)
{
return perfGetProcessCPULoad();

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
import java.lang.management.ManagementFactory;
import java.lang.management.PlatformManagedObject;
/*
* @test
* @bug 8042901
* @summary If jdk.management is present, GarbageCollectorMXBean and ThreadMXBean
* must be from com.sun.management.internal
* @author Shanliang Jiang
*/
public class CheckSomeMXBeanImplPackage {
private static String implPackageName = "com.sun.management.internal";
public static void main(String[] args) throws Exception {
boolean present = false;
try {
Class.forName("com.sun.management.GarbageCollectorMXBean");
present = true;
} catch (ClassNotFoundException cnfe) {}
if (present) {
Class <? extends PlatformManagedObject> klazz =
java.lang.management.GarbageCollectorMXBean.class;
for (Object obj :
ManagementFactory.getPlatformMXBeans(klazz)) {
check(klazz.getName(), obj);
}
klazz = com.sun.management.GarbageCollectorMXBean.class;
for (Object obj :
ManagementFactory.getPlatformMXBeans(klazz)) {
check(klazz.getName(), obj);
}
klazz = java.lang.management.ThreadMXBean.class;
check(klazz.getName(),
ManagementFactory.getPlatformMXBean(klazz));
klazz = com.sun.management.ThreadMXBean.class;
check(klazz.getName(),
ManagementFactory.getPlatformMXBean(klazz));
System.out.println("--- PASSED!");
} else {
System.out.println("--- Skip the test, jdk.management module is not present!");
}
}
private static void check(String mbeanName, Object impl) {
if (!impl.getClass().getName().startsWith(implPackageName)) {
throw new RuntimeException(mbeanName+" implementation package "
+ "should be: " + implPackageName
+ ", but got: " + impl.getClass());
} else {
System.out.println("--- Good, "+mbeanName+" got right implementation: " + impl);
}
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
import com.sun.management.VMOption;
import java.io.InvalidObjectException;
import java.util.Objects;
import javax.management.openmbean.OpenDataException;
import sun.management.MappedMXBeanType;
/*
* @test
* @bug 8042901
* @summary Check that MappedMXBeanType.toOpenTypeData supports VMOption
* @author Shanliang Jiang
*/
public class VMOptionOpenDataTest {
public static void main(String[] args) throws Exception {
System.out.println("--- VMOptionOpenDataTest-main: Checking that "
+ "MappedMXBeanType.toOpenTypeData supports VMOption");
Exception failed = null;
try {
VMOption vo = new VMOption("toto", "titi", true, VMOption.Origin.OTHER);
System.out.println("--- Construct a VMOption object: \"" + vo + "\"");
Object open = MappedMXBeanType.toOpenTypeData(vo, VMOption.class);
System.out.println("--- Map it to an open type: \"" + open +" \"");
Object back = MappedMXBeanType.toJavaTypeData(open, VMOption.class);
System.out.println("--- Map it back to java type: \"" + back +" \"");
if (back == null) {
failed = new RuntimeException("Failed, mapping back got null.");
} else if (!(back instanceof VMOption)) {
failed = new RuntimeException("Failed, not mapped back to a VMOption: "
+back.getClass());
} else {
VMOption mapBack = (VMOption)back;
if (!Objects.equals(vo.getName(), mapBack.getName()) ||
!Objects.equals(vo.getOrigin(), mapBack.getOrigin()) ||
!Objects.equals(vo.getValue(), mapBack.getValue()) ||
vo.isWriteable() != mapBack.isWriteable()) {
failed = new RuntimeException(
"Failed, failed to map back the original VMOtion.");
}
}
} catch (OpenDataException | InvalidObjectException ode) {
failed = ode;
}
if (failed == null) {
System.out.println("--- PASSED!");
} else {
System.out.println("--- Failed: "+failed.getMessage());
throw failed;
}
}
}

View File

@ -27,8 +27,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Arrays;
import java.util.stream.Collectors;
import sun.management.ManagementFactoryHelper;
import com.sun.management.DiagnosticCommandMBean;
import java.lang.management.ManagementFactory;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
public class NMTHelper
{
@ -53,7 +54,12 @@ public class NMTHelper
}
private static String executeDcmd(String cmd, String ... args) {
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
ObjectName oname = null;
try {
oname = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand");
} catch (MalformedObjectNameException mone) {
throw new RuntimeException(mone);
}
Object[] dcmdArgs = {args};
String[] signature = {String[].class.getName()};
@ -63,7 +69,8 @@ public class NMTHelper
System.out.println("Output from Dcmd '" + cmdString + "' is being written to file " + f);
try (FileWriter fw = new FileWriter(f)) {
fw.write("> " + cmdString + ":");
String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
String result = (String)ManagementFactory.getPlatformMBeanServer().
invoke(oname, cmd, dcmdArgs, signature);
fw.write(result);
return result;
} catch(Exception ex) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,7 +31,8 @@ import java.lang.management.ThreadInfo;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch;
import sun.management.ManagementFactoryHelper;
import javax.management.JMX;
import javax.management.ObjectName;
/**
* When an exception is thrown, the JVM collects just enough information
@ -103,8 +104,11 @@ public class RedefineMethodInBacktraceApp {
String[] threadPrintArgs = {};
Object[] dcmdArgs = {threadPrintArgs};
String[] signature = {String[].class.getName()};
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature));
System.out.println(ManagementFactory.getPlatformMBeanServer().invoke(
ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"),
"threadPrint",
dcmdArgs,
signature));
// release the thread
stop.countDown();

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
import java.security.AccessControlException;
import java.security.Permission;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.util.List;
/*
* @test
* @bug 8042901
* @summary Check permission for PlatformMBeanProvider Constructor
* @author Shanliang Jiang
*/
public class PlatformMBeanProviderConstructorCheck {
public static void main(String[] args) throws Exception {
Policy origPolicy = Policy.getPolicy();
SecurityManager origSM = System.getSecurityManager();
try {
System.out.println("---PlatformMBeanProviderConstructorCheck starting...");
Policy.setPolicy(new MyPolicy());
System.setSecurityManager(new SecurityManager());
System.out.println("---PlatformMBeanProviderConstructorCheck Testing without permission...");
try {
new MyProvider();
throw new RuntimeException("Does not get expected AccessControlException!");
} catch (AccessControlException ace) {
System.out.println("---PlatformMBeanProviderConstructorCheck got the expected exception: "
+ ace);
}
System.out.println("---PlatformMBeanProviderConstructorCheck Testing with permission...");
MyPolicy.allowed = true;
new MyProvider();
System.out.println("---PlatformMBeanProviderConstructorCheck PASSED!");
} finally {
System.setSecurityManager(origSM);
Policy.setPolicy(origPolicy);
}
}
private static class MyPolicy extends Policy {
private static String permName = "sun.management.spi.PlatformMBeanProvider.subclass";
private static boolean allowed = false;
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
if (permName.equals(permission.getName())) {
System.out.println("---MyPolicy-implies checks permission for "
+permName+" and returns "+allowed);
return allowed;
} else {
return true;
}
}
}
private static class MyProvider extends sun.management.spi.PlatformMBeanProvider {
@Override
public List<PlatformComponent<?>> getPlatformComponentList() {
return null;
}
}
}