diff --git a/.hgtags b/.hgtags index 6512bd4e1e6ee2a36dca269f82b7be7e420c6522..4790ae528766a08705356acae276d1bbd51c009a 100644 --- a/.hgtags +++ b/.hgtags @@ -25,3 +25,4 @@ b4ac413b1f129eeef0acab3f31081c1b7dfe3b27 jdk7-b47 5fbd9ea7def17186693b6f7099b5d0dc73903eee jdk7-b48 8311105ea7a3db7bcbcb2b696459127c7f2297a4 jdk7-b49 58ba2cd5a25053684ec53205d95edeeaa0006f13 jdk7-b50 +fea0898259ae41c73620b1815aa48f036216155c jdk7-b51 diff --git a/make/com/sun/jmx/Makefile b/make/com/sun/jmx/Makefile index c529dd4be31eed20d73efaf3e8af0bd8b7e033e2..81470f0befed24d8156d9b3721727665bb62aa9d 100644 --- a/make/com/sun/jmx/Makefile +++ b/make/com/sun/jmx/Makefile @@ -41,7 +41,15 @@ include $(BUILDDIR)/common/Defs.gmk # Note : some targets are double colon rules and some single colon rules # within common included gmk files : that is why the following for loop # has been duplicated. -SUBDIRS = snmp + +# When building the openjdk, build snmp only if importing binary plugs, +ifdef OPENJDK + ifeq ($(IMPORT_BINARY_PLUGS),true) + SUBDIRS = snmp + endif +else + SUBDIRS = snmp +endif all build: $(SUBDIRS-loop) diff --git a/make/common/Defs-windows.gmk b/make/common/Defs-windows.gmk index 75da038ffee2c756eb841d9216a983330894f184..7cb827928cd9eb9ba53cbfce3677f0c526f9f928 100644 --- a/make/common/Defs-windows.gmk +++ b/make/common/Defs-windows.gmk @@ -70,7 +70,6 @@ PLATFORM_INCLUDE = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME) # not to be REBASEd, see deploy/make/common/Release.gmk. # msvcrt.dll, msvcrnn.dll [msvcr71 or msvcr80 or msvcr90] : Microsoft runtimes MS_RUNTIME_LIBRARIES = msvcrt.dll -MSVCRNN_DLL = ifeq ($(ARCH_DATA_MODEL), 32) ifeq ($(COMPILER_VERSION), VS2003) MSVCRNN_DLL = msvcr71.dll @@ -89,6 +88,13 @@ ifeq ($(ARCH_DATA_MODEL), 32) endif endif +ifeq ($(ARCH_DATA_MODEL), 64) + ifeq ($(COMPILER_VERSION), VS2008) + MSVCRNN_DLL = msvcr90.dll + MSVCPNN_DLL = msvcp90.dll + MS_RUNTIME_LIBRARIES += $(MSVCRNN_DLL) + endif +endif EXTRA_LFLAGS += /LIBPATH:$(DXSDK_LIB_PATH) @@ -344,17 +350,12 @@ CFLAGS_COMMON += -Fd$(OBJDIR)/$(basename $(@F)).pdb -Fm$(OBJDIR)/$(basename $(@F COMPILER_WARNINGS_TO_IGNORE = 4800 CFLAGS_COMMON += $(COMPILER_WARNINGS_TO_IGNORE:%=-wd%) -# -# Add warnings and extra on 64bit issues -# -ifeq ($(ARCH_DATA_MODEL), 64) - CFLAGS_COMMON += -Wp64 -endif - # # Treat compiler warnings as errors, if requested # CFLAGS_COMMON += -W$(COMPILER_WARNING_LEVEL) +# Turn off security warnings about using the standard C library function strcpy +CFLAGS_COMMON += -D _CRT_SECURE_NO_DEPRECATE ifeq ($(COMPILER_WARNINGS_FATAL),true) CFLAGS_COMMON += -WX endif diff --git a/make/common/shared/Compiler-gcc.gmk b/make/common/shared/Compiler-gcc.gmk index 13feb4cf98cd30558371cd0eda0aa9d5e52b024c..29b8c0a80a420954d1ec1fffa6f58a3e38733246 100644 --- a/make/common/shared/Compiler-gcc.gmk +++ b/make/common/shared/Compiler-gcc.gmk @@ -27,8 +27,6 @@ # GCC Compiler settings # -COMPILER_NAME=GCC - ifeq ($(PLATFORM), windows) # Settings specific to Windows, pretty stale, hasn't been used @@ -90,3 +88,7 @@ endif _CC_VER :=$(shell $(CC) -dumpversion 2>&1 ) CC_VER :=$(call GetVersion,"$(_CC_VER)") +# Name of compiler +COMPILER_NAME = GCC$(call MajorVersion,$(CC_VER)) +COMPILER_VERSION = $(COMPILER_NAME) + diff --git a/make/common/shared/Compiler-msvc.gmk b/make/common/shared/Compiler-msvc.gmk index 4671366b5c32fb2581057fe1a8a720ba70747bd6..ade430ad9ea06f70ac46185985b9dccddf7abf6e 100644 --- a/make/common/shared/Compiler-msvc.gmk +++ b/make/common/shared/Compiler-msvc.gmk @@ -112,6 +112,12 @@ ifeq ($(PLATFORM), windows) endif endif endif + ifeq ($(CC_MAJORVER), 15) + COMPILER_NAME=Microsoft Windows SDK with Visual Studio 9 (6001.18000.367) + COMPILER_VERSION=VS2008 + RC = $(MSSDK61)/Bin/X64/rc.exe + MT = $(MSSDK61)/Bin/X64/mt.exe + endif # This will cause problems if ALT_COMPILER_PATH is defined to "" # which is a directive to use the PATH. REBASE = $(COMPILER_PATH)../REBASE diff --git a/make/common/shared/Compiler-sun.gmk b/make/common/shared/Compiler-sun.gmk index a22196b34f07296cda6c11516f2142a02e2dcecd..8bbd16f21f811fe60b1c43d114c92af784ff4d5d 100644 --- a/make/common/shared/Compiler-sun.gmk +++ b/make/common/shared/Compiler-sun.gmk @@ -27,11 +27,8 @@ # Sun Studio Compiler settings # -COMPILER_NAME=Sun Studio - # Sun Studio Compiler settings specific to Solaris ifeq ($(PLATFORM), solaris) - COMPILER_VERSION=SS12 CC = $(COMPILER_PATH)cc CPP = $(COMPILER_PATH)cc -E CXX = $(COMPILER_PATH)CC @@ -44,7 +41,6 @@ endif # Sun Studio Compiler settings specific to Linux ifeq ($(PLATFORM), linux) # This has not been tested - COMPILER_VERSION=SS12 CC = $(COMPILER_PATH)cc CPP = $(COMPILER_PATH)cc -E CXX = $(COMPILER_PATH)CC @@ -65,7 +61,19 @@ endif # Get compiler version _CC_VER :=$(shell $(CC) -V 2>&1 | $(HEAD) -n 1) CC_VER :=$(call GetVersion,"$(_CC_VER)") - + +# Name of compilers being used +COMPILER_VERSION-5.7 = SS10 +COMPILER_NAME-5.7 = Sun Studio 10 +COMPILER_VERSION-5.8 = SS11 +COMPILER_NAME-5.8 = Sun Studio 11 +COMPILER_VERSION-5.9 = SS12 +COMPILER_NAME-5.9 = Sun Studio 12 +COMPILER_VERSION-5.10 = SS13 +COMPILER_NAME-5.10 = Sun Studio 13 +COMPILER_VERSION = $(COMPILER_VERSION-$(CC_VER)) +COMPILER_NAME = $(COMPILER_NAME-$(CC_VER)) + # Arch specific settings (determines type of .o files and instruction set) # Starting in SS12 (5.9), the arch options changed. # The assembler /usr/ccs/bin/as wants older SS11 (5.8) style options. diff --git a/make/common/shared/Compiler.gmk b/make/common/shared/Compiler.gmk deleted file mode 100644 index e5847a2e28cf88d94d681164e2d3d236f9237401..0000000000000000000000000000000000000000 --- a/make/common/shared/Compiler.gmk +++ /dev/null @@ -1,47 +0,0 @@ -# -# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. Sun designates this -# particular file as subject to the "Classpath" exception as provided -# by Sun in the LICENSE file that accompanied this code. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, -# CA 95054 USA or visit www.sun.com if you need additional information or -# have any questions. -# - -# -# Compiler settings for all platforms and the default compiler for each. -# - -# Windows uses Microsoft compilers by default -ifeq ($(PLATFORM), windows) - override CC_VERSION = msvc -endif - -# Solaris uses Sun Studio compilers by default -ifeq ($(PLATFORM), solaris) - override CC_VERSION = sun -endif - -# Linux uses GNU compilers by default -ifeq ($(PLATFORM), linux) - override CC_VERSION = gcc -endif - -# Get the compiler specific settings -include $(JDK_MAKE_SHARED_DIR)/Compiler-$(CC_VERSION).gmk - diff --git a/make/common/shared/Defs-solaris.gmk b/make/common/shared/Defs-solaris.gmk index b3630bac34bb074f319b66b062f833d2c685013c..8da2d61dc2ca595b5e051fe1f9b544e36b5c2edc 100644 --- a/make/common/shared/Defs-solaris.gmk +++ b/make/common/shared/Defs-solaris.gmk @@ -91,14 +91,14 @@ endif ifneq "$(origin ALT_COMPILER_PATH)" "undefined" COMPILER_PATH :=$(call PrefixPath,$(ALT_COMPILER_PATH)) else - # Careful here, COMPILER_VERSION may not be defined yet (see Compiler.gmk) + # Careful here, REQUIRED_COMPILER_VERSION may not be defined yet (see Defs-versions.gmk) # If the place where we keep a set of Sun Studio compilers doesn't exist, # try and use /opt/SUNWspro, the default location for the SS compilers. # (DirExists checks for this path twice, an automount double check) _SUNSTUDIO_SET_ROOT=$(JDK_DEVTOOLS_DIR)/$(ARCH_FAMILY)/SUNWspro SUNSTUDIO_SET_ROOT:=$(call DirExists,$(_SUNSTUDIO_SET_ROOT),$(_SUNSTUDIO_SET_ROOT),) ifneq ($(SUNSTUDIO_SET_ROOT),) - COMPILER_PATH =$(SUNSTUDIO_SET_ROOT)/$(COMPILER_VERSION)/bin/ + COMPILER_PATH =$(SUNSTUDIO_SET_ROOT)/$(REQUIRED_COMPILER_VERSION)/bin/ else COMPILER_PATH =/opt/SUNWspro/bin/ endif diff --git a/make/common/shared/Defs-versions.gmk b/make/common/shared/Defs-versions.gmk index 007c08fd6bf15b00c525163a8518e70b3dbd5a25..0fc1bab461742ee98889d3440487582f5982b510 100644 --- a/make/common/shared/Defs-versions.gmk +++ b/make/common/shared/Defs-versions.gmk @@ -45,6 +45,12 @@ # REQUIRED_CC_VER # The primary C compiler version expected. # +# REQUIRED_COMPILER_NAME +# The long descriptive name of the compiler we should use +# +# REQUIRED_COMPILER_VERSION +# The one word name that identifies the compilers being used. +# # REQUIRED_CYGWIN_VER # Windows only: If CYGWIN is used, the minimum CYGWIN version. # @@ -114,6 +120,8 @@ ifeq ($(PLATFORM), solaris) else REQUIRED_FREE_SPACE = 1040000 endif + REQUIRED_COMPILER_NAME = Sun Studio 12 + REQUIRED_COMPILER_VERSION = SS12 ifeq ($(CC_VERSION),sun) REQUIRED_CC_VER = 5.9 endif @@ -130,6 +138,8 @@ ifeq ($(PLATFORM), linux) REQUIRED_OS_VARIANT_VERSION = 9 REQUIRED_FREE_SPACE = 1460000 REQUIRED_ALSA_VERSION = 0.9.1 + REQUIRED_COMPILER_NAME = GCC4 + REQUIRED_COMPILER_VERSION = GCC4 REQUIRED_GCC_VER = 2.95 ifeq ($(CC_VERSION),gcc) REQUIRED_CC_VER = 4.3.0 @@ -155,16 +165,22 @@ ifeq ($(PLATFORM), windows) REQUIRED_DXSDK_VER = 0x0900 ifeq ($(CC_VERSION),msvc) ifeq ($(ARCH_DATA_MODEL), 32) - REQUIRED_CC_VER = 15.00.21022.08 - REQUIRED_LINK_VER = 9.00.21022.08 + REQUIRED_COMPILER_NAME = Visual Studio 9 + REQUIRED_COMPILER_VERSION = VS2008 + REQUIRED_CC_VER = 15.00.21022.08 + REQUIRED_LINK_VER = 9.00.21022.08 else ifeq ($(ARCH), ia64) - REQUIRED_CC_VER = 13.00.9337.7 - REQUIRED_LINK_VER = 7.00.9337.7 + REQUIRED_COMPILER_NAME = Microsoft Platform SDK - November 2001 Edition + REQUIRED_COMPILER_VERSION = VS2003 + REQUIRED_CC_VER = 13.00.9337.7 + REQUIRED_LINK_VER = 7.00.9337.7 endif ifeq ($(ARCH), amd64) - REQUIRED_CC_VER = 14.00.40310.41 - REQUIRED_LINK_VER = 8.00.40310.39 + REQUIRED_COMPILER_NAME = Microsoft Windows SDK with Visual Studio 9 (6001.18000.367) + REQUIRED_COMPILER_VERSION = VS2008 + REQUIRED_CC_VER = 15.00.21022.08 + REQUIRED_LINK_VER = 9.00.21022.08 endif endif endif diff --git a/make/common/shared/Defs-windows.gmk b/make/common/shared/Defs-windows.gmk index a7caa1948939da09a60134d0690cb7a32668ffee..abaa6a1807e6d5d2cd076e1e61346d3d1f6d45d1 100644 --- a/make/common/shared/Defs-windows.gmk +++ b/make/common/shared/Defs-windows.gmk @@ -199,6 +199,7 @@ else endif ifeq ($(ARCH_DATA_MODEL), 32) _program_files :=$(call FullPath,$(xPROGRAMFILES)) + _program_files32 :=$(_program_files) else ifdef PROGRAMW6432 xPROGRAMW6432 :="$(subst \,/,$(PROGRAMW6432))" @@ -252,39 +253,51 @@ ifeq ($(ARCH_DATA_MODEL), 32) _vs90tools :=$(call FullPath,$(xVS90COMNTOOLS)) endif ifneq ($(_vs90tools),) - _msvc_dir :=$(_vs90tools)/../../Vc - _redist_sdk :=$(_msvc_dir)/../SDK/v3.5/Bin - endif - ifdef VS80COMNTOOLS # /Common/Tools directory, use ../../Vc - xVS80COMNTOOLS :="$(subst \,/,$(VS80COMNTOOLS))" - _vs80tools :=$(call FullPath,$(xVS80COMNTOOLS)) - endif - ifneq ($(_vs80tools),) - _msvc_dir :=$(_vs80tools)/../../Vc - _redist_sdk :=$(_msvc_dir)/../SDK/v2.0/Bin - endif - ifdef VS71COMNTOOLS # /Common/Tools directory, use ../../Vc7 - xVS71COMNTOOLS :="$(subst \,/,$(VS71COMNTOOLS))" - _vs71tools :=$(call FullPath,$(xVS71COMNTOOLS)) - endif - ifneq ($(_vs71tools),) - _msvc_dir :=$(_vs71tools)/../../Vc7 - _redist_sdk :=$(_vs71tools)/../.. + _msvc_dir :=$(_vs90tools)/../../Vc + else + ifdef VS80COMNTOOLS # /Common/Tools directory, use ../../Vc + xVS80COMNTOOLS :="$(subst \,/,$(VS80COMNTOOLS))" + _vs80tools :=$(call FullPath,$(xVS80COMNTOOLS)) + endif + ifneq ($(_vs80tools),) + _msvc_dir :=$(_vs80tools)/../../Vc + else + ifdef VS71COMNTOOLS # /Common/Tools directory, use ../../Vc7 + xVS71COMNTOOLS :="$(subst \,/,$(VS71COMNTOOLS))" + _vs71tools :=$(call FullPath,$(xVS71COMNTOOLS)) + endif + ifneq ($(_vs71tools),) + _msvc_dir :=$(_vs71tools)/../../Vc7 + endif + endif endif endif ifneq ($(_msvc_dir),) _compiler_bin :=$(_msvc_dir)/Bin - _ms_sdk :=$(_msvc_dir)/PlatformSDK + # Assume PlatformSDK is in VS71 (will be empty if VS90) + _ms_sdk :=$(call FullPath,$(_msvc_dir)/PlatformSDK) + # Assume VS90, then VS80, then VS71 + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v3.5/Bin) + ifeq ($(_redist_sdk),) + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v2.0/Bin) + ifeq ($(_redist_sdk),) + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v1.1/Bin) + endif + endif endif endif # The Microsoft Platform SDK installed by itself ifneq ($(_program_files),) - xPSDK :="$(_program_files)/Microsoft Platform SDK" - _psdk :=$(call FullPath,$(xPSDK)) + _PSDK :="$(_program_files)/Microsoft SDKs/Windows/v6.1/" + _psdk :=$(call FullPath,$(xMSSDK61)) ifeq ($(_psdk),) - xPSDK :="$(_program_files)/Microsoft SDK" - _psdk :=$(call FullPath,$(xMSSDK)) + xPSDK :="$(_program_files)/Microsoft Platform SDK" + _psdk :=$(call FullPath,$(xPSDK)) + ifeq ($(_psdk),) + xPSDK :="$(_program_files)/Microsoft SDK" + _psdk :=$(call FullPath,$(xMSSDK)) + endif endif endif @@ -305,13 +318,22 @@ endif # Compilers for 64bit are from SDK ifeq ($(ARCH_DATA_MODEL), 64) - ifneq ($(_ms_sdk),) - ifeq ($(ARCH), ia64) - _compiler_bin :=$(_ms_sdk)/Bin/Win64 - endif - ifeq ($(ARCH), amd64) - _compiler_bin :=$(_ms_sdk)/Bin/Win64/x86/$(ARCH) - _redist_sdk :=$(_ms_sdk)/redist/win64/AMD64 + xVS2008 :="$(_program_files32)/Microsoft Visual Studio 9.0/" + VS2008 :=$(call FullPath,$(xVS2008)) + ifneq ($(VS2008),) + _compiler_bin :=$(VS2008)/VC/Bin/$(ARCH) + xMSSDK61 :="$(_program_files)/Microsoft SDKs/Windows/v6.1/" + MSSDK61 :=$(call FullPath,$(xMSSDK61)) + _redist_sdk :=$(VS2008)/VC/redist/x86/Microsoft.VC90.CRT + else + ifneq ($(_ms_sdk),) + ifeq ($(ARCH), ia64) + _compiler_bin :=$(_ms_sdk)/Bin/Win64 + endif + ifeq ($(ARCH), amd64) + _compiler_bin :=$(_ms_sdk)/Bin/Win64/x86/$(ARCH) + _redist_sdk :=$(_ms_sdk)/redist/win64/AMD64 + endif endif endif endif @@ -414,70 +436,39 @@ ifndef ALT_BOOTDIR _BOOTDIR2 =$(USRJDKINSTANCES_PATH)/jdk$(PREVIOUS_JDK_VERSION) endif -# See if SDK area has a msvcrt.dll file, directory may exist w/o msvcr* files -_REDIST_SDK_EXISTS := $(shell \ - if [ -f "$(_redist_sdk)/msvcrt.dll" ]; then \ - echo "true"; \ - else \ - echo "false"; \ - fi) -_REDISTNN_SDK_EXISTS := $(shell \ - if [ -f "$(_redist_sdk)/$(MSVCRNN_DLL)" ]; then \ - echo "true"; \ - else \ - echo "false"; \ - fi) - -# 32 bit needs 2 runtimes -ifeq ($(ARCH_DATA_MODEL), 32) +# 32 bit always needs 2 runtimes, 64 bit usually does too - # MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed - ifdef ALT_MSVCRT_DLL_PATH - xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" - MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) +# MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed +ifdef ALT_MSVCRT_DLL_PATH + xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" + MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) +else + MSVCRT_DLL_PATH :=$(call FullPath,$(_system_root)/system32/) +endif +MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) +MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) + +# 32bit always needs the MSVCRNN runtime, 64bit does when using VS2008 +ifeq ($(ARCH_DATA_MODEL), 32) + _NEEDS_MSVCRNN = true +else + ifeq ($(VS2008),) + _NEEDS_MSVCRNN = false else - ifeq ($(_REDIST_SDK_EXISTS), true) - xREDIST_DIR :=$(_redist_sdk) - else - xREDIST_DIR :=$(_system_root)/system32 - endif - MSVCRT_DLL_PATH :=$(call FullPath,$(xREDIST_DIR)) + _NEEDS_MSVCRNN = true endif - MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) - MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) - +endif + +ifeq ($(_NEEDS_MSVCRNN), true) # MSVCRNN_DLL_PATH: location of msvcrnn.dll that will be re-distributed ifdef ALT_MSVCRNN_DLL_PATH xALT_MSVCRNN_DLL_PATH :="$(subst \,/,$(ALT_MSVCRNN_DLL_PATH))" MSVCRNN_DLL_PATH :=$(call FullPath,$(xALT_MSVCRNN_DLL_PATH)) else - ifeq ($(_REDISTNN_SDK_EXISTS), true) - xREDISTNN_DIR :=$(_redist_sdk) - else - xREDISTNN_DIR :=$(_system_root)/system32 - endif - MSVCRNN_DLL_PATH :=$(call FullPath,$(xREDISTNN_DIR)) + MSVCRNN_DLL_PATH :=$(_redist_sdk) endif MSVCRNN_DLL_PATH :=$(call AltCheckSpaces,MSVCRNN_DLL_PATH) MSVCRNN_DLL_PATH:=$(call AltCheckValue,MSVCRNN_DLL_PATH) - -else - - # MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed - ifdef ALT_MSVCRT_DLL_PATH - xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" - MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) - else - ifeq ($(_REDIST_SDK_EXISTS), true) - xREDIST_DIR :=$(_redist_sdk) - else - xREDIST_DIR :=$(_system_root)/SysWOW64 - endif - MSVCRT_DLL_PATH :=$(call FullPath,$(xREDIST_DIR)) - endif - MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) - MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) - endif # DXSDK_PATH: path to Microsoft DirectX SDK Include and Lib @@ -536,7 +527,7 @@ ifdef ALT_INSTALL_MSIVAL2 xALT_INSTALL_MSIVAL2 :="$(subst \,/,$(ALT_INSTALL_MSIVAL2))" INSTALL_MSIVAL2 :=$(call FullPath,$(xALT_INSTALL_MSIVAL2)) else - INSTALL_MSIVAL2 :=$(_program_files)/MsiVal2 + INSTALL_MSIVAL2 :=$(_program_files32)/MsiVal2 endif INSTALL_MSIVAL2:=$(call AltCheckSpaces,INSTALL_MSIVAL2) diff --git a/make/common/shared/Defs.gmk b/make/common/shared/Defs.gmk index c297bfa4d088f5a8c14bb08ec0dbafcd933ac3a4..5da4a29047e20de6af1a8777bb30b59efaad98fc 100644 --- a/make/common/shared/Defs.gmk +++ b/make/common/shared/Defs.gmk @@ -558,9 +558,24 @@ else COPYRIGHT_YEAR = $(shell $(DATE) '+%Y') endif -# Get shared compiler settings -include $(JDK_MAKE_SHARED_DIR)/Compiler.gmk +# Windows uses Microsoft compilers by default +ifeq ($(PLATFORM), windows) + override CC_VERSION = msvc +endif + +# Solaris uses Sun Studio compilers by default +ifeq ($(PLATFORM), solaris) + override CC_VERSION = sun +endif -# Get the REQUIRED versions +# Linux uses GNU compilers by default +ifeq ($(PLATFORM), linux) + override CC_VERSION = gcc +endif + +# Get the REQUIRED versions (needs CC_VERSION set) include $(JDK_MAKE_SHARED_DIR)/Defs-versions.gmk +# Get the compiler specific settings +include $(JDK_MAKE_SHARED_DIR)/Compiler-$(CC_VERSION).gmk + diff --git a/make/common/shared/Sanity-Settings.gmk b/make/common/shared/Sanity-Settings.gmk index 54f1f5fc1436b08754637bacf2a41826757cb710..987ba93489ad6f4640aec190e8f51ebb9f504c2b 100644 --- a/make/common/shared/Sanity-Settings.gmk +++ b/make/common/shared/Sanity-Settings.gmk @@ -97,7 +97,7 @@ ifeq ($(PLATFORM),solaris) endif ifeq ($(PLATFORM),windows) ALL_SETTINGS+=$(call addAltSetting,MSVCRT_DLL_PATH) - ifeq ($(ARCH_DATA_MODEL), 32) + ifneq ($(MSVCRNN_DLL),) ALL_SETTINGS+=$(call addAltSetting,MSVCRNN_DLL_PATH) endif ALL_SETTINGS+=$(call addAltSetting,MSDEVTOOLS_PATH) diff --git a/make/common/shared/Sanity.gmk b/make/common/shared/Sanity.gmk index a3c421e74b37759e7bd836475374c86a5babc893..23e3818353b0a3f32950587252d6d0231e6ae0dc 100644 --- a/make/common/shared/Sanity.gmk +++ b/make/common/shared/Sanity.gmk @@ -129,7 +129,7 @@ ifeq ($(PLATFORM), windows) ifeq ($(_OS_VERSION),) OS_VERSION = 5.0 else - OS_VERSION = $(_OS_VERSION) + OS_VERSION = $(call MajorVersion,$(_OS_VERSION)).$(call MinorVersion,$(_OS_VERSION)) endif OS_VARIANT_NAME := $(WINDOWS_MAPPING-$(OS_VERSION)) OS_VARIANT_VERSION := $(OS_VERSION) @@ -864,7 +864,7 @@ ifeq ($(PLATFORM), windows) " and/or check your value of ALT_MSVCRT_DLL_PATH. \n" \ "" >> $(ERROR_FILE) ; \ fi - ifeq ($(ARCH_DATA_MODEL), 32) + ifneq ($(MSVCRNN_DLL),) @if [ ! -r "$(MSVCRNN_DLL_PATH)/$(MSVCRNN_DLL)" ]; then \ $(ECHO) "ERROR: You do not have access to $(MSVCRNN_DLL). \n" \ " Please check your access to \n" \ @@ -1314,8 +1314,8 @@ ifdef LINK_VER fi @if [ "$(LINK_CHECK)" != "same" ]; then \ $(ECHO) "WARNING: To build Java 2 SDK $(JDK_VERSION) you need : \n" \ - " $(COMPILER_VERSION) - link.exe version \"$(REQUIRED_LINK_VER)\" \n" \ - " Specifically the $(COMPILER_NAME) link.exe. \n " \ + " $(REQUIRED_COMPILER_VERSION) - link.exe version \"$(REQUIRED_LINK_VER)\" \n" \ + " Specifically the $(REQUIRED_COMPILER_NAME) link.exe. \n " \ " $(YOU_ARE_USING) Linker version \"$(LINK_VER)\" \n" \ "" >> $(WARNING_FILE) ; \ fi @@ -1332,21 +1332,13 @@ sane-compiler: sane-link fi ifndef OPENJDK @if [ "$(CC_CHECK)" != "same" ]; then \ - $(ECHO) "WARNING: The $(PLATFORM) compiler is not version $(COMPILER_VERSION) $(REQUIRED_CC_VER) \n" \ - " Specifically the $(COMPILER_NAME) compiler. \n " \ - " $(YOU_ARE_USING) compiler version: $(CC_VER) \n" \ + $(ECHO) "WARNING: The $(PLATFORM) compiler is not version $(REQUIRED_COMPILER_VERSION) $(REQUIRED_CC_VER) \n" \ + " Specifically the $(REQUIRED_COMPILER_NAME) compiler. \n " \ + " $(YOU_ARE_USING) $(COMPILER_VERSION): $(CC_VER) \n" \ " The compiler was obtained from the following location: \n" \ " $(COMPILER_PATH) \n" \ "" >> $(WARNING_FILE) ; \ fi - ifeq ($(PLATFORM), windows) - ifeq ($(ARCH_DATA_MODEL), 64) - ifneq ($(COMPILER_VERSION), VS2005) - @$(ECHO) "WARNING: Should be using VS2005 compiler on 64bit platform. \n" \ - "" >> $(WARNING_FILE) - endif - endif - endif endif ###################################################### diff --git a/make/java/management/Makefile b/make/java/management/Makefile index 466d2212afe0433258405ab6bde534a2f80ccabe..f579e10c105afe770511d684f0785ba54ccdf920 100644 --- a/make/java/management/Makefile +++ b/make/java/management/Makefile @@ -46,6 +46,8 @@ include $(BUILDDIR)/common/Mapfile-vers.gmk # include FILES_c.gmk +# We don't need snmp here. +AUTO_JAVA_PRUNE = snmp AUTO_FILES_JAVA_DIRS = java/lang/management com/sun/management sun/management include Exportedfiles.gmk diff --git a/make/java/nio/FILES_java.gmk b/make/java/nio/FILES_java.gmk index 5027274f20932363755084d7dd2717723fb5215f..637b8dc4f96c39f5d84334f3c1d288f1b7b3f11d 100644 --- a/make/java/nio/FILES_java.gmk +++ b/make/java/nio/FILES_java.gmk @@ -220,6 +220,8 @@ FILES_src = \ sun/nio/ch/Util.java \ \ sun/nio/cs/AbstractCharsetProvider.java \ + sun/nio/cs/ArrayDecoder.java \ + sun/nio/cs/ArrayEncoder.java \ sun/nio/cs/FastCharsetProvider.java \ sun/nio/cs/HistoricallyNamedCharset.java \ sun/nio/cs/ISO_8859_1.java \ diff --git a/make/javax/management/Makefile b/make/javax/management/Makefile index 2085e38a88bbd4c0d187a4954cf2628873c1ca29..02527ec2d21fdc1d98a410834ffa250aaebf28a7 100644 --- a/make/javax/management/Makefile +++ b/make/javax/management/Makefile @@ -35,6 +35,7 @@ include $(BUILDDIR)/common/Defs.gmk # # Files to compile # +AUTO_JAVA_PRUNE = snmp AUTO_FILES_JAVA_DIRS = javax/management com/sun/jmx com/sun/management/jmx # diff --git a/make/sun/management/Makefile b/make/sun/management/Makefile index 6ae5d85d81751a29f7a612908afba149b4dc3d37..bb7ad8935c94fd655cf31e37293a7cfa485d2189 100644 --- a/make/sun/management/Makefile +++ b/make/sun/management/Makefile @@ -35,7 +35,16 @@ MGMT_LIB_SRC = $(SHARE_SRC)/lib/management all build:: properties aclfile jmxremotefiles -SUBDIRS = snmp jmxremote +# When building the openjdk, build snmp only if importing binary plugs, +ifdef OPENJDK + ifeq ($(IMPORT_BINARY_PLUGS),true) + SUBDIRS = snmp + endif +else + SUBDIRS = snmp +endif +SUBDIRS += jmxremote + all build clean clobber:: $(SUBDIRS-loop) diff --git a/src/share/classes/java/lang/StringCoding.java b/src/share/classes/java/lang/StringCoding.java index 833fdf5f603ba8801108f84f6cf16f82d09930b6..885db317af5fede1f50758de3f68e9c51d2080c6 100644 --- a/src/share/classes/java/lang/StringCoding.java +++ b/src/share/classes/java/lang/StringCoding.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,13 +25,10 @@ package java.lang; -import java.io.CharConversionException; import java.io.UnsupportedEncodingException; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.BufferOverflowException; -import java.nio.BufferUnderflowException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; @@ -39,11 +36,12 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.MalformedInputException; import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; import sun.misc.MessageUtils; import sun.nio.cs.HistoricallyNamedCharset; +import sun.nio.cs.ArrayDecoder; +import sun.nio.cs.ArrayEncoder; /** * Utility class for string encoding and decoding. @@ -74,10 +72,8 @@ class StringCoding { // Trim the given byte array to the given length // - private static byte[] safeTrim(byte[] ba, int len, Charset cs) { - if (len == ba.length - && (System.getSecurityManager() == null - || cs.getClass().getClassLoader0() == null)) + private static byte[] safeTrim(byte[] ba, int len, Charset cs, boolean isTrusted) { + if (len == ba.length && (isTrusted || System.getSecurityManager() == null)) return ba; else return Arrays.copyOf(ba, len); @@ -85,10 +81,9 @@ class StringCoding { // Trim the given char array to the given length // - private static char[] safeTrim(char[] ca, int len, Charset cs) { - if (len == ca.length - && (System.getSecurityManager() == null - || cs.getClass().getClassLoader0() == null)) + private static char[] safeTrim(char[] ca, int len, + Charset cs, boolean isTrusted) { + if (len == ca.length && (isTrusted || System.getSecurityManager() == null)) return ca; else return Arrays.copyOf(ca, len); @@ -128,6 +123,7 @@ class StringCoding { private final String requestedCharsetName; private final Charset cs; private final CharsetDecoder cd; + private final boolean isTrusted; private StringDecoder(Charset cs, String rcn) { this.requestedCharsetName = rcn; @@ -135,6 +131,7 @@ class StringCoding { this.cd = cs.newDecoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE); + this.isTrusted = (cs.getClass().getClassLoader0() == null); } String charsetName() { @@ -152,24 +149,28 @@ class StringCoding { char[] ca = new char[en]; if (len == 0) return ca; - cd.reset(); - ByteBuffer bb = ByteBuffer.wrap(ba, off, len); - CharBuffer cb = CharBuffer.wrap(ca); - try { - CoderResult cr = cd.decode(bb, cb, true); - if (!cr.isUnderflow()) - cr.throwException(); - cr = cd.flush(cb); - if (!cr.isUnderflow()) - cr.throwException(); - } catch (CharacterCodingException x) { - // Substitution is always enabled, - // so this shouldn't happen - throw new Error(x); + if (cd instanceof ArrayDecoder) { + int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca); + return safeTrim(ca, clen, cs, isTrusted); + } else { + cd.reset(); + ByteBuffer bb = ByteBuffer.wrap(ba, off, len); + CharBuffer cb = CharBuffer.wrap(ca); + try { + CoderResult cr = cd.decode(bb, cb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = cd.flush(cb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ca, cb.position(), cs, isTrusted); } - return safeTrim(ca, cb.position(), cs); } - } static char[] decode(String charsetName, byte[] ba, int off, int len) @@ -193,8 +194,57 @@ class StringCoding { } static char[] decode(Charset cs, byte[] ba, int off, int len) { - StringDecoder sd = new StringDecoder(cs, cs.name()); - return sd.decode(Arrays.copyOfRange(ba, off, off + len), 0, len); + // (1)We never cache the "external" cs, the only benefit of creating + // an additional StringDe/Encoder object to wrap it is to share the + // de/encode() method. These SD/E objects are short-lifed, the young-gen + // gc should be able to take care of them well. But the best approash + // is still not to generate them if not really necessary. + // (2)The defensive copy of the input byte/char[] has a big performance + // impact, as well as the outgoing result byte/char[]. Need to do the + // optimization check of (sm==null && classLoader0==null) for both. + // (3)getClass().getClassLoader0() is expensive + // (4)There might be a timing gap in isTrusted setting. getClassLoader0() + // is only chcked (and then isTrusted gets set) when (SM==null). It is + // possible that the SM==null for now but then SM is NOT null later + // when safeTrim() is invoked...the "safe" way to do is to redundant + // check (... && (isTrusted || SM == null || getClassLoader0())) in trim + // but it then can be argued that the SM is null when the opertaion + // is started... + CharsetDecoder cd = cs.newDecoder(); + int en = scale(len, cd.maxCharsPerByte()); + char[] ca = new char[en]; + if (len == 0) + return ca; + boolean isTrusted = false; + if (System.getSecurityManager() != null) { + if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) { + ba = Arrays.copyOfRange(ba, off, off + len); + off = 0; + } + } + if (cd instanceof ArrayDecoder) { + int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca); + return safeTrim(ca, clen, cs, isTrusted); + } else { + cd.onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE) + .reset(); + ByteBuffer bb = ByteBuffer.wrap(ba, off, len); + CharBuffer cb = CharBuffer.wrap(ca); + try { + CoderResult cr = cd.decode(bb, cb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = cd.flush(cb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ca, cb.position(), cs, isTrusted); + } } static char[] decode(byte[] ba, int off, int len) { @@ -218,14 +268,12 @@ class StringCoding { } } - - - // -- Encoding -- private static class StringEncoder { private Charset cs; private CharsetEncoder ce; private final String requestedCharsetName; + private final boolean isTrusted; private StringEncoder(Charset cs, String rcn) { this.requestedCharsetName = rcn; @@ -233,6 +281,7 @@ class StringCoding { this.ce = cs.newEncoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE); + this.isTrusted = (cs.getClass().getClassLoader0() == null); } String charsetName() { @@ -250,23 +299,27 @@ class StringCoding { byte[] ba = new byte[en]; if (len == 0) return ba; - - ce.reset(); - ByteBuffer bb = ByteBuffer.wrap(ba); - CharBuffer cb = CharBuffer.wrap(ca, off, len); - try { - CoderResult cr = ce.encode(cb, bb, true); - if (!cr.isUnderflow()) - cr.throwException(); - cr = ce.flush(bb); - if (!cr.isUnderflow()) - cr.throwException(); - } catch (CharacterCodingException x) { - // Substitution is always enabled, - // so this shouldn't happen - throw new Error(x); + if (ce instanceof ArrayEncoder) { + int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba); + return safeTrim(ba, blen, cs, isTrusted); + } else { + ce.reset(); + ByteBuffer bb = ByteBuffer.wrap(ba); + CharBuffer cb = CharBuffer.wrap(ca, off, len); + try { + CoderResult cr = ce.encode(cb, bb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = ce.flush(bb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ba, bb.position(), cs, isTrusted); } - return safeTrim(ba, bb.position(), cs); } } @@ -291,8 +344,39 @@ class StringCoding { } static byte[] encode(Charset cs, char[] ca, int off, int len) { - StringEncoder se = new StringEncoder(cs, cs.name()); - return se.encode(Arrays.copyOfRange(ca, off, off + len), 0, len); + CharsetEncoder ce = cs.newEncoder(); + int en = scale(len, ce.maxBytesPerChar()); + byte[] ba = new byte[en]; + if (len == 0) + return ba; + boolean isTrusted = false; + if (System.getSecurityManager() != null) { + if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) { + ca = Arrays.copyOfRange(ca, off, off + len); + off = 0; + } + } + if (ce instanceof ArrayEncoder) { + int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba); + return safeTrim(ba, blen, cs, isTrusted); + } else { + ce.onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE) + .reset(); + ByteBuffer bb = ByteBuffer.wrap(ba); + CharBuffer cb = CharBuffer.wrap(ca, off, len); + try { + CoderResult cr = ce.encode(cb, bb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = ce.flush(bb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + throw new Error(x); + } + return safeTrim(ba, bb.position(), cs, isTrusted); + } } static byte[] encode(char[] ca, int off, int len) { diff --git a/src/share/classes/java/lang/System.java b/src/share/classes/java/lang/System.java index eb62b4087e9e59b6cebf69f9491d012ffe9e7b0f..68958dd0898dbcd604871af94e132ad73a0b8f43 100644 --- a/src/share/classes/java/lang/System.java +++ b/src/share/classes/java/lang/System.java @@ -34,7 +34,6 @@ import java.security.AllPermission; import java.nio.channels.Channel; import java.nio.channels.spi.SelectorProvider; import sun.nio.ch.Interruptible; -import sun.net.InetAddressCachePolicy; import sun.reflect.Reflection; import sun.security.util.SecurityConstants; import sun.reflect.annotation.AnnotationType; @@ -310,7 +309,6 @@ public final class System { } security = s; - InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.FOREVER); } /** diff --git a/src/share/classes/java/util/regex/Pattern.java b/src/share/classes/java/util/regex/Pattern.java index bfc6d5925e9222f4b3dee1f2812673cb1dfd32be..bda83849a376d25f2e461c6e0c60c3f8dd233365 100644 --- a/src/share/classes/java/util/regex/Pattern.java +++ b/src/share/classes/java/util/regex/Pattern.java @@ -2567,7 +2567,8 @@ loop: for(int x=0, offset=0; x adaptorClass = + Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME,true,null); + final Method initializeMethod = + adaptorClass.getMethod("initialize", + String.class, Properties.class); + initializeMethod.invoke(null,snmpPort,props); + } catch (ClassNotFoundException x) { + // The SNMP packages are not present: throws an exception. + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } catch (NoSuchMethodException x) { + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof RuntimeException) + throw (RuntimeException) cause; + else if (cause instanceof Error) + throw (Error) cause; + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,cause); + } catch (IllegalAccessException x) { + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } + } + // read config file and initialize the properties private static void readConfiguration(String fname, Properties p) { if (fname == null) { diff --git a/src/share/classes/sun/nio/cs/ArrayDecoder.java b/src/share/classes/sun/nio/cs/ArrayDecoder.java new file mode 100644 index 0000000000000000000000000000000000000000..daff5ec39d1744ef722b015c2fe72b4e75e206bb --- /dev/null +++ b/src/share/classes/sun/nio/cs/ArrayDecoder.java @@ -0,0 +1,35 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.nio.cs; + +/* + * FastPath byte[]->char[] decoder, REPLACE on malformed or + * unmappable input. + */ + +public interface ArrayDecoder { + int decode(byte[] src, int off, int len, char[] dst); +} diff --git a/src/share/classes/sun/nio/cs/ArrayEncoder.java b/src/share/classes/sun/nio/cs/ArrayEncoder.java new file mode 100644 index 0000000000000000000000000000000000000000..1eb4726f70b7ecc03962156d0dddb4ee10ba5ca8 --- /dev/null +++ b/src/share/classes/sun/nio/cs/ArrayEncoder.java @@ -0,0 +1,35 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.nio.cs; + +/* + * FastPath char[]->byte[] encoder, REPLACE on malformed input or + * unmappable input. + */ + +public interface ArrayEncoder { + int encode(char[] src, int off, int len, byte[] dst); +} diff --git a/src/share/classes/sun/nio/cs/ISO_8859_1.java b/src/share/classes/sun/nio/cs/ISO_8859_1.java index ad27a1507ac3722db2533d99f0ad17e45e05a9cd..7eb3b5b8a833b661f2f958e8f6056e58e5f417bd 100644 --- a/src/share/classes/sun/nio/cs/ISO_8859_1.java +++ b/src/share/classes/sun/nio/cs/ISO_8859_1.java @@ -23,9 +23,6 @@ * have any questions. */ -/* - */ - package sun.nio.cs; import java.nio.ByteBuffer; @@ -34,10 +31,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.MalformedInputException; -import java.nio.charset.UnmappableCharacterException; - +import java.util.Arrays; class ISO_8859_1 extends Charset @@ -65,8 +59,8 @@ class ISO_8859_1 return new Encoder(this); } - private static class Decoder extends CharsetDecoder { - + private static class Decoder extends CharsetDecoder + implements ArrayDecoder { private Decoder(Charset cs) { super(cs, 1.0f, 1.0f); } @@ -127,10 +121,18 @@ class ISO_8859_1 return decodeBufferLoop(src, dst); } + public int decode(byte[] src, int sp, int len, char[] dst) { + if (len > dst.length) + len = dst.length; + int dp = 0; + while (dp < len) + dst[dp++] = (char)(src[sp++] & 0xff); + return dp; + } } - private static class Encoder extends CharsetEncoder { - + private static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Encoder(Charset cs) { super(cs, 1.0f, 1.0f); } @@ -139,6 +141,10 @@ class ISO_8859_1 return c <= '\u00FF'; } + public boolean isLegalReplacement(byte[] repl) { + return (repl.length == 1); // we accept any byte value + } + private final Surrogate.Parser sgp = new Surrogate.Parser(); private CoderResult encodeArrayLoop(CharBuffer src, @@ -208,5 +214,31 @@ class ISO_8859_1 return encodeBufferLoop(src, dst); } + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + if (c <= '\u00FF') { + dst[dp++] = (byte)c; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } } diff --git a/src/share/classes/sun/nio/cs/SingleByte.java b/src/share/classes/sun/nio/cs/SingleByte.java index fdbf4e3c6436234a523de587aaefd062d1fccb55..9b0531eebd93a90ce0978cdff65ca252f08f623e 100644 --- a/src/share/classes/sun/nio/cs/SingleByte.java +++ b/src/share/classes/sun/nio/cs/SingleByte.java @@ -32,6 +32,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; +import java.util.Arrays; import static sun.nio.cs.CharsetMapping.*; public class SingleByte @@ -45,7 +46,8 @@ public class SingleByte return cr; } - public static class Decoder extends CharsetDecoder { + final public static class Decoder extends CharsetDecoder + implements ArrayDecoder { private final char[] b2c; public Decoder(Charset cs, char[] b2c) { @@ -108,9 +110,29 @@ public class SingleByte private final char decode(int b) { return b2c[b + 128]; } + + private char repl = '\uFFFD'; + protected void implReplaceWith(String newReplacement) { + repl = newReplacement.charAt(0); + } + + public int decode(byte[] src, int sp, int len, char[] dst) { + if (len > dst.length) + len = dst.length; + int dp = 0; + while (dp < len) { + dst[dp] = decode(src[sp++]); + if (dst[dp] == UNMAPPABLE_DECODING) { + dst[dp] = repl; + } + dp++; + } + return dp; + } } - public static class Encoder extends CharsetEncoder { + final public static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Surrogate.Parser sgp; private final char[] c2b; private final char[] c2bIndex; @@ -125,6 +147,11 @@ public class SingleByte return encode(c) != UNMAPPABLE_ENCODING; } + public boolean isLegalReplacement(byte[] repl) { + return ((repl.length == 1 && repl[0] == (byte)'?') || + super.isLegalReplacement(repl)); + } + private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { char[] sa = src.array(); int sp = src.arrayOffset() + src.position(); @@ -200,6 +227,34 @@ public class SingleByte return UNMAPPABLE_ENCODING; return c2b[index + (ch & 0xff)]; } + + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + int b = encode(c); + if (b != UNMAPPABLE_ENCODING) { + dst[dp++] = (byte)b; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } // init the c2b and c2bIndex tables from b2c. diff --git a/src/share/classes/sun/nio/cs/US_ASCII.java b/src/share/classes/sun/nio/cs/US_ASCII.java index d22fa64e352446fdd73f4218fc9bdb32ac8a526d..fa718450768cb1f6609496f796e3cc23f9c5a6ac 100644 --- a/src/share/classes/sun/nio/cs/US_ASCII.java +++ b/src/share/classes/sun/nio/cs/US_ASCII.java @@ -31,10 +31,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.MalformedInputException; -import java.nio.charset.UnmappableCharacterException; - +import java.util.Arrays; public class US_ASCII extends Charset @@ -61,7 +58,8 @@ public class US_ASCII return new Encoder(this); } - private static class Decoder extends CharsetDecoder { + private static class Decoder extends CharsetDecoder + implements ArrayDecoder { private Decoder(Charset cs) { super(cs, 1.0f, 1.0f); @@ -131,9 +129,27 @@ public class US_ASCII return decodeBufferLoop(src, dst); } + private char repl = '\uFFFD'; + protected void implReplaceWith(String newReplacement) { + repl = newReplacement.charAt(0); + } + + public int decode(byte[] src, int sp, int len, char[] dst) { + int dp = 0; + len = Math.min(len, dst.length); + while (dp < len) { + byte b = src[sp++]; + if (b >= 0) + dst[dp++] = (char)b; + else + dst[dp++] = repl; + } + return dp; + } } - private static class Encoder extends CharsetEncoder { + private static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Encoder(Charset cs) { super(cs, 1.0f, 1.0f); @@ -143,8 +159,11 @@ public class US_ASCII return c < 0x80; } - private final Surrogate.Parser sgp = new Surrogate.Parser(); + public boolean isLegalReplacement(byte[] repl) { + return (repl.length == 1 && repl[0] >= 0); + } + private final Surrogate.Parser sgp = new Surrogate.Parser(); private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { @@ -213,6 +232,32 @@ public class US_ASCII return encodeBufferLoop(src, dst); } + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + if (c < 0x80) { + dst[dp++] = (byte)c; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } } diff --git a/src/share/classes/sun/security/tools/KeyTool.java b/src/share/classes/sun/security/tools/KeyTool.java index ca2d6a384ab8f0a627c2a69e2e23ed6e82b36ef3..163e78fc5cfe58194b9b21c670043251594ef313 100644 --- a/src/share/classes/sun/security/tools/KeyTool.java +++ b/src/share/classes/sun/security/tools/KeyTool.java @@ -875,6 +875,18 @@ public final class KeyTool { if (filename != null) { inStream = new FileInputStream(filename); } + // Read the full stream before feeding to X509Factory, + // otherwise, keytool -gencert | keytool -importcert + // might not work properly, since -gencert is slow + // and there's no data in the pipe at the beginning. + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + byte[] b = new byte[4096]; + while (true) { + int len = inStream.read(b); + if (len < 0) break; + bout.write(b, 0, len); + } + inStream = new ByteArrayInputStream(bout.toByteArray()); try { String importAlias = (alias!=null)?alias:keyAlias; if (keyStore.entryInstanceOf(importAlias, KeyStore.PrivateKeyEntry.class)) { @@ -1060,8 +1072,8 @@ public final class KeyTool { X509CertInfo info = new X509CertInfo(); info.set(X509CertInfo.VALIDITY, interval); - info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber - ((int)(firstDate.getTime()/1000))); + info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); info.set(X509CertInfo.ALGORITHM_ID, @@ -2109,8 +2121,8 @@ public final class KeyTool { certInfo.set(X509CertInfo.VALIDITY, interval); // Make new serial number - certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber - ((int)(firstDate.getTime()/1000))); + certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); // Set owner and issuer fields X500Name owner; diff --git a/src/share/classes/sun/security/x509/CertAndKeyGen.java b/src/share/classes/sun/security/x509/CertAndKeyGen.java index 38ca600927b63594064ecb6771848f12edcbef6e..2cf34c871ec733e1b12eb0187c6c69b97c3a0aa7 100644 --- a/src/share/classes/sun/security/x509/CertAndKeyGen.java +++ b/src/share/classes/sun/security/x509/CertAndKeyGen.java @@ -265,8 +265,8 @@ public final class CertAndKeyGen { // Add all mandatory attributes info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); - info.set(X509CertInfo.SERIAL_NUMBER, - new CertificateSerialNumber((int)(firstDate.getTime()/1000))); + info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); AlgorithmId algID = issuer.getAlgorithmId(); info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algID)); diff --git a/src/windows/native/sun/windows/awt.rc b/src/windows/native/sun/windows/awt.rc index aea8a5da0a9e770d61047e8d38657ab86c938785..c9c3f172125b3d71cacd6acd0902ae8801512ef0 100644 --- a/src/windows/native/sun/windows/awt.rc +++ b/src/windows/native/sun/windows/awt.rc @@ -23,7 +23,7 @@ // have any questions. // -#include "afxres.h" +#include "windows.h" // Need 2 defines so macro argument to XSTR will get expanded before quoting. #define XSTR(x) STR(x) diff --git a/src/windows/resource/version.rc b/src/windows/resource/version.rc index 61311efabcfc33afdfd0e489ab2eeb46c631b600..41479562435315d4dfc528f9f9e658b5b14c125c 100644 --- a/src/windows/resource/version.rc +++ b/src/windows/resource/version.rc @@ -23,7 +23,7 @@ // have any questions. // -#include "afxres.h" +#include "windows.h" // Need 2 defines so macro argument to XSTR will get expanded before quoting. #define XSTR(x) STR(x) diff --git a/test/com/sun/jmx/snmp/SnmpOidHashCode.java b/test/com/sun/jmx/snmp/SnmpOidHashCode.java index 907d00913f42d8210cabf67b8948f8c415304ca7..4a815de0386d282080e30915132283d5c5206a06 100644 --- a/test/com/sun/jmx/snmp/SnmpOidHashCode.java +++ b/test/com/sun/jmx/snmp/SnmpOidHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,8 @@ * @build SnmpOidHashCode * @run main SnmpOidHashCode */ -import com.sun.jmx.snmp.SnmpOid; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; public class SnmpOidHashCode { public static final String[] oids = { @@ -57,16 +58,81 @@ public class SnmpOidHashCode { ".39."+0xFFFFFFFFL }; + // We use an SnmpOidBuilder in order to adapt this test case to a + // configuration where the SNMP packages are not present in rt.jar. + // + public static final class SnmpOidBuilder { + public static final String SNMP_OID_CLASS_NAME = + "com.sun.jmx.snmp.SnmpOid"; + private static final Class SNMP_OID_CLASS; + private static final Constructor SNMP_OID_CTOR; + static { + Class snmpOidClass; + try { + snmpOidClass = + Class.forName(SNMP_OID_CLASS_NAME, true, null); + } catch (ClassNotFoundException x) { + snmpOidClass = null; + System.err.println("WARNING: can't load "+SNMP_OID_CLASS_NAME); + } catch (NoClassDefFoundError x) { + snmpOidClass = null; + System.err.println("WARNING: can't load "+SNMP_OID_CLASS_NAME); + } + SNMP_OID_CLASS = snmpOidClass; + if (SNMP_OID_CLASS != null) { + try { + SNMP_OID_CTOR = snmpOidClass.getConstructor(String.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_OID_CTOR = null; + } + } + + public static boolean isSnmpPresent() { + System.out.println(SnmpOidHashCode.class.getName()+ + ": Testing for SNMP Packages..."); + return SNMP_OID_CLASS != null; + } + + public static Object newSnmpOid(String oid) + throws InstantiationException, + IllegalAccessException, + InvocationTargetException { + return SNMP_OID_CTOR.newInstance(oid); + } + + } + + private static Object newSnmpOid(String oid) throws Exception { + try { + return SnmpOidBuilder.newSnmpOid(oid); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception)cause; + if (cause instanceof Error) throw (Error)cause; + throw x; + } + } + public static void main(String args[]) { + if (!SnmpOidBuilder.isSnmpPresent()) { + System.err.println("WARNING: "+ + SnmpOidBuilder.SNMP_OID_CLASS_NAME+" not present."); + System.err.println(SnmpOidHashCode.class.getName()+ + ": test skipped."); + return; + } try { int errCount=0; int collisions=0; for (int i=0;i SNMP_TIME_TICKS_CLASS; + private static final Constructor SNMP_long_CTOR; + private static final Constructor SNMP_LONG_CTOR; + private static final Method SNMP_LONG_VALUE; + static { + Class snmpTimeTicksClass; + try { + snmpTimeTicksClass = + Class.forName(SNMP_TIME_TICKS_CLASS_NAME, true, null); + } catch (ClassNotFoundException x) { + snmpTimeTicksClass = null; + System.err.println("WARNING: can't load "+ + SNMP_TIME_TICKS_CLASS_NAME); + } catch (NoClassDefFoundError x) { + snmpTimeTicksClass = null; + System.err.println("WARNING: can't load "+ + SNMP_TIME_TICKS_CLASS_NAME); + } + SNMP_TIME_TICKS_CLASS = snmpTimeTicksClass; + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_long_CTOR = + SNMP_TIME_TICKS_CLASS.getConstructor(long.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_long_CTOR = null; + } + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_LONG_CTOR = + SNMP_TIME_TICKS_CLASS.getConstructor(Long.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_LONG_CTOR = null; + } + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_LONG_VALUE = + SNMP_TIME_TICKS_CLASS.getMethod("longValue"); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_LONG_VALUE = null; + } + + } + + private final Object timeticks; + + public SnmpTimeticksBuilder(long ticks) throws Exception { + timeticks = newSnmpTimeticks(ticks); + } + public SnmpTimeticksBuilder(Long ticks) throws Exception { + timeticks = newSnmpTimeticks(ticks); + } + public long longValue() throws Exception { + return longValue(timeticks); + } + + public static boolean isSnmpPresent() { + System.out.println(TimeTicksWrapping.class.getName()+ + ": Testing for SNMP Packages..."); + return SNMP_TIME_TICKS_CLASS != null; + } + + private static Object newSnmpTimeticks(long time) + throws Exception { + try { + return SNMP_long_CTOR.newInstance(time); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + private static Object newSnmpTimeticks(Long time) + throws Exception { + try { + return SNMP_LONG_CTOR.newInstance(time); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + private static long longValue(Object o) + throws Exception { + try { + return ((Long)SNMP_LONG_VALUE.invoke(o)).longValue(); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + } + public static final long[] oks = { 0L, 1L, (long)Integer.MAX_VALUE, (long)Integer.MAX_VALUE*2, (long)Integer.MAX_VALUE*2+1L, (long)Integer.MAX_VALUE*2+2L, (long)Integer.MAX_VALUE*3, - SnmpUnsignedInt.MAX_VALUE, SnmpUnsignedInt.MAX_VALUE+1L, - SnmpUnsignedInt.MAX_VALUE*3-1L, Long.MAX_VALUE + SnmpTimeticksBuilder.MAX_VALUE, SnmpTimeticksBuilder.MAX_VALUE+1L, + SnmpTimeticksBuilder.MAX_VALUE*3-1L, Long.MAX_VALUE }; public static final long[] kos = { -1L, (long)Integer.MIN_VALUE, (long)Integer.MIN_VALUE*2, (long)Integer.MIN_VALUE*2-1L, (long)Integer.MIN_VALUE*3, - -SnmpUnsignedInt.MAX_VALUE, -(SnmpUnsignedInt.MAX_VALUE+1L), - -(SnmpUnsignedInt.MAX_VALUE*3-1L), Long.MIN_VALUE + -SnmpTimeticksBuilder.MAX_VALUE, -(SnmpTimeticksBuilder.MAX_VALUE+1L), + -(SnmpTimeticksBuilder.MAX_VALUE*3-1L), Long.MIN_VALUE }; + public static void main(String args[]) { + if (!SnmpTimeticksBuilder.isSnmpPresent()) { + System.err.println("WARNING: "+ + SnmpTimeticksBuilder.SNMP_TIME_TICKS_CLASS_NAME+ + " not present."); + System.err.println(TimeTicksWrapping.class.getName()+ + ": test skipped."); + return; + } try { - SnmpTimeticks t; + SnmpTimeticksBuilder t = null; for (int i=0;i SnmpUnsignedInt.MAX_VALUE) + if (t1 > SnmpTimeticksBuilder.MAX_VALUE) throw new Exception("Value should have wrapped " + "for " + oks[i] + ": " + t1 + " exceeds max: " + - SnmpUnsignedInt.MAX_VALUE); - if (t2 > SnmpUnsignedInt.MAX_VALUE) + SnmpTimeticksBuilder.MAX_VALUE); + if (t2 > SnmpTimeticksBuilder.MAX_VALUE) throw new Exception("Value should have wrapped " + "for " + oks[i] + ": " + t2 + " exceeds max: " + - SnmpUnsignedInt.MAX_VALUE); + SnmpTimeticksBuilder.MAX_VALUE); if (t1 < 0) throw new Exception("Value should have wrapped: " + @@ -90,14 +215,14 @@ public class TimeTicksWrapping { for (int i=0;iy+)z+"), + "xxxyyyzzz", + "8gname", + "yyy"); + //backref Pattern pattern = Pattern.compile("(a*)bc\\1"); check(pattern, "zzzaabcazzz", true); // found "abca" diff --git a/test/sun/nio/cs/FindEncoderBugs.java b/test/sun/nio/cs/FindEncoderBugs.java index 0f4c406d453e7793d8b3e9c528606f4d5e116f9f..54bc5b268a0da580640e9b66985f9c6a2b211337 100644 --- a/test/sun/nio/cs/FindEncoderBugs.java +++ b/test/sun/nio/cs/FindEncoderBugs.java @@ -526,4 +526,3 @@ public class FindEncoderBugs { System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} } - diff --git a/test/sun/nio/cs/StrCodingBenchmark.java b/test/sun/nio/cs/StrCodingBenchmark.java new file mode 100644 index 0000000000000000000000000000000000000000..73256eb2b43434577f9788634cb2133e3b2c5a75 --- /dev/null +++ b/test/sun/nio/cs/StrCodingBenchmark.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.util.*; +import java.nio.*; +import java.nio.charset.*; +import java.util.concurrent.*; +import java.util.regex.Pattern; + +/** + * Usage: java StringCodingBenchmark + * [-Diterations=N] [-Dsize=N] [-Dsubsize=N] [-Dmaxchar=N] + * [-Dfilter=REGEXP] [-DSecurityManager=true] + */ +public class StrCodingBenchmark { + abstract static class Job { + private final String name; + public Job(String name) { this.name = name; } + public String name() { return name; } + public abstract void work() throws Throwable; + } + + private static void collectAllGarbage() { + final java.util.concurrent.CountDownLatch drained + = new java.util.concurrent.CountDownLatch(1); + try { + System.gc(); // enqueue finalizable objects + new Object() { protected void finalize() { + drained.countDown(); }}; + System.gc(); // enqueue detector + drained.await(); // wait for finalizer queue to drain + System.gc(); // cleanup finalized objects + } catch (InterruptedException e) { throw new Error(e); } + } + + /** + * Runs each job for long enough that all the runtime compilers + * have had plenty of time to warm up, i.e. get around to + * compiling everything worth compiling. + * Returns array of average times per job per run. + */ + public static long[] time0(Job ... jobs) throws Throwable { + //final long warmupNanos = 10L * 1000L * 1000L * 1000L; + final long warmupNanos = 100L * 100L; + long[] nanoss = new long[jobs.length]; + for (int i = 0; i < jobs.length; i++) { + collectAllGarbage(); + long t0 = System.nanoTime(); + long t; + int j = 0; + do { jobs[i].work(); j++; } + while ((t = System.nanoTime() - t0) < warmupNanos); + nanoss[i] = t/j; + } + return nanoss; + } + + public static void time(Job ... jobs) throws Throwable { + + long[] warmup = time0(jobs); // Warm up run + long[] nanoss = time0(jobs); // Real timing run + long[] milliss = new long[jobs.length]; + double[] ratios = new double[jobs.length]; + + final String nameHeader = "Method"; + final String millisHeader = "Millis"; + final String ratioHeader = "Ratio"; + + int nameWidth = nameHeader.length(); + int millisWidth = millisHeader.length(); + int ratioWidth = ratioHeader.length(); + + for (int i = 0; i < jobs.length; i++) { + nameWidth = Math.max(nameWidth, jobs[i].name().length()); + + milliss[i] = nanoss[i]/(1000L * 1000L); + millisWidth = Math.max(millisWidth, + String.format("%d", milliss[i]).length()); + + ratios[i] = (double) nanoss[i] / (double) nanoss[0]; + ratioWidth = Math.max(ratioWidth, + String.format("%.3f", ratios[i]).length()); + } + String format = String.format("%%-%ds %%%dd %n", + nameWidth, millisWidth); + String headerFormat = String.format("%%-%ds %%%ds%n", + nameWidth, millisWidth); + System.out.printf(headerFormat, "Method", "Millis"); + + // Print out absolute and relative times, calibrated against first job + for (int i = 0; i < jobs.length; i++) + System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]); + } + + public static Job[] filter(Pattern filter, Job[] jobs) { + if (filter == null) return jobs; + Job[] newJobs = new Job[jobs.length]; + int n = 0; + for (Job job : jobs) + if (filter.matcher(job.name()).find()) + newJobs[n++] = job; + // Arrays.copyOf not available in JDK 5 + Job[] ret = new Job[n]; + System.arraycopy(newJobs, 0, ret, 0, n); + return ret; + } + + static class PermissiveSecurityManger extends SecurityManager { + @Override public void checkPermission(java.security.Permission p) { + } + } + + public static void main(String[] args) throws Throwable { + final int itrs = Integer.getInteger("iterations", 100000); + final int size = Integer.getInteger("size", 2048); + final int subsize = Integer.getInteger("subsize", 128); + final int maxchar = Integer.getInteger("maxchar", 128); + final String regex = System.getProperty("filter"); + final Pattern filter = (regex == null) ? null : Pattern.compile(regex); + final boolean useSecurityManager = Boolean.getBoolean("SecurityManager"); + if (useSecurityManager) + System.setSecurityManager(new PermissiveSecurityManger()); + final Random rnd = new Random(); + + for (Charset charset: Charset.availableCharsets().values()) { + if (!("ISO-8859-1".equals(charset.name()) || + "US-ASCII".equals(charset.name()) || + charset.newDecoder() instanceof sun.nio.cs.SingleByte.Decoder)) + continue; + final String csn = charset.name(); + final Charset cs = charset; + final StringBuilder sb = new StringBuilder(); + { + final CharsetEncoder enc = cs.newEncoder(); + for (int i = 0; i < size; ) { + char c = (char) rnd.nextInt(maxchar); + if (enc.canEncode(c)) { + sb.append(c); + i++; + } + } + } + final String string = sb.toString(); + final byte[] bytes = string.getBytes(cs); + + System.out.printf("%n--------%s---------%n", csn); + for (int sz = 4; sz <= 2048; sz *= 2) { + System.out.printf(" [len=%d]%n", sz); + final byte[] bs = Arrays.copyOf(bytes, sz); + final String str = new String(bs, csn); + Job[] jobs = { + new Job("String decode: csn") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + new String(bs, csn); + }}, + + new Job("String decode: cs") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + new String(bs, cs); + }}, + + new Job("String encode: csn") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + str.getBytes(csn); + }}, + + new Job("String encode: cs") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + str.getBytes(cs); + }}, + }; + time(filter(filter, jobs)); + } + } + } +} diff --git a/test/sun/nio/cs/TestStringCoding.java b/test/sun/nio/cs/TestStringCoding.java new file mode 100644 index 0000000000000000000000000000000000000000..8d0c8f94f240aeeb66a331794769555c825a24cf --- /dev/null +++ b/test/sun/nio/cs/TestStringCoding.java @@ -0,0 +1,151 @@ +/* + * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* @test + @bug 6636323 6636319 + @summary Test if StringCoding and NIO result have the same de/encoding result + * @run main/timeout=2000 TestStringCoding + */ + +import java.util.*; +import java.nio.*; +import java.nio.charset.*; + +public class TestStringCoding { + public static void main(String[] args) throws Throwable { + + for (Boolean hasSM: new boolean[] { false, true }) { + if (hasSM) + System.setSecurityManager(new PermissiveSecurityManger()); + for (Charset cs: Charset.availableCharsets().values()) { + if ("ISO-2022-CN".equals(cs.name()) || + "x-COMPOUND_TEXT".equals(cs.name()) || + "x-JISAutoDetect".equals(cs.name())) + continue; + System.out.printf("Testing(sm=%b) " + cs.name() + "....", hasSM); + // full bmp first + char[] bmpCA = new char[0x10000]; + for (int i = 0; i < 0x10000; i++) { + bmpCA[i] = (char)i; + } + byte[] sbBA = new byte[0x100]; + for (int i = 0; i < 0x100; i++) { + sbBA[i] = (byte)i; + } + test(cs, bmpCA, sbBA); + // "randomed" sizes + Random rnd = new Random(); + for (int i = 0; i < 10; i++) { + int clen = rnd.nextInt(0x10000); + int blen = rnd.nextInt(0x100); + //System.out.printf(" blen=%d, clen=%d%n", blen, clen); + test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen)); + //add a pair of surrogates + int pos = clen / 2; + if ((pos + 1) < blen) { + bmpCA[pos] = '\uD800'; + bmpCA[pos+1] = '\uDC00'; + } + test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen)); + } + System.out.println("done!"); + } + } + } + + static void test(Charset cs, char[] bmpCA, byte[] sbBA) throws Throwable { + String bmpStr = new String(bmpCA); + CharsetDecoder dec = cs.newDecoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + CharsetEncoder enc = cs.newEncoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + + //getBytes(csn); + byte[] baSC = bmpStr.getBytes(cs.name()); + ByteBuffer bf = enc.reset().encode(CharBuffer.wrap(bmpCA)); + byte[] baNIO = new byte[bf.limit()]; + bf.get(baNIO, 0, baNIO.length); + if (!Arrays.equals(baSC, baNIO)) + throw new RuntimeException("getBytes(csn) failed -> " + cs.name()); + + //getBytes(cs); + baSC = bmpStr.getBytes(cs); + if (!Arrays.equals(baSC, baNIO)) + throw new RuntimeException("getBytes(cs) failed -> " + cs.name()); + + //new String(csn); + String strSC = new String(sbBA, cs.name()); + String strNIO = dec.reset().decode(ByteBuffer.wrap(sbBA)).toString(); + if(!strNIO.equals(strSC)) + throw new RuntimeException("new String(csn) failed -> " + cs.name()); + + //new String(cs); + strSC = new String(sbBA, cs); + if (!strNIO.equals(strSC)) + throw new RuntimeException("new String(cs) failed -> " + cs.name()); + + //encode unmappable surrogates + if (enc instanceof sun.nio.cs.ArrayEncoder && + cs.contains(Charset.forName("ASCII"))) { + enc.replaceWith(new byte[] { (byte)'A'}); + sun.nio.cs.ArrayEncoder cae = (sun.nio.cs.ArrayEncoder)enc; + + String str = "ab\uD800\uDC00\uD800\uDC00cd"; + byte[] ba = new byte[str.length() - 2]; + int n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 6 || !"abAAcd".equals(new String(ba, cs.name()))) + throw new RuntimeException("encode1(surrogates) failed -> " + + cs.name()); + + ba = new byte[str.length()]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 6 || !"abAAcd".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode2(surrogates) failed -> " + + cs.name()); + str = "ab\uD800B\uDC00Bcd"; + ba = new byte[str.length()]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 8 || !"abABABcd".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode3(surrogates) failed -> " + + cs.name()); + + ba = new byte[str.length() - 1]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 7 || !"abABABc".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode4(surrogates) failed -> " + + cs.name()); + } + + } + + static class PermissiveSecurityManger extends SecurityManager { + @Override public void checkPermission(java.security.Permission p) {} + } +} diff --git a/test/sun/security/tools/keytool/importreadall.sh b/test/sun/security/tools/keytool/importreadall.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c0c65dedc7a11e95d3db1bd5cffe54fcc778d45 --- /dev/null +++ b/test/sun/security/tools/keytool/importreadall.sh @@ -0,0 +1,62 @@ +# +# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6819272 +# @summary keytool -importcert should read the whole input +# +# @run shell importreadall.sh + +# set a few environment variables so that the shell-script can run stand-alone +# in the source directory +if [ "${TESTSRC}" = "" ] ; then + TESTSRC="." +fi + +if [ "${TESTJAVA}" = "" ] ; then + JAVA_CMD=`which java` + TESTJAVA=`dirname $JAVA_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +KEYTOOL="${TESTJAVA}${FS}bin${FS}keytool -keystore importreadall.jks -storepass changeit -keypass changeit" + +# In case the test is run twice in the same directory + +$KEYTOOL -delete -alias a +$KEYTOOL -delete -alias ca +$KEYTOOL -genkeypair -alias a -dname CN=a || exit 1 +$KEYTOOL -genkeypair -alias ca -dname CN=ca || exit 2 +$KEYTOOL -certreq -alias a | $KEYTOOL -gencert -alias ca | $KEYTOOL -importcert -alias a + +exit $?