1.1 --- a/.hgtags Fri Apr 18 12:47:38 2008 -0700
1.2 +++ b/.hgtags Fri Apr 18 16:40:32 2008 -0700
1.3 @@ -1,1 +1,2 @@
1.4 37a05a11f281b4d238e2f9e7ebb67c63f64d0e77 jdk7-b24
1.5 +75fca0b0ab83ab1392e615910cea020f66535390 jdk7-b25
2.1 --- a/make/com/sun/crypto/provider/Makefile Fri Apr 18 12:47:38 2008 -0700
2.2 +++ b/make/com/sun/crypto/provider/Makefile Fri Apr 18 16:40:32 2008 -0700
2.3 @@ -1,5 +1,5 @@
2.4 #
2.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
2.6 +# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
2.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.8 #
2.9 # This code is free software; you can redistribute it and/or modify it
2.10 @@ -87,8 +87,7 @@
2.11 # sign Alias for sign-jar
2.12 # sign-jar Builds/signs sunjce_provider.jar (no install)
2.13 #
2.14 -# obfus Builds/obfuscates/signs/installs
2.15 -# sunjce_provider.jar
2.16 +# obfus Builds/obfuscates/signs sunjce_provider.jar
2.17 #
2.18 # release Builds all targets in preparation
2.19 # for workspace integration.
2.20 @@ -101,8 +100,25 @@
2.21 BUILDDIR = ../../../..
2.22 PACKAGE = com.sun.crypto.provider
2.23 PRODUCT = sun
2.24 +
2.25 +#
2.26 +# The following is for when we need to do postprocessing
2.27 +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR
2.28 +# isn't writable, the build currently crashes out.
2.29 +#
2.30 +ifndef OPENJDK
2.31 + ifdef ALT_JCE_BUILD_DIR
2.32 + # =====================================================
2.33 + # Where to place the output, in case we're building from a read-only
2.34 + # build area. (e.g. a release engineering build.)
2.35 + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
2.36 + IGNORE_WRITABLE_OUTPUTDIR_TEST=true
2.37 + else
2.38 + JCE_BUILD_DIR=${TEMPDIR}
2.39 + endif
2.40 +endif
2.41 +
2.42 include $(BUILDDIR)/common/Defs.gmk
2.43 -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
2.44
2.45 #
2.46 # Location for the newly built classfiles.
2.47 @@ -147,6 +163,8 @@
2.48 #
2.49 UNSIGNED_DIR = $(TEMPDIR)/unsigned
2.50
2.51 +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
2.52 +
2.53
2.54 # =====================================================
2.55 # Build the unsigned sunjce_provider.jar file.
2.56 @@ -184,44 +202,66 @@
2.57 # Sign the provider jar file. Not needed for OpenJDK.
2.58 #
2.59
2.60 -SIGNED_DIR = $(TEMPDIR)/signed
2.61 +SIGNED_DIR = $(JCE_BUILD_DIR)/signed
2.62
2.63 sign: sign-jar
2.64
2.65 sign-jar: $(SIGNED_DIR)/sunjce_provider.jar
2.66
2.67 +ifndef ALT_JCE_BUILD_DIR
2.68 $(SIGNED_DIR)/sunjce_provider.jar: $(UNSIGNED_DIR)/sunjce_provider.jar
2.69 - $(sign-file)
2.70 +else
2.71 +#
2.72 +# We have to remove the build dependency, otherwise, we'll try to rebuild it
2.73 +# which we can't do on a read-only filesystem.
2.74 +#
2.75 +$(SIGNED_DIR)/sunjce_provider.jar:
2.76 + @if [ ! -r $(UNSIGNED_DIR)/sunjce_provider.jar ] ; then \
2.77 + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunjce_provider.jar"; \
2.78 + exit 1; \
2.79 + fi
2.80 +endif
2.81 + $(call sign-file, $(UNSIGNED_DIR)/sunjce_provider.jar)
2.82
2.83 # =====================================================
2.84 # Obfuscate/sign/install the JDK build. Not needed for OpenJDK.
2.85 #
2.86
2.87 -OBFUS_DIR = $(TEMPDIR)/obfus
2.88 +OBFUS_DIR = $(JCE_BUILD_DIR)/obfus/sunjce
2.89
2.90 CLOSED_DIR = $(BUILDDIR)/closed/com/sun/crypto/provider
2.91
2.92 obfus: $(OBFUS_DIR)/sunjce_provider.jar
2.93 $(release-warning)
2.94
2.95 -$(OBFUS_DIR)/sunjce_provider.jar: build-jar $(JCE_MANIFEST_FILE)
2.96 +ifndef ALT_JCE_BUILD_DIR
2.97 +$(OBFUS_DIR)/sunjce_provider.jar: build-jar $(JCE_MANIFEST_FILE) \
2.98 + $(OBFUS_DIR)/sunjce.dox
2.99 +else
2.100 +$(OBFUS_DIR)/sunjce_provider.jar: $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/sunjce.dox
2.101 + @if [ ! -d $(CLASSDESTDIR) ] ; then \
2.102 + $(ECHO) "Couldn't find $(CLASSDESTDIR)"; \
2.103 + exit 1; \
2.104 + fi
2.105 +endif
2.106 + @$(ECHO) ">>>Obfuscating SunJCE Provider..."
2.107 $(presign)
2.108 $(preobfus)
2.109 - @$(ECHO) ">>>Obfuscating Sun JCE Provider..."
2.110 $(prep-target)
2.111 $(CD) $(OBFUS_DIR); \
2.112 - $(OBFUSCATOR) -fv \
2.113 - $(CURRENT_DIRECTORY)/$(CLOSED_DIR)/obfus/sunjce.dox
2.114 + $(OBFUSCATOR) -fv sunjce.dox
2.115 @$(CD) $(OBFUS_DIR); $(java-vm-cleanup)
2.116 $(BOOT_JAR_CMD) cmf $(JCE_MANIFEST_FILE) $@ \
2.117 -C $(OBFUS_DIR)/build com \
2.118 $(JAR_JFLAGS)
2.119 $(sign-target)
2.120 - $(MKDIR) -p $(dir $(JAR_DESTFILE))
2.121 - $(RM) $(JAR_DESTFILE)
2.122 - $(CP) $@ $(JAR_DESTFILE)
2.123 @$(java-vm-cleanup)
2.124
2.125 +$(OBFUS_DIR)/sunjce.dox: $(CLOSED_DIR)/obfus/sunjce.dox
2.126 + @$(ECHO) ">>>Creating sunjce.dox"
2.127 + $(prep-target)
2.128 + $(SED) "s:@@TEMPDIR@@:$(ABS_TEMPDIR):" $< > $@
2.129 +
2.130 #
2.131 # The current obfuscator has a limitation in that it currently only
2.132 # supports up to v49 class file format. Force v49 classfiles in our
2.133 @@ -235,9 +275,9 @@
2.134 #
2.135
2.136 release: $(OBFUS_DIR)/sunjce_provider.jar
2.137 - $(RM) $(RELEASE_DIR)/sunjce_provider.jar
2.138 - $(MKDIR) -p $(RELEASE_DIR)
2.139 - $(CP) $(OBFUS_DIR)/sunjce_provider.jar $(RELEASE_DIR)
2.140 + $(RM) $(JCE_BUILD_DIR)/release/sunjce_provider.jar
2.141 + $(MKDIR) -p $(JCE_BUILD_DIR)/release
2.142 + $(CP) $(OBFUS_DIR)/sunjce_provider.jar $(JCE_BUILD_DIR)/release
2.143 $(release-warning)
2.144
2.145 endif # OPENJDK
2.146 @@ -275,7 +315,7 @@
2.147 #
2.148
2.149 clobber clean::
2.150 - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR)
2.151 + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
2.152
2.153 .PHONY: build-jar jar install-jar
2.154 ifndef OPENJDK
3.1 --- a/make/common/shared/Defs.gmk Fri Apr 18 12:47:38 2008 -0700
3.2 +++ b/make/common/shared/Defs.gmk Fri Apr 18 16:40:32 2008 -0700
3.3 @@ -1,5 +1,5 @@
3.4 #
3.5 -# Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
3.6 +# Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
3.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.8 #
3.9 # This code is free software; you can redistribute it and/or modify it
3.10 @@ -451,11 +451,20 @@
3.11 # Check for spaces and null value
3.12 OUTPUTDIR:=$(call AltCheckSpaces,OUTPUTDIR)
3.13 OUTPUTDIR:=$(call AltCheckValue,OUTPUTDIR)
3.14 +
3.15 +#
3.16 +# When signing the JCE framework and provider, we could be using built
3.17 +# bits on a read-only filesystem. If so, this test will fail and crash
3.18 +# the build.
3.19 +#
3.20 +ifndef IGNORE_WRITABLE_OUTPUTDIR_TEST
3.21 # Create the output directory and make sure it exists and is writable
3.22 _create_outputdir:=$(shell $(MKDIR) -p "$(OUTPUTDIR)" > $(DEV_NULL) 2>&1)
3.23 ifeq ($(call WriteDirExists,$(OUTPUTDIR),/dev/null),/dev/null)
3.24 _outputdir_error:=$(error "ERROR: OUTPUTDIR '$(OUTPUTDIR)' not created or not writable")
3.25 endif
3.26 +endif
3.27 +
3.28 # Define absolute path if needed and check for spaces and null value
3.29 ifndef ABS_OUTPUTDIR
3.30 ABS_OUTPUTDIR:=$(call FullPath,$(OUTPUTDIR))
4.1 --- a/make/javax/crypto/Defs-jce.gmk Fri Apr 18 12:47:38 2008 -0700
4.2 +++ b/make/javax/crypto/Defs-jce.gmk Fri Apr 18 16:40:32 2008 -0700
4.3 @@ -1,5 +1,5 @@
4.4 #
4.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
4.6 +# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
4.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.8 #
4.9 # This code is free software; you can redistribute it and/or modify it
4.10 @@ -31,7 +31,7 @@
4.11 JCE_MANIFEST_FILE = $(TEMPDIR)/manifest.mf
4.12 $(JCE_MANIFEST_FILE): $(MAINMANIFEST)
4.13 $(prep-target)
4.14 - ( $(SED) "s/@@RELEASE@@/$(RELEASE)/" $(MAINMANIFEST); \
4.15 + ( $(SED) "s/@@RELEASE@@/$(RELEASE)/" $<; \
4.16 $(ECHO) "Extension-Name: javax.crypto"; \
4.17 $(ECHO) "Implementation-Vendor-Id: com.sun"; ) > $@
4.18
4.19 @@ -75,6 +75,7 @@
4.20 define sign-target
4.21 $(BOOT_JARSIGNER_CMD) -keystore $(SIGNING_KEYSTORE) \
4.22 $@ $(SIGNING_ALIAS) < $(SIGNING_PASSPHRASE)
4.23 + @$(java-vm-cleanup)
4.24 @$(ECHO) "\nJar codesigning finished."
4.25 endef
4.26
4.27 @@ -88,13 +89,15 @@
4.28 endef
4.29
4.30 #
4.31 -# Convenience macro for steps needed to sign a jar file.
4.32 +# Convenience macros for signing a jar file.
4.33 +#
4.34 +# Call through $(call sign-file, target file)
4.35 #
4.36 define sign-file
4.37 $(presign)
4.38 - $(install-file)
4.39 + $(prep-target)
4.40 + $(CP) $1 $@
4.41 $(sign-target)
4.42 - @$(java-vm-cleanup)
4.43 endef
4.44
4.45 #
5.1 --- a/make/javax/crypto/Makefile Fri Apr 18 12:47:38 2008 -0700
5.2 +++ b/make/javax/crypto/Makefile Fri Apr 18 16:40:32 2008 -0700
5.3 @@ -1,5 +1,5 @@
5.4 #
5.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
5.6 +# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
5.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.8 #
5.9 # This code is free software; you can redistribute it and/or modify it
5.10 @@ -96,7 +96,7 @@
5.11 # sign-jar Builds/signs jce.jar file (no install)
5.12 # sign-policy Builds/signs policy files (no install)
5.13 #
5.14 -# obfus Builds/obfuscates/signs/installs jce.jar
5.15 +# obfus Builds/obfuscates/signs jce.jar
5.16 #
5.17 # release Builds all targets in preparation
5.18 # for workspace integration.
5.19 @@ -110,8 +110,24 @@
5.20 PACKAGE = javax.crypto
5.21 PRODUCT = sun
5.22
5.23 +#
5.24 +# The following is for when we need to do postprocessing
5.25 +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR
5.26 +# isn't writable, the build currently crashes out.
5.27 +#
5.28 +ifndef OPENJDK
5.29 + ifdef ALT_JCE_BUILD_DIR
5.30 + # =====================================================
5.31 + # Where to place the output, in case we're building from a read-only
5.32 + # build area. (e.g. a release engineering build.)
5.33 + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
5.34 + IGNORE_WRITABLE_OUTPUTDIR_TEST=true
5.35 + else
5.36 + JCE_BUILD_DIR=${TEMPDIR}
5.37 + endif
5.38 +endif
5.39 +
5.40 include $(BUILDDIR)/common/Defs.gmk
5.41 -include Defs-jce.gmk
5.42
5.43 #
5.44 # Location for the newly built classfiles.
5.45 @@ -158,6 +174,8 @@
5.46 #
5.47 UNSIGNED_DIR = $(TEMPDIR)/unsigned
5.48
5.49 +include Defs-jce.gmk
5.50 +
5.51
5.52 # =====================================================
5.53 # Build the unsigned jce.jar file. Signing/obfuscation comes later.
5.54 @@ -299,7 +317,7 @@
5.55 # Sign the various jar files. Not needed for OpenJDK.
5.56 #
5.57
5.58 -SIGNED_DIR = $(TEMPDIR)/signed
5.59 +SIGNED_DIR = $(JCE_BUILD_DIR)/signed
5.60 SIGNED_POLICY_BUILDDIR = $(SIGNED_DIR)/policy
5.61
5.62 SIGNED_POLICY_FILES = \
5.63 @@ -312,61 +330,87 @@
5.64
5.65 sign-policy: $(SIGNED_POLICY_FILES)
5.66
5.67 +ifndef ALT_JCE_BUILD_DIR
5.68 $(SIGNED_DIR)/jce.jar: $(UNSIGNED_DIR)/jce.jar
5.69 - $(sign-file)
5.70 +else
5.71 +#
5.72 +# We have to remove the build dependency, otherwise, we'll try to rebuild it
5.73 +# which we can't do on a read-only filesystem.
5.74 +#
5.75 +$(SIGNED_DIR)/jce.jar:
5.76 + @if [ ! -r $(UNSIGNED_DIR)/jce.jar ] ; then \
5.77 + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/jce.jar"; \
5.78 + exit 1; \
5.79 + fi
5.80 +endif
5.81 + $(call sign-file, $(UNSIGNED_DIR)/jce.jar)
5.82
5.83 $(SIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar: \
5.84 -$(UNSIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar
5.85 - $(sign-file)
5.86 + $(UNSIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar
5.87 + $(call sign-file, $<)
5.88
5.89 $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar: \
5.90 -$(UNSIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar
5.91 - $(sign-file)
5.92 + $(UNSIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar
5.93 + $(call sign-file, $<)
5.94
5.95 $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar: \
5.96 -$(UNSIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar
5.97 - $(sign-file)
5.98 + $(UNSIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar
5.99 + $(call sign-file, $<)
5.100
5.101 $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar: \
5.102 -$(UNSIGNED_POLICY_BUILDDIR)/limited/local_policy.jar
5.103 - $(sign-file)
5.104 + $(UNSIGNED_POLICY_BUILDDIR)/limited/local_policy.jar
5.105 + $(call sign-file, $<)
5.106
5.107
5.108 # =====================================================
5.109 # Obfuscate/sign/install the JDK build. Not needed for OpenJDK.
5.110 #
5.111
5.112 -OBFUS_DIR = $(TEMPDIR)/obfus
5.113 +OBFUS_DIR = $(JCE_BUILD_DIR)/obfus/jce
5.114
5.115 CLOSED_DIR = $(BUILDDIR)/closed/javax/crypto
5.116
5.117 obfus: $(OBFUS_DIR)/jce.jar
5.118 $(release-warning)
5.119
5.120 -$(OBFUS_DIR)/jce.jar: build-jar $(JCE_MANIFEST_FILE)
5.121 +ifndef ALT_JCE_BUILD_DIR
5.122 +$(OBFUS_DIR)/jce.jar: build-jar $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/framework.dox
5.123 +else
5.124 +#
5.125 +# We have to remove the build dependency, otherwise, we'll try to rebuild it
5.126 +# which we can't do on a read-only filesystem.
5.127 +#
5.128 +$(OBFUS_DIR)/jce.jar: $(JCE_MANIFEST_FILE) $(OBFUS_DIR)/framework.dox
5.129 + @if [ ! -d $(CLASSDESTDIR) ] ; then \
5.130 + $(ECHO) "Couldn't find $(CLASSDESTDIR)"; \
5.131 + exit 1; \
5.132 + fi
5.133 +endif
5.134 + @$(ECHO) ">>>Obfuscating JCE framework..."
5.135 $(presign)
5.136 $(preobfus)
5.137 - @$(ECHO) ">>>Obfuscating JCE framework..."
5.138 $(prep-target)
5.139 $(CD) $(OBFUS_DIR); \
5.140 - $(OBFUSCATOR) -fv \
5.141 - $(CURRENT_DIRECTORY)/$(CLOSED_DIR)/obfus/framework.dox
5.142 + $(OBFUSCATOR) -fv framework.dox
5.143 @$(CD) $(OBFUS_DIR); $(java-vm-cleanup)
5.144 + @#
5.145 @# The sun.security.internal classes are currently not obfuscated
5.146 @# due to an obfus problem. Manually copy them to the build directory
5.147 @# so that they are included in the jce.jar file.
5.148 + @#
5.149 $(CP) -r $(CLASSDESTDIR)/sun $(OBFUS_DIR)/build
5.150 - $(RM) $(UNSIGNED_DIR)/jce.jar
5.151 $(BOOT_JAR_CMD) cmf $(JCE_MANIFEST_FILE) $@ \
5.152 -C $(OBFUS_DIR)/build javax \
5.153 -C $(OBFUS_DIR)/build sun \
5.154 $(JAR_JFLAGS)
5.155 $(sign-target)
5.156 - $(MKDIR) -p $(dir $(JAR_DESTFILE))
5.157 - $(RM) $(JAR_DESTFILE)
5.158 - $(CP) $@ $(JAR_DESTFILE)
5.159 @$(java-vm-cleanup)
5.160
5.161 +$(OBFUS_DIR)/framework.dox: $(CLOSED_DIR)/obfus/framework.dox
5.162 + @$(ECHO) ">>>Creating framework.dox"
5.163 + $(prep-target)
5.164 + $(SED) "s:@@TEMPDIR@@:$(ABS_TEMPDIR):" $< > $@
5.165 +
5.166 #
5.167 # The current obfuscator has a limitation in that it currently only
5.168 # supports up to v49 class file format. Force v49 classfiles in our
5.169 @@ -380,26 +424,27 @@
5.170 # unlimited policy file distribution, etc.
5.171 #
5.172
5.173 -release: $(OBFUS_DIR)/jce.jar sign-policy
5.174 +release: $(OBFUS_DIR)/jce.jar sign-policy $(CLOSED_DIR)/doc/COPYRIGHT.html \
5.175 + $(CLOSED_DIR)/doc/README.txt
5.176 $(RM) -r \
5.177 - $(RELEASE_DIR)/UnlimitedJCEPolicy \
5.178 - $(RELEASE_DIR)/jce.jar \
5.179 - $(RELEASE_DIR)/US_export_policy.jar \
5.180 - $(RELEASE_DIR)/local_policy.jar \
5.181 - $(RELEASE_DIR)/UnlimitedJCEPolicy.zip
5.182 - $(MKDIR) -p $(RELEASE_DIR)/UnlimitedJCEPolicy
5.183 - $(CP) $(OBFUS_DIR)/jce.jar $(RELEASE_DIR)
5.184 - $(CP) -r \
5.185 - $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar \
5.186 - $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar \
5.187 - $(RELEASE_DIR)
5.188 + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy \
5.189 + $(JCE_BUILD_DIR)/release/jce.jar \
5.190 + $(JCE_BUILD_DIR)/release/US_export_policy.jar \
5.191 + $(JCE_BUILD_DIR)/release/local_policy.jar \
5.192 + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy.zip
5.193 + $(MKDIR) -p $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy
5.194 + $(CP) $(OBFUS_DIR)/jce.jar $(JCE_BUILD_DIR)/release
5.195 + $(CP) \
5.196 + $(SIGNED_POLICY_BUILDDIR)/limited/US_export_policy.jar \
5.197 + $(SIGNED_POLICY_BUILDDIR)/limited/local_policy.jar \
5.198 + $(JCE_BUILD_DIR)/release
5.199 $(CP) \
5.200 $(SIGNED_POLICY_BUILDDIR)/unlimited/US_export_policy.jar \
5.201 - $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar \
5.202 - $(RELEASE_DIR)/UnlimitedJCEPolicy
5.203 - $(CP) $(CLOSED_DIR)/doc/COPYRIGHT.html \
5.204 - $(CLOSED_DIR)/doc/README.txt $(RELEASE_DIR)/UnlimitedJCEPolicy
5.205 - cd $(RELEASE_DIR) ; \
5.206 + $(SIGNED_POLICY_BUILDDIR)/unlimited/local_policy.jar \
5.207 + $(CLOSED_DIR)/doc/COPYRIGHT.html \
5.208 + $(CLOSED_DIR)/doc/README.txt \
5.209 + $(JCE_BUILD_DIR)/release/UnlimitedJCEPolicy
5.210 + cd $(JCE_BUILD_DIR)/release ; \
5.211 $(ZIPEXE) -qr UnlimitedJCEPolicy.zip UnlimitedJCEPolicy
5.212 $(release-warning)
5.213
5.214 @@ -478,7 +523,8 @@
5.215
5.216 clobber clean::
5.217 $(RM) -r $(JAR_DESTFILE) $(POLICY_DESTDIR)/US_export_policy.jar \
5.218 - $(POLICY_DESTDIR)/local_policy.jar $(DELETE_DIRS) $(TEMPDIR)
5.219 + $(POLICY_DESTDIR)/local_policy.jar $(DELETE_DIRS) $(TEMPDIR) \
5.220 + $(JCE_BUILD_DIR)
5.221
5.222 .PHONY: build-jar jar build-policy unlimited limited install-jar \
5.223 install-limited install-unlimited
6.1 --- a/make/sun/security/mscapi/Makefile Fri Apr 18 12:47:38 2008 -0700
6.2 +++ b/make/sun/security/mscapi/Makefile Fri Apr 18 16:40:32 2008 -0700
6.3 @@ -1,5 +1,5 @@
6.4 #
6.5 -# Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
6.6 +# Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
6.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.8 #
6.9 # This code is free software; you can redistribute it and/or modify it
6.10 @@ -92,8 +92,25 @@
6.11 PACKAGE = sun.security.mscapi
6.12 LIBRARY = sunmscapi
6.13 PRODUCT = sun
6.14 +
6.15 +#
6.16 +# The following is for when we need to do postprocessing
6.17 +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR
6.18 +# isn't writable, the build currently crashes out.
6.19 +#
6.20 +ifndef OPENJDK
6.21 + ifdef ALT_JCE_BUILD_DIR
6.22 + # =====================================================
6.23 + # Where to place the output, in case we're building from a read-only
6.24 + # build area. (e.g. a release engineering build.)
6.25 + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
6.26 + IGNORE_WRITABLE_OUTPUTDIR_TEST=true
6.27 + else
6.28 + JCE_BUILD_DIR=${TEMPDIR}
6.29 + endif
6.30 +endif
6.31 +
6.32 include $(BUILDDIR)/common/Defs.gmk
6.33 -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
6.34
6.35 CPLUSPLUSLIBRARY=true
6.36
6.37 @@ -163,6 +180,8 @@
6.38 $(build-warning)
6.39 endif
6.40
6.41 +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
6.42 +
6.43
6.44 # =====================================================
6.45 # Build the unsigned sunmscapi.jar file.
6.46 @@ -200,14 +219,26 @@
6.47 # Sign the provider jar file. Not needed for OpenJDK.
6.48 #
6.49
6.50 -SIGNED_DIR = $(TEMPDIR)/signed
6.51 +SIGNED_DIR = $(JCE_BUILD_DIR)/signed
6.52
6.53 sign: sign-jar
6.54
6.55 sign-jar: $(SIGNED_DIR)/sunmscapi.jar
6.56
6.57 +ifndef ALT_JCE_BUILD_DIR
6.58 $(SIGNED_DIR)/sunmscapi.jar: $(UNSIGNED_DIR)/sunmscapi.jar
6.59 - $(sign-file)
6.60 +else
6.61 +#
6.62 +# We have to remove the build dependency, otherwise, we'll try to rebuild it
6.63 +# which we can't do on a read-only filesystem.
6.64 +#
6.65 +$(SIGNED_DIR)/sunmscapi.jar:
6.66 + @if [ ! -r $(UNSIGNED_DIR)/sunmscapi.jar ] ; then \
6.67 + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunmscapi.jar"; \
6.68 + exit 1; \
6.69 + fi
6.70 +endif
6.71 + $(call sign-file, $(UNSIGNED_DIR)/sunmscapi.jar)
6.72
6.73
6.74 # =====================================================
6.75 @@ -215,9 +246,9 @@
6.76 #
6.77
6.78 release: $(SIGNED_DIR)/sunmscapi.jar
6.79 - $(RM) $(RELEASE_DIR)/sunmscapi.jar
6.80 - $(MKDIR) -p $(RELEASE_DIR)
6.81 - $(CP) $(SIGNED_DIR)/sunmscapi.jar $(RELEASE_DIR)
6.82 + $(RM) $(JCE_BUILD_DIR)/release/sunmscapi.jar
6.83 + $(MKDIR) -p $(JCE_BUILD_DIR)/release
6.84 + $(CP) $(SIGNED_DIR)/sunmscapi.jar $(JCE_BUILD_DIR)/release
6.85 $(release-warning)
6.86
6.87 endif # OPENJDK
6.88 @@ -255,7 +286,7 @@
6.89 #
6.90
6.91 clobber clean::
6.92 - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR)
6.93 + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
6.94
6.95 .PHONY: build-jar jar install-jar
6.96 ifndef OPENJDK
7.1 --- a/make/sun/security/pkcs11/Makefile Fri Apr 18 12:47:38 2008 -0700
7.2 +++ b/make/sun/security/pkcs11/Makefile Fri Apr 18 16:40:32 2008 -0700
7.3 @@ -1,5 +1,5 @@
7.4 #
7.5 -# Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
7.6 +# Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
7.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.8 #
7.9 # This code is free software; you can redistribute it and/or modify it
7.10 @@ -92,8 +92,25 @@
7.11 PACKAGE = sun.security.pkcs11
7.12 LIBRARY = j2pkcs11
7.13 PRODUCT = sun
7.14 +
7.15 +#
7.16 +# The following is for when we need to do postprocessing
7.17 +# (signing/obfuscation) against a read-only build. If the OUTPUTDIR
7.18 +# isn't writable, the build currently crashes out.
7.19 +#
7.20 +ifndef OPENJDK
7.21 + ifdef ALT_JCE_BUILD_DIR
7.22 + # =====================================================
7.23 + # Where to place the output, in case we're building from a read-only
7.24 + # build area. (e.g. a release engineering build.)
7.25 + JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
7.26 + IGNORE_WRITABLE_OUTPUTDIR_TEST=true
7.27 + else
7.28 + JCE_BUILD_DIR=${TEMPDIR}
7.29 + endif
7.30 +endif
7.31 +
7.32 include $(BUILDDIR)/common/Defs.gmk
7.33 -include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
7.34
7.35 #
7.36 # C and Java Files
7.37 @@ -163,6 +180,8 @@
7.38 $(build-warning)
7.39 endif
7.40
7.41 +include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
7.42 +
7.43
7.44 # =====================================================
7.45 # Build the unsigned sunpkcs11.jar file.
7.46 @@ -200,14 +219,26 @@
7.47 # Sign the provider jar file. Not needed for OpenJDK.
7.48 #
7.49
7.50 -SIGNED_DIR = $(TEMPDIR)/signed
7.51 +SIGNED_DIR = $(JCE_BUILD_DIR)/signed
7.52
7.53 sign: sign-jar
7.54
7.55 sign-jar: $(SIGNED_DIR)/sunpkcs11.jar
7.56
7.57 +ifndef ALT_JCE_BUILD_DIR
7.58 $(SIGNED_DIR)/sunpkcs11.jar: $(UNSIGNED_DIR)/sunpkcs11.jar
7.59 - $(sign-file)
7.60 +else
7.61 +#
7.62 +# We have to remove the build dependency, otherwise, we'll try to rebuild it
7.63 +# which we can't do on a read-only filesystem.
7.64 +#
7.65 +$(SIGNED_DIR)/sunpkcs11.jar:
7.66 + @if [ ! -r $(UNSIGNED_DIR)/sunpkcs11.jar ] ; then \
7.67 + $(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunpkcs11.jar"; \
7.68 + exit 1; \
7.69 + fi
7.70 +endif
7.71 + $(call sign-file, $(UNSIGNED_DIR)/sunpkcs11.jar)
7.72
7.73
7.74 # =====================================================
7.75 @@ -215,9 +246,9 @@
7.76 #
7.77
7.78 release: $(SIGNED_DIR)/sunpkcs11.jar
7.79 - $(RM) $(RELEASE_DIR)/sunpkcs11.jar
7.80 - $(MKDIR) -p $(RELEASE_DIR)
7.81 - $(CP) $(SIGNED_DIR)/sunpkcs11.jar $(RELEASE_DIR)
7.82 + $(RM) $(JCE_BUILD_DIR)/release/sunpkcs11.jar
7.83 + $(MKDIR) -p $(JCE_BUILD_DIR)/release
7.84 + $(CP) $(SIGNED_DIR)/sunpkcs11.jar $(JCE_BUILD_DIR)/release
7.85 $(release-warning)
7.86
7.87 endif # OPENJDK
7.88 @@ -255,7 +286,7 @@
7.89 #
7.90
7.91 clobber clean::
7.92 - $(RM) -r $(JAR_DESTFILE) $(TEMPDIR)
7.93 + $(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
7.94
7.95 .PHONY: build-jar jar install-jar
7.96 ifndef OPENJDK
8.1 --- a/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Fri Apr 18 12:47:38 2008 -0700
8.2 +++ b/src/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java Fri Apr 18 16:40:32 2008 -0700
8.3 @@ -34,8 +34,6 @@
8.4 import java.util.HashSet;
8.5 import java.util.WeakHashMap;
8.6 import java.lang.ref.WeakReference;
8.7 -import java.io.PrintWriter;
8.8 -import java.io.StringWriter;
8.9 import java.security.AccessControlContext;
8.10 import java.security.Permission;
8.11 import java.security.ProtectionDomain;
8.12 @@ -51,7 +49,6 @@
8.13 import javax.management.InstanceNotFoundException;
8.14 import javax.management.IntrospectionException;
8.15 import javax.management.InvalidAttributeValueException;
8.16 -import javax.management.JMException;
8.17 import javax.management.JMRuntimeException;
8.18 import javax.management.ListenerNotFoundException;
8.19 import javax.management.MalformedObjectNameException;
8.20 @@ -84,11 +81,10 @@
8.21 import com.sun.jmx.mbeanserver.DynamicMBean2;
8.22 import com.sun.jmx.mbeanserver.ModifiableClassLoaderRepository;
8.23 import com.sun.jmx.mbeanserver.MBeanInstantiator;
8.24 -import com.sun.jmx.mbeanserver.MXBeanSupport;
8.25 import com.sun.jmx.mbeanserver.Repository;
8.26 import com.sun.jmx.mbeanserver.NamedObject;
8.27 -import com.sun.jmx.defaults.ServiceName;
8.28 import com.sun.jmx.mbeanserver.Introspector;
8.29 +import com.sun.jmx.mbeanserver.Util;
8.30 import com.sun.jmx.remote.util.EnvHelp;
8.31
8.32 /**
8.33 @@ -623,18 +619,9 @@
8.34 List<String> result = new ArrayList<String>(domains.length);
8.35 for (int i = 0; i < domains.length; i++) {
8.36 try {
8.37 - ObjectName domain = new ObjectName(domains[i] + ":x=x");
8.38 + ObjectName domain = Util.newObjectName(domains[i] + ":x=x");
8.39 checkMBeanPermission((String) null, null, domain, "getDomains");
8.40 result.add(domains[i]);
8.41 - } catch (MalformedObjectNameException e) {
8.42 - // Should never occur... But let's log it just in case.
8.43 - if (MBEANSERVER_LOGGER.isLoggable(Level.SEVERE)) {
8.44 - MBEANSERVER_LOGGER.logp(Level.SEVERE,
8.45 - DefaultMBeanServerInterceptor.class.getName(),
8.46 - "getDomains",
8.47 - "Failed to check permission for domain = " +
8.48 - domains[i], e);
8.49 - }
8.50 } catch (SecurityException e) {
8.51 // OK: Do not add this domain to the list
8.52 }
9.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java Fri Apr 18 12:47:38 2008 -0700
9.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/MBeanAnalyzer.java Fri Apr 18 16:40:32 2008 -0700
9.3 @@ -107,10 +107,7 @@
9.4 private MBeanAnalyzer(Class<?> mbeanInterface,
9.5 MBeanIntrospector<M> introspector)
9.6 throws NotCompliantMBeanException {
9.7 - if (!mbeanInterface.isInterface()) {
9.8 - throw new NotCompliantMBeanException("Not an interface: " +
9.9 - mbeanInterface.getName());
9.10 - }
9.11 + introspector.checkCompliance(mbeanInterface);
9.12
9.13 try {
9.14 initMaps(mbeanInterface, introspector);
9.15 @@ -121,11 +118,10 @@
9.16
9.17 // Introspect the mbeanInterface and initialize this object's maps.
9.18 //
9.19 - private void initMaps(Class<?> mbeanInterface,
9.20 + private void initMaps(Class<?> mbeanType,
9.21 MBeanIntrospector<M> introspector) throws Exception {
9.22 - final Method[] methodArray = mbeanInterface.getMethods();
9.23 -
9.24 - final List<Method> methods = eliminateCovariantMethods(methodArray);
9.25 + final List<Method> methods1 = introspector.getMethods(mbeanType);
9.26 + final List<Method> methods = eliminateCovariantMethods(methods1);
9.27
9.28 /* Run through the methods to detect inconsistencies and to enable
9.29 us to give getter and setter together to visitAttribute. */
9.30 @@ -234,13 +230,13 @@
9.31 but existing code may depend on it and users may be used to seeing
9.32 operations or attributes appear in a particular order. */
9.33 static List<Method>
9.34 - eliminateCovariantMethods(Method[] methodArray) {
9.35 + eliminateCovariantMethods(List<Method> startMethods) {
9.36 // We are assuming that you never have very many methods with the
9.37 // same name, so it is OK to use algorithms that are quadratic
9.38 // in the number of methods with the same name.
9.39
9.40 - final int len = methodArray.length;
9.41 - final Method[] sorted = methodArray.clone();
9.42 + final int len = startMethods.size();
9.43 + final Method[] sorted = startMethods.toArray(new Method[len]);
9.44 Arrays.sort(sorted,MethodOrder.instance);
9.45 final Set<Method> overridden = newSet();
9.46 for (int i=1;i<len;i++) {
9.47 @@ -259,7 +255,7 @@
9.48 }
9.49 }
9.50
9.51 - final List<Method> methods = newList(Arrays.asList(methodArray));
9.52 + final List<Method> methods = newList(startMethods);
9.53 methods.removeAll(overridden);
9.54 return methods;
9.55 }
10.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Fri Apr 18 12:47:38 2008 -0700
10.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java Fri Apr 18 16:40:32 2008 -0700
10.3 @@ -34,6 +34,7 @@
10.4 import java.lang.reflect.InvocationTargetException;
10.5 import java.lang.reflect.Method;
10.6 import java.lang.reflect.Type;
10.7 +import java.util.Arrays;
10.8 import java.util.List;
10.9 import java.util.WeakHashMap;
10.10
10.11 @@ -169,6 +170,19 @@
10.12 */
10.13 abstract Descriptor getMBeanDescriptor(Class<?> resourceClass);
10.14
10.15 + void checkCompliance(Class<?> mbeanType) throws NotCompliantMBeanException {
10.16 + if (!mbeanType.isInterface()) {
10.17 + throw new NotCompliantMBeanException("Not an interface: " +
10.18 + mbeanType.getName());
10.19 + }
10.20 + }
10.21 +
10.22 + /**
10.23 + * Get the methods to be analyzed to build the MBean interface.
10.24 + */
10.25 + List<Method> getMethods(final Class<?> mbeanType) throws Exception {
10.26 + return Arrays.asList(mbeanType.getMethods());
10.27 + }
10.28
10.29 final PerInterface<M> getPerInterface(Class<?> mbeanInterface)
10.30 throws NotCompliantMBeanException {
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/NotificationMBeanSupport.java Fri Apr 18 16:40:32 2008 -0700
11.3 @@ -0,0 +1,81 @@
11.4 +/*
11.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Sun designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Sun in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
11.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
11.26 + * have any questions.
11.27 + */
11.28 +
11.29 +package com.sun.jmx.mbeanserver;
11.30 +
11.31 +import java.lang.reflect.Method;
11.32 +import java.util.ArrayList;
11.33 +import java.util.List;
11.34 +import javax.management.NotCompliantMBeanException;
11.35 +import javax.management.Notification;
11.36 +
11.37 +/**
11.38 + * <p>A variant of {@code StandardMBeanSupport} where the only
11.39 + * methods included are public getters. This is used by
11.40 + * {@code QueryNotificationFilter} to pretend that a Notification is
11.41 + * an MBean so it can have a query evaluated on it. Standard queries
11.42 + * never set attributes or invoke methods but custom queries could and
11.43 + * we don't want to allow that. Also we don't want to fail if a
11.44 + * Notification happens to have inconsistent types in a pair of getX and
11.45 + * setX methods, and we want to include the Object.getClass() method.
11.46 + */
11.47 +public class NotificationMBeanSupport extends StandardMBeanSupport {
11.48 + public <T extends Notification> NotificationMBeanSupport(T n)
11.49 + throws NotCompliantMBeanException {
11.50 + super(n, Util.<Class<T>>cast(n.getClass()));
11.51 + }
11.52 +
11.53 + @Override
11.54 + MBeanIntrospector<Method> getMBeanIntrospector() {
11.55 + return introspector;
11.56 + }
11.57 +
11.58 + private static class Introspector extends StandardMBeanIntrospector {
11.59 + @Override
11.60 + void checkCompliance(Class<?> mbeanType) {}
11.61 +
11.62 + @Override
11.63 + List<Method> getMethods(final Class<?> mbeanType)
11.64 + throws Exception {
11.65 + List<Method> methods = new ArrayList<Method>();
11.66 + for (Method m : mbeanType.getMethods()) {
11.67 + String name = m.getName();
11.68 + Class<?> ret = m.getReturnType();
11.69 + if (m.getParameterTypes().length == 0) {
11.70 + if ((name.startsWith("is") && name.length() > 2 &&
11.71 + ret == boolean.class) ||
11.72 + (name.startsWith("get") && name.length() > 3 &&
11.73 + ret != void.class)) {
11.74 + methods.add(m);
11.75 + }
11.76 + }
11.77 + }
11.78 + return methods;
11.79 + }
11.80 +
11.81 + }
11.82 + private static final MBeanIntrospector<Method> introspector =
11.83 + new Introspector();
11.84 +}
12.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/OpenConverter.java Fri Apr 18 12:47:38 2008 -0700
12.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/OpenConverter.java Fri Apr 18 16:40:32 2008 -0700
12.3 @@ -438,7 +438,7 @@
12.4 c.getClassLoader() == null);
12.5
12.6 final List<Method> methods =
12.7 - MBeanAnalyzer.eliminateCovariantMethods(c.getMethods());
12.8 + MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
12.9 final SortedMap<String,Method> getterMap = newSortedMap();
12.10
12.11 /* Select public methods that look like "T getX()" or "boolean
12.12 @@ -1118,11 +1118,11 @@
12.13 final Class<ConstructorProperties> propertyNamesClass = ConstructorProperties.class;
12.14
12.15 Class targetClass = getTargetClass();
12.16 - Constructor[] constrs = targetClass.getConstructors();
12.17 + Constructor<?>[] constrs = targetClass.getConstructors();
12.18
12.19 // Applicable if and only if there are any annotated constructors
12.20 - List<Constructor> annotatedConstrList = newList();
12.21 - for (Constructor constr : constrs) {
12.22 + List<Constructor<?>> annotatedConstrList = newList();
12.23 + for (Constructor<?> constr : constrs) {
12.24 if (Modifier.isPublic(constr.getModifiers())
12.25 && constr.getAnnotation(propertyNamesClass) != null)
12.26 annotatedConstrList.add(constr);
12.27 @@ -1152,7 +1152,7 @@
12.28 // Also remember the set of properties in that constructor
12.29 // so we can test unambiguity.
12.30 Set<BitSet> getterIndexSets = newSet();
12.31 - for (Constructor constr : annotatedConstrList) {
12.32 + for (Constructor<?> constr : annotatedConstrList) {
12.33 String[] propertyNames =
12.34 constr.getAnnotation(propertyNamesClass).value();
12.35
12.36 @@ -1309,10 +1309,10 @@
12.37 }
12.38
12.39 private static class Constr {
12.40 - final Constructor constructor;
12.41 + final Constructor<?> constructor;
12.42 final int[] paramIndexes;
12.43 final BitSet presentParams;
12.44 - Constr(Constructor constructor, int[] paramIndexes,
12.45 + Constr(Constructor<?> constructor, int[] paramIndexes,
12.46 BitSet presentParams) {
12.47 this.constructor = constructor;
12.48 this.paramIndexes = paramIndexes;
13.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Fri Apr 18 12:47:38 2008 -0700
13.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/Repository.java Fri Apr 18 16:40:32 2008 -0700
13.3 @@ -415,17 +415,8 @@
13.4 boolean to_default_domain = false;
13.5
13.6 // Set domain to default if domain is empty and not already set
13.7 - if (dom.length() == 0) {
13.8 - try {
13.9 - name = new ObjectName(domain + name.toString());
13.10 - } catch (MalformedObjectNameException e) {
13.11 - if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
13.12 - MBEANSERVER_LOGGER.logp(Level.FINEST,
13.13 - Repository.class.getName(), "addMBean",
13.14 - "Unexpected MalformedObjectNameException", e);
13.15 - }
13.16 - }
13.17 - }
13.18 + if (dom.length() == 0)
13.19 + name = Util.newObjectName(domain + name.toString());
13.20
13.21 // Do we have default domain ?
13.22 if (dom == domain) {
14.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/Util.java Fri Apr 18 12:47:38 2008 -0700
14.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/Util.java Fri Apr 18 16:40:32 2008 -0700
14.3 @@ -38,6 +38,8 @@
14.4 import java.util.Set;
14.5 import java.util.SortedMap;
14.6 import java.util.TreeMap;
14.7 +import javax.management.MalformedObjectNameException;
14.8 +import javax.management.ObjectName;
14.9
14.10 public class Util {
14.11 static <K, V> Map<K, V> newMap() {
14.12 @@ -85,6 +87,14 @@
14.13 return new ArrayList<E>(c);
14.14 }
14.15
14.16 + public static ObjectName newObjectName(String s) {
14.17 + try {
14.18 + return new ObjectName(s);
14.19 + } catch (MalformedObjectNameException e) {
14.20 + throw new IllegalArgumentException(e);
14.21 + }
14.22 + }
14.23 +
14.24 /* This method can be used by code that is deliberately violating the
14.25 * allowed checked casts. Rather than marking the whole method containing
14.26 * the code with @SuppressWarnings, you can use a call to this method for
15.1 --- a/src/share/classes/com/sun/management/package.html Fri Apr 18 12:47:38 2008 -0700
15.2 +++ b/src/share/classes/com/sun/management/package.html Fri Apr 18 16:40:32 2008 -0700
15.3 @@ -1,4 +1,4 @@
15.4 -CTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
15.5 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
15.6 <html>
15.7 <head>
15.8 <!--
16.1 --- a/src/share/classes/java/beans/MetaData.java Fri Apr 18 12:47:38 2008 -0700
16.2 +++ b/src/share/classes/java/beans/MetaData.java Fri Apr 18 16:40:32 2008 -0700
16.3 @@ -1553,7 +1553,7 @@
16.4 private static String[] getConstructorProperties(Class type) {
16.5 String[] names = null;
16.6 int length = 0;
16.7 - for (Constructor constructor : type.getConstructors()) {
16.8 + for (Constructor<?> constructor : type.getConstructors()) {
16.9 String[] value = getAnnotationValue(constructor);
16.10 if ((value != null) && (length < value.length) && isValid(constructor, value)) {
16.11 names = value;
16.12 @@ -1563,14 +1563,14 @@
16.13 return names;
16.14 }
16.15
16.16 - private static String[] getAnnotationValue(Constructor constructor) {
16.17 + private static String[] getAnnotationValue(Constructor<?> constructor) {
16.18 ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
16.19 return (annotation != null)
16.20 ? annotation.value()
16.21 : null;
16.22 }
16.23
16.24 - private static boolean isValid(Constructor constructor, String[] names) {
16.25 + private static boolean isValid(Constructor<?> constructor, String[] names) {
16.26 Class[] parameters = constructor.getParameterTypes();
16.27 if (names.length != parameters.length) {
16.28 return false;
17.1 --- a/src/share/classes/java/lang/instrument/Instrumentation.java Fri Apr 18 12:47:38 2008 -0700
17.2 +++ b/src/share/classes/java/lang/instrument/Instrumentation.java Fri Apr 18 16:40:32 2008 -0700
17.3 @@ -636,7 +636,11 @@
17.4 * @param transformer
17.5 * The ClassFileTransformer which wraps using this prefix.
17.6 * @param prefix
17.7 - * The prefix which has been applied to wrapped native methods.
17.8 + * The prefix to apply to wrapped native methods when
17.9 + * retrying a failed native method resolution. If prefix
17.10 + * is either <code>null</code> or the empty string, then
17.11 + * failed native method resolutions are not retried for
17.12 + * this transformer.
17.13 * @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
17.14 * @throws java.lang.UnsupportedOperationException if the current configuration of
17.15 * the JVM does not allow setting a native method prefix
18.1 --- a/src/share/classes/javax/management/MBeanServer.java Fri Apr 18 12:47:38 2008 -0700
18.2 +++ b/src/share/classes/javax/management/MBeanServer.java Fri Apr 18 16:40:32 2008 -0700
18.3 @@ -50,7 +50,7 @@
18.4 * server. A Java object cannot be registered in the MBean server
18.5 * unless it is a JMX compliant MBean.</p>
18.6 *
18.7 - * <p>When an MBean is registered or unregistered in the MBean server
18.8 + * <p id="notif">When an MBean is registered or unregistered in the MBean server
18.9 * a {@link javax.management.MBeanServerNotification
18.10 * MBeanServerNotification} Notification is emitted. To register an
18.11 * object as listener to MBeanServerNotifications you should call the
18.12 @@ -258,27 +258,43 @@
18.13 */
18.14 public interface MBeanServer extends MBeanServerConnection {
18.15
18.16 - // doc comment inherited from MBeanServerConnection
18.17 + /**
18.18 + * {@inheritDoc}
18.19 + * <p>If this method successfully creates an MBean, a notification
18.20 + * is sent as described <a href="#notif">above</a>.</p>
18.21 + */
18.22 public ObjectInstance createMBean(String className, ObjectName name)
18.23 throws ReflectionException, InstanceAlreadyExistsException,
18.24 MBeanRegistrationException, MBeanException,
18.25 NotCompliantMBeanException;
18.26
18.27 - // doc comment inherited from MBeanServerConnection
18.28 + /**
18.29 + * {@inheritDoc}
18.30 + * <p>If this method successfully creates an MBean, a notification
18.31 + * is sent as described <a href="#notif">above</a>.</p>
18.32 + */
18.33 public ObjectInstance createMBean(String className, ObjectName name,
18.34 ObjectName loaderName)
18.35 throws ReflectionException, InstanceAlreadyExistsException,
18.36 MBeanRegistrationException, MBeanException,
18.37 NotCompliantMBeanException, InstanceNotFoundException;
18.38
18.39 - // doc comment inherited from MBeanServerConnection
18.40 + /**
18.41 + * {@inheritDoc}
18.42 + * <p>If this method successfully creates an MBean, a notification
18.43 + * is sent as described <a href="#notif">above</a>.</p>
18.44 + */
18.45 public ObjectInstance createMBean(String className, ObjectName name,
18.46 Object params[], String signature[])
18.47 throws ReflectionException, InstanceAlreadyExistsException,
18.48 MBeanRegistrationException, MBeanException,
18.49 NotCompliantMBeanException;
18.50
18.51 - // doc comment inherited from MBeanServerConnection
18.52 + /**
18.53 + * {@inheritDoc}
18.54 + * <p>If this method successfully creates an MBean, a notification
18.55 + * is sent as described <a href="#notif">above</a>.</p>
18.56 + */
18.57 public ObjectInstance createMBean(String className, ObjectName name,
18.58 ObjectName loaderName, Object params[],
18.59 String signature[])
18.60 @@ -287,12 +303,15 @@
18.61 NotCompliantMBeanException, InstanceNotFoundException;
18.62
18.63 /**
18.64 - * Registers a pre-existing object as an MBean with the MBean
18.65 + * <p>Registers a pre-existing object as an MBean with the MBean
18.66 * server. If the object name given is null, the MBean must
18.67 * provide its own name by implementing the {@link
18.68 * javax.management.MBeanRegistration MBeanRegistration} interface
18.69 * and returning the name from the {@link
18.70 - * MBeanRegistration#preRegister preRegister} method.
18.71 + * MBeanRegistration#preRegister preRegister} method.</p>
18.72 + *
18.73 + * <p>If this method successfully registers an MBean, a notification
18.74 + * is sent as described <a href="#notif">above</a>.</p>
18.75 *
18.76 * @param object The MBean to be registered as an MBean.
18.77 * @param name The object name of the MBean. May be null.
18.78 @@ -319,7 +338,12 @@
18.79 throws InstanceAlreadyExistsException, MBeanRegistrationException,
18.80 NotCompliantMBeanException;
18.81
18.82 - // doc comment inherited from MBeanServerConnection
18.83 + /**
18.84 + * {@inheritDoc}
18.85 + *
18.86 + * <p>If this method successfully unregisters an MBean, a notification
18.87 + * is sent as described <a href="#notif">above</a>.</p>
18.88 + */
18.89 public void unregisterMBean(ObjectName name)
18.90 throws InstanceNotFoundException, MBeanRegistrationException;
18.91
19.1 --- a/src/share/classes/javax/management/ObjectName.java Fri Apr 18 12:47:38 2008 -0700
19.2 +++ b/src/share/classes/javax/management/ObjectName.java Fri Apr 18 16:40:32 2008 -0700
19.3 @@ -26,6 +26,7 @@
19.4 package javax.management;
19.5
19.6 import com.sun.jmx.mbeanserver.GetPropertyAction;
19.7 +import com.sun.jmx.mbeanserver.Util;
19.8 import java.io.IOException;
19.9 import java.io.InvalidObjectException;
19.10 import java.io.ObjectInputStream;
19.11 @@ -1386,12 +1387,7 @@
19.12 throws NullPointerException {
19.13 if (name.getClass().equals(ObjectName.class))
19.14 return name;
19.15 - try {
19.16 - return new ObjectName(name.getSerializedNameString());
19.17 - } catch (MalformedObjectNameException e) {
19.18 - throw new IllegalArgumentException("Unexpected: " + e);
19.19 - // can't happen
19.20 - }
19.21 + return Util.newObjectName(name.getSerializedNameString());
19.22 }
19.23
19.24 /**
19.25 @@ -1950,14 +1946,7 @@
19.26 *
19.27 * @since 1.6
19.28 */
19.29 - public static final ObjectName WILDCARD;
19.30 - static {
19.31 - try {
19.32 - WILDCARD = new ObjectName("*:*");
19.33 - } catch (MalformedObjectNameException e) {
19.34 - throw new Error("Can't initialize wildcard name", e);
19.35 - }
19.36 - }
19.37 + public static final ObjectName WILDCARD = Util.newObjectName("*:*");
19.38
19.39 // Category : Utilities <===================================
19.40
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/src/share/classes/javax/management/QueryNotificationFilter.java Fri Apr 18 16:40:32 2008 -0700
20.3 @@ -0,0 +1,417 @@
20.4 +/*
20.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 + *
20.8 + * This code is free software; you can redistribute it and/or modify it
20.9 + * under the terms of the GNU General Public License version 2 only, as
20.10 + * published by the Free Software Foundation. Sun designates this
20.11 + * particular file as subject to the "Classpath" exception as provided
20.12 + * by Sun in the LICENSE file that accompanied this code.
20.13 + *
20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 + * version 2 for more details (a copy is included in the LICENSE file that
20.18 + * accompanied this code).
20.19 + *
20.20 + * You should have received a copy of the GNU General Public License version
20.21 + * 2 along with this work; if not, write to the Free Software Foundation,
20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 + *
20.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
20.26 + * have any questions.
20.27 + */
20.28 +
20.29 +package javax.management;
20.30 +
20.31 +import com.sun.jmx.mbeanserver.NotificationMBeanSupport;
20.32 +import com.sun.jmx.mbeanserver.Util;
20.33 +import java.lang.reflect.InvocationHandler;
20.34 +import java.lang.reflect.InvocationTargetException;
20.35 +import java.lang.reflect.Method;
20.36 +import java.lang.reflect.Proxy;
20.37 +import java.util.Collections;
20.38 +import java.util.Set;
20.39 +
20.40 +/**
20.41 + * <p>General-purpose notification filter. This filter can be used to
20.42 + * filter notifications from a possibly-remote MBean. Most filtering
20.43 + * decisions can be coded using this filter, which avoids having to
20.44 + * write a custom implementation of the {@link NotificationFilter}
20.45 + * class. Writing a custom implementation requires you to deploy it
20.46 + * on both the client and the server in the remote case, so using this class
20.47 + * instead is recommended where possible.</p>
20.48 + *
20.49 + * <!-- <p>Because this class was introduced in version 2.0 of the JMX API,
20.50 + * it may not be present on a remote JMX agent that is running an earlier
20.51 + * version. The method {@link JMX#addListenerWithFilter JMX.addListenerWithFilter}
20.52 + * can be used when you cannot be sure whether this class is present in the
20.53 + * agent you are connecting to.</p> -->
20.54 + *
20.55 + * <p>This class uses the {@linkplain Query Query API} to specify the
20.56 + * filtering logic. For example, to select only notifications where the
20.57 + * {@linkplain Notification#getType() type} is {@code "com.example.mytype"},
20.58 + * you could use</p>
20.59 + *
20.60 + * <pre>
20.61 + * NotificationFilter filter =
20.62 + * new QueryNotificationFilter("Type = 'com.example.mytype'");
20.63 + * </pre>
20.64 + *
20.65 + * <p>or equivalently</p>
20.66 + *
20.67 + * <pre>
20.68 + * NotificationFilter filter =
20.69 + * new QueryNotificationFilter(
20.70 + * Query.eq(Query.attr("Type"), Query.value("com.example.mytype")));
20.71 + * </pre>
20.72 + *
20.73 + * <p>(This particular example could also use
20.74 + * {@link NotificationFilterSupport}.)</p>
20.75 + *
20.76 + * <p>Here are some other examples of filters you can specify with this class.</p>
20.77 + *
20.78 + * <dl>
20.79 + *
20.80 + * <dt>{@code QueryNotificationFilter("Type = 'com.example.type1' or
20.81 + * Type = 'com.example.type2'")}
20.82 + * <dd>Notifications where the type is either of the given strings.
20.83 + *
20.84 + * <dt>{@code QueryNotificationFilter("Type in ('com.example.type1',
20.85 + * 'com.example.type2')")}
20.86 + * <dd>Another way to write the previous example.
20.87 + *
20.88 + * <dt>{@code QueryNotificationFilter("SequenceNumber > 1000")}
20.89 + * <dd>Notifications where the {@linkplain Notification#getSequenceNumber()
20.90 + * sequence number} is greater than 1000.
20.91 + *
20.92 + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class, null)}
20.93 + * <dd>Notifications where the notification class is
20.94 + * {@link AttributeChangeNotification} or a subclass of it.
20.95 + *
20.96 + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class,
20.97 + * "AttributeName = 'Size'")}
20.98 + * <dd>Notifications where the notification class is
20.99 + * {@link AttributeChangeNotification} or a subclass, and where the
20.100 + * {@linkplain AttributeChangeNotification#getAttributeName() name of the
20.101 + * changed attribute} is {@code Size}.
20.102 + *
20.103 + * <dt>{@code QueryNotificationFilter(AttributeChangeNotification.class,
20.104 + * "AttributeName = 'Size' and NewValue - OldValue > 100")}
20.105 + * <dd>As above, but the difference between the
20.106 + * {@linkplain AttributeChangeNotification#getNewValue() new value} and the
20.107 + * {@linkplain AttributeChangeNotification#getOldValue() old value} must be
20.108 + * greater than 100.
20.109 + *
20.110 + * <dt>{@code QueryNotificationFilter("like 'com.example.mydomain:*'")}
20.111 + * <dd>Notifications where the {@linkplain Notification#getSource() source}
20.112 + * is an ObjectName that matches the pattern.
20.113 + *
20.114 + * <dt>{@code QueryNotificationFilter("Source.canonicalName like
20.115 + * 'com.example.mydomain:%'")}
20.116 + * <dd>Another way to write the previous example.
20.117 + *
20.118 + * <dt>{@code QueryNotificationFilter(MBeanServerNotification.class,
20.119 + * "Type = 'JMX.mbean.registered' and MBeanName.canonicalName like
20.120 + * 'com.example.mydomain:%'")}
20.121 + * <dd>Notifications of class {@link MBeanServerNotification} representing
20.122 + * an object registered in the domain {@code com.example.mydomain}.
20.123 + *
20.124 + * </dl>
20.125 + *
20.126 + * <h4>How it works</h4>
20.127 + *
20.128 + * <p>Although the examples above are clear, looking closely at the
20.129 + * Query API reveals a subtlety. A {@link QueryExp} is evaluated on
20.130 + * an {@link ObjectName}, not a {@code Notification}.</p>
20.131 + *
20.132 + * <p>Every time a {@code Notification} is to be filtered by a
20.133 + * {@code QueryNotificationFilter}, a special {@link MBeanServer} is created.
20.134 + * This {@code MBeanServer} contains exactly one MBean, which represents the
20.135 + * {@code Notification}. If the {@linkplain Notification#getSource()
20.136 + * source} of the notification is an {@code ObjectName}, which is
20.137 + * recommended practice, then the name of the MBean representing the
20.138 + * {@code Notification} will be this {@code ObjectName}. Otherwise the
20.139 + * name is unspecified.</p>
20.140 + *
20.141 + * <p>The query specified in the {@code QueryNotificationFilter} constructor
20.142 + * is evaluated against this {@code MBeanServer} and {@code ObjectName},
20.143 + * and the filter returns true if and only if the query does. If the
20.144 + * query throws an exception, then the filter will return false.</p>
20.145 + *
20.146 + * <p>The MBean representing the {@code Notification} has one attribute for
20.147 + * every property of the {@code Notification}. Specifically, for every public
20.148 + * method {@code T getX()} in the {@code NotificationClass}, the MBean will
20.149 + * have an attribute called {@code X} of type {@code T}. For example, if the
20.150 + * {@code Notification} is an {@code AttributeChangeNotification}, then the
20.151 + * MBean will have an attribute called {@code AttributeName} of type
20.152 + * {@code "java.lang.String"}, corresponding to the method {@link
20.153 + * AttributeChangeNotification#getAttributeName}.</p>
20.154 + *
20.155 + * <p>Query evaluation usually involves calls to the methods of {@code
20.156 + * MBeanServer}. The methods have the following behavior:</p>
20.157 + *
20.158 + * <ul>
20.159 + * <li>The {@link MBeanServer#getAttribute getAttribute} method returns the
20.160 + * value of the corresponding property.
20.161 + * <li>The {@link MBeanServer#getObjectInstance getObjectInstance}
20.162 + * method returns an {@link ObjectInstance} where the {@link
20.163 + * ObjectInstance#getObjectName ObjectName} is the name of the MBean and the
20.164 + * {@link ObjectInstance#getClassName ClassName} is the class name of the
20.165 + * {@code Notification}.
20.166 + * <li>The {@link MBeanServer#isInstanceOf isInstanceOf} method returns true
20.167 + * if and only if the {@code Notification}'s {@code ClassLoader} can load the
20.168 + * named class, and the {@code Notification} is an {@linkplain Class#isInstance
20.169 + * instance} of that class.
20.170 + * </ul>
20.171 + *
20.172 + * <p>These are the only {@code MBeanServer} methods that are needed to
20.173 + * evaluate standard queries. The behavior of the other {@code MBeanServer}
20.174 + * methods is unspecified.</p>
20.175 + *
20.176 + * @since 1.7
20.177 + */
20.178 +public class QueryNotificationFilter implements NotificationFilter {
20.179 + private static final long serialVersionUID = -8408613922660635231L;
20.180 +
20.181 + private static final ObjectName DEFAULT_NAME =
20.182 + Util.newObjectName(":type=Notification");
20.183 + private static final QueryExp trueQuery;
20.184 + static {
20.185 + ValueExp zero = Query.value(0);
20.186 + trueQuery = Query.eq(zero, zero);
20.187 + }
20.188 +
20.189 + private final QueryExp query;
20.190 +
20.191 + /**
20.192 + * Construct a {@code QueryNotificationFilter} that evaluates the given
20.193 + * {@code QueryExp} to determine whether to accept a notification.
20.194 + *
20.195 + * @param query the {@code QueryExp} to evaluate. Can be null,
20.196 + * in which case all notifications are accepted.
20.197 + */
20.198 + public QueryNotificationFilter(QueryExp query) {
20.199 + if (query == null)
20.200 + this.query = trueQuery;
20.201 + else
20.202 + this.query = query;
20.203 + }
20.204 +
20.205 + /**
20.206 + * Construct a {@code QueryNotificationFilter} that evaluates the query
20.207 + * in the given string to determine whether to accept a notification.
20.208 + * The string is converted into a {@code QueryExp} using
20.209 + * {@link Query#fromString Query.fromString}.
20.210 + *
20.211 + * @param query the string specifying the query to evaluate. Can be null,
20.212 + * in which case all notifications are accepted.
20.213 + *
20.214 + * @throws IllegalArgumentException if the string is not a valid
20.215 + * query string.
20.216 + */
20.217 + public QueryNotificationFilter(String query) {
20.218 + this(Query.fromString(query));
20.219 + }
20.220 +
20.221 + /**
20.222 + * <p>Construct a {@code QueryNotificationFilter} that evaluates the query
20.223 + * in the given string to determine whether to accept a notification,
20.224 + * and where the notification must also be an instance of the given class.
20.225 + * The string is converted into a {@code QueryExp} using
20.226 + * {@link Query#fromString Query.fromString}.</p>
20.227 + *
20.228 + * @param notifClass the class that the notification must be an instance of.
20.229 + * Cannot be null.
20.230 + *
20.231 + * @param query the string specifying the query to evaluate. Can be null,
20.232 + * in which case all notifications are accepted.
20.233 + *
20.234 + * @throws IllegalArgumentException if the string is not a valid
20.235 + * query string, or if {@code notifClass} is null.
20.236 + */
20.237 + public QueryNotificationFilter(
20.238 + Class<? extends Notification> notifClass, String query) {
20.239 + this(Query.and(Query.isInstanceOf(Query.value(notNull(notifClass).getName())),
20.240 + Query.fromString(query)));
20.241 + }
20.242 +
20.243 + private static <T> T notNull(T x) {
20.244 + if (x == null)
20.245 + throw new IllegalArgumentException("Null argument");
20.246 + return x;
20.247 + }
20.248 +
20.249 + /**
20.250 + * Retrieve the query that this notification filter will evaluate for
20.251 + * each notification.
20.252 + *
20.253 + * @return the query.
20.254 + */
20.255 + public QueryExp getQuery() {
20.256 + return query;
20.257 + }
20.258 +
20.259 + public boolean isNotificationEnabled(Notification notification) {
20.260 + ObjectName name;
20.261 +
20.262 + Object source = notification.getSource();
20.263 + if (source instanceof ObjectName)
20.264 + name = (ObjectName) source;
20.265 + else
20.266 + name = DEFAULT_NAME;
20.267 +
20.268 + MBS mbsImpl = new MBS(notification, name);
20.269 + MBeanServer mbs = (MBeanServer) Proxy.newProxyInstance(
20.270 + MBeanServer.class.getClassLoader(),
20.271 + new Class<?>[] {MBeanServer.class},
20.272 + new ForwardIH(mbsImpl));
20.273 + return evalQuery(query, mbs, name);
20.274 + }
20.275 +
20.276 + private static boolean evalQuery(
20.277 + QueryExp query, MBeanServer mbs, ObjectName name) {
20.278 + MBeanServer oldMBS = QueryEval.getMBeanServer();
20.279 + try {
20.280 + if (mbs != null)
20.281 + query.setMBeanServer(mbs);
20.282 + return query.apply(name);
20.283 + } catch (Exception e) {
20.284 + return false;
20.285 + } finally {
20.286 + query.setMBeanServer(oldMBS);
20.287 + }
20.288 + }
20.289 +
20.290 + private static class ForwardIH implements InvocationHandler {
20.291 + private final MBS mbs;
20.292 +
20.293 + ForwardIH(MBS mbs) {
20.294 + this.mbs = mbs;
20.295 + }
20.296 +
20.297 + public Object invoke(Object proxy, Method method, Object[] args)
20.298 + throws Throwable {
20.299 + Method forward;
20.300 + try {
20.301 + forward = MBS.class.getMethod(
20.302 + method.getName(), method.getParameterTypes());
20.303 + } catch (NoSuchMethodException e) {
20.304 + throw new UnsupportedOperationException(method.getName());
20.305 + }
20.306 + try {
20.307 + return forward.invoke(mbs, args);
20.308 + } catch (InvocationTargetException e) {
20.309 + throw e.getCause();
20.310 + }
20.311 + }
20.312 + }
20.313 +
20.314 + private static class MBS {
20.315 + private final Notification notification;
20.316 + private final ObjectName objectName;
20.317 + private final ObjectInstance objectInstance;
20.318 + private volatile DynamicMBean mbean;
20.319 +
20.320 + MBS(Notification n, ObjectName name) {
20.321 + this.notification = n;
20.322 + this.objectName = name;
20.323 + this.objectInstance = new ObjectInstance(name, n.getClass().getName());
20.324 + }
20.325 +
20.326 + private void checkName(ObjectName name) throws InstanceNotFoundException {
20.327 + if (!objectName.equals(name))
20.328 + throw new InstanceNotFoundException(String.valueOf(name));
20.329 + }
20.330 +
20.331 + private DynamicMBean mbean(ObjectName name)
20.332 + throws InstanceNotFoundException, ReflectionException {
20.333 + if (mbean == null) {
20.334 + try {
20.335 + mbean = new NotificationMBeanSupport(notification);
20.336 + } catch (NotCompliantMBeanException e) {
20.337 + throw new ReflectionException(e);
20.338 + }
20.339 + }
20.340 + return mbean;
20.341 + }
20.342 +
20.343 + public ObjectInstance getObjectInstance(ObjectName name)
20.344 + throws InstanceNotFoundException {
20.345 + checkName(name);
20.346 + return objectInstance;
20.347 + }
20.348 +
20.349 + public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
20.350 + Set<ObjectName> names = queryNames(name, query);
20.351 + switch (names.size()) {
20.352 + case 0:
20.353 + return Collections.emptySet();
20.354 + case 1:
20.355 + return Collections.singleton(objectInstance);
20.356 + default:
20.357 + throw new UnsupportedOperationException("Internal error");
20.358 + }
20.359 + }
20.360 +
20.361 + public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
20.362 + if ((name != null && !name.apply(objectName)) ||
20.363 + (query != null && !evalQuery(query, null, name)))
20.364 + return Collections.emptySet();
20.365 + return Collections.singleton(objectName);
20.366 + }
20.367 +
20.368 + public boolean isRegistered(ObjectName name) {
20.369 + return objectName.equals(name);
20.370 + }
20.371 +
20.372 + public Integer getMBeanCount() {
20.373 + return 1;
20.374 + }
20.375 +
20.376 + public Object getAttribute(ObjectName name, String attribute)
20.377 + throws MBeanException, AttributeNotFoundException,
20.378 + InstanceNotFoundException, ReflectionException {
20.379 + return mbean(name).getAttribute(attribute);
20.380 + }
20.381 +
20.382 + public AttributeList getAttributes(ObjectName name, String[] attributes)
20.383 + throws InstanceNotFoundException, ReflectionException {
20.384 + return mbean(name).getAttributes(attributes);
20.385 + }
20.386 +
20.387 + public String getDefaultDomain() {
20.388 + return objectName.getDomain();
20.389 + }
20.390 +
20.391 + public String[] getDomains() {
20.392 + return new String[] {objectName.getDomain()};
20.393 + }
20.394 +
20.395 + public MBeanInfo getMBeanInfo(ObjectName name)
20.396 + throws InstanceNotFoundException, ReflectionException {
20.397 + return mbean(name).getMBeanInfo();
20.398 + }
20.399 +
20.400 + public boolean isInstanceOf(ObjectName name, String className)
20.401 + throws InstanceNotFoundException {
20.402 + try {
20.403 + mbean(name);
20.404 + ClassLoader loader = notification.getClass().getClassLoader();
20.405 + Class<?> c = Class.forName(className, false, loader);
20.406 + return c.isInstance(notification);
20.407 + } catch (ReflectionException e) {
20.408 + return false;
20.409 + } catch (ClassNotFoundException e) {
20.410 + return false;
20.411 + }
20.412 + }
20.413 +
20.414 + public ClassLoader getClassLoaderFor(ObjectName mbeanName)
20.415 + throws InstanceNotFoundException {
20.416 + checkName(mbeanName);
20.417 + return notification.getClass().getClassLoader();
20.418 + }
20.419 + }
20.420 +}
21.1 --- a/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Fri Apr 18 12:47:38 2008 -0700
21.2 +++ b/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Fri Apr 18 16:40:32 2008 -0700
21.3 @@ -48,6 +48,7 @@
21.4 import java.util.Map;
21.5 import java.util.Set;
21.6
21.7 +import java.util.Vector;
21.8 import javax.management.Attribute;
21.9 import javax.management.AttributeChangeNotification;
21.10 import javax.management.AttributeChangeNotificationFilter;
21.11 @@ -132,8 +133,6 @@
21.12 * and operations will be executed */
21.13 private Object managedResource = null;
21.14
21.15 - private static final String currClass = "RequiredModelMBean";
21.16 -
21.17 /* records the registering in MBeanServer */
21.18 private boolean registered = false;
21.19 private transient MBeanServer server = null;
21.20 @@ -2488,10 +2487,13 @@
21.21 }
21.22
21.23 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
21.24 + Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
21.25 + String s = (enabledAttrs.size() > 1) ?
21.26 + "[" + enabledAttrs.firstElement() + ", ...]" :
21.27 + enabledAttrs.toString();
21.28 MODELMBEAN_LOGGER.logp(Level.FINER,
21.29 RequiredModelMBean.class.getName(), mth,
21.30 - "Set attribute change filter to " +
21.31 - currFilter.getEnabledAttributes().firstElement());
21.32 + "Set attribute change filter to " + s);
21.33 }
21.34
21.35 attributeBroadcaster.addNotificationListener(inlistener,currFilter,
22.1 --- a/src/share/classes/sun/instrument/InstrumentationImpl.java Fri Apr 18 12:47:38 2008 -0700
22.2 +++ b/src/share/classes/sun/instrument/InstrumentationImpl.java Fri Apr 18 16:40:32 2008 -0700
22.3 @@ -303,39 +303,78 @@
22.4 NoSuchMethodException firstExc = null;
22.5 boolean twoArgAgent = false;
22.6
22.7 - // The agent class has a premain or agentmain method that has 1 or 2
22.8 - // arguments. We first check for a signature of (String, Instrumentation),
22.9 - // and if not found we check for (String). If neither is found then we
22.10 - // throw the NoSuchMethodException from the first attempt so that the
22.11 - // exception text indicates the lookup failed for the 2-arg method
22.12 - // (same as JDK5.0).
22.13 + // The agent class must have a premain or agentmain method that
22.14 + // has 1 or 2 arguments. We check in the following order:
22.15 + //
22.16 + // 1) declared with a signature of (String, Instrumentation)
22.17 + // 2) declared with a signature of (String)
22.18 + // 3) inherited with a signature of (String, Instrumentation)
22.19 + // 4) inherited with a signature of (String)
22.20 + //
22.21 + // So the declared version of either 1-arg or 2-arg always takes
22.22 + // primary precedence over an inherited version. After that, the
22.23 + // 2-arg version takes precedence over the 1-arg version.
22.24 + //
22.25 + // If no method is found then we throw the NoSuchMethodException
22.26 + // from the first attempt so that the exception text indicates
22.27 + // the lookup failed for the 2-arg method (same as JDK5.0).
22.28
22.29 try {
22.30 - m = javaAgentClass.getMethod( methodname,
22.31 - new Class[] {
22.32 - String.class,
22.33 - java.lang.instrument.Instrumentation.class
22.34 - }
22.35 - );
22.36 + m = javaAgentClass.getDeclaredMethod( methodname,
22.37 + new Class[] {
22.38 + String.class,
22.39 + java.lang.instrument.Instrumentation.class
22.40 + }
22.41 + );
22.42 twoArgAgent = true;
22.43 } catch (NoSuchMethodException x) {
22.44 // remember the NoSuchMethodException
22.45 firstExc = x;
22.46 }
22.47
22.48 - // check for the 1-arg method
22.49 if (m == null) {
22.50 + // now try the declared 1-arg method
22.51 try {
22.52 - m = javaAgentClass.getMethod(methodname, new Class[] { String.class });
22.53 + m = javaAgentClass.getDeclaredMethod(methodname,
22.54 + new Class[] { String.class });
22.55 } catch (NoSuchMethodException x) {
22.56 - // Neither method exists so we throw the first NoSuchMethodException
22.57 - // as per 5.0
22.58 + // ignore this exception because we'll try
22.59 + // two arg inheritance next
22.60 + }
22.61 + }
22.62 +
22.63 + if (m == null) {
22.64 + // now try the inherited 2-arg method
22.65 + try {
22.66 + m = javaAgentClass.getMethod( methodname,
22.67 + new Class[] {
22.68 + String.class,
22.69 + java.lang.instrument.Instrumentation.class
22.70 + }
22.71 + );
22.72 + twoArgAgent = true;
22.73 + } catch (NoSuchMethodException x) {
22.74 + // ignore this exception because we'll try
22.75 + // one arg inheritance next
22.76 + }
22.77 + }
22.78 +
22.79 + if (m == null) {
22.80 + // finally try the inherited 1-arg method
22.81 + try {
22.82 + m = javaAgentClass.getMethod(methodname,
22.83 + new Class[] { String.class });
22.84 + } catch (NoSuchMethodException x) {
22.85 + // none of the methods exists so we throw the
22.86 + // first NoSuchMethodException as per 5.0
22.87 throw firstExc;
22.88 }
22.89 }
22.90
22.91 // the premain method should not be required to be public,
22.92 // make it accessible so we can call it
22.93 + // Note: The spec says the following:
22.94 + // The agent class must implement a public static premain method...
22.95 setAccessible(m, true);
22.96
22.97 // invoke the 1 or 2-arg method
23.1 --- a/src/share/classes/sun/management/Flag.java Fri Apr 18 12:47:38 2008 -0700
23.2 +++ b/src/share/classes/sun/management/Flag.java Fri Apr 18 16:40:32 2008 -0700
23.3 @@ -64,7 +64,8 @@
23.4 }
23.5
23.6 VMOption getVMOption() {
23.7 - return new VMOption(name, value.toString(), writeable, origin);
23.8 + String val = value == null ? "" : value.toString();
23.9 + return new VMOption(name, val, writeable, origin);
23.10 }
23.11
23.12 static Flag getFlag(String name) {
24.1 --- a/src/share/classes/sun/net/www/protocol/http/NegotiatorImpl.java Fri Apr 18 12:47:38 2008 -0700
24.2 +++ b/src/share/classes/sun/net/www/protocol/http/NegotiatorImpl.java Fri Apr 18 16:40:32 2008 -0700
24.3 @@ -91,9 +91,10 @@
24.4 GSSManagerImpl manager = new GSSManagerImpl(
24.5 GSSUtil.CALLER_HTTP_NEGOTIATE);
24.6
24.7 - String peerName = "HTTP/" + hostname;
24.8 + String peerName = "HTTP@" + hostname;
24.9
24.10 - GSSName serverName = manager.createName(peerName, null);
24.11 + GSSName serverName = manager.createName(peerName,
24.12 + GSSName.NT_HOSTBASED_SERVICE);
24.13 context = manager.createContext(serverName,
24.14 oid,
24.15 null,
25.1 --- a/src/share/classes/sun/security/pkcs11/P11Cipher.java Fri Apr 18 12:47:38 2008 -0700
25.2 +++ b/src/share/classes/sun/security/pkcs11/P11Cipher.java Fri Apr 18 16:40:32 2008 -0700
25.3 @@ -1,5 +1,5 @@
25.4 /*
25.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
25.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
25.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25.8 *
25.9 * This code is free software; you can redistribute it and/or modify it
25.10 @@ -22,10 +22,10 @@
25.11 * CA 95054 USA or visit www.sun.com if you need additional information or
25.12 * have any questions.
25.13 */
25.14 -
25.15 package sun.security.pkcs11;
25.16
25.17 import java.nio.ByteBuffer;
25.18 +import java.util.Arrays;
25.19
25.20 import java.security.*;
25.21 import java.security.spec.*;
25.22 @@ -34,7 +34,6 @@
25.23 import javax.crypto.spec.*;
25.24
25.25 import sun.nio.ch.DirectBuffer;
25.26 -
25.27 import sun.security.pkcs11.wrapper.*;
25.28 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
25.29
25.30 @@ -43,8 +42,8 @@
25.31 * DES, DESede, AES, ARCFOUR, and Blowfish.
25.32 *
25.33 * This class is designed to support ECB and CBC with NoPadding and
25.34 - * PKCS5Padding for both. However, currently only CBC/NoPadding (and
25.35 - * ECB/NoPadding for stream ciphers) is functional.
25.36 + * PKCS5Padding for both. It will use its own padding impl if the
25.37 + * native mechanism does not support padding.
25.38 *
25.39 * Note that PKCS#11 current only supports ECB and CBC. There are no
25.40 * provisions for other modes such as CFB, OFB, PCBC, or CTR mode.
25.41 @@ -62,10 +61,59 @@
25.42 private final static int MODE_CBC = 4;
25.43
25.44 // padding constant for NoPadding
25.45 - private final static int PAD_NONE = 5;
25.46 + private final static int PAD_NONE = 5;
25.47 // padding constant for PKCS5Padding
25.48 private final static int PAD_PKCS5 = 6;
25.49
25.50 + private static interface Padding {
25.51 + // ENC: format the specified buffer with padding bytes and return the
25.52 + // actual padding length
25.53 + int setPaddingBytes(byte[] paddingBuffer, int padLen);
25.54 +
25.55 + // DEC: return the length of trailing padding bytes given the specified
25.56 + // padded data
25.57 + int unpad(byte[] paddedData, int len)
25.58 + throws BadPaddingException;
25.59 + }
25.60 +
25.61 + private static class PKCS5Padding implements Padding {
25.62 +
25.63 + private final int blockSize;
25.64 +
25.65 + PKCS5Padding(int blockSize)
25.66 + throws NoSuchPaddingException {
25.67 + if (blockSize == 0) {
25.68 + throw new NoSuchPaddingException
25.69 + ("PKCS#5 padding not supported with stream ciphers");
25.70 + }
25.71 + this.blockSize = blockSize;
25.72 + }
25.73 +
25.74 + public int setPaddingBytes(byte[] paddingBuffer, int padLen) {
25.75 + Arrays.fill(paddingBuffer, 0, padLen, (byte) (padLen & 0x007f));
25.76 + return padLen;
25.77 + }
25.78 +
25.79 + public int unpad(byte[] paddedData, int len)
25.80 + throws BadPaddingException {
25.81 + if (len < 1 || len > paddedData.length) {
25.82 + throw new BadPaddingException("Invalid pad array length!");
25.83 + }
25.84 + byte padValue = paddedData[len - 1];
25.85 + if (padValue < 1 || padValue > blockSize) {
25.86 + throw new BadPaddingException("Invalid pad value!");
25.87 + }
25.88 + // sanity check padding bytes
25.89 + int padStartIndex = len - padValue;
25.90 + for (int i = padStartIndex; i < len; i++) {
25.91 + if (paddedData[i] != padValue) {
25.92 + throw new BadPaddingException("Invalid pad bytes!");
25.93 + }
25.94 + }
25.95 + return padValue;
25.96 + }
25.97 + }
25.98 +
25.99 // token instance
25.100 private final Token token;
25.101
25.102 @@ -99,65 +147,93 @@
25.103 // padding type, on of PAD_* above (PAD_NONE for stream ciphers)
25.104 private int paddingType;
25.105
25.106 + // when the padding is requested but unsupported by the native mechanism,
25.107 + // we use the following to do padding and necessary data buffering.
25.108 + // padding object which generate padding and unpad the decrypted data
25.109 + private Padding paddingObj;
25.110 + // buffer for holding back the block which contains padding bytes
25.111 + private byte[] padBuffer;
25.112 + private int padBufferLen;
25.113 +
25.114 // original IV, if in MODE_CBC
25.115 private byte[] iv;
25.116
25.117 - // total number of bytes processed
25.118 - private int bytesProcessed;
25.119 + // number of bytes buffered internally by the native mechanism and padBuffer
25.120 + // if we do the padding
25.121 + private int bytesBuffered;
25.122
25.123 P11Cipher(Token token, String algorithm, long mechanism)
25.124 - throws PKCS11Exception {
25.125 + throws PKCS11Exception, NoSuchAlgorithmException {
25.126 super();
25.127 this.token = token;
25.128 this.algorithm = algorithm;
25.129 this.mechanism = mechanism;
25.130 - keyAlgorithm = algorithm.split("/")[0];
25.131 +
25.132 + String algoParts[] = algorithm.split("/");
25.133 + keyAlgorithm = algoParts[0];
25.134 +
25.135 if (keyAlgorithm.equals("AES")) {
25.136 blockSize = 16;
25.137 - blockMode = MODE_CBC;
25.138 - // XXX change default to PKCS5Padding
25.139 - paddingType = PAD_NONE;
25.140 - } else if (keyAlgorithm.equals("RC4") || keyAlgorithm.equals("ARCFOUR")) {
25.141 + } else if (keyAlgorithm.equals("RC4") ||
25.142 + keyAlgorithm.equals("ARCFOUR")) {
25.143 blockSize = 0;
25.144 - blockMode = MODE_ECB;
25.145 - paddingType = PAD_NONE;
25.146 } else { // DES, DESede, Blowfish
25.147 blockSize = 8;
25.148 - blockMode = MODE_CBC;
25.149 - // XXX change default to PKCS5Padding
25.150 - paddingType = PAD_NONE;
25.151 + }
25.152 + this.blockMode =
25.153 + (algoParts.length > 1 ? parseMode(algoParts[1]) : MODE_ECB);
25.154 +
25.155 + String defPadding = (blockSize == 0 ? "NoPadding" : "PKCS5Padding");
25.156 + String paddingStr =
25.157 + (algoParts.length > 2 ? algoParts[2] : defPadding);
25.158 + try {
25.159 + engineSetPadding(paddingStr);
25.160 + } catch (NoSuchPaddingException nspe) {
25.161 + // should not happen
25.162 + throw new ProviderException(nspe);
25.163 }
25.164 session = token.getOpSession();
25.165 }
25.166
25.167 protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
25.168 + // Disallow change of mode for now since currently it's explicitly
25.169 + // defined in transformation strings
25.170 + throw new NoSuchAlgorithmException("Unsupported mode " + mode);
25.171 + }
25.172 +
25.173 + private int parseMode(String mode) throws NoSuchAlgorithmException {
25.174 mode = mode.toUpperCase();
25.175 + int result;
25.176 if (mode.equals("ECB")) {
25.177 - this.blockMode = MODE_ECB;
25.178 + result = MODE_ECB;
25.179 } else if (mode.equals("CBC")) {
25.180 if (blockSize == 0) {
25.181 throw new NoSuchAlgorithmException
25.182 ("CBC mode not supported with stream ciphers");
25.183 }
25.184 - this.blockMode = MODE_CBC;
25.185 + result = MODE_CBC;
25.186 } else {
25.187 throw new NoSuchAlgorithmException("Unsupported mode " + mode);
25.188 }
25.189 + return result;
25.190 }
25.191
25.192 // see JCE spec
25.193 protected void engineSetPadding(String padding)
25.194 throws NoSuchPaddingException {
25.195 - if (padding.equalsIgnoreCase("NoPadding")) {
25.196 + paddingObj = null;
25.197 + padBuffer = null;
25.198 + padding = padding.toUpperCase();
25.199 + if (padding.equals("NOPADDING")) {
25.200 paddingType = PAD_NONE;
25.201 - } else if (padding.equalsIgnoreCase("PKCS5Padding")) {
25.202 - if (blockSize == 0) {
25.203 - throw new NoSuchPaddingException
25.204 - ("PKCS#5 padding not supported with stream ciphers");
25.205 + } else if (padding.equals("PKCS5PADDING")) {
25.206 + paddingType = PAD_PKCS5;
25.207 + if (mechanism != CKM_DES_CBC_PAD && mechanism != CKM_DES3_CBC_PAD &&
25.208 + mechanism != CKM_AES_CBC_PAD) {
25.209 + // no native padding support; use our own padding impl
25.210 + paddingObj = new PKCS5Padding(blockSize);
25.211 + padBuffer = new byte[blockSize];
25.212 }
25.213 - paddingType = PAD_PKCS5;
25.214 - // XXX PKCS#5 not yet implemented
25.215 - throw new NoSuchPaddingException("pkcs5");
25.216 } else {
25.217 throw new NoSuchPaddingException("Unsupported padding " + padding);
25.218 }
25.219 @@ -175,7 +251,7 @@
25.220
25.221 // see JCE spec
25.222 protected byte[] engineGetIV() {
25.223 - return (iv == null) ? null : (byte[])iv.clone();
25.224 + return (iv == null) ? null : (byte[]) iv.clone();
25.225 }
25.226
25.227 // see JCE spec
25.228 @@ -185,8 +261,9 @@
25.229 }
25.230 IvParameterSpec ivSpec = new IvParameterSpec(iv);
25.231 try {
25.232 - AlgorithmParameters params = AlgorithmParameters.getInstance
25.233 - (keyAlgorithm, P11Util.getSunJceProvider());
25.234 + AlgorithmParameters params =
25.235 + AlgorithmParameters.getInstance(keyAlgorithm,
25.236 + P11Util.getSunJceProvider());
25.237 params.init(ivSpec);
25.238 return params;
25.239 } catch (GeneralSecurityException e) {
25.240 @@ -210,38 +287,38 @@
25.241 protected void engineInit(int opmode, Key key,
25.242 AlgorithmParameterSpec params, SecureRandom random)
25.243 throws InvalidKeyException, InvalidAlgorithmParameterException {
25.244 - byte[] iv;
25.245 + byte[] ivValue;
25.246 if (params != null) {
25.247 if (params instanceof IvParameterSpec == false) {
25.248 throw new InvalidAlgorithmParameterException
25.249 ("Only IvParameterSpec supported");
25.250 }
25.251 - IvParameterSpec ivSpec = (IvParameterSpec)params;
25.252 - iv = ivSpec.getIV();
25.253 + IvParameterSpec ivSpec = (IvParameterSpec) params;
25.254 + ivValue = ivSpec.getIV();
25.255 } else {
25.256 - iv = null;
25.257 + ivValue = null;
25.258 }
25.259 - implInit(opmode, key, iv, random);
25.260 + implInit(opmode, key, ivValue, random);
25.261 }
25.262
25.263 // see JCE spec
25.264 protected void engineInit(int opmode, Key key, AlgorithmParameters params,
25.265 SecureRandom random)
25.266 throws InvalidKeyException, InvalidAlgorithmParameterException {
25.267 - byte[] iv;
25.268 + byte[] ivValue;
25.269 if (params != null) {
25.270 try {
25.271 IvParameterSpec ivSpec = (IvParameterSpec)
25.272 params.getParameterSpec(IvParameterSpec.class);
25.273 - iv = ivSpec.getIV();
25.274 + ivValue = ivSpec.getIV();
25.275 } catch (InvalidParameterSpecException e) {
25.276 throw new InvalidAlgorithmParameterException
25.277 ("Could not decode IV", e);
25.278 }
25.279 } else {
25.280 - iv = null;
25.281 + ivValue = null;
25.282 }
25.283 - implInit(opmode, key, iv, random);
25.284 + implInit(opmode, key, ivValue, random);
25.285 }
25.286
25.287 // actual init() implementation
25.288 @@ -250,31 +327,31 @@
25.289 throws InvalidKeyException, InvalidAlgorithmParameterException {
25.290 cancelOperation();
25.291 switch (opmode) {
25.292 - case Cipher.ENCRYPT_MODE:
25.293 - encrypt = true;
25.294 - break;
25.295 - case Cipher.DECRYPT_MODE:
25.296 - encrypt = false;
25.297 - break;
25.298 - default:
25.299 - throw new InvalidAlgorithmParameterException
25.300 - ("Unsupported mode: " + opmode);
25.301 + case Cipher.ENCRYPT_MODE:
25.302 + encrypt = true;
25.303 + break;
25.304 + case Cipher.DECRYPT_MODE:
25.305 + encrypt = false;
25.306 + break;
25.307 + default:
25.308 + throw new InvalidAlgorithmParameterException
25.309 + ("Unsupported mode: " + opmode);
25.310 }
25.311 if (blockMode == MODE_ECB) { // ECB or stream cipher
25.312 if (iv != null) {
25.313 if (blockSize == 0) {
25.314 throw new InvalidAlgorithmParameterException
25.315 - ("IV not used with stream ciphers");
25.316 + ("IV not used with stream ciphers");
25.317 } else {
25.318 throw new InvalidAlgorithmParameterException
25.319 - ("IV not used in ECB mode");
25.320 + ("IV not used in ECB mode");
25.321 }
25.322 }
25.323 } else { // MODE_CBC
25.324 if (iv == null) {
25.325 if (encrypt == false) {
25.326 throw new InvalidAlgorithmParameterException
25.327 - ("IV must be specified for decryption in CBC mode");
25.328 + ("IV must be specified for decryption in CBC mode");
25.329 }
25.330 // generate random IV
25.331 if (random == null) {
25.332 @@ -285,7 +362,7 @@
25.333 } else {
25.334 if (iv.length != blockSize) {
25.335 throw new InvalidAlgorithmParameterException
25.336 - ("IV length must match block size");
25.337 + ("IV length must match block size");
25.338 }
25.339 }
25.340 }
25.341 @@ -331,63 +408,43 @@
25.342 session = token.getOpSession();
25.343 }
25.344 if (encrypt) {
25.345 - token.p11.C_EncryptInit
25.346 - (session.id(), new CK_MECHANISM(mechanism, iv), p11Key.keyID);
25.347 + token.p11.C_EncryptInit(session.id(),
25.348 + new CK_MECHANISM(mechanism, iv), p11Key.keyID);
25.349 } else {
25.350 - token.p11.C_DecryptInit
25.351 - (session.id(), new CK_MECHANISM(mechanism, iv), p11Key.keyID);
25.352 + token.p11.C_DecryptInit(session.id(),
25.353 + new CK_MECHANISM(mechanism, iv), p11Key.keyID);
25.354 }
25.355 - bytesProcessed = 0;
25.356 + bytesBuffered = 0;
25.357 + padBufferLen = 0;
25.358 initialized = true;
25.359 }
25.360
25.361 - // XXX the calculations below assume the PKCS#11 implementation is smart.
25.362 - // conceivably, not all implementations are and we may need to estimate
25.363 - // more conservatively
25.364 -
25.365 - private int bytesBuffered(int totalLen) {
25.366 - if (paddingType == PAD_NONE) {
25.367 - // with NoPadding, buffer only the current unfinished block
25.368 - return totalLen & (blockSize - 1);
25.369 - } else { // PKCS5
25.370 - // with PKCS5Padding in decrypt mode, the buffer must never
25.371 - // be empty. Buffer a full block instead of nothing.
25.372 - int buffered = totalLen & (blockSize - 1);
25.373 - if ((buffered == 0) && (encrypt == false)) {
25.374 - buffered = blockSize;
25.375 - }
25.376 - return buffered;
25.377 - }
25.378 - }
25.379 -
25.380 // if update(inLen) is called, how big does the output buffer have to be?
25.381 private int updateLength(int inLen) {
25.382 if (inLen <= 0) {
25.383 return 0;
25.384 }
25.385 - if (blockSize == 0) {
25.386 - return inLen;
25.387 - } else {
25.388 - // bytes that need to be buffered now
25.389 - int buffered = bytesBuffered(bytesProcessed);
25.390 - // bytes that need to be buffered after this update
25.391 - int newBuffered = bytesBuffered(bytesProcessed + inLen);
25.392 - return inLen + buffered - newBuffered;
25.393 +
25.394 + int result = inLen + bytesBuffered;
25.395 + if (blockSize != 0) {
25.396 + // minus the number of bytes in the last incomplete block.
25.397 + result -= (result & (blockSize - 1));
25.398 }
25.399 + return result;
25.400 }
25.401
25.402 // if doFinal(inLen) is called, how big does the output buffer have to be?
25.403 private int doFinalLength(int inLen) {
25.404 - if (paddingType == PAD_NONE) {
25.405 - return updateLength(inLen);
25.406 - }
25.407 if (inLen < 0) {
25.408 return 0;
25.409 }
25.410 - int buffered = bytesBuffered(bytesProcessed);
25.411 - int newProcessed = bytesProcessed + inLen;
25.412 - int paddedProcessed = (newProcessed + blockSize) & ~(blockSize - 1);
25.413 - return paddedProcessed - bytesProcessed + buffered;
25.414 +
25.415 + int result = inLen + bytesBuffered;
25.416 + if (blockSize != 0 && encrypt && paddingType != PAD_NONE) {
25.417 + // add the number of bytes to make the last block complete.
25.418 + result += (blockSize - (result & (blockSize - 1)));
25.419 + }
25.420 + return result;
25.421 }
25.422
25.423 // see JCE spec
25.424 @@ -397,6 +454,7 @@
25.425 int n = engineUpdate(in, inOfs, inLen, out, 0);
25.426 return P11Util.convert(out, 0, n);
25.427 } catch (ShortBufferException e) {
25.428 + // convert since the output length is calculated by updateLength()
25.429 throw new ProviderException(e);
25.430 }
25.431 }
25.432 @@ -409,6 +467,7 @@
25.433 }
25.434
25.435 // see JCE spec
25.436 + @Override
25.437 protected int engineUpdate(ByteBuffer inBuffer, ByteBuffer outBuffer)
25.438 throws ShortBufferException {
25.439 return implUpdate(inBuffer, outBuffer);
25.440 @@ -422,14 +481,15 @@
25.441 int n = engineDoFinal(in, inOfs, inLen, out, 0);
25.442 return P11Util.convert(out, 0, n);
25.443 } catch (ShortBufferException e) {
25.444 + // convert since the output length is calculated by doFinalLength()
25.445 throw new ProviderException(e);
25.446 }
25.447 }
25.448
25.449 // see JCE spec
25.450 protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out,
25.451 - int outOfs) throws ShortBufferException, IllegalBlockSizeException {
25.452 - // BadPaddingException {
25.453 + int outOfs) throws ShortBufferException, IllegalBlockSizeException,
25.454 + BadPaddingException {
25.455 int n = 0;
25.456 if ((inLen != 0) && (in != null)) {
25.457 n = engineUpdate(in, inOfs, inLen, out, outOfs);
25.458 @@ -440,8 +500,10 @@
25.459 }
25.460
25.461 // see JCE spec
25.462 + @Override
25.463 protected int engineDoFinal(ByteBuffer inBuffer, ByteBuffer outBuffer)
25.464 - throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
25.465 + throws ShortBufferException, IllegalBlockSizeException,
25.466 + BadPaddingException {
25.467 int n = engineUpdate(inBuffer, outBuffer);
25.468 n += implDoFinal(outBuffer);
25.469 return n;
25.470 @@ -454,18 +516,55 @@
25.471 }
25.472 try {
25.473 ensureInitialized();
25.474 - int k;
25.475 + int k = 0;
25.476 if (encrypt) {
25.477 - k = token.p11.C_EncryptUpdate
25.478 - (session.id(), 0, in, inOfs, inLen, 0, out, outOfs, outLen);
25.479 + k = token.p11.C_EncryptUpdate(session.id(), 0, in, inOfs, inLen,
25.480 + 0, out, outOfs, outLen);
25.481 } else {
25.482 - k = token.p11.C_DecryptUpdate
25.483 - (session.id(), 0, in, inOfs, inLen, 0, out, outOfs, outLen);
25.484 + int newPadBufferLen = 0;
25.485 + if (paddingObj != null) {
25.486 + if (padBufferLen != 0) {
25.487 + // NSS throws up when called with data not in multiple
25.488 + // of blocks. Try to work around this by holding the
25.489 + // extra data in padBuffer.
25.490 + if (padBufferLen != padBuffer.length) {
25.491 + int bufCapacity = padBuffer.length - padBufferLen;
25.492 + if (inLen > bufCapacity) {
25.493 + bufferInputBytes(in, inOfs, bufCapacity);
25.494 + inOfs += bufCapacity;
25.495 + inLen -= bufCapacity;
25.496 + } else {
25.497 + bufferInputBytes(in, inOfs, inLen);
25.498 + return 0;
25.499 + }
25.500 + }
25.501 + k = token.p11.C_DecryptUpdate(session.id(),
25.502 + 0, padBuffer, 0, padBufferLen,
25.503 + 0, out, outOfs, outLen);
25.504 + padBufferLen = 0;
25.505 + }
25.506 + newPadBufferLen = inLen & (blockSize - 1);
25.507 + if (newPadBufferLen == 0) {
25.508 + newPadBufferLen = padBuffer.length;
25.509 + }
25.510 + inLen -= newPadBufferLen;
25.511 + }
25.512 + if (inLen > 0) {
25.513 + k += token.p11.C_DecryptUpdate(session.id(), 0, in, inOfs,
25.514 + inLen, 0, out, (outOfs + k), (outLen - k));
25.515 + }
25.516 + // update 'padBuffer' if using our own padding impl.
25.517 + if (paddingObj != null) {
25.518 + bufferInputBytes(in, inOfs + inLen, newPadBufferLen);
25.519 + }
25.520 }
25.521 - bytesProcessed += inLen;
25.522 + bytesBuffered += (inLen - k);
25.523 return k;
25.524 } catch (PKCS11Exception e) {
25.525 - // XXX throw correct exception
25.526 + if (e.getErrorCode() == CKR_BUFFER_TOO_SMALL) {
25.527 + throw (ShortBufferException)
25.528 + (new ShortBufferException().initCause(e));
25.529 + }
25.530 throw new ProviderException("update() failed", e);
25.531 }
25.532 }
25.533 @@ -481,101 +580,167 @@
25.534 if (outLen < updateLength(inLen)) {
25.535 throw new ShortBufferException();
25.536 }
25.537 - boolean inPosChanged = false;
25.538 + int origPos = inBuffer.position();
25.539 try {
25.540 ensureInitialized();
25.541
25.542 long inAddr = 0;
25.543 - int inOfs = inBuffer.position();
25.544 + int inOfs = 0;
25.545 byte[] inArray = null;
25.546 +
25.547 if (inBuffer instanceof DirectBuffer) {
25.548 - inAddr = ((DirectBuffer)inBuffer).address();
25.549 + inAddr = ((DirectBuffer) inBuffer).address();
25.550 + inOfs = origPos;
25.551 + } else if (inBuffer.hasArray()) {
25.552 + inArray = inBuffer.array();
25.553 + inOfs = (origPos + inBuffer.arrayOffset());
25.554 + }
25.555 +
25.556 + long outAddr = 0;
25.557 + int outOfs = 0;
25.558 + byte[] outArray = null;
25.559 + if (outBuffer instanceof DirectBuffer) {
25.560 + outAddr = ((DirectBuffer) outBuffer).address();
25.561 + outOfs = outBuffer.position();
25.562 } else {
25.563 - if (inBuffer.hasArray()) {
25.564 - inArray = inBuffer.array();
25.565 - inOfs += inBuffer.arrayOffset();
25.566 + if (outBuffer.hasArray()) {
25.567 + outArray = outBuffer.array();
25.568 + outOfs = (outBuffer.position() + outBuffer.arrayOffset());
25.569 } else {
25.570 - inArray = new byte[inLen];
25.571 - inBuffer.get(inArray);
25.572 - inOfs = 0;
25.573 - inPosChanged = true;
25.574 + outArray = new byte[outLen];
25.575 }
25.576 }
25.577
25.578 - long outAddr = 0;
25.579 - int outOfs = outBuffer.position();
25.580 - byte[] outArray = null;
25.581 - if (outBuffer instanceof DirectBuffer) {
25.582 - outAddr = ((DirectBuffer)outBuffer).address();
25.583 + int k = 0;
25.584 + if (encrypt) {
25.585 + if (inAddr == 0 && inArray == null) {
25.586 + inArray = new byte[inLen];
25.587 + inBuffer.get(inArray);
25.588 + } else {
25.589 + inBuffer.position(origPos + inLen);
25.590 + }
25.591 + k = token.p11.C_EncryptUpdate(session.id(),
25.592 + inAddr, inArray, inOfs, inLen,
25.593 + outAddr, outArray, outOfs, outLen);
25.594 } else {
25.595 - if (outBuffer.hasArray()) {
25.596 - outArray = outBuffer.array();
25.597 - outOfs += outBuffer.arrayOffset();
25.598 - } else {
25.599 - outArray = new byte[outLen];
25.600 - outOfs = 0;
25.601 + int newPadBufferLen = 0;
25.602 + if (paddingObj != null) {
25.603 + if (padBufferLen != 0) {
25.604 + // NSS throws up when called with data not in multiple
25.605 + // of blocks. Try to work around this by holding the
25.606 + // extra data in padBuffer.
25.607 + if (padBufferLen != padBuffer.length) {
25.608 + int bufCapacity = padBuffer.length - padBufferLen;
25.609 + if (inLen > bufCapacity) {
25.610 + bufferInputBytes(inBuffer, bufCapacity);
25.611 + inOfs += bufCapacity;
25.612 + inLen -= bufCapacity;
25.613 + } else {
25.614 + bufferInputBytes(inBuffer, inLen);
25.615 + return 0;
25.616 + }
25.617 + }
25.618 + k = token.p11.C_DecryptUpdate(session.id(), 0,
25.619 + padBuffer, 0, padBufferLen, outAddr, outArray,
25.620 + outOfs, outLen);
25.621 + padBufferLen = 0;
25.622 + }
25.623 + newPadBufferLen = inLen & (blockSize - 1);
25.624 + if (newPadBufferLen == 0) {
25.625 + newPadBufferLen = padBuffer.length;
25.626 + }
25.627 + inLen -= newPadBufferLen;
25.628 + }
25.629 + if (inLen > 0) {
25.630 + if (inAddr == 0 && inArray == null) {
25.631 + inArray = new byte[inLen];
25.632 + inBuffer.get(inArray);
25.633 + } else {
25.634 + inBuffer.position(inBuffer.position() + inLen);
25.635 + }
25.636 + k += token.p11.C_DecryptUpdate(session.id(), inAddr,
25.637 + inArray, inOfs, inLen, outAddr, outArray,
25.638 + (outOfs + k), (outLen - k));
25.639 + }
25.640 + // update 'padBuffer' if using our own padding impl.
25.641 + if (paddingObj != null && newPadBufferLen != 0) {
25.642 + bufferInputBytes(inBuffer, newPadBufferLen);
25.643 }
25.644 }
25.645 -
25.646 - int k;
25.647 - if (encrypt) {
25.648 - k = token.p11.C_EncryptUpdate
25.649 - (session.id(), inAddr, inArray, inOfs, inLen,
25.650 - outAddr, outArray, outOfs, outLen);
25.651 - } else {
25.652 - k = token.p11.C_DecryptUpdate
25.653 - (session.id(), inAddr, inArray, inOfs, inLen,
25.654 - outAddr, outArray, outOfs, outLen);
25.655 - }
25.656 - bytesProcessed += inLen;
25.657 - if (!inPosChanged) {
25.658 - inBuffer.position(inBuffer.position() + inLen);
25.659 - }
25.660 + bytesBuffered += (inLen - k);
25.661 if (!(outBuffer instanceof DirectBuffer) &&
25.662 - !outBuffer.hasArray()) {
25.663 + !outBuffer.hasArray()) {
25.664 outBuffer.put(outArray, outOfs, k);
25.665 } else {
25.666 outBuffer.position(outBuffer.position() + k);
25.667 }
25.668 return k;
25.669 } catch (PKCS11Exception e) {
25.670 - // Un-read the bytes back to input buffer
25.671 - if (inPosChanged) {
25.672 - inBuffer.position(inBuffer.position() - inLen);
25.673 + // Reset input buffer to its original position for
25.674 + inBuffer.position(origPos);
25.675 + if (e.getErrorCode() == CKR_BUFFER_TOO_SMALL) {
25.676 + throw (ShortBufferException)
25.677 + (new ShortBufferException().initCause(e));
25.678 }
25.679 - // XXX throw correct exception
25.680 throw new ProviderException("update() failed", e);
25.681 }
25.682 }
25.683
25.684 private int implDoFinal(byte[] out, int outOfs, int outLen)
25.685 - throws ShortBufferException, IllegalBlockSizeException {
25.686 - if (outLen < doFinalLength(0)) {
25.687 + throws ShortBufferException, IllegalBlockSizeException,
25.688 + BadPaddingException {
25.689 + int requiredOutLen = doFinalLength(0);
25.690 + if (outLen < requiredOutLen) {
25.691 throw new ShortBufferException();
25.692 }
25.693 try {
25.694 ensureInitialized();
25.695 + int k = 0;
25.696 if (encrypt) {
25.697 - return token.p11.C_EncryptFinal
25.698 - (session.id(), 0, out, outOfs, outLen);
25.699 + if (paddingObj != null) {
25.700 + int actualPadLen = paddingObj.setPaddingBytes(padBuffer,
25.701 + requiredOutLen - bytesBuffered);
25.702 + k = token.p11.C_EncryptUpdate(session.id(),
25.703 + 0, padBuffer, 0, actualPadLen,
25.704 + 0, out, outOfs, outLen);
25.705 + }
25.706 + k += token.p11.C_EncryptFinal(session.id(),
25.707 + 0, out, (outOfs + k), (outLen - k));
25.708 } else {
25.709 - return token.p11.C_DecryptFinal
25.710 - (session.id(), 0, out, outOfs, outLen);
25.711 + if (paddingObj != null) {
25.712 + if (padBufferLen != 0) {
25.713 + k = token.p11.C_DecryptUpdate(session.id(), 0,
25.714 + padBuffer, 0, padBufferLen, 0, padBuffer, 0,
25.715 + padBuffer.length);
25.716 + }
25.717 + k += token.p11.C_DecryptFinal(session.id(), 0, padBuffer, k,
25.718 + padBuffer.length - k);
25.719 + int actualPadLen = paddingObj.unpad(padBuffer, k);
25.720 + k -= actualPadLen;
25.721 + System.arraycopy(padBuffer, 0, out, outOfs, k);
25.722 + } else {
25.723 + k = token.p11.C_DecryptFinal(session.id(), 0, out, outOfs,
25.724 + outLen);
25.725 + }
25.726 }
25.727 + return k;
25.728 } catch (PKCS11Exception e) {
25.729 handleException(e);
25.730 throw new ProviderException("doFinal() failed", e);
25.731 } finally {
25.732 initialized = false;
25.733 - bytesProcessed = 0;
25.734 + bytesBuffered = 0;
25.735 + padBufferLen = 0;
25.736 session = token.releaseSession(session);
25.737 }
25.738 }
25.739
25.740 private int implDoFinal(ByteBuffer outBuffer)
25.741 - throws ShortBufferException, IllegalBlockSizeException {
25.742 + throws ShortBufferException, IllegalBlockSizeException,
25.743 + BadPaddingException {
25.744 int outLen = outBuffer.remaining();
25.745 - if (outLen < doFinalLength(0)) {
25.746 + int requiredOutLen = doFinalLength(0);
25.747 + if (outLen < requiredOutLen) {
25.748 throw new ShortBufferException();
25.749 }
25.750
25.751 @@ -583,30 +748,54 @@
25.752 ensureInitialized();
25.753
25.754 long outAddr = 0;
25.755 - int outOfs = outBuffer.position();
25.756 byte[] outArray = null;
25.757 + int outOfs = 0;
25.758 if (outBuffer instanceof DirectBuffer) {
25.759 - outAddr = ((DirectBuffer)outBuffer).address();
25.760 + outAddr = ((DirectBuffer) outBuffer).address();
25.761 + outOfs = outBuffer.position();
25.762 } else {
25.763 if (outBuffer.hasArray()) {
25.764 outArray = outBuffer.array();
25.765 - outOfs += outBuffer.arrayOffset();
25.766 + outOfs = outBuffer.position() + outBuffer.arrayOffset();
25.767 } else {
25.768 outArray = new byte[outLen];
25.769 - outOfs = 0;
25.770 }
25.771 }
25.772
25.773 - int k;
25.774 + int k = 0;
25.775 +
25.776 if (encrypt) {
25.777 - k = token.p11.C_EncryptFinal
25.778 - (session.id(), outAddr, outArray, outOfs, outLen);
25.779 + if (paddingObj != null) {
25.780 + int actualPadLen = paddingObj.setPaddingBytes(padBuffer,
25.781 + requiredOutLen - bytesBuffered);
25.782 + k = token.p11.C_EncryptUpdate(session.id(),
25.783 + 0, padBuffer, 0, actualPadLen,
25.784 + outAddr, outArray, outOfs, outLen);
25.785 + }
25.786 + k += token.p11.C_EncryptFinal(session.id(),
25.787 + outAddr, outArray, (outOfs + k), (outLen - k));
25.788 } else {
25.789 - k = token.p11.C_DecryptFinal
25.790 - (session.id(), outAddr, outArray, outOfs, outLen);
25.791 + if (paddingObj != null) {
25.792 + if (padBufferLen != 0) {
25.793 + k = token.p11.C_DecryptUpdate(session.id(),
25.794 + 0, padBuffer, 0, padBufferLen,
25.795 + 0, padBuffer, 0, padBuffer.length);
25.796 + padBufferLen = 0;
25.797 + }
25.798 + k += token.p11.C_DecryptFinal(session.id(),
25.799 + 0, padBuffer, k, padBuffer.length - k);
25.800 + int actualPadLen = paddingObj.unpad(padBuffer, k);
25.801 + k -= actualPadLen;
25.802 + outArray = padBuffer;
25.803 + outOfs = 0;
25.804 + } else {
25.805 + k = token.p11.C_DecryptFinal(session.id(),
25.806 + outAddr, outArray, outOfs, outLen);
25.807 + }
25.808 }
25.809 - if (!(outBuffer instanceof DirectBuffer) &&
25.810 - !outBuffer.hasArray()) {
25.811 + if ((!encrypt && paddingObj != null) ||
25.812 + (!(outBuffer instanceof DirectBuffer) &&
25.813 + !outBuffer.hasArray())) {
25.814 outBuffer.put(outArray, outOfs, k);
25.815 } else {
25.816 outBuffer.position(outBuffer.position() + k);
25.817 @@ -617,20 +806,22 @@
25.818 throw new ProviderException("doFinal() failed", e);
25.819 } finally {
25.820 initialized = false;
25.821 - bytesProcessed = 0;
25.822 + bytesBuffered = 0;
25.823 session = token.releaseSession(session);
25.824 }
25.825 }
25.826
25.827 private void handleException(PKCS11Exception e)
25.828 - throws IllegalBlockSizeException {
25.829 + throws ShortBufferException, IllegalBlockSizeException {
25.830 long errorCode = e.getErrorCode();
25.831 - // XXX better check
25.832 - if (errorCode == CKR_DATA_LEN_RANGE) {
25.833 - throw (IllegalBlockSizeException)new
25.834 - IllegalBlockSizeException(e.toString()).initCause(e);
25.835 + if (errorCode == CKR_BUFFER_TOO_SMALL) {
25.836 + throw (ShortBufferException)
25.837 + (new ShortBufferException().initCause(e));
25.838 + } else if (errorCode == CKR_DATA_LEN_RANGE ||
25.839 + errorCode == CKR_ENCRYPTED_DATA_LEN_RANGE) {
25.840 + throw (IllegalBlockSizeException)
25.841 + (new IllegalBlockSizeException(e.toString()).initCause(e));
25.842 }
25.843 -
25.844 }
25.845
25.846 // see JCE spec
25.847 @@ -649,12 +840,14 @@
25.848 }
25.849
25.850 // see JCE spec
25.851 + @Override
25.852 protected int engineGetKeySize(Key key) throws InvalidKeyException {
25.853 int n = P11SecretKeyFactory.convertKey
25.854 - (token, key, keyAlgorithm).keyLength();
25.855 + (token, key, keyAlgorithm).keyLength();
25.856 return n;
25.857 }
25.858
25.859 + @Override
25.860 protected void finalize() throws Throwable {
25.861 try {
25.862 if ((session != null) && token.isValid()) {
25.863 @@ -666,4 +859,15 @@
25.864 }
25.865 }
25.866
25.867 + private final void bufferInputBytes(byte[] in, int inOfs, int len) {
25.868 + System.arraycopy(in, inOfs, padBuffer, padBufferLen, len);
25.869 + padBufferLen += len;
25.870 + bytesBuffered += len;
25.871 + }
25.872 +
25.873 + private final void bufferInputBytes(ByteBuffer inBuffer, int len) {
25.874 + inBuffer.get(padBuffer, padBufferLen, len);
25.875 + padBufferLen += len;
25.876 + bytesBuffered += len;
25.877 + }
25.878 }
26.1 --- a/src/share/classes/sun/security/pkcs11/P11KeyGenerator.java Fri Apr 18 12:47:38 2008 -0700
26.2 +++ b/src/share/classes/sun/security/pkcs11/P11KeyGenerator.java Fri Apr 18 16:40:32 2008 -0700
26.3 @@ -1,5 +1,5 @@
26.4 /*
26.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
26.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
26.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26.8 *
26.9 * This code is free software; you can redistribute it and/or modify it
26.10 @@ -65,10 +65,86 @@
26.11 // are supported.
26.12 private boolean supportBothKeySizes;
26.13
26.14 - // min and max key sizes (in bits) for variable-key-length
26.15 - // algorithms, e.g. RC4 and Blowfish
26.16 - private int minKeySize;
26.17 - private int maxKeySize;
26.18 + /**
26.19 + * Utility method for checking if the specified key size is valid
26.20 + * and within the supported range. Return the significant key size
26.21 + * upon successful validation.
26.22 + * @param keyGenMech the PKCS#11 key generation mechanism.
26.23 + * @param keySize the to-be-checked key size for this mechanism.
26.24 + * @param token token which provides this mechanism.
26.25 + * @return the significant key size (in bits) corresponding to the
26.26 + * specified key size.
26.27 + * @throws InvalidParameterException if the specified key size is invalid.
26.28 + * @throws ProviderException if this mechanism isn't supported by SunPKCS11
26.29 + * or underlying native impl.
26.30 + */
26.31 + static int checkKeySize(long keyGenMech, int keySize, Token token)
26.32 + throws InvalidAlgorithmParameterException, ProviderException {
26.33 + int sigKeySize;
26.34 + switch ((int)keyGenMech) {
26.35 + case (int)CKM_DES_KEY_GEN:
26.36 + if ((keySize != 64) && (keySize != 56)) {
26.37 + throw new InvalidAlgorithmParameterException
26.38 + ("DES key length must be 56 bits");
26.39 + }
26.40 + sigKeySize = 56;
26.41 + break;
26.42 + case (int)CKM_DES2_KEY_GEN:
26.43 + case (int)CKM_DES3_KEY_GEN:
26.44 + if ((keySize == 112) || (keySize == 128)) {
26.45 + sigKeySize = 112;
26.46 + } else if ((keySize == 168) || (keySize == 192)) {
26.47 + sigKeySize = 168;
26.48 + } else {
26.49 + throw new InvalidAlgorithmParameterException
26.50 + ("DESede key length must be 112, or 168 bits");
26.51 + }
26.52 + break;
26.53 + default:
26.54 + // Handle all variable-key-length algorithms here
26.55 + CK_MECHANISM_INFO info = null;
26.56 + try {
26.57 + info = token.getMechanismInfo(keyGenMech);
26.58 + } catch (PKCS11Exception p11e) {
26.59 + // Should never happen
26.60 + throw new ProviderException
26.61 + ("Cannot retrieve mechanism info", p11e);
26.62 + }
26.63 + if (info == null) {
26.64 + // XXX Unable to retrieve the supported key length from
26.65 + // the underlying native impl. Skip the checking for now.
26.66 + return keySize;
26.67 + }
26.68 + // PKCS#11 defines these to be in number of bytes except for
26.69 + // RC4 which is in bits. However, some PKCS#11 impls still use
26.70 + // bytes for all mechs, e.g. NSS. We try to detect this
26.71 + // inconsistency if the minKeySize seems unreasonably small.
26.72 + int minKeySize = (int)info.ulMinKeySize;
26.73 + int maxKeySize = (int)info.ulMaxKeySize;
26.74 + if (keyGenMech != CKM_RC4_KEY_GEN || minKeySize < 8) {
26.75 + minKeySize = (int)info.ulMinKeySize << 3;
26.76 + maxKeySize = (int)info.ulMaxKeySize << 3;
26.77 + }
26.78 + // Explicitly disallow keys shorter than 40-bits for security
26.79 + if (minKeySize < 40) minKeySize = 40;
26.80 + if (keySize < minKeySize || keySize > maxKeySize) {
26.81 + throw new InvalidAlgorithmParameterException
26.82 + ("Key length must be between " + minKeySize +
26.83 + " and " + maxKeySize + " bits");
26.84 + }
26.85 + if (keyGenMech == CKM_AES_KEY_GEN) {
26.86 + if ((keySize != 128) && (keySize != 192) &&
26.87 + (keySize != 256)) {
26.88 + throw new InvalidAlgorithmParameterException
26.89 + ("AES key length must be " + minKeySize +
26.90 + (maxKeySize >= 192? ", 192":"") +
26.91 + (maxKeySize >= 256? ", or 256":"") + " bits");
26.92 + }
26.93 + }
26.94 + sigKeySize = keySize;
26.95 + }
26.96 + return sigKeySize;
26.97 + }
26.98
26.99 P11KeyGenerator(Token token, String algorithm, long mechanism)
26.100 throws PKCS11Exception {
26.101 @@ -85,72 +161,44 @@
26.102 supportBothKeySizes =
26.103 (token.provider.config.isEnabled(CKM_DES2_KEY_GEN) &&
26.104 (token.getMechanismInfo(CKM_DES2_KEY_GEN) != null));
26.105 - } else if (this.mechanism == CKM_RC4_KEY_GEN) {
26.106 - CK_MECHANISM_INFO info = token.getMechanismInfo(mechanism);
26.107 - // Although PKCS#11 spec documented that these are in bits,
26.108 - // NSS, for one, uses bytes. Multiple by 8 if the number seems
26.109 - // unreasonably small.
26.110 - if (info.ulMinKeySize < 8) {
26.111 - minKeySize = (int)info.ulMinKeySize << 3;
26.112 - maxKeySize = (int)info.ulMaxKeySize << 3;
26.113 - } else {
26.114 - minKeySize = (int)info.ulMinKeySize;
26.115 - maxKeySize = (int)info.ulMaxKeySize;
26.116 - }
26.117 - // Explicitly disallow keys shorter than 40-bits for security
26.118 - if (minKeySize < 40) minKeySize = 40;
26.119 - } else if (this.mechanism == CKM_BLOWFISH_KEY_GEN) {
26.120 - CK_MECHANISM_INFO info = token.getMechanismInfo(mechanism);
26.121 - maxKeySize = (int)info.ulMaxKeySize << 3;
26.122 - minKeySize = (int)info.ulMinKeySize << 3;
26.123 - // Explicitly disallow keys shorter than 40-bits for security
26.124 - if (minKeySize < 40) minKeySize = 40;
26.125 }
26.126 -
26.127 setDefaultKeySize();
26.128 }
26.129
26.130 // set default keysize and also initialize keyType
26.131 private void setDefaultKeySize() {
26.132 - // whether to check default key size against the min and max value
26.133 - boolean validateKeySize = false;
26.134 switch ((int)mechanism) {
26.135 case (int)CKM_DES_KEY_GEN:
26.136 keySize = 64;
26.137 - significantKeySize = 56;
26.138 keyType = CKK_DES;
26.139 break;
26.140 case (int)CKM_DES2_KEY_GEN:
26.141 keySize = 128;
26.142 - significantKeySize = 112;
26.143 keyType = CKK_DES2;
26.144 break;
26.145 case (int)CKM_DES3_KEY_GEN:
26.146 keySize = 192;
26.147 - significantKeySize = 168;
26.148 keyType = CKK_DES3;
26.149 break;
26.150 case (int)CKM_AES_KEY_GEN:
26.151 + keySize = 128;
26.152 keyType = CKK_AES;
26.153 - keySize = 128;
26.154 - significantKeySize = 128;
26.155 break;
26.156 case (int)CKM_RC4_KEY_GEN:
26.157 + keySize = 128;
26.158 keyType = CKK_RC4;
26.159 - keySize = 128;
26.160 - validateKeySize = true;
26.161 break;
26.162 case (int)CKM_BLOWFISH_KEY_GEN:
26.163 + keySize = 128;
26.164 keyType = CKK_BLOWFISH;
26.165 - keySize = 128;
26.166 - validateKeySize = true;
26.167 break;
26.168 default:
26.169 throw new ProviderException("Unknown mechanism " + mechanism);
26.170 }
26.171 - if (validateKeySize &&
26.172 - ((keySize > maxKeySize) || (keySize < minKeySize))) {
26.173 - throw new ProviderException("Unsupported key size");
26.174 + try {
26.175 + significantKeySize = checkKeySize(mechanism, keySize, token);
26.176 + } catch (InvalidAlgorithmParameterException iape) {
26.177 + throw new ProviderException("Unsupported default key size", iape);
26.178 }
26.179 }
26.180
26.181 @@ -170,57 +218,32 @@
26.182 // see JCE spec
26.183 protected void engineInit(int keySize, SecureRandom random) {
26.184 token.ensureValid();
26.185 - switch ((int)mechanism) {
26.186 - case (int)CKM_DES_KEY_GEN:
26.187 - if ((keySize != this.keySize) &&
26.188 - (keySize != this.significantKeySize)) {
26.189 - throw new InvalidParameterException
26.190 - ("DES key length must be 56 bits");
26.191 - }
26.192 - break;
26.193 - case (int)CKM_DES2_KEY_GEN:
26.194 - case (int)CKM_DES3_KEY_GEN:
26.195 - long newMechanism;
26.196 - if ((keySize == 112) || (keySize == 128)) {
26.197 - newMechanism = CKM_DES2_KEY_GEN;
26.198 - } else if ((keySize == 168) || (keySize == 192)) {
26.199 - newMechanism = CKM_DES3_KEY_GEN;
26.200 - } else {
26.201 - throw new InvalidParameterException
26.202 - ("DESede key length must be 112, or 168 bits");
26.203 - }
26.204 + int newSignificantKeySize;
26.205 + try {
26.206 + newSignificantKeySize = checkKeySize(mechanism, keySize, token);
26.207 + } catch (InvalidAlgorithmParameterException iape) {
26.208 + throw (InvalidParameterException)
26.209 + (new InvalidParameterException().initCause(iape));
26.210 + }
26.211 + if ((mechanism == CKM_DES2_KEY_GEN) ||
26.212 + (mechanism == CKM_DES3_KEY_GEN)) {
26.213 + long newMechanism = (newSignificantKeySize == 112 ?
26.214 + CKM_DES2_KEY_GEN : CKM_DES3_KEY_GEN);
26.215 if (mechanism != newMechanism) {
26.216 if (supportBothKeySizes) {
26.217 mechanism = newMechanism;
26.218 - setDefaultKeySize();
26.219 + // Adjust keyType to reflect the mechanism change
26.220 + keyType = (mechanism == CKM_DES2_KEY_GEN ?
26.221 + CKK_DES2 : CKK_DES3);
26.222 } else {
26.223 throw new InvalidParameterException
26.224 - ("Only " + significantKeySize +
26.225 - "-bit DESede key length is supported");
26.226 + ("Only " + significantKeySize +
26.227 + "-bit DESede is supported");
26.228 }
26.229 }
26.230 - break;
26.231 - case (int)CKM_AES_KEY_GEN:
26.232 - if ((keySize != 128) && (keySize != 192) && (keySize != 256)) {
26.233 - throw new InvalidParameterException
26.234 - ("AES key length must be 128, 192, or 256 bits");
26.235 - }
26.236 - this.keySize = keySize;
26.237 - significantKeySize = keySize;
26.238 - break;
26.239 - case (int)CKM_RC4_KEY_GEN:
26.240 - case (int)CKM_BLOWFISH_KEY_GEN:
26.241 - if ((keySize < minKeySize) || (keySize > maxKeySize)) {
26.242 - throw new InvalidParameterException
26.243 - (algorithm + " key length must be between " +
26.244 - minKeySize + " and " + maxKeySize + " bits");
26.245 - }
26.246 - this.keySize = keySize;
26.247 - this.significantKeySize = keySize;
26.248 - break;
26.249 - default:
26.250 - throw new ProviderException("Unknown mechanism " + mechanism);
26.251 }
26.252 + this.keySize = keySize;
26.253 + this.significantKeySize = newSignificantKeySize;
26.254 }
26.255
26.256 // see JCE spec
27.1 --- a/src/share/classes/sun/security/pkcs11/P11KeyStore.java Fri Apr 18 12:47:38 2008 -0700
27.2 +++ b/src/share/classes/sun/security/pkcs11/P11KeyStore.java Fri Apr 18 16:40:32 2008 -0700
27.3 @@ -1,5 +1,5 @@
27.4 /*
27.5 - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
27.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
27.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.8 *
27.9 * This code is free software; you can redistribute it and/or modify it
27.10 @@ -156,10 +156,10 @@
27.11 // CKA_CLASS - entry type
27.12 private CK_ATTRIBUTE type = null;
27.13
27.14 - // CKA_LABEL of cert
27.15 + // CKA_LABEL of cert and secret key
27.16 private String label = null;
27.17
27.18 - // CKA_ID - of private key/cert
27.19 + // CKA_ID of the private key/cert pair
27.20 private byte[] id = null;
27.21
27.22 // CKA_TRUSTED - true if cert is trusted
27.23 @@ -871,10 +871,8 @@
27.24 if ((token.tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) {
27.25 token.provider.login(null, handler);
27.26 } else {
27.27 -
27.28 // token supports protected authentication path
27.29 // (external pin-pad, for example)
27.30 -
27.31 if (handler != null &&
27.32 !token.config.getKeyStoreCompatibilityMode()) {
27.33 throw new LoginException("can not specify password if token " +
27.34 @@ -1130,19 +1128,14 @@
27.35 SecretKey skey = ske.getSecretKey();
27.36
27.37 try {
27.38 - // first see if the key already exists.
27.39 - // if so, update the CKA_LABEL
27.40 - if (!updateSkey(alias)) {
27.41 + // first check if the key already exists
27.42 + AliasInfo aliasInfo = aliasMap.get(alias);
27.43
27.44 - // key entry does not exist.
27.45 - // delete existing entry for alias and
27.46 - // create new secret key entry
27.47 - // (new entry might be a secret key
27.48 - // session object converted into a token object)
27.49 + if (aliasInfo != null) {
27.50 + engineDeleteEntry(alias);
27.51 + }
27.52 + storeSkey(alias, ske);
27.53
27.54 - engineDeleteEntry(alias);
27.55 - storeSkey(alias, ske);
27.56 - }
27.57 } catch (PKCS11Exception pe) {
27.58 throw new KeyStoreException(pe);
27.59 }
27.60 @@ -1396,41 +1389,6 @@
27.61 }
27.62 }
27.63
27.64 - /**
27.65 - * return true if update occurred
27.66 - */
27.67 - private boolean updateSkey(String alias)
27.68 - throws KeyStoreException, PKCS11Exception {
27.69 -
27.70 - Session session = null;
27.71 - try {
27.72 - session = token.getOpSession();
27.73 -
27.74 - // first update existing secret key CKA_LABEL
27.75 -
27.76 - THandle h = getTokenObject(session, ATTR_CLASS_SKEY, null, alias);
27.77 - if (h.type != ATTR_CLASS_SKEY) {
27.78 - if (debug != null) {
27.79 - debug.println("did not find secret key " +
27.80 - "with CKA_LABEL [" + alias + "]");
27.81 - }
27.82 - return false;
27.83 - }
27.84 - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] {
27.85 - new CK_ATTRIBUTE(CKA_LABEL, alias) };
27.86 - token.p11.C_SetAttributeValue(session.id(), h.handle, attrs);
27.87 -
27.88 - if (debug != null) {
27.89 - debug.println("updateSkey set new alias [" +
27.90 - alias +
27.91 - "] for secret key entry");
27.92 - }
27.93 -
27.94 - return true;
27.95 - } finally {
27.96 - token.releaseSession(session);
27.97 - }
27.98 - }
27.99
27.100 /**
27.101 * XXX On ibutton, when you C_SetAttribute(CKA_ID) for a private key
27.102 @@ -1532,30 +1490,6 @@
27.103 }
27.104 }
27.105
27.106 - private void updateP11Skey(String alias, P11Key key)
27.107 - throws PKCS11Exception {
27.108 -
27.109 - Session session = null;
27.110 - try {
27.111 - session = token.getOpSession();
27.112 -
27.113 - // session key - convert to token key and set CKA_LABEL
27.114 -
27.115 - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] {
27.116 - ATTR_TOKEN_TRUE,
27.117 - new CK_ATTRIBUTE(CKA_LABEL, alias) };
27.118 - token.p11.C_CopyObject(session.id(), key.keyID, attrs);
27.119 - if (debug != null) {
27.120 - debug.println("updateP11Skey copied secret session key " +
27.121 - "for [" +
27.122 - alias +
27.123 - "] to token entry");
27.124 - }
27.125 - } finally {
27.126 - token.releaseSession(session);
27.127 - }
27.128 - }
27.129 -
27.130 private void updateP11Pkey(String alias, CK_ATTRIBUTE attribute, P11Key key)
27.131 throws PKCS11Exception {
27.132
27.133 @@ -1689,48 +1623,26 @@
27.134 throws PKCS11Exception, KeyStoreException {
27.135
27.136 SecretKey skey = ske.getSecretKey();
27.137 - long keyType = CKK_GENERIC_SECRET;
27.138 -
27.139 - if (skey instanceof P11Key && this.token == ((P11Key)skey).token) {
27.140 - updateP11Skey(alias, (P11Key)skey);
27.141 - return;
27.142 + // No need to specify CKA_CLASS, CKA_KEY_TYPE, CKA_VALUE since
27.143 + // they are handled in P11SecretKeyFactory.createKey() method.
27.144 + CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] {
27.145 + ATTR_SKEY_TOKEN_TRUE,
27.146 + ATTR_PRIVATE_TRUE,
27.147 + new CK_ATTRIBUTE(CKA_LABEL, alias),
27.148 + };
27.149 + try {
27.150 + P11SecretKeyFactory.convertKey(token, skey, null, attrs);
27.151 + } catch (InvalidKeyException ike) {
27.152 + // re-throw KeyStoreException to match javadoc
27.153 + throw new KeyStoreException("Cannot convert to PKCS11 keys", ike);
27.154 }
27.155
27.156 - if ("AES".equalsIgnoreCase(skey.getAlgorithm())) {
27.157 - keyType = CKK_AES;
27.158 - } else if ("Blowfish".equalsIgnoreCase(skey.getAlgorithm())) {
27.159 - keyType = CKK_BLOWFISH;
27.160 - } else if ("DES".equalsIgnoreCase(skey.getAlgorithm())) {
27.161 - keyType = CKK_DES;
27.162 - } else if ("DESede".equalsIgnoreCase(skey.getAlgorithm())) {
27.163 - keyType = CKK_DES3;
27.164 - } else if ("RC4".equalsIgnoreCase(skey.getAlgorithm()) ||
27.165 - "ARCFOUR".equalsIgnoreCase(skey.getAlgorithm())) {
27.166 - keyType = CKK_RC4;
27.167 - }
27.168 + // update global alias map
27.169 + aliasMap.put(alias, new AliasInfo(alias));
27.170
27.171 - CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[] {
27.172 - ATTR_SKEY_TOKEN_TRUE,
27.173 - ATTR_CLASS_SKEY,
27.174 - ATTR_PRIVATE_TRUE,
27.175 - new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType),
27.176 - new CK_ATTRIBUTE(CKA_LABEL, alias),
27.177 - new CK_ATTRIBUTE(CKA_VALUE, skey.getEncoded()) };
27.178 - attrs = token.getAttributes
27.179 - (TemplateManager.O_IMPORT, CKO_SECRET_KEY, keyType, attrs);
27.180 -
27.181 - // create the new entry
27.182 - Session session = null;
27.183 - try {
27.184 - session = token.getOpSession();
27.185 - token.p11.C_CreateObject(session.id(), attrs);
27.186 - if (debug != null) {
27.187 - debug.println("storeSkey created token secret key for [" +
27.188 - alias +
27.189 - "]");
27.190 - }
27.191 - } finally {
27.192 - token.releaseSession(session);
27.193 + if (debug != null) {
27.194 + debug.println("storeSkey created token secret key for [" +
27.195 + alias + "]");
27.196 }
27.197 }
27.198
27.199 @@ -2492,7 +2404,8 @@
27.200 // if there are duplicates (either between secret keys,
27.201 // or between a secret key and another object),
27.202 // throw an exception
27.203 - HashSet<String> sKeySet = new HashSet<String>();
27.204 + HashMap<String, AliasInfo> sKeyMap =
27.205 + new HashMap<String, AliasInfo>();
27.206
27.207 attrs = new CK_ATTRIBUTE[] {
27.208 ATTR_SKEY_TOKEN_TRUE,
27.209 @@ -2507,8 +2420,8 @@
27.210
27.211 // there is a CKA_LABEL
27.212 String cka_label = new String(attrs[0].getCharArray());
27.213 - if (!sKeySet.contains(cka_label)) {
27.214 - sKeySet.add(cka_label);
27.215 + if (sKeyMap.get(cka_label) == null) {
27.216 + sKeyMap.put(cka_label, new AliasInfo(cka_label));
27.217 } else {
27.218 throw new KeyStoreException("invalid KeyStore state: " +
27.219 "found multiple secret keys sharing same " +
27.220 @@ -2523,7 +2436,7 @@
27.221 ArrayList<AliasInfo> matchedCerts =
27.222 mapPrivateKeys(pkeyIDs, certMap);
27.223 boolean sharedLabel = mapCerts(matchedCerts, certMap);
27.224 - mapSecretKeys(sKeySet);
27.225 + mapSecretKeys(sKeyMap);
27.226
27.227 return sharedLabel;
27.228
27.229 @@ -2547,7 +2460,7 @@
27.230 HashMap<String, HashSet<AliasInfo>> certMap)
27.231 throws PKCS11Exception, CertificateException {
27.232
27.233 - // global alias map
27.234 + // reset global alias map
27.235 aliasMap = new HashMap<String, AliasInfo>();
27.236
27.237 // list of matched certs that we will return
27.238 @@ -2722,18 +2635,17 @@
27.239 * If the secret key shares a CKA_LABEL with another entry,
27.240 * throw an exception
27.241 */
27.242 - private void mapSecretKeys(HashSet<String> sKeySet)
27.243 + private void mapSecretKeys(HashMap<String, AliasInfo> sKeyMap)
27.244 throws KeyStoreException {
27.245 - for (String label : sKeySet) {
27.246 - if (!aliasMap.containsKey(label)) {
27.247 - aliasMap.put(label, new AliasInfo(label));
27.248 - } else {
27.249 + for (String label : sKeyMap.keySet()) {
27.250 + if (aliasMap.containsKey(label)) {
27.251 throw new KeyStoreException("invalid KeyStore state: " +
27.252 "found secret key sharing CKA_LABEL [" +
27.253 label +
27.254 "] with another token object");
27.255 }
27.256 }
27.257 + aliasMap.putAll(sKeyMap);
27.258 }
27.259
27.260 private void dumpTokenMap() {
28.1 --- a/src/share/classes/sun/security/pkcs11/P11RSACipher.java Fri Apr 18 12:47:38 2008 -0700
28.2 +++ b/src/share/classes/sun/security/pkcs11/P11RSACipher.java Fri Apr 18 16:40:32 2008 -0700
28.3 @@ -1,5 +1,5 @@
28.4 /*
28.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
28.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28.8 *
28.9 * This code is free software; you can redistribute it and/or modify it
28.10 @@ -98,7 +98,6 @@
28.11 this.token = token;
28.12 this.algorithm = "RSA";
28.13 this.mechanism = mechanism;
28.14 - session = token.getOpSession();
28.15 }
28.16
28.17 // modes do not make sense for RSA, but allow ECB
28.18 @@ -184,7 +183,8 @@
28.19 throw new InvalidKeyException
28.20 ("Wrap has to be used with public keys");
28.21 }
28.22 - // No further setup needed for C_Wrap(). We remain uninitialized.
28.23 + // No further setup needed for C_Wrap(). We'll initialize later if
28.24 + // we can't use C_Wrap().
28.25 return;
28.26 } else if (opmode == Cipher.UNWRAP_MODE) {
28.27 if (p11Key.isPrivate() == false) {
28.28 @@ -383,7 +383,8 @@
28.29 return implDoFinal(out, outOfs, out.length - outOfs);
28.30 }
28.31
28.32 - private byte[] doFinal() throws BadPaddingException, IllegalBlockSizeException {
28.33 + private byte[] doFinal() throws BadPaddingException,
28.34 + IllegalBlockSizeException {
28.35 byte[] t = new byte[2048];
28.36 int n = implDoFinal(t, 0, t.length);
28.37 byte[] out = new byte[n];
28.38 @@ -394,20 +395,37 @@
28.39 // see JCE spec
28.40 protected byte[] engineWrap(Key key) throws InvalidKeyException,
28.41 IllegalBlockSizeException {
28.42 - // XXX Note that if we cannot convert key to a key on this token,
28.43 - // we will fail. For example, trying a wrap an AES key on a token that
28.44 - // does not support AES.
28.45 - // We could implement a fallback that just encrypts the encoding
28.46 - // (assuming the key is not sensitive). For now, we are operating under
28.47 - // the assumption that this is not necessary.
28.48 String keyAlg = key.getAlgorithm();
28.49 - P11Key secretKey = P11SecretKeyFactory.convertKey(token, key, keyAlg);
28.50 + P11Key sKey = null;
28.51 + try {
28.52 + // The conversion may fail, e.g. trying to wrap an AES key on
28.53 + // a token that does not support AES, or when the key size is
28.54 + // not within the range supported by the token.
28.55 + sKey = P11SecretKeyFactory.convertKey(token, key, keyAlg);
28.56 + } catch (InvalidKeyException ike) {
28.57 + byte[] toBeWrappedKey = key.getEncoded();
28.58 + if (toBeWrappedKey == null) {
28.59 + throw new InvalidKeyException
28.60 + ("wrap() failed, no encoding available", ike);
28.61 + }
28.62 + // Directly encrypt the key encoding when key conversion failed
28.63 + implInit(Cipher.ENCRYPT_MODE, p11Key);
28.64 + implUpdate(toBeWrappedKey, 0, toBeWrappedKey.length);
28.65 + try {
28.66 + return doFinal();
28.67 + } catch (BadPaddingException bpe) {
28.68 + // should not occur
28.69 + throw new InvalidKeyException("wrap() failed", bpe);
28.70 + } finally {
28.71 + // Restore original mode
28.72 + implInit(Cipher.WRAP_MODE, p11Key);
28.73 + }
28.74 + }
28.75 Session s = null;
28.76 try {
28.77 s = token.getOpSession();
28.78 - byte[] b = token.p11.C_WrapKey(s.id(), new CK_MECHANISM(mechanism),
28.79 - p11Key.keyID, secretKey.keyID);
28.80 - return b;
28.81 + return token.p11.C_WrapKey(s.id(), new CK_MECHANISM(mechanism),
28.82 + p11Key.keyID, sKey.keyID);
28.83 } catch (PKCS11Exception e) {
28.84 throw new InvalidKeyException("wrap() failed", e);
28.85 } finally {
28.86 @@ -431,11 +449,13 @@
28.87 };
28.88 attributes = token.getAttributes
28.89 (O_IMPORT, CKO_SECRET_KEY, keyType, attributes);
28.90 - long keyID = token.p11.C_UnwrapKey(s.id(), new CK_MECHANISM(mechanism),
28.91 - p11Key.keyID, wrappedKey, attributes);
28.92 - return P11Key.secretKey(session, keyID, algorithm, 48 << 3, attributes);
28.93 + long keyID = token.p11.C_UnwrapKey(s.id(),
28.94 + new CK_MECHANISM(mechanism), p11Key.keyID, wrappedKey,
28.95 + attributes);
28.96 + return P11Key.secretKey(session, keyID, algorithm, 48 << 3,
28.97 + attributes);
28.98 } catch (PKCS11Exception e) {
28.99 - throw new InvalidKeyException("wrap() failed", e);
28.100 + throw new InvalidKeyException("unwrap() failed", e);
28.101 } finally {
28.102 token.releaseSession(s);
28.103 }
29.1 --- a/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java Fri Apr 18 12:47:38 2008 -0700
29.2 +++ b/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java Fri Apr 18 16:40:32 2008 -0700
29.3 @@ -1,5 +1,5 @@
29.4 /*
29.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
29.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
29.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29.8 *
29.9 * This code is free software; you can redistribute it and/or modify it
29.10 @@ -104,9 +104,20 @@
29.11
29.12 /**
29.13 * Convert an arbitrary key of algorithm into a P11Key of provider.
29.14 - * Used engineTranslateKey(), P11Cipher.init(), and P11Mac.init().
29.15 + * Used in engineTranslateKey(), P11Cipher.init(), and P11Mac.init().
29.16 */
29.17 - static P11Key convertKey(Token token, Key key, String algorithm)
29.18 + static P11Key convertKey(Token token, Key key, String algo)
29.19 + throws InvalidKeyException {
29.20 + return convertKey(token, key, algo, null);
29.21 + }
29.22 +
29.23 + /**
29.24 + * Convert an arbitrary key of algorithm w/ custom attributes into a
29.25 + * P11Key of provider.
29.26 + * Used in P11KeyStore.storeSkey.
29.27 + */
29.28 + static P11Key convertKey(Token token, Key key, String algo,
29.29 + CK_ATTRIBUTE[] extraAttrs)
29.30 throws InvalidKeyException {
29.31 token.ensureValid();
29.32 if (key == null) {
29.33 @@ -115,25 +126,41 @@
29.34 if (key instanceof SecretKey == false) {
29.35 throw new InvalidKeyException("Key must be a SecretKey");
29.36 }
29.37 - long algorithmType;
29.38 - if (algorithm == null) {
29.39 - algorithm = key.getAlgorithm();
29.40 - algorithmType = getKeyType(algorithm);
29.41 + long algoType;
29.42 + if (algo == null) {
29.43 + algo = key.getAlgorithm();
29.44 + algoType = getKeyType(algo);
29.45 } else {
29.46 - algorithmType = getKeyType(algorithm);
29.47 + algoType = getKeyType(algo);
29.48 long keyAlgorithmType = getKeyType(key.getAlgorithm());
29.49 - if (algorithmType != keyAlgorithmType) {
29.50 - if ((algorithmType == PCKK_HMAC) || (algorithmType == PCKK_SSLMAC)) {
29.51 + if (algoType != keyAlgorithmType) {
29.52 + if ((algoType == PCKK_HMAC) || (algoType == PCKK_SSLMAC)) {
29.53 // ignore key algorithm for MACs
29.54 } else {
29.55 throw new InvalidKeyException
29.56 - ("Key algorithm must be " + algorithm);
29.57 + ("Key algorithm must be " + algo);
29.58 }
29.59 }
29.60 }
29.61 if (key instanceof P11Key) {
29.62 P11Key p11Key = (P11Key)key;
29.63 if (p11Key.token == token) {
29.64 + if (extraAttrs != null) {
29.65 + Session session = null;
29.66 + try {
29.67 + session = token.getObjSession();
29.68 + long newKeyID = token.p11.C_CopyObject(session.id(),
29.69 + p11Key.keyID, extraAttrs);
29.70 + p11Key = (P11Key) (P11Key.secretKey(p11Key.session,
29.71 + newKeyID, p11Key.algorithm, p11Key.keyLength,
29.72 + extraAttrs));
29.73 + } catch (PKCS11Exception p11e) {
29.74 + throw new InvalidKeyException
29.75 + ("Cannot duplicate the PKCS11 key", p11e);
29.76 + } finally {
29.77 + token.releaseSession(session);
29.78 + }
29.79 + }
29.80 return p11Key;
29.81 }
29.82 }
29.83 @@ -141,11 +168,11 @@
29.84 if (p11Key != null) {
29.85 return p11Key;
29.86 }
29.87 - if ("RAW".equals(key.getFormat()) == false) {
29.88 + if ("RAW".equalsIgnoreCase(key.getFormat()) == false) {
29.89 throw new InvalidKeyException("Encoded format must be RAW");
29.90 }
29.91 byte[] encoded = key.getEncoded();
29.92 - p11Key = createKey(token, encoded, algorithm, algorithmType);
29.93 + p11Key = createKey(token, encoded, algo, algoType, extraAttrs);
29.94 token.secretCache.put(key, p11Key);
29.95 return p11Key;
29.96 }
29.97 @@ -159,79 +186,79 @@
29.98 }
29.99
29.100 private static P11Key createKey(Token token, byte[] encoded,
29.101 - String algorithm, long keyType) throws InvalidKeyException {
29.102 - int n = encoded.length;
29.103 - int keyLength;
29.104 - switch ((int)keyType) {
29.105 - case (int)CKK_RC4:
29.106 - if ((n < 5) || (n > 128)) {
29.107 - throw new InvalidKeyException
29.108 - ("ARCFOUR key length must be between 5 and 128 bytes");
29.109 + String algorithm, long keyType, CK_ATTRIBUTE[] extraAttrs)
29.110 + throws InvalidKeyException {
29.111 + int n = encoded.length << 3;
29.112 + int keyLength = n;
29.113 + try {
29.114 + switch ((int)keyType) {
29.115 + case (int)CKK_DES:
29.116 + keyLength =
29.117 + P11KeyGenerator.checkKeySize(CKM_DES_KEY_GEN, n, token);
29.118 + fixDESParity(encoded, 0);
29.119 + break;
29.120 + case (int)CKK_DES3:
29.121 + keyLength =
29.122 + P11KeyGenerator.checkKeySize(CKM_DES3_KEY_GEN, n, token);
29.123 + fixDESParity(encoded, 0);
29.124 + fixDESParity(encoded, 8);
29.125 + if (keyLength == 112) {
29.126 + keyType = CKK_DES2;
29.127 + } else {
29.128 + keyType = CKK_DES3;
29.129 + fixDESParity(encoded, 16);
29.130 + }
29.131 + break;
29.132 + case (int)CKK_AES:
29.133 + keyLength =
29.134 + P11KeyGenerator.checkKeySize(CKM_AES_KEY_GEN, n, token);
29.135 + break;
29.136 + case (int)CKK_RC4:
29.137 + keyLength =
29.138 + P11KeyGenerator.checkKeySize(CKM_RC4_KEY_GEN, n, token);
29.139 + break;
29.140 + case (int)CKK_BLOWFISH:
29.141 + keyLength =
29.142 + P11KeyGenerator.checkKeySize(CKM_BLOWFISH_KEY_GEN, n,
29.143 + token);
29.144 + break;
29.145 + case (int)CKK_GENERIC_SECRET:
29.146 + case (int)PCKK_TLSPREMASTER:
29.147 + case (int)PCKK_TLSRSAPREMASTER:
29.148 + case (int)PCKK_TLSMASTER:
29.149 + keyType = CKK_GENERIC_SECRET;
29.150 + break;
29.151 + case (int)PCKK_SSLMAC:
29.152 + case (int)PCKK_HMAC:
29.153 + if (n == 0) {
29.154 + throw new InvalidKeyException
29.155 + ("MAC keys must not be empty");
29.156 + }
29.157 + keyType = CKK_GENERIC_SECRET;
29.158 + break;
29.159 + default:
29.160 + throw new InvalidKeyException("Unknown algorithm " +
29.161 + algorithm);
29.162 }
29.163 - keyLength = n << 3;
29.164 - break;
29.165 - case (int)CKK_DES:
29.166 - if (n != 8) {
29.167 - throw new InvalidKeyException
29.168 - ("DES key length must be 8 bytes");
29.169 - }
29.170 - keyLength = 56;
29.171 - fixDESParity(encoded, 0);
29.172 - break;
29.173 - case (int)CKK_DES3:
29.174 - if (n == 16) {
29.175 - keyType = CKK_DES2;
29.176 - } else if (n == 24) {
29.177 - keyType = CKK_DES3;
29.178 - fixDESParity(encoded, 16);
29.179 - } else {
29.180 - throw new InvalidKeyException
29.181 - ("DESede key length must be 16 or 24 bytes");
29.182 - }
29.183 - fixDESParity(encoded, 0);
29.184 - fixDESParity(encoded, 8);
29.185 - keyLength = n * 7;
29.186 - break;
29.187 - case (int)CKK_AES:
29.188 - if ((n != 16) && (n != 24) && (n != 32)) {
29.189 - throw new InvalidKeyException
29.190 - ("AES key length must be 16, 24, or 32 bytes");
29.191 - }
29.192 - keyLength = n << 3;
29.193 - break;
29.194 - case (int)CKK_BLOWFISH:
29.195 - if ((n < 5) || (n > 56)) {
29.196 - throw new InvalidKeyException
29.197 - ("Blowfish key length must be between 5 and 56 bytes");
29.198 - }
29.199 - keyLength = n << 3;
29.200 - break;
29.201 - case (int)CKK_GENERIC_SECRET:
29.202 - case (int)PCKK_TLSPREMASTER:
29.203 - case (int)PCKK_TLSRSAPREMASTER:
29.204 - case (int)PCKK_TLSMASTER:
29.205 - keyType = CKK_GENERIC_SECRET;
29.206 - keyLength = n << 3;
29.207 - break;
29.208 - case (int)PCKK_SSLMAC:
29.209 - case (int)PCKK_HMAC:
29.210 - if (n == 0) {
29.211 - throw new InvalidKeyException
29.212 - ("MAC keys must not be empty");
29.213 - }
29.214 - keyType = CKK_GENERIC_SECRET;
29.215 - keyLength = n << 3;
29.216 - break;
29.217 - default:
29.218 - throw new InvalidKeyException("Unknown algorithm " + algorithm);
29.219 + } catch (InvalidAlgorithmParameterException iape) {
29.220 + throw new InvalidKeyException("Invalid key for " + algorithm,
29.221 + iape);
29.222 + } catch (ProviderException pe) {
29.223 + throw new InvalidKeyException("Could not create key", pe);
29.224 }
29.225 Session session = null;
29.226 try {
29.227 - CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
29.228 - new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
29.229 - new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType),
29.230 - new CK_ATTRIBUTE(CKA_VALUE, encoded),
29.231 - };
29.232 + CK_ATTRIBUTE[] attributes;
29.233 + if (extraAttrs != null) {
29.234 + attributes = new CK_ATTRIBUTE[3 + extraAttrs.length];
29.235 + System.arraycopy(extraAttrs, 0, attributes, 3,
29.236 + extraAttrs.length);
29.237 + } else {
29.238 + attributes = new CK_ATTRIBUTE[3];
29.239 + }
29.240 + attributes[0] = new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY);
29.241 + attributes[1] = new CK_ATTRIBUTE(CKA_KEY_TYPE, keyType);
29.242 + attributes[2] = new CK_ATTRIBUTE(CKA_VALUE, encoded);
29.243 attributes = token.getAttributes
29.244 (O_IMPORT, CKO_SECRET_KEY, keyType, attributes);
29.245 session = token.getObjSession();
29.246 @@ -280,7 +307,7 @@
29.247 private byte[] getKeyBytes(SecretKey key) throws InvalidKeySpecException {
29.248 try {
29.249 key = engineTranslateKey(key);
29.250 - if ("RAW".equals(key.getFormat()) == false) {
29.251 + if ("RAW".equalsIgnoreCase(key.getFormat()) == false) {
29.252 throw new InvalidKeySpecException
29.253 ("Could not obtain key bytes");
29.254 }
30.1 --- a/src/share/classes/sun/security/pkcs11/SunPKCS11.java Fri Apr 18 12:47:38 2008 -0700
30.2 +++ b/src/share/classes/sun/security/pkcs11/SunPKCS11.java Fri Apr 18 16:40:32 2008 -0700
30.3 @@ -1,5 +1,5 @@
30.4 /*
30.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
30.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
30.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30.8 *
30.9 * This code is free software; you can redistribute it and/or modify it
30.10 @@ -601,14 +601,26 @@
30.11 // XXX attributes for Ciphers (supported modes, padding)
30.12 d(CIP, "ARCFOUR", P11Cipher, s("RC4"),
30.13 m(CKM_RC4));
30.14 - // XXX only CBC/NoPadding for block ciphers
30.15 d(CIP, "DES/CBC/NoPadding", P11Cipher,
30.16 m(CKM_DES_CBC));
30.17 + d(CIP, "DES/CBC/PKCS5Padding", P11Cipher,
30.18 + m(CKM_DES_CBC_PAD, CKM_DES_CBC));
30.19 + d(CIP, "DES/ECB", P11Cipher, s("DES"),
30.20 + m(CKM_DES_ECB));
30.21 +
30.22 d(CIP, "DESede/CBC/NoPadding", P11Cipher,
30.23 m(CKM_DES3_CBC));
30.24 + d(CIP, "DESede/CBC/PKCS5Padding", P11Cipher,
30.25 + m(CKM_DES3_CBC_PAD, CKM_DES3_CBC));
30.26 + d(CIP, "DESede/ECB", P11Cipher, s("DESede"),
30.27 + m(CKM_DES3_ECB));
30.28 d(CIP, "AES/CBC/NoPadding", P11Cipher,
30.29 m(CKM_AES_CBC));
30.30 - d(CIP, "Blowfish/CBC/NoPadding", P11Cipher,
30.31 + d(CIP, "AES/CBC/PKCS5Padding", P11Cipher,
30.32 + m(CKM_AES_CBC_PAD, CKM_AES_CBC));
30.33 + d(CIP, "AES/ECB", P11Cipher, s("AES"),
30.34 + m(CKM_AES_ECB));
30.35 + d(CIP, "Blowfish/CBC", P11Cipher,
30.36 m(CKM_BLOWFISH_CBC));
30.37
30.38 // XXX RSA_X_509, RSA_OAEP not yet supported
31.1 --- a/src/share/classes/sun/security/validator/EndEntityChecker.java Fri Apr 18 12:47:38 2008 -0700
31.2 +++ b/src/share/classes/sun/security/validator/EndEntityChecker.java Fri Apr 18 16:40:32 2008 -0700
31.3 @@ -87,6 +87,9 @@
31.4 // the Microsoft Server-Gated-Cryptography EKU extension OID
31.5 private final static String OID_EKU_MS_SGC = "1.3.6.1.4.1.311.10.3.3";
31.6
31.7 + // the recognized extension OIDs
31.8 + private final static String OID_SUBJECT_ALT_NAME = "2.5.29.17";
31.9 +
31.10 private final static String NSCT_SSL_CLIENT =
31.11 NetscapeCertTypeExtension.SSL_CLIENT;
31.12
31.13 @@ -171,6 +174,13 @@
31.14 throws CertificateException {
31.15 // basic constraints irrelevant in EE certs
31.16 exts.remove(SimpleValidator.OID_BASIC_CONSTRAINTS);
31.17 +
31.18 + // If the subject field contains an empty sequence, the subjectAltName
31.19 + // extension MUST be marked critical.
31.20 + // We do not check the validity of the critical extension, just mark
31.21 + // it recognizable here.
31.22 + exts.remove(OID_SUBJECT_ALT_NAME);
31.23 +
31.24 if (!exts.isEmpty()) {
31.25 throw new CertificateException("Certificate contains unsupported "
31.26 + "critical extensions: " + exts);
32.1 --- a/src/share/instrument/InvocationAdapter.c Fri Apr 18 12:47:38 2008 -0700
32.2 +++ b/src/share/instrument/InvocationAdapter.c Fri Apr 18 16:40:32 2008 -0700
32.3 @@ -626,6 +626,7 @@
32.4 jvmtiError jvmtierr;
32.5
32.6 jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile);
32.7 + check_phase_ret_1(jvmtierr);
32.8
32.9 if (jvmtierr == JVMTI_ERROR_NONE) {
32.10 return 0;
32.11 @@ -634,6 +635,7 @@
32.12 jvmtiError err;
32.13
32.14 err = (*jvmtienv)->GetPhase(jvmtienv, &phase);
32.15 + /* can be called from any phase */
32.16 jplis_assert(err == JVMTI_ERROR_NONE);
32.17
32.18 if (phase == JVMTI_PHASE_LIVE) {
32.19 @@ -805,6 +807,8 @@
32.20
32.21 /* print warning if boot class path not updated */
32.22 if (jvmtierr != JVMTI_ERROR_NONE) {
32.23 + check_phase_blob_ret(jvmtierr, free(path));
32.24 +
32.25 fprintf(stderr, "WARNING: %s not added to bootstrap class loader search: ", path);
32.26 switch (jvmtierr) {
32.27 case JVMTI_ERROR_ILLEGAL_ARGUMENT :
33.1 --- a/src/share/instrument/JPLISAgent.c Fri Apr 18 12:47:38 2008 -0700
33.2 +++ b/src/share/instrument/JPLISAgent.c Fri Apr 18 16:40:32 2008 -0700
33.3 @@ -179,6 +179,7 @@
33.4 jvmtierror = (*jvmtienv)->GetEnvironmentLocalStorage(
33.5 jvmtienv,
33.6 (void**)&environment);
33.7 + /* can be called from any phase */
33.8 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.9
33.10 if (jvmtierror == JVMTI_ERROR_NONE) {
33.11 @@ -230,6 +231,7 @@
33.12 /* don't leak envs */
33.13 if ( initerror != JPLIS_INIT_ERROR_NONE ) {
33.14 jvmtiError jvmtierror = (*jvmtienv)->DisposeEnvironment(jvmtienv);
33.15 + /* can be called from any phase */
33.16 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.17 }
33.18 }
33.19 @@ -259,7 +261,7 @@
33.20 agent->mNormalEnvironment.mIsRetransformer = JNI_FALSE;
33.21 agent->mRetransformEnvironment.mJVMTIEnv = NULL; /* NULL until needed */
33.22 agent->mRetransformEnvironment.mAgent = agent;
33.23 - agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
33.24 + agent->mRetransformEnvironment.mIsRetransformer = JNI_FALSE; /* JNI_FALSE until mJVMTIEnv is set */
33.25 agent->mAgentmainCaller = NULL;
33.26 agent->mInstrumentationImpl = NULL;
33.27 agent->mPremainCaller = NULL;
33.28 @@ -277,18 +279,25 @@
33.29 jvmtierror = (*jvmtienv)->SetEnvironmentLocalStorage(
33.30 jvmtienv,
33.31 &(agent->mNormalEnvironment));
33.32 + /* can be called from any phase */
33.33 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.34
33.35 /* check what capabilities are available */
33.36 checkCapabilities(agent);
33.37
33.38 /* check phase - if live phase then we don't need the VMInit event */
33.39 - jvmtierror == (*jvmtienv)->GetPhase(jvmtienv, &phase);
33.40 + jvmtierror = (*jvmtienv)->GetPhase(jvmtienv, &phase);
33.41 + /* can be called from any phase */
33.42 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.43 if (phase == JVMTI_PHASE_LIVE) {
33.44 return JPLIS_INIT_ERROR_NONE;
33.45 }
33.46
33.47 + if (phase != JVMTI_PHASE_ONLOAD) {
33.48 + /* called too early or called too late; either way bail out */
33.49 + return JPLIS_INIT_ERROR_FAILURE;
33.50 + }
33.51 +
33.52 /* now turn on the VMInit event */
33.53 if ( jvmtierror == JVMTI_ERROR_NONE ) {
33.54 jvmtiEventCallbacks callbacks;
33.55 @@ -298,6 +307,7 @@
33.56 jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
33.57 &callbacks,
33.58 sizeof(callbacks));
33.59 + check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
33.60 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.61 }
33.62
33.63 @@ -307,6 +317,7 @@
33.64 JVMTI_ENABLE,
33.65 JVMTI_EVENT_VM_INIT,
33.66 NULL /* all threads */);
33.67 + check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
33.68 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.69 }
33.70
33.71 @@ -622,6 +633,7 @@
33.72 jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
33.73 &callbacks,
33.74 sizeof(callbacks));
33.75 + check_phase_ret_false(jvmtierror);
33.76 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.77
33.78
33.79 @@ -632,6 +644,7 @@
33.80 JVMTI_DISABLE,
33.81 JVMTI_EVENT_VM_INIT,
33.82 NULL /* all threads */);
33.83 + check_phase_ret_false(jvmtierror);
33.84 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.85 }
33.86
33.87 @@ -642,6 +655,7 @@
33.88 JVMTI_ENABLE,
33.89 JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
33.90 NULL /* all threads */);
33.91 + check_phase_ret_false(jvmtierror);
33.92 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.93 }
33.94
33.95 @@ -660,6 +674,7 @@
33.96 memset(&potentialCapabilities, 0, sizeof(potentialCapabilities));
33.97
33.98 jvmtierror = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &potentialCapabilities);
33.99 + check_phase_ret(jvmtierror);
33.100 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.101
33.102 if ( jvmtierror == JVMTI_ERROR_NONE ) {
33.103 @@ -681,9 +696,11 @@
33.104 jvmtiError jvmtierror;
33.105
33.106 jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
33.107 + /* can be called from any phase */
33.108 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.109 desiredCapabilities.can_set_native_method_prefix = 1;
33.110 jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
33.111 + check_phase_ret(jvmtierror);
33.112 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.113 }
33.114
33.115 @@ -715,9 +732,11 @@
33.116 jvmtiError jvmtierror;
33.117
33.118 jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
33.119 + /* can be called from any phase */
33.120 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.121 desiredCapabilities.can_maintain_original_method_order = 1;
33.122 jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
33.123 + check_phase_ret(jvmtierror);
33.124 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.125 }
33.126
33.127 @@ -732,9 +751,11 @@
33.128
33.129 if (agent->mRedefineAvailable && !agent->mRedefineAdded) {
33.130 jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
33.131 + /* can be called from any phase */
33.132 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.133 desiredCapabilities.can_redefine_classes = 1;
33.134 jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
33.135 + check_phase_ret(jvmtierror);
33.136
33.137 /*
33.138 * With mixed premain/agentmain agents then it's possible that the
33.139 @@ -998,6 +1019,7 @@
33.140 if (jvmtierror == JVMTI_ERROR_NONE) {
33.141 // install the retransforming environment
33.142 agent->mRetransformEnvironment.mJVMTIEnv = retransformerEnv;
33.143 + agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
33.144
33.145 // Make it for ClassFileLoadHook handling
33.146 jvmtierror = (*retransformerEnv)->SetEnvironmentLocalStorage(
33.147 @@ -1025,6 +1047,7 @@
33.148 jvmtierror = (*jvmtienv)->IsModifiableClass( jvmtienv,
33.149 clazz,
33.150 &is_modifiable);
33.151 + check_phase_ret_false(jvmtierror);
33.152 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.153
33.154 return is_modifiable;
33.155 @@ -1032,7 +1055,7 @@
33.156
33.157 jboolean
33.158 isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent) {
33.159 - return retransformableEnvironment(agent) != NULL;
33.160 + return agent->mRetransformEnvironment.mIsRetransformer;
33.161 }
33.162
33.163 void
33.164 @@ -1075,6 +1098,12 @@
33.165 numClasses = (*jnienv)->GetArrayLength(jnienv, classes);
33.166 errorOccurred = checkForThrowable(jnienv);
33.167 jplis_assert(!errorOccurred);
33.168 +
33.169 + if (!errorOccurred && numClasses == 0) {
33.170 + jplis_assert(numClasses != 0);
33.171 + errorOccurred = JNI_TRUE;
33.172 + errorCode = JVMTI_ERROR_NULL_POINTER;
33.173 + }
33.174 }
33.175
33.176 if (!errorOccurred) {
33.177 @@ -1096,6 +1125,13 @@
33.178 if (errorOccurred) {
33.179 break;
33.180 }
33.181 +
33.182 + if (classArray[index] == NULL) {
33.183 + jplis_assert(classArray[index] != NULL);
33.184 + errorOccurred = JNI_TRUE;
33.185 + errorCode = JVMTI_ERROR_NULL_POINTER;
33.186 + break;
33.187 + }
33.188 }
33.189 }
33.190
33.191 @@ -1217,6 +1253,7 @@
33.192 if (!errorOccurred) {
33.193 jvmtiError errorCode = JVMTI_ERROR_NONE;
33.194 errorCode = (*jvmtienv)->RedefineClasses(jvmtienv, numDefs, classDefs);
33.195 + check_phase_blob_ret(errorCode, deallocate(jvmtienv, (void*)classDefs));
33.196 errorOccurred = (errorCode != JVMTI_ERROR_NONE);
33.197 if ( errorOccurred ) {
33.198 createAndThrowThrowableFromJVMTIErrorCode(jnienv, errorCode);
33.199 @@ -1250,6 +1287,7 @@
33.200 classLoader,
33.201 &classCount,
33.202 &classes);
33.203 + check_phase_ret_blob(jvmtierror, localArray);
33.204 errorOccurred = (jvmtierror != JVMTI_ERROR_NONE);
33.205 jplis_assert(!errorOccurred);
33.206
33.207 @@ -1311,6 +1349,7 @@
33.208 jvmtiError jvmtierror = JVMTI_ERROR_NONE;
33.209
33.210 jvmtierror = (*jvmtienv)->GetObjectSize(jvmtienv, objectToSize, &objectSize);
33.211 + check_phase_ret_0(jvmtierror);
33.212 jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
33.213 if ( jvmtierror != JVMTI_ERROR_NONE ) {
33.214 createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
33.215 @@ -1360,6 +1399,7 @@
33.216 } else {
33.217 jvmtierror = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, platformChars);
33.218 }
33.219 + check_phase_ret(jvmtierror);
33.220
33.221 if ( jvmtierror != JVMTI_ERROR_NONE ) {
33.222 createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
33.223 @@ -1450,6 +1490,7 @@
33.224 }
33.225
33.226 err = (*jvmtienv)->SetNativeMethodPrefixes(jvmtienv, inx, (char**)prefixes);
33.227 + /* can be called from any phase */
33.228 jplis_assert(err == JVMTI_ERROR_NONE);
33.229
33.230 for (i = 0; i < inx; i++) {
34.1 --- a/src/share/instrument/JPLISAgent.h Fri Apr 18 12:47:38 2008 -0700
34.2 +++ b/src/share/instrument/JPLISAgent.h Fri Apr 18 16:40:32 2008 -0700
34.3 @@ -266,6 +266,48 @@
34.4
34.5 #define jvmti(a) a->mNormalEnvironment.mJVMTIEnv
34.6
34.7 +/*
34.8 + * A set of macros for insulating the JLI method callers from
34.9 + * JVMTI_ERROR_WRONG_PHASE return codes.
34.10 + */
34.11 +
34.12 +/* for a JLI method where "blob" is executed before simply returning */
34.13 +#define check_phase_blob_ret(ret, blob) \
34.14 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.15 + blob; \
34.16 + return; \
34.17 + }
34.18 +
34.19 +/* for a JLI method where simply returning is benign */
34.20 +#define check_phase_ret(ret) \
34.21 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.22 + return; \
34.23 + }
34.24 +
34.25 +/* for a JLI method where returning zero (0) is benign */
34.26 +#define check_phase_ret_0(ret) \
34.27 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.28 + return 0; \
34.29 + }
34.30 +
34.31 +/* for a JLI method where returning one (1) is benign */
34.32 +#define check_phase_ret_1(ret) \
34.33 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.34 + return 1; \
34.35 + }
34.36 +
34.37 +/* for a case where a specific "blob" must be returned */
34.38 +#define check_phase_ret_blob(ret, blob) \
34.39 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.40 + return (blob); \
34.41 + }
34.42 +
34.43 +/* for a JLI method where returning false is benign */
34.44 +#define check_phase_ret_false(ret) \
34.45 + if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
34.46 + return (jboolean) 0; \
34.47 + }
34.48 +
34.49 #ifdef __cplusplus
34.50 } /* extern "C" */
34.51 #endif /* __cplusplus */
35.1 --- a/src/share/instrument/JarFacade.c Fri Apr 18 12:47:38 2008 -0700
35.2 +++ b/src/share/instrument/JarFacade.c Fri Apr 18 16:40:32 2008 -0700
35.3 @@ -23,6 +23,14 @@
35.4 * have any questions.
35.5 */
35.6
35.7 +#ifdef _WIN32
35.8 +/*
35.9 + * Win* needs this include. However, Linux and Solaris do not.
35.10 + * Having this include on Solaris SPARC breaks having non US-ASCII
35.11 + * characters in the value of the Premain-Class attribute.
35.12 + */
35.13 +#include <ctype.h>
35.14 +#endif /* _WIN32 */
35.15 #include <string.h>
35.16 #include <stdlib.h>
35.17
35.18 @@ -45,11 +53,37 @@
35.19 if (attribute->name == NULL) {
35.20 free(attribute);
35.21 } else {
35.22 - attribute->value = strdup(value);
35.23 + char *begin = (char *)value;
35.24 + char *end;
35.25 + size_t value_len;
35.26 +
35.27 + /* skip any leading white space */
35.28 + while (isspace(*begin)) {
35.29 + begin++;
35.30 + }
35.31 +
35.32 + /* skip any trailing white space */
35.33 + end = &begin[strlen(begin)];
35.34 + while (end > begin && isspace(end[-1])) {
35.35 + end--;
35.36 + }
35.37 +
35.38 + if (begin == end) {
35.39 + /* no value so skip this attribute */
35.40 + free(attribute->name);
35.41 + free(attribute);
35.42 + return;
35.43 + }
35.44 +
35.45 + value_len = (size_t)(end - begin);
35.46 + attribute->value = malloc(value_len + 1);
35.47 if (attribute->value == NULL) {
35.48 free(attribute->name);
35.49 free(attribute);
35.50 } else {
35.51 + /* save the value without leading or trailing whitespace */
35.52 + strncpy(attribute->value, begin, value_len);
35.53 + attribute->value[value_len] = '\0';
35.54 attribute->next = NULL;
35.55 if (context->head == NULL) {
35.56 context->head = attribute;
36.1 --- a/src/share/instrument/Reentrancy.c Fri Apr 18 12:47:38 2008 -0700
36.2 +++ b/src/share/instrument/Reentrancy.c Fri Apr 18 16:40:32 2008 -0700
36.3 @@ -74,6 +74,7 @@
36.4 jvmtienv,
36.5 thread,
36.6 newValue);
36.7 + check_phase_ret_blob(error, error);
36.8
36.9 #if JPLISASSERT_ENABLEASSERTIONS
36.10 assertTLSValue( jvmtienv,
36.11 @@ -96,6 +97,7 @@
36.12 jvmtienv,
36.13 thread,
36.14 &test);
36.15 + check_phase_ret(error);
36.16 jplis_assert(error == JVMTI_ERROR_NONE);
36.17 jplis_assert(test == expected);
36.18 }
36.19 @@ -111,6 +113,7 @@
36.20 jvmtienv,
36.21 thread,
36.22 &storedValue);
36.23 + check_phase_ret_false(error);
36.24 jplis_assert(error == JVMTI_ERROR_NONE);
36.25 if ( error == JVMTI_ERROR_NONE ) {
36.26 /* if this thread is already inside, just return false and short-circuit */
37.1 --- a/src/share/instrument/Utilities.c Fri Apr 18 12:47:38 2008 -0700
37.2 +++ b/src/share/instrument/Utilities.c Fri Apr 18 16:40:32 2008 -0700
37.3 @@ -46,6 +46,7 @@
37.4 error = (*jvmtienv)->Allocate(jvmtienv,
37.5 bytecount,
37.6 (unsigned char**) &resultBuffer);
37.7 + /* may be called from any phase */
37.8 jplis_assert(error == JVMTI_ERROR_NONE);
37.9 if ( error != JVMTI_ERROR_NONE ) {
37.10 resultBuffer = NULL;
37.11 @@ -66,6 +67,7 @@
37.12
37.13 error = (*jvmtienv)->Deallocate(jvmtienv,
37.14 (unsigned char*)buffer);
37.15 + /* may be called from any phase */
37.16 jplis_assert_msg(error == JVMTI_ERROR_NONE, "Can't deallocate memory");
37.17 return;
37.18 }
38.1 --- a/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Fri Apr 18 12:47:38 2008 -0700
38.2 +++ b/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Fri Apr 18 16:40:32 2008 -0700
38.3 @@ -123,7 +123,10 @@
38.4 C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule, getFunctionListStr);
38.5 (*env)->ReleaseStringUTFChars(env, jGetFunctionList, getFunctionListStr);
38.6 }
38.7 - if ((C_GetFunctionList == NULL) || ((systemErrorMessage = dlerror()) != NULL)){
38.8 + if (C_GetFunctionList == NULL) {
38.9 + throwIOException(env, "ERROR: C_GetFunctionList == NULL");
38.10 + return;
38.11 + } else if ( (systemErrorMessage = dlerror()) != NULL ){
38.12 throwIOException(env, systemErrorMessage);
38.13 return;
38.14 }
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticOptions.java Fri Apr 18 16:40:32 2008 -0700
39.3 @@ -0,0 +1,61 @@
39.4 +/*
39.5 + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.7 + *
39.8 + * This code is free software; you can redistribute it and/or modify it
39.9 + * under the terms of the GNU General Public License version 2 only, as
39.10 + * published by the Free Software Foundation.
39.11 + *
39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.15 + * version 2 for more details (a copy is included in the LICENSE file that
39.16 + * accompanied this code).
39.17 + *
39.18 + * You should have received a copy of the GNU General Public License version
39.19 + * 2 along with this work; if not, write to the Free Software Foundation,
39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.21 + *
39.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
39.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
39.24 + * have any questions.
39.25 + */
39.26 +
39.27 +/*
39.28 + * @test
39.29 + * @bug 6658779
39.30 + * @summary Basic Test for HotSpotDiagnosticMXBean.getDiagnosticOptions()
39.31 + * @author Daniel Fuchs
39.32 + *
39.33 + * @run main GetDiagnosticOptions
39.34 + */
39.35 +
39.36 +import com.sun.management.HotSpotDiagnosticMXBean;
39.37 +import com.sun.management.VMOption;
39.38 +import java.lang.management.ManagementFactory;
39.39 +import java.util.List;
39.40 +import javax.management.MBeanServer;
39.41 +
39.42 +public class GetDiagnosticOptions {
39.43 + private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
39.44 + "com.sun.management:type=HotSpotDiagnostic";
39.45 +
39.46 + public static void main(String[] args) throws Exception {
39.47 + HotSpotDiagnosticMXBean mbean =
39.48 + sun.management.ManagementFactory.getDiagnosticMXBean();
39.49 + checkDiagnosticOptions(mbean);
39.50 +
39.51 + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
39.52 + mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
39.53 + HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
39.54 + HotSpotDiagnosticMXBean.class);
39.55 + checkDiagnosticOptions(mbean);
39.56 + }
39.57 +
39.58 + private static void checkDiagnosticOptions(HotSpotDiagnosticMXBean mbean) {
39.59 + List<VMOption> options = mbean.getDiagnosticOptions();
39.60 + for (VMOption opt : options) {
39.61 + System.out.println("option: "+opt.getName()+"="+opt.getValue());
39.62 + }
39.63 + }
39.64 +}
40.1 --- a/test/java/lang/instrument/BootClassPath/BootClassPathTest.sh Fri Apr 18 12:47:38 2008 -0700
40.2 +++ b/test/java/lang/instrument/BootClassPath/BootClassPathTest.sh Fri Apr 18 16:40:32 2008 -0700
40.3 @@ -23,8 +23,10 @@
40.4
40.5 # @test
40.6 # @bug 5055293
40.7 -# @summary Test non US-ASCII characters in the value of the Boot-Class-Path
40.8 +# @summary Test non US-ASCII characters in the value of the Boot-Class-Path
40.9 # attribute.
40.10 +#
40.11 +# @run shell/timeout=240 BootClassPathTest.sh
40.12
40.13 if [ "${TESTJAVA}" = "" ]
40.14 then
40.15 @@ -72,7 +74,7 @@
40.16
40.17 echo "Running test..."
40.18
40.19 -"${JAVA}" -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
40.20 +"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
40.21 result=$?
40.22
40.23 echo "Cleanup..."
41.1 --- a/test/java/lang/instrument/MakeJAR2.sh Fri Apr 18 12:47:38 2008 -0700
41.2 +++ b/test/java/lang/instrument/MakeJAR2.sh Fri Apr 18 16:40:32 2008 -0700
41.3 @@ -70,9 +70,11 @@
41.4 cp ${TESTSRC}/${AGENT}.java .
41.5 cp ${TESTSRC}/${APP}.java .
41.6 rm -rf ilib
41.7 -cp -r ${TESTSRC}/ilib .
41.8 -mkdir bootpath
41.9 -cp -r ${TESTSRC}/bootreporter bootpath
41.10 +mkdir ilib
41.11 +cp ${TESTSRC}/ilib/*.java ilib
41.12 +rm -rf bootpath
41.13 +mkdir -p bootpath/bootreporter
41.14 +cp ${TESTSRC}/bootreporter/*.java bootpath/bootreporter
41.15
41.16 cd bootpath
41.17 ${JAVAC} bootreporter/*.java
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/test/java/lang/instrument/ManifestTest.sh Fri Apr 18 16:40:32 2008 -0700
42.3 @@ -0,0 +1,483 @@
42.4 +#
42.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
42.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42.7 +#
42.8 +# This code is free software; you can redistribute it and/or modify it
42.9 +# under the terms of the GNU General Public License version 2 only, as
42.10 +# published by the Free Software Foundation.
42.11 +#
42.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
42.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42.15 +# version 2 for more details (a copy is included in the LICENSE file that
42.16 +# accompanied this code).
42.17 +#
42.18 +# You should have received a copy of the GNU General Public License version
42.19 +# 2 along with this work; if not, write to the Free Software Foundation,
42.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42.21 +#
42.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
42.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
42.24 +# have any questions.
42.25 +#
42.26 +
42.27 +# @test
42.28 +# @bug 6274276
42.29 +# @summary JLI JAR manifest processing should ignore leading and trailing white space.
42.30 +# @author Daniel D. Daugherty
42.31 +#
42.32 +# @run build ManifestTestApp
42.33 +# @run shell/timeout=900 ManifestTest.sh
42.34 +#
42.35 +
42.36 +make_a_JAR() {
42.37 + # version_line and premain_line are required
42.38 + version_line="Manifest-Version: 1.0"
42.39 + premain_line="Premain-Class: ${AGENT}"
42.40 + boot_cp_line=""
42.41 + expect_boot_cp_line="ExampleForBootClassPath was not loaded."
42.42 + can_redef_line=""
42.43 + expect_redef_line="isRedefineClassesSupported()=false"
42.44 + can_retrans_line=""
42.45 + expect_retrans_line="isRetransformClassesSupported()=false"
42.46 + can_set_nmp_line=""
42.47 + expect_set_nmp_line="isNativeMethodPrefixSupported()=false"
42.48 +
42.49 + while [ $# != 0 ] ; do
42.50 + case "$1" in
42.51 + defaults)
42.52 + # just use the defaults for the test
42.53 + ;;
42.54 +
42.55 + boot_cp_line1)
42.56 + boot_cp_line="Boot-Class-Path: no_white_space"
42.57 + expect_boot_cp_line="ExampleForBootClassPath was loaded."
42.58 + mkdir -p no_white_space
42.59 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space
42.60 + ;;
42.61 +
42.62 + boot_cp_line2)
42.63 + boot_cp_line="Boot-Class-Path: has_leading_blank"
42.64 + expect_boot_cp_line="ExampleForBootClassPath was loaded."
42.65 + mkdir -p has_leading_blank " has_leading_blank"
42.66 + # the good class is in the directory without the blank
42.67 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
42.68 + has_leading_blank
42.69 + # the bad class is in the directory with the blank
42.70 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
42.71 + " has_leading_blank"/ExampleForBootClassPath.class
42.72 + ;;
42.73 +
42.74 + boot_cp_line3)
42.75 + boot_cp_line="Boot-Class-Path: has_trailing_blank "
42.76 + expect_boot_cp_line="ExampleForBootClassPath was loaded."
42.77 + mkdir -p has_trailing_blank "has_trailing_blank "
42.78 + # the good class is in the directory without the blank
42.79 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
42.80 + has_trailing_blank
42.81 + # the bad class is in the directory with the blank
42.82 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
42.83 + "has_trailing_blank "/ExampleForBootClassPath.class
42.84 + ;;
42.85 +
42.86 + boot_cp_line4)
42.87 + boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank "
42.88 + expect_boot_cp_line="ExampleForBootClassPath was loaded."
42.89 + mkdir -p has_leading_and_trailing_blank \
42.90 + " has_leading_and_trailing_blank "
42.91 + # the good class is in the directory without the blanks
42.92 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
42.93 + has_leading_and_trailing_blank
42.94 + # the bad class is in the directory with the blanks
42.95 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
42.96 + " has_leading_and_trailing_blank "/ExampleForBootClassPath.class
42.97 + ;;
42.98 +
42.99 + boot_cp_line5)
42.100 + boot_cp_line="Boot-Class-Path: has_embedded blank"
42.101 + expect_boot_cp_line="ExampleForBootClassPath was loaded."
42.102 + mkdir -p has_embedded "has_embedded blank"
42.103 + # the good class is in the first blank separated word
42.104 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded
42.105 + # the bad class is in the directory with the blank
42.106 + cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
42.107 + "has_embedded blank"/ExampleForBootClassPath.class
42.108 + ;;
42.109 +
42.110 + can_redef_line1)
42.111 + can_redef_line="Can-Redefine-Classes: true"
42.112 + expect_redef_line="isRedefineClassesSupported()=true"
42.113 + ;;
42.114 +
42.115 + can_redef_line2)
42.116 + can_redef_line="Can-Redefine-Classes: true"
42.117 + expect_redef_line="isRedefineClassesSupported()=true"
42.118 + ;;
42.119 +
42.120 + can_redef_line3)
42.121 + can_redef_line="Can-Redefine-Classes: true "
42.122 + expect_redef_line="isRedefineClassesSupported()=true"
42.123 + ;;
42.124 +
42.125 + can_redef_line4)
42.126 + can_redef_line="Can-Redefine-Classes: true "
42.127 + expect_redef_line="isRedefineClassesSupported()=true"
42.128 + ;;
42.129 +
42.130 + can_redef_line5)
42.131 + can_redef_line="Can-Redefine-Classes: false"
42.132 + ;;
42.133 +
42.134 + can_redef_line6)
42.135 + can_redef_line="Can-Redefine-Classes: false"
42.136 + ;;
42.137 +
42.138 + can_redef_line7)
42.139 + can_redef_line="Can-Redefine-Classes: false "
42.140 + ;;
42.141 +
42.142 + can_redef_line8)
42.143 + can_redef_line="Can-Redefine-Classes: false "
42.144 + ;;
42.145 +
42.146 + can_redef_line9)
42.147 + # this line makes the jar command unhappy and that's
42.148 + # not what we're testing so skip this case
42.149 + can_redef_line="Can-Redefine-Classes:"
42.150 + ;;
42.151 +
42.152 + can_redef_line10)
42.153 + can_redef_line="Can-Redefine-Classes: "
42.154 + ;;
42.155 +
42.156 + can_redef_line11)
42.157 + can_redef_line="Can-Redefine-Classes: "
42.158 + ;;
42.159 +
42.160 + can_retrans_line1)
42.161 + can_retrans_line="Can-Retransform-Classes: true"
42.162 + expect_retrans_line="isRetransformClassesSupported()=true"
42.163 + ;;
42.164 +
42.165 + can_retrans_line2)
42.166 + can_retrans_line="Can-Retransform-Classes: true"
42.167 + expect_retrans_line="isRetransformClassesSupported()=true"
42.168 + ;;
42.169 +
42.170 + can_retrans_line3)
42.171 + can_retrans_line="Can-Retransform-Classes: true "
42.172 + expect_retrans_line="isRetransformClassesSupported()=true"
42.173 + ;;
42.174 +
42.175 + can_retrans_line4)
42.176 + can_retrans_line="Can-Retransform-Classes: true "
42.177 + expect_retrans_line="isRetransformClassesSupported()=true"
42.178 + ;;
42.179 +
42.180 + can_retrans_line5)
42.181 + can_retrans_line="Can-Retransform-Classes: false"
42.182 + ;;
42.183 +
42.184 + can_retrans_line6)
42.185 + can_retrans_line="Can-Retransform-Classes: false"
42.186 + ;;
42.187 +
42.188 + can_retrans_line7)
42.189 + can_retrans_line="Can-Retransform-Classes: false "
42.190 + ;;
42.191 +
42.192 + can_retrans_line8)
42.193 + can_retrans_line="Can-Retransform-Classes: false "
42.194 + ;;
42.195 +
42.196 + can_retrans_line9)
42.197 + # this line makes the jar command unhappy and that's
42.198 + # not what we're testing so skip this case
42.199 + can_retrans_line="Can-Retransform-Classes:"
42.200 + ;;
42.201 +
42.202 + can_retrans_line10)
42.203 + can_retrans_line="Can-Retransform-Classes: "
42.204 + ;;
42.205 +
42.206 + can_retrans_line11)
42.207 + can_retrans_line="Can-Retransform-Classes: "
42.208 + ;;
42.209 +
42.210 + can_set_nmp_line1)
42.211 + can_set_nmp_line="Can-Set-Native-Method-Prefix: true"
42.212 + expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
42.213 + ;;
42.214 +
42.215 + can_set_nmp_line2)
42.216 + can_set_nmp_line="Can-Set-Native-Method-Prefix: true"
42.217 + expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
42.218 + ;;
42.219 +
42.220 + can_set_nmp_line3)
42.221 + can_set_nmp_line="Can-Set-Native-Method-Prefix: true "
42.222 + expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
42.223 + ;;
42.224 +
42.225 + can_set_nmp_line4)
42.226 + can_set_nmp_line="Can-Set-Native-Method-Prefix: true "
42.227 + expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
42.228 + ;;
42.229 +
42.230 + can_set_nmp_line5)
42.231 + can_set_nmp_line="Can-Set-Native-Method-Prefix: false"
42.232 + ;;
42.233 +
42.234 + can_set_nmp_line6)
42.235 + can_set_nmp_line="Can-Set-Native-Method-Prefix: false"
42.236 + ;;
42.237 +
42.238 + can_set_nmp_line7)
42.239 + can_set_nmp_line="Can-Set-Native-Method-Prefix: false "
42.240 + ;;
42.241 +
42.242 + can_set_nmp_line8)
42.243 + can_set_nmp_line="Can-Set-Native-Method-Prefix: false "
42.244 + ;;
42.245 +
42.246 + can_set_nmp_line9)
42.247 + # this line makes the jar command unhappy and that's
42.248 + # not what we're testing so skip this case
42.249 + can_set_nmp_line="Can-Set-Native-Method-Prefix:"
42.250 + ;;
42.251 +
42.252 + can_set_nmp_line10)
42.253 + can_set_nmp_line="Can-Set-Native-Method-Prefix: "
42.254 + ;;
42.255 +
42.256 + can_set_nmp_line11)
42.257 + can_set_nmp_line="Can-Set-Native-Method-Prefix: "
42.258 + ;;
42.259 +
42.260 + premain_line1)
42.261 + premain_line="Premain-Class: ${AGENT}"
42.262 + ;;
42.263 +
42.264 + premain_line2)
42.265 + premain_line="Premain-Class: ${AGENT} "
42.266 + ;;
42.267 +
42.268 + premain_line3)
42.269 + premain_line="Premain-Class: ${AGENT} "
42.270 + ;;
42.271 +
42.272 + version_line1)
42.273 + version_line="Manifest-Version: 1.0"
42.274 + ;;
42.275 +
42.276 + version_line2)
42.277 + version_line="Manifest-Version: 1.0 "
42.278 + ;;
42.279 +
42.280 + version_line3)
42.281 + version_line="Manifest-Version: 1.0 "
42.282 + ;;
42.283 +
42.284 + *)
42.285 + echo "ERROR: invalid test token"
42.286 + exit 1
42.287 + esac
42.288 + shift
42.289 + done
42.290 +
42.291 + echo "${version_line}" > ${AGENT}.mf
42.292 + echo "${premain_line}" >> ${AGENT}.mf
42.293 +
42.294 + if [ -n "$boot_cp_line" ]; then
42.295 + echo "${boot_cp_line}" >> ${AGENT}.mf
42.296 + fi
42.297 +
42.298 + if [ -n "$can_redef_line" ]; then
42.299 + echo "${can_redef_line}" >> ${AGENT}.mf
42.300 + fi
42.301 +
42.302 + if [ -n "$can_retrans_line" ]; then
42.303 + echo "${can_retrans_line}" >> ${AGENT}.mf
42.304 + fi
42.305 +
42.306 + if [ -n "$can_set_nmp_line" ]; then
42.307 + echo "${can_set_nmp_line}" >> ${AGENT}.mf
42.308 + fi
42.309 +
42.310 + rm -f ${AGENT}.jar
42.311 + ${JAR} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class
42.312 +
42.313 + echo "$expect_boot_cp_line" > expect_boot_cp_line
42.314 + echo "$expect_redef_line" > expect_redef_line
42.315 + echo "$expect_retrans_line" > expect_retrans_line
42.316 + echo "$expect_set_nmp_line" > expect_set_nmp_line
42.317 +}
42.318 +
42.319 +if [ "${TESTJAVA}" = "" ]
42.320 +then
42.321 + echo "TESTJAVA not set. Test cannot execute. Failed."
42.322 + exit 1
42.323 +fi
42.324 +
42.325 +if [ "${TESTSRC}" = "" ]
42.326 +then
42.327 + echo "TESTSRC not set. Test cannot execute. Failed."
42.328 + exit 1
42.329 +fi
42.330 +
42.331 +if [ "${TESTCLASSES}" = "" ]
42.332 +then
42.333 + echo "TESTCLASSES not set. Test cannot execute. Failed."
42.334 + exit 1
42.335 +fi
42.336 +
42.337 +JAR="${TESTJAVA}/bin/jar"
42.338 +JAVAC="${TESTJAVA}"/bin/javac
42.339 +JAVA="${TESTJAVA}"/bin/java
42.340 +
42.341 +# Now that ManifestTestApp.class is built, we move
42.342 +# ExampleForBootClassPath.class so that it cannot be found
42.343 +# by default
42.344 +OUT_OF_THE_WAY=out_of_the_way
42.345 +mkdir $OUT_OF_THE_WAY
42.346 +mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY
42.347 +
42.348 +# create a bad version of ExampleForBootClassPath.class
42.349 +# so we can tell when the wrong version is run
42.350 +sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \
42.351 + > ExampleForBootClassPath.java
42.352 +"$JAVAC" ExampleForBootClassPath.java
42.353 +mv ExampleForBootClassPath.class \
42.354 + $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad
42.355 +mv ExampleForBootClassPath.java \
42.356 + $OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad
42.357 +
42.358 +AGENT=ManifestTestAgent
42.359 +# We compile the agent in the working directory instead of with
42.360 +# a build task because we construct a different agent JAR file
42.361 +# for each test case.
42.362 +${JAVAC} -d . ${TESTSRC}/${AGENT}.java
42.363 +
42.364 +FAIL_MARKER=fail_marker
42.365 +rm -f $FAIL_MARKER
42.366 +
42.367 +while read token; do
42.368 + echo
42.369 + echo "===== begin test case: $token ====="
42.370 + make_a_JAR "$token"
42.371 +
42.372 + "${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \
42.373 + -classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1
42.374 + result=$?
42.375 +
42.376 + cat output.log
42.377 +
42.378 + if [ "$result" = 0 ]; then
42.379 + echo "PASS: ManifestTestApp exited with status of 0."
42.380 + else
42.381 + echo "FAIL: ManifestTestApp exited with status of $result"
42.382 + touch $FAIL_MARKER
42.383 + fi
42.384 +
42.385 + MESG="Hello from ${AGENT}!"
42.386 + grep -s "$MESG" output.log > /dev/null
42.387 + result=$?
42.388 + if [ "$result" = 0 ]; then
42.389 + echo "PASS: found '$MESG' in the test output"
42.390 + else
42.391 + echo "FAIL: did NOT find '$MESG' in the test output"
42.392 + touch $FAIL_MARKER
42.393 + fi
42.394 +
42.395 + MESG=`cat expect_boot_cp_line`
42.396 + grep -s "$MESG" output.log > /dev/null
42.397 + result=$?
42.398 + if [ "$result" = 0 ]; then
42.399 + echo "PASS: found '$MESG' in the test output"
42.400 + else
42.401 + echo "FAIL: did NOT find '$MESG' in the test output"
42.402 + touch $FAIL_MARKER
42.403 + fi
42.404 +
42.405 + MESG=`cat expect_redef_line`
42.406 + grep -s "$MESG" output.log > /dev/null
42.407 + result=$?
42.408 + if [ "$result" = 0 ]; then
42.409 + echo "PASS: found '$MESG' in the test output"
42.410 + else
42.411 + echo "FAIL: did NOT find '$MESG' in the test output"
42.412 + touch $FAIL_MARKER
42.413 + fi
42.414 +
42.415 + MESG=`cat expect_retrans_line`
42.416 + grep -s "$MESG" output.log > /dev/null
42.417 + result=$?
42.418 + if [ "$result" = 0 ]; then
42.419 + echo "PASS: found '$MESG' in the test output"
42.420 + else
42.421 + echo "FAIL: did NOT find '$MESG' in the test output"
42.422 + touch $FAIL_MARKER
42.423 + fi
42.424 +
42.425 + MESG=`cat expect_set_nmp_line`
42.426 + grep -s "$MESG" output.log > /dev/null
42.427 + result=$?
42.428 + if [ "$result" = 0 ]; then
42.429 + echo "PASS: found '$MESG' in the test output"
42.430 + else
42.431 + echo "FAIL: did NOT find '$MESG' in the test output"
42.432 + touch $FAIL_MARKER
42.433 + fi
42.434 +
42.435 + echo "===== end test case: $token ====="
42.436 + echo
42.437 +done << EOF
42.438 +defaults
42.439 +version_line1
42.440 +version_line2
42.441 +version_line3
42.442 +premain_line1
42.443 +premain_line2
42.444 +premain_line3
42.445 +boot_cp_line1
42.446 +boot_cp_line2
42.447 +boot_cp_line3
42.448 +boot_cp_line4
42.449 +boot_cp_line5
42.450 +can_redef_line1
42.451 +can_redef_line2
42.452 +can_redef_line3
42.453 +can_redef_line4
42.454 +can_redef_line5
42.455 +can_redef_line6
42.456 +can_redef_line7
42.457 +can_redef_line8
42.458 +can_redef_line10
42.459 +can_redef_line11
42.460 +can_retrans_line1
42.461 +can_retrans_line2
42.462 +can_retrans_line3
42.463 +can_retrans_line4
42.464 +can_retrans_line5
42.465 +can_retrans_line6
42.466 +can_retrans_line7
42.467 +can_retrans_line8
42.468 +can_retrans_line10
42.469 +can_retrans_line11
42.470 +can_set_nmp_line1
42.471 +can_set_nmp_line2
42.472 +can_set_nmp_line3
42.473 +can_set_nmp_line4
42.474 +can_set_nmp_line5
42.475 +can_set_nmp_line6
42.476 +can_set_nmp_line7
42.477 +can_set_nmp_line8
42.478 +can_set_nmp_line10
42.479 +can_set_nmp_line11
42.480 +EOF
42.481 +
42.482 +if [ -f $FAIL_MARKER ]; then
42.483 + exit 1
42.484 +else
42.485 + exit 0
42.486 +fi
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/test/java/lang/instrument/ManifestTestAgent.java Fri Apr 18 16:40:32 2008 -0700
43.3 @@ -0,0 +1,41 @@
43.4 +/*
43.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43.7 + *
43.8 + * This code is free software; you can redistribute it and/or modify it
43.9 + * under the terms of the GNU General Public License version 2 only, as
43.10 + * published by the Free Software Foundation.
43.11 + *
43.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
43.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43.15 + * version 2 for more details (a copy is included in the LICENSE file that
43.16 + * accompanied this code).
43.17 + *
43.18 + * You should have received a copy of the GNU General Public License version
43.19 + * 2 along with this work; if not, write to the Free Software Foundation,
43.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43.21 + *
43.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
43.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
43.24 + * have any questions.
43.25 + */
43.26 +
43.27 +import java.lang.instrument.Instrumentation;
43.28 +
43.29 +public class ManifestTestAgent {
43.30 + private static Instrumentation instrumentation;
43.31 +
43.32 + private ManifestTestAgent() {
43.33 + }
43.34 +
43.35 + public static void premain(String agentArgs, Instrumentation inst) {
43.36 + System.out.println("Hello from ManifestTestAgent!");
43.37 + System.out.println("isNativeMethodPrefixSupported()=" +
43.38 + inst.isNativeMethodPrefixSupported());
43.39 + System.out.println("isRedefineClassesSupported()=" +
43.40 + inst.isRedefineClassesSupported());
43.41 + System.out.println("isRetransformClassesSupported()=" +
43.42 + inst.isRetransformClassesSupported());
43.43 + }
43.44 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/test/java/lang/instrument/ManifestTestApp.java Fri Apr 18 16:40:32 2008 -0700
44.3 @@ -0,0 +1,69 @@
44.4 +/*
44.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44.7 + *
44.8 + * This code is free software; you can redistribute it and/or modify it
44.9 + * under the terms of the GNU General Public License version 2 only, as
44.10 + * published by the Free Software Foundation.
44.11 + *
44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44.15 + * version 2 for more details (a copy is included in the LICENSE file that
44.16 + * accompanied this code).
44.17 + *
44.18 + * You should have received a copy of the GNU General Public License version
44.19 + * 2 along with this work; if not, write to the Free Software Foundation,
44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44.21 + *
44.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
44.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
44.24 + * have any questions.
44.25 + */
44.26 +
44.27 +public class ManifestTestApp {
44.28 + public static void main(String args[]) {
44.29 + System.out.println("Hello from ManifestTestApp!");
44.30 +
44.31 + new ManifestTestApp().doTest();
44.32 + System.exit(0);
44.33 + }
44.34 +
44.35 + private void doTest() {
44.36 + try {
44.37 + // load the class only found via the Boot-Class-Path attribute
44.38 + Object instance = loadExampleClass();
44.39 + if (instance.getClass().getClassLoader() == null) {
44.40 + System.out.println("PASS: ExampleForBootClassPath was loaded" +
44.41 + " by the boot class path loader.");
44.42 + } else {
44.43 + System.out.println("FAIL: ExampleForBootClassPath was loaded" +
44.44 + " by a non-boot class path loader.");
44.45 + System.exit(1);
44.46 + }
44.47 + } catch (NoClassDefFoundError ncdfe) {
44.48 + // This message just lets ManifestTest.sh know whether or
44.49 + // not ExampleForBootClassPath was loaded. Depending on
44.50 + // the current test case, that will be either a PASSing
44.51 + // condition or a FAILing condition as determined by
44.52 + // ManifestTest.sh.
44.53 + System.out.println("ExampleForBootClassPath was not loaded.");
44.54 + }
44.55 + }
44.56 +
44.57 + Object loadExampleClass() {
44.58 + ExampleForBootClassPath instance = new ExampleForBootClassPath();
44.59 + System.out.println("ExampleForBootClassPath was loaded.");
44.60 + if (instance.fifteen() == 15) {
44.61 + System.out.println("PASS: the correct" +
44.62 + " ExampleForBootClassPath was loaded.");
44.63 + } else {
44.64 + System.out.println("FAIL: the wrong ExampleForBootClassPath" +
44.65 + " was loaded.");
44.66 + System.out.println("FAIL: instance.fifteen()=" +
44.67 + instance.fifteen());
44.68 + System.exit(1);
44.69 + }
44.70 + return instance;
44.71 + }
44.72 +}
45.1 --- a/test/java/lang/instrument/NativeMethodPrefixAgent.java Fri Apr 18 12:47:38 2008 -0700
45.2 +++ b/test/java/lang/instrument/NativeMethodPrefixAgent.java Fri Apr 18 16:40:32 2008 -0700
45.3 @@ -27,7 +27,7 @@
45.4 * @summary test setNativeMethodPrefix
45.5 * @author Robert Field, Sun Microsystems
45.6 *
45.7 - * @run shell MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
45.8 + * @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
45.9 * @run main/othervm -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp
45.10 */
45.11
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/test/java/lang/instrument/ParallelTransformerLoader.sh Fri Apr 18 16:40:32 2008 -0700
46.3 @@ -0,0 +1,72 @@
46.4 +#
46.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
46.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46.7 +#
46.8 +# This code is free software; you can redistribute it and/or modify it
46.9 +# under the terms of the GNU General Public License version 2 only, as
46.10 +# published by the Free Software Foundation.
46.11 +#
46.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
46.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46.15 +# version 2 for more details (a copy is included in the LICENSE file that
46.16 +# accompanied this code).
46.17 +#
46.18 +# You should have received a copy of the GNU General Public License version
46.19 +# 2 along with this work; if not, write to the Free Software Foundation,
46.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46.21 +#
46.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
46.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
46.24 +# have any questions.
46.25 +#
46.26 +
46.27 +# @test
46.28 +# @bug 5088398
46.29 +# @summary Test parallel class loading by parallel transformers.
46.30 +# @author Daniel D. Daugherty as modified from the code of Daryl Puryear @ Wily
46.31 +#
46.32 +# @run shell MakeJAR3.sh ParallelTransformerLoaderAgent
46.33 +# @run build ParallelTransformerLoaderApp
46.34 +# @run shell/timeout=240 ParallelTransformerLoader.sh
46.35 +#
46.36 +
46.37 +if [ "${TESTJAVA}" = "" ]
46.38 +then
46.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
46.40 + exit 1
46.41 +fi
46.42 +
46.43 +if [ "${TESTSRC}" = "" ]
46.44 +then
46.45 + echo "TESTSRC not set. Test cannot execute. Failed."
46.46 + exit 1
46.47 +fi
46.48 +
46.49 +if [ "${TESTCLASSES}" = "" ]
46.50 +then
46.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
46.52 + exit 1
46.53 +fi
46.54 +
46.55 +JAR="${TESTJAVA}"/bin/jar
46.56 +JAVAC="${TESTJAVA}"/bin/javac
46.57 +JAVA="${TESTJAVA}"/bin/java
46.58 +
46.59 +"${JAVAC}" -d . \
46.60 + "${TESTSRC}"/TestClass1.java \
46.61 + "${TESTSRC}"/TestClass2.java \
46.62 + "${TESTSRC}"/TestClass3.java
46.63 +
46.64 +"${JAR}" cvf Test.jar Test*.class
46.65 +# Removing the test class files is important. If these
46.66 +# .class files are available on the classpath other
46.67 +# than via Test.jar, then the deadlock will not reproduce.
46.68 +rm -f Test*.class
46.69 +
46.70 +"${JAVA}" ${TESTVMOPTS} -javaagent:ParallelTransformerLoaderAgent.jar=Test.jar \
46.71 + -classpath "${TESTCLASSES}" ParallelTransformerLoaderApp
46.72 +result=$?
46.73 +echo "result=$result"
46.74 +
46.75 +exit $result
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
47.2 +++ b/test/java/lang/instrument/ParallelTransformerLoaderAgent.java Fri Apr 18 16:40:32 2008 -0700
47.3 @@ -0,0 +1,120 @@
47.4 +/*
47.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47.7 + *
47.8 + * This code is free software; you can redistribute it and/or modify it
47.9 + * under the terms of the GNU General Public License version 2 only, as
47.10 + * published by the Free Software Foundation.
47.11 + *
47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
47.15 + * version 2 for more details (a copy is included in the LICENSE file that
47.16 + * accompanied this code).
47.17 + *
47.18 + * You should have received a copy of the GNU General Public License version
47.19 + * 2 along with this work; if not, write to the Free Software Foundation,
47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47.21 + *
47.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
47.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
47.24 + * have any questions.
47.25 + */
47.26 +
47.27 +import java.lang.instrument.*;
47.28 +import java.net.*;
47.29 +import java.io.*;
47.30 +import java.security.*;
47.31 +
47.32 +/**
47.33 + * Test Java Agent
47.34 + *
47.35 + * @author Daryl Puryear
47.36 + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
47.37 + */
47.38 +public class ParallelTransformerLoaderAgent
47.39 +{
47.40 + private static URL sURL;
47.41 + private static ClassLoader sClassLoader;
47.42 +
47.43 + public static synchronized ClassLoader
47.44 + getClassLoader()
47.45 + {
47.46 + return sClassLoader;
47.47 + }
47.48 +
47.49 + public static synchronized void
47.50 + generateNewClassLoader()
47.51 + {
47.52 + sClassLoader = new URLClassLoader(new URL[] {sURL});
47.53 + }
47.54 +
47.55 + public static void
47.56 + premain( String agentArgs,
47.57 + Instrumentation instrumentation)
47.58 + throws Exception
47.59 + {
47.60 + if (agentArgs == null || agentArgs == "")
47.61 + {
47.62 + System.err.println("Error: No jar file name provided, test will not run.");
47.63 + return;
47.64 + }
47.65 +
47.66 + sURL = (new File(agentArgs)).toURL();
47.67 + System.out.println("Using jar file: " + sURL);
47.68 + generateNewClassLoader();
47.69 +
47.70 + instrumentation.addTransformer(new TestTransformer());
47.71 + }
47.72 +
47.73 + private static class TestTransformer
47.74 + implements ClassFileTransformer
47.75 + {
47.76 + public byte[]
47.77 + transform( ClassLoader loader,
47.78 + String className,
47.79 + Class classBeingRedefined,
47.80 + ProtectionDomain protectionDomain,
47.81 + byte[] classfileBuffer)
47.82 + throws IllegalClassFormatException
47.83 + {
47.84 + String tName = Thread.currentThread().getName();
47.85 + // In 160_03 and older, transform() is called
47.86 + // with the "system_loader_lock" held and that
47.87 + // prevents the bootstrap class loaded from
47.88 + // running in parallel. If we add a slight sleep
47.89 + // delay here when the transform() call is not
47.90 + // main or TestThread, then the deadlock in
47.91 + // 160_03 and older is much more reproducible.
47.92 + if (!tName.equals("main") && !tName.equals("TestThread")) {
47.93 + System.out.println("Thread '" + tName +
47.94 + "' has called transform()");
47.95 + try {
47.96 + Thread.sleep(500);
47.97 + } catch (InterruptedException ie) {
47.98 + }
47.99 + }
47.100 +
47.101 + // load additional classes when called from other threads
47.102 + if (!tName.equals("main"))
47.103 + {
47.104 + loadClasses(3);
47.105 + }
47.106 + return null;
47.107 + }
47.108 +
47.109 + public static void
47.110 + loadClasses( int index)
47.111 + {
47.112 + ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader();
47.113 + try
47.114 + {
47.115 + Class.forName("TestClass" + index, true, loader);
47.116 + }
47.117 + catch (Exception e)
47.118 + {
47.119 + e.printStackTrace();
47.120 + }
47.121 + }
47.122 + }
47.123 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
48.2 +++ b/test/java/lang/instrument/ParallelTransformerLoaderApp.java Fri Apr 18 16:40:32 2008 -0700
48.3 @@ -0,0 +1,90 @@
48.4 +/*
48.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48.7 + *
48.8 + * This code is free software; you can redistribute it and/or modify it
48.9 + * under the terms of the GNU General Public License version 2 only, as
48.10 + * published by the Free Software Foundation.
48.11 + *
48.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
48.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
48.15 + * version 2 for more details (a copy is included in the LICENSE file that
48.16 + * accompanied this code).
48.17 + *
48.18 + * You should have received a copy of the GNU General Public License version
48.19 + * 2 along with this work; if not, write to the Free Software Foundation,
48.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48.21 + *
48.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
48.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
48.24 + * have any questions.
48.25 + */
48.26 +
48.27 +/**
48.28 + * Test Java Program
48.29 + *
48.30 + * @author Daryl Puryear
48.31 + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
48.32 + */
48.33 +public class ParallelTransformerLoaderApp
48.34 +{
48.35 + private static final int kNumIterations = 1000;
48.36 +
48.37 + public static void
48.38 + main( String[] args)
48.39 + throws Exception
48.40 + {
48.41 + System.out.println();
48.42 + System.out.print("Starting test with " + kNumIterations + " iterations");
48.43 + for (int i = 0; i < kNumIterations; i++)
48.44 + {
48.45 + // load some classes from multiple threads (this thread and one other)
48.46 + Thread testThread = new TestThread(2);
48.47 + testThread.start();
48.48 + loadClasses(1);
48.49 +
48.50 + // log that it completed and reset for the next iteration
48.51 + testThread.join();
48.52 + System.out.print(".");
48.53 + ParallelTransformerLoaderAgent.generateNewClassLoader();
48.54 + }
48.55 +
48.56 + System.out.println();
48.57 + System.out.println("Test completed successfully");
48.58 + }
48.59 +
48.60 + private static class TestThread
48.61 + extends Thread
48.62 + {
48.63 + private final int fIndex;
48.64 +
48.65 + public
48.66 + TestThread( int index)
48.67 + {
48.68 + super("TestThread");
48.69 +
48.70 + fIndex = index;
48.71 + }
48.72 +
48.73 + public void
48.74 + run()
48.75 + {
48.76 + loadClasses(fIndex);
48.77 + }
48.78 + }
48.79 +
48.80 + public static void
48.81 + loadClasses( int index)
48.82 + {
48.83 + ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader();
48.84 + try
48.85 + {
48.86 + Class.forName("TestClass" + index, true, loader);
48.87 + }
48.88 + catch (Exception e)
48.89 + {
48.90 + e.printStackTrace();
48.91 + }
48.92 + }
48.93 +}
49.1 --- a/test/java/lang/instrument/PremainClass/DummyMain.java Fri Apr 18 12:47:38 2008 -0700
49.2 +++ b/test/java/lang/instrument/PremainClass/DummyMain.java Fri Apr 18 16:40:32 2008 -0700
49.3 @@ -22,11 +22,10 @@
49.4 */
49.5
49.6 /*
49.7 - *
49.8 - *
49.9 - * Used by PremainClassTest.sh - dummy "main application" which doesn't do anything
49.10 + * dummy "Hello World"ish application for "premain" tests
49.11 */
49.12 public class DummyMain {
49.13 public static void main(String[] args) {
49.14 + System.out.println("Hello from DummyMain!");
49.15 }
49.16 }
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0001.java Fri Apr 18 16:40:32 2008 -0700
50.3 @@ -0,0 +1,54 @@
50.4 +/*
50.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50.7 + *
50.8 + * This code is free software; you can redistribute it and/or modify it
50.9 + * under the terms of the GNU General Public License version 2 only, as
50.10 + * published by the Free Software Foundation.
50.11 + *
50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50.15 + * version 2 for more details (a copy is included in the LICENSE file that
50.16 + * accompanied this code).
50.17 + *
50.18 + * You should have received a copy of the GNU General Public License version
50.19 + * 2 along with this work; if not, write to the Free Software Foundation,
50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50.21 + *
50.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
50.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
50.24 + * have any questions.
50.25 + */
50.26 +
50.27 +/**
50.28 + * @test
50.29 + * @bug 6289149
50.30 + * @summary test config (0,0,0,1): declared 1-arg in agent class
50.31 + * @author Daniel D. Daugherty, Sun Microsystems
50.32 + *
50.33 + * @run shell ../MakeJAR3.sh InheritAgent0001
50.34 + * @run main/othervm -javaagent:InheritAgent0001.jar DummyMain
50.35 + */
50.36 +
50.37 +import java.lang.instrument.*;
50.38 +
50.39 +class InheritAgent0001 extends InheritAgent0001Super {
50.40 +
50.41 + //
50.42 + // This agent has a single argument premain() method which
50.43 + // is the one that should be called.
50.44 + //
50.45 + public static void premain (String agentArgs) {
50.46 + System.out.println("Hello from Single-Arg InheritAgent0001!");
50.47 + }
50.48 +
50.49 + // This agent does NOT have a double argument premain() method.
50.50 +}
50.51 +
50.52 +class InheritAgent0001Super {
50.53 +
50.54 + // This agent does NOT have a single argument premain() method.
50.55 +
50.56 + // This agent does NOT have a double argument premain() method.
50.57 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0010.java Fri Apr 18 16:40:32 2008 -0700
51.3 @@ -0,0 +1,54 @@
51.4 +/*
51.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51.7 + *
51.8 + * This code is free software; you can redistribute it and/or modify it
51.9 + * under the terms of the GNU General Public License version 2 only, as
51.10 + * published by the Free Software Foundation.
51.11 + *
51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51.15 + * version 2 for more details (a copy is included in the LICENSE file that
51.16 + * accompanied this code).
51.17 + *
51.18 + * You should have received a copy of the GNU General Public License version
51.19 + * 2 along with this work; if not, write to the Free Software Foundation,
51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51.21 + *
51.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
51.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
51.24 + * have any questions.
51.25 + */
51.26 +
51.27 +/**
51.28 + * @test
51.29 + * @bug 6289149
51.30 + * @summary test config (0,0,1,0): declared 2-arg in agent class
51.31 + * @author Daniel D. Daugherty, Sun Microsystems
51.32 + *
51.33 + * @run shell ../MakeJAR3.sh InheritAgent0010
51.34 + * @run main/othervm -javaagent:InheritAgent0010.jar DummyMain
51.35 + */
51.36 +
51.37 +import java.lang.instrument.*;
51.38 +
51.39 +class InheritAgent0010 extends InheritAgent0010Super {
51.40 +
51.41 + // This agent does NOT have a single argument premain() method.
51.42 +
51.43 + //
51.44 + // This agent has a double argument premain() method which
51.45 + // is the one that should be called.
51.46 + //
51.47 + public static void premain (String agentArgs, Instrumentation instArg) {
51.48 + System.out.println("Hello from Double-Arg InheritAgent0010!");
51.49 + }
51.50 +}
51.51 +
51.52 +class InheritAgent0010Super {
51.53 +
51.54 + // This agent does NOT have a single argument premain() method.
51.55 +
51.56 + // This agent does NOT have a double argument premain() method.
51.57 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0011.java Fri Apr 18 16:40:32 2008 -0700
52.3 @@ -0,0 +1,61 @@
52.4 +/*
52.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
52.7 + *
52.8 + * This code is free software; you can redistribute it and/or modify it
52.9 + * under the terms of the GNU General Public License version 2 only, as
52.10 + * published by the Free Software Foundation.
52.11 + *
52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
52.15 + * version 2 for more details (a copy is included in the LICENSE file that
52.16 + * accompanied this code).
52.17 + *
52.18 + * You should have received a copy of the GNU General Public License version
52.19 + * 2 along with this work; if not, write to the Free Software Foundation,
52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
52.21 + *
52.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
52.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
52.24 + * have any questions.
52.25 + */
52.26 +
52.27 +/**
52.28 + * @test
52.29 + * @bug 6289149
52.30 + * @summary test config (0,0,1,1): declared 2-arg and declared 1-arg in agent class
52.31 + * @author Daniel D. Daugherty, Sun Microsystems
52.32 + *
52.33 + * @run shell ../MakeJAR3.sh InheritAgent0011
52.34 + * @run main/othervm -javaagent:InheritAgent0011.jar DummyMain
52.35 + */
52.36 +
52.37 +import java.lang.instrument.*;
52.38 +
52.39 +class InheritAgent0011 extends InheritAgent0011Super {
52.40 +
52.41 + //
52.42 + // This agent has a single argument premain() method which
52.43 + // is NOT the one that should be called.
52.44 + //
52.45 + public static void premain (String agentArgs) {
52.46 + System.out.println("Hello from Single-Arg InheritAgent0011!");
52.47 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
52.48 + }
52.49 +
52.50 + //
52.51 + // This agent has a double argument premain() method which
52.52 + // is the one that should be called.
52.53 + //
52.54 + public static void premain (String agentArgs, Instrumentation instArg) {
52.55 + System.out.println("Hello from Double-Arg InheritAgent0011!");
52.56 + }
52.57 +}
52.58 +
52.59 +class InheritAgent0011Super {
52.60 +
52.61 + // This agent does NOT have a single argument premain() method.
52.62 +
52.63 + // This agent does NOT have a double argument premain() method.
52.64 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
53.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0100.java Fri Apr 18 16:40:32 2008 -0700
53.3 @@ -0,0 +1,54 @@
53.4 +/*
53.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53.7 + *
53.8 + * This code is free software; you can redistribute it and/or modify it
53.9 + * under the terms of the GNU General Public License version 2 only, as
53.10 + * published by the Free Software Foundation.
53.11 + *
53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
53.15 + * version 2 for more details (a copy is included in the LICENSE file that
53.16 + * accompanied this code).
53.17 + *
53.18 + * You should have received a copy of the GNU General Public License version
53.19 + * 2 along with this work; if not, write to the Free Software Foundation,
53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53.21 + *
53.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
53.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
53.24 + * have any questions.
53.25 + */
53.26 +
53.27 +/**
53.28 + * @test
53.29 + * @bug 6289149
53.30 + * @summary test config (0,1,0,0): inherited 1-arg in agent class
53.31 + * @author Daniel D. Daugherty, Sun Microsystems
53.32 + *
53.33 + * @run shell ../MakeJAR3.sh InheritAgent0100
53.34 + * @run main/othervm -javaagent:InheritAgent0100.jar DummyMain
53.35 + */
53.36 +
53.37 +import java.lang.instrument.*;
53.38 +
53.39 +class InheritAgent0100 extends InheritAgent0100Super {
53.40 +
53.41 + // This agent does NOT have a single argument premain() method.
53.42 +
53.43 + // This agent does NOT have a double argument premain() method.
53.44 +}
53.45 +
53.46 +class InheritAgent0100Super {
53.47 +
53.48 + //
53.49 + // This agent has a single argument premain() method which
53.50 + // is the one that should be called.
53.51 + //
53.52 + public static void premain (String agentArgs) {
53.53 + System.out.println("Hello from Single-Arg InheritAgent0100Super!");
53.54 + }
53.55 +
53.56 + // This agent does NOT have a double argument premain() method.
53.57 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0101.java Fri Apr 18 16:40:32 2008 -0700
54.3 @@ -0,0 +1,61 @@
54.4 +/*
54.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54.7 + *
54.8 + * This code is free software; you can redistribute it and/or modify it
54.9 + * under the terms of the GNU General Public License version 2 only, as
54.10 + * published by the Free Software Foundation.
54.11 + *
54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
54.15 + * version 2 for more details (a copy is included in the LICENSE file that
54.16 + * accompanied this code).
54.17 + *
54.18 + * You should have received a copy of the GNU General Public License version
54.19 + * 2 along with this work; if not, write to the Free Software Foundation,
54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
54.21 + *
54.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
54.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
54.24 + * have any questions.
54.25 + */
54.26 +
54.27 +/**
54.28 + * @test
54.29 + * @bug 6289149
54.30 + * @summary test config (0,1,0,1): inherited 1-arg and declared 1-arg in agent class
54.31 + * @author Daniel D. Daugherty, Sun Microsystems
54.32 + *
54.33 + * @run shell ../MakeJAR3.sh InheritAgent0101
54.34 + * @run main/othervm -javaagent:InheritAgent0101.jar DummyMain
54.35 + */
54.36 +
54.37 +import java.lang.instrument.*;
54.38 +
54.39 +class InheritAgent0101 extends InheritAgent0101Super {
54.40 +
54.41 + //
54.42 + // This agent has a single argument premain() method which
54.43 + // is the one that should be called.
54.44 + //
54.45 + public static void premain (String agentArgs) {
54.46 + System.out.println("Hello from Single-Arg InheritAgent0101!");
54.47 + }
54.48 +
54.49 + // This agent does NOT have a double argument premain() method.
54.50 +}
54.51 +
54.52 +class InheritAgent0101Super {
54.53 +
54.54 + //
54.55 + // This agent has a single argument premain() method which
54.56 + // is NOT the one that should be called.
54.57 + //
54.58 + public static void premain (String agentArgs) {
54.59 + System.out.println("Hello from Single-Arg InheritAgent0101Super!");
54.60 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
54.61 + }
54.62 +
54.63 + // This agent does NOT have a double argument premain() method.
54.64 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
55.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0110.java Fri Apr 18 16:40:32 2008 -0700
55.3 @@ -0,0 +1,61 @@
55.4 +/*
55.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55.7 + *
55.8 + * This code is free software; you can redistribute it and/or modify it
55.9 + * under the terms of the GNU General Public License version 2 only, as
55.10 + * published by the Free Software Foundation.
55.11 + *
55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
55.15 + * version 2 for more details (a copy is included in the LICENSE file that
55.16 + * accompanied this code).
55.17 + *
55.18 + * You should have received a copy of the GNU General Public License version
55.19 + * 2 along with this work; if not, write to the Free Software Foundation,
55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
55.21 + *
55.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
55.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
55.24 + * have any questions.
55.25 + */
55.26 +
55.27 +/**
55.28 + * @test
55.29 + * @bug 6289149
55.30 + * @summary test config (0,1,1,0): inherited 1-arg and declared 2-arg in agent class
55.31 + * @author Daniel D. Daugherty, Sun Microsystems
55.32 + *
55.33 + * @run shell ../MakeJAR3.sh InheritAgent0110
55.34 + * @run main/othervm -javaagent:InheritAgent0110.jar DummyMain
55.35 + */
55.36 +
55.37 +import java.lang.instrument.*;
55.38 +
55.39 +class InheritAgent0110 extends InheritAgent0110Super {
55.40 +
55.41 + // This agent does NOT have a one argument premain() method.
55.42 +
55.43 + //
55.44 + // This agent has a double argument premain() method which
55.45 + // is the one that should be called.
55.46 + //
55.47 + public static void premain (String agentArgs, Instrumentation instArg) {
55.48 + System.out.println("Hello from Double-Arg InheritAgent0110!");
55.49 + }
55.50 +}
55.51 +
55.52 +class InheritAgent0110Super {
55.53 +
55.54 + //
55.55 + // This agent has a single argument premain() method which
55.56 + // is NOT the one that should be called.
55.57 + //
55.58 + public static void premain (String agentArgs) {
55.59 + System.out.println("Hello from Single-Arg InheritAgent0110Super!");
55.60 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
55.61 + }
55.62 +
55.63 + // This agent does NOT have a double argument premain() method.
55.64 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
56.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent0111.java Fri Apr 18 16:40:32 2008 -0700
56.3 @@ -0,0 +1,69 @@
56.4 +/*
56.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56.7 + *
56.8 + * This code is free software; you can redistribute it and/or modify it
56.9 + * under the terms of the GNU General Public License version 2 only, as
56.10 + * published by the Free Software Foundation.
56.11 + *
56.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
56.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56.15 + * version 2 for more details (a copy is included in the LICENSE file that
56.16 + * accompanied this code).
56.17 + *
56.18 + * You should have received a copy of the GNU General Public License version
56.19 + * 2 along with this work; if not, write to the Free Software Foundation,
56.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
56.21 + *
56.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
56.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
56.24 + * have any questions.
56.25 + */
56.26 +
56.27 +/**
56.28 + * @test
56.29 + * @bug 6289149
56.30 + * @summary test config (0,1,1,1): inherited 1-arg, declared 2-arg and declared 1-arg in agent class
56.31 + * @author Daniel D. Daugherty, Sun Microsystems
56.32 + *
56.33 + * @run shell ../MakeJAR3.sh InheritAgent0111
56.34 + * @run main/othervm -javaagent:InheritAgent0111.jar DummyMain
56.35 + */
56.36 +
56.37 +import java.lang.instrument.*;
56.38 +
56.39 +class InheritAgent0111 extends InheritAgent0111Super {
56.40 +
56.41 + //
56.42 + // This agent has a single argument premain() method which
56.43 + // is NOT the one that should be called.
56.44 + //
56.45 + public static void premain (String agentArgs) {
56.46 + System.out.println("Hello from Single-Arg InheritAgent0111!");
56.47 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
56.48 + }
56.49 +
56.50 + //
56.51 + // This agent has a double argument premain() method which
56.52 + // is the one that should be called.
56.53 + //
56.54 + public static void premain (String agentArgs, Instrumentation instArg) {
56.55 + System.out.println("Hello from Double-Arg InheritAgent0111!");
56.56 + }
56.57 +
56.58 +}
56.59 +
56.60 +class InheritAgent0111Super {
56.61 +
56.62 + //
56.63 + // This agent has a single argument premain() method which
56.64 + // is NOT the one that should be called.
56.65 + //
56.66 + public static void premain (String agentArgs) {
56.67 + System.out.println("Hello from Single-Arg InheritAgent0111Super!");
56.68 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
56.69 + }
56.70 +
56.71 + // This agent does NOT have a double argument premain() method.
56.72 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
57.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1000.java Fri Apr 18 16:40:32 2008 -0700
57.3 @@ -0,0 +1,54 @@
57.4 +/*
57.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57.7 + *
57.8 + * This code is free software; you can redistribute it and/or modify it
57.9 + * under the terms of the GNU General Public License version 2 only, as
57.10 + * published by the Free Software Foundation.
57.11 + *
57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57.15 + * version 2 for more details (a copy is included in the LICENSE file that
57.16 + * accompanied this code).
57.17 + *
57.18 + * You should have received a copy of the GNU General Public License version
57.19 + * 2 along with this work; if not, write to the Free Software Foundation,
57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57.21 + *
57.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
57.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
57.24 + * have any questions.
57.25 + */
57.26 +
57.27 +/**
57.28 + * @test
57.29 + * @bug 6289149
57.30 + * @summary test config (1,0,0,0): inherited 2-arg in agent class
57.31 + * @author Daniel D. Daugherty, Sun Microsystems
57.32 + *
57.33 + * @run shell ../MakeJAR3.sh InheritAgent1000
57.34 + * @run main/othervm -javaagent:InheritAgent1000.jar DummyMain
57.35 + */
57.36 +
57.37 +import java.lang.instrument.*;
57.38 +
57.39 +class InheritAgent1000 extends InheritAgent1000Super {
57.40 +
57.41 + // This agent does NOT have a single argument premain() method.
57.42 +
57.43 + // This agent does NOT have a double argument premain() method.
57.44 +}
57.45 +
57.46 +class InheritAgent1000Super {
57.47 +
57.48 + // This agent does NOT have a single argument premain() method.
57.49 +
57.50 + //
57.51 + // This agent has a double argument premain() method which
57.52 + // is the one that should be called.
57.53 + //
57.54 + public static void premain (String agentArgs, Instrumentation instArg) {
57.55 + System.out.println("Hello from Double-Arg InheritAgent1000Super!");
57.56 + }
57.57 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
58.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1001.java Fri Apr 18 16:40:32 2008 -0700
58.3 @@ -0,0 +1,61 @@
58.4 +/*
58.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
58.7 + *
58.8 + * This code is free software; you can redistribute it and/or modify it
58.9 + * under the terms of the GNU General Public License version 2 only, as
58.10 + * published by the Free Software Foundation.
58.11 + *
58.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
58.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
58.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
58.15 + * version 2 for more details (a copy is included in the LICENSE file that
58.16 + * accompanied this code).
58.17 + *
58.18 + * You should have received a copy of the GNU General Public License version
58.19 + * 2 along with this work; if not, write to the Free Software Foundation,
58.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
58.21 + *
58.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
58.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
58.24 + * have any questions.
58.25 + */
58.26 +
58.27 +/**
58.28 + * @test
58.29 + * @bug 6289149
58.30 + * @summary test config (1,0,0,1): inherited 2-arg, and declared 1-arg in agent class
58.31 + * @author Daniel D. Daugherty, Sun Microsystems
58.32 + *
58.33 + * @run shell ../MakeJAR3.sh InheritAgent1001
58.34 + * @run main/othervm -javaagent:InheritAgent1001.jar DummyMain
58.35 + */
58.36 +
58.37 +import java.lang.instrument.*;
58.38 +
58.39 +class InheritAgent1001 extends InheritAgent1001Super {
58.40 +
58.41 + //
58.42 + // This agent has a single argument premain() method which
58.43 + // is the one that should be called.
58.44 + //
58.45 + public static void premain (String agentArgs) {
58.46 + System.out.println("Hello from Single-Arg InheritAgent1001!");
58.47 + }
58.48 +
58.49 + // This agent does NOT have a double argument premain() method.
58.50 +}
58.51 +
58.52 +class InheritAgent1001Super {
58.53 +
58.54 + // This agent does NOT have a single argument premain() method.
58.55 +
58.56 + //
58.57 + // This agent has a double argument premain() method which
58.58 + // is NOT the one that should be called.
58.59 + //
58.60 + public static void premain (String agentArgs, Instrumentation instArg) {
58.61 + System.out.println("Hello from Double-Arg InheritAgent1001Super!");
58.62 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
58.63 + }
58.64 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
59.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1010.java Fri Apr 18 16:40:32 2008 -0700
59.3 @@ -0,0 +1,61 @@
59.4 +/*
59.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59.7 + *
59.8 + * This code is free software; you can redistribute it and/or modify it
59.9 + * under the terms of the GNU General Public License version 2 only, as
59.10 + * published by the Free Software Foundation.
59.11 + *
59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59.15 + * version 2 for more details (a copy is included in the LICENSE file that
59.16 + * accompanied this code).
59.17 + *
59.18 + * You should have received a copy of the GNU General Public License version
59.19 + * 2 along with this work; if not, write to the Free Software Foundation,
59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59.21 + *
59.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
59.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
59.24 + * have any questions.
59.25 + */
59.26 +
59.27 +/**
59.28 + * @test
59.29 + * @bug 6289149
59.30 + * @summary test config (1,0,1,0): inherited 2-arg, and declared 2-arg in agent class
59.31 + * @author Daniel D. Daugherty, Sun Microsystems
59.32 + *
59.33 + * @run shell ../MakeJAR3.sh InheritAgent1010
59.34 + * @run main/othervm -javaagent:InheritAgent1010.jar DummyMain
59.35 + */
59.36 +
59.37 +import java.lang.instrument.*;
59.38 +
59.39 +class InheritAgent1010 extends InheritAgent1010Super {
59.40 +
59.41 + // This agent does NOT have a single argument premain() method.
59.42 +
59.43 + //
59.44 + // This agent has a double argument premain() method which
59.45 + // is the one that should be called.
59.46 + //
59.47 + public static void premain (String agentArgs, Instrumentation instArg) {
59.48 + System.out.println("Hello from Double-Arg InheritAgent1010!");
59.49 + }
59.50 +}
59.51 +
59.52 +class InheritAgent1010Super {
59.53 +
59.54 + // This agent does NOT have a single argument premain() method.
59.55 +
59.56 + //
59.57 + // This agent has a double argument premain() method which
59.58 + // is NOT the one that should be called.
59.59 + //
59.60 + public static void premain (String agentArgs, Instrumentation instArg) {
59.61 + System.out.println("Hello from Double-Arg InheritAgent1010Super!");
59.62 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
59.63 + }
59.64 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
60.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1011.java Fri Apr 18 16:40:32 2008 -0700
60.3 @@ -0,0 +1,68 @@
60.4 +/*
60.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
60.7 + *
60.8 + * This code is free software; you can redistribute it and/or modify it
60.9 + * under the terms of the GNU General Public License version 2 only, as
60.10 + * published by the Free Software Foundation.
60.11 + *
60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
60.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
60.15 + * version 2 for more details (a copy is included in the LICENSE file that
60.16 + * accompanied this code).
60.17 + *
60.18 + * You should have received a copy of the GNU General Public License version
60.19 + * 2 along with this work; if not, write to the Free Software Foundation,
60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
60.21 + *
60.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
60.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
60.24 + * have any questions.
60.25 + */
60.26 +
60.27 +/**
60.28 + * @test
60.29 + * @bug 6289149
60.30 + * @summary test config (1,0,1,1): inherited 2-arg, declared 2-arg and declared 1-arg in agent class
60.31 + * @author Daniel D. Daugherty, Sun Microsystems
60.32 + *
60.33 + * @run shell ../MakeJAR3.sh InheritAgent1011
60.34 + * @run main/othervm -javaagent:InheritAgent1011.jar DummyMain
60.35 + */
60.36 +
60.37 +import java.lang.instrument.*;
60.38 +
60.39 +class InheritAgent1011 extends InheritAgent1011Super {
60.40 +
60.41 + //
60.42 + // This agent has a single argument premain() method which
60.43 + // is NOT the one that should be called.
60.44 + //
60.45 + public static void premain (String agentArgs) {
60.46 + System.out.println("Hello from Single-Arg InheritAgent1011!");
60.47 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
60.48 + }
60.49 +
60.50 + //
60.51 + // This agent has a double argument premain() method which
60.52 + // is the one that should be called.
60.53 + //
60.54 + public static void premain (String agentArgs, Instrumentation instArg) {
60.55 + System.out.println("Hello from Double-Arg InheritAgent1011!");
60.56 + }
60.57 +}
60.58 +
60.59 +class InheritAgent1011Super {
60.60 +
60.61 + // This agent does NOT have a single argument premain() method.
60.62 +
60.63 + //
60.64 + // This agent has a double argument premain() method which
60.65 + // is NOT the one that should be called.
60.66 + //
60.67 + public static void premain (String agentArgs, Instrumentation instArg) {
60.68 + System.out.println("Hello from Double-Arg InheritAgent1011Super!");
60.69 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
60.70 + }
60.71 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
61.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1100.java Fri Apr 18 16:40:32 2008 -0700
61.3 @@ -0,0 +1,61 @@
61.4 +/*
61.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
61.7 + *
61.8 + * This code is free software; you can redistribute it and/or modify it
61.9 + * under the terms of the GNU General Public License version 2 only, as
61.10 + * published by the Free Software Foundation.
61.11 + *
61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
61.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
61.15 + * version 2 for more details (a copy is included in the LICENSE file that
61.16 + * accompanied this code).
61.17 + *
61.18 + * You should have received a copy of the GNU General Public License version
61.19 + * 2 along with this work; if not, write to the Free Software Foundation,
61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
61.21 + *
61.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
61.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
61.24 + * have any questions.
61.25 + */
61.26 +
61.27 +/**
61.28 + * @test
61.29 + * @bug 6289149
61.30 + * @summary test config (1,1,0,0): inherited 2-arg and inherited 1-arg in agent class
61.31 + * @author Daniel D. Daugherty, Sun Microsystems
61.32 + *
61.33 + * @run shell ../MakeJAR3.sh InheritAgent1100
61.34 + * @run main/othervm -javaagent:InheritAgent1100.jar DummyMain
61.35 + */
61.36 +
61.37 +import java.lang.instrument.*;
61.38 +
61.39 +class InheritAgent1100 extends InheritAgent1100Super {
61.40 +
61.41 + // This agent does NOT have a single argument premain() method.
61.42 +
61.43 + // This agent does NOT have a double argument premain() method.
61.44 +}
61.45 +
61.46 +class InheritAgent1100Super {
61.47 +
61.48 + //
61.49 + // This agent has a single argument premain() method which
61.50 + // is NOT the one that should be called.
61.51 + //
61.52 + public static void premain (String agentArgs) {
61.53 + System.out.println("Hello from Single-Arg InheritAgent1100Super!");
61.54 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
61.55 + }
61.56 +
61.57 + //
61.58 + // This agent has a double argument premain() method which
61.59 + // is the one that should be called.
61.60 + //
61.61 + public static void premain (String agentArgs, Instrumentation instArg) {
61.62 + System.out.println("Hello from Double-Arg InheritAgent1100Super!");
61.63 + }
61.64 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1101.java Fri Apr 18 16:40:32 2008 -0700
62.3 @@ -0,0 +1,68 @@
62.4 +/*
62.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62.7 + *
62.8 + * This code is free software; you can redistribute it and/or modify it
62.9 + * under the terms of the GNU General Public License version 2 only, as
62.10 + * published by the Free Software Foundation.
62.11 + *
62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62.15 + * version 2 for more details (a copy is included in the LICENSE file that
62.16 + * accompanied this code).
62.17 + *
62.18 + * You should have received a copy of the GNU General Public License version
62.19 + * 2 along with this work; if not, write to the Free Software Foundation,
62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62.21 + *
62.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
62.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
62.24 + * have any questions.
62.25 + */
62.26 +
62.27 +/**
62.28 + * @test
62.29 + * @bug 6289149
62.30 + * @summary test config (1,1,0,1): inherited 2-arg, inherited 1-arg, and declared 1-arg in agent class
62.31 + * @author Daniel D. Daugherty, Sun Microsystems
62.32 + *
62.33 + * @run shell ../MakeJAR3.sh InheritAgent1101
62.34 + * @run main/othervm -javaagent:InheritAgent1101.jar DummyMain
62.35 + */
62.36 +
62.37 +import java.lang.instrument.*;
62.38 +
62.39 +class InheritAgent1101 extends InheritAgent1101Super {
62.40 +
62.41 + //
62.42 + // This agent has a single argument premain() method which
62.43 + // is the one that should be called.
62.44 + //
62.45 + public static void premain (String agentArgs) {
62.46 + System.out.println("Hello from Single-Arg InheritAgent1101!");
62.47 + }
62.48 +
62.49 + // This agent does NOT have a double argument premain() method.
62.50 +}
62.51 +
62.52 +class InheritAgent1101Super {
62.53 +
62.54 + //
62.55 + // This agent has a single argument premain() method which
62.56 + // is NOT the one that should be called.
62.57 + //
62.58 + public static void premain (String agentArgs) {
62.59 + System.out.println("Hello from Single-Arg InheritAgent1101Super!");
62.60 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
62.61 + }
62.62 +
62.63 + //
62.64 + // This agent has a double argument premain() method which
62.65 + // is NOT the one that should be called.
62.66 + //
62.67 + public static void premain (String agentArgs, Instrumentation instArg) {
62.68 + System.out.println("Hello from Double-Arg InheritAgent1101Super!");
62.69 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
62.70 + }
62.71 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1110.java Fri Apr 18 16:40:32 2008 -0700
63.3 @@ -0,0 +1,68 @@
63.4 +/*
63.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63.7 + *
63.8 + * This code is free software; you can redistribute it and/or modify it
63.9 + * under the terms of the GNU General Public License version 2 only, as
63.10 + * published by the Free Software Foundation.
63.11 + *
63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63.15 + * version 2 for more details (a copy is included in the LICENSE file that
63.16 + * accompanied this code).
63.17 + *
63.18 + * You should have received a copy of the GNU General Public License version
63.19 + * 2 along with this work; if not, write to the Free Software Foundation,
63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63.21 + *
63.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
63.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
63.24 + * have any questions.
63.25 + */
63.26 +
63.27 +/**
63.28 + * @test
63.29 + * @bug 6289149
63.30 + * @summary test config (1,1,1,0): inherited 2-arg, inherited 1-arg, and declared 2-arg in agent class
63.31 + * @author Daniel D. Daugherty, Sun Microsystems
63.32 + *
63.33 + * @run shell ../MakeJAR3.sh InheritAgent1110
63.34 + * @run main/othervm -javaagent:InheritAgent1110.jar DummyMain
63.35 + */
63.36 +
63.37 +import java.lang.instrument.*;
63.38 +
63.39 +class InheritAgent1110 extends InheritAgent1110Super {
63.40 +
63.41 + // This agent does NOT have a single argument premain() method.
63.42 +
63.43 + //
63.44 + // This agent has a double argument premain() method which
63.45 + // is the one that should be called.
63.46 + //
63.47 + public static void premain (String agentArgs, Instrumentation instArg) {
63.48 + System.out.println("Hello from Double-Arg InheritAgent1110!");
63.49 + }
63.50 +}
63.51 +
63.52 +class InheritAgent1110Super {
63.53 +
63.54 + //
63.55 + // This agent has a single argument premain() method which
63.56 + // is NOT the one that should be called.
63.57 + //
63.58 + public static void premain (String agentArgs) {
63.59 + System.out.println("Hello from Single-Arg InheritAgent1110Super!");
63.60 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
63.61 + }
63.62 +
63.63 + //
63.64 + // This agent has a double argument premain() method which
63.65 + // is NOT the one that should be called.
63.66 + //
63.67 + public static void premain (String agentArgs, Instrumentation instArg) {
63.68 + System.out.println("Hello from Double-Arg InheritAgent1110Super!");
63.69 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
63.70 + }
63.71 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
64.2 +++ b/test/java/lang/instrument/PremainClass/InheritAgent1111.java Fri Apr 18 16:40:32 2008 -0700
64.3 @@ -0,0 +1,75 @@
64.4 +/*
64.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64.7 + *
64.8 + * This code is free software; you can redistribute it and/or modify it
64.9 + * under the terms of the GNU General Public License version 2 only, as
64.10 + * published by the Free Software Foundation.
64.11 + *
64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
64.15 + * version 2 for more details (a copy is included in the LICENSE file that
64.16 + * accompanied this code).
64.17 + *
64.18 + * You should have received a copy of the GNU General Public License version
64.19 + * 2 along with this work; if not, write to the Free Software Foundation,
64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64.21 + *
64.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
64.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
64.24 + * have any questions.
64.25 + */
64.26 +
64.27 +/**
64.28 + * @test
64.29 + * @bug 6289149
64.30 + * @summary test config (1,1,1,1): inherited 2-arg, inherited 1-arg, declared 2-arg and declared 1-arg in agent class
64.31 + * @author Daniel D. Daugherty, Sun Microsystems
64.32 + *
64.33 + * @run shell ../MakeJAR3.sh InheritAgent1111
64.34 + * @run main/othervm -javaagent:InheritAgent1111.jar DummyMain
64.35 + */
64.36 +
64.37 +import java.lang.instrument.*;
64.38 +
64.39 +class InheritAgent1111 extends InheritAgent1111Super {
64.40 +
64.41 + //
64.42 + // This agent has a single argument premain() method which
64.43 + // is NOT the one that should be called.
64.44 + //
64.45 + public static void premain (String agentArgs) {
64.46 + System.out.println("Hello from Single-Arg InheritAgent1111!");
64.47 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
64.48 + }
64.49 +
64.50 + //
64.51 + // This agent has a double argument premain() method which
64.52 + // is the one that should be called.
64.53 + //
64.54 + public static void premain (String agentArgs, Instrumentation instArg) {
64.55 + System.out.println("Hello from Double-Arg InheritAgent1111!");
64.56 + }
64.57 +}
64.58 +
64.59 +class InheritAgent1111Super {
64.60 +
64.61 + //
64.62 + // This agent has a single argument premain() method which
64.63 + // is NOT the one that should be called.
64.64 + //
64.65 + public static void premain (String agentArgs) {
64.66 + System.out.println("Hello from Single-Arg InheritAgent1111Super!");
64.67 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
64.68 + }
64.69 +
64.70 + //
64.71 + // This agent has a double argument premain() method which
64.72 + // is NOT the one that should be called.
64.73 + //
64.74 + public static void premain (String agentArgs, Instrumentation instArg) {
64.75 + System.out.println("Hello from Double-Arg InheritAgent1111Super!");
64.76 + throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
64.77 + }
64.78 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/test/java/lang/instrument/PremainClass/NoPremainAgent.java Fri Apr 18 16:40:32 2008 -0700
65.3 @@ -0,0 +1,29 @@
65.4 +/*
65.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65.7 + *
65.8 + * This code is free software; you can redistribute it and/or modify it
65.9 + * under the terms of the GNU General Public License version 2 only, as
65.10 + * published by the Free Software Foundation.
65.11 + *
65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65.15 + * version 2 for more details (a copy is included in the LICENSE file that
65.16 + * accompanied this code).
65.17 + *
65.18 + * You should have received a copy of the GNU General Public License version
65.19 + * 2 along with this work; if not, write to the Free Software Foundation,
65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65.21 + *
65.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
65.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
65.24 + * have any questions.
65.25 + */
65.26 +
65.27 +import java.lang.instrument.*;
65.28 +
65.29 +class NoPremainAgent {
65.30 +
65.31 + // This agent is missing the premain() function.
65.32 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/test/java/lang/instrument/PremainClass/NoPremainAgent.sh Fri Apr 18 16:40:32 2008 -0700
66.3 @@ -0,0 +1,68 @@
66.4 +#
66.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
66.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66.7 +#
66.8 +# This code is free software; you can redistribute it and/or modify it
66.9 +# under the terms of the GNU General Public License version 2 only, as
66.10 +# published by the Free Software Foundation.
66.11 +#
66.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
66.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
66.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
66.15 +# version 2 for more details (a copy is included in the LICENSE file that
66.16 +# accompanied this code).
66.17 +#
66.18 +# You should have received a copy of the GNU General Public License version
66.19 +# 2 along with this work; if not, write to the Free Software Foundation,
66.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
66.21 +#
66.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
66.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
66.24 +# have any questions.
66.25 +#
66.26 +
66.27 +# @test
66.28 +# @bug 6289149
66.29 +# @summary test when the agent's class is missing the premain() function.
66.30 +# @author Daniel D. Daugherty, Sun Microsystems
66.31 +#
66.32 +# @run build DummyMain
66.33 +# @run shell ../MakeJAR3.sh NoPremainAgent
66.34 +# @run shell NoPremainAgent.sh
66.35 +#
66.36 +
66.37 +if [ "${TESTJAVA}" = "" ]
66.38 +then
66.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
66.40 + exit 1
66.41 +fi
66.42 +
66.43 +if [ "${TESTSRC}" = "" ]
66.44 +then
66.45 + echo "TESTSRC not set. Test cannot execute. Failed."
66.46 + exit 1
66.47 +fi
66.48 +
66.49 +if [ "${TESTCLASSES}" = "" ]
66.50 +then
66.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
66.52 + exit 1
66.53 +fi
66.54 +
66.55 +JAVAC="${TESTJAVA}"/bin/javac
66.56 +JAVA="${TESTJAVA}"/bin/java
66.57 +
66.58 +"${JAVA}" ${TESTVMOPTS} -javaagent:NoPremainAgent.jar \
66.59 + -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
66.60 +cat output.log
66.61 +
66.62 +MESG="java.lang.NoSuchMethodException"
66.63 +grep "$MESG" output.log
66.64 +result=$?
66.65 +if [ "$result" = 0 ]; then
66.66 + echo "PASS: found '$MESG' in the test output"
66.67 +else
66.68 + echo "FAIL: did NOT find '$MESG' in the test output"
66.69 +fi
66.70 +
66.71 +exit $result
67.1 --- a/test/java/lang/instrument/PremainClass/PremainClassTest.sh Fri Apr 18 12:47:38 2008 -0700
67.2 +++ b/test/java/lang/instrument/PremainClass/PremainClassTest.sh Fri Apr 18 16:40:32 2008 -0700
67.3 @@ -49,7 +49,7 @@
67.4
67.5 "$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/DummyMain.java
67.6
67.7 -"${JAVA}" -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
67.8 +"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
67.9 result=$?
67.10
67.11 exit $result
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
68.2 +++ b/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.java Fri Apr 18 16:40:32 2008 -0700
68.3 @@ -0,0 +1,32 @@
68.4 +/*
68.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
68.7 + *
68.8 + * This code is free software; you can redistribute it and/or modify it
68.9 + * under the terms of the GNU General Public License version 2 only, as
68.10 + * published by the Free Software Foundation.
68.11 + *
68.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
68.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
68.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
68.15 + * version 2 for more details (a copy is included in the LICENSE file that
68.16 + * accompanied this code).
68.17 + *
68.18 + * You should have received a copy of the GNU General Public License version
68.19 + * 2 along with this work; if not, write to the Free Software Foundation,
68.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
68.21 + *
68.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
68.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
68.24 + * have any questions.
68.25 + */
68.26 +
68.27 +import java.lang.instrument.*;
68.28 +
68.29 +class ZeroArgPremainAgent {
68.30 +
68.31 + // This agent has a zero arg premain() function.
68.32 + public static void premain () {
68.33 + System.out.println("Hello from ZeroArgInheritAgent!");
68.34 + }
68.35 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.sh Fri Apr 18 16:40:32 2008 -0700
69.3 @@ -0,0 +1,68 @@
69.4 +#
69.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
69.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69.7 +#
69.8 +# This code is free software; you can redistribute it and/or modify it
69.9 +# under the terms of the GNU General Public License version 2 only, as
69.10 +# published by the Free Software Foundation.
69.11 +#
69.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
69.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69.15 +# version 2 for more details (a copy is included in the LICENSE file that
69.16 +# accompanied this code).
69.17 +#
69.18 +# You should have received a copy of the GNU General Public License version
69.19 +# 2 along with this work; if not, write to the Free Software Foundation,
69.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69.21 +#
69.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
69.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
69.24 +# have any questions.
69.25 +#
69.26 +
69.27 +# @test
69.28 +# @bug 6289149
69.29 +# @summary test when the agent's class has a zero arg premain() function.
69.30 +# @author Daniel D. Daugherty, Sun Microsystems
69.31 +#
69.32 +# @run build DummyMain
69.33 +# @run shell ../MakeJAR3.sh ZeroArgPremainAgent
69.34 +# @run shell ZeroArgPremainAgent.sh
69.35 +#
69.36 +
69.37 +if [ "${TESTJAVA}" = "" ]
69.38 +then
69.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
69.40 + exit 1
69.41 +fi
69.42 +
69.43 +if [ "${TESTSRC}" = "" ]
69.44 +then
69.45 + echo "TESTSRC not set. Test cannot execute. Failed."
69.46 + exit 1
69.47 +fi
69.48 +
69.49 +if [ "${TESTCLASSES}" = "" ]
69.50 +then
69.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
69.52 + exit 1
69.53 +fi
69.54 +
69.55 +JAVAC="${TESTJAVA}"/bin/javac
69.56 +JAVA="${TESTJAVA}"/bin/java
69.57 +
69.58 +"${JAVA}" ${TESTVMOPTS} -javaagent:ZeroArgPremainAgent.jar \
69.59 + -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
69.60 +cat output.log
69.61 +
69.62 +MESG="java.lang.NoSuchMethodException"
69.63 +grep "$MESG" output.log
69.64 +result=$?
69.65 +if [ "$result" = 0 ]; then
69.66 + echo "PASS: found '$MESG' in the test output"
69.67 +else
69.68 + echo "FAIL: did NOT find '$MESG' in the test output"
69.69 +fi
69.70 +
69.71 +exit $result
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
70.2 +++ b/test/java/lang/instrument/RedefineClassWithNativeMethod.sh Fri Apr 18 16:40:32 2008 -0700
70.3 @@ -0,0 +1,81 @@
70.4 +#
70.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
70.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70.7 +#
70.8 +# This code is free software; you can redistribute it and/or modify it
70.9 +# under the terms of the GNU General Public License version 2 only, as
70.10 +# published by the Free Software Foundation.
70.11 +#
70.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
70.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70.15 +# version 2 for more details (a copy is included in the LICENSE file that
70.16 +# accompanied this code).
70.17 +#
70.18 +# You should have received a copy of the GNU General Public License version
70.19 +# 2 along with this work; if not, write to the Free Software Foundation,
70.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70.21 +#
70.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
70.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
70.24 +# have any questions.
70.25 +#
70.26 +
70.27 +# @test
70.28 +# @bug 5003341 4917140 6545149
70.29 +# @summary Redefine a class with a native method.
70.30 +# @author Daniel D. Daugherty as modified from the test submitted by clovis@par.univie.ac.at
70.31 +#
70.32 +# @run shell MakeJAR3.sh RedefineClassWithNativeMethodAgent 'Can-Redefine-Classes: true'
70.33 +# @run build RedefineClassWithNativeMethodApp
70.34 +# @run shell RedefineClassWithNativeMethod.sh
70.35 +#
70.36 +
70.37 +if [ "${TESTJAVA}" = "" ]
70.38 +then
70.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
70.40 + exit 1
70.41 +fi
70.42 +
70.43 +if [ "${TESTSRC}" = "" ]
70.44 +then
70.45 + echo "TESTSRC not set. Test cannot execute. Failed."
70.46 + exit 1
70.47 +fi
70.48 +
70.49 +if [ "${TESTCLASSES}" = "" ]
70.50 +then
70.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
70.52 + exit 1
70.53 +fi
70.54 +
70.55 +JAVAC="${TESTJAVA}"/bin/javac
70.56 +JAVA="${TESTJAVA}"/bin/java
70.57 +
70.58 +"${JAVA}" ${TESTVMOPTS} \
70.59 + -javaagent:RedefineClassWithNativeMethodAgent.jar=java/lang/Thread.class \
70.60 + -classpath "${TESTCLASSES}" RedefineClassWithNativeMethodApp \
70.61 + > output.log 2>&1
70.62 +result=$?
70.63 +
70.64 +cat output.log
70.65 +
70.66 +if [ "$result" = 0 ]; then
70.67 + echo "PASS: RedefineClassWithNativeMethodApp exited with status of 0."
70.68 +else
70.69 + echo "FAIL: RedefineClassWithNativeMethodApp exited with status of $result"
70.70 + exit "$result"
70.71 +fi
70.72 +
70.73 +MESG="Exception"
70.74 +grep "$MESG" output.log
70.75 +result=$?
70.76 +if [ "$result" = 0 ]; then
70.77 + echo "FAIL: found '$MESG' in the test output"
70.78 + result=1
70.79 +else
70.80 + echo "PASS: did NOT find '$MESG' in the test output"
70.81 + result=0
70.82 +fi
70.83 +
70.84 +exit $result
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
71.2 +++ b/test/java/lang/instrument/RedefineClassWithNativeMethodAgent.java Fri Apr 18 16:40:32 2008 -0700
71.3 @@ -0,0 +1,70 @@
71.4 +/*
71.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71.7 + *
71.8 + * This code is free software; you can redistribute it and/or modify it
71.9 + * under the terms of the GNU General Public License version 2 only, as
71.10 + * published by the Free Software Foundation.
71.11 + *
71.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
71.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
71.15 + * version 2 for more details (a copy is included in the LICENSE file that
71.16 + * accompanied this code).
71.17 + *
71.18 + * You should have received a copy of the GNU General Public License version
71.19 + * 2 along with this work; if not, write to the Free Software Foundation,
71.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71.21 + *
71.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
71.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
71.24 + * have any questions.
71.25 + */
71.26 +
71.27 +import java.lang.instrument.*;
71.28 +import java.net.*;
71.29 +import java.util.*;
71.30 +import java.io.*;
71.31 +
71.32 +public class RedefineClassWithNativeMethodAgent {
71.33 + static Class clz;
71.34 +
71.35 + // just read the original class and redefine it via a Timer
71.36 + public static void premain(String agentArgs, final Instrumentation inst) throws Exception {
71.37 + String s = agentArgs.substring(0, agentArgs.indexOf(".class"));
71.38 + clz = Class.forName(s.replace('/', '.'));
71.39 + ClassLoader loader =
71.40 + RedefineClassWithNativeMethodAgent.class.getClassLoader();
71.41 + URL classURL = loader.getResource(agentArgs);
71.42 + if (classURL == null) {
71.43 + throw new Exception("Cannot find class: " + agentArgs);
71.44 + }
71.45 +
71.46 + int redefineLength;
71.47 + InputStream redefineStream;
71.48 +
71.49 + System.out.println("Reading test class from " + classURL);
71.50 + if (classURL.getProtocol().equals("file")) {
71.51 + File f = new File(classURL.getFile());
71.52 + redefineStream = new FileInputStream(f);
71.53 + redefineLength = (int) f.length();
71.54 + } else {
71.55 + URLConnection conn = classURL.openConnection();
71.56 + redefineStream = conn.getInputStream();
71.57 + redefineLength = conn.getContentLength();
71.58 + }
71.59 +
71.60 + final byte[] buffer = new byte[redefineLength];
71.61 + new BufferedInputStream(redefineStream).read(buffer);
71.62 + new Timer(true).schedule(new TimerTask() {
71.63 + public void run() {
71.64 + try {
71.65 + System.out.println("Instrumenting");
71.66 + ClassDefinition cld = new ClassDefinition(clz, buffer);
71.67 + inst.redefineClasses(new ClassDefinition[] { cld });
71.68 + }
71.69 + catch (Exception e) { e.printStackTrace(); }
71.70 + }
71.71 + }, 500);
71.72 + }
71.73 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/test/java/lang/instrument/RedefineClassWithNativeMethodApp.java Fri Apr 18 16:40:32 2008 -0700
72.3 @@ -0,0 +1,38 @@
72.4 +/*
72.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72.7 + *
72.8 + * This code is free software; you can redistribute it and/or modify it
72.9 + * under the terms of the GNU General Public License version 2 only, as
72.10 + * published by the Free Software Foundation.
72.11 + *
72.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
72.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
72.15 + * version 2 for more details (a copy is included in the LICENSE file that
72.16 + * accompanied this code).
72.17 + *
72.18 + * You should have received a copy of the GNU General Public License version
72.19 + * 2 along with this work; if not, write to the Free Software Foundation,
72.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72.21 + *
72.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
72.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
72.24 + * have any questions.
72.25 + */
72.26 +
72.27 +public class RedefineClassWithNativeMethodApp {
72.28 + public static void main(String[] args) throws Exception {
72.29 + try {
72.30 + // give the agent a chance to redefine the target class
72.31 + Thread.sleep(2000);
72.32 + } catch (InterruptedException ie) {
72.33 + }
72.34 +
72.35 + System.out.println("Creating instance of " +
72.36 + RedefineClassWithNativeMethodAgent.clz);
72.37 + RedefineClassWithNativeMethodAgent.clz.newInstance();
72.38 +
72.39 + System.exit(0);
72.40 + }
72.41 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvoke.sh Fri Apr 18 16:40:32 2008 -0700
73.3 @@ -0,0 +1,82 @@
73.4 +#
73.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
73.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73.7 +#
73.8 +# This code is free software; you can redistribute it and/or modify it
73.9 +# under the terms of the GNU General Public License version 2 only, as
73.10 +# published by the Free Software Foundation.
73.11 +#
73.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
73.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
73.15 +# version 2 for more details (a copy is included in the LICENSE file that
73.16 +# accompanied this code).
73.17 +#
73.18 +# You should have received a copy of the GNU General Public License version
73.19 +# 2 along with this work; if not, write to the Free Software Foundation,
73.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73.21 +#
73.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
73.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
73.24 +# have any questions.
73.25 +#
73.26 +
73.27 +# @test
73.28 +# @bug 6667089
73.29 +# @summary Reflexive invocation of newly added methods broken.
73.30 +# @author Daniel D. Daugherty
73.31 +#
73.32 +# @run shell MakeJAR3.sh RedefineMethodAddInvokeAgent 'Can-Redefine-Classes: true'
73.33 +# @run build RedefineMethodAddInvokeApp
73.34 +# @run shell RedefineMethodAddInvoke.sh
73.35 +#
73.36 +
73.37 +if [ "${TESTJAVA}" = "" ]
73.38 +then
73.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
73.40 + exit 1
73.41 +fi
73.42 +
73.43 +if [ "${TESTSRC}" = "" ]
73.44 +then
73.45 + echo "TESTSRC not set. Test cannot execute. Failed."
73.46 + exit 1
73.47 +fi
73.48 +
73.49 +if [ "${TESTCLASSES}" = "" ]
73.50 +then
73.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
73.52 + exit 1
73.53 +fi
73.54 +
73.55 +JAVAC="${TESTJAVA}"/bin/javac
73.56 +JAVA="${TESTJAVA}"/bin/java
73.57 +
73.58 +cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_1.java \
73.59 + RedefineMethodAddInvokeTarget.java
73.60 +"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
73.61 +mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_1.java
73.62 +mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_1.class
73.63 +
73.64 +cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_2.java \
73.65 + RedefineMethodAddInvokeTarget.java
73.66 +"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
73.67 +mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_2.java
73.68 +mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_2.class
73.69 +
73.70 +"${JAVA}" ${TESTVMOPTS} -javaagent:RedefineMethodAddInvokeAgent.jar \
73.71 + -classpath "${TESTCLASSES}" RedefineMethodAddInvokeApp > output.log 2>&1
73.72 +cat output.log
73.73 +
73.74 +MESG="Exception"
73.75 +grep "$MESG" output.log
73.76 +result=$?
73.77 +if [ "$result" = 0 ]; then
73.78 + echo "FAIL: found '$MESG' in the test output"
73.79 + result=1
73.80 +else
73.81 + echo "PASS: did NOT find '$MESG' in the test output"
73.82 + result=0
73.83 +fi
73.84 +
73.85 +exit $result
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvokeAgent.java Fri Apr 18 16:40:32 2008 -0700
74.3 @@ -0,0 +1,43 @@
74.4 +/*
74.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74.7 + *
74.8 + * This code is free software; you can redistribute it and/or modify it
74.9 + * under the terms of the GNU General Public License version 2 only, as
74.10 + * published by the Free Software Foundation.
74.11 + *
74.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
74.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74.15 + * version 2 for more details (a copy is included in the LICENSE file that
74.16 + * accompanied this code).
74.17 + *
74.18 + * You should have received a copy of the GNU General Public License version
74.19 + * 2 along with this work; if not, write to the Free Software Foundation,
74.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74.21 + *
74.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
74.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
74.24 + * have any questions.
74.25 + */
74.26 +
74.27 +import java.lang.instrument.Instrumentation;
74.28 +
74.29 +public class RedefineMethodAddInvokeAgent {
74.30 + private static Instrumentation instrumentation;
74.31 +
74.32 + private RedefineMethodAddInvokeAgent() {
74.33 + }
74.34 +
74.35 + public static void premain(String agentArgs, Instrumentation inst) {
74.36 + System.out.println("Hello from RedefineMethodAddInvokeAgent!");
74.37 + System.out.println("isRedefineClassesSupported()=" +
74.38 + inst.isRedefineClassesSupported());
74.39 +
74.40 + instrumentation = inst;
74.41 + }
74.42 +
74.43 + public static Instrumentation getInstrumentation() {
74.44 + return instrumentation;
74.45 + }
74.46 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvokeApp.java Fri Apr 18 16:40:32 2008 -0700
75.3 @@ -0,0 +1,70 @@
75.4 +/*
75.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
75.7 + *
75.8 + * This code is free software; you can redistribute it and/or modify it
75.9 + * under the terms of the GNU General Public License version 2 only, as
75.10 + * published by the Free Software Foundation.
75.11 + *
75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
75.15 + * version 2 for more details (a copy is included in the LICENSE file that
75.16 + * accompanied this code).
75.17 + *
75.18 + * You should have received a copy of the GNU General Public License version
75.19 + * 2 along with this work; if not, write to the Free Software Foundation,
75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
75.21 + *
75.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
75.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
75.24 + * have any questions.
75.25 + */
75.26 +
75.27 +import java.io.*;
75.28 +import java.lang.instrument.*;
75.29 +
75.30 +public class RedefineMethodAddInvokeApp {
75.31 + public static void main(String args[]) throws Exception {
75.32 + System.out.println("Hello from RedefineMethodAddInvokeApp!");
75.33 +
75.34 + new RedefineMethodAddInvokeApp().doTest();
75.35 +
75.36 + System.exit(0);
75.37 + }
75.38 +
75.39 + private void doTest() throws Exception {
75.40 + RedefineMethodAddInvokeTarget target =
75.41 + new RedefineMethodAddInvokeTarget();
75.42 +
75.43 + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod()");
75.44 + target.test(0); // invoke the original myMethod()
75.45 +
75.46 + // add myMethod1()
75.47 + do_redefine(1);
75.48 +
75.49 + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod1()");
75.50 + target.test(1); // invoke myMethod1()
75.51 +
75.52 + // add myMethod2()
75.53 + do_redefine(2);
75.54 +
75.55 + System.out.println("RedefineMethodAddInvokeApp: invoking myMethod2()");
75.56 + target.test(2); // invoke myMethod2()
75.57 + }
75.58 +
75.59 + private static void do_redefine(int counter) throws Exception {
75.60 + File f = new File("RedefineMethodAddInvokeTarget_" + counter +
75.61 + ".class");
75.62 + System.out.println("Reading test class from " + f);
75.63 + InputStream redefineStream = new FileInputStream(f);
75.64 +
75.65 + byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream);
75.66 +
75.67 + ClassDefinition redefineParamBlock = new ClassDefinition(
75.68 + RedefineMethodAddInvokeTarget.class, redefineBuffer);
75.69 +
75.70 + RedefineMethodAddInvokeAgent.getInstrumentation().redefineClasses(
75.71 + new ClassDefinition[] {redefineParamBlock});
75.72 + }
75.73 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
76.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvokeTarget.java Fri Apr 18 16:40:32 2008 -0700
76.3 @@ -0,0 +1,37 @@
76.4 +/*
76.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76.7 + *
76.8 + * This code is free software; you can redistribute it and/or modify it
76.9 + * under the terms of the GNU General Public License version 2 only, as
76.10 + * published by the Free Software Foundation.
76.11 + *
76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
76.15 + * version 2 for more details (a copy is included in the LICENSE file that
76.16 + * accompanied this code).
76.17 + *
76.18 + * You should have received a copy of the GNU General Public License version
76.19 + * 2 along with this work; if not, write to the Free Software Foundation,
76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76.21 + *
76.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
76.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
76.24 + * have any questions.
76.25 + */
76.26 +
76.27 +import java.lang.reflect.Method;
76.28 +
76.29 +public class RedefineMethodAddInvokeTarget {
76.30 + public void test(int counter) throws Exception {
76.31 + Method method = getClass().getDeclaredMethod("myMethod" +
76.32 + (counter == 0 ? "" : counter));
76.33 + method.setAccessible(true);
76.34 + method.invoke(this);
76.35 + }
76.36 +
76.37 + public void myMethod() {
76.38 + System.out.println("Hello from the original myMethod()!");
76.39 + }
76.40 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
77.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvokeTarget_1.java Fri Apr 18 16:40:32 2008 -0700
77.3 @@ -0,0 +1,43 @@
77.4 +/*
77.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
77.7 + *
77.8 + * This code is free software; you can redistribute it and/or modify it
77.9 + * under the terms of the GNU General Public License version 2 only, as
77.10 + * published by the Free Software Foundation.
77.11 + *
77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
77.15 + * version 2 for more details (a copy is included in the LICENSE file that
77.16 + * accompanied this code).
77.17 + *
77.18 + * You should have received a copy of the GNU General Public License version
77.19 + * 2 along with this work; if not, write to the Free Software Foundation,
77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
77.21 + *
77.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
77.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
77.24 + * have any questions.
77.25 + */
77.26 +
77.27 +import java.lang.reflect.Method;
77.28 +
77.29 +public class RedefineMethodAddInvokeTarget {
77.30 + public void test(int counter) throws Exception {
77.31 + Method method = getClass().getDeclaredMethod("myMethod" +
77.32 + (counter == 0 ? "" : counter));
77.33 + method.setAccessible(true);
77.34 + method.invoke(this);
77.35 + }
77.36 +
77.37 + public void myMethod() {
77.38 + System.out.println("Hello from the non-EMCP myMethod()!");
77.39 + }
77.40 +
77.41 + private final void myMethod1() {
77.42 + System.out.println("Hello from myMethod1()!");
77.43 + System.out.println("Calling myMethod() from myMethod1():");
77.44 + myMethod();
77.45 + }
77.46 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/test/java/lang/instrument/RedefineMethodAddInvokeTarget_2.java Fri Apr 18 16:40:32 2008 -0700
78.3 @@ -0,0 +1,49 @@
78.4 +/*
78.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78.7 + *
78.8 + * This code is free software; you can redistribute it and/or modify it
78.9 + * under the terms of the GNU General Public License version 2 only, as
78.10 + * published by the Free Software Foundation.
78.11 + *
78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78.15 + * version 2 for more details (a copy is included in the LICENSE file that
78.16 + * accompanied this code).
78.17 + *
78.18 + * You should have received a copy of the GNU General Public License version
78.19 + * 2 along with this work; if not, write to the Free Software Foundation,
78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78.21 + *
78.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
78.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
78.24 + * have any questions.
78.25 + */
78.26 +
78.27 +import java.lang.reflect.Method;
78.28 +
78.29 +public class RedefineMethodAddInvokeTarget {
78.30 + public void test(int counter) throws Exception {
78.31 + Method method = getClass().getDeclaredMethod("myMethod" +
78.32 + (counter == 0 ? "" : counter));
78.33 + method.setAccessible(true);
78.34 + method.invoke(this);
78.35 + }
78.36 +
78.37 + public void myMethod() {
78.38 + System.out.println("Hello from the non-EMCP again myMethod()!");
78.39 + }
78.40 +
78.41 + private final void myMethod1() {
78.42 + System.out.println("Hello from myMethod1()!");
78.43 + System.out.println("Calling myMethod() from myMethod1():");
78.44 + myMethod();
78.45 + }
78.46 +
78.47 + private final void myMethod2() {
78.48 + System.out.println("Hello from myMethod2()!");
78.49 + System.out.println("Calling myMethod1() from myMethod2():");
78.50 + myMethod1();
78.51 + }
78.52 +}
79.1 --- a/test/java/lang/instrument/RetransformAgent.java Fri Apr 18 12:47:38 2008 -0700
79.2 +++ b/test/java/lang/instrument/RetransformAgent.java Fri Apr 18 16:40:32 2008 -0700
79.3 @@ -27,7 +27,7 @@
79.4 * @summary test retransformClasses
79.5 * @author Robert Field, Sun Microsystems
79.6 *
79.7 - * @run shell MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true'
79.8 + * @run shell/timeout=240 MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true'
79.9 * @run main/othervm -javaagent:RetransformAgent.jar RetransformApp
79.10 */
79.11
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80.2 +++ b/test/java/lang/instrument/StressGetObjectSizeApp.java Fri Apr 18 16:40:32 2008 -0700
80.3 @@ -0,0 +1,86 @@
80.4 +/*
80.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80.7 + *
80.8 + * This code is free software; you can redistribute it and/or modify it
80.9 + * under the terms of the GNU General Public License version 2 only, as
80.10 + * published by the Free Software Foundation.
80.11 + *
80.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
80.15 + * version 2 for more details (a copy is included in the LICENSE file that
80.16 + * accompanied this code).
80.17 + *
80.18 + * You should have received a copy of the GNU General Public License version
80.19 + * 2 along with this work; if not, write to the Free Software Foundation,
80.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
80.21 + *
80.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
80.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
80.24 + * have any questions.
80.25 + */
80.26 +
80.27 +import java.lang.instrument.Instrumentation;
80.28 +
80.29 +public class StressGetObjectSizeApp
80.30 + extends ASimpleInstrumentationTestCase
80.31 +{
80.32 +
80.33 + /**
80.34 + * Constructor for StressGetObjectSizeApp.
80.35 + * @param name
80.36 + */
80.37 + public StressGetObjectSizeApp(String name)
80.38 + {
80.39 + super(name);
80.40 + }
80.41 +
80.42 + public static void
80.43 + main (String[] args)
80.44 + throws Throwable {
80.45 + ATestCaseScaffold test = new StressGetObjectSizeApp(args[0]);
80.46 + test.runTest();
80.47 + }
80.48 +
80.49 + protected final void
80.50 + doRunTest()
80.51 + throws Throwable {
80.52 + stressGetObjectSize();
80.53 + }
80.54 +
80.55 + public void stressGetObjectSize() {
80.56 + System.out.println("main: an object size=" +
80.57 + fInst.getObjectSize(new Object()));
80.58 +
80.59 + RoundAndRound[] threads = new RoundAndRound[10];
80.60 + for (int i = 0; i < threads.length; ++i) {
80.61 + threads[i] = new RoundAndRound(fInst);
80.62 + threads[i].start();
80.63 + }
80.64 + try {
80.65 + Thread.sleep(500); // let all threads get going in their loops
80.66 + } catch (InterruptedException ie) {
80.67 + }
80.68 + System.out.println("stressGetObjectSize: returning");
80.69 + return;
80.70 + }
80.71 +
80.72 + private static class RoundAndRound extends Thread {
80.73 + private final Instrumentation inst;
80.74 + private final Object anObject;
80.75 +
80.76 + public RoundAndRound(Instrumentation inst) {
80.77 + this.inst = inst;
80.78 + this.anObject = new Object();
80.79 + setDaemon(true);
80.80 + }
80.81 +
80.82 + public void run() {
80.83 + long sum = 0;
80.84 + while (true) {
80.85 + sum += inst.getObjectSize(anObject);
80.86 + }
80.87 + }
80.88 + }
80.89 +}
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
81.2 +++ b/test/java/lang/instrument/StressGetObjectSizeTest.sh Fri Apr 18 16:40:32 2008 -0700
81.3 @@ -0,0 +1,70 @@
81.4 +#
81.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
81.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81.7 +#
81.8 +# This code is free software; you can redistribute it and/or modify it
81.9 +# under the terms of the GNU General Public License version 2 only, as
81.10 +# published by the Free Software Foundation.
81.11 +#
81.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
81.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
81.15 +# version 2 for more details (a copy is included in the LICENSE file that
81.16 +# accompanied this code).
81.17 +#
81.18 +# You should have received a copy of the GNU General Public License version
81.19 +# 2 along with this work; if not, write to the Free Software Foundation,
81.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81.21 +#
81.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
81.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
81.24 +# have any questions.
81.25 +#
81.26 +
81.27 +# @test
81.28 +# @bug 6572160
81.29 +# @summary stress getObjectSize() API
81.30 +# @author Daniel D. Daugherty as modified from the code of fischman@google.com
81.31 +#
81.32 +# @run build StressGetObjectSizeApp
81.33 +# @run shell MakeJAR.sh basicAgent
81.34 +# @run shell StressGetObjectSizeTest.sh
81.35 +#
81.36 +
81.37 +if [ "${TESTJAVA}" = "" ]
81.38 +then
81.39 + echo "TESTJAVA not set. Test cannot execute. Failed."
81.40 + exit 1
81.41 +fi
81.42 +
81.43 +if [ "${TESTSRC}" = "" ]
81.44 +then
81.45 + echo "TESTSRC not set. Test cannot execute. Failed."
81.46 + exit 1
81.47 +fi
81.48 +
81.49 +if [ "${TESTCLASSES}" = "" ]
81.50 +then
81.51 + echo "TESTCLASSES not set. Test cannot execute. Failed."
81.52 + exit 1
81.53 +fi
81.54 +
81.55 +JAVA="${TESTJAVA}"/bin/java
81.56 +
81.57 +"${JAVA}" ${TESTVMOPTS} -javaagent:basicAgent.jar \
81.58 + -classpath "${TESTCLASSES}" StressGetObjectSizeApp StressGetObjectSizeApp \
81.59 + > output.log 2>&1
81.60 +cat output.log
81.61 +
81.62 +MESG="ASSERTION FAILED"
81.63 +grep "$MESG" output.log
81.64 +result=$?
81.65 +if [ "$result" = 0 ]; then
81.66 + echo "FAIL: found '$MESG' in the test output"
81.67 + result=1
81.68 +else
81.69 + echo "PASS: did NOT find '$MESG' in the test output"
81.70 + result=0
81.71 +fi
81.72 +
81.73 +exit $result
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
82.2 +++ b/test/java/lang/instrument/TestClass1.java Fri Apr 18 16:40:32 2008 -0700
82.3 @@ -0,0 +1,36 @@
82.4 +/*
82.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82.7 + *
82.8 + * This code is free software; you can redistribute it and/or modify it
82.9 + * under the terms of the GNU General Public License version 2 only, as
82.10 + * published by the Free Software Foundation.
82.11 + *
82.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
82.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
82.15 + * version 2 for more details (a copy is included in the LICENSE file that
82.16 + * accompanied this code).
82.17 + *
82.18 + * You should have received a copy of the GNU General Public License version
82.19 + * 2 along with this work; if not, write to the Free Software Foundation,
82.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82.21 + *
82.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
82.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
82.24 + * have any questions.
82.25 + */
82.26 +
82.27 +/**
82.28 + * Test Java Program
82.29 + *
82.30 + * @author Daryl Puryear
82.31 + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
82.32 + */
82.33 +public class TestClass1
82.34 +{
82.35 + public
82.36 + TestClass1()
82.37 + {
82.38 + }
82.39 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83.2 +++ b/test/java/lang/instrument/TestClass2.java Fri Apr 18 16:40:32 2008 -0700
83.3 @@ -0,0 +1,36 @@
83.4 +/*
83.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83.7 + *
83.8 + * This code is free software; you can redistribute it and/or modify it
83.9 + * under the terms of the GNU General Public License version 2 only, as
83.10 + * published by the Free Software Foundation.
83.11 + *
83.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
83.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
83.15 + * version 2 for more details (a copy is included in the LICENSE file that
83.16 + * accompanied this code).
83.17 + *
83.18 + * You should have received a copy of the GNU General Public License version
83.19 + * 2 along with this work; if not, write to the Free Software Foundation,
83.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83.21 + *
83.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
83.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
83.24 + * have any questions.
83.25 + */
83.26 +
83.27 +/**
83.28 + * Test Java Program
83.29 + *
83.30 + * @author Daryl Puryear
83.31 + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
83.32 + */
83.33 +public class TestClass2
83.34 +{
83.35 + public
83.36 + TestClass2()
83.37 + {
83.38 + }
83.39 +}
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
84.2 +++ b/test/java/lang/instrument/TestClass3.java Fri Apr 18 16:40:32 2008 -0700
84.3 @@ -0,0 +1,36 @@
84.4 +/*
84.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84.7 + *
84.8 + * This code is free software; you can redistribute it and/or modify it
84.9 + * under the terms of the GNU General Public License version 2 only, as
84.10 + * published by the Free Software Foundation.
84.11 + *
84.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
84.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84.15 + * version 2 for more details (a copy is included in the LICENSE file that
84.16 + * accompanied this code).
84.17 + *
84.18 + * You should have received a copy of the GNU General Public License version
84.19 + * 2 along with this work; if not, write to the Free Software Foundation,
84.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84.21 + *
84.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
84.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
84.24 + * have any questions.
84.25 + */
84.26 +
84.27 +/**
84.28 + * Test Java Program
84.29 + *
84.30 + * @author Daryl Puryear
84.31 + * @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
84.32 + */
84.33 +public class TestClass3
84.34 +{
84.35 + public
84.36 + TestClass3()
84.37 + {
84.38 + }
84.39 +}
85.1 --- a/test/java/lang/instrument/TransformerManagementThreadAddTests.java Fri Apr 18 12:47:38 2008 -0700
85.2 +++ b/test/java/lang/instrument/TransformerManagementThreadAddTests.java Fri Apr 18 16:40:32 2008 -0700
85.3 @@ -79,6 +79,12 @@
85.4 protected static final int TOTAL_THREADS = MAX_TRANS - MIN_TRANS + 1;
85.5
85.6 private byte[] fDummyClassBytes;
85.7 + // fCheckedTransformers is a Vector that is used to verify
85.8 + // that the transform() function is called in the same
85.9 + // order in which the transformers were added to the
85.10 + // TransformerManager. The test currently verifies that all
85.11 + // transformers for a specific worker thread are in
85.12 + // increasing order by index value.
85.13 private Vector fCheckedTransformers;
85.14 private Instrumentation fInstrumentation;
85.15 private int fFinished;
85.16 @@ -131,9 +137,16 @@
85.17 threads[i].start();
85.18 }
85.19
85.20 - while (!exec.fDone)
85.21 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.22 + // Don't use a direct field getter.
85.23 + while (!exec.isDone())
85.24 {
85.25 - Thread.currentThread().yield();
85.26 + // Effective Java - Item 51: Don't depend on the thread scheduler
85.27 + // Use sleep() instead of yield().
85.28 + try {
85.29 + Thread.sleep(500);
85.30 + } catch (InterruptedException ie) {
85.31 + }
85.32 }
85.33 assertTrue(finalCheck());
85.34
85.35 @@ -169,13 +182,17 @@
85.36 this.fExec = exec;
85.37 }
85.38
85.39 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.40 + // Document a synchronized setter.
85.41 protected synchronized void
85.42 threadFinished(Thread t)
85.43 {
85.44 fFinished++;
85.45 }
85.46
85.47 - protected boolean
85.48 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.49 + // Provide synchronized getter.
85.50 + protected synchronized boolean
85.51 threadsDone()
85.52 {
85.53 return fFinished == TOTAL_THREADS;
85.54 @@ -188,7 +205,9 @@
85.55 protected boolean
85.56 testCompleted()
85.57 {
85.58 - return getExecThread().fDone;
85.59 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.60 + // Don't use direct field getter.
85.61 + return getExecThread().isDone();
85.62 }
85.63
85.64 /**
85.65 @@ -264,11 +283,19 @@
85.66 private void
85.67 executeTransform()
85.68 {
85.69 - fCheckedTransformers.clear();
85.70 -
85.71 try
85.72 {
85.73 ClassDefinition cd = new ClassDefinition(DummyClass.class, fDummyClassBytes);
85.74 +
85.75 + // When the ClassDefinition above is created for the first
85.76 + // time and every time redefineClasses() below is called,
85.77 + // the transform() function is called for each registered
85.78 + // transformer. We only want one complete set of calls to
85.79 + // be logged in the fCheckedTransformers Vector so we clear
85.80 + // any calls logged for ClassDefinition above and just use
85.81 + // the ones logged for redefineClasses() below.
85.82 + fCheckedTransformers.clear();
85.83 +
85.84 getInstrumentation().redefineClasses(new ClassDefinition[]{ cd });
85.85 }
85.86 catch (ClassNotFoundException e)
85.87 @@ -325,6 +352,18 @@
85.88 {
85.89 private boolean fDone = false;
85.90
85.91 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.92 + // Provide a synchronized getter.
85.93 + private synchronized boolean isDone() {
85.94 + return fDone;
85.95 + }
85.96 +
85.97 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.98 + // Provide a synchronized setter.
85.99 + private synchronized void setIsDone() {
85.100 + fDone = true;
85.101 + }
85.102 +
85.103 public void
85.104 run()
85.105 {
85.106 @@ -335,7 +374,9 @@
85.107
85.108 // Do a final check for good measure
85.109 executeTransform();
85.110 - fDone = true;
85.111 + // Effective Java - Item 48: Synchronize access to shared mutable data
85.112 + // Don't use direct field setter.
85.113 + setIsDone();
85.114 }
85.115 }
85.116
86.1 --- a/test/java/lang/instrument/TransformerManagementThreadRemoveTests.java Fri Apr 18 12:47:38 2008 -0700
86.2 +++ b/test/java/lang/instrument/TransformerManagementThreadRemoveTests.java Fri Apr 18 16:40:32 2008 -0700
86.3 @@ -27,10 +27,9 @@
86.4 * @summary multi-thread test to exercise sync and contention for removes to transformer registry
86.5 * @author Gabriel Adauto, Wily Technology
86.6 *
86.7 - * @ignore Disabled until race condition which hangs test can be fixed.
86.8 * @run build TransformerManagementThreadRemoveTests
86.9 - * @run shell MakeJAR.sh basicAgent
86.10 - * @run main/othervm -javaagent:basicAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
86.11 + * @run shell MakeJAR.sh redefineAgent
86.12 + * @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
86.13 */
86.14 import java.util.*;
86.15
86.16 @@ -87,7 +86,12 @@
86.17
86.18 while (!testCompleted())
86.19 {
86.20 - Thread.currentThread().yield();
86.21 + // Effective Java - Item 51: Don't depend on the thread scheduler
86.22 + // Use sleep() instead of yield().
86.23 + try {
86.24 + Thread.sleep(500);
86.25 + } catch (InterruptedException ie) {
86.26 + }
86.27 }
86.28 assertTrue(finalCheck());
86.29
87.1 --- a/test/java/lang/instrument/appendToClassLoaderSearch/CircularityErrorTest.sh Fri Apr 18 12:47:38 2008 -0700
87.2 +++ b/test/java/lang/instrument/appendToClassLoaderSearch/CircularityErrorTest.sh Fri Apr 18 16:40:32 2008 -0700
87.3 @@ -26,14 +26,14 @@
87.4 # @summary Unit tests for appendToBootstrapClassLoaderSearch and
87.5 # appendToSystemClasLoaderSearch methods.
87.6 #
87.7 -# @run shell CircularityErrorTest.sh
87.8 +# @run shell/timeout=240 CircularityErrorTest.sh
87.9
87.10 if [ "${TESTSRC}" = "" ]
87.11 then
87.12 echo "TESTSRC not set. Test cannot execute. Failed."
87.13 exit 1
87.14 fi
87.15 -
87.16 +
87.17 . ${TESTSRC}/CommonSetup.sh
87.18
87.19 # Setup to create circularity condition
87.20 @@ -71,5 +71,5 @@
87.21 -C "${TESTCLASSES}" CircularityErrorTest.class
87.22
87.23 # Finally we run the test
87.24 -(cd "${TESTCLASSES}";
87.25 - $JAVA -javaagent:CircularityErrorTest.jar CircularityErrorTest)
87.26 +(cd "${TESTCLASSES}";
87.27 + $JAVA ${TESTVMOPTS} -javaagent:CircularityErrorTest.jar CircularityErrorTest)
88.1 --- a/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Fri Apr 18 12:47:38 2008 -0700
88.2 +++ b/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Fri Apr 18 16:40:32 2008 -0700
88.3 @@ -34,11 +34,11 @@
88.4 echo "TESTSRC not set. Test cannot execute. Failed."
88.5 exit 1
88.6 fi
88.7 -
88.8 +
88.9 . ${TESTSRC}/CommonSetup.sh
88.10
88.11 # Create Foo and Bar
88.12 -# Foo has a reference to Bar but we deleted Bar so that
88.13 +# Foo has a reference to Bar but we deleted Bar so that
88.14 # a NoClassDefFoundError will be thrown when Foo tries to
88.15 # resolve the reference to Bar
88.16
88.17 @@ -53,11 +53,11 @@
88.18 public class Foo {
88.19 public static boolean doSomething() {
88.20 try {
88.21 - Bar b = new Bar();
88.22 - return true;
88.23 - } catch (NoClassDefFoundError x) {
88.24 - return false;
88.25 - }
88.26 + Bar b = new Bar();
88.27 + return true;
88.28 + } catch (NoClassDefFoundError x) {
88.29 + return false;
88.30 + }
88.31 }
88.32 }
88.33 EOF
88.34 @@ -79,5 +79,5 @@
88.35
88.36 # Finally we run the test
88.37 (cd "${TESTCLASSES}"; \
88.38 - $JAVA -Xverify:none -XX:+TraceClassUnloading -javaagent:ClassUnloadTest.jar \
88.39 - ClassUnloadTest "${OTHERDIR}" Bar.jar)
88.40 + $JAVA ${TESTVMOPTS} -Xverify:none -XX:+TraceClassUnloading \
88.41 + -javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)
89.1 --- a/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh Fri Apr 18 12:47:38 2008 -0700
89.2 +++ b/test/java/lang/instrument/appendToClassLoaderSearch/CommonSetup.sh Fri Apr 18 16:40:32 2008 -0700
89.3 @@ -24,7 +24,6 @@
89.4 #
89.5
89.6
89.7 -#%E
89.8 #
89.9 # Common setup for unit tests. Setups up the following variables:
89.10 #
89.11 @@ -66,7 +65,7 @@
89.12 echo "TESTSRC not set. Test cannot execute. Failed."
89.13 exit 1
89.14 fi
89.15 -
89.16 +
89.17 if [ "${TESTCLASSES}" = "" ]
89.18 then
89.19 echo "TESTCLASSES not set. Test cannot execute. Failed."
90.1 --- a/test/java/lang/instrument/appendToClassLoaderSearch/run_tests.sh Fri Apr 18 12:47:38 2008 -0700
90.2 +++ b/test/java/lang/instrument/appendToClassLoaderSearch/run_tests.sh Fri Apr 18 16:40:32 2008 -0700
90.3 @@ -23,24 +23,24 @@
90.4 # have any questions.
90.5 #
90.6
90.7 -
90.8 +
90.9 # @test
90.10 # @bug 6173575 6388987
90.11 -# @summary Unit tests for appendToBootstrapClassLoaderSearch and
90.12 +# @summary Unit tests for appendToBootstrapClassLoaderSearch and
90.13 # appendToSystemClasLoaderSearch methods.
90.14 #
90.15 # @build Agent AgentSupport BootSupport BasicTest PrematureLoadTest DynamicTest
90.16 -# @run shell run_tests.sh
90.17 +# @run shell/timeout=240 run_tests.sh
90.18
90.19 if [ "${TESTSRC}" = "" ]
90.20 then
90.21 echo "TESTSRC not set. Test cannot execute. Failed."
90.22 exit 1
90.23 fi
90.24 -
90.25 +
90.26 . ${TESTSRC}/CommonSetup.sh
90.27
90.28 -
90.29 +
90.30 # Simple tests
90.31
90.32 echo "Creating jar files for simple tests..."
90.33 @@ -50,13 +50,13 @@
90.34 "$JAR" -cfm Agent.jar "${TESTSRC}"/manifest.mf Agent.class
90.35 "$JAR" -cf AgentSupport.jar AgentSupport.class
90.36 "$JAR" -cf BootSupport.jar BootSupport.class
90.37 -"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class
90.38 +"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class
90.39
90.40 failures=0
90.41
90.42 go() {
90.43 echo ''
90.44 - sh -xc "$JAVA -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1
90.45 + sh -xc "$JAVA ${TESTVMOPTS} -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1
90.46 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90.47 }
90.48
90.49 @@ -75,7 +75,7 @@
90.50 "${JAVAC}" -d tmp "${TESTSRC}"/Tracer.java
90.51 (cd tmp; "${JAR}" cf ../Tracer.jar org/tools/Tracer.class)
90.52
90.53 -# InstrumentedApplication is Application+instrmentation - don't copy as
90.54 +# InstrumentedApplication is Application+instrmentation - don't copy as
90.55 # we don't want the original file permission
90.56
90.57 cat "${TESTSRC}"/InstrumentedApplication.java > ./Application.java
90.58 @@ -85,11 +85,11 @@
90.59 cp "${TESTSRC}"/Application.java .
90.60 "${JAVAC}" -d . Application.java
90.61
90.62 -sh -xc "$JAVA -classpath . -javaagent:Agent.jar DynamicTest" 2>&1
90.63 +sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar DynamicTest" 2>&1
90.64 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90.65
90.66 # Repeat test with security manager
90.67 -sh -xc "$JAVA -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1
90.68 +sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1
90.69 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90.70
90.71 #
91.1 --- a/test/javax/crypto/Cipher/TestGetInstance.java Fri Apr 18 12:47:38 2008 -0700
91.2 +++ b/test/javax/crypto/Cipher/TestGetInstance.java Fri Apr 18 16:40:32 2008 -0700
91.3 @@ -1,5 +1,5 @@
91.4 /*
91.5 - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
91.6 + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
91.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
91.8 *
91.9 * This code is free software; you can redistribute it and/or modify it
91.10 @@ -46,9 +46,7 @@
91.11
91.12 Cipher c;
91.13
91.14 - c = Cipher.getInstance("des");
91.15 - same(p, c.getProvider());
91.16 - c = Cipher.getInstance("des/cbc/pkcs5padding");
91.17 + c = Cipher.getInstance("PBEWithMD5AndTripleDES");
91.18 same(p, c.getProvider());
91.19
91.20 c = Cipher.getInstance("des", "SunJCE");
92.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
92.2 +++ b/test/javax/management/modelmbean/LoggingExceptionTest.java Fri Apr 18 16:40:32 2008 -0700
92.3 @@ -0,0 +1,81 @@
92.4 +/*
92.5 + * @test
92.6 + * @bug 6471865 6675768
92.7 + * @summary DescriptorSupport constructors throw IAE when traces are enabled;
92.8 + * RequiredModelMBean.addAttributeChangeNotificationListener throws exception
92.9 + * when traces enabled and no attributes.
92.10 + * @author Luis-Miguel Alventosa
92.11 + * @author Paul Cheeseman
92.12 + */
92.13 +
92.14 +import java.util.logging.ConsoleHandler;
92.15 +import java.util.logging.Handler;
92.16 +import java.util.logging.Level;
92.17 +import java.util.logging.Logger;
92.18 +import javax.management.Notification;
92.19 +import javax.management.NotificationListener;
92.20 +import javax.management.modelmbean.DescriptorSupport;
92.21 +import javax.management.modelmbean.RequiredModelMBean;
92.22 +
92.23 +public class LoggingExceptionTest {
92.24 + private static final String tests[] = new String[] {
92.25 + "DescriptorSupport()",
92.26 + "DescriptorSupport(int)",
92.27 + "DescriptorSupport(String)",
92.28 + "DescriptorSupport(String...)",
92.29 + "DescriptorSupport(String[], Object[])",
92.30 + "DescriptorSupport(DescriptorSupport)",
92.31 + "RequiredModelMBean.addAttributeChangeNotificationListener",
92.32 + };
92.33 + public static void main(String[] args) {
92.34 + Handler handler = new ConsoleHandler();
92.35 + Logger logger = Logger.getLogger("javax.management.modelmbean");
92.36 + logger.addHandler(handler);
92.37 + logger.setLevel(Level.FINEST);
92.38 + try {
92.39 + for (int i = 0; i < tests.length; i++) {
92.40 + System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
92.41 + DescriptorSupport ds;
92.42 + String msg = "Instantiate " + tests[i];
92.43 + System.out.println(msg);
92.44 + switch (i) {
92.45 + case 0:
92.46 + ds = new DescriptorSupport();
92.47 + break;
92.48 + case 1:
92.49 + ds = new DescriptorSupport(10);
92.50 + break;
92.51 + case 2:
92.52 + ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
92.53 + break;
92.54 + case 3:
92.55 + ds = new DescriptorSupport("name1=value1", "name2=value2");
92.56 + break;
92.57 + case 4:
92.58 + ds = new DescriptorSupport(new String[] {"name"}, new Object[] {"value"});
92.59 + break;
92.60 + case 5:
92.61 + ds = new DescriptorSupport(new DescriptorSupport());
92.62 + break;
92.63 + case 6:
92.64 + RequiredModelMBean mbean = new RequiredModelMBean();
92.65 + NotificationListener nl = new NotificationListener() {
92.66 + public void handleNotification(Notification notification,
92.67 + Object handback) {}
92.68 + };
92.69 + mbean.addAttributeChangeNotificationListener(nl, null, null);
92.70 + break;
92.71 + default:
92.72 + throw new AssertionError();
92.73 + }
92.74 + System.out.println(msg + " OK");
92.75 + }
92.76 + } catch (Exception e) {
92.77 + System.out.println("Got unexpected exception = " + e);
92.78 + String msg = "Test FAILED!";
92.79 + System.out.println(msg);
92.80 + throw new IllegalArgumentException(msg);
92.81 + }
92.82 + System.out.println("Test PASSED!");
92.83 + }
92.84 +}
93.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
93.2 +++ b/test/javax/management/query/QueryNotifFilterTest.java Fri Apr 18 16:40:32 2008 -0700
93.3 @@ -0,0 +1,347 @@
93.4 +/*
93.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
93.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93.7 + *
93.8 + * This code is free software; you can redistribute it and/or modify it
93.9 + * under the terms of the GNU General Public License version 2 only, as
93.10 + * published by the Free Software Foundation.
93.11 + *
93.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
93.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93.15 + * version 2 for more details (a copy is included in the LICENSE file that
93.16 + * accompanied this code).
93.17 + *
93.18 + * You should have received a copy of the GNU General Public License version
93.19 + * 2 along with this work; if not, write to the Free Software Foundation,
93.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93.21 + *
93.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
93.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
93.24 + * have any questions.
93.25 + */
93.26 +
93.27 +/*
93.28 + * @test QueryNotifFilterTest
93.29 + * @bug 6610917
93.30 + * @summary Test the QueryNotificationFilter class
93.31 + * @author Eamonn McManus
93.32 + */
93.33 +
93.34 +import java.util.Arrays;
93.35 +import java.util.Collections;
93.36 +import java.util.HashSet;
93.37 +import java.util.List;
93.38 +import java.util.Set;
93.39 +import javax.management.Attribute;
93.40 +import javax.management.AttributeChangeNotification;
93.41 +import javax.management.MBeanAttributeInfo;
93.42 +import javax.management.MBeanInfo;
93.43 +import javax.management.MBeanServer;
93.44 +import javax.management.MalformedObjectNameException;
93.45 +import javax.management.Notification;
93.46 +import javax.management.NotificationFilter;
93.47 +import javax.management.ObjectInstance;
93.48 +import javax.management.ObjectName;
93.49 +import javax.management.Query;
93.50 +import javax.management.QueryEval;
93.51 +import javax.management.QueryExp;
93.52 +import javax.management.QueryNotificationFilter;
93.53 +
93.54 +public class QueryNotifFilterTest {
93.55 + private static class Case {
93.56 + final Notification notif;
93.57 + final QueryExp query;
93.58 + final boolean expect;
93.59 + final Class<? extends Notification> notifClass;
93.60 + Case(Notification notif, String query, boolean expect) {
93.61 + this(notif, query, notif.getClass(), expect);
93.62 + }
93.63 + Case(Notification notif, String query,
93.64 + Class<? extends Notification> notifClass, boolean expect) {
93.65 + this(notif, Query.fromString(query), notifClass, expect);
93.66 + }
93.67 + Case(Notification notif, QueryExp query, boolean expect) {
93.68 + this(notif, query, notif.getClass(), expect);
93.69 + }
93.70 + Case(Notification notif, QueryExp query,
93.71 + Class<? extends Notification> notifClass, boolean expect) {
93.72 + this.notif = notif;
93.73 + this.query = query;
93.74 + this.expect = expect;
93.75 + this.notifClass = notifClass;
93.76 + }
93.77 + }
93.78 +
93.79 + /* In principle users can create their own implementations of QueryExp
93.80 + * and use them with QueryNotificationFilter. If they do so, then
93.81 + * they can call any MBeanServer method. Not all of those methods
93.82 + * will work with the special MBeanServer we concoct to analyze a
93.83 + * Notification, but some will, including some that are not called
93.84 + * by the standard queries. So we check each of those cases too.
93.85 + */
93.86 + private static class ExoticCase {
93.87 + final Notification trueNotif;
93.88 + final Notification falseNotif;
93.89 + final QueryExp query;
93.90 + ExoticCase(Notification trueNotif, Notification falseNotif, QueryExp query) {
93.91 + this.trueNotif = trueNotif;
93.92 + this.falseNotif = falseNotif;
93.93 + this.query = query;
93.94 + }
93.95 + }
93.96 +
93.97 + private static abstract class ExoticQuery
93.98 + extends QueryEval implements QueryExp {
93.99 + private final String queryString;
93.100 + ExoticQuery(String queryString) {
93.101 + this.queryString = queryString;
93.102 + }
93.103 + abstract boolean apply(MBeanServer mbs, ObjectName name) throws Exception;
93.104 + @Override
93.105 + public boolean apply(ObjectName name) {
93.106 + try {
93.107 + return apply(getMBeanServer(), name);
93.108 + } catch (Exception e) {
93.109 + e.printStackTrace(System.out);
93.110 + return false;
93.111 + }
93.112 + }
93.113 + @Override
93.114 + public String toString() {
93.115 + return queryString;
93.116 + }
93.117 + }
93.118 +
93.119 + private static ObjectName makeObjectName(String s) {
93.120 + try {
93.121 + return new ObjectName(s);
93.122 + } catch (MalformedObjectNameException e) {
93.123 + throw new RuntimeException(e);
93.124 + }
93.125 + }
93.126 +
93.127 + public static class CustomNotification extends Notification {
93.128 + public CustomNotification(String type, Object source, long seqNo) {
93.129 + super(type, source, seqNo);
93.130 + }
93.131 +
93.132 + public String getName() {
93.133 + return "claude";
93.134 + }
93.135 +
93.136 + public boolean isInteresting() {
93.137 + return true;
93.138 + }
93.139 + }
93.140 +
93.141 + private static final Notification simpleNotif =
93.142 + new Notification("mytype", "source", 0L);
93.143 + private static final Notification attrChangeNotif =
93.144 + new AttributeChangeNotification(
93.145 + "x", 0L, 0L, "msg", "AttrName", "int", 2, 3);
93.146 + private static final ObjectName testObjectName = makeObjectName("a:b=c");
93.147 + private static final Notification sourcedNotif =
93.148 + new Notification("mytype", testObjectName, 0L);
93.149 + private static final Notification customNotif =
93.150 + new CustomNotification("mytype", testObjectName, 0L);
93.151 +
93.152 + private static final Case[] testCases = {
93.153 + new Case(simpleNotif, "Type = 'mytype'", true),
93.154 + new Case(simpleNotif, "Type = 'mytype'",
93.155 + Notification.class, true),
93.156 + new Case(simpleNotif, "Type = 'mytype'",
93.157 + AttributeChangeNotification.class, false),
93.158 + new Case(simpleNotif, "Type != 'mytype'", false),
93.159 + new Case(simpleNotif, "Type = 'somethingelse'", false),
93.160 + new Case(attrChangeNotif, "AttributeName = 'AttrName'", true),
93.161 + new Case(attrChangeNotif,
93.162 + "instanceof 'javax.management.AttributeChangeNotification'",
93.163 + true),
93.164 + new Case(attrChangeNotif,
93.165 + "instanceof 'javax.management.Notification'",
93.166 + true),
93.167 + new Case(attrChangeNotif,
93.168 + "instanceof 'javax.management.relation.MBeanServerNotification'",
93.169 + false),
93.170 + new Case(attrChangeNotif,
93.171 + "class = 'javax.management.AttributeChangeNotification'",
93.172 + true),
93.173 + new Case(attrChangeNotif,
93.174 + "javax.management.AttributeChangeNotification#AttributeName = 'AttrName'",
93.175 + true),
93.176 + new Case(sourcedNotif,
93.177 + testObjectName,
93.178 + true),
93.179 + new Case(sourcedNotif,
93.180 + makeObjectName("a*:b=*"),
93.181 + true),
93.182 + new Case(sourcedNotif,
93.183 + makeObjectName("a*:c=*"),
93.184 + false),
93.185 + new Case(customNotif, "Name = 'claude'", true),
93.186 + new Case(customNotif, "Name = 'tiddly'", false),
93.187 + new Case(customNotif, "Interesting = true", true),
93.188 + new Case(customNotif, "Interesting = false", false),
93.189 + };
93.190 +
93.191 + private static final ExoticCase[] exoticTestCases = {
93.192 + new ExoticCase(
93.193 + simpleNotif, new Notification("notmytype", "source", 0L),
93.194 + new ExoticQuery("getAttributes") {
93.195 + boolean apply(MBeanServer mbs, ObjectName name)
93.196 + throws Exception {
93.197 + List<Attribute> attrs = mbs.getAttributes(
93.198 + name, new String[] {"Type", "Source"}).asList();
93.199 + return (attrs.get(0).equals(new Attribute("Type", "mytype")) &&
93.200 + attrs.get(1).equals(new Attribute("Source", "source")));
93.201 + }
93.202 + }),
93.203 + new ExoticCase(
93.204 + new Notification("mytype", "source", 0L) {},
93.205 + simpleNotif,
93.206 + new ExoticQuery("getClassLoaderFor") {
93.207 + boolean apply(MBeanServer mbs, ObjectName name)
93.208 + throws Exception {
93.209 + return (mbs.getClassLoaderFor(name) ==
93.210 + this.getClass().getClassLoader());
93.211 + }
93.212 + }),
93.213 + new ExoticCase(
93.214 + sourcedNotif, simpleNotif,
93.215 + new ExoticQuery("getDomains") {
93.216 + boolean apply(MBeanServer mbs, ObjectName name)
93.217 + throws Exception {
93.218 + return Arrays.equals(mbs.getDomains(),
93.219 + new String[] {testObjectName.getDomain()});
93.220 + }
93.221 + }),
93.222 + new ExoticCase(
93.223 + simpleNotif, attrChangeNotif,
93.224 + new ExoticQuery("getMBeanInfo") {
93.225 + boolean apply(MBeanServer mbs, ObjectName name)
93.226 + throws Exception {
93.227 + MBeanInfo mbi = mbs.getMBeanInfo(name);
93.228 + // If we ever add a constructor to Notification then
93.229 + // we will have to change the 4 below.
93.230 + if (mbi.getOperations().length > 0 ||
93.231 + mbi.getConstructors().length != 4 ||
93.232 + mbi.getNotifications().length > 0)
93.233 + return false;
93.234 + Set<String> expect = new HashSet<String>(
93.235 + Arrays.asList(
93.236 + "Class", "Message", "SequenceNumber", "Source",
93.237 + "TimeStamp", "Type", "UserData"));
93.238 + Set<String> actual = new HashSet<String>();
93.239 + for (MBeanAttributeInfo mbai : mbi.getAttributes())
93.240 + actual.add(mbai.getName());
93.241 + return actual.equals(expect);
93.242 + }
93.243 + }),
93.244 + new ExoticCase(
93.245 + simpleNotif, attrChangeNotif,
93.246 + new ExoticQuery("getObjectInstance") {
93.247 + boolean apply(MBeanServer mbs, ObjectName name)
93.248 + throws Exception {
93.249 + ObjectInstance oi = mbs.getObjectInstance(name);
93.250 + return oi.getClassName().equals(Notification.class.getName());
93.251 + }
93.252 + }),
93.253 + new ExoticCase(
93.254 + sourcedNotif, simpleNotif,
93.255 + new ExoticQuery("queryNames") {
93.256 + boolean apply(MBeanServer mbs, ObjectName name)
93.257 + throws Exception {
93.258 + Set<ObjectName> names = mbs.queryNames(null,
93.259 + Query.eq(Query.attr("Type"), Query.value("mytype")));
93.260 + return names.equals(Collections.singleton(testObjectName));
93.261 + }
93.262 + }),
93.263 + new ExoticCase(
93.264 + sourcedNotif, simpleNotif,
93.265 + new ExoticQuery("queryMBeans") {
93.266 + boolean apply(MBeanServer mbs, ObjectName name)
93.267 + throws Exception {
93.268 + Set<ObjectInstance> insts = mbs.queryMBeans(null,
93.269 + Query.eq(Query.attr("Type"), Query.value("mytype")));
93.270 + if (insts.size() != 1)
93.271 + return false;
93.272 + ObjectInstance inst = insts.iterator().next();
93.273 + return (inst.getObjectName().equals(testObjectName) &&
93.274 + inst.getClassName().equals(Notification.class.getName()));
93.275 + }
93.276 + }),
93.277 + };
93.278 +
93.279 + private static enum Test {
93.280 + QUERY_EXP("query"), STRING("string"), STRING_PLUS_CLASS("string with class");
93.281 + private final String name;
93.282 + Test(String name) {
93.283 + this.name = name;
93.284 + }
93.285 + @Override
93.286 + public String toString() {
93.287 + return name;
93.288 + }
93.289 + }
93.290 +
93.291 + public static void main(String[] args) throws Exception {
93.292 + boolean allok = true;
93.293 + for (Case testCase : testCases) {
93.294 + for (Test test : Test.values()) {
93.295 + QueryNotificationFilter nf;
93.296 + String queryString;
93.297 + switch (test) {
93.298 + case QUERY_EXP: {
93.299 + QueryExp inst = Query.isInstanceOf(
93.300 + Query.value(testCase.notifClass.getName()));
93.301 + QueryExp and = Query.and(inst, testCase.query);
93.302 + queryString = Query.toString(and);
93.303 + nf = new QueryNotificationFilter(and);
93.304 + break;
93.305 + }
93.306 + case STRING: {
93.307 + String s = "instanceof '" + testCase.notifClass.getName() + "'";
93.308 + queryString = s + " and " + Query.toString(testCase.query);
93.309 + nf = new QueryNotificationFilter(queryString);
93.310 + break;
93.311 + }
93.312 + case STRING_PLUS_CLASS:
93.313 + queryString = null;
93.314 + nf = new QueryNotificationFilter(
93.315 + testCase.notifClass, Query.toString(testCase.query));
93.316 + break;
93.317 + default:
93.318 + throw new AssertionError();
93.319 + }
93.320 + boolean accept = nf.isNotificationEnabled(testCase.notif);
93.321 + if (queryString != null) {
93.322 + queryString = Query.toString(Query.fromString(queryString));
93.323 + if (!queryString.equals(Query.toString(nf.getQuery()))) {
93.324 + System.out.println("FAIL: query string mismatch: expected " +
93.325 + "\"" + queryString + "\", got \"" +
93.326 + Query.toString(nf.getQuery()));
93.327 + allok = false;
93.328 + }
93.329 + }
93.330 + boolean ok = (accept == testCase.expect);
93.331 + System.out.println((ok ? "pass" : "FAIL") + ": " +
93.332 + testCase.query + " (" + test + ")");
93.333 + allok &= ok;
93.334 + }
93.335 + }
93.336 + for (ExoticCase testCase : exoticTestCases) {
93.337 + NotificationFilter nf = new QueryNotificationFilter(testCase.query);
93.338 + for (boolean expect : new boolean[] {true, false}) {
93.339 + Notification n = expect ? testCase.trueNotif : testCase.falseNotif;
93.340 + boolean accept = nf.isNotificationEnabled(n);
93.341 + boolean ok = (accept == expect);
93.342 + System.out.println((ok ? "pass" : "FAIL") + ": " +
93.343 + testCase.query + ": " + n);
93.344 + allok &= ok;
93.345 + }
93.346 + }
93.347 + if (!allok)
93.348 + throw new Exception("TEST FAILED");
93.349 + }
93.350 +}
94.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
94.2 +++ b/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java Fri Apr 18 16:40:32 2008 -0700
94.3 @@ -0,0 +1,109 @@
94.4 +/*
94.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
94.7 + *
94.8 + * This code is free software; you can redistribute it and/or modify it
94.9 + * under the terms of the GNU General Public License version 2 only, as
94.10 + * published by the Free Software Foundation.
94.11 + *
94.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
94.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
94.15 + * version 2 for more details (a copy is included in the LICENSE file that
94.16 + * accompanied this code).
94.17 + *
94.18 + * You should have received a copy of the GNU General Public License version
94.19 + * 2 along with this work; if not, write to the Free Software Foundation,
94.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
94.21 + *
94.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
94.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
94.24 + * have any questions.
94.25 + */
94.26 +
94.27 +/**
94.28 + * @test
94.29 + * @bug 6572331
94.30 + * @summary basic test for RSA cipher key wrapping functionality
94.31 + * @author Valerie Peng
94.32 + * @library ..
94.33 + */
94.34 +import java.io.*;
94.35 +import java.util.*;
94.36 +
94.37 +import java.security.*;
94.38 +
94.39 +import javax.crypto.*;
94.40 +import javax.crypto.spec.SecretKeySpec;
94.41 +
94.42 +public class TestRSACipherWrap extends PKCS11Test {
94.43 +
94.44 + private static final String RSA_ALGO = "RSA/ECB/PKCS1Padding";
94.45 +
94.46 + public void main(Provider p) throws Exception {
94.47 + try {
94.48 + Cipher.getInstance(RSA_ALGO, p);
94.49 + } catch (GeneralSecurityException e) {
94.50 + System.out.println("Not supported by provider, skipping");
94.51 + return;
94.52 + }
94.53 + KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", p);
94.54 + kpg.initialize(1024);
94.55 + KeyPair kp = kpg.generateKeyPair();
94.56 + PublicKey publicKey = kp.getPublic();
94.57 + PrivateKey privateKey = kp.getPrivate();
94.58 +
94.59 + Cipher cipherPKCS11 = Cipher.getInstance(RSA_ALGO, p);
94.60 + Cipher cipherJce = Cipher.getInstance(RSA_ALGO, "SunJCE");
94.61 +
94.62 + String algos[] = {"AES", "RC2", "Blowfish"};
94.63 + int keySizes[] = {128, 256};
94.64 +
94.65 + for (int j = 0; j < algos.length; j++) {
94.66 + String algorithm = algos[j];
94.67 + KeyGenerator keygen =
94.68 + KeyGenerator.getInstance(algorithm);
94.69 +
94.70 + for (int i = 0; i < keySizes.length; i++) {
94.71 + SecretKey secretKey = null;
94.72 + System.out.print("Generate " + keySizes[i] + "-bit " +
94.73 + algorithm + " key using ");
94.74 + try {
94.75 + keygen.init(keySizes[i]);
94.76 + secretKey = keygen.generateKey();
94.77 + System.out.println(keygen.getProvider().getName());
94.78 + } catch (InvalidParameterException ipe) {
94.79 + secretKey = new SecretKeySpec(new byte[32], algorithm);
94.80 + System.out.println("SecretKeySpec class");
94.81 + }
94.82 + test(kp, secretKey, cipherPKCS11, cipherJce);
94.83 + test(kp, secretKey, cipherPKCS11, cipherPKCS11);
94.84 + test(kp, secretKey, cipherJce, cipherPKCS11);
94.85 + }
94.86 + }
94.87 + }
94.88 +
94.89 + private static void test(KeyPair kp, SecretKey secretKey,
94.90 + Cipher wrapCipher, Cipher unwrapCipher)
94.91 + throws Exception {
94.92 + String algo = secretKey.getAlgorithm();
94.93 + wrapCipher.init(Cipher.WRAP_MODE, kp.getPublic());
94.94 + byte[] wrappedKey = wrapCipher.wrap(secretKey);
94.95 + unwrapCipher.init(Cipher.UNWRAP_MODE, kp.getPrivate());
94.96 + Key unwrappedKey =
94.97 + unwrapCipher.unwrap(wrappedKey, algo, Cipher.SECRET_KEY);
94.98 +
94.99 + System.out.println("Test " + wrapCipher.getProvider().getName() +
94.100 + "/" + unwrapCipher.getProvider().getName() + ": ");
94.101 + if (!Arrays.equals(secretKey.getEncoded(),
94.102 + unwrappedKey.getEncoded())) {
94.103 + throw new Exception("Test Failed!");
94.104 + }
94.105 + System.out.println("Passed");
94.106 + }
94.107 +
94.108 + public static void main(String[] args) throws Exception {
94.109 + main(new TestRSACipherWrap());
94.110 + }
94.111 +}
94.112 +
95.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
95.2 +++ b/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java Fri Apr 18 16:40:32 2008 -0700
95.3 @@ -0,0 +1,282 @@
95.4 +/*
95.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
95.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
95.7 + *
95.8 + * This code is free software; you can redistribute it and/or modi
95.9 +fy it
95.10 + * under the terms of the GNU General Public License version 2 onl
95.11 +y, as
95.12 + * published by the Free Software Foundation.
95.13 + *
95.14 + * This code is distributed in the hope that it will be useful, bu
95.15 +t WITHOUT
95.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABIL
95.17 +ITY or
95.18 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public L
95.19 +icense
95.20 + * version 2 for more details (a copy is included in the LICENSE f
95.21 +ile that
95.22 + * accompanied this code).
95.23 + *
95.24 + * You should have received a copy of the GNU General Public Licen
95.25 +se version
95.26 + * 2 along with this work; if not, write to the Free Software Foun
95.27 +dation,
95.28 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
95.29 + *
95.30 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, San
95.31 +ta Clara,
95.32 + * CA 95054 USA or visit www.sun.com if you need additional inform
95.33 +ation or
95.34 + * have any questions.
95.35 + */
95.36 +
95.37 +/**
95.38 + * @test %I% %E%
95.39 + * @bug 4898461
95.40 + * @summary basic test for symmetric ciphers with padding
95.41 + * @author Valerie Peng
95.42 + * @library ..
95.43 + */
95.44 +import java.io.*;
95.45 +import java.nio.*;
95.46 +import java.util.*;
95.47 +
95.48 +import java.security.*;
95.49 +import java.security.spec.AlgorithmParameterSpec;
95.50 +
95.51 +import javax.crypto.*;
95.52 +import javax.crypto.spec.IvParameterSpec;
95.53 +
95.54 +public class TestSymmCiphers extends PKCS11Test {
95.55 +
95.56 + private static class CI { // class for holding Cipher Information
95.57 +
95.58 + String transformation;
95.59 + String keyAlgo;
95.60 + int dataSize;
95.61 +
95.62 + CI(String transformation, String keyAlgo, int dataSize) {
95.63 + this.transformation = transformation;
95.64 + this.keyAlgo = keyAlgo;
95.65 + this.dataSize = dataSize;
95.66 + }
95.67 + }
95.68 + private static final CI[] TEST_LIST = {
95.69 + new CI("ARCFOUR", "ARCFOUR", 400),
95.70 + new CI("RC4", "RC4", 401),
95.71 + new CI("DES/CBC/NoPadding", "DES", 400),
95.72 + new CI("DESede/CBC/NoPadding", "DESede", 160),
95.73 + new CI("AES/CBC/NoPadding", "AES", 4800),
95.74 + new CI("Blowfish/CBC/NoPadding", "Blowfish", 24),
95.75 + new CI("DES/cbc/PKCS5Padding", "DES", 6401),
95.76 + new CI("DESede/CBC/PKCS5Padding", "DESede", 402),
95.77 + new CI("AES/CBC/PKCS5Padding", "AES", 30),
95.78 + new CI("Blowfish/CBC/PKCS5Padding", "Blowfish", 19),
95.79 + new CI("DES/ECB/NoPadding", "DES", 400),
95.80 + new CI("DESede/ECB/NoPadding", "DESede", 160),
95.81 + new CI("AES/ECB/NoPadding", "AES", 4800),
95.82 + new CI("DES/ECB/PKCS5Padding", "DES", 32),
95.83 + new CI("DES/ECB/PKCS5Padding", "DES", 6400),
95.84 + new CI("DESede/ECB/PKCS5Padding", "DESede", 400),
95.85 + new CI("AES/ECB/PKCS5Padding", "AES", 64),
95.86 + new CI("DES", "DES", 6400),
95.87 + new CI("DESede", "DESede", 408),
95.88 + new CI("AES", "AES", 128)
95.89 + };
95.90 + private static StringBuffer debugBuf = new StringBuffer();
95.91 +
95.92 + public void main(Provider p) throws Exception {
95.93 + // NSS reports CKR_DEVICE_ERROR when the data passed to
95.94 + // its EncryptUpdate/DecryptUpdate is not multiple of blocks
95.95 + int firstBlkSize = 16;
95.96 + boolean status = true;
95.97 + Random random = new Random();
95.98 + try {
95.99 + for (int i = 0; i < TEST_LIST.length; i++) {
95.100 + CI currTest = TEST_LIST[i];
95.101 + System.out.println("===" + currTest.transformation + "===");
95.102 + try {
95.103 + KeyGenerator kg =
95.104 + KeyGenerator.getInstance(currTest.keyAlgo, p);
95.105 + SecretKey key = kg.generateKey();
95.106 + Cipher c1 = Cipher.getInstance(currTest.transformation, p);
95.107 + Cipher c2 = Cipher.getInstance(currTest.transformation,
95.108 + "SunJCE");
95.109 +
95.110 + byte[] plainTxt = new byte[currTest.dataSize];
95.111 + random.nextBytes(plainTxt);
95.112 + System.out.println("Testing inLen = " + plainTxt.length);
95.113 +
95.114 + c2.init(Cipher.ENCRYPT_MODE, key);
95.115 + AlgorithmParameters params = c2.getParameters();
95.116 + byte[] answer = c2.doFinal(plainTxt);
95.117 + System.out.println("Encryption tests: START");
95.118 + test(c1, Cipher.ENCRYPT_MODE, key, params, firstBlkSize,
95.119 + plainTxt, answer);
95.120 + System.out.println("Encryption tests: DONE");
95.121 + c2.init(Cipher.DECRYPT_MODE, key, params);
95.122 + byte[] answer2 = c2.doFinal(answer);
95.123 + System.out.println("Decryption tests: START");
95.124 + test(c1, Cipher.DECRYPT_MODE, key, params, firstBlkSize,
95.125 + answer, answer2);
95.126 + System.out.println("Decryption tests: DONE");
95.127 + } catch (NoSuchAlgorithmException nsae) {
95.128 + System.out.println("Skipping unsupported algorithm: " +
95.129 + nsae);
95.130 + }
95.131 + }
95.132 + } catch (Exception ex) {
95.133 + // print out debug info when exception is encountered
95.134 + if (debugBuf != null) {
95.135 + System.out.println(debugBuf.toString());
95.136 + debugBuf = new StringBuffer();
95.137 + }
95.138 + throw ex;
95.139 + }
95.140 + }
95.141 +
95.142 + private static void test(Cipher cipher, int mode, SecretKey key,
95.143 + AlgorithmParameters params, int firstBlkSize,
95.144 + byte[] in, byte[] answer) throws Exception {
95.145 + // test setup
95.146 + long startTime, endTime;
95.147 + cipher.init(mode, key, params);
95.148 + int outLen = cipher.getOutputSize(in.length);
95.149 + //debugOut("Estimated output size = " + outLen + "\n");
95.150 +
95.151 + // test data preparation
95.152 + ByteBuffer inBuf = ByteBuffer.allocate(in.length);
95.153 + inBuf.put(in);
95.154 + inBuf.position(0);
95.155 + ByteBuffer inDirectBuf = ByteBuffer.allocateDirect(in.length);
95.156 + inDirectBuf.put(in);
95.157 + inDirectBuf.position(0);
95.158 + ByteBuffer outBuf = ByteBuffer.allocate(outLen);
95.159 + ByteBuffer outDirectBuf = ByteBuffer.allocateDirect(outLen);
95.160 +
95.161 + // test#1: byte[] in + byte[] out
95.162 + //debugOut("Test#1:\n");
95.163 +
95.164 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
95.165 +
95.166 + startTime = System.nanoTime();
95.167 + byte[] temp = cipher.update(in, 0, firstBlkSize);
95.168 + if (temp != null && temp.length > 0) {
95.169 + baos.write(temp, 0, temp.length);
95.170 + }
95.171 + temp = cipher.doFinal(in, firstBlkSize, in.length - firstBlkSize);
95.172 + if (temp != null && temp.length > 0) {
95.173 + baos.write(temp, 0, temp.length);
95.174 + }
95.175 + byte[] testOut1 = baos.toByteArray();
95.176 + endTime = System.nanoTime();
95.177 + perfOut("stream InBuf + stream OutBuf: " +
95.178 + (endTime - startTime));
95.179 + match(testOut1, answer);
95.180 +
95.181 + // test#2: Non-direct Buffer in + non-direct Buffer out
95.182 + //debugOut("Test#2:\n");
95.183 + //debugOut("inputBuf: " + inBuf + "\n");
95.184 + //debugOut("outputBuf: " + outBuf + "\n");
95.185 +
95.186 + startTime = System.nanoTime();
95.187 + cipher.update(inBuf, outBuf);
95.188 + cipher.doFinal(inBuf, outBuf);
95.189 + endTime = System.nanoTime();
95.190 + perfOut("non-direct InBuf + non-direct OutBuf: " +
95.191 + (endTime - startTime));
95.192 + match(outBuf, answer);
95.193 +
95.194 + // test#3: Direct Buffer in + direc Buffer out
95.195 + //debugOut("Test#3:\n");
95.196 + //debugOut("(pre) inputBuf: " + inDirectBuf + "\n");
95.197 + //debugOut("(pre) outputBuf: " + outDirectBuf + "\n");
95.198 +
95.199 + startTime = System.nanoTime();
95.200 + cipher.update(inDirectBuf, outDirectBuf);
95.201 + cipher.doFinal(inDirectBuf, outDirectBuf);
95.202 + endTime = System.nanoTime();
95.203 + perfOut("direct InBuf + direct OutBuf: " +
95.204 + (endTime - startTime));
95.205 +
95.206 + //debugOut("(post) inputBuf: " + inDirectBuf + "\n");
95.207 + //debugOut("(post) outputBuf: " + outDirectBuf + "\n");
95.208 + match(outDirectBuf, answer);
95.209 +
95.210 + // test#4: Direct Buffer in + non-direct Buffer out
95.211 + //debugOut("Test#4:\n");
95.212 + inDirectBuf.position(0);
95.213 + outBuf.position(0);
95.214 + //debugOut("inputBuf: " + inDirectBuf + "\n");
95.215 + //debugOut("outputBuf: " + outBuf + "\n");
95.216 +
95.217 + startTime = System.nanoTime();
95.218 + cipher.update(inDirectBuf, outBuf);
95.219 + cipher.doFinal(inDirectBuf, outBuf);
95.220 + endTime = System.nanoTime();
95.221 + perfOut("direct InBuf + non-direct OutBuf: " +
95.222 + (endTime - startTime));
95.223 + match(outBuf, answer);
95.224 +
95.225 + // test#5: Non-direct Buffer in + direct Buffer out
95.226 + //debugOut("Test#5:\n");
95.227 + inBuf.position(0);
95.228 + outDirectBuf.position(0);
95.229 +
95.230 + //debugOut("(pre) inputBuf: " + inBuf + "\n");
95.231 + //debugOut("(pre) outputBuf: " + outDirectBuf + "\n");
95.232 +
95.233 + startTime = System.nanoTime();
95.234 + cipher.update(inBuf, outDirectBuf);
95.235 + cipher.doFinal(inBuf, outDirectBuf);
95.236 + endTime = System.nanoTime();
95.237 + perfOut("non-direct InBuf + direct OutBuf: " +
95.238 + (endTime - startTime));
95.239 +
95.240 + //debugOut("(post) inputBuf: " + inBuf + "\n");
95.241 + //debugOut("(post) outputBuf: " + outDirectBuf + "\n");
95.242 + match(outDirectBuf, answer);
95.243 +
95.244 + debugBuf = null;
95.245 + }
95.246 +
95.247 + private static void perfOut(String msg) {
95.248 + if (debugBuf != null) {
95.249 + debugBuf.append("PERF>" + msg);
95.250 + }
95.251 + }
95.252 +
95.253 + private static void debugOut(String msg) {
95.254 + if (debugBuf != null) {
95.255 + debugBuf.append(msg);
95.256 + }
95.257 + }
95.258 +
95.259 + private static void match(byte[] b1, byte[] b2) throws Exception {
95.260 + if (b1.length != b2.length) {
95.261 + debugOut("got len : " + b1.length + "\n");
95.262 + debugOut("expect len: " + b2.length + "\n");
95.263 + throw new Exception("mismatch - different length! got: " + b1.length + ", expect: " + b2.length + "\n");
95.264 + } else {
95.265 + for (int i = 0; i < b1.length; i++) {
95.266 + if (b1[i] != b2[i]) {
95.267 + debugOut("got : " + toString(b1) + "\n");
95.268 + debugOut("expect: " + toString(b2) + "\n");
95.269 + throw new Exception("mismatch");
95.270 + }
95.271 + }
95.272 + }
95.273 + }
95.274 +
95.275 + private static void match(ByteBuffer bb, byte[] answer) throws Exception {
95.276 + byte[] bbTemp = new byte[bb.position()];
95.277 + bb.position(0);
95.278 + bb.get(bbTemp, 0, bbTemp.length);
95.279 + match(bbTemp, answer);
95.280 + }
95.281 +
95.282 + public static void main(String[] args) throws Exception {
95.283 + main(new TestSymmCiphers());
95.284 + }
95.285 +}
96.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
96.2 +++ b/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.java Fri Apr 18 16:40:32 2008 -0700
96.3 @@ -0,0 +1,194 @@
96.4 +/*
96.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
96.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96.7 + *
96.8 + * This code is free software; you can redistribute it and/or modify it
96.9 + * under the terms of the GNU General Public License version 2 only, as
96.10 + * published by the Free Software Foundation.
96.11 + *
96.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
96.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
96.15 + * version 2 for more details (a copy is included in the LICENSE file that
96.16 + * accompanied this code).
96.17 + *
96.18 + * You should have received a copy of the GNU General Public License version
96.19 + * 2 along with this work; if not, write to the Free Software Foundation,
96.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96.21 + *
96.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
96.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
96.24 + * have any questions.
96.25 + */
96.26 +
96.27 +import java.io.*;
96.28 +import java.util.*;
96.29 +import java.lang.reflect.*;
96.30 +
96.31 +import java.security.*;
96.32 +import java.security.cert.*;
96.33 +import java.security.spec.*;
96.34 +import java.security.interfaces.*;
96.35 +import java.math.BigInteger;
96.36 +
96.37 +import javax.crypto.*;
96.38 +import javax.crypto.spec.*;
96.39 +
96.40 +public class SecretKeysBasic extends PKCS11Test {
96.41 +
96.42 + private static final char SEP = File.separatorChar;
96.43 + private static char[] tokenPwd;
96.44 + private static final char[] nssPwd =
96.45 + new char[]{'t', 'e', 's', 't', '1', '2'};
96.46 + private static final char[] solarisPwd =
96.47 + new char[]{'p', 'i', 'n'};
96.48 + private static SecretKey sk1;
96.49 + private static SecretKey sk2;
96.50 + private static SecretKey softkey;
96.51 + private static KeyStore ks;
96.52 + private static final String KS_TYPE = "PKCS11";
96.53 + private static Provider provider;
96.54 +
96.55 + public static void main(String[] args) throws Exception {
96.56 + main(new SecretKeysBasic());
96.57 + }
96.58 +
96.59 + public void main(Provider p) throws Exception {
96.60 + this.provider = p;
96.61 +
96.62 + // create secret key
96.63 + byte[] keyVal = new byte[16];
96.64 + (new SecureRandom()).nextBytes(keyVal);
96.65 + // NSS will throw CKR_HOST_MEMORY if calling C_DecryptInit w/
96.66 + // (keyVal[0] == 0)
96.67 + if (keyVal[0] == 0) {
96.68 + keyVal[0] = 1;
96.69 + }
96.70 + softkey = new SecretKeySpec(keyVal, "AES");
96.71 + dumpKey("softkey", softkey);
96.72 +
96.73 + KeyGenerator kg = KeyGenerator.getInstance("DESede", provider);
96.74 + sk1 = kg.generateKey();
96.75 + dumpKey("skey1", sk1);
96.76 + sk2 = kg.generateKey();
96.77 + dumpKey("skey2", sk2);
96.78 +
96.79 + String token = System.getProperty("TOKEN");
96.80 +
96.81 + if (token == null || token.length() == 0) {
96.82 + System.out.println("Error: missing TOKEN system property");
96.83 + throw new Exception("token arg required");
96.84 + }
96.85 +
96.86 + if ("nss".equals(token)) {
96.87 + tokenPwd = nssPwd;
96.88 + } else if ("solaris".equals(token)) {
96.89 + tokenPwd = solarisPwd;
96.90 + }
96.91 +
96.92 + int testnum = 1;
96.93 + doTest();
96.94 + }
96.95 +
96.96 + private static boolean checkSecretKeyEntry(String alias,
96.97 + SecretKey expected,
96.98 + boolean saveBeforeCheck)
96.99 + throws Exception {
96.100 + if (saveBeforeCheck) {
96.101 + ks.setKeyEntry(alias, expected, null, null);
96.102 + }
96.103 + SecretKey result = (SecretKey) (ks.getKey(alias, null));
96.104 + String keyEncFormat = result.getFormat();
96.105 + if (keyEncFormat == null) {
96.106 + // sensitive or un-extractable keys - verify by encrypt/decrypt
96.107 + byte[] data = new byte[64];
96.108 + Cipher c =
96.109 + Cipher.getInstance(result.getAlgorithm() + "/CBC/NoPadding",
96.110 + provider);
96.111 + c.init(Cipher.ENCRYPT_MODE, expected);
96.112 + byte[] encOut = c.doFinal(data);
96.113 + c.init(Cipher.DECRYPT_MODE, result, c.getParameters());
96.114 + byte[] decOut = c.doFinal(encOut);
96.115 + if (!Arrays.equals(data, decOut)) {
96.116 + return false;
96.117 + }
96.118 + } else if (keyEncFormat.toUpperCase().equals("RAW")) {
96.119 + if (!Arrays.equals(result.getEncoded(), expected.getEncoded())) {
96.120 + dumpKey("\texpected:", expected);
96.121 + dumpKey("\treturns:", result);
96.122 + return false;
96.123 + }
96.124 + }
96.125 + return true;
96.126 + }
96.127 +
96.128 + private static void dumpKey(String info, SecretKey key) {
96.129 + System.out.println(info + "> " + key);
96.130 + System.out.println("\tALGO=" + key.getAlgorithm());
96.131 + if (key.getFormat() != null) {
96.132 + System.out.println("\t[" + key.getFormat() + "] VALUE=" +
96.133 + new BigInteger(key.getEncoded()));
96.134 + } else {
96.135 + System.out.println("\tVALUE=n/a");
96.136 + }
96.137 + }
96.138 +
96.139 + private static void doTest() throws Exception {
96.140 + if (ks == null) {
96.141 + ks = KeyStore.getInstance(KS_TYPE, provider);
96.142 + ks.load(null, tokenPwd);
96.143 + }
96.144 +
96.145 + System.out.println("Number of entries: " + ks.size());
96.146 + if (ks.size() != 0) {
96.147 + System.out.println("Deleting entries under aliases: ");
96.148 + for (Enumeration<String> aliases = ks.aliases();
96.149 + aliases.hasMoreElements();) {
96.150 + String alias = aliases.nextElement();
96.151 + System.out.println("\t" + alias);
96.152 + ks.deleteEntry(alias);
96.153 + }
96.154 + }
96.155 +
96.156 + String alias = "testSKey";
96.157 +
96.158 + boolean testResult = checkSecretKeyEntry(alias, softkey, true);
96.159 + if (!testResult) {
96.160 + System.out.println("FAILURE: setKey() w/ softSecretKey failed");
96.161 + }
96.162 +
96.163 + if (!checkSecretKeyEntry(alias, sk1, true)) {
96.164 + testResult = false;
96.165 + System.out.println("FAILURE: setKey() w/ skey1 failed");
96.166 + }
96.167 + if (!checkSecretKeyEntry(alias, sk2, true)) {
96.168 + testResult = false;
96.169 + System.out.println("FAILURE: setKey() w/ skey2 failed");
96.170 + }
96.171 +
96.172 + ks.store(null);
96.173 + System.out.println("Reloading keystore...");
96.174 +
96.175 + ks.load(null, "whatever".toCharArray());
96.176 + if (ks.size() != 1) {
96.177 + System.out.println("FAILURE: reload#1 ks.size() != 1");
96.178 + }
96.179 + if (!checkSecretKeyEntry(alias, sk2, false)) {
96.180 + testResult = false;
96.181 + System.out.println("FAILURE: reload#1 ks entry check failed");
96.182 + }
96.183 +
96.184 + ks.deleteEntry(alias);
96.185 + ks.store(null);
96.186 +
96.187 + System.out.println("Reloading keystore...");
96.188 + ks.load(null, "whatever".toCharArray());
96.189 + if (ks.size() != 0) {
96.190 + testResult = false;
96.191 + System.out.println("FAILURE: reload#2 ks.size() != 0");
96.192 + }
96.193 + if (!testResult) {
96.194 + throw new Exception("One or more test failed!");
96.195 + }
96.196 + }
96.197 +}
97.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
97.2 +++ b/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.sh Fri Apr 18 16:40:32 2008 -0700
97.3 @@ -0,0 +1,164 @@
97.4 +#
97.5 +# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
97.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97.7 +#
97.8 +# This code is free software; you can redistribute it and/or modify it
97.9 +# under the terms of the GNU General Public License version 2 only, as
97.10 +# published by the Free Software Foundation.
97.11 +#
97.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
97.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
97.15 +# version 2 for more details (a copy is included in the LICENSE file that
97.16 +# accompanied this code).
97.17 +#
97.18 +# You should have received a copy of the GNU General Public License version
97.19 +# 2 along with this work; if not, write to the Free Software Foundation,
97.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97.21 +#
97.22 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
97.23 +# CA 95054 USA or visit www.sun.com if you need additional information or
97.24 +# have any questions.
97.25 +#
97.26 +
97.27 +# @test
97.28 +# @bug 6599979
97.29 +# @summary Ensure that re-assigning the alias works
97.30 +#
97.31 +# @run shell SecretKeysBasic.sh
97.32 +#
97.33 +# To run by hand:
97.34 +# %sh SecretKeysBasic.sh
97.35 +#
97.36 +# Note:
97.37 +# . test only runs on solaris at the moment
97.38 +
97.39 +# set a few environment variables so that the shell-script can run stand-alone
97.40 +# in the source directory
97.41 +
97.42 +# if running by hand on windows, change TESTSRC and TESTCLASSES to "."
97.43 +if [ "${TESTSRC}" = "" ] ; then
97.44 + TESTSRC=`pwd`
97.45 +fi
97.46 +if [ "${TESTCLASSES}" = "" ] ; then
97.47 + TESTCLASSES=`pwd`
97.48 +fi
97.49 +
97.50 +# if running by hand on windows, change this to appropriate value
97.51 +if [ "${TESTJAVA}" = "" ] ; then
97.52 + TESTJAVA="/net/shimmer/export/valeriep/jdk7/build/solaris-sparc"
97.53 +fi
97.54 +echo TESTSRC=${TESTSRC}
97.55 +echo TESTCLASSES=${TESTCLASSES}
97.56 +echo TESTJAVA=${TESTJAVA}
97.57 +echo ""
97.58 +
97.59 +#DEBUG=sunpkcs11,pkcs11keystore
97.60 +
97.61 +echo DEBUG=${DEBUG}
97.62 +echo ""
97.63 +
97.64 +OS=`uname -s`
97.65 +case "$OS" in
97.66 + SunOS )
97.67 + FS="/"
97.68 + PS=":"
97.69 + SCCS="${FS}usr${FS}ccs${FS}bin${FS}sccs"
97.70 + CP="${FS}bin${FS}cp -f"
97.71 + RM="${FS}bin${FS}rm -rf"
97.72 + MKDIR="${FS}bin${FS}mkdir -p"
97.73 + CHMOD="${FS}bin${FS}chmod"
97.74 + ;;
97.75 + * )
97.76 + echo "Unsupported System ${OS} - Test only runs on Solaris"
97.77 + exit 0;
97.78 + ;;
97.79 +esac
97.80 +
97.81 +TOKENS="nss solaris"
97.82 +STATUS=0
97.83 +for token in ${TOKENS}
97.84 +do
97.85 +
97.86 +if [ ${token} = "nss" ]
97.87 +then
97.88 + # make cert/key DBs writable if token is NSS
97.89 + ${CP} ${TESTSRC}${FS}..${FS}nss${FS}db${FS}cert8.db ${TESTCLASSES}
97.90 + ${CHMOD} +w ${TESTCLASSES}${FS}cert8.db
97.91 +
97.92 + ${CP} ${TESTSRC}${FS}..${FS}nss${FS}db${FS}key3.db ${TESTCLASSES}
97.93 + ${CHMOD} +w ${TESTCLASSES}${FS}key3.db
97.94 + USED_FILE_LIST="${TESTCLASSES}${FS}cert8.db ${TESTCLASSES}${FS}key3.db"
97.95 +elif [ ${token} = "solaris" ]
97.96 +then
97.97 + OS_VERSION=`uname -r`
97.98 + case "${OS_VERSION}" in
97.99 + 5.1* )
97.100 + SOFTTOKEN_DIR=${TESTCLASSES}
97.101 + export SOFTTOKEN_DIR
97.102 + ;;
97.103 + * )
97.104 + echo "Unsupported Version ${OS_VERSION} - Test only runs on Solaris"
97.105 + exit 0;
97.106 + ;;
97.107 + esac
97.108 +
97.109 + # copy keystore into write-able location
97.110 + if [ -d ${TESTCLASSES}${FS}pkcs11_softtoken ]
97.111 + then
97.112 + echo "Removing old pkcs11_keystore, creating new pkcs11_keystore"
97.113 +
97.114 + echo ${RM} ${TESTCLASSES}${FS}pkcs11_softtoken
97.115 + ${RM} ${TESTCLASSES}${FS}pkcs11_softtoken
97.116 + fi
97.117 + echo ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}private
97.118 + ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}private
97.119 +
97.120 + echo ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}public
97.121 + ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}public
97.122 +
97.123 + echo ${CP} ${TESTSRC}${FS}BasicData${FS}pkcs11_softtoken${FS}objstore_info \
97.124 + ${TESTCLASSES}${FS}pkcs11_softtoken
97.125 + ${CP} ${TESTSRC}${FS}BasicData${FS}pkcs11_softtoken${FS}objstore_info \
97.126 + ${TESTCLASSES}${FS}pkcs11_softtoken
97.127 +
97.128 + echo ${CHMOD} +w ${TESTCLASSES}${FS}pkcs11_softtoken${FS}objstore_info
97.129 + ${CHMOD} 600 ${TESTCLASSES}${FS}pkcs11_softtoken${FS}objstore_info
97.130 + USED_FILE_LIST="${TESTCLASSES}${FS}pkcs11_softtoken"
97.131 +fi
97.132 +
97.133 +cd ${TESTCLASSES}
97.134 +${TESTJAVA}${FS}bin${FS}javac \
97.135 + -classpath ${TESTCLASSES} \
97.136 + -d ${TESTCLASSES} \
97.137 + ${TESTSRC}${FS}SecretKeysBasic.java
97.138 +
97.139 +# run test
97.140 +cd ${TESTSRC}
97.141 +${TESTJAVA}${FS}bin${FS}java \
97.142 + -DDIR=${TESTSRC}${FS}BasicData${FS} \
97.143 + -classpath ${TESTCLASSES}${PS}${TESTSRC}${FS}loader.jar \
97.144 + -DCUSTOM_DB_DIR=${TESTCLASSES} \
97.145 + -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}BasicData${FS}p11-${token}.txt \
97.146 + -DNO_DEFAULT=true \
97.147 + -DNO_DEIMOS=true \
97.148 + -DTOKEN=${token} \
97.149 + -Djava.security.debug=${DEBUG} \
97.150 + SecretKeysBasic
97.151 +
97.152 +# -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}BasicData${FS}p11-${token}.txt \
97.153 +
97.154 +# save error status
97.155 +if [ $? != 0 ]
97.156 +then
97.157 + echo "Test against " ${token} " Failed!"
97.158 + STATUS=1
97.159 +fi
97.160 +
97.161 +# clean up
97.162 +${RM} ${USED_FILE_LIST}
97.163 +
97.164 +done
97.165 +
97.166 +# return
97.167 +exit ${STATUS}
98.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
98.2 +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnection/CriticalSubjectAltName.java Fri Apr 18 16:40:32 2008 -0700
98.3 @@ -0,0 +1,262 @@
98.4 +/*
98.5 + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
98.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98.7 + *
98.8 + * This code is free software; you can redistribute it and/or modify it
98.9 + * under the terms of the GNU General Public License version 2 only, as
98.10 + * published by the Free Software Foundation.
98.11 + *
98.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
98.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
98.15 + * version 2 for more details (a copy is included in the LICENSE file that
98.16 + * accompanied this code).
98.17 + *
98.18 + * You should have received a copy of the GNU General Public License version
98.19 + * 2 along with this work; if not, write to the Free Software Foundation,
98.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98.21 + *
98.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
98.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
98.24 + * have any questions.
98.25 + */
98.26 +
98.27 +/*
98.28 + * @test
98.29 + * @bug 6668231
98.30 + * @summary Presence of a critical subjectAltName causes JSSE's SunX509 to
98.31 + * fail trusted checks
98.32 + * @author Xuelei Fan
98.33 + *
98.34 + * This test depends on binary keystore, crisubn.jks and trusted.jks. Because
98.35 + * JAVA keytool cannot generate X509 certificate with SubjectAltName extension,
98.36 + * the certificates are generated with openssl toolkits and then imported into
98.37 + * JAVA keystore.
98.38 + *
98.39 + * The crisubn.jks holds a private key entry and the corresponding X509
98.40 + * certificate issued with an empty Subject field, and a critical
98.41 + * SubjectAltName extension.
98.42 + *
98.43 + * The trusted.jks holds the trusted certificate.
98.44 + */
98.45 +import java.io.*;
98.46 +import java.net.*;
98.47 +import javax.net.ssl.*;
98.48 +import java.security.cert.Certificate;
98.49 +
98.50 +public class CriticalSubjectAltName implements HostnameVerifier {
98.51 + /*
98.52 + * =============================================================
98.53 + * Set the various variables needed for the tests, then
98.54 + * specify what tests to run on each side.
98.55 + */
98.56 +
98.57 + /*
98.58 + * Should we run the client or server in a separate thread?
98.59 + * Both sides can throw exceptions, but do you have a preference
98.60 + * as to which side should be the main thread.
98.61 + */
98.62 + static boolean separateServerThread = true;
98.63 +
98.64 + /*
98.65 + * Where do we find the keystores?
98.66 + */
98.67 + static String pathToStores = "./";
98.68 + static String keyStoreFile = "crisubn.jks";
98.69 + static String trustStoreFile = "trusted.jks";
98.70 + static String passwd = "passphrase";
98.71 +
98.72 + /*
98.73 + * Is the server ready to serve?
98.74 + */
98.75 + volatile static boolean serverReady = false;
98.76 +
98.77 + /*
98.78 + * Turn on SSL debugging?
98.79 + */
98.80 + static boolean debug = false;
98.81 +
98.82 + /*
98.83 + * If the client or server is doing some kind of object creation
98.84 + * that the other side depends on, and that thread prematurely
98.85 + * exits, you may experience a hang. The test harness will
98.86 + * terminate all hung threads after its timeout has expired,
98.87 + * currently 3 minutes by default, but you might try to be
98.88 + * smart about it....
98.89 + */
98.90 +
98.91 + /*
98.92 + * Define the server side of the test.
98.93 + *
98.94 + * If the server prematurely exits, serverReady will be set to true
98.95 + * to avoid infinite hangs.
98.96 + */
98.97 + void doServerSide() throws Exception {
98.98 + SSLServerSocketFactory sslssf =
98.99 + (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
98.100 + SSLServerSocket sslServerSocket =
98.101 + (SSLServerSocket) sslssf.createServerSocket(serverPort);
98.102 + serverPort = sslServerSocket.getLocalPort();
98.103 +
98.104 + /*
98.105 + * Signal Client, we're ready for his connect.
98.106 + */
98.107 + serverReady = true;
98.108 +
98.109 + SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
98.110 + OutputStream sslOS = sslSocket.getOutputStream();
98.111 + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sslOS));
98.112 + bw.write("HTTP/1.1 200 OK\r\n\r\n\r\n");
98.113 + bw.flush();
98.114 + Thread.sleep(5000);
98.115 + sslSocket.close();
98.116 + }
98.117 +
98.118 + /*
98.119 + * Define the client side of the test.
98.120 + *
98.121 + * If the server prematurely exits, serverReady will be set to true
98.122 + * to avoid infinite hangs.
98.123 + */
98.124 + void doClientSide() throws Exception {
98.125 +
98.126 + /*
98.127 + * Wait for server to get started.
98.128 + */
98.129 + while (!serverReady) {
98.130 + Thread.sleep(50);
98.131 + }
98.132 +
98.133 + URL url = new URL("https://localhost:"+serverPort+"/index.html");
98.134 + HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection();
98.135 + urlc.setHostnameVerifier(this);
98.136 + urlc.getInputStream();
98.137 +
98.138 + if (urlc.getResponseCode() == -1) {
98.139 + throw new RuntimeException("getResponseCode() returns -1");
98.140 + }
98.141 + }
98.142 +
98.143 + /*
98.144 + * =============================================================
98.145 + * The remainder is just support stuff
98.146 + */
98.147 +
98.148 + // use any free port by default
98.149 + volatile int serverPort = 0;
98.150 +
98.151 + volatile Exception serverException = null;
98.152 + volatile Exception clientException = null;
98.153 +
98.154 + public static void main(String[] args) throws Exception {
98.155 + String keyFilename =
98.156 + System.getProperty("test.src", "./") + "/" + pathToStores +
98.157 + "/" + keyStoreFile;
98.158 + String trustFilename =
98.159 + System.getProperty("test.src", "./") + "/" + pathToStores +
98.160 + "/" + trustStoreFile;
98.161 +
98.162 + System.setProperty("javax.net.ssl.keyStore", keyFilename);
98.163 + System.setProperty("javax.net.ssl.keyStorePassword", passwd);
98.164 + System.setProperty("javax.net.ssl.trustStore", trustFilename);
98.165 + System.setProperty("javax.net.ssl.trustStorePassword", passwd);
98.166 +
98.167 + if (debug)
98.168 + System.setProperty("javax.net.debug", "all");
98.169 +
98.170 + /*
98.171 + * Start the tests.
98.172 + */
98.173 + new CriticalSubjectAltName();
98.174 + }
98.175 +
98.176 + Thread clientThread = null;
98.177 + Thread serverThread = null;
98.178 +
98.179 + /*
98.180 + * Primary constructor, used to drive remainder of the test.
98.181 + *
98.182 + * Fork off the other side, then do your work.
98.183 + */
98.184 + CriticalSubjectAltName() throws Exception {
98.185 + if (separateServerThread) {
98.186 + startServer(true);
98.187 + startClient(false);
98.188 + } else {
98.189 + startClient(true);
98.190 + startServer(false);
98.191 + }
98.192 +
98.193 + /*
98.194 + * Wait for other side to close down.
98.195 + */
98.196 + if (separateServerThread) {
98.197 + serverThread.join();
98.198 + } else {
98.199 + clientThread.join();
98.200 + }
98.201 +
98.202 + /*
98.203 + * When we get here, the test is pretty much over.
98.204 + *
98.205 + * If the main thread excepted, that propagates back
98.206 + * immediately. If the other thread threw an exception, we
98.207 + * should report back.
98.208 + */
98.209 + if (serverException != null)
98.210 + throw serverException;
98.211 + if (clientException != null)
98.212 + throw clientException;
98.213 + }
98.214 +
98.215 + void startServer(boolean newThread) throws Exception {
98.216 + if (newThread) {
98.217 + serverThread = new Thread() {
98.218 + public void run() {
98.219 + try {
98.220 + doServerSide();
98.221 + } catch (Exception e) {
98.222 + /*
98.223 + * Our server thread just died.
98.224 + *
98.225 + * Release the client, if not active already...
98.226 + */
98.227 + System.err.println("Server died...");
98.228 + serverReady = true;
98.229 + serverException = e;
98.230 + }
98.231 + }
98.232 + };
98.233 + serverThread.start();
98.234 + } else {
98.235 + doServerSide();
98.236 + }
98.237 + }
98.238 +
98.239 + void startClient(boolean newThread) throws Exception {
98.240 + if (newThread) {
98.241 + clientThread = new Thread() {
98.242 + public void run() {
98.243 + try {
98.244 + doClientSide();
98.245 + } catch (Exception e) {
98.246 + /*
98.247 + * Our client thread just died.
98.248 + */
98.249 + System.err.println("Client died...");
98.250 + clientException = e;
98.251 + }
98.252 + }
98.253 + };
98.254 + clientThread.start();
98.255 + } else {
98.256 + doClientSide();
98.257 + }
98.258 + }
98.259 +
98.260 + // Simple test method to blindly agree that hostname and certname match
98.261 + public boolean verify(String hostname, SSLSession session) {
98.262 + return true;
98.263 + }
98.264 +
98.265 +}
99.1 Binary file test/sun/security/ssl/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnection/crisubn.jks has changed
100.1 Binary file test/sun/security/ssl/com/sun/net/ssl/internal/www/protocol/https/HttpsURLConnection/trusted.jks has changed