OpenJDK / jdk-updates / jdk12u
changeset 369:640d1cdd140f
Merge
author | kamg |
---|---|
date | Wed, 23 Apr 2008 06:35:28 -0400 |
parents | 61dbce75b71d 5ae7db536e3f |
children | 6969999e4e7b ec5fd25a5edf |
files | hotspot/make/hotspot_version hotspot/src/share/vm/opto/memnode.cpp hotspot/src/share/vm/opto/memnode.hpp hotspot/src/share/vm/opto/node.cpp hotspot/src/share/vm/opto/node.hpp |
diffstat | 319 files changed, 14707 insertions(+), 9124 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ 1cc8dd79fd1cd13d36b385196271a29632c67c3b jdk7-b24 +bf2517e15f0c0f950e5b3143c4ca11e2df73dcc1 jdk7-b25
--- a/.hgtags-top-repo Fri Apr 18 07:51:43 2008 -0400 +++ b/.hgtags-top-repo Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ cfeea66a3fa8ca3686a7cfa2d0ce8ab0169f168d jdk7-b24 +cbc8ad9dd0e085a607427ea35411990982f19a36 jdk7-b25
--- a/corba/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/corba/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ 55540e827aef970ecc010b7e06b912d991c8e3ce jdk7-b24 +5e61d5df62586474414d1058e9186441aa908f51 jdk7-b25
--- a/hotspot/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/hotspot/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ a61af66fc99eb5ec9d50c05b0c599757b1289ceb jdk7-b24 +7836be3e92d0a4f9ee7566f602c91f5609534e66 jdk7-b25
--- a/jaxp/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/jaxp/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ 6ce5f4757bde08f7470cbb9f0b46da8f2f3d4f56 jdk7-b24 +a3b3ba7d6034dc754b51ddc3d281399ac1cae5f1 jdk7-b25
--- a/jaxws/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/jaxws/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ 0961a4a211765fea071b8dac419003ee0c3d5973 jdk7-b24 +59fd8224ba2da5c2d8d4c68e33cf33ab41ce8de0 jdk7-b25
--- a/jdk/.hgtags Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/.hgtags Wed Apr 23 06:35:28 2008 -0400 @@ -1,1 +1,2 @@ 37a05a11f281b4d238e2f9e7ebb67c63f64d0e77 jdk7-b24 +75fca0b0ab83ab1392e615910cea020f66535390 jdk7-b25
--- a/jdk/make/com/sun/crypto/provider/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/com/sun/crypto/provider/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2007-2008 Sun Microsystems, Inc. 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 @@ -87,8 +87,7 @@ # sign Alias for sign-jar # sign-jar Builds/signs sunjce_provider.jar (no install) # -# obfus Builds/obfuscates/signs/installs -# sunjce_provider.jar +# obfus Builds/obfuscates/signs sunjce_provider.jar # # release Builds all targets in preparation # for workspace integration. @@ -101,8 +100,25 @@ BUILDDIR = ../../../.. PACKAGE = com.sun.crypto.provider PRODUCT = sun + +# +# The following is for when we need to do postprocessing +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR +# isn't writable, the build currently crashes out. +# +ifndef OPENJDK + ifdef ALT_JCE_BUILD_DIR + # ===================================================== + # Where to place the output, in case we're building from a read-only + # build area. (e.g. a release engineering build.) + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR} + IGNORE_WRITABLE_OUTPUTDIR_TEST=true + else + JCE_BUILD_DIR=${TEMPDIR} + endif +endif + include $(BUILDDIR)/common/Defs.gmk -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk # # Location for the newly built classfiles. @@ -147,6 +163,8 @@ # UNSIGNED_DIR = $(TEMPDIR)/unsigned +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk + # ===================================================== # Build the unsigned sunjce_provider.jar file. @@ -184,44 +202,66 @@ # Sign the provider jar file. Not needed for OpenJDK. # -SIGNED_DIR = $(TEMPDIR)/signed +SIGNED_DIR = $(JCE_BUILD_DIR)/signed sign: sign-jar sign-jar: $(SIGNED_DIR)/sunjce_provider.jar +ifndef ALT_JCE_BUILD_DIR $(SIGNED_DIR)/sunjce_provider.jar: $(UNSIGNED_DIR)/sunjce_provider.jar - $(sign-file) +else +# +# We have to remove the build dependency, otherwise, we'll try to rebuild it +# which we can't do on a read-only filesystem. +# +$(SIGNED_DIR)/sunjce_provider.jar: + @if [ ! -r $(UNSIGNED_DIR)/sunjce_provider.jar ] ; then \ + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunjce_provider.jar"; \ + exit 1; \ + fi +endif + $(call sign-file, $(UNSIGNED_DIR)/sunjce_provider.jar) # ===================================================== # Obfuscate/sign/install the JDK build. Not needed for OpenJDK. # -OBFUS_DIR = $(TEMPDIR)/obfus +OBFUS_DIR = $(JCE_BUILD_DIR)/obfus/sunjce CLOSED_DIR = $(BUILDDIR)/closed/com/sun/crypto/provider obfus: $(OBFUS_DIR)/sunjce_provider.jar $(release-warning) -$(OBFUS_DIR)/sunjce_provider.jar: build-jar $(JCE_MANIFEST_FILE) +ifndef ALT_JCE_BUILD_DIR +$(OBFUS_DIR)/sunjce_provider.jar: build-jar $(JCE_MANIFEST_FILE) \ + $(OBFUS_DIR)/sunjce.dox +else +$(OBFUS_DIR)/sunjce_provider.jar: $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/sunjce.dox + @if [ ! -d $(CLASSDESTDIR) ] ; then \ + $(ECHO) "Couldn't find $(CLASSDESTDIR)"; \ + exit 1; \ + fi +endif + @$(ECHO) ">>>Obfuscating SunJCE Provider..." $(presign) $(preobfus) - @$(ECHO) ">>>Obfuscating Sun JCE Provider..." $(prep-target) $(CD) $(OBFUS_DIR); \ - $(OBFUSCATOR) -fv \ - $(CURRENT_DIRECTORY)/$(CLOSED_DIR)/obfus/sunjce.dox + $(OBFUSCATOR) -fv sunjce.dox @$(CD) $(OBFUS_DIR); $(java-vm-cleanup) $(BOOT_JAR_CMD) cmf $(JCE_MANIFEST_FILE) $@ \ -C $(OBFUS_DIR)/build com \ $(JAR_JFLAGS) $(sign-target) - $(MKDIR) -p $(dir $(JAR_DESTFILE)) - $(RM) $(JAR_DESTFILE) - $(CP) $@ $(JAR_DESTFILE) @$(java-vm-cleanup) +$(OBFUS_DIR)/sunjce.dox: $(CLOSED_DIR)/obfus/sunjce.dox + @$(ECHO) ">>>Creating sunjce.dox" + $(prep-target) + $(SED) "s:@@TEMPDIR@@:$(ABS_TEMPDIR):" $< > $@ + # # The current obfuscator has a limitation in that it currently only # supports up to v49 class file format. Force v49 classfiles in our @@ -235,9 +275,9 @@ # release: $(OBFUS_DIR)/sunjce_provider.jar - $(RM) $(RELEASE_DIR)/sunjce_provider.jar - $(MKDIR) -p $(RELEASE_DIR) - $(CP) $(OBFUS_DIR)/sunjce_provider.jar $(RELEASE_DIR) + $(RM) $(JCE_BUILD_DIR)/release/sunjce_provider.jar + $(MKDIR) -p $(JCE_BUILD_DIR)/release + $(CP) $(OBFUS_DIR)/sunjce_provider.jar $(JCE_BUILD_DIR)/release $(release-warning) endif # OPENJDK @@ -275,7 +315,7 @@ # clobber clean:: - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR) .PHONY: build-jar jar install-jar ifndef OPENJDK
--- a/jdk/make/common/Defs.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/Defs.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -303,6 +303,8 @@ # for build tool jar files BUILDTOOLJARDIR = $(OUTPUTDIR)/btjars ABS_BUILDTOOLJARDIR = $(ABS_OUTPUTDIR)/btjars +# for generated tool class files +BUILDTOOLBINDIR = $(OUTPUTDIR)/btbins # for generated java source files GENSRCDIR = $(OUTPUTDIR)/gensrc # for generated C source files (not javah)
--- a/jdk/make/common/Rules.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/Rules.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -231,12 +231,14 @@ .compile.classlist : $(JAVA_SOURCE_LIST) @$(MKDIR) -p $(CLASSDESTDIR) - @if [ `$(CAT) $(JAVA_SOURCE_LIST) | $(WC) -l` -ge 1 ] ; then \ - $(ECHO) "# Java sources to be compiled: (listed in file $(JAVA_SOURCE_LIST))"; \ - $(CAT) $(JAVA_SOURCE_LIST); \ + @$(RM) $<.filtered + @$(CAT) $< | $(NAWK) 'length>0' | $(SORT) -u > $<.filtered + @if [ `$(CAT) $<.filtered | $(WC) -l` -ge 1 ] ; then \ + $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \ + $(CAT) $<.filtered; \ $(ECHO) "# Running javac:"; \ - $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \ - $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \ + $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \ + $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \ fi @$(java-vm-cleanup)
--- a/jdk/make/common/shared/Compiler-gcc.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/shared/Compiler-gcc.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -45,10 +45,8 @@ NMAKE = MFLAGS= MAKEFLAGS= $(COMPILER_PATH)nmake -nologo ifeq ($(ARCH_DATA_MODEL), 32) CC_VER = UNKNOWN - CC_TYPE = UNKNOWN else CC_VER = UNKNOWN - CC_TYPE = UNKNOWN endif _LINK_VER :=$(shell $(LINK) 2>&1 | $(HEAD) -n 1) LINK_VER :=$(call GetVersion,"$(_LINK_VER)")
--- a/jdk/make/common/shared/Compiler-msvc.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/shared/Compiler-msvc.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -47,13 +47,13 @@ # unset any GNU Make settings of MFLAGS and MAKEFLAGS which may mess up nmake NMAKE = MFLAGS= MAKEFLAGS= $(COMPILER_PATH)nmake -nologo + # Compiler version and type (Always get word after "Version") + CC_VER := $(shell $(CC) 2>&1 | $(HEAD) -n 1 | $(SED) 's/.*\(Version.*\)/\1/' | $(NAWK) '{print $$2}') + # SDK-64 and MSVC6 put REBASE.EXE in a different places - go figure... ifeq ($(ARCH_DATA_MODEL), 32) - CC_VER := $(shell $(CC) 2>&1 | $(HEAD) -n 1 | $(NAWK) '{print $$8}') LINK_VER := $(shell $(LINK) | $(HEAD) -n 1 | $(NAWK) '{print $$6}') - CC_TYPE := $(shell $(CC) 2>&1 | $(HEAD) -n 1 | $(NAWK) '{print $$5}') CC_MAJORVER :=$(call MajorVersion,$(CC_VER)) - REQUIRED_CCTYPE = Optimizing REQUIRED_CC_VER = 13.10.3077 REQUIRED_LINK_VER = 7.10.3077 ifeq ($(CC_MAJORVER), 12) @@ -85,9 +85,7 @@ endif endif else - CC_VER := $(shell $(CC) 2>&1 | $(HEAD) -n 1 | $(NAWK) '{print $$7}') LINK_VER := $(shell $(LINK) | $(HEAD) -n 1 | $(NAWK) '{print $$6}') - CC_TYPE := $(shell $(CC) 2>&1 | $(HEAD) -n 1 | $(NAWK) '{print $$4}') CC_MAJORVER :=$(call MajorVersion,$(CC_VER)) CC_MINORVER :=$(call MinorVersion,$(CC_VER)) CC_MICROVER :=$(call MicroVersion,$(CC_VER))
--- a/jdk/make/common/shared/Defs-control.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/shared/Defs-control.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -69,9 +69,8 @@ # Get shared platform settings include $(JDK_MAKE_SHARED_DIR)/Platform.gmk -# Default output directory +# Default directory immediately above the "build" output directory (OUTPUTDIR) BUILD_PARENT_DIRECTORY=$(TOPDIR) -_OUTPUTDIR=$(TOPDIR)/build/$(PLATFORM)-$(ARCH) # Get platform specific settings include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
--- a/jdk/make/common/shared/Defs.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/shared/Defs.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2005-2008 Sun Microsystems, Inc. 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 @@ -265,7 +265,9 @@ FULL_VERSION = $(RELEASE)-$(BUILD_NUMBER) else BUILD_NUMBER = b00 - USER_RELEASE_SUFFIX := $(shell echo $(USER)_`date '+%d_%b_%Y_%H_%M' | tr "A-Z" "a-z"`) + BUILD_DATE := $(shell $(DATE) '+%Y_%m_%d_%H_%M') + CLEAN_USERNAME := $(shell $(ECHO) "$(USER)" | $(TR) -d -c '[:alnum:]') + USER_RELEASE_SUFFIX := $(shell $(ECHO) "$(CLEAN_USERNAME)_$(BUILD_DATE)" | $(TR) '[:upper:]' '[:lower:]' ) FULL_VERSION = $(RELEASE)-$(USER_RELEASE_SUFFIX)-$(BUILD_NUMBER) endif @@ -449,11 +451,20 @@ # Check for spaces and null value OUTPUTDIR:=$(call AltCheckSpaces,OUTPUTDIR) OUTPUTDIR:=$(call AltCheckValue,OUTPUTDIR) + +# +# When signing the JCE framework and provider, we could be using built +# bits on a read-only filesystem. If so, this test will fail and crash +# the build. +# +ifndef IGNORE_WRITABLE_OUTPUTDIR_TEST # Create the output directory and make sure it exists and is writable _create_outputdir:=$(shell $(MKDIR) -p "$(OUTPUTDIR)" > $(DEV_NULL) 2>&1) ifeq ($(call WriteDirExists,$(OUTPUTDIR),/dev/null),/dev/null) _outputdir_error:=$(error "ERROR: OUTPUTDIR '$(OUTPUTDIR)' not created or not writable") endif +endif + # Define absolute path if needed and check for spaces and null value ifndef ABS_OUTPUTDIR ABS_OUTPUTDIR:=$(call FullPath,$(OUTPUTDIR))
--- a/jdk/make/common/shared/Sanity.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/common/shared/Sanity.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -788,21 +788,17 @@ ifdef OPENJDK -#name of test program that prints out "Failed" if freetype is not good enough -FREETYPE_VERSION_CHECK_NAME = freetype_versioncheck -FREETYPE_VERSION_CHECK = $(TEMPDIR)/$(FREETYPE_VERSION_CHECK_NAME)$(EXE_SUFFIX) +# The freetypecheck Makefile prints out "Failed" if not good enough +$(TEMPDIR)/freetypeinfo: FRC + @$(prep-target) + @(($(CD) $(BUILDDIR)/tools/freetypecheck && $(MAKE)) || \ + $(ECHO) "Failed to build freetypecheck." ) > $@ -sane-freetype: - @-($(CD) $(BUILDDIR)/tools/freetypecheck && \ - $(MAKE) REQUIRED_FREETYPE_VERSION=$(REQUIRED_FREETYPE_VERSION) \ - FT_TEST=$(FREETYPE_VERSION_CHECK_NAME) \ - FT_HEADERS=$(FREETYPE_HEADERS_PATH) \ - FT_LIB=$(FREETYPE_LIB_PATH) \ - XARCH=$(XARCH)) - @if [ ! -r $(FREETYPE_VERSION_CHECK) -o \ - "`$(FREETYPE_VERSION_CHECK) | $(GREP) Fail`" != "" ]; then \ +sane-freetype: $(TEMPDIR)/freetypeinfo + @if [ "`$(CAT) $< | $(GREP) Fail`" != "" ]; then \ $(ECHO) "ERROR: FreeType version " $(REQUIRED_FREETYPE_VERSION) \ - "or higher is required. \n" >> $(ERROR_FILE) ; \ + " or higher is required. \n" \ + "`$(CAT) $<` \n" >> $(ERROR_FILE) ; \ fi else @@ -1339,7 +1335,7 @@ ifndef OPENJDK @if [ "$(CC_CHECK)" != "same" ]; then \ $(ECHO) "WARNING: The $(PLATFORM) compiler is not version $(COMPILER_VERSION) $(REQUIRED_CC_VER) \n" \ - " Specifically the $(COMPILER_NAME) $(CC_TYPE) compiler. \n " \ + " Specifically the $(COMPILER_NAME) compiler. \n " \ " $(YOU_ARE_USING) compiler version: $(CC_VER) \n" \ " The compiler was obtained from the following location: \n" \ " $(COMPILER_PATH) \n" \
--- a/jdk/make/java/java/genlocales.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/java/java/genlocales.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -80,7 +80,8 @@ @$(ECHO) $(subst .java,'\n',$(Euro_Resources_java)) >> $@.tmp.euro; @$(ECHO) $(subst .properties,'\n',$(NonEuro_Resources_properties)) > $@.tmp.noneuro; @$(ECHO) $(subst .java,'\n',$(NonEuro_Resources_java)) >> $@.tmp.noneuro; - NAWK=$(NAWK) SED=$(SED) $(SH) $(LOCALEGEN_SH) $(RESOURCE_NAMES) $@.tmp.euro \ + NAWK="$(NAWK)" SED="$(SED)" SORT="$(SORT)" \ + $(SH) $(LOCALEGEN_SH) $(RESOURCE_NAMES) $@.tmp.euro \ $@.tmp.noneuro $< $@ @$(RM) $@.tmp.euro $@.tmp.noneuro;
--- a/jdk/make/java/java/localegen.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/java/java/localegen.sh Wed Apr 23 06:35:28 2008 -0400 @@ -29,7 +29,7 @@ # This script is to generate the supported locale list string and replace the # LocaleDataMetaInfo-XLocales.java in <ws>/src/share/classes/sun/util # -# NAWK & SED is passed in as environment variables. +# SORT, NAWK & SED is passed in as environment variables. # # A list of resource base name list; @@ -47,7 +47,7 @@ localelist= getlocalelist() { localelist="" - localelist=`$NAWK -F$1_ '{print $2}' $2 | sort` + localelist=`$NAWK -F$1_ '{print $2}' $2 | $SORT` } sed_script="$SED -e \"s@^#warn .*@// -- This file was mechanically generated: Do not edit! -- //@\" "
--- a/jdk/make/javax/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/javax/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -30,24 +30,10 @@ BUILDDIR = .. include $(BUILDDIR)/common/Defs.gmk -# -# Files to compile -# -AUTO_FILES_JAVA_DIRS = \ - javax/naming \ - com/sun/naming/internal \ - javax/net \ - javax/script \ - javax/security/auth \ - javax/security/cert \ - javax/security/sasl \ - javax/smartcardio \ - javax/tools \ - javax/xml - # imageio uses xml, so build it last SUBDIRS = \ + others \ accessibility \ print \ swing \ @@ -63,8 +49,3 @@ clean clobber:: $(SUBDIRS-loop) -# -# Rules -# -include $(BUILDDIR)/common/Classes.gmk -
--- a/jdk/make/javax/crypto/Defs-jce.gmk Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/javax/crypto/Defs-jce.gmk Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,7 @@ JCE_MANIFEST_FILE = $(TEMPDIR)/manifest.mf $(JCE_MANIFEST_FILE): $(MAINMANIFEST) $(prep-target) - ( $(SED) "s/@@RELEASE@@/$(RELEASE)/" $(MAINMANIFEST); \ + ( $(SED) "s/@@RELEASE@@/$(RELEASE)/" $<; \ $(ECHO) "Extension-Name: javax.crypto"; \ $(ECHO) "Implementation-Vendor-Id: com.sun"; ) > $@ @@ -75,6 +75,7 @@ define sign-target $(BOOT_JARSIGNER_CMD) -keystore $(SIGNING_KEYSTORE) \ $@ $(SIGNING_ALIAS) < $(SIGNING_PASSPHRASE) + @$(java-vm-cleanup) @$(ECHO) "\nJar codesigning finished." endef @@ -88,13 +89,15 @@ endef # -# Convenience macro for steps needed to sign a jar file. +# Convenience macros for signing a jar file. +# +# Call through $(call sign-file, target file) # define sign-file $(presign) - $(install-file) + $(prep-target) + $(CP) $1 $@ $(sign-target) - @$(java-vm-cleanup) endef #
--- a/jdk/make/javax/crypto/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/javax/crypto/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2007-2008 Sun Microsystems, Inc. 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 @@ -96,7 +96,7 @@ # sign-jar Builds/signs jce.jar file (no install) # sign-policy Builds/signs policy files (no install) # -# obfus Builds/obfuscates/signs/installs jce.jar +# obfus Builds/obfuscates/signs jce.jar # # release Builds all targets in preparation # for workspace integration. @@ -110,8 +110,24 @@ PACKAGE = javax.crypto PRODUCT = sun +# +# The following is for when we need to do postprocessing +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR +# isn't writable, the build currently crashes out. +# +ifndef OPENJDK + ifdef ALT_JCE_BUILD_DIR + # ===================================================== + # Where to place the output, in case we're building from a read-only + # build area. (e.g. a release engineering build.) + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR} + IGNORE_WRITABLE_OUTPUTDIR_TEST=true + else + JCE_BUILD_DIR=${TEMPDIR} + endif +endif + include $(BUILDDIR)/common/Defs.gmk -include Defs-jce.gmk # # Location for the newly built classfiles. @@ -158,6 +174,8 @@ # UNSIGNED_DIR = $(TEMPDIR)/unsigned +include Defs-jce.gmk + # ===================================================== # Build the unsigned jce.jar file. Signing/obfuscation comes later. @@ -299,7 +317,7 @@ # Sign the various jar files. Not needed for OpenJDK. # -SIGNED_DIR = $(TEMPDIR)/signed +SIGNED_DIR = $(JCE_BUILD_DIR)/signed SIGNED_POLICY_BUILDDIR = $(SIGNED_DIR)/policy SIGNED_POLICY_FILES = \ @@ -312,61 +330,87 @@ sign-policy: $(SIGNED_POLICY_FILES) +ifndef ALT_JCE_BUILD_DIR $(SIGNED_DIR)/jce.jar: $(UNSIGNED_DIR)/jce.jar - $(sign-file) +else +# +# We have to remove the build dependency, otherwise, we'll try to rebuild it +# which we can't do on a read-only filesystem. +# +$(SIGNED_DIR)/jce.jar: + @if [ ! -r $(UNSIGNED_DIR)/jce.jar ] ; then \ + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/jce.jar"; \ + exit 1; \ + fi +endif + $(call sign-file, $(UNSIGNED_DIR)/jce.jar) $(SIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar: \ -$(UNSIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar - $(sign-file) + $(UNSIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar + $(call sign-file, $<) $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar: \ -$(UNSIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar - $(sign-file) + $(UNSIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar + $(call sign-file, $<) $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar: \ -$(UNSIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar - $(sign-file) + $(UNSIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar + $(call sign-file, $<) $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar: \ -$(UNSIGNED_POLICY_BUILDDIR)/limited/local_policy.jar - $(sign-file) + $(UNSIGNED_POLICY_BUILDDIR)/limited/local_policy.jar + $(call sign-file, $<) # ===================================================== # Obfuscate/sign/install the JDK build. Not needed for OpenJDK. # -OBFUS_DIR = $(TEMPDIR)/obfus +OBFUS_DIR = $(JCE_BUILD_DIR)/obfus/jce CLOSED_DIR = $(BUILDDIR)/closed/javax/crypto obfus: $(OBFUS_DIR)/jce.jar $(release-warning) -$(OBFUS_DIR)/jce.jar: build-jar $(JCE_MANIFEST_FILE) +ifndef ALT_JCE_BUILD_DIR +$(OBFUS_DIR)/jce.jar: build-jar $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/framework.dox +else +# +# We have to remove the build dependency, otherwise, we'll try to rebuild it +# which we can't do on a read-only filesystem. +# +$(OBFUS_DIR)/jce.jar: $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/framework.dox + @if [ ! -d $(CLASSDESTDIR) ] ; then \ + $(ECHO) "Couldn't find $(CLASSDESTDIR)"; \ + exit 1; \ + fi +endif + @$(ECHO) ">>>Obfuscating JCE framework..." $(presign) $(preobfus) - @$(ECHO) ">>>Obfuscating JCE framework..." $(prep-target) $(CD) $(OBFUS_DIR); \ - $(OBFUSCATOR) -fv \ - $(CURRENT_DIRECTORY)/$(CLOSED_DIR)/obfus/framework.dox + $(OBFUSCATOR) -fv framework.dox @$(CD) $(OBFUS_DIR); $(java-vm-cleanup) + @# @# The sun.security.internal classes are currently not obfuscated @# due to an obfus problem. Manually copy them to the build directory @# so that they are included in the jce.jar file. + @# $(CP) -r $(CLASSDESTDIR)/sun $(OBFUS_DIR)/build - $(RM) $(UNSIGNED_DIR)/jce.jar $(BOOT_JAR_CMD) cmf $(JCE_MANIFEST_FILE) $@ \ -C $(OBFUS_DIR)/build javax \ -C $(OBFUS_DIR)/build sun \ $(JAR_JFLAGS) $(sign-target) - $(MKDIR) -p $(dir $(JAR_DESTFILE)) - $(RM) $(JAR_DESTFILE) - $(CP) $@ $(JAR_DESTFILE) @$(java-vm-cleanup) +$(OBFUS_DIR)/framework.dox: $(CLOSED_DIR)/obfus/framework.dox + @$(ECHO) ">>>Creating framework.dox" + $(prep-target) + $(SED) "s:@@TEMPDIR@@:$(ABS_TEMPDIR):" $< > $@ + # # The current obfuscator has a limitation in that it currently only # supports up to v49 class file format. Force v49 classfiles in our @@ -380,26 +424,27 @@ # unlimited policy file distribution, etc. # -release: $(OBFUS_DIR)/jce.jar sign-policy +release: $(OBFUS_DIR)/jce.jar sign-policy $(CLOSED_DIR)/doc/COPYRIGHT.html \ + $(CLOSED_DIR)/doc/README.txt $(RM) -r \ - $(RELEASE_DIR)/UnlimitedJCEPolicy \ - $(RELEASE_DIR)/jce.jar \ - $(RELEASE_DIR)/US_export_policy.jar \ - $(RELEASE_DIR)/local_policy.jar \ - $(RELEASE_DIR)/UnlimitedJCEPolicy.zip - $(MKDIR) -p $(RELEASE_DIR)/UnlimitedJCEPolicy - $(CP) $(OBFUS_DIR)/jce.jar $(RELEASE_DIR) - $(CP) -r \ - $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar \ - $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar \ - $(RELEASE_DIR) + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy \ + $(JCE_BUILD_DIR)/release/jce.jar \ + $(JCE_BUILD_DIR)/release/US_export_policy.jar \ + $(JCE_BUILD_DIR)/release/local_policy.jar \ + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy.zip + $(MKDIR) -p $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy + $(CP) $(OBFUS_DIR)/jce.jar $(JCE_BUILD_DIR)/release + $(CP) \ + $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar \ + $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar \ + $(JCE_BUILD_DIR)/release $(CP) \ $(SIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar \ - $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar \ - $(RELEASE_DIR)/UnlimitedJCEPolicy - $(CP) $(CLOSED_DIR)/doc/COPYRIGHT.html \ - $(CLOSED_DIR)/doc/README.txt $(RELEASE_DIR)/UnlimitedJCEPolicy - cd $(RELEASE_DIR) ; \ + $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar \ + $(CLOSED_DIR)/doc/COPYRIGHT.html \ + $(CLOSED_DIR)/doc/README.txt \ + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy + cd $(JCE_BUILD_DIR)/release ; \ $(ZIPEXE) -qr UnlimitedJCEPolicy.zip UnlimitedJCEPolicy $(release-warning) @@ -478,7 +523,8 @@ clobber clean:: $(RM) -r $(JAR_DESTFILE) $(POLICY_DESTDIR)/US_export_policy.jar \ - $(POLICY_DESTDIR)/local_policy.jar $(DELETE_DIRS) $(TEMPDIR) + $(POLICY_DESTDIR)/local_policy.jar $(DELETE_DIRS) $(TEMPDIR) \ + $(JCE_BUILD_DIR) .PHONY: build-jar jar build-policy unlimited limited install-jar \ install-limited install-unlimited
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/make/javax/others/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,52 @@ +# +# Copyright 1998-2007 Sun Microsystems, Inc. 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. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# +# Makefile for building javax (other classes) +# + +BUILDDIR = ../.. +include $(BUILDDIR)/common/Defs.gmk + +# +# Files to compile +# +AUTO_FILES_JAVA_DIRS = \ + javax/naming \ + com/sun/naming/internal \ + javax/net \ + javax/script \ + javax/security/auth \ + javax/security/cert \ + javax/security/sasl \ + javax/smartcardio \ + javax/tools \ + javax/xml + +# +# Rules +# +include $(BUILDDIR)/common/Classes.gmk +
--- a/jdk/make/sun/security/mscapi/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/sun/security/mscapi/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2005-2008 Sun Microsystems, Inc. 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 @@ -92,8 +92,25 @@ PACKAGE = sun.security.mscapi LIBRARY = sunmscapi PRODUCT = sun + +# +# The following is for when we need to do postprocessing +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR +# isn't writable, the build currently crashes out. +# +ifndef OPENJDK + ifdef ALT_JCE_BUILD_DIR + # ===================================================== + # Where to place the output, in case we're building from a read-only + # build area. (e.g. a release engineering build.) + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR} + IGNORE_WRITABLE_OUTPUTDIR_TEST=true + else + JCE_BUILD_DIR=${TEMPDIR} + endif +endif + include $(BUILDDIR)/common/Defs.gmk -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk CPLUSPLUSLIBRARY=true @@ -163,6 +180,8 @@ $(build-warning) endif +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk + # ===================================================== # Build the unsigned sunmscapi.jar file. @@ -200,14 +219,26 @@ # Sign the provider jar file. Not needed for OpenJDK. # -SIGNED_DIR = $(TEMPDIR)/signed +SIGNED_DIR = $(JCE_BUILD_DIR)/signed sign: sign-jar sign-jar: $(SIGNED_DIR)/sunmscapi.jar +ifndef ALT_JCE_BUILD_DIR $(SIGNED_DIR)/sunmscapi.jar: $(UNSIGNED_DIR)/sunmscapi.jar - $(sign-file) +else +# +# We have to remove the build dependency, otherwise, we'll try to rebuild it +# which we can't do on a read-only filesystem. +# +$(SIGNED_DIR)/sunmscapi.jar: + @if [ ! -r $(UNSIGNED_DIR)/sunmscapi.jar ] ; then \ + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunmscapi.jar"; \ + exit 1; \ + fi +endif + $(call sign-file, $(UNSIGNED_DIR)/sunmscapi.jar) # ===================================================== @@ -215,9 +246,9 @@ # release: $(SIGNED_DIR)/sunmscapi.jar - $(RM) $(RELEASE_DIR)/sunmscapi.jar - $(MKDIR) -p $(RELEASE_DIR) - $(CP) $(SIGNED_DIR)/sunmscapi.jar $(RELEASE_DIR) + $(RM) $(JCE_BUILD_DIR)/release/sunmscapi.jar + $(MKDIR) -p $(JCE_BUILD_DIR)/release + $(CP) $(SIGNED_DIR)/sunmscapi.jar $(JCE_BUILD_DIR)/release $(release-warning) endif # OPENJDK @@ -255,7 +286,7 @@ # clobber clean:: - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR) .PHONY: build-jar jar install-jar ifndef OPENJDK
--- a/jdk/make/sun/security/pkcs11/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/sun/security/pkcs11/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ # -# Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -92,8 +92,25 @@ PACKAGE = sun.security.pkcs11 LIBRARY = j2pkcs11 PRODUCT = sun + +# +# The following is for when we need to do postprocessing +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR +# isn't writable, the build currently crashes out. +# +ifndef OPENJDK + ifdef ALT_JCE_BUILD_DIR + # ===================================================== + # Where to place the output, in case we're building from a read-only + # build area. (e.g. a release engineering build.) + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR} + IGNORE_WRITABLE_OUTPUTDIR_TEST=true + else + JCE_BUILD_DIR=${TEMPDIR} + endif +endif + include $(BUILDDIR)/common/Defs.gmk -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk # # C and Java Files @@ -163,6 +180,8 @@ $(build-warning) endif +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk + # ===================================================== # Build the unsigned sunpkcs11.jar file. @@ -200,14 +219,26 @@ # Sign the provider jar file. Not needed for OpenJDK. # -SIGNED_DIR = $(TEMPDIR)/signed +SIGNED_DIR = $(JCE_BUILD_DIR)/signed sign: sign-jar sign-jar: $(SIGNED_DIR)/sunpkcs11.jar +ifndef ALT_JCE_BUILD_DIR $(SIGNED_DIR)/sunpkcs11.jar: $(UNSIGNED_DIR)/sunpkcs11.jar - $(sign-file) +else +# +# We have to remove the build dependency, otherwise, we'll try to rebuild it +# which we can't do on a read-only filesystem. +# +$(SIGNED_DIR)/sunpkcs11.jar: + @if [ ! -r $(UNSIGNED_DIR)/sunpkcs11.jar ] ; then \ + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunpkcs11.jar"; \ + exit 1; \ + fi +endif + $(call sign-file, $(UNSIGNED_DIR)/sunpkcs11.jar) # ===================================================== @@ -215,9 +246,9 @@ # release: $(SIGNED_DIR)/sunpkcs11.jar - $(RM) $(RELEASE_DIR)/sunpkcs11.jar - $(MKDIR) -p $(RELEASE_DIR) - $(CP) $(SIGNED_DIR)/sunpkcs11.jar $(RELEASE_DIR) + $(RM) $(JCE_BUILD_DIR)/release/sunpkcs11.jar + $(MKDIR) -p $(JCE_BUILD_DIR)/release + $(CP) $(SIGNED_DIR)/sunpkcs11.jar $(JCE_BUILD_DIR)/release $(release-warning) endif # OPENJDK @@ -255,7 +286,7 @@ # clobber clean:: - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR) .PHONY: build-jar jar install-jar ifndef OPENJDK
--- a/jdk/make/tools/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/tools/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -40,6 +40,7 @@ dir_diff \ dtdbuilder \ fontchecker \ + freetypecheck \ generate_break_iterator \ GenerateCharacter \ generatecurrencydata \ @@ -58,4 +59,5 @@ clean clobber:: $(RM) -r $(BUILDTOOLCLASSDIR) $(RM) -r $(BUILDTOOLJARDIR) + $(RM) -r $(BUILDTOOLBINDIR)
--- a/jdk/make/tools/freetypecheck/Makefile Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/make/tools/freetypecheck/Makefile Wed Apr 23 06:35:28 2008 -0400 @@ -22,55 +22,58 @@ # CA 95054 USA or visit www.sun.com if you need additional information or # have any questions. -# Builds test program for freetype sanity check. -# -# Makefile should be called with following input parameters -# FT_TEST - full name of test program -# FT_HEADERS - path to freetype headers -# FT_LIB - location of directory with library -# XARCH - xarch option if required +# Builds and runs test program for freetype sanity check. BUILDDIR = ../.. include $(BUILDDIR)/common/Defs.gmk -#test program is expected in the TEMPDIR -FT_TEST_PATH = $(TEMPDIR)/$(FT_TEST) +# Default name +FT_TEST = $(BUILDTOOLBINDIR)/freetype_versioncheck$(EXE_SUFFIX) -all: $(FT_TEST_PATH) +# Used on openjdk only +ifeq ($(OPENJDK),true) # Start with CFLAGS (which gets us the required -xarch setting on solaris) ifeq ($(PLATFORM), windows) - FT_OPTIONS = + FT_OPTIONS = /nologo $(CC_OBJECT_OUTPUT_FLAG)$(TEMPDIR) + FREETYPE_DLL = $(FREETYPE_LIB_PATH)/freetype.dll + FT_LD_OPTIONS = $(FREETYPE_LIB_PATH)/freetype.lib else FT_OPTIONS = $(CFLAGS) -endif - -FT_OPTIONS += -I$(FT_HEADERS) -I$(FT_HEADERS)/freetype2 -FT_OPTIONS += $(XARCH) - -#add runtime library search path -ifeq ($(PLATFORM), windows) - FREETYPE_LIB=$(FT_LIB)/freetype.lib - FREETYPE_DLL=$(FT_LIB)/freetype.dll - DFLAG=/D -else - FT_OPTIONS += -L$(FT_LIB) - DFLAG = -D - - #add runtime lib search path to ensure test will be runnable + FT_LD_OPTIONS = -L$(FREETYPE_LIB_PATH) + # Add runtime lib search path to ensure test will be runnable ifeq ($(PLATFORM), solaris) - FT_OPTIONS += -R $(FT_LIB) -lfreetype + FT_LD_OPTIONS += -R $(FREETYPE_LIB_PATH) -lfreetype else #linux - FT_OPTIONS += -Wl,-rpath -Wl,$(FT_LIB) -lfreetype + FT_LD_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH) -lfreetype endif endif +FT_OPTIONS += -I$(FREETYPE_HEADERS_PATH) +FT_OPTIONS += -I$(FREETYPE_HEADERS_PATH)/freetype2 +FT_OPTIONS += -DREQUIRED_FREETYPE_VERSION=$(REQUIRED_FREETYPE_VERSION) +FT_LD_OPTIONS += $(LFLAGS_$(COMPILER_VERSION)) -FT_OPTIONS += $(DFLAG)REQUIRED_FREETYPE_VERSION=$(REQUIRED_FREETYPE_VERSION) +# Create test program +all: $(FT_TEST) + @$(FT_TEST) -# On windows we need to copy dll to test dir -# ti ensure it will be found in runtime -$(FT_TEST_PATH): freetypecheck.c - @$(CC) $(FT_OPTIONS) $(CC_PROGRAM_OUTPUT_FLAG)$@ $< $(FREETYPE_LIB) $(LFLAGS_$(COMPILER_VERSION)) +# On windows we need to copy dll to test dir to ensure it will be found +# at runtime +$(FT_TEST): freetypecheck.c + @$(prep-target) + @$(CC) $(FT_OPTIONS) $(CC_PROGRAM_OUTPUT_FLAG)$@ $< $(FT_LD_OPTIONS) ifeq ($(PLATFORM), windows) @$(CP) $(FREETYPE_DLL) `dirname $@` endif + +else + +# Inform user this is openjdk only +all: + @$(ECHO) "The freetype files are only used with OpenJDK" + +endif + +clean:: + $(RM) $(FT_TEST) +
--- a/jdk/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Wed Apr 23 06:35:28 2008 -0400 @@ -34,8 +34,6 @@ import java.util.HashSet; import java.util.WeakHashMap; import java.lang.ref.WeakReference; -import java.io.PrintWriter; -import java.io.StringWriter; import java.security.AccessControlContext; import java.security.Permission; import java.security.ProtectionDomain; @@ -51,7 +49,6 @@ import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; import javax.management.InvalidAttributeValueException; -import javax.management.JMException; import javax.management.JMRuntimeException; import javax.management.ListenerNotFoundException; import javax.management.MalformedObjectNameException; @@ -84,11 +81,10 @@ import com.sun.jmx.mbeanserver.DynamicMBean2; import com.sun.jmx.mbeanserver.ModifiableClassLoaderRepository; import com.sun.jmx.mbeanserver.MBeanInstantiator; -import com.sun.jmx.mbeanserver.MXBeanSupport; import com.sun.jmx.mbeanserver.Repository; import com.sun.jmx.mbeanserver.NamedObject; -import com.sun.jmx.defaults.ServiceName; import com.sun.jmx.mbeanserver.Introspector; +import com.sun.jmx.mbeanserver.Util; import com.sun.jmx.remote.util.EnvHelp; /** @@ -623,18 +619,9 @@ List<String> result = new ArrayList<String>(domains.length); for (int i = 0; i < domains.length; i++) { try { - ObjectName domain = new ObjectName(domains[i] + ":x=x"); + ObjectName domain = Util.newObjectName(domains[i] + ":x=x"); checkMBeanPermission((String) null, null, domain, "getDomains"); result.add(domains[i]); - } catch (MalformedObjectNameException e) { - // Should never occur... But let's log it just in case. - if (MBEANSERVER_LOGGER.isLoggable(Level.SEVERE)) { - MBEANSERVER_LOGGER.logp(Level.SEVERE, - DefaultMBeanServerInterceptor.class.getName(), - "getDomains", - "Failed to check permission for domain = " + - domains[i], e); - } } catch (SecurityException e) { // OK: Do not add this domain to the list }
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java Wed Apr 23 06:35:28 2008 -0400 @@ -107,10 +107,7 @@ private MBeanAnalyzer(Class<?> mbeanInterface, MBeanIntrospector<M> introspector) throws NotCompliantMBeanException { - if (!mbeanInterface.isInterface()) { - throw new NotCompliantMBeanException("Not an interface: " + - mbeanInterface.getName()); - } + introspector.checkCompliance(mbeanInterface); try { initMaps(mbeanInterface, introspector); @@ -121,11 +118,10 @@ // Introspect the mbeanInterface and initialize this object's maps. // - private void initMaps(Class<?> mbeanInterface, + private void initMaps(Class<?> mbeanType, MBeanIntrospector<M> introspector) throws Exception { - final Method[] methodArray = mbeanInterface.getMethods(); - - final List<Method> methods = eliminateCovariantMethods(methodArray); + final List<Method> methods1 = introspector.getMethods(mbeanType); + final List<Method> methods = eliminateCovariantMethods(methods1); /* Run through the methods to detect inconsistencies and to enable us to give getter and setter together to visitAttribute. */ @@ -234,13 +230,13 @@ but existing code may depend on it and users may be used to seeing operations or attributes appear in a particular order. */ static List<Method> - eliminateCovariantMethods(Method[] methodArray) { + eliminateCovariantMethods(List<Method> startMethods) { // We are assuming that you never have very many methods with the // same name, so it is OK to use algorithms that are quadratic // in the number of methods with the same name. - final int len = methodArray.length; - final Method[] sorted = methodArray.clone(); + final int len = startMethods.size(); + final Method[] sorted = startMethods.toArray(new Method[len]); Arrays.sort(sorted,MethodOrder.instance); final Set<Method> overridden = newSet(); for (int i=1;i<len;i++) { @@ -259,7 +255,7 @@ } } - final List<Method> methods = newList(Arrays.asList(methodArray)); + final List<Method> methods = newList(startMethods); methods.removeAll(overridden); return methods; }
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Wed Apr 23 06:35:28 2008 -0400 @@ -34,6 +34,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; +import java.util.Arrays; import java.util.List; import java.util.WeakHashMap; @@ -169,6 +170,19 @@ */ abstract Descriptor getMBeanDescriptor(Class<?> resourceClass); + void checkCompliance(Class<?> mbeanType) throws NotCompliantMBeanException { + if (!mbeanType.isInterface()) { + throw new NotCompliantMBeanException("Not an interface: " + + mbeanType.getName()); + } + } + + /** + * Get the methods to be analyzed to build the MBean interface. + */ + List<Method> getMethods(final Class<?> mbeanType) throws Exception { + return Arrays.asList(mbeanType.getMethods()); + } final PerInterface<M> getPerInterface(Class<?> mbeanInterface) throws NotCompliantMBeanException {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/NotificationMBeanSupport.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,81 @@ +/* + * Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package com.sun.jmx.mbeanserver; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import javax.management.NotCompliantMBeanException; +import javax.management.Notification; + +/** + * <p>A variant of {@code StandardMBeanSupport} where the only + * methods included are public getters. This is used by + * {@code QueryNotificationFilter} to pretend that a Notification is + * an MBean so it can have a query evaluated on it. Standard queries + * never set attributes or invoke methods but custom queries could and + * we don't want to allow that. Also we don't want to fail if a + * Notification happens to have inconsistent types in a pair of getX and + * setX methods, and we want to include the Object.getClass() method. + */ +public class NotificationMBeanSupport extends StandardMBeanSupport { + public <T extends Notification> NotificationMBeanSupport(T n) + throws NotCompliantMBeanException { + super(n, Util.<Class<T>>cast(n.getClass())); + } + + @Override + MBeanIntrospector<Method> getMBeanIntrospector() { + return introspector; + } + + private static class Introspector extends StandardMBeanIntrospector { + @Override + void checkCompliance(Class<?> mbeanType) {} + + @Override + List<Method> getMethods(final Class<?> mbeanType) + throws Exception { + List<Method> methods = new ArrayList<Method>(); + for (Method m : mbeanType.getMethods()) { + String name = m.getName(); + Class<?> ret = m.getReturnType(); + if (m.getParameterTypes().length == 0) { + if ((name.startsWith("is") && name.length() > 2 && + ret == boolean.class) || + (name.startsWith("get") && name.length() > 3 && + ret != void.class)) { + methods.add(m); + } + } + } + return methods; + } + + } + private static final MBeanIntrospector<Method> introspector = + new Introspector(); +}
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/OpenConverter.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/OpenConverter.java Wed Apr 23 06:35:28 2008 -0400 @@ -438,7 +438,7 @@ c.getClassLoader() == null); final List<Method> methods = - MBeanAnalyzer.eliminateCovariantMethods(c.getMethods()); + MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods())); final SortedMap<String,Method> getterMap = newSortedMap(); /* Select public methods that look like "T getX()" or "boolean @@ -1118,11 +1118,11 @@ final Class<ConstructorProperties> propertyNamesClass = ConstructorProperties.class; Class targetClass = getTargetClass(); - Constructor[] constrs = targetClass.getConstructors(); + Constructor<?>[] constrs = targetClass.getConstructors(); // Applicable if and only if there are any annotated constructors - List<Constructor> annotatedConstrList = newList(); - for (Constructor constr : constrs) { + List<Constructor<?>> annotatedConstrList = newList(); + for (Constructor<?> constr : constrs) { if (Modifier.isPublic(constr.getModifiers()) && constr.getAnnotation(propertyNamesClass) != null) annotatedConstrList.add(constr); @@ -1152,7 +1152,7 @@ // Also remember the set of properties in that constructor // so we can test unambiguity. Set<BitSet> getterIndexSets = newSet(); - for (Constructor constr : annotatedConstrList) { + for (Constructor<?> constr : annotatedConstrList) { String[] propertyNames = constr.getAnnotation(propertyNamesClass).value(); @@ -1309,10 +1309,10 @@ } private static class Constr { - final Constructor constructor; + final Constructor<?> constructor; final int[] paramIndexes; final BitSet presentParams; - Constr(Constructor constructor, int[] paramIndexes, + Constr(Constructor<?> constructor, int[] paramIndexes, BitSet presentParams) { this.constructor = constructor; this.paramIndexes = paramIndexes;
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Wed Apr 23 06:35:28 2008 -0400 @@ -415,17 +415,8 @@ boolean to_default_domain = false; // Set domain to default if domain is empty and not already set - if (dom.length() == 0) { - try { - name = new ObjectName(domain + name.toString()); - } catch (MalformedObjectNameException e) { - if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) { - MBEANSERVER_LOGGER.logp(Level.FINEST, - Repository.class.getName(), "addMBean", - "Unexpected MalformedObjectNameException", e); - } - } - } + if (dom.length() == 0) + name = Util.newObjectName(domain + name.toString()); // Do we have default domain ? if (dom == domain) {
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/Util.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/Util.java Wed Apr 23 06:35:28 2008 -0400 @@ -38,6 +38,8 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; public class Util { static <K, V> Map<K, V> newMap() { @@ -85,6 +87,14 @@ return new ArrayList<E>(c); } + public static ObjectName newObjectName(String s) { + try { + return new ObjectName(s); + } catch (MalformedObjectNameException e) { + throw new IllegalArgumentException(e); + } + } + /* This method can be used by code that is deliberately violating the * allowed checked casts. Rather than marking the whole method containing * the code with @SuppressWarnings, you can use a call to this method for
--- a/jdk/src/share/classes/com/sun/management/package.html Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/com/sun/management/package.html Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -CTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <!--
--- a/jdk/src/share/classes/java/beans/MetaData.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/java/beans/MetaData.java Wed Apr 23 06:35:28 2008 -0400 @@ -1553,7 +1553,7 @@ private static String[] getConstructorProperties(Class type) { String[] names = null; int length = 0; - for (Constructor constructor : type.getConstructors()) { + for (Constructor<?> constructor : type.getConstructors()) { String[] value = getAnnotationValue(constructor); if ((value != null) && (length < value.length) && isValid(constructor, value)) { names = value; @@ -1563,14 +1563,14 @@ return names; } - private static String[] getAnnotationValue(Constructor constructor) { + private static String[] getAnnotationValue(Constructor<?> constructor) { ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class); return (annotation != null) ? annotation.value() : null; } - private static boolean isValid(Constructor constructor, String[] names) { + private static boolean isValid(Constructor<?> constructor, String[] names) { Class[] parameters = constructor.getParameterTypes(); if (names.length != parameters.length) { return false;
--- a/jdk/src/share/classes/java/lang/instrument/Instrumentation.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/java/lang/instrument/Instrumentation.java Wed Apr 23 06:35:28 2008 -0400 @@ -636,7 +636,11 @@ * @param transformer * The ClassFileTransformer which wraps using this prefix. * @param prefix - * The prefix which has been applied to wrapped native methods. + * The prefix to apply to wrapped native methods when + * retrying a failed native method resolution. If prefix + * is either <code>null</code> or the empty string, then + * failed native method resolutions are not retried for + * this transformer. * @throws java.lang.NullPointerException if passed a <code>null</code> transformer. * @throws java.lang.UnsupportedOperationException if the current configuration of * the JVM does not allow setting a native method prefix
--- a/jdk/src/share/classes/javax/management/MBeanServer.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/javax/management/MBeanServer.java Wed Apr 23 06:35:28 2008 -0400 @@ -50,7 +50,7 @@ * server. A Java object cannot be registered in the MBean server * unless it is a JMX compliant MBean.</p> * - * <p>When an MBean is registered or unregistered in the MBean server + * <p id="notif">When an MBean is registered or unregistered in the MBean server * a {@link javax.management.MBeanServerNotification * MBeanServerNotification} Notification is emitted. To register an * object as listener to MBeanServerNotifications you should call the @@ -258,27 +258,43 @@ */ public interface MBeanServer extends MBeanServerConnection { - // doc comment inherited from MBeanServerConnection + /** + * {@inheritDoc} + * <p>If this method successfully creates an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> + */ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException; - // doc comment inherited from MBeanServerConnection + /** + * {@inheritDoc} + * <p>If this method successfully creates an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> + */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException; - // doc comment inherited from MBeanServerConnection + /** + * {@inheritDoc} + * <p>If this method successfully creates an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> + */ public ObjectInstance createMBean(String className, ObjectName name, Object params[], String signature[]) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException; - // doc comment inherited from MBeanServerConnection + /** + * {@inheritDoc} + * <p>If this method successfully creates an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> + */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params[], String signature[]) @@ -287,12 +303,15 @@ NotCompliantMBeanException, InstanceNotFoundException; /** - * Registers a pre-existing object as an MBean with the MBean + * <p>Registers a pre-existing object as an MBean with the MBean * server. If the object name given is null, the MBean must * provide its own name by implementing the {@link * javax.management.MBeanRegistration MBeanRegistration} interface * and returning the name from the {@link - * MBeanRegistration#preRegister preRegister} method. + * MBeanRegistration#preRegister preRegister} method.</p> + * + * <p>If this method successfully registers an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> * * @param object The MBean to be registered as an MBean. * @param name The object name of the MBean. May be null. @@ -319,7 +338,12 @@ throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException; - // doc comment inherited from MBeanServerConnection + /** + * {@inheritDoc} + * + * <p>If this method successfully unregisters an MBean, a notification + * is sent as described <a href="#notif">above</a>.</p> + */ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException;
--- a/jdk/src/share/classes/javax/management/ObjectName.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/javax/management/ObjectName.java Wed Apr 23 06:35:28 2008 -0400 @@ -26,6 +26,7 @@ package javax.management; import com.sun.jmx.mbeanserver.GetPropertyAction; +import com.sun.jmx.mbeanserver.Util; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; @@ -1386,12 +1387,7 @@ throws NullPointerException { if (name.getClass().equals(ObjectName.class)) return name; - try { - return new ObjectName(name.getSerializedNameString()); - } catch (MalformedObjectNameException e) { - throw new IllegalArgumentException("Unexpected: " + e); - // can't happen - } + return Util.newObjectName(name.getSerializedNameString()); } /** @@ -1950,14 +1946,7 @@ * * @since 1.6 */ - public static final ObjectName WILDCARD; - static { - try { - WILDCARD = new ObjectName("*:*"); - } catch (MalformedObjectNameException e) { - throw new Error("Can't initialize wildcard name", e); - } - } + public static final ObjectName WILDCARD = Util.newObjectName("*:*"); // Category : Utilities <===================================
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/javax/management/QueryNotificationFilter.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,417 @@ +/* + * Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.management; + +import com.sun.jmx.mbeanserver.NotificationMBeanSupport; +import com.sun.jmx.mbeanserver.Util; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Collections; +import java.util.Set; + +/** + * <p>General-purpose notification filter. This filter can be used to + * filter notifications from a possibly-remote MBean. Most filtering + * decisions can be coded using this filter, which avoids having to + * write a custom implementation of the {@link NotificationFilter} + * class. Writing a custom implementation requires you to deploy it + * on both the client and the server in the remote case, so using this class + * instead is recommended where possible.</p> + * + * <!-- <p>Because this class was introduced in version 2.0 of the JMX API, + * it may not be present on a remote JMX agent that is running an earlier + * version. The method {@link JMX#addListenerWithFilter JMX.addListenerWithFilter} + * can be used when you cannot be sure whether this class is present in the + * agent you are connecting to.</p> --> + * + * <p>This class uses the {@linkplain Query Query API} to specify the + * filtering logic. For example, to select only notifications where the + * {@linkplain Notification#getType() type} is {@code "com.example.mytype"}, + * you could use</p> + * + * <pre> + * NotificationFilter filter = + * new QueryNotificationFilter("Type = 'com.example.mytype'"); + * </pre> + * + * <p>or equivalently</p> + * + * <pre> + * NotificationFilter filter = + * new QueryNotificationFilter( + * Query.eq(Query.attr("Type"), Query.value("com.example.mytype"))); + * </pre> + * + * <p>(This particular example could also use + * {@link NotificationFilterSupport}.)</p> + * + * <p>Here are some other examples of filters you can specify with this class.</p> + * + * <dl> + * + * <dt>{@code QueryNotificationFilter("Type = 'com.example.type1' or + * Type = 'com.example.type2'")} + * <dd>Notifications where the type is either of the given strings. + * + * <dt>{@code QueryNotificationFilter("Type in ('com.example.type1', + * 'com.example.type2')")} + * <dd>Another way to write the previous example. + * + * <dt>{@code QueryNotificationFilter("SequenceNumber > 1000")} + * <dd>Notifications where the {@linkplain Notification#getSequenceNumber() + * sequence number} is greater than 1000. + * + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class, null)} + * <dd>Notifications where the notification class is + * {@link AttributeChangeNotification} or a subclass of it. + * + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class, + * "AttributeName = 'Size'")} + * <dd>Notifications where the notification class is + * {@link AttributeChangeNotification} or a subclass, and where the + * {@linkplain AttributeChangeNotification#getAttributeName() name of the + * changed attribute} is {@code Size}. + * + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class, + * "AttributeName = 'Size' and NewValue - OldValue > 100")} + * <dd>As above, but the difference between the + * {@linkplain AttributeChangeNotification#getNewValue() new value} and the + * {@linkplain AttributeChangeNotification#getOldValue() old value} must be + * greater than 100. + * + * <dt>{@code QueryNotificationFilter("like 'com.example.mydomain:*'")} + * <dd>Notifications where the {@linkplain Notification#getSource() source} + * is an ObjectName that matches the pattern. + * + * <dt>{@code QueryNotificationFilter("Source.canonicalName like + * 'com.example.mydomain:%'")} + * <dd>Another way to write the previous example. + * + * <dt>{@code QueryNotificationFilter(MBeanServerNotification.class, + * "Type = 'JMX.mbean.registered' and MBeanName.canonicalName like + * 'com.example.mydomain:%'")} + * <dd>Notifications of class {@link MBeanServerNotification} representing + * an object registered in the domain {@code com.example.mydomain}. + * + * </dl> + * + * <h4>How it works</h4> + * + * <p>Although the examples above are clear, looking closely at the + * Query API reveals a subtlety. A {@link QueryExp} is evaluated on + * an {@link ObjectName}, not a {@code Notification}.</p> + * + * <p>Every time a {@code Notification} is to be filtered by a + * {@code QueryNotificationFilter}, a special {@link MBeanServer} is created. + * This {@code MBeanServer} contains exactly one MBean, which represents the + * {@code Notification}. If the {@linkplain Notification#getSource() + * source} of the notification is an {@code ObjectName}, which is + * recommended practice, then the name of the MBean representing the + * {@code Notification} will be this {@code ObjectName}. Otherwise the + * name is unspecified.</p> + * + * <p>The query specified in the {@code QueryNotificationFilter} constructor + * is evaluated against this {@code MBeanServer} and {@code ObjectName}, + * and the filter returns true if and only if the query does. If the + * query throws an exception, then the filter will return false.</p> + * + * <p>The MBean representing the {@code Notification} has one attribute for + * every property of the {@code Notification}. Specifically, for every public + * method {@code T getX()} in the {@code NotificationClass}, the MBean will + * have an attribute called {@code X} of type {@code T}. For example, if the + * {@code Notification} is an {@code AttributeChangeNotification}, then the + * MBean will have an attribute called {@code AttributeName} of type + * {@code "java.lang.String"}, corresponding to the method {@link + * AttributeChangeNotification#getAttributeName}.</p> + * + * <p>Query evaluation usually involves calls to the methods of {@code + * MBeanServer}. The methods have the following behavior:</p> + * + * <ul> + * <li>The {@link MBeanServer#getAttribute getAttribute} method returns the + * value of the corresponding property. + * <li>The {@link MBeanServer#getObjectInstance getObjectInstance} + * method returns an {@link ObjectInstance} where the {@link + * ObjectInstance#getObjectName ObjectName} is the name of the MBean and the + * {@link ObjectInstance#getClassName ClassName} is the class name of the + * {@code Notification}. + * <li>The {@link MBeanServer#isInstanceOf isInstanceOf} method returns true + * if and only if the {@code Notification}'s {@code ClassLoader} can load the + * named class, and the {@code Notification} is an {@linkplain Class#isInstance + * instance} of that class. + * </ul> + * + * <p>These are the only {@code MBeanServer} methods that are needed to + * evaluate standard queries. The behavior of the other {@code MBeanServer} + * methods is unspecified.</p> + * + * @since 1.7 + */ +public class QueryNotificationFilter implements NotificationFilter { + private static final long serialVersionUID = -8408613922660635231L; + + private static final ObjectName DEFAULT_NAME = + Util.newObjectName(":type=Notification"); + private static final QueryExp trueQuery; + static { + ValueExp zero = Query.value(0); + trueQuery = Query.eq(zero, zero); + } + + private final QueryExp query; + + /** + * Construct a {@code QueryNotificationFilter} that evaluates the given + * {@code QueryExp} to determine whether to accept a notification. + * + * @param query the {@code QueryExp} to evaluate. Can be null, + * in which case all notifications are accepted. + */ + public QueryNotificationFilter(QueryExp query) { + if (query == null) + this.query = trueQuery; + else + this.query = query; + } + + /** + * Construct a {@code QueryNotificationFilter} that evaluates the query + * in the given string to determine whether to accept a notification. + * The string is converted into a {@code QueryExp} using + * {@link Query#fromString Query.fromString}. + * + * @param query the string specifying the query to evaluate. Can be null, + * in which case all notifications are accepted. + * + * @throws IllegalArgumentException if the string is not a valid + * query string. + */ + public QueryNotificationFilter(String query) { + this(Query.fromString(query)); + } + + /** + * <p>Construct a {@code QueryNotificationFilter} that evaluates the query + * in the given string to determine whether to accept a notification, + * and where the notification must also be an instance of the given class. + * The string is converted into a {@code QueryExp} using + * {@link Query#fromString Query.fromString}.</p> + * + * @param notifClass the class that the notification must be an instance of. + * Cannot be null. + * + * @param query the string specifying the query to evaluate. Can be null, + * in which case all notifications are accepted. + * + * @throws IllegalArgumentException if the string is not a valid + * query string, or if {@code notifClass} is null. + */ + public QueryNotificationFilter( + Class<? extends Notification> notifClass, String query) { + this(Query.and(Query.isInstanceOf(Query.value(notNull(notifClass).getName())), + Query.fromString(query))); + } + + private static <T> T notNull(T x) { + if (x == null) + throw new IllegalArgumentException("Null argument"); + return x; + } + + /** + * Retrieve the query that this notification filter will evaluate for + * each notification. + * + * @return the query. + */ + public QueryExp getQuery() { + return query; + } + + public boolean isNotificationEnabled(Notification notification) { + ObjectName name; + + Object source = notification.getSource(); + if (source instanceof ObjectName) + name = (ObjectName) source; + else + name = DEFAULT_NAME; + + MBS mbsImpl = new MBS(notification, name); + MBeanServer mbs = (MBeanServer) Proxy.newProxyInstance( + MBeanServer.class.getClassLoader(), + new Class<?>[] {MBeanServer.class}, + new ForwardIH(mbsImpl)); + return evalQuery(query, mbs, name); + } + + private static boolean evalQuery( + QueryExp query, MBeanServer mbs, ObjectName name) { + MBeanServer oldMBS = QueryEval.getMBeanServer(); + try { + if (mbs != null) + query.setMBeanServer(mbs); + return query.apply(name); + } catch (Exception e) { + return false; + } finally { + query.setMBeanServer(oldMBS); + } + } + + private static class ForwardIH implements InvocationHandler { + private final MBS mbs; + + ForwardIH(MBS mbs) { + this.mbs = mbs; + } + + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + Method forward; + try { + forward = MBS.class.getMethod( + method.getName(), method.getParameterTypes()); + } catch (NoSuchMethodException e) { + throw new UnsupportedOperationException(method.getName()); + } + try { + return forward.invoke(mbs, args); + } catch (InvocationTargetException e) { + throw e.getCause(); + } + } + } + + private static class MBS { + private final Notification notification; + private final ObjectName objectName; + private final ObjectInstance objectInstance; + private volatile DynamicMBean mbean; + + MBS(Notification n, ObjectName name) { + this.notification = n; + this.objectName = name; + this.objectInstance = new ObjectInstance(name, n.getClass().getName()); + } + + private void checkName(ObjectName name) throws InstanceNotFoundException { + if (!objectName.equals(name)) + throw new InstanceNotFoundException(String.valueOf(name)); + } + + private DynamicMBean mbean(ObjectName name) + throws InstanceNotFoundException, ReflectionException { + if (mbean == null) { + try { + mbean = new NotificationMBeanSupport(notification); + } catch (NotCompliantMBeanException e) { + throw new ReflectionException(e); + } + } + return mbean; + } + + public ObjectInstance getObjectInstance(ObjectName name) + throws InstanceNotFoundException { + checkName(name); + return objectInstance; + } + + public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) { + Set<ObjectName> names = queryNames(name, query); + switch (names.size()) { + case 0: + return Collections.emptySet(); + case 1: + return Collections.singleton(objectInstance); + default: + throw new UnsupportedOperationException("Internal error"); + } + } + + public Set<ObjectName> queryNames(ObjectName name, QueryExp query) { + if ((name != null && !name.apply(objectName)) || + (query != null && !evalQuery(query, null, name))) + return Collections.emptySet(); + return Collections.singleton(objectName); + } + + public boolean isRegistered(ObjectName name) { + return objectName.equals(name); + } + + public Integer getMBeanCount() { + return 1; + } + + public Object getAttribute(ObjectName name, String attribute) + throws MBeanException, AttributeNotFoundException, + InstanceNotFoundException, ReflectionException { + return mbean(name).getAttribute(attribute); + } + + public AttributeList getAttributes(ObjectName name, String[] attributes) + throws InstanceNotFoundException, ReflectionException { + return mbean(name).getAttributes(attributes); + } + + public String getDefaultDomain() { + return objectName.getDomain(); + } + + public String[] getDomains() { + return new String[] {objectName.getDomain()}; + } + + public MBeanInfo getMBeanInfo(ObjectName name) + throws InstanceNotFoundException, ReflectionException { + return mbean(name).getMBeanInfo(); + } + + public boolean isInstanceOf(ObjectName name, String className) + throws InstanceNotFoundException { + try { + mbean(name); + ClassLoader loader = notification.getClass().getClassLoader(); + Class<?> c = Class.forName(className, false, loader); + return c.isInstance(notification); + } catch (ReflectionException e) { + return false; + } catch (ClassNotFoundException e) { + return false; + } + } + + public ClassLoader getClassLoaderFor(ObjectName mbeanName) + throws InstanceNotFoundException { + checkName(mbeanName); + return notification.getClass().getClassLoader(); + } + } +}
--- a/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Wed Apr 23 06:35:28 2008 -0400 @@ -48,6 +48,7 @@ import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.management.Attribute; import javax.management.AttributeChangeNotification; import javax.management.AttributeChangeNotificationFilter; @@ -132,8 +133,6 @@ * and operations will be executed */ private Object managedResource = null; - private static final String currClass = "RequiredModelMBean"; - /* records the registering in MBeanServer */ private boolean registered = false; private transient MBeanServer server = null; @@ -2488,10 +2487,13 @@ } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { + Vector<String> enabledAttrs = currFilter.getEnabledAttributes(); + String s = (enabledAttrs.size() > 1) ? + "[" + enabledAttrs.firstElement() + ", ...]" : + enabledAttrs.toString(); MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, - "Set attribute change filter to " + - currFilter.getEnabledAttributes().firstElement()); + "Set attribute change filter to " + s); } attributeBroadcaster.addNotificationListener(inlistener,currFilter,
--- a/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java Wed Apr 23 06:35:28 2008 -0400 @@ -303,39 +303,78 @@ NoSuchMethodException firstExc = null; boolean twoArgAgent = false; - // The agent class has a premain or agentmain method that has 1 or 2 - // arguments. We first check for a signature of (String, Instrumentation), - // and if not found we check for (String). If neither is found then we - // throw the NoSuchMethodException from the first attempt so that the - // exception text indicates the lookup failed for the 2-arg method - // (same as JDK5.0). + // The agent class must have a premain or agentmain method that + // has 1 or 2 arguments. We check in the following order: + // + // 1) declared with a signature of (String, Instrumentation) + // 2) declared with a signature of (String) + // 3) inherited with a signature of (String, Instrumentation) + // 4) inherited with a signature of (String) + // + // So the declared version of either 1-arg or 2-arg always takes + // primary precedence over an inherited version. After that, the + // 2-arg version takes precedence over the 1-arg version. + // + // If no method is found then we throw the NoSuchMethodException + // from the first attempt so that the exception text indicates + // the lookup failed for the 2-arg method (same as JDK5.0). try { - m = javaAgentClass.getMethod( methodname, - new Class[] { - String.class, - java.lang.instrument.Instrumentation.class - } - ); + m = javaAgentClass.getDeclaredMethod( methodname, + new Class[] { + String.class, + java.lang.instrument.Instrumentation.class + } + ); twoArgAgent = true; } catch (NoSuchMethodException x) { // remember the NoSuchMethodException firstExc = x; } - // check for the 1-arg method if (m == null) { + // now try the declared 1-arg method try { - m = javaAgentClass.getMethod(methodname, new Class[] { String.class }); + m = javaAgentClass.getDeclaredMethod(methodname, + new Class[] { String.class }); } catch (NoSuchMethodException x) { - // Neither method exists so we throw the first NoSuchMethodException - // as per 5.0 + // ignore this exception because we'll try + // two arg inheritance next + } + } + + if (m == null) { + // now try the inherited 2-arg method + try { + m = javaAgentClass.getMethod( methodname, + new Class[] { + String.class, + java.lang.instrument.Instrumentation.class + } + ); + twoArgAgent = true; + } catch (NoSuchMethodException x) { + // ignore this exception because we'll try + // one arg inheritance next + } + } + + if (m == null) { + // finally try the inherited 1-arg method + try { + m = javaAgentClass.getMethod(methodname, + new Class[] { String.class }); + } catch (NoSuchMethodException x) { + // none of the methods exists so we throw the + // first NoSuchMethodException as per 5.0 throw firstExc; } } // the premain method should not be required to be public, // make it accessible so we can call it + // Note: The spec says the following: + // The agent class must implement a public static premain method... setAccessible(m, true); // invoke the 1 or 2-arg method
--- a/jdk/src/share/classes/sun/management/Flag.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/management/Flag.java Wed Apr 23 06:35:28 2008 -0400 @@ -64,7 +64,8 @@ } VMOption getVMOption() { - return new VMOption(name, value.toString(), writeable, origin); + String val = value == null ? "" : value.toString(); + return new VMOption(name, val, writeable, origin); } static Flag getFlag(String name) {
--- a/jdk/src/share/classes/sun/net/www/protocol/http/NegotiatorImpl.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/net/www/protocol/http/NegotiatorImpl.java Wed Apr 23 06:35:28 2008 -0400 @@ -91,9 +91,10 @@ GSSManagerImpl manager = new GSSManagerImpl( GSSUtil.CALLER_HTTP_NEGOTIATE); - String peerName = "HTTP/" + hostname; + String peerName = "HTTP@" + hostname; - GSSName serverName = manager.createName(peerName, null); + GSSName serverName = manager.createName(peerName, + GSSName.NT_HOSTBASED_SERVICE); context = manager.createContext(serverName, oid, null,
--- a/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,10 +22,10 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - package sun.security.pkcs11; import java.nio.ByteBuffer; +import java.util.Arrays; import java.security.*; import java.security.spec.*; @@ -34,7 +34,6 @@ import javax.crypto.spec.*; import sun.nio.ch.DirectBuffer; - import sun.security.pkcs11.wrapper.*; import static sun.security.pkcs11.wrapper.PKCS11Constants.*; @@ -43,8 +42,8 @@ * DES, DESede, AES, ARCFOUR, and Blowfish. * * This class is designed to support ECB and CBC with NoPadding and - * PKCS5Padding for both. However, currently only CBC/NoPadding (and - * ECB/NoPadding for stream ciphers) is functional. + * PKCS5Padding for both. It will use its own padding impl if the + * native mechanism does not support padding. * * Note that PKCS#11 current only supports ECB and CBC. There are no * provisions for other modes such as CFB, OFB, PCBC, or CTR mode. @@ -62,10 +61,59 @@ private final static int MODE_CBC = 4; // padding constant for NoPadding - private final static int PAD_NONE = 5; + private final static int PAD_NONE = 5; // padding constant for PKCS5Padding private final static int PAD_PKCS5 = 6; + private static interface Padding { + // ENC: format the specified buffer with padding bytes and return the + // actual padding length + int setPaddingBytes(byte[] paddingBuffer, int padLen); + + // DEC: return the length of trailing padding bytes given the specified + // padded data + int unpad(byte[] paddedData, int len) + throws BadPaddingException; + } + + private static class PKCS5Padding implements Padding { + + private final int blockSize; + + PKCS5Padding(int blockSize) + throws NoSuchPaddingException { + if (blockSize == 0) { + throw new NoSuchPaddingException + ("PKCS#5 padding not supported with stream ciphers"); + } + this.blockSize = blockSize; + } + + public int setPaddingBytes(byte[] paddingBuffer, int padLen) { + Arrays.fill(paddingBuffer, 0, padLen, (byte) (padLen & 0x007f)); + return padLen; + } + + public int unpad(byte[] paddedData, int len) + throws BadPaddingException { + if (len < 1 || len > paddedData.length) { + throw new BadPaddingException("Invalid pad array length!"); + } + byte padValue = paddedData[len - 1]; + if (padValue < 1 || padValue > blockSize) { + throw new BadPaddingException("Invalid pad value!"); + } + // sanity check padding bytes + int padStartIndex = len - padValue; + for (int i = padStartIndex; i < len; i++) { + if (paddedData[i] != padValue) { + throw new BadPaddingException("Invalid pad bytes!"); + } + } + return padValue; + } + } + // token instance private final Token token; @@ -99,65 +147,93 @@ // padding type, on of PAD_* above (PAD_NONE for stream ciphers) private int paddingType; + // when the padding is requested but unsupported by the native mechanism, + // we use the following to do padding and necessary data buffering. + // padding object which generate padding and unpad the decrypted data + private Padding paddingObj; + // buffer for holding back the block which contains padding bytes + private byte[] padBuffer; + private int padBufferLen; + // original IV, if in MODE_CBC private byte[] iv; - // total number of bytes processed - private int bytesProcessed; + // number of bytes buffered internally by the native mechanism and padBuffer + // if we do the padding + private int bytesBuffered; P11Cipher(Token token, String algorithm, long mechanism) - throws PKCS11Exception { + throws PKCS11Exception, NoSuchAlgorithmException { super(); this.token = token; this.algorithm = algorithm; this.mechanism = mechanism; - keyAlgorithm = algorithm.split("/")[0]; + + String algoParts[] = algorithm.split("/"); + keyAlgorithm = algoParts[0]; + if (keyAlgorithm.equals("AES")) { blockSize = 16; - blockMode = MODE_CBC; - // XXX change default to PKCS5Padding - paddingType = PAD_NONE; - } else if (keyAlgorithm.equals("RC4") || keyAlgorithm.equals("ARCFOUR")) { + } else if (keyAlgorithm.equals("RC4") || + keyAlgorithm.equals("ARCFOUR")) { blockSize = 0; - blockMode = MODE_ECB; - paddingType = PAD_NONE; } else { // DES, DESede, Blowfish blockSize = 8; - blockMode = MODE_CBC; - // XXX change default to PKCS5Padding - paddingType = PAD_NONE; + } + this.blockMode = + (algoParts.length > 1 ? parseMode(algoParts[1]) : MODE_ECB); + + String defPadding = (blockSize == 0 ? "NoPadding" : "PKCS5Padding"); + String paddingStr = + (algoParts.length > 2 ? algoParts[2] : defPadding); + try { + engineSetPadding(paddingStr); + } catch (NoSuchPaddingException nspe) { + // should not happen + throw new ProviderException(nspe); } session = token.getOpSession(); } protected void engineSetMode(String mode) throws NoSuchAlgorithmException { + // Disallow change of mode for now since currently it's explicitly + // defined in transformation strings + throw new NoSuchAlgorithmException("Unsupported mode " + mode); + } + + private int parseMode(String mode) throws NoSuchAlgorithmException { mode = mode.toUpperCase(); + int result; if (mode.equals("ECB")) { - this.blockMode = MODE_ECB; + result = MODE_ECB; } else if (mode.equals("CBC")) { if (blockSize == 0) { throw new NoSuchAlgorithmException ("CBC mode not supported with stream ciphers"); } - this.blockMode = MODE_CBC; + result = MODE_CBC; } else { throw new NoSuchAlgorithmException("Unsupported mode " + mode); } + return result; } // see JCE spec protected void engineSetPadding(String padding) throws NoSuchPaddingException { - if (padding.equalsIgnoreCase("NoPadding")) { + paddingObj = null; + padBuffer = null; + padding = padding.toUpperCase(); + if (padding.equals("NOPADDING")) { paddingType = PAD_NONE; - } else if (padding.equalsIgnoreCase("PKCS5Padding")) { - if (blockSize == 0) { - throw new NoSuchPaddingException - ("PKCS#5 padding not supported with stream ciphers"); + } else if (padding.equals("PKCS5PADDING")) { + paddingType = PAD_PKCS5; + if (mechanism != CKM_DES_CBC_PAD && mechanism != CKM_DES3_CBC_PAD && + mechanism != CKM_AES_CBC_PAD) { + // no native padding support; use our own padding impl + paddingObj = new PKCS5Padding(blockSize); + padBuffer = new byte[blockSize]; } - paddingType = PAD_PKCS5; - // XXX PKCS#5 not yet implemented - throw new NoSuchPaddingException("pkcs5"); } else { throw new NoSuchPaddingException("Unsupported padding " + padding); } @@ -175,7 +251,7 @@ // see JCE spec protected byte[] engineGetIV() { - return (iv == null) ? null : (byte[])iv.clone(); + return (iv == null) ? null : (byte[]) iv.clone(); } // see JCE spec @@ -185,8 +261,9 @@ } IvParameterSpec ivSpec = new IvParameterSpec(iv); try { - AlgorithmParameters params = AlgorithmParameters.getInstance - (keyAlgorithm, P11Util.getSunJceProvider()); + AlgorithmParameters params = + AlgorithmParameters.getInstance(keyAlgorithm, + P11Util.getSunJceProvider()); params.init(ivSpec); return params; } catch (GeneralSecurityException e) { @@ -210,38 +287,38 @@ protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { - byte[] iv; + byte[] ivValue; if (params != null) { if (params instanceof IvParameterSpec == false) { throw new InvalidAlgorithmParameterException ("Only IvParameterSpec supported"); } - IvParameterSpec ivSpec = (IvParameterSpec)params; - iv = ivSpec.getIV(); + IvParameterSpec ivSpec = (IvParameterSpec) params; + ivValue = ivSpec.getIV(); } else { - iv = null; + ivValue = null; } - implInit(opmode, key, iv, random); + implInit(opmode, key, ivValue, random); } // see JCE spec protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { - byte[] iv; + byte[] ivValue; if (params != null) { try { IvParameterSpec ivSpec = (IvParameterSpec) params.getParameterSpec(IvParameterSpec.class); - iv = ivSpec.getIV(); + ivValue = ivSpec.getIV(); } catch (InvalidParameterSpecException e) { throw new InvalidAlgorithmParameterException ("Could not decode IV", e); } } else { - iv = null; + ivValue = null; } - implInit(opmode, key, iv, random); + implInit(opmode, key, ivValue, random); } // actual init() implementation @@ -250,31 +327,31 @@ throws InvalidKeyException, InvalidAlgorithmParameterException { cancelOperation(); switch (opmode) { - case Cipher.ENCRYPT_MODE: - encrypt = true; - break; - case Cipher.DECRYPT_MODE: - encrypt = false; - break; - default: - throw new InvalidAlgorithmParameterException - ("Unsupported mode: " + opmode); + case Cipher.ENCRYPT_MODE: + encrypt = true; + break; + case Cipher.DECRYPT_MODE: + encrypt = false; + break; + default: + throw new InvalidAlgorithmParameterException + ("Unsupported mode: " + opmode); } if (blockMode == MODE_ECB) { // ECB or stream cipher if (iv != null) { if (blockSize == 0) { throw new InvalidAlgorithmParameterException - ("IV not used with stream ciphers"); + ("IV not used with stream ciphers"); } else { throw new InvalidAlgorithmParameterException - ("IV not used in ECB mode"); + ("IV not used in ECB mode"); } } } else { // MODE_CBC if (iv == null) { if (encrypt == false) { throw new InvalidAlgorithmParameterException - ("IV must be specified for decryption in CBC mode"); + ("IV must be specified for decryption in CBC mode"); } // generate random IV if (random == null) { @@ -285,7 +362,7 @@ } else { if (iv.length != blockSize) { throw new InvalidAlgorithmParameterException - ("IV length must match block size"); + ("IV length must match block size"); } } } @@ -331,63 +408,43 @@ session = token.getOpSession(); } if (encrypt) { - token.p11.C_EncryptInit - (session.id(), new CK_MECHANISM(mechanism, iv), p11Key.keyID); + token.p11.C_EncryptInit(session.id(), + new CK_MECHANISM(mechanism, iv), p11Key.keyID); } else { - token.p11.C_DecryptInit - (session.id(), new CK_MECHANISM(mechanism, iv), p11Key.keyID); + token.p11.C_DecryptInit(session.id(), + new CK_MECHANISM(mechanism, iv), p11Key.keyID); } - bytesProcessed = 0; + bytesBuffered = 0; + padBufferLen = 0; initialized = true; } - // XXX the calculations below assume the PKCS#11 implementation is smart. - // conceivably, not all implementations are and we may need to estimate - // more conservatively - - private int bytesBuffered(int totalLen) { - if (paddingType == PAD_NONE) { - // with NoPadding, buffer only the current unfinished block - return totalLen & (blockSize - 1); - } else { // PKCS5 - // with PKCS5Padding in decrypt mode, the buffer must never - // be empty. Buffer a full block instead of nothing. - int buffered = totalLen & (blockSize - 1); - if ((buffered == 0) && (encrypt == false)) { - buffered = blockSize; - } - return buffered; - } - } - // if update(inLen) is called, how big does the output buffer have to be? private int updateLength(int inLen) { if (inLen <= 0) { return 0; } - if (blockSize == 0) { - return inLen; - } else { - // bytes that need to be buffered now - int buffered = bytesBuffered(bytesProcessed); - // bytes that need to be buffered after this update - int newBuffered = bytesBuffered(bytesProcessed + inLen); - return inLen + buffered - newBuffered; + + int result = inLen + bytesBuffered; + if (blockSize != 0) { + // minus the number of bytes in the last incomplete block. + result -= (result & (blockSize - 1)); } + return result; } // if doFinal(inLen) is called, how big does the output buffer have to be? private int doFinalLength(int inLen) { - if (paddingType == PAD_NONE) { - return updateLength(inLen); - } if (inLen < 0) { return 0; } - int buffered = bytesBuffered(bytesProcessed); - int newProcessed = bytesProcessed + inLen; - int paddedProcessed = (newProcessed + blockSize) & ~(blockSize - 1); - return paddedProcessed - bytesProcessed + buffered; + + int result = inLen + bytesBuffered; + if (blockSize != 0 && encrypt && paddingType != PAD_NONE) { + // add the number of bytes to make the last block complete. + result += (blockSize - (result & (blockSize - 1))); + } + return result; } // see JCE spec @@ -397,6 +454,7 @@ int n = engineUpdate(in, inOfs, inLen, out, 0); return P11Util.convert(out, 0, n); } catch (ShortBufferException e) { + // convert since the output length is calculated by updateLength() throw new ProviderException(e); } } @@ -409,6 +467,7 @@ } // see JCE spec + @Override protected int engineUpdate(ByteBuffer inBuffer, ByteBuffer outBuffer) throws ShortBufferException { return implUpdate(inBuffer, outBuffer); @@ -422,14 +481,15 @@ int n = engineDoFinal(in, inOfs, inLen, out, 0); return P11Util.convert(out, 0, n); } catch (ShortBufferException e) { + // convert since the output length is calculated by doFinalLength() throw new ProviderException(e); } } // see JCE spec protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out, - int outOfs) throws ShortBufferException, IllegalBlockSizeException { - // BadPaddingException { + int outOfs) throws ShortBufferException, IllegalBlockSizeException, + BadPaddingException { int n = 0; if ((inLen != 0) && (in != null)) { n = engineUpdate(in, inOfs, inLen, out, outOfs); @@ -440,8 +500,10 @@ } // see JCE spec + @Override protected int engineDoFinal(ByteBuffer inBuffer, ByteBuffer outBuffer) - throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { + throws ShortBufferException, IllegalBlockSizeException, + BadPaddingException { int n = engineUpdate(inBuffer, outBuffer); n += implDoFinal(outBuffer); return n; @@ -454,18 +516,55 @@ } try { ensureInitialized(); - int k; + int k = 0; if (encrypt) { - k = token.p11.C_EncryptUpdate - (session.id(), 0, in, inOfs, inLen, 0, out, outOfs, outLen); + k = token.p11.C_EncryptUpdate(session.id(), 0, in, inOfs, inLen, + 0, out, outOfs, outLen); } else { - k = token.p11.C_DecryptUpdate - (session.id(), 0, in, inOfs, inLen, 0, out, outOfs, outLen); + int newPadBufferLen = 0; + if (paddingObj != null) { + if (padBufferLen != 0) { + // NSS throws up when called with data not in multiple + // of blocks. Try to work around this by holding the + // extra data in padBuffer. + if (padBufferLen != padBuffer.length) { + int bufCapacity = padBuffer.length - padBufferLen; + if (inLen > bufCapacity) { + bufferInputBytes(in, inOfs, bufCapacity); + inOfs += bufCapacity; + inLen -= bufCapacity; + } else { + bufferInputBytes(in, inOfs, inLen); + return 0; + } + } + k = token.p11.C_DecryptUpdate(session.id(), + 0, padBuffer, 0, padBufferLen, + 0, out, outOfs, outLen); + padBufferLen = 0; + } + newPadBufferLen = inLen & (blockSize - 1); + if (newPadBufferLen == 0) { + newPadBufferLen = padBuffer.length; + } + inLen -= newPadBufferLen; + } + if (inLen > 0) { + k += token.p11.C_DecryptUpdate(session.id(), 0, in, inOfs, + inLen, 0, out, (outOfs + k), (outLen - k)); + } + // update 'padBuffer' if using our own padding impl. + if (paddingObj != null) { + bufferInputBytes(in, inOfs + inLen, newPadBufferLen); + } } - bytesProcessed += inLen; + bytesBuffered += (inLen - k); return k; } catch (PKCS11Exception e) { - // XXX throw correct exception + if (e.getErrorCode() == CKR_BUFFER_TOO_SMALL) { + throw (ShortBufferException) + (new ShortBufferException().initCause(e)); + } throw new ProviderException("update() failed", e); } } @@ -481,101 +580,167 @@ if (outLen < updateLength(inLen)) { throw new ShortBufferException(); } - boolean inPosChanged = false; + int origPos = inBuffer.position(); try { ensureInitialized(); long inAddr = 0; - int inOfs = inBuffer.position(); + int inOfs = 0; byte[] inArray = null; + if (inBuffer instanceof DirectBuffer) { - inAddr = ((DirectBuffer)inBuffer).address(); + inAddr = ((DirectBuffer) inBuffer).address(); + inOfs = origPos; + } else if (inBuffer.hasArray()) { + inArray = inBuffer.array(); + inOfs = (origPos + inBuffer.arrayOffset()); + } + + long outAddr = 0; + int outOfs = 0; + byte[] outArray = null; + if (outBuffer instanceof DirectBuffer) { + outAddr = ((DirectBuffer) outBuffer).address(); + outOfs = outBuffer.position(); } else { - if (inBuffer.hasArray()) { - inArray = inBuffer.array(); - inOfs += inBuffer.arrayOffset(); + if (outBuffer.hasArray()) { + outArray = outBuffer.array(); + outOfs = (outBuffer.position() + outBuffer.arrayOffset()); } else { - inArray = new byte[inLen]; - inBuffer.get(inArray); - inOfs = 0; - inPosChanged = true; + outArray = new byte[outLen]; } } - long outAddr = 0; - int outOfs = outBuffer.position(); - byte[] outArray = null; - if (outBuffer instanceof DirectBuffer) { - outAddr = ((DirectBuffer)outBuffer).address(); + int k = 0; + if (encrypt) { + if (inAddr == 0 && inArray == null) { + inArray = new byte[inLen]; + inBuffer.get(inArray); + } else { + inBuffer.position(origPos + inLen); + } + k = token.p11.C_EncryptUpdate(session.id(), + inAddr, inArray, inOfs, inLen, + outAddr, outArray, outOfs, outLen); } else { - if (outBuffer.hasArray()) { - outArray = outBuffer.array(); - outOfs += outBuffer.arrayOffset(); - } else { - outArray = new byte[outLen]; - outOfs = 0; + int newPadBufferLen = 0; + if (paddingObj != null) { + if (padBufferLen != 0) { + // NSS throws up when called with data not in multiple + // of blocks. Try to work around this by holding the + // extra data in padBuffer. + if (padBufferLen != padBuffer.length) { + int bufCapacity = padBuffer.length - padBufferLen; + if (inLen > bufCapacity) { + bufferInputBytes(inBuffer, bufCapacity); + inOfs += bufCapacity; + inLen -= bufCapacity; + } else { + bufferInputBytes(inBuffer, inLen); + return 0; + } + } + k = token.p11.C_DecryptUpdate(session.id(), 0, + padBuffer, 0, padBufferLen, outAddr, outArray, + outOfs, outLen); + padBufferLen = 0; + } + newPadBufferLen = inLen & (blockSize - 1); + if (newPadBufferLen == 0) { + newPadBufferLen = padBuffer.length; + } + inLen -= newPadBufferLen; + } + if (inLen > 0) { + if (inAddr == 0 && inArray == null) { + inArray = new byte[inLen]; + inBuffer.get(inArray); + } else { + inBuffer.position(inBuffer.position() + inLen); + } + k += token.p11.C_DecryptUpdate(session.id(), inAddr, + inArray, inOfs, inLen, outAddr, outArray, + (outOfs + k), (outLen - k)); + } + // update 'padBuffer' if using our own padding impl. + if (paddingObj != null && newPadBufferLen != 0) { + bufferInputBytes(inBuffer, newPadBufferLen); } } - - int k; - if (encrypt) { - k = token.p11.C_EncryptUpdate - (session.id(), inAddr, inArray, inOfs, inLen, - outAddr, outArray, outOfs, outLen); - } else { - k = token.p11.C_DecryptUpdate - (session.id(), inAddr, inArray, inOfs, inLen, - outAddr, outArray, outOfs, outLen); - } - bytesProcessed += inLen; - if (!inPosChanged) { - inBuffer.position(inBuffer.position() + inLen); - } + bytesBuffered += (inLen - k); if (!(outBuffer instanceof DirectBuffer) && - !outBuffer.hasArray()) { + !outBuffer.hasArray()) { outBuffer.put(outArray, outOfs, k); } else { outBuffer.position(outBuffer.position() + k); } return k; } catch (PKCS11Exception e) { - // Un-read the bytes back to input buffer - if (inPosChanged) { - inBuffer.position(inBuffer.position() - inLen); + // Reset input buffer to its original position for + inBuffer.position(origPos); + if (e.getErrorCode() == CKR_BUFFER_TOO_SMALL) { + throw (ShortBufferException) + (new ShortBufferException().initCause(e)); } - // XXX throw correct exception throw new ProviderException("update() failed", e); } } private int implDoFinal(byte[] out, int outOfs, int outLen) - throws ShortBufferException, IllegalBlockSizeException { - if (outLen < doFinalLength(0)) { + throws ShortBufferException, IllegalBlockSizeException, + BadPaddingException { + int requiredOutLen = doFinalLength(0); + if (outLen < requiredOutLen) { throw new ShortBufferException(); } try { ensureInitialized(); + int k = 0; if (encrypt) { - return token.p11.C_EncryptFinal - (session.id(), 0, out, outOfs, outLen); + if (paddingObj != null) { + int actualPadLen = paddingObj.setPaddingBytes(padBuffer, + requiredOutLen - bytesBuffered); + k = token.p11.C_EncryptUpdate(session.id(), + 0, padBuffer, 0, actualPadLen, + 0, out, outOfs, outLen); + } + k += token.p11.C_EncryptFinal(session.id(), + 0, out, (outOfs + k), (outLen - k)); } else { - return token.p11.C_DecryptFinal - (session.id(), 0, out, outOfs, outLen); + if (paddingObj != null) { + if (padBufferLen != 0) { + k = token.p11.C_DecryptUpdate(session.id(), 0, + padBuffer, 0, padBufferLen, 0, padBuffer, 0, + padBuffer.length); + } + k += token.p11.C_DecryptFinal(session.id(), 0, padBuffer, k, + padBuffer.length - k); + int actualPadLen = paddingObj.unpad(padBuffer, k); + k -= actualPadLen; + System.arraycopy(padBuffer, 0, out, outOfs, k); + } else { + k = token.p11.C_DecryptFinal(session.id(), 0, out, outOfs, + outLen); + } } + return k; } catch (PKCS11Exception e) { handleException(e); throw new ProviderException("doFinal() failed", e); } finally { initialized = false; - bytesProcessed = 0; + bytesBuffered = 0; + padBufferLen = 0; session = token.releaseSession(session); } } private int implDoFinal(ByteBuffer outBuffer) - throws ShortBufferException, IllegalBlockSizeException { + throws ShortBufferException, IllegalBlockSizeException, + BadPaddingException { int outLen = outBuffer.remaining(); - if (outLen < doFinalLength(0)) { + int requiredOutLen = doFinalLength(0); + if (outLen < requiredOutLen) { throw new ShortBufferException(); } @@ -583,30 +748,54 @@ ensureInitialized(); long outAddr = 0; - int outOfs = outBuffer.position(); byte[] outArray = null; + int outOfs = 0; if (outBuffer instanceof DirectBuffer) { - outAddr = ((DirectBuffer)outBuffer).address(); + outAddr = ((DirectBuffer) outBuffer).address(); + outOfs = outBuffer.position(); } else { if (outBuffer.hasArray()) { outArray = outBuffer.array(); - outOfs += outBuffer.arrayOffset(); + outOfs = outBuffer.position() + outBuffer.arrayOffset(); } else { outArray = new byte[outLen]; - outOfs = 0; } } - int k; + int k = 0; + if (encrypt) { - k = token.p11.C_EncryptFinal - (session.id(), outAddr, outArray, outOfs, outLen); + if (paddingObj != null) { + int actualPadLen = paddingObj.setPaddingBytes(padBuffer, + requiredOutLen - bytesBuffered); + k = token.p11.C_EncryptUpdate(session.id(), + 0, padBuffer, 0, actualPadLen, + outAddr, outArray, outOfs, outLen); + } + k += token.p11.C_EncryptFinal(session.id(), + outAddr, outArray, (outOfs + k), (outLen - k)); } else { - k = token.p11.C_DecryptFinal - (session.id(), outAddr, outArray, outOfs, outLen); + if (paddingObj != null) { + if (padBufferLen != 0) { + k = token.p11.C_DecryptUpdate(session.id(), + 0, padBuffer, 0, padBufferLen, + 0, padBuffer, 0, padBuffer.length); + padBufferLen = 0; + } + k += token.p11.C_DecryptFinal(session.id(), + 0, padBuffer, k, padBuffer.length - k); + int actualPadLen = paddingObj.unpad(padBuffer, k); + k -= actualPadLen; + outArray = padBuffer; + outOfs = 0; + } else { + k = token.p11.C_DecryptFinal(session.id(), + outAddr, outArray, outOfs, outLen); + } } - if (!(outBuffer instanceof DirectBuffer) && - !outBuffer.hasArray()) { + if ((!encrypt && paddingObj != null) || + (!(outBuffer instanceof DirectBuffer) && + !outBuffer.hasArray())) { outBuffer.put(outArray, outOfs, k); } else { outBuffer.position(outBuffer.position() + k); @@ -617,20 +806,22 @@ throw new ProviderException("doFinal() failed", e); } finally { initialized = false; - bytesProcessed = 0; + bytesBuffered = 0; session = token.releaseSession(session); } } private void handleException(PKCS11Exception e) - throws IllegalBlockSizeException { + throws ShortBufferException, IllegalBlockSizeException { long errorCode = e.getErrorCode(); - // XXX better check - if (errorCode == CKR_DATA_LEN_RANGE) { - throw (IllegalBlockSizeException)new - IllegalBlockSizeException(e.toString()).initCause(e); + if (errorCode == CKR_BUFFER_TOO_SMALL) { + throw (ShortBufferException) + (new ShortBufferException().initCause(e)); + } else if (errorCode == CKR_DATA_LEN_RANGE || + errorCode == CKR_ENCRYPTED_DATA_LEN_RANGE) { + throw (IllegalBlockSizeException) + (new IllegalBlockSizeException(e.toString()).initCause(e)); } - } // see JCE spec @@ -649,12 +840,14 @@ } // see JCE spec + @Override protected int engineGetKeySize(Key key) throws InvalidKeyException { int n = P11SecretKeyFactory.convertKey - (token, key, keyAlgorithm).keyLength(); + (token, key, keyAlgorithm).keyLength(); return n; } + @Override protected void finalize() throws Throwable { try { if ((session != null) && token.isValid()) { @@ -666,4 +859,15 @@ } } + private final void bufferInputBytes(byte[] in, int inOfs, int len) { + System.arraycopy(in, inOfs, padBuffer, padBufferLen, len); + padBufferLen += len; + bytesBuffered += len; + } + + private final void bufferInputBytes(ByteBuffer inBuffer, int len) { + inBuffer.get(padBuffer, padBufferLen, len); + padBufferLen += len; + bytesBuffered += len; + } }
--- a/jdk/src/share/classes/sun/security/pkcs11/P11KeyGenerator.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11KeyGenerator.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -65,10 +65,86 @@ // are supported. private boolean supportBothKeySizes; - // min and max key sizes (in bits) for variable-key-length - // algorithms, e.g. RC4 and Blowfish - private int minKeySize; - private int maxKeySize; + /** + * Utility method for checking if the specified key size is valid + * and within the supported range. Return the significant key size + * upon successful validation. + * @param keyGenMech the PKCS#11 key generation mechanism. + * @param keySize the to-be-checked key size for this mechanism. + * @param token token which provides this mechanism. + * @return the significant key size (in bits) corresponding to the + * specified key size. + * @throws InvalidParameterException if the specified key size is invalid. + * @throws ProviderException if this mechanism isn't supported by SunPKCS11 + * or underlying native impl. + */ + static int checkKeySize(long keyGenMech, int keySize, Token token) + throws InvalidAlgorithmParameterException, ProviderException { + int sigKeySize; + switch ((int)keyGenMech) { + case (int)CKM_DES_KEY_GEN: + if ((keySize != 64) && (keySize != 56)) { + throw new InvalidAlgorithmParameterException + ("DES key length must be 56 bits"); + } + sigKeySize = 56; + break; + case (int)CKM_DES2_KEY_GEN: + case (int)CKM_DES3_KEY_GEN: + if ((keySize == 112) || (keySize == 128)) { + sigKeySize = 112; + } else if ((keySize == 168) || (keySize == 192)) { + sigKeySize = 168; + } else { + throw new InvalidAlgorithmParameterException + ("DESede key length must be 112, or 168 bits"); + } + break; + default: + // Handle all variable-key-length algorithms here + CK_MECHANISM_INFO info = null; + try { + info = token.getMechanismInfo(keyGenMech); + } catch (PKCS11Exception p11e) { + // Should never happen + throw new ProviderException + ("Cannot retrieve mechanism info", p11e); + } + if (info == null) { + // XXX Unable to retrieve the supported key length from + // the underlying native impl. Skip the checking for now. + return keySize; + } + // PKCS#11 defines these to be in number of bytes except for + // RC4 which is in bits. However, some PKCS#11 impls still use + // bytes for all mechs, e.g. NSS. We try to detect this + // inconsistency if the minKeySize seems unreasonably small. + int minKeySize = (int)info.ulMinKeySize; + int maxKeySize = (int)info.ulMaxKeySize; + if (keyGenMech != CKM_RC4_KEY_GEN || minKeySize < 8) { + minKeySize = (int)info.ulMinKeySize << 3; + maxKeySize = (int)info.ulMaxKeySize << 3; + } + // Explicitly disallow keys shorter than 40-bits for security + if (minKeySize < 40) minKeySize = 40; + if (keySize < minKeySize || keySize > maxKeySize) { + throw new InvalidAlgorithmParameterException + ("Key length must be between " + minKeySize + + " and " + maxKeySize + " bits"); + } + if (keyGenMech == CKM_AES_KEY_GEN) { + if ((keySize != 128) && (keySize != 192) && + (keySize != 256)) { + throw new InvalidAlgorithmParameterException + ("AES key length must be " + minKeySize + + (maxKeySize >= 192? ", 192":"") + + (maxKeySize >= 256? ", or 256":"") + " bits"); + } + } + sigKeySize = keySize; + } + return sigKeySize; + } P11KeyGenerator(Token token, String algorithm, long mechanism) throws PKCS11Exception { @@ -85,72 +161,44 @@ supportBothKeySizes = (token.provider.config.isEnabled(CKM_DES2_KEY_GEN) && (token.getMechanismInfo(CKM_DES2_KEY_GEN) != null)); - } else if (this.mechanism == CKM_RC4_KEY_GEN) { - CK_MECHANISM_INFO info = token.getMechanismInfo(mechanism); - // Although PKCS#11 spec documented that these are in bits, - // NSS, for one, uses bytes. Multiple by 8 if the number seems - // unreasonably small. - if (info.ulMinKeySize < 8) { - minKeySize = (int)info.ulMinKeySize << 3; - maxKeySize = (int)info.ulMaxKeySize << 3; - } else { - minKeySize = (int)info.ulMinKeySize; - maxKeySize = (int)info.ulMaxKeySize; - } - // Explicitly disallow keys shorter than 40-bits for security - if (minKeySize < 40) minKeySize = 40; - } else if (this.mechanism == CKM_BLOWFISH_KEY_GEN) { - CK_MECHANISM_INFO info = token.getMechanismInfo(mechanism); - maxKeySize = (int)info.ulMaxKeySize << 3; - minKeySize = (int)info.ulMinKeySize << 3; - // Explicitly disallow keys shorter than 40-bits for security - if (minKeySize < 40) minKeySize = 40; } - setDefaultKeySize(); } // set default keysize and also initialize keyType private void setDefaultKeySize() { - // whether to check default key size against the min and max value - boolean validateKeySize = false; switch ((int)mechanism) { case (int)CKM_DES_KEY_GEN: keySize = 64; - significantKeySize = 56; keyType = CKK_DES; break; case (int)CKM_DES2_KEY_GEN: keySize = 128; - significantKeySize = 112; keyType = CKK_DES2; break; case (int)CKM_DES3_KEY_GEN: keySize = 192; - significantKeySize = 168; keyType = CKK_DES3; break; case (int)CKM_AES_KEY_GEN: + keySize = 128; keyType = CKK_AES; - keySize = 128; - significantKeySize = 128; break; case (int)CKM_RC4_KEY_GEN: + keySize = 128; keyType = CKK_RC4; - keySize = 128; - validateKeySize = true; break; case (int)CKM_BLOWFISH_KEY_GEN: + keySize = 128; keyType = CKK_BLOWFISH; - keySize = 128; - validateKeySize = true; break; default: throw new ProviderException("Unknown mechanism " + mechanism); } - if (validateKeySize && - ((keySize > maxKeySize) || (keySize < minKeySize))) { - throw new ProviderException("Unsupported key size"); + try { + significantKeySize = checkKeySize(mechanism, keySize, token); + } catch (InvalidAlgorithmParameterException iape) { + throw new ProviderException("Unsupported default key size", iape); } } @@ -170,57 +218,32 @@ // see JCE spec protected void engineInit(int keySize, SecureRandom random) { token.ensureValid(); - switch ((int)mechanism) { - case (int)CKM_DES_KEY_GEN: - if ((keySize != this.keySize) && - (keySize != this.significantKeySize)) { - throw new InvalidParameterException - ("DES key length must be 56 bits"); - } - break; - case (int)CKM_DES2_KEY_GEN: - case (int)CKM_DES3_KEY_GEN: - long newMechanism; - if ((keySize == 112) || (keySize == 128)) { - newMechanism = CKM_DES2_KEY_GEN; - } else if ((keySize == 168) || (keySize == 192)) { - newMechanism = CKM_DES3_KEY_GEN; - } else { - throw new InvalidParameterException - ("DESede key length must be 112, or 168 bits"); - } + int newSignificantKeySize; + try { + newSignificantKeySize = checkKeySize(mechanism, keySize, token); + } catch (InvalidAlgorithmParameterException iape) { + throw (InvalidParameterException) + (new InvalidParameterException().initCause(iape)); + } + if ((mechanism == CKM_DES2_KEY_GEN) || + (mechanism == CKM_DES3_KEY_GEN)) { + long newMechanism = (newSignificantKeySize == 112 ? + CKM_DES2_KEY_GEN : CKM_DES3_KEY_GEN); if (mechanism != newMechanism) { if (supportBothKeySizes) { mechanism = newMechanism; - setDefaultKeySize(); + // Adjust keyType to reflect the mechanism change + keyType = (mechanism == CKM_DES2_KEY_GEN ? + CKK_DES2 : CKK_DES3); } else { throw new InvalidParameterException - ("Only " + significantKeySize + - "-bit DESede key length is supported"); + ("Only " + significantKeySize + + "-bit DESede is supported"); } } - break; - case (int)CKM_AES_KEY_GEN: - if ((keySize != 128) && (keySize != 192) && (keySize != 256)) { - throw new InvalidParameterException - ("AES key length must be 128, 192, or 256 bits"); - } - this.keySize = keySize; - significantKeySize = keySize; - break; - case (int)CKM_RC4_KEY_GEN: - case (int)CKM_BLOWFISH_KEY_GEN: - if ((keySize < minKeySize) || (keySize > maxKeySize)) { - throw new InvalidParameterException - (algorithm + " key length must be between " + - minKeySize + " and " + maxKeySize + " bits"); - } - this.keySize = keySize; - this.significantKeySize = keySize; - break; - default: - throw new ProviderException("Unknown mechanism " + mechanism); } + this.keySize = keySize; + this.significantKeySize = newSignificantKeySize; } // see JCE spec
--- a/jdk/src/share/classes/sun/security/pkcs11/P11KeyStore.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11KeyStore.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -156,10 +156,10 @@ // CKA_CLASS - entry type private CK_ATTRIBUTE type = null; - // CKA_LABEL of cert + // CKA_LABEL of cert and secret key private String label = null; - // CKA_ID - of private key/cert + // CKA_ID of the private key/cert pair private byte[] id = null; // CKA_TRUSTED - true if cert is trusted @@ -871,10 +871,8 @@ if ((token.tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) { token.provider.login(null, handler); } else { - // token supports protected authentication path // (external pin-pad, for example) - if (handler != null && !token.config.getKeyStoreCompatibilityMode()) { throw new LoginException("can not specify password if token " + @@ -1130,19 +1128,14 @@ SecretKey skey = ske.getSecretKey(); try { - // first see if the key already exists. - // if so, update the CKA_LABEL - if (!updateSkey(alias)) { + // first check if the key already exists + AliasInfo aliasInfo = aliasMap.get(alias); - // key entry does not exist. - // delete existing entry for alias and - // create new secret key entry - // (new entry might be a secret key - // session object converted into a token object) + if (aliasInfo != null) { + engineDeleteEntry(alias); + } + storeSkey(alias, ske); - engineDeleteEntry(alias); - storeSkey(alias, ske); - } } catch (PKCS11Exception pe) { throw new KeyStoreException(pe); } @@ -1396,41 +1389,6 @@ } } - /** - * return true if update occurred - */ - private boolean updateSkey(String alias) - throws KeyStoreException, PKCS11Exception { - - Session session = null; - try { - session = token.getOpSession(); - - // first update existing secret key CKA_LABEL - - THandle h = getTokenObject(session, ATTR_CLASS_SKEY, null, alias); - if (h.type != ATTR_CLASS_SKEY) { - if (debug != null) { - debug.println("did not find secret key " + - "with CKA_LABEL [" + alias + "]"); - } - return false; - } - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] { - new CK_ATTRIBUTE(CKA_LABEL, alias) }; - token.p11.C_SetAttributeValue(session.id(), h.handle, attrs); - - if (debug != null) { - debug.println("updateSkey set new alias [" + - alias + - "] for secret key entry"); - } - - return true; - } finally { - token.releaseSession(session); - } - } /** * XXX On ibutton, when you C_SetAttribute(CKA_ID) for a private key @@ -1532,30 +1490,6 @@ } } - private void updateP11Skey(String alias, P11Key key) - throws PKCS11Exception { - - Session session = null; - try { - session = token.getOpSession(); - - // session key - convert to token key and set CKA_LABEL - - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] { - ATTR_TOKEN_TRUE, - new CK_ATTRIBUTE(CKA_LABEL, alias) }; - token.p11.C_CopyObject(session.id(), key.keyID, attrs); - if (debug != null) { - debug.println("updateP11Skey copied secret session key " + - "for [" + - alias + - "] to token entry"); - } - } finally { - token.releaseSession(session); - } - } - private void updateP11Pkey(String alias, CK_ATTRIBUTE attribute, P11Key key) throws PKCS11Exception { @@ -1689,48 +1623,26 @@ throws PKCS11Exception, KeyStoreException { SecretKey skey = ske.getSecretKey(); - long keyType = CKK_GENERIC_SECRET; - - if (skey instanceof P11Key && this.token == ((P11Key)skey).token) { - updateP11Skey(alias, (P11Key)skey); - return; + // No need to specify CKA_CLASS, CKA_KEY_TYPE, CKA_VALUE since + // they are handled in P11SecretKeyFactory.createKey() method. + CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] { + ATTR_SKEY_TOKEN_TRUE, + ATTR_PRIVATE_TRUE, + new CK_ATTRIBUTE(CKA_LABEL, alias), + }; + try { + P11SecretKeyFactory.convertKey(token, skey, null, attrs); + } catch (InvalidKeyException ike) { + // re-throw KeyStoreException to match javadoc + throw new KeyStoreException("Cannot convert to PKCS11 keys", ike); } - if ("AES".equalsIgnoreCase(skey.getAlgorithm())) { - keyType = CKK_AES; - } else if ("Blowfish".equalsIgnoreCase(skey.getAlgorithm())) { - keyType = CKK_BLOWFISH; - } else if ("DES".equalsIgnoreCase(skey.getAlgorithm())) { - keyType = CKK_DES; - } else if ("DESede".equalsIgnoreCase(skey.getAlgorithm())) { - keyType = CKK_DES3; - } else if ("RC4".equalsIgnoreCase(skey.getAlgorithm()) || - "ARCFOUR".equalsIgnoreCase(skey.getAlgorithm())) { - keyType = CKK_RC4; - } + // update global alias map + aliasMap.put(alias, new AliasInfo(alias)); - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] { - ATTR_SKEY_TOKEN_TRUE, - ATTR_CLASS_SKEY, - ATTR_PRIVATE_TRUE, - new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType), - new CK_ATTRIBUTE(CKA_LABEL, alias), - new CK_ATTRIBUTE(CKA_VALUE, skey.getEncoded()) }; - attrs = token.getAttributes - (TemplateManager.O_IMPORT, CKO_SECRET_KEY, keyType, attrs); - - // create the new entry - Session session = null; - try { - session = token.getOpSession(); - token.p11.C_CreateObject(session.id(), attrs); - if (debug != null) { - debug.println("storeSkey created token secret key for [" + - alias + - "]"); - } - } finally { - token.releaseSession(session); + if (debug != null) { + debug.println("storeSkey created token secret key for [" + + alias + "]"); } } @@ -2492,7 +2404,8 @@ // if there are duplicates (either between secret keys, // or between a secret key and another object), // throw an exception - HashSet<String> sKeySet = new HashSet<String>(); + HashMap<String, AliasInfo> sKeyMap = + new HashMap<String, AliasInfo>(); attrs = new CK_ATTRIBUTE[] { ATTR_SKEY_TOKEN_TRUE, @@ -2507,8 +2420,8 @@ // there is a CKA_LABEL String cka_label = new String(attrs[0].getCharArray()); - if (!sKeySet.contains(cka_label)) { - sKeySet.add(cka_label); + if (sKeyMap.get(cka_label) == null) { + sKeyMap.put(cka_label, new AliasInfo(cka_label)); } else { throw new KeyStoreException("invalid KeyStore state: " + "found multiple secret keys sharing same " + @@ -2523,7 +2436,7 @@ ArrayList<AliasInfo> matchedCerts = mapPrivateKeys(pkeyIDs, certMap); boolean sharedLabel = mapCerts(matchedCerts, certMap); - mapSecretKeys(sKeySet); + mapSecretKeys(sKeyMap); return sharedLabel; @@ -2547,7 +2460,7 @@ HashMap<String, HashSet<AliasInfo>> certMap) throws PKCS11Exception, CertificateException { - // global alias map + // reset global alias map aliasMap = new HashMap<String, AliasInfo>(); // list of matched certs that we will return @@ -2722,18 +2635,17 @@ * If the secret key shares a CKA_LABEL with another entry, * throw an exception */ - private void mapSecretKeys(HashSet<String> sKeySet) + private void mapSecretKeys(HashMap<String, AliasInfo> sKeyMap) throws KeyStoreException { - for (String label : sKeySet) { - if (!aliasMap.containsKey(label)) { - aliasMap.put(label, new AliasInfo(label)); - } else { + for (String label : sKeyMap.keySet()) { + if (aliasMap.containsKey(label)) { throw new KeyStoreException("invalid KeyStore state: " + "found secret key sharing CKA_LABEL [" + label + "] with another token object"); } } + aliasMap.putAll(sKeyMap); } private void dumpTokenMap() {
--- a/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -98,7 +98,6 @@ this.token = token; this.algorithm = "RSA"; this.mechanism = mechanism; - session = token.getOpSession(); } // modes do not make sense for RSA, but allow ECB @@ -184,7 +183,8 @@ throw new InvalidKeyException ("Wrap has to be used with public keys"); } - // No further setup needed for C_Wrap(). We remain uninitialized. + // No further setup needed for C_Wrap(). We'll initialize later if + // we can't use C_Wrap(). return; } else if (opmode == Cipher.UNWRAP_MODE) { if (p11Key.isPrivate() == false) { @@ -383,7 +383,8 @@ return implDoFinal(out, outOfs, out.length - outOfs); } - private byte[] doFinal() throws BadPaddingException, IllegalBlockSizeException { + private byte[] doFinal() throws BadPaddingException, + IllegalBlockSizeException { byte[] t = new byte[2048]; int n = implDoFinal(t, 0, t.length); byte[] out = new byte[n]; @@ -394,20 +395,37 @@ // see JCE spec protected byte[] engineWrap(Key key) throws InvalidKeyException, IllegalBlockSizeException { - // XXX Note that if we cannot convert key to a key on this token, - // we will fail. For example, trying a wrap an AES key on a token that - // does not support AES. - // We could implement a fallback that just encrypts the encoding - // (assuming the key is not sensitive). For now, we are operating under - // the assumption that this is not necessary. String keyAlg = key.getAlgorithm(); - P11Key secretKey = P11SecretKeyFactory.convertKey(token, key, keyAlg); + P11Key sKey = null; + try { + // The conversion may fail, e.g. trying to wrap an AES key on + // a token that does not support AES, or when the key size is + // not within the range supported by the token. + sKey = P11SecretKeyFactory.convertKey(token, key, keyAlg); + } catch (InvalidKeyException ike) { + byte[] toBeWrappedKey = key.getEncoded(); + if (toBeWrappedKey == null) { + throw new InvalidKeyException + ("wrap() failed, no encoding available", ike); + } + // Directly encrypt the key encoding when key conversion failed + implInit(Cipher.ENCRYPT_MODE, p11Key); + implUpdate(toBeWrappedKey, 0, toBeWrappedKey.length); + try { + return doFinal(); + } catch (BadPaddingException bpe) { + // should not occur + throw new InvalidKeyException("wrap() failed", bpe); + } finally { + // Restore original mode + implInit(Cipher.WRAP_MODE, p11Key); + } + } Session s = null; try { s = token.getOpSession(); - byte[] b = token.p11.C_WrapKey(s.id(), new CK_MECHANISM(mechanism), - p11Key.keyID, secretKey.keyID); - return b; + return token.p11.C_WrapKey(s.id(), new CK_MECHANISM(mechanism), + p11Key.keyID, sKey.keyID); } catch (PKCS11Exception e) { throw new InvalidKeyException("wrap() failed", e); } finally { @@ -431,11 +449,13 @@ }; attributes = token.getAttributes (O_IMPORT, CKO_SECRET_KEY, keyType, attributes); - long keyID = token.p11.C_UnwrapKey(s.id(), new CK_MECHANISM(mechanism), - p11Key.keyID, wrappedKey, attributes); - return P11Key.secretKey(session, keyID, algorithm, 48 << 3, attributes); + long keyID = token.p11.C_UnwrapKey(s.id(), + new CK_MECHANISM(mechanism), p11Key.keyID, wrappedKey, + attributes); + return P11Key.secretKey(session, keyID, algorithm, 48 << 3, + attributes); } catch (PKCS11Exception e) { - throw new InvalidKeyException("wrap() failed", e); + throw new InvalidKeyException("unwrap() failed", e); } finally { token.releaseSession(s); }
--- a/jdk/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -104,9 +104,20 @@ /** * Convert an arbitrary key of algorithm into a P11Key of provider. - * Used engineTranslateKey(), P11Cipher.init(), and P11Mac.init(). + * Used in engineTranslateKey(), P11Cipher.init(), and P11Mac.init(). */ - static P11Key convertKey(Token token, Key key, String algorithm) + static P11Key convertKey(Token token, Key key, String algo) + throws InvalidKeyException { + return convertKey(token, key, algo, null); + } + + /** + * Convert an arbitrary key of algorithm w/ custom attributes into a + * P11Key of provider. + * Used in P11KeyStore.storeSkey. + */ + static P11Key convertKey(Token token, Key key, String algo, + CK_ATTRIBUTE[] extraAttrs) throws InvalidKeyException { token.ensureValid(); if (key == null) { @@ -115,25 +126,41 @@ if (key instanceof SecretKey == false) { throw new InvalidKeyException("Key must be a SecretKey"); } - long algorithmType; - if (algorithm == null) { - algorithm = key.getAlgorithm(); - algorithmType = getKeyType(algorithm); + long algoType; + if (algo == null) { + algo = key.getAlgorithm(); + algoType = getKeyType(algo); } else { - algorithmType = getKeyType(algorithm); + algoType = getKeyType(algo); long keyAlgorithmType = getKeyType(key.getAlgorithm()); - if (algorithmType != keyAlgorithmType) { - if ((algorithmType == PCKK_HMAC) || (algorithmType == PCKK_SSLMAC)) { + if (algoType != keyAlgorithmType) { + if ((algoType == PCKK_HMAC) || (algoType == PCKK_SSLMAC)) { // ignore key algorithm for MACs } else { throw new InvalidKeyException - ("Key algorithm must be " + algorithm); + ("Key algorithm must be " + algo); } } } if (key instanceof P11Key) { P11Key p11Key = (P11Key)key; if (p11Key.token == token) { + if (extraAttrs != null) { + Session session = null; + try { + session = token.getObjSession(); + long newKeyID = token.p11.C_CopyObject(session.id(), + p11Key.keyID, extraAttrs); + p11Key = (P11Key) (P11Key.secretKey(p11Key.session, + newKeyID, p11Key.algorithm, p11Key.keyLength, + extraAttrs)); + } catch (PKCS11Exception p11e) { + throw new InvalidKeyException + ("Cannot duplicate the PKCS11 key", p11e); + } finally { + token.releaseSession(session); + } + } return p11Key; } } @@ -141,11 +168,11 @@ if (p11Key != null) { return p11Key; } - if ("RAW".equals(key.getFormat()) == false) { + if ("RAW".equalsIgnoreCase(key.getFormat()) == false) { throw new InvalidKeyException("Encoded format must be RAW"); } byte[] encoded = key.getEncoded(); - p11Key = createKey(token, encoded, algorithm, algorithmType); + p11Key = createKey(token, encoded, algo, algoType, extraAttrs); token.secretCache.put(key, p11Key); return p11Key; } @@ -159,79 +186,79 @@ } private static P11Key createKey(Token token, byte[] encoded, - String algorithm, long keyType) throws InvalidKeyException { - int n = encoded.length; - int keyLength; - switch ((int)keyType) { - case (int)CKK_RC4: - if ((n < 5) || (n > 128)) { - throw new InvalidKeyException - ("ARCFOUR key length must be between 5 and 128 bytes"); + String algorithm, long keyType, CK_ATTRIBUTE[] extraAttrs) + throws InvalidKeyException { + int n = encoded.length << 3; + int keyLength = n; + try { + switch ((int)keyType) { + case (int)CKK_DES: + keyLength = + P11KeyGenerator.checkKeySize(CKM_DES_KEY_GEN, n, token); + fixDESParity(encoded, 0); + break; + case (int)CKK_DES3: + keyLength = + P11KeyGenerator.checkKeySize(CKM_DES3_KEY_GEN, n, token); + fixDESParity(encoded, 0); + fixDESParity(encoded, 8); + if (keyLength == 112) { + keyType = CKK_DES2; + } else { + keyType = CKK_DES3; + fixDESParity(encoded, 16); + } + break; + case (int)CKK_AES: + keyLength = + P11KeyGenerator.checkKeySize(CKM_AES_KEY_GEN, n, token); + break; + case (int)CKK_RC4: + keyLength = + P11KeyGenerator.checkKeySize(CKM_RC4_KEY_GEN, n, token); + break; + case (int)CKK_BLOWFISH: + keyLength = + P11KeyGenerator.checkKeySize(CKM_BLOWFISH_KEY_GEN, n, + token); + break; + case (int)CKK_GENERIC_SECRET: + case (int)PCKK_TLSPREMASTER: + case (int)PCKK_TLSRSAPREMASTER: + case (int)PCKK_TLSMASTER: + keyType = CKK_GENERIC_SECRET; + break; + case (int)PCKK_SSLMAC: + case (int)PCKK_HMAC: + if (n == 0) { + throw new InvalidKeyException + ("MAC keys must not be empty"); + } + keyType = CKK_GENERIC_SECRET; + break; + default: + throw new InvalidKeyException("Unknown algorithm " + + algorithm); } - keyLength = n << 3; - break; - case (int)CKK_DES: - if (n != 8) { - throw new InvalidKeyException - ("DES key length must be 8 bytes"); - } - keyLength = 56; - fixDESParity(encoded, 0); - break; - case (int)CKK_DES3: - if (n == 16) { - keyType = CKK_DES2; - } else if (n == 24) { - keyType = CKK_DES3; - fixDESParity(encoded, 16); - } else { - throw new InvalidKeyException - ("DESede key length must be 16 or 24 bytes"); - } - fixDESParity(encoded, 0); - fixDESParity(encoded, 8); - keyLength = n * 7; - break; - case (int)CKK_AES: - if ((n != 16) && (n != 24) && (n != 32)) { - throw new InvalidKeyException - ("AES key length must be 16, 24, or 32 bytes"); - } - keyLength = n << 3; - break; - case (int)CKK_BLOWFISH: - if ((n < 5) || (n > 56)) { - throw new InvalidKeyException - ("Blowfish key length must be between 5 and 56 bytes"); - } - keyLength = n << 3; - break; - case (int)CKK_GENERIC_SECRET: - case (int)PCKK_TLSPREMASTER: - case (int)PCKK_TLSRSAPREMASTER: - case (int)PCKK_TLSMASTER: - keyType = CKK_GENERIC_SECRET; - keyLength = n << 3; - break; - case (int)PCKK_SSLMAC: - case (int)PCKK_HMAC: - if (n == 0) { - throw new InvalidKeyException - ("MAC keys must not be empty"); - } - keyType = CKK_GENERIC_SECRET; - keyLength = n << 3; - break; - default: - throw new InvalidKeyException("Unknown algorithm " + algorithm); + } catch (InvalidAlgorithmParameterException iape) { + throw new InvalidKeyException("Invalid key for " + algorithm, + iape); + } catch (ProviderException pe) { + throw new InvalidKeyException("Could not create key", pe); } Session session = null; try { - CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] { - new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY), - new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType), - new CK_ATTRIBUTE(CKA_VALUE, encoded), - }; + CK_ATTRIBUTE[] attributes; + if (extraAttrs != null) { + attributes = new CK_ATTRIBUTE[3 + extraAttrs.length]; + System.arraycopy(extraAttrs, 0, attributes, 3, + extraAttrs.length); + } else { + attributes = new CK_ATTRIBUTE[3]; + } + attributes[0] = new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY); + attributes[1] = new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType); + attributes[2] = new CK_ATTRIBUTE(CKA_VALUE, encoded); attributes = token.getAttributes (O_IMPORT, CKO_SECRET_KEY, keyType, attributes); session = token.getObjSession(); @@ -280,7 +307,7 @@ private byte[] getKeyBytes(SecretKey key) throws InvalidKeySpecException { try { key = engineTranslateKey(key); - if ("RAW".equals(key.getFormat()) == false) { + if ("RAW".equalsIgnoreCase(key.getFormat()) == false) { throw new InvalidKeySpecException ("Could not obtain key bytes"); }
--- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. 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 @@ -601,14 +601,26 @@ // XXX attributes for Ciphers (supported modes, padding) d(CIP, "ARCFOUR", P11Cipher, s("RC4"), m(CKM_RC4)); - // XXX only CBC/NoPadding for block ciphers d(CIP, "DES/CBC/NoPadding", P11Cipher, m(CKM_DES_CBC)); + d(CIP, "DES/CBC/PKCS5Padding", P11Cipher, + m(CKM_DES_CBC_PAD, CKM_DES_CBC)); + d(CIP, "DES/ECB", P11Cipher, s("DES"), + m(CKM_DES_ECB)); + d(CIP, "DESede/CBC/NoPadding", P11Cipher, m(CKM_DES3_CBC)); + d(CIP, "DESede/CBC/PKCS5Padding", P11Cipher, + m(CKM_DES3_CBC_PAD, CKM_DES3_CBC)); + d(CIP, "DESede/ECB", P11Cipher, s("DESede"), + m(CKM_DES3_ECB)); d(CIP, "AES/CBC/NoPadding", P11Cipher, m(CKM_AES_CBC)); - d(CIP, "Blowfish/CBC/NoPadding", P11Cipher, + d(CIP, "AES/CBC/PKCS5Padding", P11Cipher, + m(CKM_AES_CBC_PAD, CKM_AES_CBC)); + d(CIP, "AES/ECB", P11Cipher, s("AES"), + m(CKM_AES_ECB)); + d(CIP, "Blowfish/CBC", P11Cipher, m(CKM_BLOWFISH_CBC)); // XXX RSA_X_509, RSA_OAEP not yet supported
--- a/jdk/src/share/classes/sun/security/validator/EndEntityChecker.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/classes/sun/security/validator/EndEntityChecker.java Wed Apr 23 06:35:28 2008 -0400 @@ -87,6 +87,9 @@ // the Microsoft Server-Gated-Cryptography EKU extension OID private final static String OID_EKU_MS_SGC = "1.3.6.1.4.1.311.10.3.3"; + // the recognized extension OIDs + private final static String OID_SUBJECT_ALT_NAME = "2.5.29.17"; + private final static String NSCT_SSL_CLIENT = NetscapeCertTypeExtension.SSL_CLIENT; @@ -171,6 +174,13 @@ throws CertificateException { // basic constraints irrelevant in EE certs exts.remove(SimpleValidator.OID_BASIC_CONSTRAINTS); + + // If the subject field contains an empty sequence, the subjectAltName + // extension MUST be marked critical. + // We do not check the validity of the critical extension, just mark + // it recognizable here. + exts.remove(OID_SUBJECT_ALT_NAME); + if (!exts.isEmpty()) { throw new CertificateException("Certificate contains unsupported " + "critical extensions: " + exts);
--- a/jdk/src/share/instrument/InvocationAdapter.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/InvocationAdapter.c Wed Apr 23 06:35:28 2008 -0400 @@ -626,6 +626,7 @@ jvmtiError jvmtierr; jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile); + check_phase_ret_1(jvmtierr); if (jvmtierr == JVMTI_ERROR_NONE) { return 0; @@ -634,6 +635,7 @@ jvmtiError err; err = (*jvmtienv)->GetPhase(jvmtienv, &phase); + /* can be called from any phase */ jplis_assert(err == JVMTI_ERROR_NONE); if (phase == JVMTI_PHASE_LIVE) { @@ -805,6 +807,8 @@ /* print warning if boot class path not updated */ if (jvmtierr != JVMTI_ERROR_NONE) { + check_phase_blob_ret(jvmtierr, free(path)); + fprintf(stderr, "WARNING: %s not added to bootstrap class loader search: ", path); switch (jvmtierr) { case JVMTI_ERROR_ILLEGAL_ARGUMENT :
--- a/jdk/src/share/instrument/JPLISAgent.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/JPLISAgent.c Wed Apr 23 06:35:28 2008 -0400 @@ -179,6 +179,7 @@ jvmtierror = (*jvmtienv)->GetEnvironmentLocalStorage( jvmtienv, (void**)&environment); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); if (jvmtierror == JVMTI_ERROR_NONE) { @@ -230,6 +231,7 @@ /* don't leak envs */ if ( initerror != JPLIS_INIT_ERROR_NONE ) { jvmtiError jvmtierror = (*jvmtienv)->DisposeEnvironment(jvmtienv); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } } @@ -259,7 +261,7 @@ agent->mNormalEnvironment.mIsRetransformer = JNI_FALSE; agent->mRetransformEnvironment.mJVMTIEnv = NULL; /* NULL until needed */ agent->mRetransformEnvironment.mAgent = agent; - agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE; + agent->mRetransformEnvironment.mIsRetransformer = JNI_FALSE; /* JNI_FALSE until mJVMTIEnv is set */ agent->mAgentmainCaller = NULL; agent->mInstrumentationImpl = NULL; agent->mPremainCaller = NULL; @@ -277,18 +279,25 @@ jvmtierror = (*jvmtienv)->SetEnvironmentLocalStorage( jvmtienv, &(agent->mNormalEnvironment)); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); /* check what capabilities are available */ checkCapabilities(agent); /* check phase - if live phase then we don't need the VMInit event */ - jvmtierror == (*jvmtienv)->GetPhase(jvmtienv, &phase); + jvmtierror = (*jvmtienv)->GetPhase(jvmtienv, &phase); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); if (phase == JVMTI_PHASE_LIVE) { return JPLIS_INIT_ERROR_NONE; } + if (phase != JVMTI_PHASE_ONLOAD) { + /* called too early or called too late; either way bail out */ + return JPLIS_INIT_ERROR_FAILURE; + } + /* now turn on the VMInit event */ if ( jvmtierror == JVMTI_ERROR_NONE ) { jvmtiEventCallbacks callbacks; @@ -298,6 +307,7 @@ jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv, &callbacks, sizeof(callbacks)); + check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -307,6 +317,7 @@ JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL /* all threads */); + check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -622,6 +633,7 @@ jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv, &callbacks, sizeof(callbacks)); + check_phase_ret_false(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); @@ -632,6 +644,7 @@ JVMTI_DISABLE, JVMTI_EVENT_VM_INIT, NULL /* all threads */); + check_phase_ret_false(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -642,6 +655,7 @@ JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL /* all threads */); + check_phase_ret_false(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -660,6 +674,7 @@ memset(&potentialCapabilities, 0, sizeof(potentialCapabilities)); jvmtierror = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &potentialCapabilities); + check_phase_ret(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); if ( jvmtierror == JVMTI_ERROR_NONE ) { @@ -681,9 +696,11 @@ jvmtiError jvmtierror; jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); desiredCapabilities.can_set_native_method_prefix = 1; jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities); + check_phase_ret(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -715,9 +732,11 @@ jvmtiError jvmtierror; jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); desiredCapabilities.can_maintain_original_method_order = 1; jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities); + check_phase_ret(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); } @@ -732,9 +751,11 @@ if (agent->mRedefineAvailable && !agent->mRedefineAdded) { jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities); + /* can be called from any phase */ jplis_assert(jvmtierror == JVMTI_ERROR_NONE); desiredCapabilities.can_redefine_classes = 1; jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities); + check_phase_ret(jvmtierror); /* * With mixed premain/agentmain agents then it's possible that the @@ -998,6 +1019,7 @@ if (jvmtierror == JVMTI_ERROR_NONE) { // install the retransforming environment agent->mRetransformEnvironment.mJVMTIEnv = retransformerEnv; + agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE; // Make it for ClassFileLoadHook handling jvmtierror = (*retransformerEnv)->SetEnvironmentLocalStorage( @@ -1025,6 +1047,7 @@ jvmtierror = (*jvmtienv)->IsModifiableClass( jvmtienv, clazz, &is_modifiable); + check_phase_ret_false(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); return is_modifiable; @@ -1032,7 +1055,7 @@ jboolean isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent) { - return retransformableEnvironment(agent) != NULL; + return agent->mRetransformEnvironment.mIsRetransformer; } void @@ -1075,6 +1098,12 @@ numClasses = (*jnienv)->GetArrayLength(jnienv, classes); errorOccurred = checkForThrowable(jnienv); jplis_assert(!errorOccurred); + + if (!errorOccurred && numClasses == 0) { + jplis_assert(numClasses != 0); + errorOccurred = JNI_TRUE; + errorCode = JVMTI_ERROR_NULL_POINTER; + } } if (!errorOccurred) { @@ -1096,6 +1125,13 @@ if (errorOccurred) { break; } + + if (classArray[index] == NULL) { + jplis_assert(classArray[index] != NULL); + errorOccurred = JNI_TRUE; + errorCode = JVMTI_ERROR_NULL_POINTER; + break; + } } } @@ -1217,6 +1253,7 @@ if (!errorOccurred) { jvmtiError errorCode = JVMTI_ERROR_NONE; errorCode = (*jvmtienv)->RedefineClasses(jvmtienv, numDefs, classDefs); + check_phase_blob_ret(errorCode, deallocate(jvmtienv, (void*)classDefs)); errorOccurred = (errorCode != JVMTI_ERROR_NONE); if ( errorOccurred ) { createAndThrowThrowableFromJVMTIErrorCode(jnienv, errorCode); @@ -1250,6 +1287,7 @@ classLoader, &classCount, &classes); + check_phase_ret_blob(jvmtierror, localArray); errorOccurred = (jvmtierror != JVMTI_ERROR_NONE); jplis_assert(!errorOccurred); @@ -1311,6 +1349,7 @@ jvmtiError jvmtierror = JVMTI_ERROR_NONE; jvmtierror = (*jvmtienv)->GetObjectSize(jvmtienv, objectToSize, &objectSize); + check_phase_ret_0(jvmtierror); jplis_assert(jvmtierror == JVMTI_ERROR_NONE); if ( jvmtierror != JVMTI_ERROR_NONE ) { createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror); @@ -1360,6 +1399,7 @@ } else { jvmtierror = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, platformChars); } + check_phase_ret(jvmtierror); if ( jvmtierror != JVMTI_ERROR_NONE ) { createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror); @@ -1450,6 +1490,7 @@ } err = (*jvmtienv)->SetNativeMethodPrefixes(jvmtienv, inx, (char**)prefixes); + /* can be called from any phase */ jplis_assert(err == JVMTI_ERROR_NONE); for (i = 0; i < inx; i++) {
--- a/jdk/src/share/instrument/JPLISAgent.h Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/JPLISAgent.h Wed Apr 23 06:35:28 2008 -0400 @@ -266,6 +266,48 @@ #define jvmti(a) a->mNormalEnvironment.mJVMTIEnv +/* + * A set of macros for insulating the JLI method callers from + * JVMTI_ERROR_WRONG_PHASE return codes. + */ + +/* for a JLI method where "blob" is executed before simply returning */ +#define check_phase_blob_ret(ret, blob) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + blob; \ + return; \ + } + +/* for a JLI method where simply returning is benign */ +#define check_phase_ret(ret) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + return; \ + } + +/* for a JLI method where returning zero (0) is benign */ +#define check_phase_ret_0(ret) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + return 0; \ + } + +/* for a JLI method where returning one (1) is benign */ +#define check_phase_ret_1(ret) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + return 1; \ + } + +/* for a case where a specific "blob" must be returned */ +#define check_phase_ret_blob(ret, blob) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + return (blob); \ + } + +/* for a JLI method where returning false is benign */ +#define check_phase_ret_false(ret) \ + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \ + return (jboolean) 0; \ + } + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */
--- a/jdk/src/share/instrument/JarFacade.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/JarFacade.c Wed Apr 23 06:35:28 2008 -0400 @@ -23,6 +23,14 @@ * have any questions. */ +#ifdef _WIN32 +/* + * Win* needs this include. However, Linux and Solaris do not. + * Having this include on Solaris SPARC breaks having non US-ASCII + * characters in the value of the Premain-Class attribute. + */ +#include <ctype.h> +#endif /* _WIN32 */ #include <string.h> #include <stdlib.h> @@ -45,11 +53,37 @@ if (attribute->name == NULL) { free(attribute); } else { - attribute->value = strdup(value); + char *begin = (char *)value; + char *end; + size_t value_len; + + /* skip any leading white space */ + while (isspace(*begin)) { + begin++; + } + + /* skip any trailing white space */ + end = &begin[strlen(begin)]; + while (end > begin && isspace(end[-1])) { + end--; + } + + if (begin == end) { + /* no value so skip this attribute */ + free(attribute->name); + free(attribute); + return; + } + + value_len = (size_t)(end - begin); + attribute->value = malloc(value_len + 1); if (attribute->value == NULL) { free(attribute->name); free(attribute); } else { + /* save the value without leading or trailing whitespace */ + strncpy(attribute->value, begin, value_len); + attribute->value[value_len] = '\0'; attribute->next = NULL; if (context->head == NULL) { context->head = attribute;
--- a/jdk/src/share/instrument/Reentrancy.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/Reentrancy.c Wed Apr 23 06:35:28 2008 -0400 @@ -74,6 +74,7 @@ jvmtienv, thread, newValue); + check_phase_ret_blob(error, error); #if JPLISASSERT_ENABLEASSERTIONS assertTLSValue( jvmtienv, @@ -96,6 +97,7 @@ jvmtienv, thread, &test); + check_phase_ret(error); jplis_assert(error == JVMTI_ERROR_NONE); jplis_assert(test == expected); } @@ -111,6 +113,7 @@ jvmtienv, thread, &storedValue); + check_phase_ret_false(error); jplis_assert(error == JVMTI_ERROR_NONE); if ( error == JVMTI_ERROR_NONE ) { /* if this thread is already inside, just return false and short-circuit */
--- a/jdk/src/share/instrument/Utilities.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/share/instrument/Utilities.c Wed Apr 23 06:35:28 2008 -0400 @@ -46,6 +46,7 @@ error = (*jvmtienv)->Allocate(jvmtienv, bytecount, (unsigned char**) &resultBuffer); + /* may be called from any phase */ jplis_assert(error == JVMTI_ERROR_NONE); if ( error != JVMTI_ERROR_NONE ) { resultBuffer = NULL; @@ -66,6 +67,7 @@ error = (*jvmtienv)->Deallocate(jvmtienv, (unsigned char*)buffer); + /* may be called from any phase */ jplis_assert_msg(error == JVMTI_ERROR_NONE, "Can't deallocate memory"); return; }
--- a/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Wed Apr 23 06:35:28 2008 -0400 @@ -123,7 +123,10 @@ C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule, getFunctionListStr); (*env)->ReleaseStringUTFChars(env, jGetFunctionList, getFunctionListStr); } - if ((C_GetFunctionList == NULL) || ((systemErrorMessage = dlerror()) != NULL)){ + if (C_GetFunctionList == NULL) { + throwIOException(env, "ERROR: C_GetFunctionList == NULL"); + return; + } else if ( (systemErrorMessage = dlerror()) != NULL ){ throwIOException(env, systemErrorMessage); return; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticOptions.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6658779 + * @summary Basic Test for HotSpotDiagnosticMXBean.getDiagnosticOptions() + * @author Daniel Fuchs + * + * @run main GetDiagnosticOptions + */ + +import com.sun.management.HotSpotDiagnosticMXBean; +import com.sun.management.VMOption; +import java.lang.management.ManagementFactory; +import java.util.List; +import javax.management.MBeanServer; + +public class GetDiagnosticOptions { + private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = + "com.sun.management:type=HotSpotDiagnostic"; + + public static void main(String[] args) throws Exception { + HotSpotDiagnosticMXBean mbean = + sun.management.ManagementFactory.getDiagnosticMXBean(); + checkDiagnosticOptions(mbean); + + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + mbean = ManagementFactory.newPlatformMXBeanProxy(mbs, + HOTSPOT_DIAGNOSTIC_MXBEAN_NAME, + HotSpotDiagnosticMXBean.class); + checkDiagnosticOptions(mbean); + } + + private static void checkDiagnosticOptions(HotSpotDiagnosticMXBean mbean) { + List<VMOption> options = mbean.getDiagnosticOptions(); + for (VMOption opt : options) { + System.out.println("option: "+opt.getName()+"="+opt.getValue()); + } + } +}
--- a/jdk/test/java/lang/instrument/BootClassPath/BootClassPathTest.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/BootClassPath/BootClassPathTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -23,8 +23,10 @@ # @test # @bug 5055293 -# @summary Test non US-ASCII characters in the value of the Boot-Class-Path +# @summary Test non US-ASCII characters in the value of the Boot-Class-Path # attribute. +# +# @run shell/timeout=240 BootClassPathTest.sh if [ "${TESTJAVA}" = "" ] then @@ -72,7 +74,7 @@ echo "Running test..." -"${JAVA}" -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain +"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain result=$? echo "Cleanup..."
--- a/jdk/test/java/lang/instrument/MakeJAR2.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/MakeJAR2.sh Wed Apr 23 06:35:28 2008 -0400 @@ -70,9 +70,11 @@ cp ${TESTSRC}/${AGENT}.java . cp ${TESTSRC}/${APP}.java . rm -rf ilib -cp -r ${TESTSRC}/ilib . -mkdir bootpath -cp -r ${TESTSRC}/bootreporter bootpath +mkdir ilib +cp ${TESTSRC}/ilib/*.java ilib +rm -rf bootpath +mkdir -p bootpath/bootreporter +cp ${TESTSRC}/bootreporter/*.java bootpath/bootreporter cd bootpath ${JAVAC} bootreporter/*.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ManifestTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,483 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6274276 +# @summary JLI JAR manifest processing should ignore leading and trailing white space. +# @author Daniel D. Daugherty +# +# @run build ManifestTestApp +# @run shell/timeout=900 ManifestTest.sh +# + +make_a_JAR() { + # version_line and premain_line are required + version_line="Manifest-Version: 1.0" + premain_line="Premain-Class: ${AGENT}" + boot_cp_line="" + expect_boot_cp_line="ExampleForBootClassPath was not loaded." + can_redef_line="" + expect_redef_line="isRedefineClassesSupported()=false" + can_retrans_line="" + expect_retrans_line="isRetransformClassesSupported()=false" + can_set_nmp_line="" + expect_set_nmp_line="isNativeMethodPrefixSupported()=false" + + while [ $# != 0 ] ; do + case "$1" in + defaults) + # just use the defaults for the test + ;; + + boot_cp_line1) + boot_cp_line="Boot-Class-Path: no_white_space" + expect_boot_cp_line="ExampleForBootClassPath was loaded." + mkdir -p no_white_space + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space + ;; + + boot_cp_line2) + boot_cp_line="Boot-Class-Path: has_leading_blank" + expect_boot_cp_line="ExampleForBootClassPath was loaded." + mkdir -p has_leading_blank " has_leading_blank" + # the good class is in the directory without the blank + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ + has_leading_blank + # the bad class is in the directory with the blank + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ + " has_leading_blank"/ExampleForBootClassPath.class + ;; + + boot_cp_line3) + boot_cp_line="Boot-Class-Path: has_trailing_blank " + expect_boot_cp_line="ExampleForBootClassPath was loaded." + mkdir -p has_trailing_blank "has_trailing_blank " + # the good class is in the directory without the blank + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ + has_trailing_blank + # the bad class is in the directory with the blank + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ + "has_trailing_blank "/ExampleForBootClassPath.class + ;; + + boot_cp_line4) + boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank " + expect_boot_cp_line="ExampleForBootClassPath was loaded." + mkdir -p has_leading_and_trailing_blank \ + " has_leading_and_trailing_blank " + # the good class is in the directory without the blanks + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ + has_leading_and_trailing_blank + # the bad class is in the directory with the blanks + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ + " has_leading_and_trailing_blank "/ExampleForBootClassPath.class + ;; + + boot_cp_line5) + boot_cp_line="Boot-Class-Path: has_embedded blank" + expect_boot_cp_line="ExampleForBootClassPath was loaded." + mkdir -p has_embedded "has_embedded blank" + # the good class is in the first blank separated word + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded + # the bad class is in the directory with the blank + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ + "has_embedded blank"/ExampleForBootClassPath.class + ;; + + can_redef_line1) + can_redef_line="Can-Redefine-Classes: true" + expect_redef_line="isRedefineClassesSupported()=true" + ;; + + can_redef_line2) + can_redef_line="Can-Redefine-Classes: true" + expect_redef_line="isRedefineClassesSupported()=true" + ;; + + can_redef_line3) + can_redef_line="Can-Redefine-Classes: true " + expect_redef_line="isRedefineClassesSupported()=true" + ;; + + can_redef_line4) + can_redef_line="Can-Redefine-Classes: true " + expect_redef_line="isRedefineClassesSupported()=true" + ;; + + can_redef_line5) + can_redef_line="Can-Redefine-Classes: false" + ;; + + can_redef_line6) + can_redef_line="Can-Redefine-Classes: false" + ;; + + can_redef_line7) + can_redef_line="Can-Redefine-Classes: false " + ;; + + can_redef_line8) + can_redef_line="Can-Redefine-Classes: false " + ;; + + can_redef_line9) + # this line makes the jar command unhappy and that's + # not what we're testing so skip this case + can_redef_line="Can-Redefine-Classes:" + ;; + + can_redef_line10) + can_redef_line="Can-Redefine-Classes: " + ;; + + can_redef_line11) + can_redef_line="Can-Redefine-Classes: " + ;; + + can_retrans_line1) + can_retrans_line="Can-Retransform-Classes: true" + expect_retrans_line="isRetransformClassesSupported()=true" + ;; + + can_retrans_line2) + can_retrans_line="Can-Retransform-Classes: true" + expect_retrans_line="isRetransformClassesSupported()=true" + ;; + + can_retrans_line3) + can_retrans_line="Can-Retransform-Classes: true " + expect_retrans_line="isRetransformClassesSupported()=true" + ;; + + can_retrans_line4) + can_retrans_line="Can-Retransform-Classes: true " + expect_retrans_line="isRetransformClassesSupported()=true" + ;; + + can_retrans_line5) + can_retrans_line="Can-Retransform-Classes: false" + ;; + + can_retrans_line6) + can_retrans_line="Can-Retransform-Classes: false" + ;; + + can_retrans_line7) + can_retrans_line="Can-Retransform-Classes: false " + ;; + + can_retrans_line8) + can_retrans_line="Can-Retransform-Classes: false " + ;; + + can_retrans_line9) + # this line makes the jar command unhappy and that's + # not what we're testing so skip this case + can_retrans_line="Can-Retransform-Classes:" + ;; + + can_retrans_line10) + can_retrans_line="Can-Retransform-Classes: " + ;; + + can_retrans_line11) + can_retrans_line="Can-Retransform-Classes: " + ;; + + can_set_nmp_line1) + can_set_nmp_line="Can-Set-Native-Method-Prefix: true" + expect_set_nmp_line="isNativeMethodPrefixSupported()=true" + ;; + + can_set_nmp_line2) + can_set_nmp_line="Can-Set-Native-Method-Prefix: true" + expect_set_nmp_line="isNativeMethodPrefixSupported()=true" + ;; + + can_set_nmp_line3) + can_set_nmp_line="Can-Set-Native-Method-Prefix: true " + expect_set_nmp_line="isNativeMethodPrefixSupported()=true" + ;; + + can_set_nmp_line4) + can_set_nmp_line="Can-Set-Native-Method-Prefix: true " + expect_set_nmp_line="isNativeMethodPrefixSupported()=true" + ;; + + can_set_nmp_line5) + can_set_nmp_line="Can-Set-Native-Method-Prefix: false" + ;; + + can_set_nmp_line6) + can_set_nmp_line="Can-Set-Native-Method-Prefix: false" + ;; + + can_set_nmp_line7) + can_set_nmp_line="Can-Set-Native-Method-Prefix: false " + ;; + + can_set_nmp_line8) + can_set_nmp_line="Can-Set-Native-Method-Prefix: false " + ;; + + can_set_nmp_line9) + # this line makes the jar command unhappy and that's + # not what we're testing so skip this case + can_set_nmp_line="Can-Set-Native-Method-Prefix:" + ;; + + can_set_nmp_line10) + can_set_nmp_line="Can-Set-Native-Method-Prefix: " + ;; + + can_set_nmp_line11) + can_set_nmp_line="Can-Set-Native-Method-Prefix: " + ;; + + premain_line1) + premain_line="Premain-Class: ${AGENT}" + ;; + + premain_line2) + premain_line="Premain-Class: ${AGENT} " + ;; + + premain_line3) + premain_line="Premain-Class: ${AGENT} " + ;; + + version_line1) + version_line="Manifest-Version: 1.0" + ;; + + version_line2) + version_line="Manifest-Version: 1.0 " + ;; + + version_line3) + version_line="Manifest-Version: 1.0 " + ;; + + *) + echo "ERROR: invalid test token" + exit 1 + esac + shift + done + + echo "${version_line}" > ${AGENT}.mf + echo "${premain_line}" >> ${AGENT}.mf + + if [ -n "$boot_cp_line" ]; then + echo "${boot_cp_line}" >> ${AGENT}.mf + fi + + if [ -n "$can_redef_line" ]; then + echo "${can_redef_line}" >> ${AGENT}.mf + fi + + if [ -n "$can_retrans_line" ]; then + echo "${can_retrans_line}" >> ${AGENT}.mf + fi + + if [ -n "$can_set_nmp_line" ]; then + echo "${can_set_nmp_line}" >> ${AGENT}.mf + fi + + rm -f ${AGENT}.jar + ${JAR} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class + + echo "$expect_boot_cp_line" > expect_boot_cp_line + echo "$expect_redef_line" > expect_redef_line + echo "$expect_retrans_line" > expect_retrans_line + echo "$expect_set_nmp_line" > expect_set_nmp_line +} + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAR="${TESTJAVA}/bin/jar" +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +# Now that ManifestTestApp.class is built, we move +# ExampleForBootClassPath.class so that it cannot be found +# by default +OUT_OF_THE_WAY=out_of_the_way +mkdir $OUT_OF_THE_WAY +mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY + +# create a bad version of ExampleForBootClassPath.class +# so we can tell when the wrong version is run +sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \ + > ExampleForBootClassPath.java +"$JAVAC" ExampleForBootClassPath.java +mv ExampleForBootClassPath.class \ + $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad +mv ExampleForBootClassPath.java \ + $OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad + +AGENT=ManifestTestAgent +# We compile the agent in the working directory instead of with +# a build task because we construct a different agent JAR file +# for each test case. +${JAVAC} -d . ${TESTSRC}/${AGENT}.java + +FAIL_MARKER=fail_marker +rm -f $FAIL_MARKER + +while read token; do + echo + echo "===== begin test case: $token =====" + make_a_JAR "$token" + + "${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \ + -classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1 + result=$? + + cat output.log + + if [ "$result" = 0 ]; then + echo "PASS: ManifestTestApp exited with status of 0." + else + echo "FAIL: ManifestTestApp exited with status of $result" + touch $FAIL_MARKER + fi + + MESG="Hello from ${AGENT}!" + grep -s "$MESG" output.log > /dev/null + result=$? + if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" + else + echo "FAIL: did NOT find '$MESG' in the test output" + touch $FAIL_MARKER + fi + + MESG=`cat expect_boot_cp_line` + grep -s "$MESG" output.log > /dev/null + result=$? + if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" + else + echo "FAIL: did NOT find '$MESG' in the test output" + touch $FAIL_MARKER + fi + + MESG=`cat expect_redef_line` + grep -s "$MESG" output.log > /dev/null + result=$? + if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" + else + echo "FAIL: did NOT find '$MESG' in the test output" + touch $FAIL_MARKER + fi + + MESG=`cat expect_retrans_line` + grep -s "$MESG" output.log > /dev/null + result=$? + if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" + else + echo "FAIL: did NOT find '$MESG' in the test output" + touch $FAIL_MARKER + fi + + MESG=`cat expect_set_nmp_line` + grep -s "$MESG" output.log > /dev/null + result=$? + if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" + else + echo "FAIL: did NOT find '$MESG' in the test output" + touch $FAIL_MARKER + fi + + echo "===== end test case: $token =====" + echo +done << EOF +defaults +version_line1 +version_line2 +version_line3 +premain_line1 +premain_line2 +premain_line3 +boot_cp_line1 +boot_cp_line2 +boot_cp_line3 +boot_cp_line4 +boot_cp_line5 +can_redef_line1 +can_redef_line2 +can_redef_line3 +can_redef_line4 +can_redef_line5 +can_redef_line6 +can_redef_line7 +can_redef_line8 +can_redef_line10 +can_redef_line11 +can_retrans_line1 +can_retrans_line2 +can_retrans_line3 +can_retrans_line4 +can_retrans_line5 +can_retrans_line6 +can_retrans_line7 +can_retrans_line8 +can_retrans_line10 +can_retrans_line11 +can_set_nmp_line1 +can_set_nmp_line2 +can_set_nmp_line3 +can_set_nmp_line4 +can_set_nmp_line5 +can_set_nmp_line6 +can_set_nmp_line7 +can_set_nmp_line8 +can_set_nmp_line10 +can_set_nmp_line11 +EOF + +if [ -f $FAIL_MARKER ]; then + exit 1 +else + exit 0 +fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ManifestTestAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.Instrumentation; + +public class ManifestTestAgent { + private static Instrumentation instrumentation; + + private ManifestTestAgent() { + } + + public static void premain(String agentArgs, Instrumentation inst) { + System.out.println("Hello from ManifestTestAgent!"); + System.out.println("isNativeMethodPrefixSupported()=" + + inst.isNativeMethodPrefixSupported()); + System.out.println("isRedefineClassesSupported()=" + + inst.isRedefineClassesSupported()); + System.out.println("isRetransformClassesSupported()=" + + inst.isRetransformClassesSupported()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ManifestTestApp.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,69 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +public class ManifestTestApp { + public static void main(String args[]) { + System.out.println("Hello from ManifestTestApp!"); + + new ManifestTestApp().doTest(); + System.exit(0); + } + + private void doTest() { + try { + // load the class only found via the Boot-Class-Path attribute + Object instance = loadExampleClass(); + if (instance.getClass().getClassLoader() == null) { + System.out.println("PASS: ExampleForBootClassPath was loaded" + + " by the boot class path loader."); + } else { + System.out.println("FAIL: ExampleForBootClassPath was loaded" + + " by a non-boot class path loader."); + System.exit(1); + } + } catch (NoClassDefFoundError ncdfe) { + // This message just lets ManifestTest.sh know whether or + // not ExampleForBootClassPath was loaded. Depending on + // the current test case, that will be either a PASSing + // condition or a FAILing condition as determined by + // ManifestTest.sh. + System.out.println("ExampleForBootClassPath was not loaded."); + } + } + + Object loadExampleClass() { + ExampleForBootClassPath instance = new ExampleForBootClassPath(); + System.out.println("ExampleForBootClassPath was loaded."); + if (instance.fifteen() == 15) { + System.out.println("PASS: the correct" + + " ExampleForBootClassPath was loaded."); + } else { + System.out.println("FAIL: the wrong ExampleForBootClassPath" + + " was loaded."); + System.out.println("FAIL: instance.fifteen()=" + + instance.fifteen()); + System.exit(1); + } + return instance; + } +}
--- a/jdk/test/java/lang/instrument/NativeMethodPrefixAgent.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/NativeMethodPrefixAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -27,7 +27,7 @@ * @summary test setNativeMethodPrefix * @author Robert Field, Sun Microsystems * - * @run shell MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true' + * @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true' * @run main/othervm -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ParallelTransformerLoader.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,72 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 5088398 +# @summary Test parallel class loading by parallel transformers. +# @author Daniel D. Daugherty as modified from the code of Daryl Puryear @ Wily +# +# @run shell MakeJAR3.sh ParallelTransformerLoaderAgent +# @run build ParallelTransformerLoaderApp +# @run shell/timeout=240 ParallelTransformerLoader.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAR="${TESTJAVA}"/bin/jar +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +"${JAVAC}" -d . \ + "${TESTSRC}"/TestClass1.java \ + "${TESTSRC}"/TestClass2.java \ + "${TESTSRC}"/TestClass3.java + +"${JAR}" cvf Test.jar Test*.class +# Removing the test class files is important. If these +# .class files are available on the classpath other +# than via Test.jar, then the deadlock will not reproduce. +rm -f Test*.class + +"${JAVA}" ${TESTVMOPTS} -javaagent:ParallelTransformerLoaderAgent.jar=Test.jar \ + -classpath "${TESTCLASSES}" ParallelTransformerLoaderApp +result=$? +echo "result=$result" + +exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ParallelTransformerLoaderAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,120 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.*; +import java.net.*; +import java.io.*; +import java.security.*; + +/** + * Test Java Agent + * + * @author Daryl Puryear + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. + */ +public class ParallelTransformerLoaderAgent +{ + private static URL sURL; + private static ClassLoader sClassLoader; + + public static synchronized ClassLoader + getClassLoader() + { + return sClassLoader; + } + + public static synchronized void + generateNewClassLoader() + { + sClassLoader = new URLClassLoader(new URL[] {sURL}); + } + + public static void + premain( String agentArgs, + Instrumentation instrumentation) + throws Exception + { + if (agentArgs == null || agentArgs == "") + { + System.err.println("Error: No jar file name provided, test will not run."); + return; + } + + sURL = (new File(agentArgs)).toURL(); + System.out.println("Using jar file: " + sURL); + generateNewClassLoader(); + + instrumentation.addTransformer(new TestTransformer()); + } + + private static class TestTransformer + implements ClassFileTransformer + { + public byte[] + transform( ClassLoader loader, + String className, + Class classBeingRedefined, + ProtectionDomain protectionDomain, + byte[] classfileBuffer) + throws IllegalClassFormatException + { + String tName = Thread.currentThread().getName(); + // In 160_03 and older, transform() is called + // with the "system_loader_lock" held and that + // prevents the bootstrap class loaded from + // running in parallel. If we add a slight sleep + // delay here when the transform() call is not + // main or TestThread, then the deadlock in + // 160_03 and older is much more reproducible. + if (!tName.equals("main") && !tName.equals("TestThread")) { + System.out.println("Thread '" + tName + + "' has called transform()"); + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + } + } + + // load additional classes when called from other threads + if (!tName.equals("main")) + { + loadClasses(3); + } + return null; + } + + public static void + loadClasses( int index) + { + ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader(); + try + { + Class.forName("TestClass" + index, true, loader); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/ParallelTransformerLoaderApp.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,90 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * Test Java Program + * + * @author Daryl Puryear + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. + */ +public class ParallelTransformerLoaderApp +{ + private static final int kNumIterations = 1000; + + public static void + main( String[] args) + throws Exception + { + System.out.println(); + System.out.print("Starting test with " + kNumIterations + " iterations"); + for (int i = 0; i < kNumIterations; i++) + { + // load some classes from multiple threads (this thread and one other) + Thread testThread = new TestThread(2); + testThread.start(); + loadClasses(1); + + // log that it completed and reset for the next iteration + testThread.join(); + System.out.print("."); + ParallelTransformerLoaderAgent.generateNewClassLoader(); + } + + System.out.println(); + System.out.println("Test completed successfully"); + } + + private static class TestThread + extends Thread + { + private final int fIndex; + + public + TestThread( int index) + { + super("TestThread"); + + fIndex = index; + } + + public void + run() + { + loadClasses(fIndex); + } + } + + public static void + loadClasses( int index) + { + ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader(); + try + { + Class.forName("TestClass" + index, true, loader); + } + catch (Exception e) + { + e.printStackTrace(); + } + } +}
--- a/jdk/test/java/lang/instrument/PremainClass/DummyMain.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/PremainClass/DummyMain.java Wed Apr 23 06:35:28 2008 -0400 @@ -22,11 +22,10 @@ */ /* - * - * - * Used by PremainClassTest.sh - dummy "main application" which doesn't do anything + * dummy "Hello World"ish application for "premain" tests */ public class DummyMain { public static void main(String[] args) { + System.out.println("Hello from DummyMain!"); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0001.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,0,0,1): declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0001 + * @run main/othervm -javaagent:InheritAgent0001.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0001 extends InheritAgent0001Super { + + // + // This agent has a single argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0001!"); + } + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent0001Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0010.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,0,1,0): declared 2-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0010 + * @run main/othervm -javaagent:InheritAgent0010.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0010 extends InheritAgent0010Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent0010!"); + } +} + +class InheritAgent0010Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0011.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,0,1,1): declared 2-arg and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0011 + * @run main/othervm -javaagent:InheritAgent0011.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0011 extends InheritAgent0011Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0011!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent0011!"); + } +} + +class InheritAgent0011Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0100.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,1,0,0): inherited 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0100 + * @run main/othervm -javaagent:InheritAgent0100.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0100 extends InheritAgent0100Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent0100Super { + + // + // This agent has a single argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0100Super!"); + } + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0101.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,1,0,1): inherited 1-arg and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0101 + * @run main/othervm -javaagent:InheritAgent0101.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0101 extends InheritAgent0101Super { + + // + // This agent has a single argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0101!"); + } + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent0101Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0101Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0110.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,1,1,0): inherited 1-arg and declared 2-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0110 + * @run main/othervm -javaagent:InheritAgent0110.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0110 extends InheritAgent0110Super { + + // This agent does NOT have a one argument premain() method. + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent0110!"); + } +} + +class InheritAgent0110Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0110Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0111.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,69 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (0,1,1,1): inherited 1-arg, declared 2-arg and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent0111 + * @run main/othervm -javaagent:InheritAgent0111.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent0111 extends InheritAgent0111Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0111!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent0111!"); + } + +} + +class InheritAgent0111Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent0111Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // This agent does NOT have a double argument premain() method. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1000.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,0,0,0): inherited 2-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1000 + * @run main/othervm -javaagent:InheritAgent1000.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1000 extends InheritAgent1000Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent1000Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1000Super!"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1001.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,0,0,1): inherited 2-arg, and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1001 + * @run main/othervm -javaagent:InheritAgent1001.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1001 extends InheritAgent1001Super { + + // + // This agent has a single argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1001!"); + } + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent1001Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1001Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1010.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,0,1,0): inherited 2-arg, and declared 2-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1010 + * @run main/othervm -javaagent:InheritAgent1010.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1010 extends InheritAgent1010Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1010!"); + } +} + +class InheritAgent1010Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1010Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1011.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,0,1,1): inherited 2-arg, declared 2-arg and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1011 + * @run main/othervm -javaagent:InheritAgent1011.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1011 extends InheritAgent1011Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1011!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1011!"); + } +} + +class InheritAgent1011Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1011Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1100.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,1,0,0): inherited 2-arg and inherited 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1100 + * @run main/othervm -javaagent:InheritAgent1100.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1100 extends InheritAgent1100Super { + + // This agent does NOT have a single argument premain() method. + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent1100Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1100Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1100Super!"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1101.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,1,0,1): inherited 2-arg, inherited 1-arg, and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1101 + * @run main/othervm -javaagent:InheritAgent1101.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1101 extends InheritAgent1101Super { + + // + // This agent has a single argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1101!"); + } + + // This agent does NOT have a double argument premain() method. +} + +class InheritAgent1101Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1101Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1101Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1110.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,1,1,0): inherited 2-arg, inherited 1-arg, and declared 2-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1110 + * @run main/othervm -javaagent:InheritAgent1110.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1110 extends InheritAgent1110Super { + + // This agent does NOT have a single argument premain() method. + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1110!"); + } +} + +class InheritAgent1110Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1110Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1110Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1111.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,75 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6289149 + * @summary test config (1,1,1,1): inherited 2-arg, inherited 1-arg, declared 2-arg and declared 1-arg in agent class + * @author Daniel D. Daugherty, Sun Microsystems + * + * @run shell ../MakeJAR3.sh InheritAgent1111 + * @run main/othervm -javaagent:InheritAgent1111.jar DummyMain + */ + +import java.lang.instrument.*; + +class InheritAgent1111 extends InheritAgent1111Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1111!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1111!"); + } +} + +class InheritAgent1111Super { + + // + // This agent has a single argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs) { + System.out.println("Hello from Single-Arg InheritAgent1111Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } + + // + // This agent has a double argument premain() method which + // is NOT the one that should be called. + // + public static void premain (String agentArgs, Instrumentation instArg) { + System.out.println("Hello from Double-Arg InheritAgent1111Super!"); + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.*; + +class NoPremainAgent { + + // This agent is missing the premain() function. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,68 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6289149 +# @summary test when the agent's class is missing the premain() function. +# @author Daniel D. Daugherty, Sun Microsystems +# +# @run build DummyMain +# @run shell ../MakeJAR3.sh NoPremainAgent +# @run shell NoPremainAgent.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +"${JAVA}" ${TESTVMOPTS} -javaagent:NoPremainAgent.jar \ + -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1 +cat output.log + +MESG="java.lang.NoSuchMethodException" +grep "$MESG" output.log +result=$? +if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" +else + echo "FAIL: did NOT find '$MESG' in the test output" +fi + +exit $result
--- a/jdk/test/java/lang/instrument/PremainClass/PremainClassTest.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/PremainClass/PremainClassTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -49,7 +49,7 @@ "$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/DummyMain.java -"${JAVA}" -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain +"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain result=$? exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,32 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.*; + +class ZeroArgPremainAgent { + + // This agent has a zero arg premain() function. + public static void premain () { + System.out.println("Hello from ZeroArgInheritAgent!"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,68 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6289149 +# @summary test when the agent's class has a zero arg premain() function. +# @author Daniel D. Daugherty, Sun Microsystems +# +# @run build DummyMain +# @run shell ../MakeJAR3.sh ZeroArgPremainAgent +# @run shell ZeroArgPremainAgent.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +"${JAVA}" ${TESTVMOPTS} -javaagent:ZeroArgPremainAgent.jar \ + -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1 +cat output.log + +MESG="java.lang.NoSuchMethodException" +grep "$MESG" output.log +result=$? +if [ "$result" = 0 ]; then + echo "PASS: found '$MESG' in the test output" +else + echo "FAIL: did NOT find '$MESG' in the test output" +fi + +exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineClassWithNativeMethod.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,81 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 5003341 4917140 6545149 +# @summary Redefine a class with a native method. +# @author Daniel D. Daugherty as modified from the test submitted by clovis@par.univie.ac.at +# +# @run shell MakeJAR3.sh RedefineClassWithNativeMethodAgent 'Can-Redefine-Classes: true' +# @run build RedefineClassWithNativeMethodApp +# @run shell RedefineClassWithNativeMethod.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +"${JAVA}" ${TESTVMOPTS} \ + -javaagent:RedefineClassWithNativeMethodAgent.jar=java/lang/Thread.class \ + -classpath "${TESTCLASSES}" RedefineClassWithNativeMethodApp \ + > output.log 2>&1 +result=$? + +cat output.log + +if [ "$result" = 0 ]; then + echo "PASS: RedefineClassWithNativeMethodApp exited with status of 0." +else + echo "FAIL: RedefineClassWithNativeMethodApp exited with status of $result" + exit "$result" +fi + +MESG="Exception" +grep "$MESG" output.log +result=$? +if [ "$result" = 0 ]; then + echo "FAIL: found '$MESG' in the test output" + result=1 +else + echo "PASS: did NOT find '$MESG' in the test output" + result=0 +fi + +exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineClassWithNativeMethodAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,70 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.*; +import java.net.*; +import java.util.*; +import java.io.*; + +public class RedefineClassWithNativeMethodAgent { + static Class clz; + + // just read the original class and redefine it via a Timer + public static void premain(String agentArgs, final Instrumentation inst) throws Exception { + String s = agentArgs.substring(0, agentArgs.indexOf(".class")); + clz = Class.forName(s.replace('/', '.')); + ClassLoader loader = + RedefineClassWithNativeMethodAgent.class.getClassLoader(); + URL classURL = loader.getResource(agentArgs); + if (classURL == null) { + throw new Exception("Cannot find class: " + agentArgs); + } + + int redefineLength; + InputStream redefineStream; + + System.out.println("Reading test class from " + classURL); + if (classURL.getProtocol().equals("file")) { + File f = new File(classURL.getFile()); + redefineStream = new FileInputStream(f); + redefineLength = (int) f.length(); + } else { + URLConnection conn = classURL.openConnection(); + redefineStream = conn.getInputStream(); + redefineLength = conn.getContentLength(); + } + + final byte[] buffer = new byte[redefineLength]; + new BufferedInputStream(redefineStream).read(buffer); + new Timer(true).schedule(new TimerTask() { + public void run() { + try { + System.out.println("Instrumenting"); + ClassDefinition cld = new ClassDefinition(clz, buffer); + inst.redefineClasses(new ClassDefinition[] { cld }); + } + catch (Exception e) { e.printStackTrace(); } + } + }, 500); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineClassWithNativeMethodApp.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +public class RedefineClassWithNativeMethodApp { + public static void main(String[] args) throws Exception { + try { + // give the agent a chance to redefine the target class + Thread.sleep(2000); + } catch (InterruptedException ie) { + } + + System.out.println("Creating instance of " + + RedefineClassWithNativeMethodAgent.clz); + RedefineClassWithNativeMethodAgent.clz.newInstance(); + + System.exit(0); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvoke.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,82 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6667089 +# @summary Reflexive invocation of newly added methods broken. +# @author Daniel D. Daugherty +# +# @run shell MakeJAR3.sh RedefineMethodAddInvokeAgent 'Can-Redefine-Classes: true' +# @run build RedefineMethodAddInvokeApp +# @run shell RedefineMethodAddInvoke.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAVAC="${TESTJAVA}"/bin/javac +JAVA="${TESTJAVA}"/bin/java + +cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_1.java \ + RedefineMethodAddInvokeTarget.java +"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java +mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_1.java +mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_1.class + +cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_2.java \ + RedefineMethodAddInvokeTarget.java +"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java +mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_2.java +mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_2.class + +"${JAVA}" ${TESTVMOPTS} -javaagent:RedefineMethodAddInvokeAgent.jar \ + -classpath "${TESTCLASSES}" RedefineMethodAddInvokeApp > output.log 2>&1 +cat output.log + +MESG="Exception" +grep "$MESG" output.log +result=$? +if [ "$result" = 0 ]; then + echo "FAIL: found '$MESG' in the test output" + result=1 +else + echo "PASS: did NOT find '$MESG' in the test output" + result=0 +fi + +exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvokeAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,43 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.Instrumentation; + +public class RedefineMethodAddInvokeAgent { + private static Instrumentation instrumentation; + + private RedefineMethodAddInvokeAgent() { + } + + public static void premain(String agentArgs, Instrumentation inst) { + System.out.println("Hello from RedefineMethodAddInvokeAgent!"); + System.out.println("isRedefineClassesSupported()=" + + inst.isRedefineClassesSupported()); + + instrumentation = inst; + } + + public static Instrumentation getInstrumentation() { + return instrumentation; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvokeApp.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,70 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.io.*; +import java.lang.instrument.*; + +public class RedefineMethodAddInvokeApp { + public static void main(String args[]) throws Exception { + System.out.println("Hello from RedefineMethodAddInvokeApp!"); + + new RedefineMethodAddInvokeApp().doTest(); + + System.exit(0); + } + + private void doTest() throws Exception { + RedefineMethodAddInvokeTarget target = + new RedefineMethodAddInvokeTarget(); + + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod()"); + target.test(0); // invoke the original myMethod() + + // add myMethod1() + do_redefine(1); + + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod1()"); + target.test(1); // invoke myMethod1() + + // add myMethod2() + do_redefine(2); + + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod2()"); + target.test(2); // invoke myMethod2() + } + + private static void do_redefine(int counter) throws Exception { + File f = new File("RedefineMethodAddInvokeTarget_" + counter + + ".class"); + System.out.println("Reading test class from " + f); + InputStream redefineStream = new FileInputStream(f); + + byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream); + + ClassDefinition redefineParamBlock = new ClassDefinition( + RedefineMethodAddInvokeTarget.class, redefineBuffer); + + RedefineMethodAddInvokeAgent.getInstrumentation().redefineClasses( + new ClassDefinition[] {redefineParamBlock}); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvokeTarget.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,37 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.reflect.Method; + +public class RedefineMethodAddInvokeTarget { + public void test(int counter) throws Exception { + Method method = getClass().getDeclaredMethod("myMethod" + + (counter == 0 ? "" : counter)); + method.setAccessible(true); + method.invoke(this); + } + + public void myMethod() { + System.out.println("Hello from the original myMethod()!"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvokeTarget_1.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,43 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.reflect.Method; + +public class RedefineMethodAddInvokeTarget { + public void test(int counter) throws Exception { + Method method = getClass().getDeclaredMethod("myMethod" + + (counter == 0 ? "" : counter)); + method.setAccessible(true); + method.invoke(this); + } + + public void myMethod() { + System.out.println("Hello from the non-EMCP myMethod()!"); + } + + private final void myMethod1() { + System.out.println("Hello from myMethod1()!"); + System.out.println("Calling myMethod() from myMethod1():"); + myMethod(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/RedefineMethodAddInvokeTarget_2.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,49 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.reflect.Method; + +public class RedefineMethodAddInvokeTarget { + public void test(int counter) throws Exception { + Method method = getClass().getDeclaredMethod("myMethod" + + (counter == 0 ? "" : counter)); + method.setAccessible(true); + method.invoke(this); + } + + public void myMethod() { + System.out.println("Hello from the non-EMCP again myMethod()!"); + } + + private final void myMethod1() { + System.out.println("Hello from myMethod1()!"); + System.out.println("Calling myMethod() from myMethod1():"); + myMethod(); + } + + private final void myMethod2() { + System.out.println("Hello from myMethod2()!"); + System.out.println("Calling myMethod1() from myMethod2():"); + myMethod1(); + } +}
--- a/jdk/test/java/lang/instrument/RetransformAgent.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/RetransformAgent.java Wed Apr 23 06:35:28 2008 -0400 @@ -27,7 +27,7 @@ * @summary test retransformClasses * @author Robert Field, Sun Microsystems * - * @run shell MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true' + * @run shell/timeout=240 MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true' * @run main/othervm -javaagent:RetransformAgent.jar RetransformApp */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/StressGetObjectSizeApp.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,86 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.lang.instrument.Instrumentation; + +public class StressGetObjectSizeApp + extends ASimpleInstrumentationTestCase +{ + + /** + * Constructor for StressGetObjectSizeApp. + * @param name + */ + public StressGetObjectSizeApp(String name) + { + super(name); + } + + public static void + main (String[] args) + throws Throwable { + ATestCaseScaffold test = new StressGetObjectSizeApp(args[0]); + test.runTest(); + } + + protected final void + doRunTest() + throws Throwable { + stressGetObjectSize(); + } + + public void stressGetObjectSize() { + System.out.println("main: an object size=" + + fInst.getObjectSize(new Object())); + + RoundAndRound[] threads = new RoundAndRound[10]; + for (int i = 0; i < threads.length; ++i) { + threads[i] = new RoundAndRound(fInst); + threads[i].start(); + } + try { + Thread.sleep(500); // let all threads get going in their loops + } catch (InterruptedException ie) { + } + System.out.println("stressGetObjectSize: returning"); + return; + } + + private static class RoundAndRound extends Thread { + private final Instrumentation inst; + private final Object anObject; + + public RoundAndRound(Instrumentation inst) { + this.inst = inst; + this.anObject = new Object(); + setDaemon(true); + } + + public void run() { + long sum = 0; + while (true) { + sum += inst.getObjectSize(anObject); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/StressGetObjectSizeTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,70 @@ +# +# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6572160 +# @summary stress getObjectSize() API +# @author Daniel D. Daugherty as modified from the code of fischman@google.com +# +# @run build StressGetObjectSizeApp +# @run shell MakeJAR.sh basicAgent +# @run shell StressGetObjectSizeTest.sh +# + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +JAVA="${TESTJAVA}"/bin/java + +"${JAVA}" ${TESTVMOPTS} -javaagent:basicAgent.jar \ + -classpath "${TESTCLASSES}" StressGetObjectSizeApp StressGetObjectSizeApp \ + > output.log 2>&1 +cat output.log + +MESG="ASSERTION FAILED" +grep "$MESG" output.log +result=$? +if [ "$result" = 0 ]; then + echo "FAIL: found '$MESG' in the test output" + result=1 +else + echo "PASS: did NOT find '$MESG' in the test output" + result=0 +fi + +exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/TestClass1.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * Test Java Program + * + * @author Daryl Puryear + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. + */ +public class TestClass1 +{ + public + TestClass1() + { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/TestClass2.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * Test Java Program + * + * @author Daryl Puryear + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. + */ +public class TestClass2 +{ + public + TestClass2() + { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/TestClass3.java Wed Apr 23 06:35:28 2008 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * Test Java Program + * + * @author Daryl Puryear + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. + */ +public class TestClass3 +{ + public + TestClass3() + { + } +}
--- a/jdk/test/java/lang/instrument/TransformerManagementThreadAddTests.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/TransformerManagementThreadAddTests.java Wed Apr 23 06:35:28 2008 -0400 @@ -79,6 +79,12 @@ protected static final int TOTAL_THREADS = MAX_TRANS - MIN_TRANS + 1; private byte[] fDummyClassBytes; + // fCheckedTransformers is a Vector that is used to verify + // that the transform() function is called in the same + // order in which the transformers were added to the + // TransformerManager. The test currently verifies that all + // transformers for a specific worker thread are in + // increasing order by index value. private Vector fCheckedTransformers; private Instrumentation fInstrumentation; private int fFinished; @@ -131,9 +137,16 @@ threads[i].start(); } - while (!exec.fDone) + // Effective Java - Item 48: Synchronize access to shared mutable data + // Don't use a direct field getter. + while (!exec.isDone()) { - Thread.currentThread().yield(); + // Effective Java - Item 51: Don't depend on the thread scheduler + // Use sleep() instead of yield(). + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + } } assertTrue(finalCheck()); @@ -169,13 +182,17 @@ this.fExec = exec; } + // Effective Java - Item 48: Synchronize access to shared mutable data + // Document a synchronized setter. protected synchronized void threadFinished(Thread t) { fFinished++; } - protected boolean + // Effective Java - Item 48: Synchronize access to shared mutable data + // Provide synchronized getter. + protected synchronized boolean threadsDone() { return fFinished == TOTAL_THREADS; @@ -188,7 +205,9 @@ protected boolean testCompleted() { - return getExecThread().fDone; + // Effective Java - Item 48: Synchronize access to shared mutable data + // Don't use direct field getter. + return getExecThread().isDone(); } /** @@ -264,11 +283,19 @@ private void executeTransform() { - fCheckedTransformers.clear(); - try { ClassDefinition cd = new ClassDefinition(DummyClass.class, fDummyClassBytes); + + // When the ClassDefinition above is created for the first + // time and every time redefineClasses() below is called, + // the transform() function is called for each registered + // transformer. We only want one complete set of calls to + // be logged in the fCheckedTransformers Vector so we clear + // any calls logged for ClassDefinition above and just use + // the ones logged for redefineClasses() below. + fCheckedTransformers.clear(); + getInstrumentation().redefineClasses(new ClassDefinition[]{ cd }); } catch (ClassNotFoundException e) @@ -325,6 +352,18 @@ { private boolean fDone = false; + // Effective Java - Item 48: Synchronize access to shared mutable data + // Provide a synchronized getter. + private synchronized boolean isDone() { + return fDone; + } + + // Effective Java - Item 48: Synchronize access to shared mutable data + // Provide a synchronized setter. + private synchronized void setIsDone() { + fDone = true; + } + public void run() { @@ -335,7 +374,9 @@ // Do a final check for good measure executeTransform(); - fDone = true; + // Effective Java - Item 48: Synchronize access to shared mutable data + // Don't use direct field setter. + setIsDone(); } }
--- a/jdk/test/java/lang/instrument/TransformerManagementThreadRemoveTests.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/TransformerManagementThreadRemoveTests.java Wed Apr 23 06:35:28 2008 -0400 @@ -27,10 +27,9 @@ * @summary multi-thread test to exercise sync and contention for removes to transformer registry * @author Gabriel Adauto, Wily Technology * - * @ignore Disabled until race condition which hangs test can be fixed. * @run build TransformerManagementThreadRemoveTests - * @run shell MakeJAR.sh basicAgent - * @run main/othervm -javaagent:basicAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests + * @run shell MakeJAR.sh redefineAgent + * @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests */ import java.util.*; @@ -87,7 +86,12 @@ while (!testCompleted()) { - Thread.currentThread().yield(); + // Effective Java - Item 51: Don't depend on the thread scheduler + // Use sleep() instead of yield(). + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + } } assertTrue(finalCheck());
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CircularityErrorTest.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CircularityErrorTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -26,14 +26,14 @@ # @summary Unit tests for appendToBootstrapClassLoaderSearch and # appendToSystemClasLoaderSearch methods. # -# @run shell CircularityErrorTest.sh +# @run shell/timeout=240 CircularityErrorTest.sh if [ "${TESTSRC}" = "" ] then echo "TESTSRC not set. Test cannot execute. Failed." exit 1 fi - + . ${TESTSRC}/CommonSetup.sh # Setup to create circularity condition @@ -71,5 +71,5 @@ -C "${TESTCLASSES}" CircularityErrorTest.class # Finally we run the test -(cd "${TESTCLASSES}"; - $JAVA -javaagent:CircularityErrorTest.jar CircularityErrorTest) +(cd "${TESTCLASSES}"; + $JAVA ${TESTVMOPTS} -javaagent:CircularityErrorTest.jar CircularityErrorTest)
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Wed Apr 23 06:35:28 2008 -0400 @@ -34,11 +34,11 @@ echo "TESTSRC not set. Test cannot execute. Failed." exit 1 fi - + . ${TESTSRC}/CommonSetup.sh # Create Foo and Bar -# Foo has a reference to Bar but we deleted Bar so that +# Foo has a reference to Bar but we deleted Bar so that # a NoClassDefFoundError will be thrown when Foo tries to # resolve the reference to Bar @@ -53,11 +53,11 @@ public class Foo { public static boolean doSomething() { try { - Bar b = new Bar(); - return true; - } catch (NoClassDefFoundError x) { - return false; - } + Bar b = new Bar(); + return true; + } catch (NoClassDefFoundError x) { + return false; + } } } EOF @@ -79,5 +79,5 @@ # Finally we run the test (cd "${TESTCLASSES}"; \ - $JAVA -Xverify:none -XX:+TraceClassUnloading -javaagent:ClassUnloadTest.jar \ - ClassUnloadTest "${OTHERDIR}" Bar.jar) + $JAVA ${TESTVMOPTS} -Xverify:none -XX:+TraceClassUnloading \ + -javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh Wed Apr 23 06:35:28 2008 -0400 @@ -24,7 +24,6 @@ # -#%E # # Common setup for unit tests. Setups up the following variables: # @@ -66,7 +65,7 @@ echo "TESTSRC not set. Test cannot execute. Failed." exit 1 fi - + if [ "${TESTCLASSES}" = "" ] then echo "TESTCLASSES not set. Test cannot execute. Failed."
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/run_tests.sh Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/run_tests.sh Wed Apr 23 06:35:28 2008 -0400 @@ -23,24 +23,24 @@ # have any questions. # - + # @test # @bug 6173575 6388987 -# @summary Unit tests for appendToBootstrapClassLoaderSearch and +# @summary Unit tests for appendToBootstrapClassLoaderSearch and # appendToSystemClasLoaderSearch methods. # # @build Agent AgentSupport BootSupport BasicTest PrematureLoadTest DynamicTest -# @run shell run_tests.sh +# @run shell/timeout=240 run_tests.sh if [ "${TESTSRC}" = "" ] then echo "TESTSRC not set. Test cannot execute. Failed." exit 1 fi - + . ${TESTSRC}/CommonSetup.sh - + # Simple tests echo "Creating jar files for simple tests..." @@ -50,13 +50,13 @@ "$JAR" -cfm Agent.jar "${TESTSRC}"/manifest.mf Agent.class "$JAR" -cf AgentSupport.jar AgentSupport.class "$JAR" -cf BootSupport.jar BootSupport.class -"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class +"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class failures=0 go() { echo '' - sh -xc "$JAVA -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1 + sh -xc "$JAVA ${TESTVMOPTS} -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi } @@ -75,7 +75,7 @@ "${JAVAC}" -d tmp "${TESTSRC}"/Tracer.java (cd tmp; "${JAR}" cf ../Tracer.jar org/tools/Tracer.class) -# InstrumentedApplication is Application+instrmentation - don't copy as +# InstrumentedApplication is Application+instrmentation - don't copy as # we don't want the original file permission cat "${TESTSRC}"/InstrumentedApplication.java > ./Application.java @@ -85,11 +85,11 @@ cp "${TESTSRC}"/Application.java . "${JAVAC}" -d . Application.java -sh -xc "$JAVA -classpath . -javaagent:Agent.jar DynamicTest" 2>&1 +sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar DynamicTest" 2>&1 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi # Repeat test with security manager -sh -xc "$JAVA -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1 +sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi #
--- a/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/CreatePrivateActivatable.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/CreatePrivateActivatable.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -49,116 +49,116 @@ public class CreatePrivateActivatable { private static class PrivateActivatable extends Activatable - implements ActivateMe, Runnable + implements ActivateMe, Runnable { - private PrivateActivatable(ActivationID id, MarshalledObject obj) - throws ActivationException, RemoteException - { - super(id, 0); - } + private PrivateActivatable(ActivationID id, MarshalledObject obj) + throws ActivationException, RemoteException + { + super(id, 0); + } - public void ping() - {} + public void ping() + {} - /** - * Spawns a thread to deactivate the object. - */ - public void shutdown() throws Exception - { - (new Thread(this, "CreatePrivateActivatable$PrivateActivatable")).start(); - } + /** + * Spawns a thread to deactivate the object. + */ + public void shutdown() throws Exception + { + (new Thread(this, "CreatePrivateActivatable$PrivateActivatable")).start(); + } - /** - * Thread to deactivate object. First attempts to make object - * inactive (via the inactive method). If that fails (the - * object may still have pending/executing calls), then - * unexport the object forcibly. - */ - public void run() { - ActivationLibrary.deactivate(this, getID()); - } + /** + * Thread to deactivate object. First attempts to make object + * inactive (via the inactive method). If that fails (the + * object may still have pending/executing calls), then + * unexport the object forcibly. + */ + public void run() { + ActivationLibrary.deactivate(this, getID()); + } } - + public static void main(String[] args) { - /* - * The following line is required with the JDK 1.2 VM so that the - * VM can exit gracefully when this test completes. Otherwise, the - * conservative garbage collector will find a handle to the server - * object on the native stack and not clear the weak reference to - * it in the RMI runtime's object table. - */ - Object dummy = new Object(); - RMID rmid = null; - ActivateMe obj; + /* + * The following line is required with the JDK 1.2 VM so that the + * VM can exit gracefully when this test completes. Otherwise, the + * conservative garbage collector will find a handle to the server + * object on the native stack and not clear the weak reference to + * it in the RMI runtime's object table. + */ + Object dummy = new Object(); + RMID rmid = null; + ActivateMe obj; - System.err.println("\nRegression test for bug 4164971\n"); - System.err.println("java.security.policy = " + - System.getProperty("java.security.policy", "no policy")); + System.err.println("\nRegression test for bug 4164971\n"); + System.err.println("java.security.policy = " + + System.getProperty("java.security.policy", "no policy")); - CreatePrivateActivatable server; - try { - TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager); + CreatePrivateActivatable server; + try { + TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager); - // start an rmid. - RMID.removeLog(); - rmid = RMID.createRMID(); - rmid.start(); - - /* Cause activation groups to have a security policy that will - * allow security managers to be downloaded and installed - */ - Properties p = new Properties(); - // this test must always set policies/managers in its - // activation groups - p.put("java.security.policy", - TestParams.defaultGroupPolicy); - p.put("java.security.manager", - TestParams.defaultSecurityManager); - - /* - * Activate an object by registering its object - * descriptor and invoking a method on the - * stub returned from the register call. - */ - ActivationGroupDesc groupDesc = - new ActivationGroupDesc(p, null); - ActivationSystem system = ActivationGroup.getSystem(); - ActivationGroupID groupID = system.registerGroup(groupDesc); + // start an rmid. + RMID.removeLog(); + rmid = RMID.createRMID(); + rmid.start(); - System.err.println("Creating descriptor"); - ActivationDesc desc = - new ActivationDesc(groupID, - "CreatePrivateActivatable$PrivateActivatable", - null, null); - - System.err.println("Registering descriptor"); - obj = (ActivateMe) Activatable.register(desc); - - /* - * Loop a bunch of times to force activator to - * spawn VMs (groups) - */ - System.err.println("Activate object via method call"); - obj.ping(); - - /* - * Clean up object too. - */ - System.err.println("Deactivate object via method call"); - obj.shutdown(); - - System.err.println("\nsuccess: CreatePrivateActivatable test passed "); - - } catch (Exception e) { - if (e instanceof java.security.PrivilegedActionException) { - e = ((java.security.PrivilegedActionException)e).getException(); - } - TestLibrary.bomb("\nfailure: unexpected exception " + - e.getClass().getName(), e); - - } finally { - ActivationLibrary.rmidCleanup(rmid); - obj = null; - } + /* Cause activation groups to have a security policy that will + * allow security managers to be downloaded and installed + */ + Properties p = new Properties(); + // this test must always set policies/managers in its + // activation groups + p.put("java.security.policy", + TestParams.defaultGroupPolicy); + p.put("java.security.manager", + TestParams.defaultSecurityManager); + + /* + * Activate an object by registering its object + * descriptor and invoking a method on the + * stub returned from the register call. + */ + ActivationGroupDesc groupDesc = + new ActivationGroupDesc(p, null); + ActivationSystem system = ActivationGroup.getSystem(); + ActivationGroupID groupID = system.registerGroup(groupDesc); + + System.err.println("Creating descriptor"); + ActivationDesc desc = + new ActivationDesc(groupID, + "CreatePrivateActivatable$PrivateActivatable", + null, null); + + System.err.println("Registering descriptor"); + obj = (ActivateMe) Activatable.register(desc); + + /* + * Loop a bunch of times to force activator to + * spawn VMs (groups) + */ + System.err.println("Activate object via method call"); + obj.ping(); + + /* + * Clean up object too. + */ + System.err.println("Deactivate object via method call"); + obj.shutdown(); + + System.err.println("\nsuccess: CreatePrivateActivatable test passed "); + + } catch (Exception e) { + if (e instanceof java.security.PrivilegedActionException) { + e = ((java.security.PrivilegedActionException)e).getException(); + } + TestLibrary.bomb("\nfailure: unexpected exception " + + e.getClass().getName(), e); + + } finally { + ActivationLibrary.rmidCleanup(rmid); + obj = null; + } } }
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -24,10 +24,10 @@ /* @test * @bug 4097135 * @summary Need a specific subtype of RemoteException for activation failure. - * If activation fails to happen during a call to a remote object, - * then the call should end in an ActivateFailedException. In this - * test, the actual "activatable" remote object fails to activate - * since its * "activation" constructor throws an exception. + * If activation fails to happen during a call to a remote object, + * then the call should end in an ActivateFailedException. In this + * test, the actual "activatable" remote object fails to activate + * since its * "activation" constructor throws an exception. * @author Ann Wollrath * * @library ../../../testlibrary @@ -46,128 +46,127 @@ import java.util.Properties; public class ActivateFails - extends Activatable - implements ActivateMe + extends Activatable + implements ActivateMe { public ActivateFails(ActivationID id, MarshalledObject obj) - throws ActivationException, RemoteException + throws ActivationException, RemoteException { - super(id, 0); + super(id, 0); - boolean refuseToActivate = false; - try { - refuseToActivate = ((Boolean)obj.get()).booleanValue(); - } catch (Exception impossible) { - } - - if (refuseToActivate) - throw new RemoteException("object refuses to activate"); + boolean refuseToActivate = false; + try { + refuseToActivate = ((Boolean)obj.get()).booleanValue(); + } catch (Exception impossible) { + } + + if (refuseToActivate) + throw new RemoteException("object refuses to activate"); } public void ping() {} - + /** * Spawns a thread to deactivate the object. */ public ShutdownThread shutdown() throws Exception { - ShutdownThread shutdownThread = new ShutdownThread(this, getID()); - shutdownThread.start(); - return(shutdownThread); + ShutdownThread shutdownThread = new ShutdownThread(this, getID()); + shutdownThread.start(); + return(shutdownThread); } - - public static void main(String[] args) + + public static void main(String[] args) { - RMID rmid = null; - ActivateMe obj1, obj2; - ShutdownThread shutdownThread; - - System.err.println("\nRegression test for bug 4097135\n"); - try { - TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); + RMID rmid = null; + ActivateMe obj1, obj2; + ShutdownThread shutdownThread; - /* - * First run "rmid" and wait for it to start up. - */ - RMID.removeLog(); - rmid = RMID.createRMID(); - rmid.start(); + System.err.println("\nRegression test for bug 4097135\n"); + try { + TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); - /* Cause activation groups to have a security policy that will - * allow security managers to be downloaded and installed - */ - Properties p = new Properties(); - // this test must always set policies/managers in its - // activation groups - p.put("java.security.policy", - TestParams.defaultGroupPolicy); - p.put("java.security.manager", - TestParams.defaultSecurityManager); + /* + * First run "rmid" and wait for it to start up. + */ + RMID.removeLog(); + rmid = RMID.createRMID(); + rmid.start(); - /* - * Create activation descriptor... - */ - System.err.println("creating activation descriptor..."); - ActivationGroupDesc groupDesc = - new ActivationGroupDesc(p, null); - ActivationGroupID groupID = - ActivationGroup.getSystem().registerGroup(groupDesc); - - ActivationDesc desc1 = - new ActivationDesc(groupID, "ActivateFails", - null, - new MarshalledObject(new Boolean(true))); - - ActivationDesc desc2 = - new ActivationDesc(groupID, "ActivateFails", - null, - new MarshalledObject(new Boolean(false))); - /* - * Register activation descriptor and make a call on - * the stub. Activation should fail with an - * ActivateFailedException. If not, report an - * error as a RuntimeException - */ + /* Cause activation groups to have a security policy that will + * allow security managers to be downloaded and installed + */ + Properties p = new Properties(); + // this test must always set policies/managers in its + // activation groups + p.put("java.security.policy", + TestParams.defaultGroupPolicy); + p.put("java.security.manager", + TestParams.defaultSecurityManager); - System.err.println("registering activation descriptor..."); - obj1 = (ActivateMe)Activatable.register(desc1); - obj2 = (ActivateMe)Activatable.register(desc2); + /* + * Create activation descriptor... + */ + System.err.println("creating activation descriptor..."); + ActivationGroupDesc groupDesc = + new ActivationGroupDesc(p, null); + ActivationGroupID groupID = + ActivationGroup.getSystem().registerGroup(groupDesc); - System.err.println("invoking method on activatable object..."); - try { - obj1.ping(); - - } catch (ActivateFailedException e) { + ActivationDesc desc1 = + new ActivationDesc(groupID, "ActivateFails", + null, + new MarshalledObject(new Boolean(true))); - /* - * This is what is expected so exit with status 0 - */ - System.err.println("\nsuccess: ActivateFailedException " + - "generated"); - e.getMessage(); - } + ActivationDesc desc2 = + new ActivationDesc(groupID, "ActivateFails", + null, + new MarshalledObject(new Boolean(false))); + /* + * Register activation descriptor and make a call on + * the stub. Activation should fail with an + * ActivateFailedException. If not, report an + * error as a RuntimeException + */ - obj2.ping(); - shutdownThread = obj2.shutdown(); + System.err.println("registering activation descriptor..."); + obj1 = (ActivateMe)Activatable.register(desc1); + obj2 = (ActivateMe)Activatable.register(desc2); - // wait for shutdown to work - Thread.sleep(2000); + System.err.println("invoking method on activatable object..."); + try { + obj1.ping(); - shutdownThread = null; - - } catch (Exception e) { - /* - * Test failed; unexpected exception generated. - */ - TestLibrary.bomb("\nfailure: unexpected exception " + - e.getClass().getName() + ": " + e.getMessage(), e); - - } finally { - obj1 = obj2 = null; - ActivationLibrary.rmidCleanup(rmid); - } + } catch (ActivateFailedException e) { + + /* + * This is what is expected so exit with status 0 + */ + System.err.println("\nsuccess: ActivateFailedException " + + "generated"); + e.getMessage(); + } + + obj2.ping(); + shutdownThread = obj2.shutdown(); + + // wait for shutdown to work + Thread.sleep(2000); + + shutdownThread = null; + + } catch (Exception e) { + /* + * Test failed; unexpected exception generated. + */ + TestLibrary.bomb("\nfailure: unexpected exception " + + e.getClass().getName() + ": " + e.getMessage(), e); + + } finally { + obj1 = obj2 = null; + ActivationLibrary.rmidCleanup(rmid); + } } } -
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails_Stub.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails_Stub.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,88 +29,88 @@ implements ActivateMe, java.rmi.Remote { private static final java.rmi.server.Operation[] operations = { - new java.rmi.server.Operation("void ping()"), - new java.rmi.server.Operation("ShutdownThread shutdown()") + new java.rmi.server.Operation("void ping()"), + new java.rmi.server.Operation("ShutdownThread shutdown()") }; - + private static final long interfaceHash = -6632667923281093978L; - + private static final long serialVersionUID = 2; - + private static boolean useNewInvoke; private static java.lang.reflect.Method $method_ping_0; private static java.lang.reflect.Method $method_shutdown_1; - + static { - try { - java.rmi.server.RemoteRef.class.getMethod("invoke", - new java.lang.Class[] { - java.rmi.Remote.class, - java.lang.reflect.Method.class, - java.lang.Object[].class, - long.class - }); - useNewInvoke = true; - $method_ping_0 = ActivateMe.class.getMethod("ping", new java.lang.Class[] {}); - $method_shutdown_1 = ActivateMe.class.getMethod("shutdown", new java.lang.Class[] {}); - } catch (java.lang.NoSuchMethodException e) { - useNewInvoke = false; - } + try { + java.rmi.server.RemoteRef.class.getMethod("invoke", + new java.lang.Class[] { + java.rmi.Remote.class, + java.lang.reflect.Method.class, + java.lang.Object[].class, + long.class + }); + useNewInvoke = true; + $method_ping_0 = ActivateMe.class.getMethod("ping", new java.lang.Class[] {}); + $method_shutdown_1 = ActivateMe.class.getMethod("shutdown", new java.lang.Class[] {}); + } catch (java.lang.NoSuchMethodException e) { + useNewInvoke = false; + } } - + // constructors public ActivateFails_Stub() { - super(); + super(); } public ActivateFails_Stub(java.rmi.server.RemoteRef ref) { - super(ref); + super(ref); } - + // methods from remote interfaces - + // implementation of ping() public void ping() - throws java.rmi.RemoteException + throws java.rmi.RemoteException { - try { - if (useNewInvoke) { - ref.invoke(this, $method_ping_0, null, 5866401369815527589L); - } else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash); - ref.invoke(call); - ref.done(call); - } - } catch (java.lang.RuntimeException e) { - throw e; - } catch (java.rmi.RemoteException e) { - throw e; - } catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } + try { + if (useNewInvoke) { + ref.invoke(this, $method_ping_0, null, 5866401369815527589L); + } else { + java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash); + ref.invoke(call); + ref.done(call); + } + } catch (java.lang.RuntimeException e) { + throw e; + } catch (java.rmi.RemoteException e) { + throw e; + } catch (java.lang.Exception e) { + throw new java.rmi.UnexpectedException("undeclared checked exception", e); + } } - + // implementation of shutdown() public ShutdownThread shutdown() - throws java.lang.Exception + throws java.lang.Exception { - if (useNewInvoke) { - Object $result = ref.invoke(this, $method_shutdown_1, null, -3616843253114182719L); - return ((ShutdownThread) $result); - } else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 1, interfaceHash); - ref.invoke(call); - ShutdownThread $result; - try { - java.io.ObjectInput in = call.getInputStream(); - $result = (ShutdownThread) in.readObject(); - } catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } catch (java.lang.ClassNotFoundException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } finally { - ref.done(call); - } - return $result; - } + if (useNewInvoke) { + Object $result = ref.invoke(this, $method_shutdown_1, null, -3616843253114182719L); + return ((ShutdownThread) $result); + } else { + java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 1, interfaceHash); + ref.invoke(call); + ShutdownThread $result; + try { + java.io.ObjectInput in = call.getInputStream(); + $result = (ShutdownThread) in.readObject(); + } catch (java.io.IOException e) { + throw new java.rmi.UnmarshalException("error unmarshalling return", e); + } catch (java.lang.ClassNotFoundException e) { + throw new java.rmi.UnmarshalException("error unmarshalling return", e); + } finally { + ref.done(call); + } + return $result; + } } }
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateMe.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateMe.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ShutdownThread.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ShutdownThread.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -31,21 +31,20 @@ ActivationID activationID = null; public ShutdownThread(Remote remoteObject, ActivationID activationID) { - remoteObject = remoteObject; - activationID = activationID; + remoteObject = remoteObject; + activationID = activationID; } public void run() { - try { + try { - Activatable.unexportObject(remoteObject, true); - Activatable.inactive(activationID); + Activatable.unexportObject(remoteObject, true); + Activatable.inactive(activationID); - } catch (Exception e) { - } + } catch (Exception e) { + } } } -
--- a/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/DownloadActivationGroup.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/DownloadActivationGroup.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -23,7 +23,7 @@ /* * @test - * @bug 4510355 + * @bug 4510355 * @summary ActivationGroup implementations cannot be downloaded by default; * Creates a custom activation group without setting a security manager * in activation group's descriptor. The custom activation group @@ -49,28 +49,28 @@ import java.util.Properties; public class DownloadActivationGroup - implements Ping, Runnable + implements Ping, Runnable { private ActivationID id; public DownloadActivationGroup(ActivationID id, MarshalledObject mobj) - throws ActivationException, RemoteException + throws ActivationException, RemoteException { - this.id = id; - Activatable.exportObject(this, id, 0); - System.err.println("object activated in group"); + this.id = id; + Activatable.exportObject(this, id, 0); + System.err.println("object activated in group"); } public DownloadActivationGroup() throws RemoteException { - UnicastRemoteObject.exportObject(this, 0); + UnicastRemoteObject.exportObject(this, 0); } /** * Used to activate object. */ public void ping() { - System.err.println("received ping"); + System.err.println("received ping"); } /** @@ -79,87 +79,87 @@ */ public void shutdown() throws Exception { - (new Thread(this,"DownloadActivationGroup")).start(); + (new Thread(this,"DownloadActivationGroup")).start(); } /** * Thread to deactivate object. */ public void run() { - ActivationLibrary.deactivate(this, getID()); + ActivationLibrary.deactivate(this, getID()); } - + public ActivationID getID() { - return id; + return id; } public static void main(String[] args) { - RMID rmid = null; - - System.out.println("\nRegression test for bug 4510355\n"); - - try { - TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); + RMID rmid = null; - /* - * Install group class file in codebase. - */ - System.err.println("install class file in codebase"); - URL groupURL = TestLibrary.installClassInCodebase( - "MyActivationGroupImpl", "group"); - System.err.println("class file installed"); + System.out.println("\nRegression test for bug 4510355\n"); - /* - * Start rmid. - */ - RMID.removeLog(); - rmid = RMID.createRMID(); - String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none"; - rmid.addOptions(new String[] { execPolicyOption }); - rmid.start(); + try { + TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); - /* - * Create and register descriptors for custom group and an - * activatable object in that group. - */ - System.err.println("register group"); - - Properties p = new Properties(); - p.put("java.security.policy", TestParams.defaultGroupPolicy); - - ActivationGroupDesc groupDesc = - new ActivationGroupDesc("MyActivationGroupImpl", - groupURL.toExternalForm(), - null, p, null); - ActivationGroupID groupID = - ActivationGroup.getSystem().registerGroup(groupDesc); - - - System.err.println("register activatable object"); - ActivationDesc desc = - new ActivationDesc(groupID, "DownloadActivationGroup", - null, null); - Ping obj = (Ping) Activatable.register(desc); + /* + * Install group class file in codebase. + */ + System.err.println("install class file in codebase"); + URL groupURL = TestLibrary.installClassInCodebase( + "MyActivationGroupImpl", "group"); + System.err.println("class file installed"); - /* - * Start group (by calling ping). - */ - System.err.println( - "ping object (forces download of group's class)"); - obj.ping(); - System.err.println( - "TEST PASSED: group's class downloaded successfully"); - System.err.println("shutdown object"); - obj.shutdown(); - System.err.println("TEST PASSED"); + /* + * Start rmid. + */ + RMID.removeLog(); + rmid = RMID.createRMID(); + String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none"; + rmid.addOptions(new String[] { execPolicyOption }); + rmid.start(); - } catch (Exception e) { - TestLibrary.bomb(e); - } finally { - ActivationLibrary.rmidCleanup(rmid); - } + /* + * Create and register descriptors for custom group and an + * activatable object in that group. + */ + System.err.println("register group"); + + Properties p = new Properties(); + p.put("java.security.policy", TestParams.defaultGroupPolicy); + + ActivationGroupDesc groupDesc = + new ActivationGroupDesc("MyActivationGroupImpl", + groupURL.toExternalForm(), + null, p, null); + ActivationGroupID groupID = + ActivationGroup.getSystem().registerGroup(groupDesc); + + + System.err.println("register activatable object"); + ActivationDesc desc = + new ActivationDesc(groupID, "DownloadActivationGroup", + null, null); + Ping obj = (Ping) Activatable.register(desc); + + /* + * Start group (by calling ping). + */ + System.err.println( + "ping object (forces download of group's class)"); + obj.ping(); + System.err.println( + "TEST PASSED: group's class downloaded successfully"); + System.err.println("shutdown object"); + obj.shutdown(); + System.err.println("TEST PASSED"); + + } catch (Exception e) { + TestLibrary.bomb(e); + } finally { + ActivationLibrary.rmidCleanup(rmid); + } } }
--- a/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/DownloadActivationGroup_Stub.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/DownloadActivationGroup_Stub.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,46 +29,46 @@ implements Ping { private static final long serialVersionUID = 2; - + private static java.lang.reflect.Method $method_ping_0; private static java.lang.reflect.Method $method_shutdown_1; - + static { - try { - $method_ping_0 = Ping.class.getMethod("ping", new java.lang.Class[] {}); - $method_shutdown_1 = Ping.class.getMethod("shutdown", new java.lang.Class[] {}); - } catch (java.lang.NoSuchMethodException e) { - throw new java.lang.NoSuchMethodError( - "stub class initialization failed"); - } + try { + $method_ping_0 = Ping.class.getMethod("ping", new java.lang.Class[] {}); + $method_shutdown_1 = Ping.class.getMethod("shutdown", new java.lang.Class[] {}); + } catch (java.lang.NoSuchMethodException e) { + throw new java.lang.NoSuchMethodError( + "stub class initialization failed"); + } } - + // constructors public DownloadActivationGroup_Stub(java.rmi.server.RemoteRef ref) { - super(ref); + super(ref); } - + // methods from remote interfaces - + // implementation of ping() public void ping() - throws java.rmi.RemoteException + throws java.rmi.RemoteException { - try { - ref.invoke(this, $method_ping_0, null, 5866401369815527589L); - } catch (java.lang.RuntimeException e) { - throw e; - } catch (java.rmi.RemoteException e) { - throw e; - } catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } + try { + ref.invoke(this, $method_ping_0, null, 5866401369815527589L); + } catch (java.lang.RuntimeException e) { + throw e; + } catch (java.rmi.RemoteException e) { + throw e; + } catch (java.lang.Exception e) { + throw new java.rmi.UnexpectedException("undeclared checked exception", e); + } } - + // implementation of shutdown() public void shutdown() - throws java.lang.Exception + throws java.lang.Exception { - ref.invoke(this, $method_shutdown_1, null, -7207851917985848402L); + ref.invoke(this, $method_shutdown_1, null, -7207851917985848402L); } }
--- a/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/MyActivationGroupImpl.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/MyActivationGroupImpl.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -27,11 +27,11 @@ public class MyActivationGroupImpl extends ActivationGroupImpl { - + public MyActivationGroupImpl(ActivationGroupID id, MarshalledObject mobj) - throws RemoteException, ActivationException + throws RemoteException, ActivationException { - super(id, mobj); - System.err.println("custom group implementation created"); + super(id, mobj); + System.err.println("custom group implementation created"); } }
--- a/jdk/test/java/rmi/activation/ActivationGroupDesc/checkDefaultGroupName/CheckDefaultGroupName.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationGroupDesc/checkDefaultGroupName/CheckDefaultGroupName.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -42,19 +42,19 @@ */ public class CheckDefaultGroupName { public static void main(String[] args) { - System.out.println("\n\nRegression test for, 4252236\n\n"); + System.out.println("\n\nRegression test for, 4252236\n\n"); - ActivationGroupDesc groupDesc = - new ActivationGroupDesc(null, null); + ActivationGroupDesc groupDesc = + new ActivationGroupDesc(null, null); - String className = groupDesc.getClassName(); - if (className != null) { - TestLibrary.bomb("ActivationGroupDesc had incorrect default" + - " group implementation class name: " + className); - } else { - System.err.println("test passed, had correct default group" + - " implementation class name: " + className + - "\n\n"); - } + String className = groupDesc.getClassName(); + if (className != null) { + TestLibrary.bomb("ActivationGroupDesc had incorrect default" + + " group implementation class name: " + className); + } else { + System.err.println("test passed, had correct default group" + + " implementation class name: " + className + + "\n\n"); + } } }
--- a/jdk/test/java/rmi/activation/ActivationSystem/activeGroup/IdempotentActiveGroup.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationSystem/activeGroup/IdempotentActiveGroup.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -49,81 +49,81 @@ import java.rmi.server.UnicastRemoteObject; public class IdempotentActiveGroup { - + public static void main(String[] args) { - System.err.println("\nRegression test for bug 4720528\n"); - - TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); - RMID rmid = null; - ActivationInstantiator inst1 = null; - ActivationInstantiator inst2 = null; - - try { - RMID.removeLog(); - rmid = RMID.createRMID(); - rmid.start(); + System.err.println("\nRegression test for bug 4720528\n"); - System.err.println("Create group descriptor"); - ActivationGroupDesc groupDesc = - new ActivationGroupDesc(null, null); - ActivationSystem system = ActivationGroup.getSystem(); - System.err.println("Register group descriptor"); - ActivationGroupID groupID = system.registerGroup(groupDesc); - inst1 = new FakeInstantiator(); - inst2 = new FakeInstantiator(); - - System.err.println("Invoke activeGroup with inst1"); - system.activeGroup(groupID, inst1, 0); + TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); + RMID rmid = null; + ActivationInstantiator inst1 = null; + ActivationInstantiator inst2 = null; - try { - System.err.println("Invoke activeGroup with inst2"); - system.activeGroup(groupID, inst2, 0); - throw new RuntimeException( - "TEST FAILED: activeGroup with unequal groups succeeded!"); - } catch (ActivationException expected) { - System.err.println("Caught expected ActivationException"); - System.err.println("Test 1 (of 2) passed"); - } + try { + RMID.removeLog(); + rmid = RMID.createRMID(); + rmid.start(); - try { - System.err.println("Invoke activeGroup with inst1"); - system.activeGroup(groupID, inst1, 0); - System.err.println("activeGroup call succeeded"); - System.err.println("Test 2 (of 2) passed"); - } catch (ActivationException unexpected) { - throw new RuntimeException( - "TEST FAILED: activeGroup with equal groups failed!", - unexpected); - } - - } catch (Exception e) { - TestLibrary.bomb("test failed", e); - } finally { - try { - if (inst1 != null) { - UnicastRemoteObject.unexportObject(inst1, true); - } - if (inst2 != null) { - UnicastRemoteObject.unexportObject(inst2, true); - } - } catch (NoSuchObjectException unexpected) { - throw new AssertionError(unexpected); - } - ActivationLibrary.rmidCleanup(rmid); - } + System.err.println("Create group descriptor"); + ActivationGroupDesc groupDesc = + new ActivationGroupDesc(null, null); + ActivationSystem system = ActivationGroup.getSystem(); + System.err.println("Register group descriptor"); + ActivationGroupID groupID = system.registerGroup(groupDesc); + inst1 = new FakeInstantiator(); + inst2 = new FakeInstantiator(); + + System.err.println("Invoke activeGroup with inst1"); + system.activeGroup(groupID, inst1, 0); + + try { + System.err.println("Invoke activeGroup with inst2"); + system.activeGroup(groupID, inst2, 0); + throw new RuntimeException( + "TEST FAILED: activeGroup with unequal groups succeeded!"); + } catch (ActivationException expected) { + System.err.println("Caught expected ActivationException"); + System.err.println("Test 1 (of 2) passed"); + } + + try { + System.err.println("Invoke activeGroup with inst1"); + system.activeGroup(groupID, inst1, 0); + System.err.println("activeGroup call succeeded"); + System.err.println("Test 2 (of 2) passed"); + } catch (ActivationException unexpected) { + throw new RuntimeException( + "TEST FAILED: activeGroup with equal groups failed!", + unexpected); + } + + } catch (Exception e) { + TestLibrary.bomb("test failed", e); + } finally { + try { + if (inst1 != null) { + UnicastRemoteObject.unexportObject(inst1, true); + } + if (inst2 != null) { + UnicastRemoteObject.unexportObject(inst2, true); + } + } catch (NoSuchObjectException unexpected) { + throw new AssertionError(unexpected); + } + ActivationLibrary.rmidCleanup(rmid); + } } private static class FakeInstantiator - extends UnicastRemoteObject - implements ActivationInstantiator + extends UnicastRemoteObject + implements ActivationInstantiator { - FakeInstantiator() throws RemoteException {} + FakeInstantiator() throws RemoteException {} - public MarshalledObject newInstance(ActivationID id, - ActivationDesc desc) - { - throw new AssertionError(); - } + public MarshalledObject newInstance(ActivationID id, + ActivationDesc desc) + { + throw new AssertionError(); + } } }
--- a/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ActivateMe.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ActivateMe.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
--- a/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ModifyDescriptor.java Fri Apr 18 07:51:43 2008 -0400 +++ b/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ModifyDescriptor.java Wed Apr 23 06:35:28 2008 -0400 @@ -1,4 +1,4 @@ -/* +/* * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -25,7 +25,7 @@ * @bug 4127754 * * @summary synopsis: need to modify registered ActivationDesc and - * ActivationGroupDesc + * ActivationGroupDesc * @author Ann Wollrath * * @library ../../../testlibrary @@ -43,7 +43,7 @@ import java.util.*; public class ModifyDescriptor - implements ActivateMe, Runnable + implements ActivateMe, Runnable { private ActivationID id; @@ -54,28 +54,28 @@ public ModifyDescriptor(ActivationID id, MarshalledObject mobj) - throws ActivationException, RemoteException + throws ActivationException, RemoteException { - this.id = id; - Activatable.exportObject(this, id, 0); - - try { - message = (String) mobj.get(); - } catch (Exception e) { - System.err.println("unable to get message from marshalled object"); - } + this.id = id; + Activatable.exportObject(this, id, 0); + + try { + message = (String) mobj.get(); + } catch (Exception e) { + System.err.println("unable to get message from marshalled object"); + } } public String getMessage() { - return message; + return message; } public String getProperty(String name) { - return TestLibrary.getProperty(name, null); + return TestLibrary.getProperty(name, null); } public ActivationID getID() { - return id; + return id; } /** @@ -83,7 +83,7 @@ */ public void shutdown() throws Exception { - (new Thread(this,"ModifyDescriptor")).start(); + (new Thread(this,"ModifyDescriptor")).start(); } /** @@ -93,165 +93,165 @@ * unexport the object forcibly. */ public void run() { - ActivationLibrary.deactivate(this, getID()); + ActivationLibrary.deactivate(this, getID()); } - + public static void main(String[] args) { - System.out.println("\nRegression test for bug 4127754\n"); - - TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); + System.out.println("\nRegression test for bug 4127754\n"); - RMID rmid = null; - - try { - RMID.removeLog(); - rmid = RMID.createRMID(); - rmid.start(); + TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); - /* - * Create and register a group and activatable object - */ + RMID rmid = null; - System.err.println("Creating group descriptor"); - Properties props = new Properties(); - props.put("java.security.policy", - TestParams.defaultGroupPolicy); - props.put("java.security.manager", - TestParams.defaultSecurityManager); - props.put("test.message", MESSAGE1); - ActivationGroupDesc initialGroupDesc = - new ActivationGroupDesc(props, null); - System.err.println("Registering group"); - ActivationSystem system = ActivationGroup.getSystem(); - ActivationGroupID groupID = system.registerGroup(initialGroupDesc); - - System.err.println("Creating descriptor"); - ActivationDesc initialDesc = - new ActivationDesc(groupID, "ModifyDescriptor", null, - new MarshalledObject(MESSAGE1), false); - - System.err.println("Registering descriptor"); - ActivateMe obj = (ActivateMe) Activatable.register(initialDesc); + try { + RMID.removeLog(); + rmid = RMID.createRMID(); + rmid.start(); - /* - * Ping object and verify that MarshalledObject is okay. - */ - System.err.println("Ping object"); - String message1 = obj.getMessage(); - System.err.println("message = " + message1); + /* + * Create and register a group and activatable object + */ - if (message1.equals(MESSAGE1)) { - System.err.println("Test1a passed: initial MarshalledObject " + - "correct"); - } else { - TestLibrary.bomb("Test1 failed: unexpected MarshalledObject passed to " + - "constructor", null); - } + System.err.println("Creating group descriptor"); + Properties props = new Properties(); + props.put("java.security.policy", + TestParams.defaultGroupPolicy); + props.put("java.security.manager", + TestParams.defaultSecurityManager); + props.put("test.message", MESSAGE1); + ActivationGroupDesc initialGroupDesc = + new ActivationGroupDesc(props, null); + System.err.println("Registering group"); + ActivationSystem system = ActivationGroup.getSystem(); + ActivationGroupID groupID = system.registerGroup(initialGroupDesc); - /* - * Get property from remote group and make sure it's okay - */ - message1 = obj.getProperty("test.message"); - if (message1.equals(MESSAGE1)) { - System.err.println("Test1b passed: initial group property " + - "correct"); - } else { - TestLibrary.bomb("Test1 failed: unexpected property passed to " + - "group", null); - } + System.err.println("Creating descriptor"); + ActivationDesc initialDesc = + new ActivationDesc(groupID, "ModifyDescriptor", null, + new MarshalledObject(MESSAGE1), false); - /* - * Update activation descriptor for object and group - */ - System.err.println("Update activation descriptor"); - ActivationDesc newDesc =