This commit is contained in:
Alejandro Murillo 2015-05-01 03:56:04 -07:00
commit c185e9a5bf
103 changed files with 3026 additions and 1266 deletions

View File

@ -32,11 +32,11 @@ include MakeBase.gmk
# Put the libraries here. Different locations for different target OS types. # Put the libraries here. Different locations for different target OS types.
ifneq ($(OPENJDK_TARGET_OS), windows) ifneq ($(OPENJDK_TARGET_OS), windows)
HOTSPOT_LIB_DIR := $(HOTSPOT_DIST)/jre/lib$(OPENJDK_TARGET_CPU_LIBDIR) HOTSPOT_LIB_DIR := $(HOTSPOT_DIST)/lib$(OPENJDK_TARGET_CPU_LIBDIR)
BASE_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR) BASE_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)
SA_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.hotspot.agent$(OPENJDK_TARGET_CPU_LIBDIR) SA_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.hotspot.agent$(OPENJDK_TARGET_CPU_LIBDIR)
else else
HOTSPOT_LIB_DIR := $(HOTSPOT_DIST)/jre/bin HOTSPOT_LIB_DIR := $(HOTSPOT_DIST)/bin
BASE_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base BASE_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
SA_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.hotspot.agent SA_INSTALL_LIBRARIES_HERE := $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.hotspot.agent
endif endif
@ -80,11 +80,11 @@ SA_TARGETS := $(COPY_HOTSPOT_SA)
################################################################################ ################################################################################
ifeq ($(OPENJDK_TARGET_OS), macosx) ifeq ($(OPENJDK_TARGET_OS), macosx)
JSIG_DEBUGINFO := $(strip $(wildcard $(HOTSPOT_DIST)/jre/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig$(SHARED_LIBRARY_SUFFIX).dSYM) \ JSIG_DEBUGINFO := $(strip $(wildcard $(HOTSPOT_DIST)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig$(SHARED_LIBRARY_SUFFIX).dSYM) \
$(wildcard $(HOTSPOT_DIST)/jre/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.diz) ) $(wildcard $(HOTSPOT_DIST)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.diz) )
else else
JSIG_DEBUGINFO := $(strip $(wildcard $(HOTSPOT_DIST)/jre/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.debuginfo) \ JSIG_DEBUGINFO := $(strip $(wildcard $(HOTSPOT_DIST)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.debuginfo) \
$(wildcard $(HOTSPOT_DIST)/jre/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.diz) ) $(wildcard $(HOTSPOT_DIST)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/libjsig.diz) )
endif endif
ifneq ($(OPENJDK_TARGET_OS), windows) ifneq ($(OPENJDK_TARGET_OS), windows)

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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
include LibCommon.gmk include LibCommon.gmk
# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, jdk, lib/Lib-java.instrument.gmk))
################################################################################ ################################################################################
LIBINSTRUMENT_SRC := $(JDK_TOPDIR)/src/java.instrument/share/native/libinstrument \ LIBINSTRUMENT_SRC := $(JDK_TOPDIR)/src/java.instrument/share/native/libinstrument \

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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -30,10 +30,10 @@ $(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 $(JDK_TOPDIR)/src/java.management/$(OPENJDK_TARGET_OS_TYPE)/native/libmanagement
BUILD_LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/include \ LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/include \
$(addprefix -I,$(BUILD_LIBMANAGEMENT_SRC)) \ $(addprefix -I,$(LIBMANAGEMENT_SRC)) \
-I$(SUPPORT_OUTPUTDIR)/headers/java.management \ -I$(SUPPORT_OUTPUTDIR)/headers/java.management \
$(LIBJAVA_HEADER_FLAGS) \ $(LIBJAVA_HEADER_FLAGS) \
# #
@ -43,20 +43,6 @@ BUILD_LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/java.management/share/native/i
# See MSDN documentation for GetProcessMemoryInfo for more information. # See MSDN documentation for GetProcessMemoryInfo for more information.
BUILD_LIBMANAGEMENT_CFLAGS += -DPSAPI_VERSION=1 BUILD_LIBMANAGEMENT_CFLAGS += -DPSAPI_VERSION=1
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 LIBMANAGEMENT_OPTIMIZATION := HIGH
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), ) ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
ifeq ($(ENABLE_DEBUG_SYMBOLS), true) ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
@ -64,17 +50,13 @@ ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
endif endif
endif endif
# Make it possible to override this variable
LIBMANAGEMENT_MAPFILE ?= $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers
$(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT, \ $(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT, \
LIBRARY := management, \ LIBRARY := management, \
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
SRC := $(BUILD_LIBMANAGEMENT_SRC), \ SRC := $(LIBMANAGEMENT_SRC), \
EXCLUDE_FILES := $(BUILD_LIBMANAGEMENT_EXCLUDES), \
OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \ OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(BUILD_LIBMANAGEMENT_CFLAGS), \ CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(LIBMANAGEMENT_CFLAGS), \
MAPFILE := $(LIBMANAGEMENT_MAPFILE), \ MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers, \
LDFLAGS := $(LDFLAGS_JDKLIB) \ LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \ $(call SET_SHARED_LIBRARY_ORIGIN), \
LDFLAGS_solaris := -lkstat, \ 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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -27,37 +27,10 @@
SUNWprivate_1.1 { SUNWprivate_1.1 {
global: 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_ClassLoadingImpl_setVerboseClass;
Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand; Java_sun_management_FileSystemImpl_isAccessUserOnly0;
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommands; Java_sun_management_GarbageCollectorImpl_getCollectionCount;
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_GarbageCollectorImpl_getCollectionTime; 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_getInternalThreadCount;
Java_sun_management_HotspotThread_getInternalThreadTimes0; Java_sun_management_HotspotThread_getInternalThreadTimes0;
Java_sun_management_MemoryImpl_getMemoryManagers0; 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.hprof.agent
jdk.httpserver jdk.httpserver
jdk.jfr jdk.jfr
jdk.management
jdk.management.cmm jdk.management.cmm
jdk.naming.rmi jdk.naming.rmi
jdk.sctp jdk.sctp

View File

@ -38,7 +38,17 @@ import static com.sun.crypto.provider.AESConstants.AES_BLOCK_SIZE;
* under section 6.5. It needs to be constructed w/ an initialized * under section 6.5. It needs to be constructed w/ an initialized
* cipher object, and initial counter block(ICB). Given an input X * cipher object, and initial counter block(ICB). Given an input X
* of arbitrary length, it processes and returns an output which has * of arbitrary length, it processes and returns an output which has
* the same length as X. * the same length as X. The invariants of this class are:
*
* (1) The length of intialCounterBlk (and also of its clones, e.g.,
* fields counter and counterSave) is equal to AES_BLOCK_SIZE.
*
* (2) After construction, the field counter never becomes null, it
* always contains a byte array of length AES_BLOCK_SIZE.
*
* If any invariant is broken, failures can occur because the
* AESCrypt.encryptBlock method can be intrinsified on the HotSpot VM
* (see JDK-8067648 for details).
* *
* <p>This function is used in the implementation of GCM mode. * <p>This function is used in the implementation of GCM mode.
* *
@ -59,6 +69,10 @@ final class GCTR {
// NOTE: cipher should already be initialized // NOTE: cipher should already be initialized
GCTR(SymmetricCipher cipher, byte[] initialCounterBlk) { GCTR(SymmetricCipher cipher, byte[] initialCounterBlk) {
this.aes = cipher; this.aes = cipher;
if (initialCounterBlk.length != AES_BLOCK_SIZE) {
throw new RuntimeException("length of initial counter block (" + initialCounterBlk.length +
") not equal to AES_BLOCK_SIZE (" + AES_BLOCK_SIZE + ")");
}
this.icb = initialCounterBlk; this.icb = initialCounterBlk;
this.counter = icb.clone(); this.counter = icb.clone();
} }
@ -137,6 +151,8 @@ final class GCTR {
* Restores the content of this object to the previous saved one. * Restores the content of this object to the previous saved one.
*/ */
void restore() { void restore() {
this.counter = this.counterSave; if (this.counterSave != null) {
this.counter = this.counterSave;
}
} }
} }

View File

@ -1312,7 +1312,7 @@ public final class Class<T> implements java.io.Serializable,
// e) Anonymous classes // e) Anonymous classes
// JVM Spec 4.8.6: A class must have an EnclosingMethod // JVM Spec 4.7.7: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an // attribute if and only if it is a local class or an
// anonymous class. // anonymous class.
EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo(); EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
@ -1357,28 +1357,7 @@ public final class Class<T> implements java.io.Serializable,
simpleName = getName(); simpleName = getName();
return simpleName.substring(simpleName.lastIndexOf('.')+1); // strip the package name return simpleName.substring(simpleName.lastIndexOf('.')+1); // strip the package name
} }
// According to JLS3 "Binary Compatibility" (13.1) the binary return simpleName;
// name of non-package classes (not top level) is the binary
// name of the immediately enclosing class followed by a '$' followed by:
// (for nested and inner classes): the simple name.
// (for local classes): 1 or more digits followed by the simple name.
// (for anonymous classes): 1 or more digits.
// Since getSimpleBinaryName() will strip the binary name of
// the immediately enclosing class, we are now looking at a
// string that matches the regular expression "\$[0-9]*"
// followed by a simple name (considering the simple of an
// anonymous class to be the empty string).
// Remove leading "\$[0-9]*" from the name
int length = simpleName.length();
if (length < 1 || simpleName.charAt(0) != '$')
throw new InternalError("Malformed class name");
int index = 1;
while (index < length && isAsciiDigit(simpleName.charAt(index)))
index++;
// Eventually, this is the empty string iff this is an anonymous class
return simpleName.substring(index);
} }
/** /**
@ -1489,20 +1468,20 @@ public final class Class<T> implements java.io.Serializable,
Class<?> enclosingClass = getEnclosingClass(); Class<?> enclosingClass = getEnclosingClass();
if (enclosingClass == null) // top level class if (enclosingClass == null) // top level class
return null; return null;
// Otherwise, strip the enclosing class' name String name = getSimpleBinaryName0();
try { if (name == null) // anonymous class
return getName().substring(enclosingClass.getName().length()); return "";
} catch (IndexOutOfBoundsException ex) { return name;
throw new InternalError("Malformed class name", ex);
}
} }
private native String getSimpleBinaryName0();
/** /**
* Returns {@code true} if this is a local class or an anonymous * Returns {@code true} if this is a local class or an anonymous
* class. Returns {@code false} otherwise. * class. Returns {@code false} otherwise.
*/ */
private boolean isLocalOrAnonymousClass() { private boolean isLocalOrAnonymousClass() {
// JVM Spec 4.8.6: A class must have an EnclosingMethod // JVM Spec 4.7.7: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an // attribute if and only if it is a local class or an
// anonymous class. // anonymous class.
return getEnclosingMethodInfo() != null; return getEnclosingMethodInfo() != null;

View File

@ -25,9 +25,10 @@
package java.lang.invoke; package java.lang.invoke;
import sun.invoke.empty.Empty;
import static java.lang.invoke.MethodHandleStatics.*; import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
import java.lang.reflect.Field;
import sun.misc.Cleaner;
/** /**
* A {@code CallSite} is a holder for a variable {@link MethodHandle}, * A {@code CallSite} is a holder for a variable {@link MethodHandle},
@ -135,6 +136,50 @@ public class CallSite {
this.target = boundTarget; this.target = boundTarget;
} }
/**
* {@code CallSite} dependency context.
* VM uses context class to store nmethod dependencies on the call site target.
* Can be in 2 states: (a) null; or (b) {@code Cleaner} instance pointing to some Class instance.
* Lazily initialized when CallSite instance is linked to some indy call site or VM needs
* it to store dependencies. As a corollary, "null" context means there are no dependencies
* registered yet. {@code Cleaner} is used in 2 roles:
* (a) context class access for VM;
* (b) stale context class cleanup.
* {@code Cleaner} holds the context class until cleanup action is finished (see {@code PhantomReference}).
* Though it's impossible to get the context class using {@code Reference.get()}, VM extracts it directly
* from {@code Reference.referent} field.
*/
private volatile Cleaner context = null;
/**
* Default context.
* VM uses it to initialize non-linked CallSite context.
*/
private static class DefaultContext {}
private static final Cleaner DEFAULT_CONTEXT = makeContext(DefaultContext.class, null);
private static Cleaner makeContext(Class<?> referent, final CallSite holder) {
return Cleaner.create(referent,
new Runnable() {
@Override public void run() {
MethodHandleNatives.invalidateDependentNMethods(holder);
}
});
}
/** Initialize context class used for nmethod dependency tracking */
/*package-private*/
void initContext(Class<?> newContext) {
// If there are concurrent actions, exactly one succeeds.
if (context == null) {
UNSAFE.compareAndSwapObject(this, CONTEXT_OFFSET, /*expected=*/null, makeContext(newContext, this));
// No need to care about failed CAS attempt.
// Since initContext is called from indy call site linkage in newContext class, there's no risk
// that the context class becomes dead while corresponding context cleaner is alive (causing cleanup
// action in the wrong context).
}
}
/** /**
* Returns the type of this call site's target. * Returns the type of this call site's target.
* Although targets may change, any call site's type is permanent, and can never change to an unequal type. * Although targets may change, any call site's type is permanent, and can never change to an unequal type.
@ -246,11 +291,13 @@ public class CallSite {
} }
// unsafe stuff: // unsafe stuff:
private static final long TARGET_OFFSET; private static final long TARGET_OFFSET;
private static final long CONTEXT_OFFSET;
static { static {
try { try {
TARGET_OFFSET = UNSAFE.objectFieldOffset(CallSite.class.getDeclaredField("target")); TARGET_OFFSET = UNSAFE.objectFieldOffset(CallSite.class.getDeclaredField("target"));
} catch (Exception ex) { throw new Error(ex); } CONTEXT_OFFSET = UNSAFE.objectFieldOffset(CallSite.class.getDeclaredField("context"));
} catch (Exception ex) { throw newInternalError(ex); }
} }
/*package-private*/ /*package-private*/

View File

@ -691,10 +691,4 @@ class DirectMethodHandle extends MethodHandle {
} }
} }
} }
@Override
void customize() {
assert(form.customized == null);
// No need to customize DMHs.
}
} }

View File

@ -847,11 +847,7 @@ class InvokerBytecodeGenerator {
refKind = REF_invokeVirtual; refKind = REF_invokeVirtual;
} }
if (member.getDeclaringClass().isInterface() && refKind == REF_invokeVirtual) { assert(!(member.getDeclaringClass().isInterface() && refKind == REF_invokeVirtual));
// Methods from Object declared in an interface can be resolved by JVM to invokevirtual kind.
// Need to convert it back to invokeinterface to pass verification and make the invocation works as expected.
refKind = REF_invokeInterface;
}
// push arguments // push arguments
emitPushArguments(name); emitPushArguments(name);

View File

@ -281,7 +281,7 @@ class Invokers {
outArgs[0] = names[CHECK_TYPE]; outArgs[0] = names[CHECK_TYPE];
} }
if (CHECK_CUSTOM != -1) { if (CHECK_CUSTOM != -1) {
names[CHECK_CUSTOM] = new Name(NF_checkCustomized, names[CALL_MH]); names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]);
} }
names[LINKER_CALL] = new Name(outCallType, outArgs); names[LINKER_CALL] = new Name(outCallType, outArgs);
lform = new LambdaForm(debugName, INARG_LIMIT, names); lform = new LambdaForm(debugName, INARG_LIMIT, names);
@ -394,6 +394,7 @@ class Invokers {
@ForceInline @ForceInline
void checkCustomized(Object o) { void checkCustomized(Object o) {
MethodHandle mh = (MethodHandle)o; MethodHandle mh = (MethodHandle)o;
if (MethodHandleImpl.isCompileConstant(mh)) return;
if (mh.form.customized == null) { if (mh.form.customized == null) {
maybeCustomize(mh); maybeCustomize(mh);
} }

View File

@ -722,6 +722,13 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
return result; return result;
} }
// Intrinsified by C2. Returns true if obj is a compile-time constant.
@LambdaForm.Hidden
static
boolean isCompileConstant(Object obj) {
return false;
}
static static
MethodHandle makeGuardWithTest(MethodHandle test, MethodHandle makeGuardWithTest(MethodHandle test,
MethodHandle target, MethodHandle target,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,121 +55,42 @@ class MethodHandleNatives {
static native Object staticFieldBase(MemberName self); // e.g., returns clazz static native Object staticFieldBase(MemberName self); // e.g., returns clazz
static native Object getMemberVMInfo(MemberName self); // returns {vmindex,vmtarget} static native Object getMemberVMInfo(MemberName self); // returns {vmindex,vmtarget}
/// MethodHandle support
/** Fetch MH-related JVM parameter.
* which=0 retrieves MethodHandlePushLimit
* which=1 retrieves stack slot push size (in address units)
*/
static native int getConstant(int which);
static final boolean COUNT_GWT;
/// CallSite support /// CallSite support
/** Tell the JVM that we need to change the target of a CallSite. */ /** Tell the JVM that we need to change the target of a CallSite. */
static native void setCallSiteTargetNormal(CallSite site, MethodHandle target); static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target); static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
/** Invalidate CallSite context: clean up dependent nmethods and reset call site context to initial state (null). */
static native void invalidateDependentNMethods(CallSite site);
private static native void registerNatives(); private static native void registerNatives();
static { static {
registerNatives(); registerNatives();
COUNT_GWT = getConstant(Constants.GC_COUNT_GWT) != 0;
// The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed: // The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed:
MethodHandleImpl.initStatics(); MethodHandleImpl.initStatics();
} }
// All compile-time constants go here. /**
// There is an opportunity to check them against the JVM's idea of them. * Compile-time constants go here. This collection exists not only for
* reference from clients, but also for ensuring the VM and JDK agree on the
* values of these constants (see {@link #verifyConstants()}).
*/
static class Constants { static class Constants {
Constants() { } // static only Constants() { } // static only
// MethodHandleImpl
static final int // for getConstant
GC_COUNT_GWT = 4,
GC_LAMBDA_SUPPORT = 5;
// MemberName
// The JVM uses values of -2 and above for vtable indexes.
// Field values are simple positive offsets.
// Ref: src/share/vm/oops/methodOop.hpp
// This value is negative enough to avoid such numbers,
// but not too negative.
static final int static final int
MN_IS_METHOD = 0x00010000, // method (not constructor) MN_IS_METHOD = 0x00010000, // method (not constructor)
MN_IS_CONSTRUCTOR = 0x00020000, // constructor MN_IS_CONSTRUCTOR = 0x00020000, // constructor
MN_IS_FIELD = 0x00040000, // field MN_IS_FIELD = 0x00040000, // field
MN_IS_TYPE = 0x00080000, // nested type MN_IS_TYPE = 0x00080000, // nested type
MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
MN_REFERENCE_KIND_SHIFT = 24, // refKind MN_REFERENCE_KIND_SHIFT = 24, // refKind
MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT, MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
// The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers: // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
MN_SEARCH_SUPERCLASSES = 0x00100000, MN_SEARCH_SUPERCLASSES = 0x00100000,
MN_SEARCH_INTERFACES = 0x00200000; MN_SEARCH_INTERFACES = 0x00200000;
/**
* Basic types as encoded in the JVM. These code values are not
* intended for use outside this class. They are used as part of
* a private interface between the JVM and this class.
*/
static final int
T_BOOLEAN = 4,
T_CHAR = 5,
T_FLOAT = 6,
T_DOUBLE = 7,
T_BYTE = 8,
T_SHORT = 9,
T_INT = 10,
T_LONG = 11,
T_OBJECT = 12,
//T_ARRAY = 13
T_VOID = 14,
//T_ADDRESS = 15
T_ILLEGAL = 99;
/**
* Constant pool entry types.
*/
static final byte
CONSTANT_Utf8 = 1,
CONSTANT_Integer = 3,
CONSTANT_Float = 4,
CONSTANT_Long = 5,
CONSTANT_Double = 6,
CONSTANT_Class = 7,
CONSTANT_String = 8,
CONSTANT_Fieldref = 9,
CONSTANT_Methodref = 10,
CONSTANT_InterfaceMethodref = 11,
CONSTANT_NameAndType = 12,
CONSTANT_MethodHandle = 15, // JSR 292
CONSTANT_MethodType = 16, // JSR 292
CONSTANT_InvokeDynamic = 18,
CONSTANT_LIMIT = 19; // Limit to tags found in classfiles
/**
* Access modifier flags.
*/
static final char
ACC_PUBLIC = 0x0001,
ACC_PRIVATE = 0x0002,
ACC_PROTECTED = 0x0004,
ACC_STATIC = 0x0008,
ACC_FINAL = 0x0010,
ACC_SYNCHRONIZED = 0x0020,
ACC_VOLATILE = 0x0040,
ACC_TRANSIENT = 0x0080,
ACC_NATIVE = 0x0100,
ACC_INTERFACE = 0x0200,
ACC_ABSTRACT = 0x0400,
ACC_STRICT = 0x0800,
ACC_SYNTHETIC = 0x1000,
ACC_ANNOTATION = 0x2000,
ACC_ENUM = 0x4000,
// aliases:
ACC_SUPER = ACC_SYNCHRONIZED,
ACC_BRIDGE = ACC_VOLATILE,
ACC_VARARGS = ACC_TRANSIENT;
/** /**
* Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries. * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
@ -314,6 +235,7 @@ class MethodHandleNatives {
return Invokers.linkToTargetMethod(type); return Invokers.linkToTargetMethod(type);
} else { } else {
appendixResult[0] = callSite; appendixResult[0] = callSite;
callSite.initContext(caller);
return Invokers.linkToCallSiteMethod(type); return Invokers.linkToCallSiteMethod(type);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -567,32 +567,13 @@ class Bits { // package-private
// -- Processor and memory-system properties -- // -- Processor and memory-system properties --
private static final ByteOrder byteOrder; private static final ByteOrder byteOrder
= unsafe.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
static ByteOrder byteOrder() { static ByteOrder byteOrder() {
if (byteOrder == null)
throw new Error("Unknown byte order");
return byteOrder; return byteOrder;
} }
static {
long a = unsafe.allocateMemory(8);
try {
unsafe.putLong(a, 0x0102030405060708L);
byte b = unsafe.getByte(a);
switch (b) {
case 0x01: byteOrder = ByteOrder.BIG_ENDIAN; break;
case 0x08: byteOrder = ByteOrder.LITTLE_ENDIAN; break;
default:
assert false;
byteOrder = null;
}
} finally {
unsafe.freeMemory(a);
}
}
private static int pageSize = -1; private static int pageSize = -1;
static int pageSize() { static int pageSize() {
@ -605,17 +586,9 @@ class Bits { // package-private
return (int)(size + (long)pageSize() - 1L) / pageSize(); return (int)(size + (long)pageSize() - 1L) / pageSize();
} }
private static boolean unaligned; private static boolean unaligned = unsafe.unalignedAccess();
private static boolean unalignedKnown = false;
static boolean unaligned() { static boolean unaligned() {
if (unalignedKnown)
return unaligned;
String arch = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("os.arch"));
unaligned = arch.equals("i386") || arch.equals("x86")
|| arch.equals("amd64") || arch.equals("x86_64");
unalignedKnown = true;
return unaligned; return unaligned;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
package java.nio; package java.nio;
import sun.misc.Unsafe;
/** /**
#if[rw] #if[rw]
@ -52,6 +53,16 @@ class Heap$Type$Buffer$RW$
#end[rw] #end[rw]
*/ */
#if[byte]
// Cached unsafe-access object
private static final Unsafe unsafe = Bits.unsafe();
// Cached array base offset
private static final long arrayBaseOffset = unsafe.arrayBaseOffset($type$[].class);
#end[byte]
Heap$Type$Buffer$RW$(int cap, int lim) { // package-private Heap$Type$Buffer$RW$(int cap, int lim) { // package-private
#if[rw] #if[rw]
super(-1, 0, lim, cap, new $type$[cap], 0); super(-1, 0, lim, cap, new $type$[cap], 0);
@ -131,6 +142,12 @@ class Heap$Type$Buffer$RW$
return i + offset; return i + offset;
} }
#if[byte]
private long byteOffset(long i) {
return arrayBaseOffset + i + offset;
}
#end[byte]
public $type$ get() { public $type$ get() {
return hb[ix(nextGetIndex())]; return hb[ix(nextGetIndex())];
} }
@ -256,18 +273,18 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public char getChar() { public char getChar() {
return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian); return unsafe.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
} }
public char getChar(int i) { public char getChar(int i) {
return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian); return unsafe.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
} }
#end[rw] #end[rw]
public $Type$Buffer putChar(char x) { public $Type$Buffer putChar(char x) {
#if[rw] #if[rw]
Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian); unsafe.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -276,7 +293,7 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putChar(int i, char x) { public $Type$Buffer putChar(int i, char x) {
#if[rw] #if[rw]
Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian); unsafe.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -307,18 +324,18 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public short getShort() { public short getShort() {
return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian); return unsafe.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian);
} }
public short getShort(int i) { public short getShort(int i) {
return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian); return unsafe.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian);
} }
#end[rw] #end[rw]
public $Type$Buffer putShort(short x) { public $Type$Buffer putShort(short x) {
#if[rw] #if[rw]
Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian); unsafe.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -327,7 +344,7 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putShort(int i, short x) { public $Type$Buffer putShort(int i, short x) {
#if[rw] #if[rw]
Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian); unsafe.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -358,18 +375,18 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public int getInt() { public int getInt() {
return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian); return unsafe.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian);
} }
public int getInt(int i) { public int getInt(int i) {
return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian); return unsafe.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
} }
#end[rw] #end[rw]
public $Type$Buffer putInt(int x) { public $Type$Buffer putInt(int x) {
#if[rw] #if[rw]
Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian); unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -378,7 +395,7 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putInt(int i, int x) { public $Type$Buffer putInt(int i, int x) {
#if[rw] #if[rw]
Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian); unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -409,18 +426,18 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public long getLong() { public long getLong() {
return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian); return unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
} }
public long getLong(int i) { public long getLong(int i) {
return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian); return unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
} }
#end[rw] #end[rw]
public $Type$Buffer putLong(long x) { public $Type$Buffer putLong(long x) {
#if[rw] #if[rw]
Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian); unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -429,7 +446,7 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putLong(int i, long x) { public $Type$Buffer putLong(int i, long x) {
#if[rw] #if[rw]
Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian); unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -460,18 +477,21 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public float getFloat() { public float getFloat() {
return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian); int x = unsafe.getIntUnaligned(hb, byteOffset(nextPutIndex(4)), bigEndian);
return Float.intBitsToFloat(x);
} }
public float getFloat(int i) { public float getFloat(int i) {
return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian); int x = unsafe.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian);
return Float.intBitsToFloat(x);
} }
#end[rw] #end[rw]
public $Type$Buffer putFloat(float x) { public $Type$Buffer putFloat(float x) {
#if[rw] #if[rw]
Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian); int y = Float.floatToRawIntBits(x);
unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -480,7 +500,8 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putFloat(int i, float x) { public $Type$Buffer putFloat(int i, float x) {
#if[rw] #if[rw]
Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian); int y = Float.floatToRawIntBits(x);
unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -511,18 +532,21 @@ class Heap$Type$Buffer$RW$
#if[rw] #if[rw]
public double getDouble() { public double getDouble() {
return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian); long x = unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian);
return Double.longBitsToDouble(x);
} }
public double getDouble(int i) { public double getDouble(int i) {
return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian); long x = unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian);
return Double.longBitsToDouble(x);
} }
#end[rw] #end[rw]
public $Type$Buffer putDouble(double x) { public $Type$Buffer putDouble(double x) {
#if[rw] #if[rw]
Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian); long y = Double.doubleToRawLongBits(x);
unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();
@ -531,7 +555,8 @@ class Heap$Type$Buffer$RW$
public $Type$Buffer putDouble(int i, double x) { public $Type$Buffer putDouble(int i, double x) {
#if[rw] #if[rw]
Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian); long y = Double.doubleToRawLongBits(x);
unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
return this; return this;
#else[rw] #else[rw]
throw new ReadOnlyBufferException(); throw new ReadOnlyBufferException();

View File

@ -183,7 +183,7 @@ public final class Unsafe {
* <p> * <p>
* Unless the reference {@code x} being stored is either null * Unless the reference {@code x} being stored is either null
* or matches the field type, the results are undefined. * or matches the field type, the results are undefined.
* If the reference {@code o} is non-null, car marks or * If the reference {@code o} is non-null, card marks or
* other store barriers for that object (if the VM requires them) * other store barriers for that object (if the VM requires them)
* are updated. * are updated.
* @see #putInt(Object, long, int) * @see #putInt(Object, long, int)
@ -219,6 +219,35 @@ public final class Unsafe {
/** @see #putInt(Object, long, int) */ /** @see #putInt(Object, long, int) */
public native void putDouble(Object o, long offset, double x); public native void putDouble(Object o, long offset, double x);
// These read VM internal data.
/**
* Fetches an uncompressed reference value from a given native variable
* ignoring the VM's compressed references mode.
*
* @param address a memory address locating the variable
* @return the value fetched from the indicated native variable
*/
public native Object getUncompressedObject(long address);
/**
* Fetches the {@link java.lang.Class} Java mirror for the given native
* metaspace {@code Klass} pointer.
*
* @param metaspaceKlass a native metaspace {@code Klass} pointer
* @return the {@link java.lang.Class} Java mirror
*/
public native Class<?> getJavaMirror(long metaspaceKlass);
/**
* Fetches a native metaspace {@code Klass} pointer for the given Java
* object.
*
* @param o Java heap object for which to fetch the class pointer
* @return a native metaspace {@code Klass} pointer
*/
public native long getKlassPointer(Object o);
// These work on values in the C heap. // These work on values in the C heap.
/** /**
@ -934,4 +963,347 @@ public final class Unsafe {
private static void throwIllegalAccessError() { private static void throwIllegalAccessError() {
throw new IllegalAccessError(); throw new IllegalAccessError();
} }
/**
* @return Returns true if the native byte ordering of this
* platform is big-endian, false if it is little-endian.
*/
public final boolean isBigEndian() { return BE; }
/**
* @return Returns true if this platform is capable of performing
* accesses at addresses which are not aligned for the type of the
* primitive type being accessed, false otherwise.
*/
public final boolean unalignedAccess() { return unalignedAccess; }
/**
* Fetches a value at some byte offset into a given Java object.
* More specifically, fetches a value within the given object
* <code>o</code> at the given offset, or (if <code>o</code> is
* null) from the memory address whose numerical value is the
* given offset. <p>
*
* The specification of this method is the same as {@link
* #getLong(Object, long)} except that the offset does not need to
* have been obtained from {@link #objectFieldOffset} on the
* {@link java.lang.reflect.Field} of some Java field. The value
* in memory is raw data, and need not correspond to any Java
* variable. Unless <code>o</code> is null, the value accessed
* must be entirely within the allocated object. The endianness
* of the value in memory is the endianness of the native platform.
*
* <p> The read will be atomic with respect to the largest power
* of two that divides the GCD of the offset and the storage size.
* For example, getLongUnaligned will make atomic reads of 2-, 4-,
* or 8-byte storage units if the offset is zero mod 2, 4, or 8,
* respectively. There are no other guarantees of atomicity.
* <p>
* 8-byte atomicity is only guaranteed on platforms on which
* support atomic accesses to longs.
*
* @param o Java heap object in which the value resides, if any, else
* null
* @param offset The offset in bytes from the start of the object
* @return the value fetched from the indicated object
* @throws RuntimeException No defined exceptions are thrown, not even
* {@link NullPointerException}
* @since 1.9
*/
public final long getLongUnaligned(Object o, long offset) {
if ((offset & 7) == 0) {
return getLong(o, offset);
} else if ((offset & 3) == 0) {
return makeLong(getInt(o, offset),
getInt(o, offset + 4));
} else if ((offset & 1) == 0) {
return makeLong(getShort(o, offset),
getShort(o, offset + 2),
getShort(o, offset + 4),
getShort(o, offset + 6));
} else {
return makeLong(getByte(o, offset),
getByte(o, offset + 1),
getByte(o, offset + 2),
getByte(o, offset + 3),
getByte(o, offset + 4),
getByte(o, offset + 5),
getByte(o, offset + 6),
getByte(o, offset + 7));
}
}
/**
* As {@link #getLongUnaligned(Object, long)} but with an
* additional argument which specifies the endianness of the value
* as stored in memory.
*
* @param o Java heap object in which the variable resides
* @param offset The offset in bytes from the start of the object
* @param bigEndian The endianness of the value
* @return the value fetched from the indicated object
* @since 1.9
*/
public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {
return convEndian(bigEndian, getLongUnaligned(o, offset));
}
/** @see #getLongUnaligned(Object, long) */
public final int getIntUnaligned(Object o, long offset) {
if ((offset & 3) == 0) {
return getInt(o, offset);
} else if ((offset & 1) == 0) {
return makeInt(getShort(o, offset),
getShort(o, offset + 2));
} else {
return makeInt(getByte(o, offset),
getByte(o, offset + 1),
getByte(o, offset + 2),
getByte(o, offset + 3));
}
}
/** @see #getLongUnaligned(Object, long, boolean) */
public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {
return convEndian(bigEndian, getIntUnaligned(o, offset));
}
/** @see #getLongUnaligned(Object, long) */
public final short getShortUnaligned(Object o, long offset) {
if ((offset & 1) == 0) {
return getShort(o, offset);
} else {
return makeShort(getByte(o, offset),
getByte(o, offset + 1));
}
}
/** @see #getLongUnaligned(Object, long, boolean) */
public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {
return convEndian(bigEndian, getShortUnaligned(o, offset));
}
/** @see #getLongUnaligned(Object, long) */
public final char getCharUnaligned(Object o, long offset) {
return (char)getShortUnaligned(o, offset);
}
/** @see #getLongUnaligned(Object, long, boolean) */
public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {
return convEndian(bigEndian, getCharUnaligned(o, offset));
}
/**
* Stores a value at some byte offset into a given Java object.
* <p>
* The specification of this method is the same as {@link
* #getLong(Object, long)} except that the offset does not need to
* have been obtained from {@link #objectFieldOffset} on the
* {@link java.lang.reflect.Field} of some Java field. The value
* in memory is raw data, and need not correspond to any Java
* variable. The endianness of the value in memory is the
* endianness of the native platform.
* <p>
* The write will be atomic with respect to the largest power of
* two that divides the GCD of the offset and the storage size.
* For example, putLongUnaligned will make atomic writes of 2-, 4-,
* or 8-byte storage units if the offset is zero mod 2, 4, or 8,
* respectively. There are no other guarantees of atomicity.
* <p>
* 8-byte atomicity is only guaranteed on platforms on which
* support atomic accesses to longs.
* <p>
*
* @param o Java heap object in which the value resides, if any, else
* null
* @param offset The offset in bytes from the start of the object
* @param x the value to store
* @throws RuntimeException No defined exceptions are thrown, not even
* {@link NullPointerException}
* @since 1.9
*/
public final void putLongUnaligned(Object o, long offset, long x) {
if ((offset & 7) == 0) {
putLong(o, offset, x);
} else if ((offset & 3) == 0) {
putLongParts(o, offset,
(int)(x >> 0),
(int)(x >>> 32));
} else if ((offset & 1) == 0) {
putLongParts(o, offset,
(short)(x >>> 0),
(short)(x >>> 16),
(short)(x >>> 32),
(short)(x >>> 48));
} else {
putLongParts(o, offset,
(byte)(x >>> 0),
(byte)(x >>> 8),
(byte)(x >>> 16),
(byte)(x >>> 24),
(byte)(x >>> 32),
(byte)(x >>> 40),
(byte)(x >>> 48),
(byte)(x >>> 56));
}
}
/**
* As {@link #putLongUnaligned(Object, long, long)} but with an additional
* argument which specifies the endianness of the value as stored in memory.
* @param o Java heap object in which the value resides
* @param offset The offset in bytes from the start of the object
* @param x the value to store
* @param bigEndian The endianness of the value
* @throws RuntimeException No defined exceptions are thrown, not even
* {@link NullPointerException}
* @since 1.9
*/
public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {
putLongUnaligned(o, offset, convEndian(bigEndian, x));
}
/** @see #putLongUnaligned(Object, long, long) */
public final void putIntUnaligned(Object o, long offset, int x) {
if ((offset & 3) == 0) {
putInt(o, offset, x);
} else if ((offset & 1) == 0) {
putIntParts(o, offset,
(short)(x >> 0),
(short)(x >>> 16));
} else {
putIntParts(o, offset,
(byte)(x >>> 0),
(byte)(x >>> 8),
(byte)(x >>> 16),
(byte)(x >>> 24));
}
}
/** @see #putLongUnaligned(Object, long, long, boolean) */
public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {
putIntUnaligned(o, offset, convEndian(bigEndian, x));
}
/** @see #putLongUnaligned(Object, long, long) */
public final void putShortUnaligned(Object o, long offset, short x) {
if ((offset & 1) == 0) {
putShort(o, offset, x);
} else {
putShortParts(o, offset,
(byte)(x >>> 0),
(byte)(x >>> 8));
}
}
/** @see #putLongUnaligned(Object, long, long, boolean) */
public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {
putShortUnaligned(o, offset, convEndian(bigEndian, x));
}
/** @see #putLongUnaligned(Object, long, long) */
public final void putCharUnaligned(Object o, long offset, char x) {
putShortUnaligned(o, offset, (short)x);
}
/** @see #putLongUnaligned(Object, long, long, boolean) */
public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
putCharUnaligned(o, offset, convEndian(bigEndian, x));
}
// JVM interface methods
private native boolean unalignedAccess0();
private native boolean isBigEndian0();
// BE is true iff the native endianness of this platform is big.
private static final boolean BE = theUnsafe.isBigEndian0();
// unalignedAccess is true iff this platform can perform unaligned accesses.
private static final boolean unalignedAccess = theUnsafe.unalignedAccess0();
private static int pickPos(int top, int pos) { return BE ? top - pos : pos; }
// These methods construct integers from bytes. The byte ordering
// is the native endianness of this platform.
private static long makeLong(byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
return ((toUnsignedLong(i0) << pickPos(56, 0))
| (toUnsignedLong(i1) << pickPos(56, 8))
| (toUnsignedLong(i2) << pickPos(56, 16))
| (toUnsignedLong(i3) << pickPos(56, 24))
| (toUnsignedLong(i4) << pickPos(56, 32))
| (toUnsignedLong(i5) << pickPos(56, 40))
| (toUnsignedLong(i6) << pickPos(56, 48))
| (toUnsignedLong(i7) << pickPos(56, 56)));
}
private static long makeLong(short i0, short i1, short i2, short i3) {
return ((toUnsignedLong(i0) << pickPos(48, 0))
| (toUnsignedLong(i1) << pickPos(48, 16))
| (toUnsignedLong(i2) << pickPos(48, 32))
| (toUnsignedLong(i3) << pickPos(48, 48)));
}
private static long makeLong(int i0, int i1) {
return (toUnsignedLong(i0) << pickPos(32, 0))
| (toUnsignedLong(i1) << pickPos(32, 32));
}
private static int makeInt(short i0, short i1) {
return (toUnsignedInt(i0) << pickPos(16, 0))
| (toUnsignedInt(i1) << pickPos(16, 16));
}
private static int makeInt(byte i0, byte i1, byte i2, byte i3) {
return ((toUnsignedInt(i0) << pickPos(24, 0))
| (toUnsignedInt(i1) << pickPos(24, 8))
| (toUnsignedInt(i2) << pickPos(24, 16))
| (toUnsignedInt(i3) << pickPos(24, 24)));
}
private static short makeShort(byte i0, byte i1) {
return (short)((toUnsignedInt(i0) << pickPos(8, 0))
| (toUnsignedInt(i1) << pickPos(8, 8)));
}
private static byte pick(byte le, byte be) { return BE ? be : le; }
private static short pick(short le, short be) { return BE ? be : le; }
private static int pick(int le, int be) { return BE ? be : le; }
// These methods write integers to memory from smaller parts
// provided by their caller. The ordering in which these parts
// are written is the native endianness of this platform.
private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
putByte(o, offset + 0, pick(i0, i7));
putByte(o, offset + 1, pick(i1, i6));
putByte(o, offset + 2, pick(i2, i5));
putByte(o, offset + 3, pick(i3, i4));
putByte(o, offset + 4, pick(i4, i3));
putByte(o, offset + 5, pick(i5, i2));
putByte(o, offset + 6, pick(i6, i1));
putByte(o, offset + 7, pick(i7, i0));
}
private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {
putShort(o, offset + 0, pick(i0, i3));
putShort(o, offset + 2, pick(i1, i2));
putShort(o, offset + 4, pick(i2, i1));
putShort(o, offset + 6, pick(i3, i0));
}
private void putLongParts(Object o, long offset, int i0, int i1) {
putInt(o, offset + 0, pick(i0, i1));
putInt(o, offset + 4, pick(i1, i0));
}
private void putIntParts(Object o, long offset, short i0, short i1) {
putShort(o, offset + 0, pick(i0, i1));
putShort(o, offset + 2, pick(i1, i0));
}
private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {
putByte(o, offset + 0, pick(i0, i3));
putByte(o, offset + 1, pick(i1, i2));
putByte(o, offset + 2, pick(i2, i1));
putByte(o, offset + 3, pick(i3, i0));
}
private void putShortParts(Object o, long offset, byte i0, byte i1) {
putByte(o, offset + 0, pick(i0, i1));
putByte(o, offset + 1, pick(i1, i0));
}
// Zero-extend an integer
private static int toUnsignedInt(byte n) { return n & 0xff; }
private static int toUnsignedInt(short n) { return n & 0xffff; }
private static long toUnsignedLong(byte n) { return n & 0xffl; }
private static long toUnsignedLong(short n) { return n & 0xffffl; }
private static long toUnsignedLong(int n) { return n & 0xffffffffl; }
// Maybe byte-reverse an integer
private static char convEndian(boolean big, char n) { return big == BE ? n : Character.reverseBytes(n); }
private static short convEndian(boolean big, short n) { return big == BE ? n : Short.reverseBytes(n) ; }
private static int convEndian(boolean big, int n) { return big == BE ? n : Integer.reverseBytes(n) ; }
private static long convEndian(boolean big, long n) { return big == BE ? n : Long.reverseBytes(n) ; }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -88,13 +88,8 @@ final class ByteArrayAccess {
// Return whether this platform supports full speed int/long memory access // Return whether this platform supports full speed int/long memory access
// at unaligned addresses. // at unaligned addresses.
// This code was copied from java.nio.Bits because there is no equivalent
// public API.
private static boolean unaligned() { private static boolean unaligned() {
String arch = java.security.AccessController.doPrivileged return unsafe.unalignedAccess();
(new sun.security.action.GetPropertyAction("os.arch", ""));
return arch.equals("i386") || arch.equals("x86") || arch.equals("amd64")
|| arch.equals("x86_64");
} }
/** /**

View File

@ -395,6 +395,9 @@ JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass);
JNIEXPORT jclass JNICALL JNIEXPORT jclass JNICALL
JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass); JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass);
JNIEXPORT jstring JNICALL
JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass);
/* Generics support (JDK 1.5) */ /* Generics support (JDK 1.5) */
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
JVM_GetClassSignature(JNIEnv *env, jclass cls); JVM_GetClassSignature(JNIEnv *env, jclass cls);

View File

@ -67,6 +67,7 @@ static JNINativeMethod methods[] = {
{"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain}, {"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain},
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses}, {"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses},
{"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass}, {"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass},
{"getSimpleBinaryName0", "()" STR, (void *)&JVM_GetSimpleBinaryName},
{"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature}, {"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature},
{"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations}, {"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations},
{"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool}, {"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool},

View File

@ -33,7 +33,6 @@ import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.management.DynamicMBean;
import javax.management.ObjectName; import javax.management.ObjectName;
import sun.management.ManagementFactoryHelper; import sun.management.ManagementFactoryHelper;
import sun.management.spi.PlatformMBeanProvider; import sun.management.spi.PlatformMBeanProvider;
@ -162,8 +161,7 @@ class DefaultPlatformMBeanProvider extends PlatformMBeanProvider {
@Override @Override
public Set<Class<? extends MemoryManagerMXBean>> mbeanInterfaces() { public Set<Class<? extends MemoryManagerMXBean>> mbeanInterfaces() {
return Stream.of(MemoryManagerMXBean.class, return Stream.of(MemoryManagerMXBean.class,
GarbageCollectorMXBean.class, GarbageCollectorMXBean.class).collect(Collectors.toSet());
com.sun.management.GarbageCollectorMXBean.class).collect(Collectors.toSet());
} }
@Override @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(); initMBeanList.trimToSize();
return initMBeanList; return initMBeanList;
} }

View File

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

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.MissingResourceException; import java.util.MissingResourceException;
@ -55,6 +56,125 @@ import sun.misc.VMSupport;
* system class loader. Also jmx framework could be started by jcmd * system class loader. Also jmx framework could be started by jcmd
*/ */
public class Agent { public class Agent {
/**
* Agent status collector strategy class
*/
private static abstract class StatusCollector {
final protected StringBuilder sb = new StringBuilder();
final public String collect() {
Properties agentProps = VMSupport.getAgentProperties();
String localConnAddr = (String)agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
if (localConnAddr != null || jmxServer != null) {
addAgentStatus(true);
appendConnections(localConnAddr);
} else {
addAgentStatus(false);
}
return sb.toString();
}
private void appendConnections(String localConnAddr) {
appendConnectionsHeader();
if (localConnAddr != null) {
try {
JMXServiceURL u = new JMXServiceURL(localConnAddr);
addConnection(false, u);
} catch (MalformedURLException e) {
// will never happen
}
}
if (jmxServer != null) {
addConnection(true, jmxServer.getAddress());
}
appendConnectionsFooter();
}
private void addConnection(boolean remote, JMXServiceURL u) {
appendConnectionHeader(remote);
addConnectionDetails(u);
if (remote) {
addConfigProperties();
}
appendConnectionFooter(remote);
}
private void addConfigProperties() {
appendConfigPropsHeader();
boolean[] first = new boolean[] {true};
configProps.entrySet().stream().forEach((e) -> {
String key = (String)e.getKey();
if (key.startsWith("com.sun.management.")) {
addConfigProp(key, e.getValue(), first[0]);
first[0] = false;
}
});
appendConfigPropsFooter();
}
abstract protected void addAgentStatus(boolean enabled);
abstract protected void appendConnectionsHeader();
abstract protected void appendConnectionsFooter();
abstract protected void addConnectionDetails(JMXServiceURL u);
abstract protected void appendConnectionHeader(boolean remote);
abstract protected void appendConnectionFooter(boolean remote);
abstract protected void appendConfigPropsHeader();
abstract protected void appendConfigPropsFooter();
abstract protected void addConfigProp(String key, Object value, boolean first);
}
/**
* Free-text status collector strategy implementation
*/
final private static class TextStatusCollector extends StatusCollector {
@Override
protected void addAgentStatus(boolean enabled) {
sb.append("Agent: ").append(enabled ? "enabled" : "disabled").append('\n');
}
@Override
protected void appendConnectionsHeader() {
sb.append('\n');
}
@Override
protected void addConnectionDetails(JMXServiceURL u) {
sb.append("Protocol : ").append(u.getProtocol()).append('\n')
.append("Host : ").append(u.getHost()).append('\n')
.append("URL : ").append(u).append('\n');
}
@Override
protected void appendConnectionHeader(boolean remote) {
sb.append("Connection Type: ").append(remote ? "remote" : "local").append('\n');
}
@Override
protected void appendConfigPropsHeader() {
sb.append("Properties :\n");
}
@Override
protected void addConfigProp(String key, Object value, boolean first) {
if (!first) {
sb.append('\n');
}
sb.append(" ").append(key).append(" = ").append(value);
}
@Override
protected void appendConnectionsFooter() {}
@Override
protected void appendConnectionFooter(boolean remote) {
sb.append('\n');
}
@Override
protected void appendConfigPropsFooter() {}
}
// management properties // management properties
private static Properties mgmtProps; private static Properties mgmtProps;
@ -81,6 +201,8 @@ public class Agent {
// The only active agent allowed // The only active agent allowed
private static JMXConnectorServer jmxServer = null; private static JMXConnectorServer jmxServer = null;
// The properties used to configure the server
private static Properties configProps = null;
// Parse string com.sun.management.prop=xxx,com.sun.management.prop=yyyy // Parse string com.sun.management.prop=xxx,com.sun.management.prop=yyyy
// and return property set if args is null or empty // and return property set if args is null or empty
@ -161,7 +283,7 @@ public class Agent {
try { try {
Properties argProps = parseString(args); Properties argProps = parseString(args);
Properties configProps = new Properties(); configProps = new Properties();
// Load the management properties from the config file // Load the management properties from the config file
// if config file is not specified readConfiguration implicitly // if config file is not specified readConfiguration implicitly
@ -228,9 +350,14 @@ public class Agent {
// Don't cause any errors. // Don't cause any errors.
jmxServer.stop(); jmxServer.stop();
jmxServer = null; jmxServer = null;
configProps = null;
} }
} }
private static synchronized String getManagementAgentStatus() throws Exception {
return new TextStatusCollector().collect();
}
private static void startAgent(Properties props) throws Exception { private static void startAgent(Properties props) throws Exception {
String snmpPort = props.getProperty(SNMP_PORT); String snmpPort = props.getProperty(SNMP_PORT);
String jmxremote = props.getProperty(JMXREMOTE); String jmxremote = props.getProperty(JMXREMOTE);

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,168 +25,31 @@
package sun.management; package sun.management;
import com.sun.management.GarbageCollectorMXBean; import java.lang.management.GarbageCollectorMXBean;
import com.sun.management.GarbageCollectionNotificationInfo;
import java.lang.management.ManagementFactory; 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.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. * Implementation class for the garbage collector.
* Standard and committed hotspot-specific metrics if any.
* *
* ManagementFactory.getGarbageCollectorMXBeans() returns a list * ManagementFactory.getGarbageCollectorMXBeans() returns a list
* of instances of this class. * of instances of this class.
*/ */
class GarbageCollectorImpl extends MemoryManagerImpl public class GarbageCollectorImpl extends MemoryManagerImpl
implements GarbageCollectorMXBean { implements GarbageCollectorMXBean {
GarbageCollectorImpl(String name) { protected GarbageCollectorImpl(String name) {
super(name); super(name);
} }
@Override
public native long getCollectionCount(); public native long getCollectionCount();
@Override
public native long getCollectionTime(); public native long getCollectionTime();
@Override
// 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);
}
}
public ObjectName getObjectName() { public ObjectName getObjectName() {
return Util.newObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, getName()); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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(); protected abstract CompositeData getCompositeData();
// Helper methods // Helper methods
static String getString(CompositeData cd, String itemName) { public static String getString(CompositeData cd, String itemName) {
if (cd == null) if (cd == null)
throw new IllegalArgumentException("Null CompositeData"); throw new IllegalArgumentException("Null CompositeData");
return (String) cd.get(itemName); return (String) cd.get(itemName);
} }
static boolean getBoolean(CompositeData cd, String itemName) { public static boolean getBoolean(CompositeData cd, String itemName) {
if (cd == null) if (cd == null)
throw new IllegalArgumentException("Null CompositeData"); throw new IllegalArgumentException("Null CompositeData");
return ((Boolean) cd.get(itemName)).booleanValue(); return ((Boolean) cd.get(itemName)).booleanValue();
} }
static long getLong(CompositeData cd, String itemName) { public static long getLong(CompositeData cd, String itemName) {
if (cd == null) if (cd == null)
throw new IllegalArgumentException("Null CompositeData"); throw new IllegalArgumentException("Null CompositeData");
return ((Long) cd.get(itemName)).longValue(); return ((Long) cd.get(itemName)).longValue();
} }
static int getInt(CompositeData cd, String itemName) { public static int getInt(CompositeData cd, String itemName) {
if (cd == null) if (cd == null)
throw new IllegalArgumentException("Null CompositeData"); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,8 +26,6 @@
package sun.management; package sun.management;
import java.lang.management.*; import java.lang.management.*;
import javax.management.DynamicMBean;
import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException; import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
@ -38,30 +36,35 @@ import javax.management.RuntimeOperationsException;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import sun.util.logging.LoggingSupport; import sun.util.logging.LoggingSupport;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.sun.management.DiagnosticCommandMBean;
import com.sun.management.HotSpotDiagnosticMXBean;
/** /**
* ManagementFactoryHelper provides static factory methods to create * ManagementFactoryHelper provides static factory methods to create
* instances of the management interface. * instances of the management interface.
*/ */
public class ManagementFactoryHelper { 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 ManagementFactoryHelper() {};
private static VMManagement jvm; public static VMManagement getVMManagement() {
return jvm;
}
private static ClassLoadingImpl classMBean = null; private static ClassLoadingImpl classMBean = null;
private static MemoryImpl memoryMBean = null; private static MemoryImpl memoryMBean = null;
private static ThreadImpl threadMBean = null; private static ThreadImpl threadMBean = null;
private static RuntimeImpl runtimeMBean = null; private static RuntimeImpl runtimeMBean = null;
private static CompilationImpl compileMBean = null; private static CompilationImpl compileMBean = null;
private static OperatingSystemImpl osMBean = null; private static BaseOperatingSystemImpl osMBean = null;
public static synchronized ClassLoadingMXBean getClassLoadingMXBean() { public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
if (classMBean == null) { if (classMBean == null) {
@ -100,7 +103,7 @@ public class ManagementFactoryHelper {
public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() { public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
if (osMBean == null) { if (osMBean == null) {
osMBean = new OperatingSystemImpl(jvm); osMBean = new BaseOperatingSystemImpl(jvm);
} }
return osMBean; return osMBean;
} }
@ -123,7 +126,7 @@ public class ManagementFactoryHelper {
return result; return result;
} }
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() { public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers();
List<GarbageCollectorMXBean> result = new ArrayList<>(mgrs.length); List<GarbageCollectorMXBean> result = new ArrayList<>(mgrs.length);
for (MemoryManagerMXBean m : mgrs) { for (MemoryManagerMXBean m : mgrs) {
@ -257,20 +260,11 @@ public class ManagementFactoryHelper {
}; };
} }
private static HotSpotDiagnostic hsDiagMBean = null;
private static HotspotRuntime hsRuntimeMBean = null; private static HotspotRuntime hsRuntimeMBean = null;
private static HotspotClassLoading hsClassMBean = null; private static HotspotClassLoading hsClassMBean = null;
private static HotspotThread hsThreadMBean = null; private static HotspotThread hsThreadMBean = null;
private static HotspotCompilation hsCompileMBean = null; private static HotspotCompilation hsCompileMBean = null;
private static HotspotMemory hsMemoryMBean = 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. * This method is for testing only.
@ -312,14 +306,6 @@ public class ManagementFactoryHelper {
return hsMemoryMBean; 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. * This method is for testing only.
*/ */
@ -374,18 +360,6 @@ public class ManagementFactoryHelper {
private final static String HOTSPOT_THREAD_MBEAN_NAME = private final static String HOTSPOT_THREAD_MBEAN_NAME =
"sun.management:type=HotspotThreading"; "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) { static void registerInternalMBeans(MBeanServer mbs) {
// register all internal MBeans if not registered // register all internal MBeans if not registered
// No exception is thrown if a MBean with that object name // 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) { public static boolean isThreadSuspended(int state) {
return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0); 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_SUSPENDED = 0x00100000;
private static final int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.PrivilegedAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import javax.management.*;
import javax.management.openmbean.*; import javax.management.openmbean.*;
import static javax.management.openmbean.SimpleType.*; import static javax.management.openmbean.SimpleType.*;
import com.sun.management.VMOption;
/** /**
* A mapped mxbean type maps a Java type to an open type. * A mapped mxbean type maps a Java type to an open type.
@ -113,7 +111,7 @@ public abstract class MappedMXBeanType {
return mt; return mt;
} }
static synchronized MappedMXBeanType getMappedType(Type t) public static synchronized MappedMXBeanType getMappedType(Type t)
throws OpenDataException { throws OpenDataException {
MappedMXBeanType mt = convertedTypes.get(t); MappedMXBeanType mt = convertedTypes.get(t);
if (mt == null) { if (mt == null) {
@ -152,7 +150,7 @@ public abstract class MappedMXBeanType {
} }
// Return the mapped open type // Return the mapped open type
OpenType<?> getOpenType() { public OpenType<?> getOpenType() {
return openType; return openType;
} }
@ -177,10 +175,10 @@ public abstract class MappedMXBeanType {
// return name of the class or the generic type // return name of the class or the generic type
abstract String getName(); abstract String getName();
abstract Object toOpenTypeData(Object javaTypeData) public abstract Object toOpenTypeData(Object javaTypeData)
throws OpenDataException; throws OpenDataException;
abstract Object toJavaTypeData(Object openTypeData) public abstract Object toJavaTypeData(Object openTypeData)
throws OpenDataException, InvalidObjectException; throws OpenDataException, InvalidObjectException;
// Basic Types - Classes that do not require data conversion // Basic Types - Classes that do not require data conversion
@ -208,11 +206,11 @@ public abstract class MappedMXBeanType {
return basicType.getName(); return basicType.getName();
} }
Object toOpenTypeData(Object data) throws OpenDataException { public Object toOpenTypeData(Object data) throws OpenDataException {
return data; return data;
} }
Object toJavaTypeData(Object data) public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException { throws OpenDataException, InvalidObjectException {
return data; return data;
@ -243,11 +241,11 @@ public abstract class MappedMXBeanType {
return enumClass.getName(); return enumClass.getName();
} }
Object toOpenTypeData(Object data) throws OpenDataException { public Object toOpenTypeData(Object data) throws OpenDataException {
return ((Enum) data).name(); return ((Enum) data).name();
} }
Object toJavaTypeData(Object data) public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException { throws OpenDataException, InvalidObjectException {
try { try {
@ -315,7 +313,7 @@ public abstract class MappedMXBeanType {
return arrayClass.getName(); 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 // If the base element type is a basic type
// return the data as no conversion is needed. // return the data as no conversion is needed.
// Primitive types are not converted to wrappers. // 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 { throws OpenDataException, InvalidObjectException {
// If the base element type is a basic type // If the base element type is a basic type
@ -457,7 +455,7 @@ public abstract class MappedMXBeanType {
return typeName; return typeName;
} }
Object toOpenTypeData(Object data) throws OpenDataException { public Object toOpenTypeData(Object data) throws OpenDataException {
final List<Object> list = (List<Object>) data; final List<Object> list = (List<Object>) data;
final Object[] openArray = (Object[]) final Object[] openArray = (Object[])
@ -470,7 +468,7 @@ public abstract class MappedMXBeanType {
return openArray; return openArray;
} }
Object toJavaTypeData(Object data) public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException { throws OpenDataException, InvalidObjectException {
final Object[] openArray = (Object[]) data; final Object[] openArray = (Object[]) data;
@ -538,7 +536,7 @@ public abstract class MappedMXBeanType {
return typeName; 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 Map<Object,Object> map = (Map<Object,Object>) data;
final TabularType tabularType = (TabularType) openType; final TabularType tabularType = (TabularType) openType;
final TabularData table = new TabularDataSupport(tabularType); final TabularData table = new TabularDataSupport(tabularType);
@ -556,7 +554,7 @@ public abstract class MappedMXBeanType {
return table; return table;
} }
Object toJavaTypeData(Object data) public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException { throws OpenDataException, InvalidObjectException {
final TabularData td = (TabularData) data; final TabularData td = (TabularData) data;
@ -605,8 +603,9 @@ public abstract class MappedMXBeanType {
// //
static class CompositeDataMXBeanType extends MappedMXBeanType { static class CompositeDataMXBeanType extends MappedMXBeanType {
final Class<?> javaClass; final Class<?> javaClass;
final boolean isCompositeData; boolean isCompositeData = false;
Method fromMethod = null; Method fromMethod = null;
Method toMethod = null;
CompositeDataMXBeanType(Class<?> c) throws OpenDataException { CompositeDataMXBeanType(Class<?> c) throws OpenDataException {
this.javaClass = c; this.javaClass = c;
@ -624,6 +623,26 @@ public abstract class MappedMXBeanType {
// that has no from method to be embeded in another class. // 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)) { if (COMPOSITE_DATA_CLASS.isAssignableFrom(c)) {
// c implements CompositeData - set openType to null // c implements CompositeData - set openType to null
// defer generating the CompositeType // defer generating the CompositeType
@ -636,16 +655,16 @@ public abstract class MappedMXBeanType {
// Make a CompositeData containing all the getters // Make a CompositeData containing all the getters
final Method[] methods = final Method[] methods =
AccessController.doPrivileged(new PrivilegedAction<Method[]>() { AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
public Method[] run() { public Method[] run() {
return javaClass.getMethods(); return javaClass.getMethods();
} }
}); });
final List<String> names = new ArrayList<>(); final List<String> names = new ArrayList<>();
final List<OpenType<?>> types = new ArrayList<>(); final List<OpenType<?>> types = new ArrayList<>();
/* Select public methods that look like "T getX()" or "boolean /* Select public methods that look like "T getX()" or "boolean
isX()", where T is not void and X is not the empty isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */ string. Exclude "Class getClass()" inherited from Object. */
for (int i = 0; i < methods.length; i++) { for (int i = 0; i < methods.length; i++) {
final Method method = methods[i]; final Method method = methods[i];
final String name = method.getName(); final String name = method.getName();
@ -676,10 +695,10 @@ public abstract class MappedMXBeanType {
final String[] nameArray = names.toArray(new String[0]); final String[] nameArray = names.toArray(new String[0]);
openType = new CompositeType(c.getName(), openType = new CompositeType(c.getName(),
c.getName(), c.getName(),
nameArray, // field names nameArray, // field names
nameArray, // field descriptions nameArray, // field descriptions
types.toArray(new OpenType<?>[0])); types.toArray(new OpenType<?>[0]));
} }
} }
@ -691,7 +710,23 @@ public abstract class MappedMXBeanType {
return javaClass.getName(); 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) { if (data instanceof MemoryUsage) {
return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data); return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
} }
@ -712,10 +747,6 @@ public abstract class MappedMXBeanType {
toCompositeData((MemoryNotificationInfo) data); toCompositeData((MemoryNotificationInfo) data);
} }
if (data instanceof VMOption) {
return VMOptionCompositeData.toCompositeData((VMOption) data);
}
if (isCompositeData) { if (isCompositeData) {
// Classes that implement CompositeData // Classes that implement CompositeData
// //
@ -732,7 +763,7 @@ public abstract class MappedMXBeanType {
" is not supported for platform MXBeans"); " is not supported for platform MXBeans");
} }
Object toJavaTypeData(Object data) public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException { throws OpenDataException, InvalidObjectException {
if (fromMethod == null) { 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Collections; import java.util.Collections;
/** /**
* Abstract helper class for notification emitter support. * Abstract helper class for notification emitter support.
*/ */
abstract class NotificationEmitterSupport implements NotificationEmitter { public abstract class NotificationEmitterSupport implements NotificationEmitter {
protected NotificationEmitterSupport() { protected NotificationEmitterSupport() {
} }
@ -135,7 +134,7 @@ abstract class NotificationEmitterSupport implements NotificationEmitter {
} }
} }
void sendNotification(Notification notification) { public void sendNotification(Notification notification) {
if (notification == null) { if (notification == null) {
return; return;
@ -162,7 +161,7 @@ abstract class NotificationEmitterSupport implements NotificationEmitter {
} }
} }
boolean hasListeners() { public boolean hasListeners() {
synchronized (listenerLock) { synchronized (listenerLock) {
return !listenerList.isEmpty(); return !listenerList.isEmpty();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2011, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,20 +26,18 @@
package sun.management; package sun.management;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo; import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import javax.management.ObjectName; import javax.management.ObjectName;
/** /**
* Implementation class for the thread subsystem. * Implementation for java.lang.management.ThreadMXBean as well as providing the
* Standard and committed hotspot-specific metrics if any. * supporting method for com.sun.management.ThreadMXBean.
* * The supporting method for com.sun.management.ThreadMXBean can be moved to
* ManagementFactory.getThreadMXBean() returns an instance * jdk.management in the future.
* of this class.
*/ */
class ThreadImpl implements com.sun.management.ThreadMXBean {
public class ThreadImpl implements ThreadMXBean {
private final VMManagement jvm; private final VMManagement jvm;
// default for thread contention monitoring is disabled. // default for thread contention monitoring is disabled.
@ -50,32 +48,38 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
/** /**
* Constructor of ThreadImpl class. * Constructor of ThreadImpl class.
*/ */
ThreadImpl(VMManagement vm) { protected ThreadImpl(VMManagement vm) {
this.jvm = vm; this.jvm = vm;
this.cpuTimeEnabled = jvm.isThreadCpuTimeEnabled(); this.cpuTimeEnabled = jvm.isThreadCpuTimeEnabled();
this.allocatedMemoryEnabled = jvm.isThreadAllocatedMemoryEnabled(); this.allocatedMemoryEnabled = jvm.isThreadAllocatedMemoryEnabled();
} }
@Override
public int getThreadCount() { public int getThreadCount() {
return jvm.getLiveThreadCount(); return jvm.getLiveThreadCount();
} }
@Override
public int getPeakThreadCount() { public int getPeakThreadCount() {
return jvm.getPeakThreadCount(); return jvm.getPeakThreadCount();
} }
@Override
public long getTotalStartedThreadCount() { public long getTotalStartedThreadCount() {
return jvm.getTotalThreadCount(); return jvm.getTotalThreadCount();
} }
@Override
public int getDaemonThreadCount() { public int getDaemonThreadCount() {
return jvm.getDaemonThreadCount(); return jvm.getDaemonThreadCount();
} }
@Override
public boolean isThreadContentionMonitoringSupported() { public boolean isThreadContentionMonitoringSupported() {
return jvm.isThreadContentionMonitoringSupported(); return jvm.isThreadContentionMonitoringSupported();
} }
@Override
public synchronized boolean isThreadContentionMonitoringEnabled() { public synchronized boolean isThreadContentionMonitoringEnabled() {
if (!isThreadContentionMonitoringSupported()) { if (!isThreadContentionMonitoringSupported()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
@ -84,18 +88,21 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return contentionMonitoringEnabled; return contentionMonitoringEnabled;
} }
@Override
public boolean isThreadCpuTimeSupported() { public boolean isThreadCpuTimeSupported() {
return jvm.isOtherThreadCpuTimeSupported(); return jvm.isOtherThreadCpuTimeSupported();
} }
@Override
public boolean isCurrentThreadCpuTimeSupported() { public boolean isCurrentThreadCpuTimeSupported() {
return jvm.isCurrentThreadCpuTimeSupported(); return jvm.isCurrentThreadCpuTimeSupported();
} }
public boolean isThreadAllocatedMemorySupported() { protected boolean isThreadAllocatedMemorySupported() {
return jvm.isThreadAllocatedMemorySupported(); return jvm.isThreadAllocatedMemorySupported();
} }
@Override
public boolean isThreadCpuTimeEnabled() { public boolean isThreadCpuTimeEnabled() {
if (!isThreadCpuTimeSupported() && if (!isThreadCpuTimeSupported() &&
!isCurrentThreadCpuTimeSupported()) { !isCurrentThreadCpuTimeSupported()) {
@ -105,7 +112,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return cpuTimeEnabled; return cpuTimeEnabled;
} }
public boolean isThreadAllocatedMemoryEnabled() { protected boolean isThreadAllocatedMemoryEnabled() {
if (!isThreadAllocatedMemorySupported()) { if (!isThreadAllocatedMemorySupported()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Thread allocated memory measurement is not supported"); "Thread allocated memory measurement is not supported");
@ -113,6 +120,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return allocatedMemoryEnabled; return allocatedMemoryEnabled;
} }
@Override
public long[] getAllThreadIds() { public long[] getAllThreadIds() {
Util.checkMonitorAccess(); Util.checkMonitorAccess();
@ -126,6 +134,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids; return ids;
} }
@Override
public ThreadInfo getThreadInfo(long id) { public ThreadInfo getThreadInfo(long id) {
long[] ids = new long[1]; long[] ids = new long[1];
ids[0] = id; ids[0] = id;
@ -133,6 +142,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos[0]; return infos[0];
} }
@Override
public ThreadInfo getThreadInfo(long id, int maxDepth) { public ThreadInfo getThreadInfo(long id, int maxDepth) {
long[] ids = new long[1]; long[] ids = new long[1];
ids[0] = id; ids[0] = id;
@ -140,6 +150,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos[0]; return infos[0];
} }
@Override
public ThreadInfo[] getThreadInfo(long[] ids) { public ThreadInfo[] getThreadInfo(long[] ids) {
return getThreadInfo(ids, 0); return getThreadInfo(ids, 0);
} }
@ -157,6 +168,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
} }
} }
@Override
public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) { public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
verifyThreadIds(ids); verifyThreadIds(ids);
@ -165,6 +177,10 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
"Invalid maxDepth parameter: " + maxDepth); "Invalid maxDepth parameter: " + maxDepth);
} }
// ids has been verified to be non-null
// an empty array of ids should return an empty array of ThreadInfos
if (ids.length == 0) return new ThreadInfo[0];
Util.checkMonitorAccess(); Util.checkMonitorAccess();
ThreadInfo[] infos = new ThreadInfo[ids.length]; // nulls ThreadInfo[] infos = new ThreadInfo[ids.length]; // nulls
@ -176,6 +192,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return infos; return infos;
} }
@Override
public void setThreadContentionMonitoringEnabled(boolean enable) { public void setThreadContentionMonitoringEnabled(boolean enable) {
if (!isThreadContentionMonitoringSupported()) { if (!isThreadContentionMonitoringSupported()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
@ -209,6 +226,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadCpuTimeEnabled(); return isThreadCpuTimeEnabled();
} }
@Override
public long getCurrentThreadCpuTime() { public long getCurrentThreadCpuTime() {
if (verifyCurrentThreadCpuTime()) { if (verifyCurrentThreadCpuTime()) {
return getThreadTotalCpuTime0(0); return getThreadTotalCpuTime0(0);
@ -216,6 +234,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return -1; return -1;
} }
@Override
public long getThreadCpuTime(long id) { public long getThreadCpuTime(long id) {
long[] ids = new long[1]; long[] ids = new long[1];
ids[0] = id; ids[0] = id;
@ -247,7 +266,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadCpuTimeEnabled(); return isThreadCpuTimeEnabled();
} }
public long[] getThreadCpuTime(long[] ids) { protected long[] getThreadCpuTime(long[] ids) {
boolean verified = verifyThreadCpuTime(ids); boolean verified = verifyThreadCpuTime(ids);
int length = ids.length; int length = ids.length;
@ -268,6 +287,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times; return times;
} }
@Override
public long getCurrentThreadUserTime() { public long getCurrentThreadUserTime() {
if (verifyCurrentThreadCpuTime()) { if (verifyCurrentThreadCpuTime()) {
return getThreadUserCpuTime0(0); return getThreadUserCpuTime0(0);
@ -275,6 +295,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return -1; return -1;
} }
@Override
public long getThreadUserTime(long id) { public long getThreadUserTime(long id) {
long[] ids = new long[1]; long[] ids = new long[1];
ids[0] = id; ids[0] = id;
@ -282,7 +303,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times[0]; return times[0];
} }
public long[] getThreadUserTime(long[] ids) { protected long[] getThreadUserTime(long[] ids) {
boolean verified = verifyThreadCpuTime(ids); boolean verified = verifyThreadCpuTime(ids);
int length = ids.length; int length = ids.length;
@ -303,6 +324,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return times; return times;
} }
@Override
public void setThreadCpuTimeEnabled(boolean enable) { public void setThreadCpuTimeEnabled(boolean enable) {
if (!isThreadCpuTimeSupported() && if (!isThreadCpuTimeSupported() &&
!isCurrentThreadCpuTimeSupported()) { !isCurrentThreadCpuTimeSupported()) {
@ -320,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]; long[] ids = new long[1];
ids[0] = id; ids[0] = id;
final long[] sizes = getThreadAllocatedBytes(ids); final long[] sizes = getThreadAllocatedBytes(ids);
@ -339,7 +361,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return isThreadAllocatedMemoryEnabled(); return isThreadAllocatedMemoryEnabled();
} }
public long[] getThreadAllocatedBytes(long[] ids) { protected long[] getThreadAllocatedBytes(long[] ids) {
boolean verified = verifyThreadAllocatedMemory(ids); boolean verified = verifyThreadAllocatedMemory(ids);
long[] sizes = new long[ids.length]; long[] sizes = new long[ids.length];
@ -351,7 +373,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return sizes; return sizes;
} }
public void setThreadAllocatedMemoryEnabled(boolean enable) { protected void setThreadAllocatedMemoryEnabled(boolean enable) {
if (!isThreadAllocatedMemorySupported()) { if (!isThreadAllocatedMemorySupported()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Thread allocated memory measurement is not supported."); "Thread allocated memory measurement is not supported.");
@ -367,6 +389,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
} }
} }
@Override
public long[] findMonitorDeadlockedThreads() { public long[] findMonitorDeadlockedThreads() {
Util.checkMonitorAccess(); Util.checkMonitorAccess();
@ -383,6 +406,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids; return ids;
} }
@Override
public long[] findDeadlockedThreads() { public long[] findDeadlockedThreads() {
if (!isSynchronizerUsageSupported()) { if (!isSynchronizerUsageSupported()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
@ -404,15 +428,18 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
return ids; return ids;
} }
@Override
public void resetPeakThreadCount() { public void resetPeakThreadCount() {
Util.checkControlAccess(); Util.checkControlAccess();
resetPeakThreadCount0(); resetPeakThreadCount0();
} }
@Override
public boolean isObjectMonitorUsageSupported() { public boolean isObjectMonitorUsageSupported() {
return jvm.isObjectMonitorUsageSupported(); return jvm.isObjectMonitorUsageSupported();
} }
@Override
public boolean isSynchronizerUsageSupported() { public boolean isSynchronizerUsageSupported() {
return jvm.isSynchronizerUsageSupported(); return jvm.isSynchronizerUsageSupported();
} }
@ -432,14 +459,20 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
Util.checkMonitorAccess(); Util.checkMonitorAccess();
} }
@Override
public ThreadInfo[] getThreadInfo(long[] ids, public ThreadInfo[] getThreadInfo(long[] ids,
boolean lockedMonitors, boolean lockedMonitors,
boolean lockedSynchronizers) { boolean lockedSynchronizers) {
verifyThreadIds(ids); verifyThreadIds(ids);
// ids has been verified to be non-null
// an empty array of ids should return an empty array of ThreadInfos
if (ids.length == 0) return new ThreadInfo[0];
verifyDumpThreads(lockedMonitors, lockedSynchronizers); verifyDumpThreads(lockedMonitors, lockedSynchronizers);
return dumpThreads0(ids, lockedMonitors, lockedSynchronizers); return dumpThreads0(ids, lockedMonitors, lockedSynchronizers);
} }
@Override
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, public ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
boolean lockedSynchronizers) { boolean lockedSynchronizers) {
verifyDumpThreads(lockedMonitors, lockedSynchronizers); verifyDumpThreads(lockedMonitors, lockedSynchronizers);
@ -469,6 +502,7 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
// tid == 0 to reset contention times for all threads // tid == 0 to reset contention times for all threads
private static native void resetContentionTimes0(long tid); private static native void resetContentionTimes0(long tid);
@Override
public ObjectName getObjectName() { public ObjectName getObjectName() {
return Util.newObjectName(ManagementFactory.THREAD_MXBEAN_NAME); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 { static void checkMonitorAccess() throws SecurityException {
checkAccess(monitorPermission); checkAccess(monitorPermission);
} }
static void checkControlAccess() throws SecurityException { public static void checkControlAccess() throws SecurityException {
checkAccess(controlPermission); checkAccess(controlPermission);
} }
} }

View File

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

View File

@ -36,17 +36,3 @@ JNIEXPORT jlong JNICALL Java_sun_management_GarbageCollectorImpl_getCollectionTi
(JNIEnv *env, jobject mgr) { (JNIEnv *env, jobject mgr) {
return jmm_interface->GetLongAttribute(env, mgr, JMM_GC_TIME_MS); 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) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -130,6 +130,15 @@ final public class InterfaceTypeImpl extends InvokableTypeImpl
return null; return null;
} }
@Override
boolean isAssignableTo(ReferenceType type) {
if (type.name().equals("java.lang.Object")) {
// interfaces are always assignable to j.l.Object
return true;
}
return super.isAssignableTo(type);
}
@Override @Override
List<InterfaceType> interfaces() { List<InterfaceType> interfaces() {
return superinterfaces(); return superinterfaces();
@ -140,4 +149,4 @@ final public class InterfaceTypeImpl extends InvokableTypeImpl
// method must be directly in this interface // method must be directly in this interface
return this.equals(method.declaringType()); return this.equals(method.declaringType());
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -64,15 +64,9 @@ public class Jstatd {
int localport = (port < 0) ? Registry.REGISTRY_PORT : port; int localport = (port < 0) ? Registry.REGISTRY_PORT : port;
registry = LocateRegistry.createRegistry(localport); registry = LocateRegistry.createRegistry(localport);
bind(name, remoteHost); bind(name, remoteHost);
} else {
throw e;
} }
else {
System.out.println("Could not contact registry\n"
+ e.getMessage());
e.printStackTrace();
}
} catch (RemoteException e) {
System.err.println("Could not bind " + name + " to RMI Registry");
e.printStackTrace();
} }
} }
@ -142,23 +136,28 @@ public class Jstatd {
RemoteHost stub = (RemoteHost) UnicastRemoteObject.exportObject( RemoteHost stub = (RemoteHost) UnicastRemoteObject.exportObject(
remoteHost, 0); remoteHost, 0);
bind(name.toString(), remoteHost); bind(name.toString(), remoteHost);
System.out.println("jstatd started (bound to " + name.toString() + ")");
System.out.flush();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
if (rminame != null) { if (rminame != null) {
System.out.println("Bad RMI server name: " + rminame); System.out.println("Bad RMI server name: " + rminame);
} else { } else {
System.out.println("Bad RMI URL: " + name + " : " System.out.println("Bad RMI URL: " + name);
+ e.getMessage());
} }
e.printStackTrace(System.out);
System.exit(1); System.exit(1);
} catch (java.rmi.ConnectException e) { } catch (java.rmi.ConnectException e) {
// could not attach to or create a registry // could not attach to or create a registry
System.out.println("Could not contact RMI registry\n" System.out.println("Could not contact RMI registry");
+ e.getMessage()); e.printStackTrace(System.out);
System.exit(1);
} catch (RemoteException e) {
System.out.println("Could not bind " + name + " to RMI Registry");
e.printStackTrace(System.out);
System.exit(1); System.exit(1);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Could not create remote object\n" System.out.println("Could not create remote object");
+ e.getMessage()); e.printStackTrace(System.out);
e.printStackTrace();
System.exit(1); System.exit(1);
} }
} }

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
#include "sun_management_OperatingSystemImpl.h" #include "com_sun_management_internal_OperatingSystemImpl.h"
struct ticks { struct ticks {
uint64_t used; uint64_t used;
@ -311,7 +311,7 @@ double get_process_load() {
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
if(perfInit() == 0) { if(perfInit() == 0) {
@ -322,7 +322,7 @@ Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
if(perfInit() == 0) { 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
#include "sun_management_OperatingSystemImpl.h" #include "com_sun_management_internal_OperatingSystemImpl.h"
#include <sys/time.h> #include <sys/time.h>
#include <mach/mach.h> #include <mach/mach.h>
@ -32,7 +32,7 @@
#include "jvm.h" #include "jvm.h"
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
// This code is influenced by the darwin top source // This code is influenced by the darwin top source
@ -84,7 +84,7 @@ Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
// This code is influenced by the darwin top source // 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,10 @@
package com.sun.management; package com.sun.management;
import javax.management.Notification;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataView; import javax.management.openmbean.CompositeDataView;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
import java.util.Collection; import com.sun.management.internal.GarbageCollectionNotifInfoCompositeData;
import java.util.Collections;
import sun.management.GarbageCollectionNotifInfoCompositeData;
/** /**
* The information about a garbage collection * 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.List; import com.sun.management.internal.GcInfoCompositeData;
import sun.management.GcInfoCompositeData; import com.sun.management.internal.GcInfoBuilder;
import sun.management.GcInfoBuilder;
/** /**
* Garbage collection information. It contains the following * 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package com.sun.management; package com.sun.management;
import sun.management.VMOptionCompositeData; import com.sun.management.internal.VMOptionCompositeData;
import javax.management.openmbean.CompositeData; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
/** /**
* Diagnostic Command Argument information. It contains the description * 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,21 +23,41 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import com.sun.management.DiagnosticCommandMBean; import com.sun.management.DiagnosticCommandMBean;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.security.Permission; import java.security.Permission;
import java.util.*; 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. * Implementation class for the diagnostic commands subsystem.
* *
* @since 1.8 * @since 1.8
*/ */
class DiagnosticCommandImpl extends NotificationEmitterSupport public class DiagnosticCommandImpl extends NotificationEmitterSupport
implements DiagnosticCommandMBean { implements DiagnosticCommandMBean {
private final VMManagement jvm; private final VMManagement jvm;
@ -45,6 +65,17 @@ class DiagnosticCommandImpl extends NotificationEmitterSupport
private static final String strClassName = "".getClass().getName(); private static final String strClassName = "".getClass().getName();
private static final String strArrayClassName = String[].class.getName(); private static final String strArrayClassName = String[].class.getName();
private final boolean isSupported; 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 @Override
public Object getAttribute(String attribute) throws AttributeNotFoundException, public Object getAttribute(String attribute) throws AttributeNotFoundException,
@ -327,7 +358,7 @@ class DiagnosticCommandImpl extends NotificationEmitterSupport
} }
ObjectName on = null; ObjectName on = null;
try { try {
on = ObjectName.getInstance(ManagementFactoryHelper.HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME); on = ObjectName.getInstance(PlatformMBeanProviderImpl.DIAGNOSTIC_COMMAND_MBEAN_NAME);
} catch (MalformedObjectNameException e) { } } catch (MalformedObjectNameException e) { }
Notification notif = new Notification("jmx.mbean.info.changed", Notification notif = new Notification("jmx.mbean.info.changed",
on, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import java.util.List; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import java.util.*; import java.util.*;
import com.sun.management.VMOption; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,10 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import com.sun.management.GarbageCollectionNotificationInfo; import com.sun.management.GarbageCollectionNotificationInfo;
import com.sun.management.GcInfo; import com.sun.management.GcInfo;
import java.lang.reflect.Method;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
@ -38,6 +37,9 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; 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. * A CompositeData for GarbageCollectionNotificationInfo for the local management support.
@ -95,7 +97,7 @@ public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
compositeTypeByBuilder.put(builder,gict); compositeTypeByBuilder.put(builder,gict);
} catch (OpenDataException e) { } catch (OpenDataException e) {
// shouldn't reach here // shouldn't reach here
throw Util.newException(e); throw new RuntimeException(e);
} }
} }
} }
@ -205,7 +207,7 @@ public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
baseGcNotifInfoItemTypes); baseGcNotifInfoItemTypes);
} catch (OpenDataException e) { } catch (OpenDataException e) {
// shouldn't reach here // shouldn't reach here
throw Util.newException(e); throw new RuntimeException(e);
} }
} }
return baseGcNotifInfoCompositeType; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import java.lang.management.GarbageCollectorMXBean; import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.MemoryUsage; import java.lang.management.MemoryUsage;
import javax.management.openmbean.OpenType; import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType; 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.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException; import javax.management.openmbean.OpenDataException;
import com.sun.management.GcInfo; import com.sun.management.GcInfo;
import sun.management.Util;
/** /**
* Helper class to build composite data. * Helper class to build composite data.
@ -164,7 +160,7 @@ public class GcInfoBuilder {
allItemTypes); allItemTypes);
} catch (OpenDataException e) { } catch (OpenDataException e) {
// shouldn't reach here // shouldn't reach here
throw Util.newException(e); throw new RuntimeException(e);
} }
gcInfoCompositeType = gict; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,12 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import java.lang.management.MemoryUsage; import java.lang.management.MemoryUsage;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
@ -42,9 +38,12 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.OpenType; import javax.management.openmbean.OpenType;
import javax.management.openmbean.OpenDataException; import javax.management.openmbean.OpenDataException;
import com.sun.management.GcInfo; import com.sun.management.GcInfo;
import com.sun.management.GarbageCollectionNotificationInfo;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; 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. * A CompositeData for GcInfo for the local management support.
@ -266,7 +265,7 @@ public class GcInfoCompositeData extends LazyCompositeData {
getBaseGcInfoItemTypes()); getBaseGcInfoItemTypes());
} catch (OpenDataException e) { } catch (OpenDataException e) {
// shouldn't reach here // shouldn't reach here
throw Util.newException(e); throw new RuntimeException(e);
} }
} }
return baseGcInfoCompositeType; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,6 +32,7 @@ import javax.management.ObjectName;
import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption; import com.sun.management.VMOption;
import sun.management.Util;
/** /**
* Implementation of the diagnostic MBean for Hotspot VM. * 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; 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.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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -34,12 +41,23 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.management.DynamicMBean; import javax.management.DynamicMBean;
import javax.management.ObjectName;
import sun.management.ManagementFactoryHelper; import sun.management.ManagementFactoryHelper;
import sun.management.spi.PlatformMBeanProvider; import sun.management.spi.PlatformMBeanProvider;
public final class PlatformMBeanProviderImpl extends 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 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() { public PlatformMBeanProviderImpl() {
mxbeanList = Collections.unmodifiableList(init()); mxbeanList = Collections.unmodifiableList(init());
@ -55,7 +73,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
/** /**
* Garbage Collector in the Java virtual machine. * 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 private final Set<String> garbageCollectorMXBeanInterfaceNames
= Collections.unmodifiableSet( = Collections.unmodifiableSet(
Stream.of("java.lang.management.MemoryManagerMXBean", Stream.of("java.lang.management.MemoryManagerMXBean",
@ -64,8 +82,8 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
.collect(Collectors.toSet())); .collect(Collectors.toSet()));
@Override @Override
public Set<Class<? extends java.lang.management.MemoryManagerMXBean>> mbeanInterfaces() { public Set<Class<? extends MemoryManagerMXBean>> mbeanInterfaces() {
return Stream.of(java.lang.management.MemoryManagerMXBean.class, return Stream.of(MemoryManagerMXBean.class,
java.lang.management.GarbageCollectorMXBean.class, java.lang.management.GarbageCollectorMXBean.class,
com.sun.management.GarbageCollectorMXBean.class) com.sun.management.GarbageCollectorMXBean.class)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
@ -87,27 +105,67 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
} }
@Override @Override
public Map<String, java.lang.management.MemoryManagerMXBean> nameToMBeanMap() { public Map<String, MemoryManagerMXBean> nameToMBeanMap() {
List<java.lang.management.GarbageCollectorMXBean> list List<java.lang.management.GarbageCollectorMXBean> list
= ManagementFactoryHelper.getGarbageCollectorMXBeans();; = ManagementFactoryHelper.getGarbageCollectorMXBeans();
Map<String, java.lang.management.MemoryManagerMXBean> map; Map<String, MemoryManagerMXBean> map;
if (list.isEmpty()) { if (list.isEmpty()) {
map = Collections.<String, java.lang.management.MemoryManagerMXBean>emptyMap(); map = Collections.emptyMap();
} else { } else {
map = new HashMap<>(list.size()); map = new HashMap<>(list.size());
for (java.lang.management.MemoryManagerMXBean gcm : list) { for (MemoryManagerMXBean gcm : list) {
map.put(gcm.getObjectName().getCanonicalName(), map.put(gcm.getObjectName().getCanonicalName(),
gcm); gcm);
} }
} }
return map; 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 * OperatingSystemMXBean
*/ */
initMBeanList.add(new PlatformComponent<java.lang.management.OperatingSystemMXBean>() { initMBeanList.add(new PlatformComponent<OperatingSystemMXBean>() {
private final Set<String> operatingSystemMXBeanInterfaceNames private final Set<String> operatingSystemMXBeanInterfaceNames
= Collections.unmodifiableSet( = Collections.unmodifiableSet(
Stream.of("java.lang.management.OperatingSystemMXBean", Stream.of("java.lang.management.OperatingSystemMXBean",
@ -116,7 +174,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
.collect(Collectors.toSet())); .collect(Collectors.toSet()));
@Override @Override
public Set<Class<? extends java.lang.management.OperatingSystemMXBean>> mbeanInterfaces() { public Set<Class<? extends OperatingSystemMXBean>> mbeanInterfaces() {
return Stream.of(java.lang.management.OperatingSystemMXBean.class, return Stream.of(java.lang.management.OperatingSystemMXBean.class,
com.sun.management.OperatingSystemMXBean.class, com.sun.management.OperatingSystemMXBean.class,
com.sun.management.UnixOperatingSystemMXBean.class) com.sun.management.UnixOperatingSystemMXBean.class)
@ -137,7 +195,7 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
public Map<String, java.lang.management.OperatingSystemMXBean> nameToMBeanMap() { public Map<String, java.lang.management.OperatingSystemMXBean> nameToMBeanMap() {
return Collections.<String, java.lang.management.OperatingSystemMXBean>singletonMap( return Collections.<String, java.lang.management.OperatingSystemMXBean>singletonMap(
ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, 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>() { initMBeanList.add(new PlatformComponent<com.sun.management.HotSpotDiagnosticMXBean>() {
private final Set<String> hotSpotDiagnosticMXBeanInterfaceNames = private final Set<String> hotSpotDiagnosticMXBeanInterfaceNames =
Collections.unmodifiableSet(Collections.<String>singleton("com.sun.management.HotSpotDiagnosticMXBean")); Collections.unmodifiableSet(Collections.<String>singleton(
"com.sun.management.HotSpotDiagnosticMXBean"));
@Override @Override
public Set<Class<? extends com.sun.management.HotSpotDiagnosticMXBean>> mbeanInterfaces() { 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() { public Map<String, com.sun.management.HotSpotDiagnosticMXBean> nameToMBeanMap() {
return Collections.<String, com.sun.management.HotSpotDiagnosticMXBean>singletonMap( return Collections.<String, com.sun.management.HotSpotDiagnosticMXBean>singletonMap(
"com.sun.management:type=HotSpotDiagnostic", "com.sun.management:type=HotSpotDiagnostic",
ManagementFactoryHelper.getDiagnosticMXBean()); getDiagnosticMXBean());
} }
}); });
/** /**
* DynamicMBean * Diagnostic command MBean
*/ */
HashMap<ObjectName, DynamicMBean> dynmbeans DiagnosticCommandMBean diagMBean = DiagnosticCommandImpl.getDiagnosticCommandMBean();
= ManagementFactoryHelper.getPlatformDynamicMBeans(); if (diagMBean != null) {
final Set<String> dynamicMBeanInterfaceNames =
Collections.unmodifiableSet(Collections.<String>singleton("javax.management.DynamicMBean"));
for (Map.Entry<ObjectName, DynamicMBean> e : dynmbeans.entrySet()) {
initMBeanList.add(new PlatformComponent<DynamicMBean>() { initMBeanList.add(new PlatformComponent<DynamicMBean>() {
final Set<String> dynamicMBeanInterfaceNames
= Collections.unmodifiableSet(Collections.<String>singleton(
"javax.management.DynamicMBean"));
@Override @Override
public Set<String> mbeanInterfaceNames() { public Set<String> mbeanInterfaceNames() {
return dynamicMBeanInterfaceNames; return dynamicMBeanInterfaceNames;
@ -187,23 +247,39 @@ public final class PlatformMBeanProviderImpl extends PlatformMBeanProvider {
@Override @Override
public Set<Class<? extends DynamicMBean>> mbeanInterfaces() { 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 @Override
public String getObjectNamePattern() { public String getObjectNamePattern() {
return e.getKey().getCanonicalName(); return DIAGNOSTIC_COMMAND_MBEAN_NAME;
} }
@Override @Override
public Map<String, DynamicMBean> nameToMBeanMap() { public Map<String, DynamicMBean> nameToMBeanMap() {
return Collections.<String, DynamicMBean>singletonMap( return Collections.<String, DynamicMBean>singletonMap(
e.getKey().getCanonicalName(), DIAGNOSTIC_COMMAND_MBEAN_NAME,
e.getValue()); diagMBean);
} }
}); });
} }
initMBeanList.trimToSize(); initMBeanList.trimToSize();
return initMBeanList; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import com.sun.management.VMOption; import com.sun.management.VMOption;
import com.sun.management.VMOption.Origin; import com.sun.management.VMOption.Origin;
@ -31,6 +31,8 @@ import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException; import javax.management.openmbean.OpenDataException;
import sun.management.LazyCompositeData;
import sun.management.MappedMXBeanType;
/** /**
* A CompositeData for VMOption for the local management support. * 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <jni.h> #include <jni.h>
#include "management.h" #include "management_ext.h"
#include "sun_management_DiagnosticCommandImpl.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) { (JNIEnv *env, jobject dummy, jboolean enabled) {
if (jmm_version <= JMM_VERSION_1_2_2) { if (jmm_version <= JMM_VERSION_1_2_2) {
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
@ -39,7 +39,7 @@ JNIEXPORT void JNICALL Java_sun_management_DiagnosticCommandImpl_setNotification
} }
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommands Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
return jmm_interface->GetDiagnosticCommands(env); return jmm_interface->GetDiagnosticCommands(env);
@ -64,7 +64,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command, jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
dcmd_arg_info_array); dcmd_arg_info_array);
dcmdArgInfoCls = (*env)->FindClass(env, dcmdArgInfoCls = (*env)->FindClass(env,
"sun/management/DiagnosticCommandArgumentInfo"); "com/sun/management/internal/DiagnosticCommandArgumentInfo");
if ((*env)->ExceptionCheck(env)) { if ((*env)->ExceptionCheck(env)) {
free(dcmd_arg_info_array); free(dcmd_arg_info_array);
return NULL; return NULL;
@ -77,7 +77,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
} }
for (i=0; i<num_arg; i++) { for (i=0; i<num_arg; i++) {
obj = JNU_NewObjectByName(env, 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", "(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].name),
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].description), (*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 * passed in argument is not supported by the JVM
*/ */
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo
(JNIEnv *env, jobject dummy, jobjectArray commands) (JNIEnv *env, jobject dummy, jobjectArray commands)
{ {
int i; int i;
@ -132,7 +132,7 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
} }
num_commands = (*env)->GetArrayLength(env, commands); num_commands = (*env)->GetArrayLength(env, commands);
dcmdInfoCls = (*env)->FindClass(env, dcmdInfoCls = (*env)->FindClass(env,
"sun/management/DiagnosticCommandInfo"); "com/sun/management/internal/DiagnosticCommandInfo");
if ((*env)->ExceptionCheck(env)) { if ((*env)->ExceptionCheck(env)) {
return NULL; return NULL;
} }
@ -163,7 +163,7 @@ Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
return NULL; return NULL;
} }
obj = JNU_NewObjectByName(env, 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", "(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].name),
(*env)->NewStringUTF(env,dcmd_info_array[i].description), (*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 * passed in argument is not supported by the JVM
*/ */
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand
(JNIEnv *env, jobject dummy, jstring command) { (JNIEnv *env, jobject dummy, jstring command) {
return jmm_interface->ExecuteDiagnosticCommand(env, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <jni.h> #include <jni.h>
#include "management.h" #include "management_ext.h"
#include "sun_management_Flag.h" #include "com_sun_management_internal_Flag.h"
static jobject default_origin = NULL; static jobject default_origin = NULL;
static jobject vm_creation_origin = NULL; static jobject vm_creation_origin = NULL;
@ -40,7 +40,7 @@ static jobject attach_origin = NULL;
static jobject other_origin = NULL; static jobject other_origin = NULL;
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_sun_management_Flag_getInternalFlagCount Java_com_sun_management_internal_Flag_getInternalFlagCount
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
jlong count = jmm_interface->GetLongAttribute(env, NULL, jlong count = jmm_interface->GetLongAttribute(env, NULL,
@ -49,7 +49,7 @@ Java_sun_management_Flag_getInternalFlagCount
} }
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_sun_management_Flag_getAllFlagNames Java_com_sun_management_internal_Flag_getAllFlagNames
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
return jmm_interface->GetVMGlobalNames(env); return jmm_interface->GetVMGlobalNames(env);
@ -66,7 +66,7 @@ static jobject find_origin_constant(JNIEnv* env, const char* enum_name) {
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_Flag_initialize Java_com_sun_management_internal_Flag_initialize
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
default_origin = find_origin_constant(env, "DEFAULT"); default_origin = find_origin_constant(env, "DEFAULT");
@ -80,13 +80,13 @@ Java_sun_management_Flag_initialize
} }
JNIEXPORT jint JNICALL 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) (JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count)
{ {
jint num_flags, i, index; jint num_flags, i, index;
jmmVMGlobal* globals; jmmVMGlobal* globals;
size_t gsize; 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"; const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V";
jobject origin; jobject origin;
jobject valueObj; jobject valueObj;
@ -196,7 +196,7 @@ Java_sun_management_Flag_getFlags
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_Flag_setLongValue Java_com_sun_management_internal_Flag_setLongValue
(JNIEnv *env, jclass cls, jstring name, jlong value) (JNIEnv *env, jclass cls, jstring name, jlong value)
{ {
jvalue v; jvalue v;
@ -206,7 +206,7 @@ Java_sun_management_Flag_setLongValue
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_Flag_setDoubleValue Java_com_sun_management_internal_Flag_setDoubleValue
(JNIEnv *env, jclass cls, jstring name, jdouble value) (JNIEnv *env, jclass cls, jstring name, jdouble value)
{ {
jvalue v; jvalue v;
@ -216,7 +216,7 @@ Java_sun_management_Flag_setDoubleValue
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_Flag_setBooleanValue Java_com_sun_management_internal_Flag_setBooleanValue
(JNIEnv *env, jclass cls, jstring name, jboolean value) (JNIEnv *env, jclass cls, jstring name, jboolean value)
{ {
jvalue v; jvalue v;
@ -226,7 +226,7 @@ Java_sun_management_Flag_setBooleanValue
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_Flag_setStringValue Java_com_sun_management_internal_Flag_setStringValue
(JNIEnv *env, jclass cls, jstring name, jstring value) (JNIEnv *env, jclass cls, jstring name, jstring value)
{ {
jvalue v; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,10 +26,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <jni.h> #include <jni.h>
#include "management.h" #include "management_ext.h"
#include "sun_management_GcInfoBuilder.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) { (JNIEnv *env, jobject dummy, jobject gc) {
jlong value; jlong value;
@ -42,7 +42,7 @@ JNIEXPORT jint JNICALL Java_sun_management_GcInfoBuilder_getNumGcExtAttributes
return (jint) value; 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, (JNIEnv *env, jobject dummy, jobject gc,
jint num_attributes, jobjectArray attributeNames, jint num_attributes, jobjectArray attributeNames,
jcharArray types, jobjectArray descriptions) { jcharArray types, jobjectArray descriptions) {
@ -173,7 +173,7 @@ static void setCharValueAtObjectArray(JNIEnv *env, jobjectArray array,
(*env)->SetObjectArrayElement(env, array, index, obj); (*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, (JNIEnv *env, jobject builder, jobject gc,
jint ext_att_count, jobjectArray ext_att_values, jcharArray ext_att_types, jint ext_att_count, jobjectArray ext_att_values, jcharArray ext_att_types,
jobjectArray usageBeforeGC, jobjectArray usageAfterGC) { jobjectArray usageBeforeGC, jobjectArray usageAfterGC) {
@ -273,7 +273,7 @@ JNIEXPORT jobject JNICALL Java_sun_management_GcInfoBuilder_getLastGcInfo0
return JNU_NewObjectByName(env, return JNU_NewObjectByName(env,
"com/sun/management/GcInfo", "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, builder,
gc_stat.gc_index, gc_stat.gc_index,
gc_stat.start_time, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
#include <jni.h> #include <jni.h>
#include "jvm.h" #include "jvm.h"
#include "management.h" #include "management_ext.h"
#include "sun_management_HotSpotDiagnostic.h" #include "com_sun_management_internal_HotSpotDiagnostic.h"
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_HotSpotDiagnostic_dumpHeap0 Java_com_sun_management_internal_HotSpotDiagnostic_dumpHeap0
(JNIEnv *env, jobject dummy, jstring outputfile, jboolean live) (JNIEnv *env, jobject dummy, jstring outputfile, jboolean live)
{ {
jmm_interface->DumpHeap0(env, outputfile, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,33 +23,39 @@
* questions. * questions.
*/ */
package sun.management; #include <stdio.h>
#include <jni.h>
#include "jvm.h"
#include "management_ext.h"
import java.lang.management.MemoryManagerMXBean; #define ERR_MSG_SIZE 128
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.GarbageCollectorMXBean;
/** const JmmInterface* jmm_interface = NULL;
* ManagementFactory class provides the methods that the HotSpot VM JavaVM* jvm = NULL;
* will invoke. So the class and method names cannot be renamed. jint jmm_version = 0;
*/
class ManagementFactory {
private ManagementFactory() {};
// Invoked by the VM JNIEXPORT jint JNICALL
private static MemoryPoolMXBean createMemoryPool JNI_OnLoad(JavaVM *vm, void *reserved) {
(String name, boolean isHeap, long uThreshold, long gcThreshold) { JNIEnv* env;
return new MemoryPoolImpl(name, isHeap, uThreshold, gcThreshold);
jvm = vm;
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_2) != JNI_OK) {
return JNI_ERR;
} }
private static MemoryManagerMXBean createMemoryManager(String name) { jmm_interface = (JmmInterface*) JVM_GetManagement(JMM_VERSION_1_0);
return new MemoryManagerImpl(name); if (jmm_interface == NULL) {
JNU_ThrowInternalError(env, "Unsupported Management version");
return JNI_ERR;
} }
private static GarbageCollectorMXBean jmm_version = jmm_interface->GetVersion(env);
createGarbageCollector(String name, String type) { return (*env)->GetVersion(env);
}
// ignore type parameter which is for future extension
return new GarbageCollectorImpl(name); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -38,7 +38,7 @@
#include <sys/loadavg.h> #include <sys/loadavg.h>
#include <jni.h> #include <jni.h>
#include "jvm.h" #include "jvm.h"
#include "sun_management_OperatingSystemImpl.h" #include "com_sun_management_internal_OperatingSystemImpl.h"
typedef struct { typedef struct {
kstat_t *kstat; kstat_t *kstat;
@ -226,14 +226,14 @@ double get_process_load(void) {
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
return get_cpu_load(-1); return get_cpu_load(-1);
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
return get_process_load(); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,10 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import sun.management.BaseOperatingSystemImpl;
import sun.management.VMManagement;
/** /**
* Implementation class for the operating system. * Implementation class for the operating system.
* Standard and committed hotspot-specific metrics if any. * 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include "jni_util.h" #include "jni_util.h"
#include "jlong.h" #include "jlong.h"
#include "jvm.h" #include "jvm.h"
#include "management.h" #include "management_ext.h"
#include "sun_management_OperatingSystemImpl.h" #include "com_sun_management_internal_OperatingSystemImpl.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.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 JNIEXPORT void JNICALL
Java_sun_management_OperatingSystemImpl_initialize0 Java_com_sun_management_internal_OperatingSystemImpl_initialize0
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
page_size = sysconf(_SC_PAGESIZE); page_size = sysconf(_SC_PAGESIZE);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
#ifdef __solaris__ #ifdef __solaris__
@ -256,21 +256,21 @@ Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0 Java_com_sun_management_internal_OperatingSystemImpl_getTotalSwapSpaceSize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
return get_total_or_available_swap_space_size(env, JNI_FALSE); return get_total_or_available_swap_space_size(env, JNI_FALSE);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0 Java_com_sun_management_internal_OperatingSystemImpl_getFreeSwapSpaceSize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
return get_total_or_available_swap_space_size(env, JNI_TRUE); return get_total_or_available_swap_space_size(env, JNI_TRUE);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuTime0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
@ -312,7 +312,7 @@ Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getFreePhysicalMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
@ -346,7 +346,7 @@ Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getTotalPhysicalMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
#ifdef _ALLBSD_SOURCE #ifdef _ALLBSD_SOURCE
@ -377,7 +377,7 @@ Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0 Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
@ -466,7 +466,7 @@ Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getMaxFileDescriptorCount0 Java_com_sun_management_internal_OperatingSystemImpl_getMaxFileDescriptorCount0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
struct rlimit rlp; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,9 +23,11 @@
* questions. * questions.
*/ */
package sun.management; package com.sun.management.internal;
import com.sun.management.OperatingSystemMXBean; import com.sun.management.OperatingSystemMXBean;
import sun.management.BaseOperatingSystemImpl;
import sun.management.VMManagement;
/** /**
* Implementation class for the operating system. * Implementation class for the operating system.
@ -45,36 +47,44 @@ class OperatingSystemImpl extends BaseOperatingSystemImpl
super(vm); super(vm);
} }
@Override
public long getCommittedVirtualMemorySize() { public long getCommittedVirtualMemorySize() {
synchronized (psapiLock) { synchronized (psapiLock) {
return getCommittedVirtualMemorySize0(); return getCommittedVirtualMemorySize0();
} }
} }
@Override
public long getTotalSwapSpaceSize() { public long getTotalSwapSpaceSize() {
return getTotalSwapSpaceSize0(); return getTotalSwapSpaceSize0();
} }
@Override
public long getFreeSwapSpaceSize() { public long getFreeSwapSpaceSize() {
return getFreeSwapSpaceSize0(); return getFreeSwapSpaceSize0();
} }
@Override
public long getProcessCpuTime() { public long getProcessCpuTime() {
return getProcessCpuTime0(); return getProcessCpuTime0();
} }
@Override
public long getFreePhysicalMemorySize() { public long getFreePhysicalMemorySize() {
return getFreePhysicalMemorySize0(); return getFreePhysicalMemorySize0();
} }
@Override
public long getTotalPhysicalMemorySize() { public long getTotalPhysicalMemorySize() {
return getTotalPhysicalMemorySize0(); return getTotalPhysicalMemorySize0();
} }
@Override
public double getSystemCpuLoad() { public double getSystemCpuLoad() {
return getSystemCpuLoad0(); return getSystemCpuLoad0();
} }
@Override
public double getProcessCpuLoad() { public double getProcessCpuLoad() {
return getProcessCpuLoad0(); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
#include "jni_util.h" #include "jni_util.h"
#include "jlong.h" #include "jlong.h"
#include "jvm.h" #include "jvm.h"
#include "management.h" #include "management_ext.h"
#include "sun_management_OperatingSystemImpl.h" #include "com_sun_management_internal_OperatingSystemImpl.h"
#include <psapi.h> #include <psapi.h>
#include <errno.h> #include <errno.h>
@ -75,7 +75,7 @@ static HANDLE main_process;
static void perfInit(void); static void perfInit(void);
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_management_OperatingSystemImpl_initialize0 Java_com_sun_management_internal_OperatingSystemImpl_initialize0
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
main_process = GetCurrentProcess(); main_process = GetCurrentProcess();
@ -83,7 +83,7 @@ Java_sun_management_OperatingSystemImpl_initialize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS pmc;
@ -95,7 +95,7 @@ Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0 Java_com_sun_management_internal_OperatingSystemImpl_getTotalSwapSpaceSize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
MEMORYSTATUSEX ms; MEMORYSTATUSEX ms;
@ -105,7 +105,7 @@ Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0 Java_com_sun_management_internal_OperatingSystemImpl_getFreeSwapSpaceSize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
MEMORYSTATUSEX ms; MEMORYSTATUSEX ms;
@ -115,7 +115,7 @@ Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuTime0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
@ -134,7 +134,7 @@ Java_sun_management_OperatingSystemImpl_getProcessCpuTime0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getFreePhysicalMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
MEMORYSTATUSEX ms; MEMORYSTATUSEX ms;
@ -144,7 +144,7 @@ Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0 Java_com_sun_management_internal_OperatingSystemImpl_getTotalPhysicalMemorySize0
(JNIEnv *env, jobject mbean) (JNIEnv *env, jobject mbean)
{ {
MEMORYSTATUSEX ms; MEMORYSTATUSEX ms;
@ -1349,14 +1349,14 @@ perfGetCPULoad(int which) {
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
return perfGetCPULoad(-1); return perfGetCPULoad(-1);
} }
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_management_OperatingSystemImpl_getProcessCpuLoad0 Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
(JNIEnv *env, jobject dummy) (JNIEnv *env, jobject dummy)
{ {
return perfGetProcessCPULoad(); return perfGetProcessCPULoad();

View File

@ -136,13 +136,6 @@ java/lang/instrument/BootClassPath/BootClassPathTest.sh macosx-all
############################################################################ ############################################################################
# jdk_management
# 8058492
java/lang/management/ThreadMXBean/FindDeadlocks.java generic-all
############################################################################
# jdk_jmx # jdk_jmx
# 8030957 # 8030957
@ -353,9 +346,6 @@ com/sun/jdi/RedefinePop.sh generic-all
# 8068645 # 8068645
com/sun/jdi/CatchPatternTest.sh generic-all com/sun/jdi/CatchPatternTest.sh generic-all
# 8069402
com/sun/jdi/ConnectedVMs.java generic-all
# 8067354 # 8067354
com/sun/jdi/GetLocalVariables4Test.sh windows-all com/sun/jdi/GetLocalVariables4Test.sh windows-all
@ -380,13 +370,7 @@ sun/tools/jcmd/TestJcmdSanity.java windows-all
# 8072131 # 8072131
sun/tools/jmap/heapconfig/JMapHeapConfigTest.java macosx-all sun/tools/jmap/heapconfig/JMapHeapConfigTest.java macosx-all
# 8027668 # 8046285
sun/tools/jstatd/TestJstatdDefaults.java generic-all
sun/tools/jstatd/TestJstatdServer.java generic-all
sun/tools/jstatd/TestJstatdPort.java generic-all
sun/tools/jstatd/TestJstatdPortAndServer.java generic-all
# 8046285 8027668
sun/tools/jstatd/TestJstatdExternalRegistry.java generic-all sun/tools/jstatd/TestJstatdExternalRegistry.java generic-all
# 6456333 # 6456333

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -104,7 +104,10 @@ public class InstanceFilter extends TestScaffold {
return; return;
} }
if (theThis == null) { if (theThis == null) {
// This happens when the thread has exited. // This happens when the thread has exited or when a
// static method is called. Setting an instance
// filter does not prevent this event from being
// emitted with a this that is null.
methodEntryRequest.disable(); methodEntryRequest.disable();
return; return;
} }
@ -138,6 +141,10 @@ public class InstanceFilter extends TestScaffold {
EventRequestManager mgr = vm().eventRequestManager(); EventRequestManager mgr = vm().eventRequestManager();
methodEntryRequest = mgr.createMethodEntryRequest(); methodEntryRequest = mgr.createMethodEntryRequest();
methodEntryRequest.addInstanceFilter(theInstance); methodEntryRequest.addInstanceFilter(theInstance);
// Thread filter is needed to prevent MethodEntry events
// to be emitted by the debugee when a static method
// is called on any thread.
methodEntryRequest.addThreadFilter(bpe.thread());
methodEntryRequest.enable(); methodEntryRequest.enable();
listenUntilVMDisconnect(); listenUntilVMDisconnect();

View File

@ -0,0 +1,97 @@
/*
* 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.
*/
/**
* @test
* @bug 8075331
* @summary Verify that we can call varargs methods
* @run build TestScaffold VMConnection TargetAdapter TargetListener
* @run compile -g InvokeVarArgs.java
* @run driver InvokeVarArgs
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import java.util.Arrays;
interface MyInterface {
}
class SomeClass implements MyInterface {
}
class InvokeVarArgsTarg {
public static void main(String args[]) {
new InvokeVarArgsTarg().run();
}
SomeClass someClass1 = new SomeClass();
SomeClass someClass2 = new SomeClass();
MyInterface[] array = new MyInterface[]{someClass1, someClass2};
SomeClass[] array2 = new SomeClass[]{someClass1, someClass2};
public void run() {
System.out.println("size(array) : " + size(array));
System.out.println("size(array2) : " + size(array2));
}
int size(Object... value) {
return value.length;
}
}
public class InvokeVarArgs extends TestScaffold {
public static void main(String args[]) throws Exception {
new InvokeVarArgs(args).startTests();
}
InvokeVarArgs(String args[]) throws Exception {
super(args);
}
protected void runTests() throws Exception {
BreakpointEvent bpe = startTo("InvokeVarArgsTarg", "run", "()V");
StackFrame frame = bpe.thread().frame(0);
ObjectReference targetObj = frame.thisObject();
ReferenceType targetType = (ReferenceType) targetObj.type();
Value arrayVal = targetObj.getValue(targetType.fieldByName("array"));
Value array2Val = targetObj.getValue(targetType.fieldByName("array2"));
Method sizeMethod = targetType.methodsByName("size", "([Ljava/lang/Object;)I").get(0);
IntegerValue size = (IntegerValue) targetObj.invokeMethod(bpe.thread(), sizeMethod, Arrays.asList(new Value[]{arrayVal}), 0);
if (size.value() != 2) {
throw new Exception("size(array) should be 2, but was " + size.value());
}
size = (IntegerValue) targetObj.invokeMethod(bpe.thread(), sizeMethod, Arrays.asList(new Value[]{array2Val}), 0);
if (size.value() != 2) {
throw new Exception("size(array2) should be 2, but was " + size.value());
}
listenUntilVMDisconnect();
}
}

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

@ -0,0 +1,207 @@
/*
* 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.
*/
/* @test
* @bug 8057919
* @summary Class.getSimpleName() should work for non-JLS compliant class names
*/
import jdk.internal.org.objectweb.asm.*;
import static jdk.internal.org.objectweb.asm.Opcodes.*;
public class GetSimpleNameTest {
static class NestedClass {}
class InnerClass {}
static Class<?> f1() {
class LocalClass {}
return LocalClass.class;
}
public static void main(String[] args) throws Exception {
assertEquals(NestedClass.class.getSimpleName(), "NestedClass");
assertEquals( InnerClass.class.getSimpleName(), "InnerClass");
assertEquals( f1().getSimpleName(), "LocalClass");
java.io.Serializable anon = new java.io.Serializable() {};
assertEquals(anon.getClass().getSimpleName(), "");
// Java class names, prepended enclosing class name.
testNested("p.Outer$Nested", "p.Outer", "Nested");
testInner( "p.Outer$Inner", "p.Inner", "Inner");
testLocal( "p.Outer$1Local", "p.Outer", "Local");
testAnon( "p.Outer$1", "p.Outer", "");
// Non-Java class names, prepended enclosing class name.
testNested("p.$C1$Nested", "p.$C1$", "Nested");
testInner( "p.$C1$Inner", "p.$C1$", "Inner");
testLocal( "p.$C1$Local", "p.$C1$", "Local");
testAnon( "p.$C1$1", "p.$C1$", "");
// Non-Java class names, unrelated class names.
testNested("p1.$Nested$", "p2.$C1$", "Nested");
testInner( "p1.$Inner$", "p2.$C1$", "Inner");
testLocal( "p1.$Local$", "p2.$C1$", "Local");
testAnon( "p1.$anon$", "p2.$C1$", "");
}
static void testNested(String innerName, String outerName, String simpleName) throws Exception {
BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
CustomCL cl = new CustomCL(innerName, outerName, bg.getNestedClasses(true), bg.getNestedClasses(false));
assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
}
static void testInner(String innerName, String outerName, String simpleName) throws Exception {
BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
CustomCL cl = new CustomCL(innerName, outerName, bg.getInnerClasses(true), bg.getInnerClasses(false));
assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
}
static void testLocal(String innerName, String outerName, String simpleName) throws Exception {
BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
CustomCL cl = new CustomCL(innerName, outerName, bg.getLocalClasses(true), bg.getLocalClasses(false));
assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
}
static void testAnon(String innerName, String outerName, String simpleName) throws Exception {
BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
CustomCL cl = new CustomCL(innerName, outerName, bg.getAnonymousClasses(true), bg.getAnonymousClasses(false));
assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
}
static void assertEquals(Object o1, Object o2) {
if (!java.util.Objects.equals(o1, o2)) {
throw new AssertionError(o1 + " != " + o2);
}
}
static class CustomCL extends ClassLoader {
final String innerName;
final String outerName;
final byte[] innerClassFile;
final byte[] outerClassFile;
CustomCL(String innerName, String outerName, byte[] innerClassFile, byte[] outerClassFile) {
this.innerName = innerName;
this.outerName = outerName;
this.innerClassFile = innerClassFile;
this.outerClassFile = outerClassFile;
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (innerName.equals(name)) {
return defineClass(innerName, innerClassFile, 0, innerClassFile.length);
} else if (outerName.equals(name)) {
return defineClass(outerName, outerClassFile, 0, outerClassFile.length);
} else {
throw new ClassNotFoundException(name);
}
}
}
static class BytecodeGenerator {
final String innerName;
final String outerName;
final String simpleName;
BytecodeGenerator(String innerName, String outerName, String simpleName) {
this.innerName = intl(innerName);
this.outerName = intl(outerName);
this.simpleName = simpleName;
}
static String intl(String name) { return name.replace('.', '/'); }
static void makeDefaultCtor(ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
void makeCtxk(ClassWriter cw, boolean isInner) {
if (isInner) {
cw.visitOuterClass(outerName, "f", "()V");
} else {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f", "()V", null, null);
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
}
byte[] getNestedClasses(boolean isInner) {
String name = (isInner ? innerName : outerName);
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
cw.visitInnerClass(innerName, outerName, simpleName, ACC_PUBLIC | ACC_STATIC);
makeDefaultCtor(cw);
cw.visitEnd();
return cw.toByteArray();
}
byte[] getInnerClasses(boolean isInner) {
String name = (isInner ? innerName : outerName);
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
cw.visitInnerClass(innerName, outerName, simpleName, ACC_PUBLIC);
makeDefaultCtor(cw);
cw.visitEnd();
return cw.toByteArray();
}
byte[] getLocalClasses(boolean isInner) {
String name = (isInner ? innerName : outerName);
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
cw.visitInnerClass(innerName, null, simpleName, ACC_PUBLIC | ACC_STATIC);
makeCtxk(cw, isInner);
makeDefaultCtor(cw);
cw.visitEnd();
return cw.toByteArray();
}
byte[] getAnonymousClasses(boolean isInner) {
String name = (isInner ? innerName : outerName);
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
cw.visitInnerClass(innerName, null, null, ACC_PUBLIC | ACC_STATIC);
makeCtxk(cw, isInner);
makeDefaultCtor(cw);
cw.visitEnd();
return cw.toByteArray();
}
}
}

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport; import java.util.concurrent.locks.LockSupport;
import jdk.testlibrary.LockFreeLogManager; import jdk.testlibrary.LockFreeLogManager;
import jdk.testlibrary.Utils;
/** /**
* ThreadStateController allows a thread to request this thread to transition * ThreadStateController allows a thread to request this thread to transition
@ -73,7 +74,7 @@ public class ThreadStateController extends Thread {
public static void pause(long ms) { public static void pause(long ms) {
try { try {
Thread.sleep(ms); Thread.sleep(Utils.adjustTimeout(ms));
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -135,7 +136,7 @@ public class ThreadStateController extends Thread {
try { try {
// this thread has escaped the BLOCKED state // this thread has escaped the BLOCKED state
// release the lock and a short wait before continue // release the lock and a short wait before continue
lock.wait(10); lock.wait(Utils.adjustTimeout(10));
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
interrupted.incrementAndGet(); interrupted.incrementAndGet();
@ -165,7 +166,7 @@ public class ThreadStateController extends Thread {
getId(), getName(), iterations.get(), interrupted.get()); getId(), getName(), iterations.get(), interrupted.get());
try { try {
stateChange(nextState); stateChange(nextState);
lock.wait(10000); lock.wait(Integer.MAX_VALUE);
log("%d: %s wakes up from timed waiting (iterations %d interrupted %d)%n", log("%d: %s wakes up from timed waiting (iterations %d interrupted %d)%n",
getId(), getName(), iterations.get(), interrupted.get()); getId(), getName(), iterations.get(), interrupted.get());
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -185,7 +186,8 @@ public class ThreadStateController extends Thread {
case S_TIMED_PARKED: { case S_TIMED_PARKED: {
log("%d: %s is going to timed park (iterations %d)%n", log("%d: %s is going to timed park (iterations %d)%n",
getId(), getName(), iterations.get()); getId(), getName(), iterations.get());
long deadline = System.currentTimeMillis() + 10000*1000; long deadline = System.currentTimeMillis() +
Utils.adjustTimeout(10000*1000);
stateChange(nextState); stateChange(nextState);
LockSupport.parkUntil(deadline); LockSupport.parkUntil(deadline);
break; break;
@ -195,7 +197,7 @@ public class ThreadStateController extends Thread {
getId(), getName(), iterations.get(), interrupted.get()); getId(), getName(), iterations.get(), interrupted.get());
try { try {
stateChange(nextState); stateChange(nextState);
Thread.sleep(1000000); Thread.sleep(Utils.adjustTimeout(1000000));
} catch (InterruptedException e) { } catch (InterruptedException e) {
// finish sleeping // finish sleeping
interrupted.incrementAndGet(); interrupted.incrementAndGet();

View File

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

View File

@ -77,7 +77,7 @@ fi
cat output.log cat output.log
MESG="Exception" MESG="Test failed"
grep "$MESG" output.log grep "$MESG" output.log
result=$? result=$?
if [ "$result" = 0 ]; then if [ "$result" = 0 ]; then

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch; 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 * When an exception is thrown, the JVM collects just enough information
@ -46,12 +47,15 @@ import sun.management.ManagementFactoryHelper;
* could be freed, since class redefinition didn't know about the backtraces. * could be freed, since class redefinition didn't know about the backtraces.
*/ */
public class RedefineMethodInBacktraceApp { public class RedefineMethodInBacktraceApp {
static boolean failed = false;
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
System.out.println("Hello from RedefineMethodInBacktraceApp!"); System.out.println("Hello from RedefineMethodInBacktraceApp!");
new RedefineMethodInBacktraceApp().doTest(); new RedefineMethodInBacktraceApp().doTest();
System.exit(0); if (failed) {
throw new Exception("ERROR: RedefineMethodInBacktraceApp failed.");
}
} }
public static CountDownLatch stop = new CountDownLatch(1); public static CountDownLatch stop = new CountDownLatch(1);
@ -63,13 +67,18 @@ public class RedefineMethodInBacktraceApp {
} }
private void doMethodInBacktraceTest() throws Exception { private void doMethodInBacktraceTest() throws Exception {
Throwable t = getThrowableFromMethodToRedefine(); Throwable t1 = getThrowableFromMethodToRedefine();
Throwable t2 = getThrowableFromMethodToDelete();
doRedefine(RedefineMethodInBacktraceTarget.class); doRedefine(RedefineMethodInBacktraceTarget.class);
doClassUnloading(); doClassUnloading();
touchRedefinedMethodInBacktrace(t); System.out.println("checking backtrace for throwable from methodToRedefine");
touchRedefinedMethodInBacktrace(t1);
System.out.println("checking backtrace for throwable from methodToDelete");
touchRedefinedMethodInBacktrace(t2);
} }
private void doMethodInBacktraceTestB() throws Exception { private void doMethodInBacktraceTestB() throws Exception {
@ -95,8 +104,11 @@ public class RedefineMethodInBacktraceApp {
String[] threadPrintArgs = {}; String[] threadPrintArgs = {};
Object[] dcmdArgs = {threadPrintArgs}; Object[] dcmdArgs = {threadPrintArgs};
String[] signature = {String[].class.getName()}; String[] signature = {String[].class.getName()};
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean(); System.out.println(ManagementFactory.getPlatformMBeanServer().invoke(
System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature)); ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"),
"threadPrint",
dcmdArgs,
signature));
// release the thread // release the thread
stop.countDown(); stop.countDown();
@ -115,6 +127,10 @@ public class RedefineMethodInBacktraceApp {
if (!(thrownFromMethodToRedefine instanceof RuntimeException)) { if (!(thrownFromMethodToRedefine instanceof RuntimeException)) {
throw e; throw e;
} }
} catch (Exception e) {
e.printStackTrace();
System.out.println("\nTest failed: unexpected exception: " + e.toString());
failed = true;
} }
method = null; method = null;
c = null; c = null;
@ -122,15 +138,49 @@ public class RedefineMethodInBacktraceApp {
return thrownFromMethodToRedefine; return thrownFromMethodToRedefine;
} }
private static Throwable getThrowableFromMethodToDelete() throws Exception {
Class<RedefineMethodInBacktraceTarget> c =
RedefineMethodInBacktraceTarget.class;
Method method = c.getMethod("callMethodToDelete");
Throwable thrownFromMethodToDelete = null;
try {
method.invoke(null);
} catch (InvocationTargetException e) {
thrownFromMethodToDelete = e.getCause();
if (!(thrownFromMethodToDelete instanceof RuntimeException)) {
throw e;
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("\nTest failed: unexpected exception: " + e.toString());
failed = true;
}
return thrownFromMethodToDelete;
}
private static void doClassUnloading() { private static void doClassUnloading() {
// This will clean out old, unused redefined methods. // This will clean out old, unused redefined methods.
System.gc(); System.gc();
} }
private static void touchRedefinedMethodInBacktrace(Throwable throwable) { private static void touchRedefinedMethodInBacktrace(Throwable throwable) {
throwable.printStackTrace();
// Make sure that we can convert the backtrace, which is referring to // Make sure that we can convert the backtrace, which is referring to
// the redefined method, to a StrackTraceElement[] without crashing. // the redefined method, to a StrackTraceElement[] without crashing.
throwable.getStackTrace(); StackTraceElement[] stackTrace = throwable.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement frame = stackTrace[i];
if (frame.getClassName() == null) {
System.out.println("\nTest failed: trace[" + i + "].getClassName() returned null");
failed = true;
}
if (frame.getMethodName() == null) {
System.out.println("\nTest failed: trace[" + i + "].getMethodName() returned null");
failed = true;
}
}
} }
private static void doRedefine(Class<?> clazz) throws Exception { private static void doRedefine(Class<?> clazz) throws Exception {

View File

@ -29,4 +29,13 @@ public class RedefineMethodInBacktraceTarget {
public static void methodToRedefine() { public static void methodToRedefine() {
throw new RuntimeException("Test exception"); throw new RuntimeException("Test exception");
} }
public static void callMethodToDelete() {
methodToDelete();
}
private static void methodToDelete() {
throw new RuntimeException("Test exception in methodToDelete");
}
} }

View File

@ -37,4 +37,16 @@ public class RedefineMethodInBacktraceTargetB {
// ignore, test will fail // ignore, test will fail
} }
} }
public static void callMethodToDelete() {
try {
// signal that we are here
RedefineMethodInBacktraceApp.called.countDown();
// wait until test is done
RedefineMethodInBacktraceApp.stop.await();
} catch (InterruptedException ex) {
// ignore, test will fail
}
}
} }

View File

@ -28,4 +28,7 @@
public class RedefineMethodInBacktraceTargetB { public class RedefineMethodInBacktraceTargetB {
public static void methodToRedefine() { public static void methodToRedefine() {
} }
public static void callMethodToDelete() {
}
} }

View File

@ -29,4 +29,8 @@ public class RedefineMethodInBacktraceTarget {
public static void methodToRedefine() { public static void methodToRedefine() {
throw new RuntimeException("Test exception 2"); throw new RuntimeException("Test exception 2");
} }
public static void callMethodToDelete() {
throw new RuntimeException("Test exception 2 in callMethodToDelete");
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2010, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* @bug 5086470 * @bug 5086470
* @key intermittent
* @summary Basic Test for the following methods: * @summary Basic Test for the following methods:
* - ThreadMXBean.findDeadlockedThreads() * - ThreadMXBean.findDeadlockedThreads()
* - ThreadMXBean.findMonitorDeadlockedThreads() * - ThreadMXBean.findMonitorDeadlockedThreads()

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,12 @@
/* /*
* @test * @test
* @bug 5058327 * @bug 5058327 8074368
* @summary Test if getThreadInfo(long[]) returns a ThreadInfo[] * @summary Tests the correct behaviour of getThreadInfo(long[]) for non-existent
* with null elements with no exception. * thread IDs and the empty thread id array.
* *
* @author Mandy Chung * @author Mandy Chung
* @author Jaroslav Bachorik
* *
* @build ThreadInfoArray * @build ThreadInfoArray
* @run main ThreadInfoArray * @run main ThreadInfoArray
@ -35,15 +36,30 @@
import java.lang.management.*; import java.lang.management.*;
import javax.management.*; import javax.management.*;
import java.util.*;
import static java.lang.management.ManagementFactory.*; import static java.lang.management.ManagementFactory.*;
public class ThreadInfoArray { public class ThreadInfoArray {
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
ThreadMXBean proxy = newPlatformMXBeanProxy(mbs,
on.toString(),
ThreadMXBean.class);
checkNullElement(mbean, proxy, mbs, on);
checkEmptyArray(mbean, proxy, mbs, on);
System.out.println("Test passed");
}
private static void checkNullElement(ThreadMXBean mbean, ThreadMXBean proxy,
MBeanServer mbs, ObjectName on)
throws Exception {
System.out.println("--- Check null element");
// ID for a new thread // ID for a new thread
long [] ids = {new Thread().getId()}; long [] ids = {new Thread().getId()};
// direct call
ThreadInfo[] tinfos = mbean.getThreadInfo(ids); ThreadInfo[] tinfos = mbean.getThreadInfo(ids);
if (tinfos[0] != null) { if (tinfos[0] != null) {
@ -52,8 +68,6 @@ public class ThreadInfoArray {
} }
// call getThreadInfo through MBeanServer // call getThreadInfo through MBeanServer
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
Object[] params = {ids}; Object[] params = {ids};
String[] sigs = {"[J"}; String[] sigs = {"[J"};
Object[] result = (Object[]) mbs.invoke(on, "getThreadInfo", params, sigs); Object[] result = (Object[]) mbs.invoke(on, "getThreadInfo", params, sigs);
@ -64,14 +78,57 @@ public class ThreadInfoArray {
} }
// call getThreadInfo through proxy // call getThreadInfo through proxy
ThreadMXBean proxy = newPlatformMXBeanProxy(mbs,
on.toString(),
ThreadMXBean.class);
tinfos = proxy.getThreadInfo(ids); tinfos = proxy.getThreadInfo(ids);
if (tinfos[0] != null) { if (tinfos[0] != null) {
throw new RuntimeException("TEST FAILED: " + throw new RuntimeException("TEST FAILED: " +
"Expected to have a null element"); "Expected to have a null element");
} }
System.out.println("Test passed"); System.out.println("--- PASSED");
}
private static void checkEmptyArray(ThreadMXBean mbean, ThreadMXBean proxy,
MBeanServer mbs, ObjectName on)
throws Exception {
System.out.println("--- Check empty TID array");
long[] ids = new long[0];
// direct call
assertEmptyArray(mbean.getThreadInfo(ids), "Expected empty ThreadInfo array");
assertEmptyArray(mbean.getThreadInfo(ids, 1), "Expected empty ThreadInfo array");
assertEmptyArray(mbean.getThreadInfo(ids, true, true), "Expected empty ThreadInfo array");
// call getThreadInfo through MBeanServer
assertEmptyArray(
(Object[]) mbs.invoke(
on, "getThreadInfo", new Object[]{ids}, new String[]{"[J"}
),
"Expected empty ThreadInfo array via MBeanServer"
);
assertEmptyArray(
(Object[]) mbs.invoke(
on, "getThreadInfo", new Object[]{ids, 1},
new String[]{"[J", "int"}
),
"Expected empty ThreadInfo array via MBeanServer"
);
assertEmptyArray(
(Object[]) mbs.invoke(
on, "getThreadInfo", new Object[]{ids, true, true},
new String[]{"[J", "boolean", "boolean"}
),
"Expected empty ThreadInfo array via MBeanServer"
);
// call getThreadInfo through proxy
assertEmptyArray(proxy.getThreadInfo(ids), "Expected empty ThreadInfo array");
assertEmptyArray(proxy.getThreadInfo(ids, 1), "Expected empty ThreadInfo array");
assertEmptyArray(proxy.getThreadInfo(ids, true, true), "Expected empty ThreadInfo array");
System.out.println("--- PASSED");
}
private static void assertEmptyArray(Object[] arr, String message) throws Exception {
if (arr.length > 0) {
throw new RuntimeException("TEST FAILED: " + message);
}
} }
} }

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -64,60 +64,61 @@ public class ThreadMXBeanStateTest {
Thread.currentThread().getState(); Thread.currentThread().getState();
ThreadStateController thread = new ThreadStateController("StateChanger", globalLock); ThreadStateController thread = new ThreadStateController("StateChanger", globalLock);
thread.setDaemon(true); thread.setDaemon(true);
// before myThread starts
thread.checkThreadState(NEW);
thread.start();
thread.transitionTo(RUNNABLE);
thread.checkThreadState(RUNNABLE);
checkLockInfo(thread, RUNNABLE, null, null);
thread.suspend();
ThreadStateController.pause(10);
thread.checkThreadState(RUNNABLE);
checkSuspendedThreadState(thread, RUNNABLE);
thread.resume();
synchronized (globalLock) {
thread.transitionTo(BLOCKED);
thread.checkThreadState(BLOCKED);
checkLockInfo(thread, BLOCKED,
globalLock, Thread.currentThread());
}
thread.transitionTo(WAITING);
thread.checkThreadState(WAITING);
checkLockInfo(thread, Thread.State.WAITING,
globalLock, null);
thread.transitionTo(TIMED_WAITING);
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING,
globalLock, null);
thread.transitionToPark(true /* timed park */);
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING, null, null);
thread.transitionToPark(false /* indefinite park */);
thread.checkThreadState(WAITING);
checkLockInfo(thread, WAITING, null, null);
thread.transitionToSleep();
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING, null, null);
thread.transitionTo(TERMINATED);
thread.checkThreadState(TERMINATED);
try { try {
System.out.println(thread.getLog()); // before myThread starts
} catch (InterruptedException e) { thread.checkThreadState(NEW);
e.printStackTrace();
System.out.println("TEST FAILED: Unexpected exception."); thread.start();
throw new RuntimeException(e); thread.transitionTo(RUNNABLE);
thread.checkThreadState(RUNNABLE);
checkLockInfo(thread, RUNNABLE, null, null);
thread.suspend();
ThreadStateController.pause(10);
thread.checkThreadState(RUNNABLE);
checkSuspendedThreadState(thread, RUNNABLE);
thread.resume();
synchronized (globalLock) {
thread.transitionTo(BLOCKED);
thread.checkThreadState(BLOCKED);
checkLockInfo(thread, BLOCKED,
globalLock, Thread.currentThread());
}
thread.transitionTo(WAITING);
thread.checkThreadState(WAITING);
checkLockInfo(thread, Thread.State.WAITING,
globalLock, null);
thread.transitionTo(TIMED_WAITING);
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING,
globalLock, null);
thread.transitionToPark(true /* timed park */);
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING, null, null);
thread.transitionToPark(false /* indefinite park */);
thread.checkThreadState(WAITING);
checkLockInfo(thread, WAITING, null, null);
thread.transitionToSleep();
thread.checkThreadState(TIMED_WAITING);
checkLockInfo(thread, TIMED_WAITING, null, null);
thread.transitionTo(TERMINATED);
thread.checkThreadState(TERMINATED);
} finally {
try {
System.out.println(thread.getLog());
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("TEST FAILED: Unexpected exception.");
throw new RuntimeException(e);
}
} }
System.out.println("Test passed."); System.out.println("Test passed.");
} }

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,25 +28,26 @@
* ThreadInfo.getThreadState() * ThreadInfo.getThreadState()
* @author Mandy Chung * @author Mandy Chung
* *
* @run build Semaphore Utils * @run build Utils
* @run main ThreadStackTrace * @run main ThreadStackTrace
*/ */
import java.lang.management.*; import java.lang.management.*;
import java.util.concurrent.Phaser;
public class ThreadStackTrace { public class ThreadStackTrace {
private static ThreadMXBean mbean private static final ThreadMXBean mbean
= ManagementFactory.getThreadMXBean(); = ManagementFactory.getThreadMXBean();
private static boolean notified = false; private static boolean notified = false;
private static Object lockA = new Object(); private static final Object lockA = new Object();
private static Object lockB = new Object(); private static final Object lockB = new Object();
private static volatile boolean testFailed = false; private static volatile boolean testFailed = false;
private static String[] blockedStack = {"run", "test", "A", "B", "C", "D"}; private static final String[] blockedStack = {"run", "test", "A", "B", "C", "D"};
private static int bsDepth = 6; private static final int bsDepth = 6;
private static int methodB = 4; private static final int methodB = 4;
private static String[] examinerStack = {"run", "examine1", "examine2"}; private static final String[] examinerStack = {"run", "examine1", "examine2"};
private static int esDepth = 3; private static final int esDepth = 3;
private static int methodExamine1= 2; private static final int methodExamine1= 2;
private static void checkNullThreadInfo(Thread t) throws Exception { private static void checkNullThreadInfo(Thread t) throws Exception {
ThreadInfo ti = mbean.getThreadInfo(t.getId()); ThreadInfo ti = mbean.getThreadInfo(t.getId());
@ -69,8 +70,10 @@ public class ThreadStackTrace {
trace = true; trace = true;
} }
Examiner examiner = new Examiner("Examiner"); final Phaser p = new Phaser(2);
BlockedThread blocked = new BlockedThread("BlockedThread");
Examiner examiner = new Examiner("Examiner", p);
BlockedThread blocked = new BlockedThread("BlockedThread", p);
examiner.setThread(blocked); examiner.setThread(blocked);
checkNullThreadInfo(examiner); checkNullThreadInfo(examiner);
@ -79,8 +82,8 @@ public class ThreadStackTrace {
// Start the threads and check them in Blocked and Waiting states // Start the threads and check them in Blocked and Waiting states
examiner.start(); examiner.start();
// block until examiner begins doing its real work // #1 - block until examiner begins doing its real work
examiner.waitForStarted(); p.arriveAndAwaitAdvance();
System.out.println("Checking stack trace for the examiner thread " + System.out.println("Checking stack trace for the examiner thread " +
"is waiting to begin."); "is waiting to begin.");
@ -145,35 +148,11 @@ public class ThreadStackTrace {
} }
static class BlockedThread extends Thread { static class BlockedThread extends Thread {
private Semaphore handshake = new Semaphore(); private final Phaser phaser;
BlockedThread(String name) { BlockedThread(String name, Phaser phaser) {
super(name); super(name);
} this.phaser = phaser;
boolean hasWaitersForBlocked() {
return (handshake.getWaiterCount() > 0);
}
void waitUntilBlocked() {
handshake.semaP();
// give a chance for the examiner thread to really wait
Utils.goSleep(20);
}
void waitUntilLockAReleased() {
handshake.semaP();
// give a chance for the examiner thread to really wait
Utils.goSleep(50);
}
private void notifyWaiter() {
// wait until the examiner waits on the semaphore
while (handshake.getWaiterCount() == 0) {
Utils.goSleep(20);
}
handshake.semaV();
} }
private void test() { private void test() {
@ -185,25 +164,24 @@ public class ThreadStackTrace {
private void B() { private void B() {
C(); C();
// notify the examiner about to block on lockB // #4 - notify the examiner about to block on lockB
notifyWaiter(); phaser.arriveAndAwaitAdvance();
synchronized (lockB) { synchronized (lockB) {};
};
} }
private void C() { private void C() {
D(); D();
} }
private void D() { private void D() {
// Notify that examiner about to enter lockA // #2 - Notify that examiner about to enter lockA
notifyWaiter(); phaser.arriveAndAwaitAdvance();
synchronized (lockA) { synchronized (lockA) {
notified = false; notified = false;
while (!notified) { while (!notified) {
try { try {
// notify the examiner about to release lockA // #3 - notify the examiner about to release lockA
notifyWaiter(); phaser.arriveAndAwaitAdvance();
// Wait and let examiner thread check the mbean // Wait and let examiner thread check the mbean
lockA.wait(); lockA.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -216,6 +194,7 @@ public class ThreadStackTrace {
} }
} }
@Override
public void run() { public void run() {
test(); test();
} // run() } // run()
@ -223,28 +202,17 @@ public class ThreadStackTrace {
static class Examiner extends Thread { static class Examiner extends Thread {
private static BlockedThread blockedThread; private static BlockedThread blockedThread;
private Semaphore handshake = new Semaphore(); private final Phaser phaser;
Examiner(String name) { Examiner(String name, Phaser phaser) {
super(name); super(name);
this.phaser = phaser;
} }
public void setThread(BlockedThread thread) { public void setThread(BlockedThread thread) {
blockedThread = thread; blockedThread = thread;
} }
public synchronized void waitForStarted() {
// wait until the examiner is about to block
handshake.semaP();
// wait until the examiner is waiting for blockedThread's notification
while (!blockedThread.hasWaitersForBlocked()) {
Utils.goSleep(50);
}
// give a chance for the examiner thread to really wait
Utils.goSleep(20);
}
private Thread itself; private Thread itself;
private void examine1() { private void examine1() {
synchronized (lockB) { synchronized (lockB) {
@ -254,8 +222,9 @@ public class ThreadStackTrace {
Utils.checkThreadState(itself, Thread.State.RUNNABLE); Utils.checkThreadState(itself, Thread.State.RUNNABLE);
checkStack(itself, examinerStack, methodExamine1); checkStack(itself, examinerStack, methodExamine1);
// wait until blockedThread is blocked on lockB // #4 - wait until blockedThread is blocked on lockB
blockedThread.waitUntilBlocked(); phaser.arriveAndAwaitAdvance();
Utils.waitForThreadState(blockedThread, State.BLOCKED);
System.out.println("Checking stack trace for " + System.out.println("Checking stack trace for " +
"BlockedThread - should be blocked on lockB."); "BlockedThread - should be blocked on lockB.");
@ -271,15 +240,12 @@ public class ThreadStackTrace {
private void examine2() { private void examine2() {
synchronized (lockA) { synchronized (lockA) {
// wait until main thread gets signalled of the semaphore // #1 - examiner ready to do the real work
while (handshake.getWaiterCount() == 0) { phaser.arriveAndAwaitAdvance();
Utils.goSleep(20);
}
handshake.semaV(); // notify the main thread
try { try {
// Wait until BlockedThread is about to block on lockA // #2 - Wait until BlockedThread is about to block on lockA
blockedThread.waitUntilBlocked(); phaser.arriveAndAwaitAdvance();
Utils.waitForThreadState(blockedThread, State.BLOCKED);
System.out.println("Checking examiner's its own stack trace"); System.out.println("Checking examiner's its own stack trace");
Utils.checkThreadState(itself, Thread.State.RUNNABLE); Utils.checkThreadState(itself, Thread.State.RUNNABLE);
@ -297,9 +263,10 @@ public class ThreadStackTrace {
} }
} }
// release lockA and let BlockedThread to get the lock // #3 - release lockA and let BlockedThread to get the lock
// and wait on lockA // and wait on lockA
blockedThread.waitUntilLockAReleased(); phaser.arriveAndAwaitAdvance();
Utils.waitForThreadState(blockedThread, State.WAITING);
synchronized (lockA) { synchronized (lockA) {
try { try {
@ -321,6 +288,7 @@ public class ThreadStackTrace {
Utils.goSleep(50); Utils.goSleep(50);
} // examine2() } // examine2()
@Override
public void run() { public void run() {
itself = Thread.currentThread(); itself = Thread.currentThread();
examine1(); examine1();

View File

@ -227,7 +227,8 @@ public final class ProcessTools {
* <span>The default redirects of STDOUT and STDERR are started</span> * <span>The default redirects of STDOUT and STDERR are started</span>
* <p> * <p>
* It is possible to wait for the process to get to a warmed-up state * It is possible to wait for the process to get to a warmed-up state
* via {@linkplain Predicate} condition on the STDOUT * via {@linkplain Predicate} condition on the STDOUT. The warm-up will
* wait indefinitely.
* </p> * </p>
* @param name The process name * @param name The process name
* @param processBuilder The process builder * @param processBuilder The process builder

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;
}
}
}

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -120,9 +120,7 @@ public class LocalManagementTest {
return true; return true;
} }
return false; return false;
}, }
5,
TimeUnit.SECONDS
); );
System.out.println("Attaching test manager:"); System.out.println("Attaching test manager:");
@ -142,9 +140,7 @@ public class LocalManagementTest {
clientPrc = ProcessTools.startProcess( clientPrc = ProcessTools.startProcess(
"TestManager", "TestManager",
client, client,
(String line) -> line.startsWith("Starting TestManager for PID"), (String line) -> line.startsWith("Starting TestManager for PID")
10,
TimeUnit.SECONDS
); );
int clientExitCode = clientPrc.waitFor(); int clientExitCode = clientPrc.waitFor();

View File

@ -35,20 +35,16 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.management.*; import javax.management.*;
import javax.management.remote.*; import javax.management.remote.*;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import jdk.testlibrary.ProcessTools; import jdk.testlibrary.ProcessTools;
import jdk.testlibrary.JDKToolLauncher;
import sun.management.Agent; import sun.management.Agent;
import sun.management.AgentConfigurationError; import sun.management.AgentConfigurationError;
@ -56,46 +52,20 @@ import sun.management.AgentConfigurationError;
* @test * @test
* @bug 7110104 * @bug 7110104
* @library /lib/testlibrary * @library /lib/testlibrary
* @build jdk.testlibrary.* JMXStartStopTest JMXStartStopDoSomething * @build jdk.testlibrary.* JMXStartStopTest PortAllocator TestApp ManagementAgentJcmd
* @run main/othervm/timeout=600 -XX:+UsePerfData JMXStartStopTest * @run main/othervm/timeout=600 -XX:+UsePerfData JMXStartStopTest
* @summary Makes sure that enabling/disabling the management agent through JCMD * @summary Makes sure that enabling/disabling the management agent through JCMD
* achieves the desired results * achieves the desired results
* @key randomness * @key randomness
*/ */
public class JMXStartStopTest { public class JMXStartStopTest {
private static final String TEST_APP_NAME = "TestApp";
private static final String TEST_SRC = System.getProperty("test.src"); private static final String TEST_SRC = System.getProperty("test.src");
private static final boolean verbose = false; private static final boolean verbose = false;
/** private static ManagementAgentJcmd jcmd = new ManagementAgentJcmd(TEST_APP_NAME, verbose);
* Dynamically allocates distinct ports from the ephemeral range 49152-65535
*/
private static class PortAllocator {
private final static int LOWER_BOUND = 49152;
private final static int UPPER_BOUND = 65535;
private final static Random RND = new Random(System.currentTimeMillis());
private static int[] allocatePorts(final int numPorts) {
int[] ports = new int[numPorts];
for (int i = 0; i < numPorts; i++) {
int port = -1;
while (port == -1) {
port = RND.nextInt(UPPER_BOUND - LOWER_BOUND + 1) + LOWER_BOUND;
for (int j = 0; j < i; j++) {
if (ports[j] == port) {
port = -1;
break;
}
}
}
ports[i] = port;
}
return ports;
}
}
private static void dbg_print(String msg) { private static void dbg_print(String msg) {
if (verbose) { if (verbose) {
@ -318,14 +288,14 @@ public class JMXStartStopTest {
} }
} }
private static class Something { private static class TestAppRun {
private Process p; private Process p;
private final ProcessBuilder pb; private final ProcessBuilder pb;
private final String name; private final String name;
private final AtomicBoolean started = new AtomicBoolean(false); private final AtomicBoolean started = new AtomicBoolean(false);
private volatile long pid = -1; private volatile long pid = -1;
public Something(ProcessBuilder pb, String name) { public TestAppRun(ProcessBuilder pb, String name) {
this.pb = pb; this.pb = pb;
this.name = name; this.name = name;
} }
@ -335,16 +305,14 @@ public class JMXStartStopTest {
try { try {
AtomicBoolean error = new AtomicBoolean(false); AtomicBoolean error = new AtomicBoolean(false);
p = ProcessTools.startProcess( p = ProcessTools.startProcess(
"JMXStartStopDoSomething{" + name + "}", TEST_APP_NAME + "{" + name + "}",
pb, pb,
(line) -> { (line) -> {
boolean ok = line.equals("main enter"); boolean ok = line.equals("main enter");
error.set(line.contains("BindException")); error.set(line.contains("BindException"));
return ok || error.get(); return ok || error.get();
}, }
5,
TimeUnit.SECONDS
); );
if (error.get()) { if (error.get()) {
throw new BindException("Starting process failed due to " + throw new BindException("Starting process failed due to " +
@ -352,8 +320,10 @@ public class JMXStartStopTest {
} }
pid = p.getPid(); pid = p.getPid();
} catch (TimeoutException e) { } catch (TimeoutException e) {
p.destroy(); if (p != null) {
p.waitFor(); p.destroy();
p.waitFor();
}
throw e; throw e;
} }
} }
@ -382,105 +352,32 @@ public class JMXStartStopTest {
} }
/** /**
* Runs the test application "JMXStartStopDoSomething" * Runs the test application "TestApp"
* @param name Test run name * @param name Test run name
* @param args Additional arguments * @param args Additional arguments
* @return Returns a {@linkplain Something} instance representing the run * @return Returns a {@linkplain TestAppRun} instance representing the run
* @throws IOException * @throws IOException
* @throws InterruptedException * @throws InterruptedException
* @throws TimeoutException * @throws TimeoutException
*/ */
private static Something doSomething(String name, String ... args) private static TestAppRun doTest(String name, String ... args)
throws Exception { throws Exception {
List<String> pbArgs = new ArrayList<>(Arrays.asList( List<String> pbArgs = new ArrayList<>(Arrays.asList(
"-cp", "-cp",
System.getProperty("test.class.path") System.getProperty("test.class.path"),
"-XX:+UsePerfData"
)); ));
pbArgs.addAll(Arrays.asList(args)); pbArgs.addAll(Arrays.asList(args));
pbArgs.add("JMXStartStopDoSomething"); pbArgs.add(TEST_APP_NAME);
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
pbArgs.toArray(new String[pbArgs.size()]) pbArgs.toArray(new String[pbArgs.size()])
); );
Something s = new Something(pb, name); TestAppRun s = new TestAppRun(pb, name);
s.start(); s.start();
return s; return s;
} }
/**
* Run the "jcmd" command
*
* @param command Command with parameters; space separated string
* @throws IOException
* @throws InterruptedException
*/
private static void jcmd(String ... command) throws IOException, InterruptedException {
if (command.length == 0) {
jcmd(null, c->{});
} else {
jcmd(null, command);
}
}
/**
* Run the "jcmd" command
*
* @param c {@linkplain Consumer} instance
* @param command Command with parameters; space separated string
* @throws IOException
* @throws InterruptedException
*/
private static void jcmd(Consumer<String> c, String ... command) throws IOException, InterruptedException {
jcmd("JMXStartStopDoSomething", c, command);
}
/**
* Run the "jcmd" command
*
* @param target The target application name (or PID)
* @param c {@linkplain Consumer} instance
* @param command Command with parameters; space separated string
* @throws IOException
* @throws InterruptedException
*/
private static void jcmd(String target, final Consumer<String> c, String ... command) throws IOException, InterruptedException {
dbg_print("[jcmd] " + (command.length > 0 ? command[0] : "list"));
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jcmd");
l.addToolArg(target);
for (String cmd : command) {
l.addToolArg(cmd);
}
AtomicBoolean portUnavailable = new AtomicBoolean(false);
Process p = ProcessTools.startProcess(
"jcmd",
new ProcessBuilder(l.getCommand()),
line -> {
if (line.contains("BindException") ||
line.contains(Agent.getText(AgentConfigurationError.CONNECTOR_SERVER_IO_ERROR))) {
portUnavailable.set(true);
} else {
c.accept(line);
}
}
);
p.waitFor();
dbg_print("[jcmd] --------");
if (portUnavailable.get()) {
String cmd = Arrays.asList(l.getCommand()).stream()
.collect(
Collectors.joining(" ", "", ": Unable to bind address")
);
throw new BindException(cmd);
}
}
private static final String CMD_STOP = "ManagementAgent.stop";
private static final String CMD_START = "ManagementAgent.start";
private static final String CMD_START_LOCAL = "ManagementAgent.start_local";
static void test_01() throws Exception { static void test_01() throws Exception {
// Run an app with JMX enabled stop it and // Run an app with JMX enabled stop it and
// restart on other port // restart on other port
@ -488,7 +385,7 @@ public class JMXStartStopTest {
System.out.println("**** Test one ****"); System.out.println("**** Test one ****");
int ports[] = PortAllocator.allocatePorts(2); int ports[] = PortAllocator.allocatePorts(2);
Something s = doSomething( TestAppRun s = doTest(
"test_01", "test_01",
"-Dcom.sun.management.jmxremote.port=" + ports[0], "-Dcom.sun.management.jmxremote.port=" + ports[0],
"-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.authenticate=false",
@ -497,10 +394,10 @@ public class JMXStartStopTest {
try { try {
testConnect(ports[0]); testConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_START, "jmxremote.port=" + ports[1]); jcmd.start("jmxremote.port=" + ports[1]);
testConnect(ports[1]); testConnect(ports[1]);
} finally { } finally {
s.stop(); s.stop();
@ -514,12 +411,13 @@ public class JMXStartStopTest {
System.out.println("**** Test two ****"); System.out.println("**** Test two ****");
int[] ports = PortAllocator.allocatePorts(1); int[] ports = PortAllocator.allocatePorts(1);
Something s = doSomething("test_02"); TestAppRun s = doTest("test_02");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
testConnect(ports[0]); testConnect(ports[0]);
} finally { } finally {
@ -535,18 +433,20 @@ public class JMXStartStopTest {
System.out.println("**** Test three ****"); System.out.println("**** Test three ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_03"); TestAppRun s = doTest("test_03");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
// Second agent shouldn't start // Second agent shouldn't start
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[1], "jmxremote.port=" + ports[1],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
// First agent should connect // First agent should connect
testConnect(ports[0]); testConnect(ports[0]);
@ -565,13 +465,14 @@ public class JMXStartStopTest {
System.out.println("**** Test four ****"); System.out.println("**** Test four ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_04"); TestAppRun s = doTest("test_04");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.rmi.port=" + ports[1], "jmxremote.rmi.port=" + ports[1],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
testConnect(ports[0], ports[1]); testConnect(ports[0], ports[1]);
} finally { } finally {
@ -585,9 +486,9 @@ public class JMXStartStopTest {
System.out.println("**** Test five ****"); System.out.println("**** Test five ****");
int[] ports = PortAllocator.allocatePorts(1); int[] ports = PortAllocator.allocatePorts(1);
Something s = doSomething("test_05"); TestAppRun s = doTest("test_05");
try { try {
jcmd(CMD_START_LOCAL); jcmd.startLocal();
testNoConnect(ports[0]); testNoConnect(ports[0]);
testConnectLocal(s.getPid()); testConnectLocal(s.getPid());
@ -605,26 +506,27 @@ public class JMXStartStopTest {
System.out.println("**** Test six ****"); System.out.println("**** Test six ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_06"); TestAppRun s = doTest("test_06");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
testConnect(ports[0], ports[1]); testConnect(ports[0], ports[1]);
final AtomicBoolean checks = new AtomicBoolean(false); final AtomicBoolean checks = new AtomicBoolean(false);
jcmd( jcmd.start(
line -> { line -> {
if (line.contains("java.lang.RuntimeException: Invalid agent state")) { if (line.contains("java.lang.RuntimeException: Invalid agent state")) {
checks.set(true); checks.set(true);
} }
}, },
CMD_START, "jmxremote.port=" + ports[0],
"jmxremote.port=" + ports[0], "jmxremote.authenticate=false",
"jmxremote.authenticate=false", "jmxremote.ssl=false"
"jmxremote.ssl=false"); );
if (!checks.get()) { if (!checks.get()) {
throw new Exception("Starting agent on port " + ports[0] + " should " throw new Exception("Starting agent on port " + ports[0] + " should "
@ -644,27 +546,28 @@ public class JMXStartStopTest {
System.out.println("**** Test seven ****"); System.out.println("**** Test seven ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_07"); TestAppRun s = doTest("test_07");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
testConnect(ports[0], ports[1]); testConnect(ports[0], ports[1]);
final AtomicBoolean checks = new AtomicBoolean(false); final AtomicBoolean checks = new AtomicBoolean(false);
jcmd( jcmd.start(
line -> { line -> {
if (line.contains("java.lang.RuntimeException: Invalid agent state")) { if (line.contains("java.lang.RuntimeException: Invalid agent state")) {
checks.set(true); checks.set(true);
} }
}, },
CMD_START, "jmxremote.port=" + ports[1],
"jmxremote.port=" + ports[1], "jmxremote.authenticate=false",
"jmxremote.authenticate=false", "jmxremote.ssl=false"
"jmxremote.ssl=false"); );
if (!checks.get()) { if (!checks.get()) {
throw new Exception("Starting agent on poprt " + ports[1] + " should " throw new Exception("Starting agent on poprt " + ports[1] + " should "
@ -684,17 +587,18 @@ public class JMXStartStopTest {
System.out.println("**** Test eight ****"); System.out.println("**** Test eight ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_08"); TestAppRun s = doTest("test_08");
try { try {
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false"
);
testConnect(ports[0], ports[1]); testConnect(ports[0], ports[1]);
jcmd(CMD_STOP); jcmd.stop();
jcmd(CMD_STOP); jcmd.stop();
} finally { } finally {
s.stop(); s.stop();
} }
@ -707,7 +611,7 @@ public class JMXStartStopTest {
System.out.println("**** Test nine ****"); System.out.println("**** Test nine ****");
Something s = doSomething("test_09"); TestAppRun s = doTest("test_09");
try (ServerSocket ss = new ServerSocket(0)) { try (ServerSocket ss = new ServerSocket(0)) {
int localPort = ss.getLocalPort(); int localPort = ss.getLocalPort();
@ -723,13 +627,12 @@ public class JMXStartStopTest {
final AtomicBoolean retry = new AtomicBoolean(false); final AtomicBoolean retry = new AtomicBoolean(false);
try { try {
jcmd( jcmd.start(
line -> { line -> {
if (line.contains(Agent.getText(AgentConfigurationError.AGENT_EXCEPTION))) { if (line.contains(Agent.getText(AgentConfigurationError.AGENT_EXCEPTION))) {
retry.set(true); retry.set(true);
} }
}, },
CMD_START,
"jmxremote.port=" + ports[0], "jmxremote.port=" + ports[0],
"jmxremote.rmi.port=" + localPort, "jmxremote.rmi.port=" + localPort,
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
@ -764,18 +667,17 @@ public class JMXStartStopTest {
System.out.println("**** Test ten ****"); System.out.println("**** Test ten ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething( TestAppRun s = doTest(
"test_10", "test_10",
"-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.ssl=true"); "-Dcom.sun.management.jmxremote.ssl=true");
try { try {
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd( jcmd.start(
CMD_START, "jmxremote.port=" + ports[1],
"jmxremote.port=" + ports[1], "jmxremote.authenticate=false",
"jmxremote.authenticate=false", "jmxremote.ssl=false"
"jmxremote.ssl=false"
); );
testConnect(ports[1]); testConnect(ports[1]);
} finally { } finally {
@ -791,7 +693,7 @@ public class JMXStartStopTest {
System.out.println("**** Test eleven ****"); System.out.println("**** Test eleven ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething( TestAppRun s = doTest(
"test_11", "test_11",
"-Dcom.sun.management.jmxremote.port=" + ports[0], "-Dcom.sun.management.jmxremote.port=" + ports[0],
"-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.authenticate=false",
@ -800,15 +702,14 @@ public class JMXStartStopTest {
try { try {
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd( jcmd.start(
CMD_START, "jmxremote.port=" + ports[1],
"jmxremote.port=" + ports[1], "jmxremote.authenticate=false",
"jmxremote.authenticate=false", "jmxremote.ssl=false"
"jmxremote.ssl=false"
); );
testConnect(ports[1]); testConnect(ports[1]);
@ -828,7 +729,7 @@ public class JMXStartStopTest {
System.out.println("**** Test twelve ****"); System.out.println("**** Test twelve ****");
int[] ports = PortAllocator.allocatePorts(2); int[] ports = PortAllocator.allocatePorts(2);
Something s = doSomething("test_12", TestAppRun s = doTest("test_12",
"-Dcom.sun.management.config.file=" "-Dcom.sun.management.config.file="
+ TEST_SRC + File.separator + "management_cl.properties", + TEST_SRC + File.separator + "management_cl.properties",
"-Dcom.sun.management.jmxremote.authenticate=false" "-Dcom.sun.management.jmxremote.authenticate=false"
@ -837,15 +738,15 @@ public class JMXStartStopTest {
try { try {
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_START, jcmd.start(
"config.file=" + TEST_SRC + File.separator "config.file=" + TEST_SRC + File.separator
+ "management_jcmd.properties", + "management_jcmd.properties",
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.port=" + ports[1] "jmxremote.port=" + ports[1]
); );
testConnect(ports[1]); testConnect(ports[1]);
@ -863,7 +764,7 @@ public class JMXStartStopTest {
System.out.println("**** Test thirteen ****"); System.out.println("**** Test thirteen ****");
int[] ports = PortAllocator.allocatePorts(1); int[] ports = PortAllocator.allocatePorts(1);
Something s = doSomething( TestAppRun s = doTest(
"test_13", "test_13",
"-Dcom.sun.management.jmxremote.port=" + ports[0], "-Dcom.sun.management.jmxremote.port=" + ports[0],
"-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.authenticate=false",
@ -872,16 +773,16 @@ public class JMXStartStopTest {
try { try {
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
jcmd(CMD_START, jcmd.start(
"jmxremote.ssl=false", "jmxremote.ssl=false",
"jmxremote.port=" + ports[0] "jmxremote.port=" + ports[0]
); );
testConnect(ports[0]); testConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
jcmd(CMD_START, jcmd.start(
"jmxremote.port=" + ports[0] "jmxremote.port=" + ports[0]
); );
testNoConnect(ports[0]); testNoConnect(ports[0]);
@ -897,14 +798,14 @@ public class JMXStartStopTest {
System.out.println("**** Test fourteen ****"); System.out.println("**** Test fourteen ****");
int[] ports = PortAllocator.allocatePorts(1); int[] ports = PortAllocator.allocatePorts(1);
Something s = doSomething( TestAppRun s = doTest(
"test_14", "test_14",
"-Dcom.sun.management.jmxremote.port=" + ports[0], "-Dcom.sun.management.jmxremote.port=" + ports[0],
"-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.ssl=false"); "-Dcom.sun.management.jmxremote.ssl=false");
try { try {
testConnect(ports[0]); testConnect(ports[0]);
jcmd(CMD_STOP); jcmd.stop();
testConnectLocal(s.getPid()); testConnectLocal(s.getPid());
} finally { } finally {
s.stop(); s.stop();
@ -918,11 +819,11 @@ public class JMXStartStopTest {
System.out.println("**** Test fifteen ****"); System.out.println("**** Test fifteen ****");
int[] ports = PortAllocator.allocatePorts(1); int[] ports = PortAllocator.allocatePorts(1);
Something s = doSomething("test_15"); TestAppRun s = doTest("test_15");
try { try {
testNoConnect(ports[0]); testNoConnect(ports[0]);
jcmd(CMD_START + "_local"); jcmd.startLocal();
testConnectLocal(s.getPid()); testConnectLocal(s.getPid());

View File

@ -0,0 +1,150 @@
/*
* 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.net.BindException;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import jdk.testlibrary.ProcessTools;
/**
* @test
* @bug 8023093
* @summary Performs a sanity test for the ManagementAgent.status diagnostic command.
* Management agent may be disable, started (only local connections) and started.
* The test asserts that the expected text is being printed.
* @library /lib/testlibrary
* @build jdk.testlibrary.* PortAllocator TestApp ManagementAgentJcmd
* @run testng/othervm -XX:+UsePerfData JMXStatusTest
*/
public class JMXStatusTest {
private final static String TEST_APP_NAME = "TestApp";
private final static Pattern DISABLE_AGENT_STATUS = Pattern.compile(
"Agent\\s*\\: disabled$"
);
private final static Pattern LOCAL_AGENT_STATUS = Pattern.compile(
"Agent\\s*\\:\\s*enabled\\n+" +
"Connection Type\\s*\\:\\s*local\\n+" +
"Protocol\\s*\\:\\s*[a-z]+\\n+" +
"Host\\s*\\:\\s*.+\\n+" +
"URL\\s*\\:\\s*service\\:jmx\\:.+",
Pattern.MULTILINE
);
private final static Pattern REMOTE_AGENT_STATUS = Pattern.compile(
"Agent\\s*\\: enabled\\n+" +
"Connection Type\\s*\\: remote\\n+" +
"Protocol\\s*\\: [a-z]+\\n+" +
"Host\\s*\\: .+\\n+" +
"URL\\s*\\: service\\:jmx\\:.+\\n+" +
"Properties\\s*\\:\\n+(\\s*\\S+\\s*=\\s*\\S+\\n*)+",
Pattern.MULTILINE
);
private static ProcessBuilder testAppPb;
private Process testApp;
private ManagementAgentJcmd jcmd;
@BeforeClass
public static void setupClass() throws Exception {
testAppPb = ProcessTools.createJavaProcessBuilder(
"-cp", System.getProperty("test.class.path"),
"-XX:+UsePerfData",
TEST_APP_NAME
);
}
@BeforeTest
public void setup() {
jcmd = new ManagementAgentJcmd(TEST_APP_NAME, false);
}
@BeforeMethod
public void startTestApp() throws Exception {
testApp = ProcessTools.startProcess(
TEST_APP_NAME, testAppPb,
(Predicate<String>)l->l.trim().equals("main enter")
);
}
@AfterMethod
public void stopTestApp() throws Exception {
testApp.getOutputStream().write(1);
testApp.getOutputStream().flush();
testApp.waitFor();
testApp = null;
}
@Test
public void testAgentDisabled() throws Exception {
String status = jcmd.status();
assertStatusMatches(DISABLE_AGENT_STATUS, status);
}
@Test
public void testAgentLocal() throws Exception {
jcmd.startLocal();
String status = jcmd.status();
assertStatusMatches(LOCAL_AGENT_STATUS, status);
}
@Test
public void testAgentRemote() throws Exception {
while (true) {
try {
int[] ports = PortAllocator.allocatePorts(1);
jcmd.start(
"jmxremote.port=" + ports[0],
"jmxremote.authenticate=false",
"jmxremote.ssl=false"
);
String status = jcmd.status();
assertStatusMatches(REMOTE_AGENT_STATUS, status);
return;
} catch (BindException e) {
System.out.println("Failed to allocate ports. Retrying ...");
}
}
}
private void assertStatusMatches(Pattern expected, String value) {
assertStatusMatches(expected, value, "");
}
private void assertStatusMatches(Pattern expected, String value, String msg) {
int idx = value.indexOf('\n');
if (idx > -1) {
value = value.substring(idx + 1).trim();
assertTrue(expected.matcher(value).find(), msg);
} else {
fail("The management agent status must contain more then one line of text");
}
}
}

View File

@ -0,0 +1,198 @@
/*
* 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.io.IOException;
import java.net.BindException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import sun.management.Agent;
import sun.management.AgentConfigurationError;
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.ProcessTools;
/**
* A helper class for issuing ManagementAgent.* diagnostic commands and capturing
* their output.
*/
final class ManagementAgentJcmd {
private static final String CMD_STOP = "ManagementAgent.stop";
private static final String CMD_START = "ManagementAgent.start";
private static final String CMD_START_LOCAL = "ManagementAgent.start_local";
private static final String CMD_STATUS = "ManagementAgent.status";
private final String id;
private final boolean verbose;
public ManagementAgentJcmd(String targetApp, boolean verbose) {
this.id = targetApp;
this.verbose = verbose;
}
/**
* `jcmd`
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
public String list() throws IOException, InterruptedException {
return jcmd();
}
/**
* `jcmd <app> ManagementAgent.stop`
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
public String stop() throws IOException, InterruptedException {
return jcmd(CMD_STOP);
}
/**
* `jcmd <app> ManagementAgent.start_local`
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
public String startLocal() throws IOException, InterruptedException {
return jcmd(CMD_START_LOCAL);
}
/**
* `jcmd <app> ManagementAgent.start <args>`
* @return The JCMD output
* @param params The arguments to <b>ManagementAgent.start</b> command
* @throws IOException
* @throws InterruptedException
*/
public String start(String ... params) throws IOException, InterruptedException {
return start(c->{}, params);
}
/**
* `jcmd <pp> ManagementAgent.start <args>`
* @param c A string consumer used to inspect the jcmd output line-by-line
* @param params The arguments to <b>ManagementAgent.start</b> command
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
public String start(Consumer<String> c, String ... params) throws IOException, InterruptedException {
List<String> args = new ArrayList<>();
args.add(CMD_START);
args.addAll(Arrays.asList(params));
return jcmd(c, args.toArray(new String[args.size()]));
}
public String status() throws IOException, InterruptedException {
return jcmd(CMD_STATUS);
}
/**
* Run the "jcmd" command
*
* @param command Command + arguments
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
private String jcmd(String ... command) throws IOException, InterruptedException {
if (command.length == 0) {
return jcmd(null, c->{});
} else {
return jcmd(c->{}, command);
}
}
/**
* Run the "jcmd" command
*
* @param c {@linkplain Consumer} instance
* @param command Command + arguments
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
private String jcmd(Consumer<String> c, String ... command) throws IOException, InterruptedException {
return jcmd(id, c, command);
}
/**
* Run the "jcmd" command
*
* @param target The target application name (or PID)
* @param c {@linkplain Consumer} instance
* @param command Command + arguments
* @return The JCMD output
* @throws IOException
* @throws InterruptedException
*/
private String jcmd(String target, final Consumer<String> c, String ... command) throws IOException, InterruptedException {
dbg_print("[jcmd] " + (command.length > 0 ? command[0] : "list"));
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jcmd");
l.addToolArg(target);
for (String cmd : command) {
l.addToolArg(cmd);
}
StringBuilder output = new StringBuilder();
AtomicBoolean portUnavailable = new AtomicBoolean(false);
Process p = ProcessTools.startProcess(
"jcmd",
new ProcessBuilder(l.getCommand()),
line -> {
if (line.contains("BindException") ||
line.contains(Agent.getText(AgentConfigurationError.CONNECTOR_SERVER_IO_ERROR))) {
portUnavailable.set(true);
} else {
output.append(line).append('\n');
c.accept(line);
}
}
);
p.waitFor();
dbg_print("[jcmd] --------");
if (portUnavailable.get()) {
String cmd = Arrays.asList(l.getCommand()).stream()
.collect(
Collectors.joining(" ", "", ": Unable to bind address")
);
throw new BindException(cmd);
}
return output.toString();
}
private void dbg_print(String msg) {
if (verbose) {
System.out.println("DBG: " + msg);
}
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,54 +21,32 @@
* questions. * questions.
*/ */
/* import java.util.Random;
* @bug 4530538
* @summary A semaphore utility class. /**
* @author Mandy Chung * Dynamically allocates distinct ports from the ephemeral range 49152-65535
*/ */
class PortAllocator {
private final static int LOWER_BOUND = 49152;
private final static int UPPER_BOUND = 65535;
public class Semaphore { private final static Random RND = new Random(System.currentTimeMillis());
private Object go = new Object();
private int semaCount;
private int waiters = 0;
public Semaphore() { static int[] allocatePorts(final int numPorts) {
semaCount = 0; int[] ports = new int[numPorts];
} for (int i = 0; i < numPorts; i++) {
int port = -1;
public Semaphore(int initialCount) { while (port == -1) {
semaCount = initialCount; port = RND.nextInt(UPPER_BOUND - LOWER_BOUND + 1) + LOWER_BOUND;
} for (int j = 0; j < i; j++) {
if (ports[j] == port) {
public void semaP() { port = -1;
synchronized (go) { break;
waiters++; }
while (semaCount == 0) {
try {
go.wait();
} catch (InterruptedException e) {
e.printStackTrace();
throw new InternalError();
} }
} }
semaCount--; ports[i] = port;
waiters--;
} }
} return ports;
public void semaV() {
synchronized (go) {
semaCount++;
go.notify();
}
}
public int getWaiterCount() {
synchronized (go) {
return waiters;
}
}
public Object getLock() {
return go;
} }
} }

View File

@ -4,7 +4,7 @@
on host 1 on host 1
4. run 4. run
${TESTJAVA}/bin/java -server JMXStartStopDoSomething \ ${TESTJAVA}/bin/java -server TestApp \
-Dcom.sun.management.jmxremote.port=50234 \ -Dcom.sun.management.jmxremote.port=50234 \
-Dcom.sun.management.jmxremote.rmi.port=50235 \ -Dcom.sun.management.jmxremote.rmi.port=50235 \
-Dcom.sun.management.jmxremote.authenticate=false \ -Dcom.sun.management.jmxremote.authenticate=false \

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,9 +22,8 @@
*/ */
import java.io.IOException; import java.io.IOException;
import jdk.testlibrary.ProcessTools;
public class JMXStartStopDoSomething { public class TestApp {
public static void doSomething() throws IOException{ public static void doSomething() throws IOException{
int r = System.in.read(); int r = System.in.read();
System.out.println("read: " + r); System.out.println("read: " + r);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,10 +23,8 @@
* questions. * questions.
*/ */
import sun.management.ManagementFactoryHelper; import java.lang.management.ManagementFactory;
import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.HotSpotDiagnosticMXBean;
import jdk.testlibrary.OutputAnalyzer; import jdk.testlibrary.OutputAnalyzer;
import static jdk.testlibrary.Platform.isSolaris; import static jdk.testlibrary.Platform.isSolaris;
import static jdk.testlibrary.Asserts.assertEquals; import static jdk.testlibrary.Asserts.assertEquals;
@ -114,13 +112,15 @@ public class JInfoRunningProcessFlagTest {
} }
private static void verifyIsEnabled(String flag) { private static void verifyIsEnabled(String flag) {
HotSpotDiagnosticMXBean hotspotDiagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); HotSpotDiagnosticMXBean hotspotDiagnostic =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
String flagValue = hotspotDiagnostic.getVMOption(flag).getValue(); String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
assertEquals(flagValue, "true", "Expected '" + flag + "' flag be enabled"); assertEquals(flagValue, "true", "Expected '" + flag + "' flag be enabled");
} }
private static void verifyIsDisabled(String flag) { private static void verifyIsDisabled(String flag) {
HotSpotDiagnosticMXBean hotspotDiagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); HotSpotDiagnosticMXBean hotspotDiagnostic =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
String flagValue = hotspotDiagnostic.getVMOption(flag).getValue(); String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
assertEquals(flagValue, "false", "Expected '" + flag + "' flag be disabled"); assertEquals(flagValue, "false", "Expected '" + flag + "' flag be disabled");
} }

Some files were not shown because too many files have changed in this diff Show More