diff --git a/.hgtags b/.hgtags index 73855f4306a..1166f5fb614 100644 --- a/.hgtags +++ b/.hgtags @@ -460,5 +460,6 @@ a2008587c13fa05fa2dbfcb09fe987576fbedfd1 jdk-10+32 bbd692ad4fa300ecca7939ffbe3b1d5e52a28cc6 jdk-10+33 89deac44e51517841491ba86ff44aa82a5ca96b3 jdk-10+34 d8c634b016c628622c9abbdc6bf50509e5dedbec jdk-10+35 -cb54a299aa91419cb7caef3992592e7b22488163 jdk-10+36 +0ee20aad71c4f33c426372b4c8bcc1235ce2ec08 jdk-11+0 +959f2f7cbaa6d2ee45d50029744efb219721576c jdk-10+36 4f830b447edf04fb4a52151a5ad44d9bb60723cd jdk-10+37 diff --git a/make/Main.gmk b/make/Main.gmk index 9e4917b4553..0dc06bd98ef 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -637,7 +637,7 @@ else # Declare dependencies between hotspot-* targets $(foreach v, $(JVM_VARIANTS), \ $(eval hotspot-$v: hotspot-$v-gensrc hotspot-$v-libs) \ - $(eval hotspot-$v-libs: hotspot-$v-gensrc) \ + $(eval hotspot-$v-libs: hotspot-$v-gensrc java.base-copy) \ ) hotspot-ide-project: hotspot exploded-image @@ -691,8 +691,9 @@ else jdk.jdwp.agent-libs: jdk.jdwp.agent-gensrc # The swing beans need to have java base properly generated to avoid errors - # in javadoc. - java.desktop-gensrc-src: java.base-gensrc + # in javadoc. The X11 wrappers need the java.base include files to have been + # copied and processed. + java.desktop-gensrc-src: java.base-gensrc java.base-copy # The annotation processing for jdk.internal.vm.ci and jdk.internal.vm.compiler # needs classes from the current JDK. diff --git a/make/autoconf/buildjdk-spec.gmk.in b/make/autoconf/buildjdk-spec.gmk.in index aceaef7c452..b01d00b7c35 100644 --- a/make/autoconf/buildjdk-spec.gmk.in +++ b/make/autoconf/buildjdk-spec.gmk.in @@ -55,6 +55,7 @@ OPENJDK_TARGET_CPU_ARCH := @OPENJDK_BUILD_CPU_ARCH@ OPENJDK_TARGET_CPU_BITS := @OPENJDK_BUILD_CPU_BITS@ OPENJDK_TARGET_CPU_ENDIAN := @OPENJDK_BUILD_CPU_ENDIAN@ OPENJDK_TARGET_CPU_LEGACY := @OPENJDK_BUILD_CPU_LEGACY@ +OPENJDK_TARGET_OS_INCLUDE_SUBDIR := @OPENJDK_BUILD_OS_INCLUDE_SUBDIR@ HOTSPOT_TARGET_OS := @HOTSPOT_BUILD_OS@ HOTSPOT_TARGET_OS_TYPE := @HOTSPOT_BUILD_OS_TYPE@ diff --git a/make/autoconf/flags.m4 b/make/autoconf/flags.m4 index b1c2982aa65..85a014bdbd5 100644 --- a/make/autoconf/flags.m4 +++ b/make/autoconf/flags.m4 @@ -1162,9 +1162,7 @@ AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER], # Setup some hard coded includes $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK \ -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base \ - -I${TOPDIR}/src/java.base/share/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_$1_OS/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_$1_OS_TYPE/native/include \ + -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base/\$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \ -I${TOPDIR}/src/java.base/share/native/libjava \ -I${TOPDIR}/src/java.base/$OPENJDK_$1_OS_TYPE/native/libjava \ -I${TOPDIR}/src/hotspot/share/include \ diff --git a/make/autoconf/generated-configure.sh b/make/autoconf/generated-configure.sh index 3381ec75b7c..c762c36d07b 100644 --- a/make/autoconf/generated-configure.sh +++ b/make/autoconf/generated-configure.sh @@ -886,6 +886,8 @@ JAVA BOOT_JDK JAVA_CHECK JAVAC_CHECK +VERSION_CLASSFILE_MINOR +VERSION_CLASSFILE_MAJOR VENDOR_VERSION_STRING VERSION_DATE VERSION_IS_GA @@ -967,6 +969,7 @@ JDK_VARIANT USERNAME TOPDIR PATH_SEP +OPENJDK_BUILD_OS_INCLUDE_SUBDIR HOTSPOT_BUILD_CPU_DEFINE HOTSPOT_BUILD_CPU_ARCH HOTSPOT_BUILD_CPU @@ -977,6 +980,7 @@ OPENJDK_BUILD_CPU_OSARCH OPENJDK_BUILD_CPU_ISADIR OPENJDK_BUILD_CPU_LEGACY_LIB OPENJDK_BUILD_CPU_LEGACY +OPENJDK_TARGET_OS_INCLUDE_SUBDIR HOTSPOT_TARGET_CPU_DEFINE HOTSPOT_TARGET_CPU_ARCH HOTSPOT_TARGET_CPU @@ -16303,6 +16307,14 @@ $as_echo "$COMPILE_TYPE" >&6; } fi + # For historical reasons, the OS include directories have odd names. + OPENJDK_TARGET_OS_INCLUDE_SUBDIR="$OPENJDK_TARGET_OS" + if test "x$OPENJDK_TARGET_OS" = "xwindows"; then + OPENJDK_TARGET_OS_INCLUDE_SUBDIR="win32" + elif test "x$OPENJDK_TARGET_OS" = "xmacosx"; then + OPENJDK_TARGET_OS_INCLUDE_SUBDIR="darwin" + fi + # Also store the legacy naming of the cpu. @@ -16454,6 +16466,14 @@ $as_echo "$COMPILE_TYPE" >&6; } fi + # For historical reasons, the OS include directories have odd names. + OPENJDK_BUILD_OS_INCLUDE_SUBDIR="$OPENJDK_TARGET_OS" + if test "x$OPENJDK_TARGET_OS" = "xwindows"; then + OPENJDK_BUILD_OS_INCLUDE_SUBDIR="win32" + elif test "x$OPENJDK_TARGET_OS" = "xmacosx"; then + OPENJDK_BUILD_OS_INCLUDE_SUBDIR="darwin" + fi + @@ -25459,6 +25479,10 @@ fi VENDOR_VERSION_STRING="$with_vendor_version_string" fi + # We could define --with flags for these, if really needed + VERSION_CLASSFILE_MAJOR="$DEFAULT_VERSION_CLASSFILE_MAJOR" + VERSION_CLASSFILE_MINOR="$DEFAULT_VERSION_CLASSFILE_MINOR" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for version string" >&5 $as_echo_n "checking for version string... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $VERSION_STRING" >&5 @@ -25480,6 +25504,9 @@ $as_echo "$VERSION_STRING" >&6; } + + + ############################################################################### # # Setup BootJDK, used to bootstrap the build. @@ -52752,9 +52779,7 @@ fi # Setup some hard coded includes COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \ -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base \ - -I${TOPDIR}/src/java.base/share/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_TARGET_OS/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include \ + -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base/\$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \ -I${TOPDIR}/src/java.base/share/native/libjava \ -I${TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava \ -I${TOPDIR}/src/hotspot/share/include \ @@ -53635,9 +53660,7 @@ fi # Setup some hard coded includes OPENJDK_BUILD_COMMON_CCXXFLAGS_JDK="$OPENJDK_BUILD_COMMON_CCXXFLAGS_JDK \ -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base \ - -I${TOPDIR}/src/java.base/share/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_BUILD_OS/native/include \ - -I${TOPDIR}/src/java.base/$OPENJDK_BUILD_OS_TYPE/native/include \ + -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base/\$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \ -I${TOPDIR}/src/java.base/share/native/libjava \ -I${TOPDIR}/src/java.base/$OPENJDK_BUILD_OS_TYPE/native/libjava \ -I${TOPDIR}/src/hotspot/share/include \ diff --git a/make/autoconf/jdk-version.m4 b/make/autoconf/jdk-version.m4 index c2e300e861a..a3024a3c45a 100644 --- a/make/autoconf/jdk-version.m4 +++ b/make/autoconf/jdk-version.m4 @@ -342,6 +342,10 @@ AC_DEFUN_ONCE([JDKVER_SETUP_JDK_VERSION_NUMBERS], VENDOR_VERSION_STRING="$with_vendor_version_string" fi + # We could define --with flags for these, if really needed + VERSION_CLASSFILE_MAJOR="$DEFAULT_VERSION_CLASSFILE_MAJOR" + VERSION_CLASSFILE_MINOR="$DEFAULT_VERSION_CLASSFILE_MINOR" + AC_MSG_CHECKING([for version string]) AC_MSG_RESULT([$VERSION_STRING]) @@ -359,4 +363,7 @@ AC_DEFUN_ONCE([JDKVER_SETUP_JDK_VERSION_NUMBERS], AC_SUBST(VERSION_IS_GA) AC_SUBST(VERSION_DATE) AC_SUBST(VENDOR_VERSION_STRING) + AC_SUBST(VERSION_CLASSFILE_MAJOR) + AC_SUBST(VERSION_CLASSFILE_MINOR) + ]) diff --git a/make/autoconf/platform.m4 b/make/autoconf/platform.m4 index f62f94daace..654ce9b2b4e 100644 --- a/make/autoconf/platform.m4 +++ b/make/autoconf/platform.m4 @@ -478,6 +478,14 @@ AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS_HELPER], fi AC_SUBST(HOTSPOT_$1_CPU_DEFINE) + # For historical reasons, the OS include directories have odd names. + OPENJDK_$1_OS_INCLUDE_SUBDIR="$OPENJDK_TARGET_OS" + if test "x$OPENJDK_TARGET_OS" = "xwindows"; then + OPENJDK_$1_OS_INCLUDE_SUBDIR="win32" + elif test "x$OPENJDK_TARGET_OS" = "xmacosx"; then + OPENJDK_$1_OS_INCLUDE_SUBDIR="darwin" + fi + AC_SUBST(OPENJDK_$1_OS_INCLUDE_SUBDIR) ]) AC_DEFUN([PLATFORM_SET_RELEASE_FILE_OS_VALUES], diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index c41d0b164d1..747472112b4 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -78,6 +78,7 @@ OPENJDK_TARGET_CPU_ISADIR:=@OPENJDK_TARGET_CPU_ISADIR@ OPENJDK_TARGET_CPU_LEGACY:=@OPENJDK_TARGET_CPU_LEGACY@ OPENJDK_TARGET_CPU_LEGACY_LIB:=@OPENJDK_TARGET_CPU_LEGACY_LIB@ OPENJDK_TARGET_CPU_OSARCH:=@OPENJDK_TARGET_CPU_OSARCH@ +OPENJDK_TARGET_OS_INCLUDE_SUBIDR:=@OPENJDK_TARGET_OS_INCLUDE_SUBDIR@ HOTSPOT_TARGET_OS := @HOTSPOT_TARGET_OS@ HOTSPOT_TARGET_OS_TYPE := @HOTSPOT_TARGET_OS_TYPE@ @@ -100,6 +101,8 @@ OPENJDK_BUILD_CPU_ARCH:=@OPENJDK_BUILD_CPU_ARCH@ OPENJDK_BUILD_CPU_BITS:=@OPENJDK_BUILD_CPU_BITS@ OPENJDK_BUILD_CPU_ENDIAN:=@OPENJDK_BUILD_CPU_ENDIAN@ +OPENJDK_BUILD_OS_INCLUDE_SUBIDR:=@OPENJDK_TARGET_OS_INCLUDE_SUBDIR@ + # Target platform value in ModuleTarget class file attribute. OPENJDK_MODULE_TARGET_PLATFORM:=@OPENJDK_MODULE_TARGET_PLATFORM@ @@ -175,6 +178,10 @@ VERSION_DATE := @VERSION_DATE@ # Vendor version string VENDOR_VERSION_STRING := @VENDOR_VERSION_STRING@ +# Class-file version +VERSION_CLASSFILE_MAJOR := @VERSION_CLASSFILE_MAJOR@ +VERSION_CLASSFILE_MINOR := @VERSION_CLASSFILE_MINOR@ + # Convenience CFLAGS settings for passing version information into native programs. VERSION_CFLAGS := \ -DVERSION_FEATURE=$(VERSION_FEATURE) \ @@ -190,6 +197,8 @@ VERSION_CFLAGS := \ -DVERSION_SPECIFICATION='"$(VERSION_SPECIFICATION)"' \ -DVERSION_DATE='"$(VERSION_DATE)"' \ -DVENDOR_VERSION_STRING='"$(VENDOR_VERSION_STRING)"' \ + -DVERSION_CLASSFILE_MAJOR=$(VERSION_CLASSFILE_MAJOR) \ + -DVERSION_CLASSFILE_MINOR=$(VERSION_CLASSFILE_MINOR) \ # # Platform naming variables diff --git a/make/autoconf/version-numbers b/make/autoconf/version-numbers index 60d565c1805..fb748470c00 100644 --- a/make/autoconf/version-numbers +++ b/make/autoconf/version-numbers @@ -30,6 +30,8 @@ DEFAULT_VERSION_INTERIM=0 DEFAULT_VERSION_UPDATE=0 DEFAULT_VERSION_PATCH=0 DEFAULT_VERSION_DATE=2018-03-20 +DEFAULT_VERSION_CLASSFILE_MAJOR=55 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`" +DEFAULT_VERSION_CLASSFILE_MINOR=0 LAUNCHER_NAME=openjdk PRODUCT_NAME=OpenJDK diff --git a/make/common/SetupJavaCompilers.gmk b/make/common/SetupJavaCompilers.gmk index 72bc7e442b7..02b6e442f67 100644 --- a/make/common/SetupJavaCompilers.gmk +++ b/make/common/SetupJavaCompilers.gmk @@ -69,7 +69,7 @@ $(eval $(call SetupJavaCompiler,GENERATE_OLDBYTECODE, \ $(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE, \ JVM := $(JAVA_JAVAC), \ JAVAC := $(NEW_JAVAC), \ - FLAGS := -source 10 -target 10 --doclint-format html5 \ + FLAGS := -source 11 -target 11 --doclint-format html5 \ -encoding ascii -XDignore.symbol.file=true $(JAVAC_WARNINGS), \ SERVER_DIR := $(SJAVAC_SERVER_DIR), \ SERVER_JVM := $(SJAVAC_SERVER_JAVA))) @@ -79,7 +79,7 @@ $(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE, \ $(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE_NOWARNINGS, \ JVM := $(JAVA_JAVAC), \ JAVAC := $(NEW_JAVAC), \ - FLAGS := -source 10 -target 10 \ + FLAGS := -source 11 -target 11 \ -encoding ascii -XDignore.symbol.file=true $(DISABLE_WARNINGS), \ SERVER_DIR := $(SJAVAC_SERVER_DIR), \ SERVER_JVM := $(SJAVAC_SERVER_JAVA))) diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js index 5066599a924..d01fdaeaa16 100644 --- a/make/conf/jib-profiles.js +++ b/make/conf/jib-profiles.js @@ -829,7 +829,7 @@ var getJibProfilesDependencies = function (input, common) { jtreg: { server: "javare", revision: "4.2", - build_number: "b10", + build_number: "b11", checksum_file: "MD5_VALUES", file: "jtreg_bin-4.2.zip", environment_name: "JT_HOME", diff --git a/make/copy/Copy-java.base.gmk b/make/copy/Copy-java.base.gmk index 74759879179..096f6c0e903 100644 --- a/make/copy/Copy-java.base.gmk +++ b/make/copy/Copy-java.base.gmk @@ -24,6 +24,7 @@ # include CopyCommon.gmk +include TextFileProcessing.gmk $(eval $(call IncludeCustomExtension, copy/Copy-java.base.gmk)) @@ -244,3 +245,16 @@ ifeq ($(ENABLE_LIBFFI_BUNDLING), true) endif ################################################################################ +# Generate classfile_constants.h + +$(eval $(call SetupTextFileProcessing, CREATE_CLASSFILE_CONSTANTS_H, \ + SOURCE_FILES := $(TOPDIR)/src/java.base/share/native/include/classfile_constants.h.template, \ + OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/modules_include/java.base/classfile_constants.h, \ + REPLACEMENTS := \ + @@VERSION_CLASSFILE_MAJOR@@ => $(VERSION_CLASSFILE_MAJOR) ; \ + @@VERSION_CLASSFILE_MINOR@@ => $(VERSION_CLASSFILE_MINOR) ; , \ +)) + +TARGETS += $(CREATE_CLASSFILE_CONSTANTS_H) + +################################################################################ diff --git a/make/copy/CopyCommon.gmk b/make/copy/CopyCommon.gmk index 2956e9ddf92..6d4cdbaf747 100644 --- a/make/copy/CopyCommon.gmk +++ b/make/copy/CopyCommon.gmk @@ -39,20 +39,12 @@ ifneq ($(wildcard $(INCLUDE_SOURCE_DIR)/*), ) $(eval $(call SetupCopyFiles, COPY_EXPORTED_INCLUDE, \ SRC := $(INCLUDE_SOURCE_DIR), \ DEST := $(INCLUDE_TARGET_DIR), \ - FILES := $(shell $(FIND) $(INCLUDE_SOURCE_DIR) -type f), \ + FILES := $(filter %.h, $(call CacheFind, $(INCLUDE_SOURCE_DIR))), \ )) TARGETS += $(COPY_EXPORTED_INCLUDE) endif -# For historical reasons, the OS include directories have odd names. -INCLUDE_TARGET_OS_SUBDIR := $(OPENJDK_TARGET_OS) -ifeq ($(OPENJDK_TARGET_OS), windows) - INCLUDE_TARGET_OS_SUBDIR := win32 -else ifeq ($(OPENJDK_TARGET_OS), macosx) - INCLUDE_TARGET_OS_SUBDIR := darwin -endif - # Use the most specific of OS and OS_TYPE. INCLUDE_SOURCE_OS_DIR := $(TOPDIR)/src/$(MODULE)/$(OPENJDK_TARGET_OS)/native/include ifeq ($(wildcard $(INCLUDE_SOURCE_OS_DIR)/*), ) @@ -62,8 +54,8 @@ endif ifneq ($(wildcard $(INCLUDE_SOURCE_OS_DIR)/*), ) $(eval $(call SetupCopyFiles, COPY_EXPORTED_INCLUDE_OS, \ SRC := $(INCLUDE_SOURCE_OS_DIR), \ - DEST := $(INCLUDE_TARGET_DIR)/$(INCLUDE_TARGET_OS_SUBDIR), \ - FILES := $(shell $(FIND) $(INCLUDE_SOURCE_OS_DIR) -type f), \ + DEST := $(INCLUDE_TARGET_DIR)/$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR), \ + FILES := $(filter %.h, $(call CacheFind, $(INCLUDE_SOURCE_OS_DIR))), \ )) TARGETS += $(COPY_EXPORTED_INCLUDE_OS) diff --git a/make/gensrc/GensrcX11Wrappers.gmk b/make/gensrc/GensrcX11Wrappers.gmk index e506c5c01ff..ca95d0edae9 100644 --- a/make/gensrc/GensrcX11Wrappers.gmk +++ b/make/gensrc/GensrcX11Wrappers.gmk @@ -92,10 +92,10 @@ ifneq ($(COMPILE_TYPE), cross) endif SIZER_CFLAGS := \ - -I${TOPDIR}/src/hotspot/share/include \ - -I${TOPDIR}/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE)/include \ - -I$(TOPDIR)/src/java.base/share/native/include \ - -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include \ + -I$(TOPDIR)/src/hotspot/share/include \ + -I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE)/include \ + -I$(SUPPORT_OUTPUTDIR)/modules_include/java.base \ + -I$(SUPPORT_OUTPUTDIR)/modules_include/java.base/$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \ -I$(TOPDIR)/src/java.base/share/native/libjava \ -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \ -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \ diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index 77ee5d99df1..7be0c043f4a 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -59,8 +59,8 @@ JVM_CFLAGS_INCLUDES += \ -I$(TOPDIR)/src/hotspot/share/precompiled \ -I$(TOPDIR)/src/hotspot/share/include \ -I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE)/include \ - -I$(TOPDIR)/src/java.base/share/native/include \ - -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include \ + -I$(SUPPORT_OUTPUTDIR)/modules_include/java.base \ + -I$(SUPPORT_OUTPUTDIR)/modules_include/java.base/$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \ -I$(TOPDIR)/src/java.base/share/native/libjimage \ # diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index 6326ca1e76a..e39d0ee7d66 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -86,8 +86,6 @@ #define JAVA_CLASSFILE_MAGIC 0xCAFEBABE #define JAVA_MIN_SUPPORTED_VERSION 45 -#define JAVA_MAX_SUPPORTED_VERSION 54 -#define JAVA_MAX_SUPPORTED_MINOR_VERSION 0 // Used for two backward compatibility reasons: // - to check for new additions to the class file format in JDK1.5 @@ -110,6 +108,8 @@ #define JAVA_10_VERSION 54 +#define JAVA_11_VERSION 55 + void ClassFileParser::set_class_bad_constant_seen(short bad_constant) { assert((bad_constant == 19 || bad_constant == 20) && _major_version >= JAVA_9_VERSION, "Unexpected bad constant pool entry"); @@ -4642,11 +4642,11 @@ static bool has_illegal_visibility(jint flags) { } static bool is_supported_version(u2 major, u2 minor){ - const u2 max_version = JAVA_MAX_SUPPORTED_VERSION; + const u2 max_version = JVM_CLASSFILE_MAJOR_VERSION; return (major >= JAVA_MIN_SUPPORTED_VERSION) && (major <= max_version) && ((major != max_version) || - (minor <= JAVA_MAX_SUPPORTED_MINOR_VERSION)); + (minor <= JVM_CLASSFILE_MINOR_VERSION)); } void ClassFileParser::verify_legal_field_modifiers(jint flags, @@ -5808,8 +5808,8 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream, _class_name->as_C_string(), _major_version, _minor_version, - JAVA_MAX_SUPPORTED_VERSION, - JAVA_MAX_SUPPORTED_MINOR_VERSION); + JVM_CLASSFILE_MAJOR_VERSION, + JVM_CLASSFILE_MINOR_VERSION); return; } diff --git a/src/hotspot/share/classfile/vmSymbols.hpp b/src/hotspot/share/classfile/vmSymbols.hpp index 65246e04bae..ddc54315ade 100644 --- a/src/hotspot/share/classfile/vmSymbols.hpp +++ b/src/hotspot/share/classfile/vmSymbols.hpp @@ -996,8 +996,8 @@ do_name( montgomerySquare_name, "implMontgomerySquare") \ do_signature(montgomerySquare_signature, "([I[IIJ[I)[I") \ \ - do_class(java_util_ArraysSupport, "java/util/ArraysSupport") \ - do_intrinsic(_vectorizedMismatch, java_util_ArraysSupport, vectorizedMismatch_name, vectorizedMismatch_signature, F_S)\ + do_class(jdk_internal_util_ArraysSupport, "jdk/internal/util/ArraysSupport") \ + do_intrinsic(_vectorizedMismatch, jdk_internal_util_ArraysSupport, vectorizedMismatch_name, vectorizedMismatch_signature, F_S)\ do_name(vectorizedMismatch_name, "vectorizedMismatch") \ do_signature(vectorizedMismatch_signature, "(Ljava/lang/Object;JLjava/lang/Object;JII)I") \ \ diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 2540390b5c9..a8ad10d820d 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -497,7 +497,7 @@ static SpecialFlag const special_jvm_flags[] = { { "MaxRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() }, { "MinRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() }, { "InitialRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() }, - { "UseMembar", JDK_Version::jdk(10), JDK_Version::jdk(11), JDK_Version::jdk(12) }, + { "UseMembar", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() }, { "FastTLABRefill", JDK_Version::jdk(10), JDK_Version::jdk(11), JDK_Version::jdk(12) }, { "SafepointSpinBeforeYield", JDK_Version::jdk(10), JDK_Version::jdk(11), JDK_Version::jdk(12) }, { "DeferThrSuspendLoopCount", JDK_Version::jdk(10), JDK_Version::jdk(11), JDK_Version::jdk(12) }, @@ -674,6 +674,14 @@ static bool lookup_special_flag(const char *flag_name, size_t skip_index) { return false; } +// Verifies the correctness of the entries in the special_jvm_flags table. +// If there is a semantic error (i.e. a bug in the table) such as the obsoletion +// version being earlier than the deprecation version, then a warning is issued +// and verification fails - by returning false. If it is detected that the table +// is out of date, with respect to the current version, then a warning is issued +// but verification does not fail. This allows the VM to operate when the version +// is first updated, without needing to update all the impacted flags at the +// same time. static bool verify_special_jvm_flags() { bool success = true; for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) { @@ -710,7 +718,6 @@ static bool verify_special_jvm_flags() { if (!version_less_than(JDK_Version::current(), flag.obsolete_in)) { if (Flag::find_flag(flag.name) != NULL) { warning("Global variable for obsolete special flag entry \"%s\" should be removed", flag.name); - success = false; } } } @@ -720,7 +727,6 @@ static bool verify_special_jvm_flags() { if (!version_less_than(JDK_Version::current(), flag.expired_in)) { if (Flag::find_flag(flag.name) != NULL) { warning("Global variable for expired flag entry \"%s\" should be removed", flag.name); - success = false; } } } diff --git a/src/java.base/share/classes/com/sun/java/util/jar/pack/Constants.java b/src/java.base/share/classes/com/sun/java/util/jar/pack/Constants.java index 5eb79adb6ae..6d2922fb337 100644 --- a/src/java.base/share/classes/com/sun/java/util/jar/pack/Constants.java +++ b/src/java.base/share/classes/com/sun/java/util/jar/pack/Constants.java @@ -48,6 +48,7 @@ class Constants { 1.8 to 1.8.X 52,0 1.9 to 1.9.X 53,0 1.10 to 1.10.X 54,0 + 1.11 to 1.11.X 55,0 */ public static final Package.Version JAVA_MIN_CLASS_VERSION = @@ -71,6 +72,9 @@ class Constants { public static final Package.Version JAVA10_MAX_CLASS_VERSION = Package.Version.of(54, 00); + public static final Package.Version JAVA11_MAX_CLASS_VERSION = + Package.Version.of(55, 00); + public static final int JAVA_PACKAGE_MAGIC = 0xCAFED00D; public static final Package.Version JAVA5_PACKAGE_VERSION = @@ -87,7 +91,7 @@ class Constants { // upper limit, should point to the latest class version public static final Package.Version JAVA_MAX_CLASS_VERSION = - JAVA10_MAX_CLASS_VERSION; + JAVA11_MAX_CLASS_VERSION; // upper limit should point to the latest package version, for version info!. public static final Package.Version MAX_PACKAGE_VERSION = diff --git a/src/java.base/share/classes/java/io/InputStream.java b/src/java.base/share/classes/java/io/InputStream.java index b4d6255034f..8ca91962262 100644 --- a/src/java.base/share/classes/java/io/InputStream.java +++ b/src/java.base/share/classes/java/io/InputStream.java @@ -25,7 +25,9 @@ package java.io; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Objects; /** @@ -229,30 +231,55 @@ public abstract class InputStream implements Closeable { * @since 9 */ public byte[] readAllBytes() throws IOException { - byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; - int capacity = buf.length; - int nread = 0; + List bufs = null; + byte[] result = null; + int total = 0; int n; - for (;;) { - // read to EOF which may read more or less than initial buffer size - while ((n = read(buf, nread, capacity - nread)) > 0) + do { + byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; + int nread = 0; + + // read to EOF which may read more or less than buffer size + while ((n = read(buf, nread, buf.length - nread)) > 0) { nread += n; - - // if the last call to read returned -1, then we're done - if (n < 0) - break; - - // need to allocate a larger buffer - if (capacity <= MAX_BUFFER_SIZE - capacity) { - capacity = capacity << 1; - } else { - if (capacity == MAX_BUFFER_SIZE) - throw new OutOfMemoryError("Required array size too large"); - capacity = MAX_BUFFER_SIZE; } - buf = Arrays.copyOf(buf, capacity); + + if (nread > 0) { + if (MAX_BUFFER_SIZE - total < nread) { + throw new OutOfMemoryError("Required array size too large"); + } + total += nread; + if (result == null) { + result = buf; + } else { + if (bufs == null) { + bufs = new ArrayList<>(); + bufs.add(result); + } + bufs.add(buf); + } + } + } while (n >= 0); // if the last call to read returned -1, then break + + if (bufs == null) { + if (result == null) { + return new byte[0]; + } + return result.length == total ? + result : Arrays.copyOf(result, total); } - return (capacity == nread) ? buf : Arrays.copyOf(buf, nread); + + result = new byte[total]; + int offset = 0; + int remaining = total; + for (byte[] b : bufs) { + int len = Math.min(b.length, remaining); + System.arraycopy(b, 0, result, offset, len); + offset += len; + remaining -= len; + } + + return result; } /** diff --git a/src/java.base/share/classes/java/lang/ref/Reference.java b/src/java.base/share/classes/java/lang/ref/Reference.java index 5125e7cb553..2ead79fb636 100644 --- a/src/java.base/share/classes/java/lang/ref/Reference.java +++ b/src/java.base/share/classes/java/lang/ref/Reference.java @@ -140,14 +140,6 @@ public abstract class Reference { } } - /* - * system property to disable clearing before enqueuing. - */ - private static final class ClearBeforeEnqueue { - static final boolean DISABLE = - Boolean.getBoolean("jdk.lang.ref.disableClearBeforeEnqueue"); - } - /* * Atomically get and clear (set to null) the VM's pending list. */ @@ -299,8 +291,7 @@ public abstract class Reference { * it was not registered with a queue when it was created */ public boolean enqueue() { - if (!ClearBeforeEnqueue.DISABLE) - this.referent = null; + this.referent = null; return this.queue.enqueue(this); } diff --git a/src/java.base/share/classes/java/nio/Bits.java b/src/java.base/share/classes/java/nio/Bits.java index dfe6a8f13a7..fff84e9e58d 100644 --- a/src/java.base/share/classes/java/nio/Bits.java +++ b/src/java.base/share/classes/java/nio/Bits.java @@ -63,38 +63,38 @@ class Bits { // package-private // -- Unsafe access -- - private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); static Unsafe unsafe() { - return unsafe; + return UNSAFE; } // -- Processor and memory-system properties -- - private static final ByteOrder byteOrder - = unsafe.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; + private static final ByteOrder BYTE_ORDER + = UNSAFE.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; static ByteOrder byteOrder() { - return byteOrder; + return BYTE_ORDER; } - private static int pageSize = -1; + private static int PAGE_SIZE = -1; static int pageSize() { - if (pageSize == -1) - pageSize = unsafe().pageSize(); - return pageSize; + if (PAGE_SIZE == -1) + PAGE_SIZE = unsafe().pageSize(); + return PAGE_SIZE; } static int pageCount(long size) { return (int)(size + (long)pageSize() - 1L) / pageSize(); } - private static boolean unaligned = unsafe.unalignedAccess(); + private static boolean UNALIGNED = UNSAFE.unalignedAccess(); static boolean unaligned() { - return unaligned; + return UNALIGNED; } @@ -103,11 +103,11 @@ class Bits { // package-private // A user-settable upper limit on the maximum amount of allocatable // direct buffer memory. This value may be changed during VM // initialization if it is launched with "-XX:MaxDirectMemorySize=". - private static volatile long maxMemory = VM.maxDirectMemory(); - private static final AtomicLong reservedMemory = new AtomicLong(); - private static final AtomicLong totalCapacity = new AtomicLong(); - private static final AtomicLong count = new AtomicLong(); - private static volatile boolean memoryLimitSet; + private static volatile long MAX_MEMORY = VM.maxDirectMemory(); + private static final AtomicLong RESERVED_MEMORY = new AtomicLong(); + private static final AtomicLong TOTAL_CAPACITY = new AtomicLong(); + private static final AtomicLong COUNT = new AtomicLong(); + private static volatile boolean MEMORY_LIMIT_SET; // max. number of sleeps during try-reserving with exponentially // increasing delay before throwing OutOfMemoryError: @@ -120,9 +120,9 @@ class Bits { // package-private // which a process may access. All sizes are specified in bytes. static void reserveMemory(long size, int cap) { - if (!memoryLimitSet && VM.initLevel() >= 1) { - maxMemory = VM.maxDirectMemory(); - memoryLimitSet = true; + if (!MEMORY_LIMIT_SET && VM.initLevel() >= 1) { + MAX_MEMORY = VM.maxDirectMemory(); + MEMORY_LIMIT_SET = true; } // optimist! @@ -200,10 +200,10 @@ class Bits { // package-private // actual memory usage, which will differ when buffers are page // aligned. long totalCap; - while (cap <= maxMemory - (totalCap = totalCapacity.get())) { - if (totalCapacity.compareAndSet(totalCap, totalCap + cap)) { - reservedMemory.addAndGet(size); - count.incrementAndGet(); + while (cap <= MAX_MEMORY - (totalCap = TOTAL_CAPACITY.get())) { + if (TOTAL_CAPACITY.compareAndSet(totalCap, totalCap + cap)) { + RESERVED_MEMORY.addAndGet(size); + COUNT.incrementAndGet(); return true; } } @@ -213,9 +213,9 @@ class Bits { // package-private static void unreserveMemory(long size, int cap) { - long cnt = count.decrementAndGet(); - long reservedMem = reservedMemory.addAndGet(-size); - long totalCap = totalCapacity.addAndGet(-cap); + long cnt = COUNT.decrementAndGet(); + long reservedMem = RESERVED_MEMORY.addAndGet(-size); + long totalCap = TOTAL_CAPACITY.addAndGet(-cap); assert cnt >= 0 && reservedMem >= 0 && totalCap >= 0; } @@ -234,15 +234,15 @@ class Bits { // package-private } @Override public long getCount() { - return Bits.count.get(); + return Bits.COUNT.get(); } @Override public long getTotalCapacity() { - return Bits.totalCapacity.get(); + return Bits.TOTAL_CAPACITY.get(); } @Override public long getMemoryUsed() { - return Bits.reservedMemory.get(); + return Bits.RESERVED_MEMORY.get(); } }; } diff --git a/src/java.base/share/classes/java/nio/Buffer.java b/src/java.base/share/classes/java/nio/Buffer.java index 1f6bef17960..1217ca78a74 100644 --- a/src/java.base/share/classes/java/nio/Buffer.java +++ b/src/java.base/share/classes/java/nio/Buffer.java @@ -26,6 +26,7 @@ package java.nio; import jdk.internal.HotSpotIntrinsicCandidate; +import jdk.internal.misc.Unsafe; import java.util.Spliterator; @@ -181,6 +182,8 @@ import java.util.Spliterator; */ public abstract class Buffer { + // Cached unsafe-access object + static final Unsafe UNSAFE = Bits.unsafe(); /** * The characteristics of Spliterators that traverse and split elements @@ -616,6 +619,14 @@ public abstract class Buffer { // -- Package-private methods for bounds checking, etc. -- + /** + * + * @return the base reference, paired with the address + * field, which in combination can be used for unsafe access into a heap + * buffer or direct byte buffer (and views of). + */ + abstract Object base(); + /** * Checks the current position against the limit, throwing a {@link * BufferUnderflowException} if it is not smaller than the limit, and then diff --git a/src/java.base/share/classes/java/nio/BufferMismatch.java b/src/java.base/share/classes/java/nio/BufferMismatch.java new file mode 100644 index 00000000000..c1260f62a19 --- /dev/null +++ b/src/java.base/share/classes/java/nio/BufferMismatch.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.nio; + +import jdk.internal.util.ArraysSupport; + +/** + * Mismatch methods for buffers + */ +final class BufferMismatch { + + static int mismatch(ByteBuffer a, int aOff, ByteBuffer b, int bOff, int length) { + int i = 0; + if (length > 7) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + aOff, + b.base(), b.address + bOff, + length, + ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE); + if (i >= 0) return i; + i = length - ~i; + } + for (; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + static int mismatch(CharBuffer a, int aOff, CharBuffer b, int bOff, int length) { + int i = 0; + // Ensure only heap or off-heap buffer instances use the + // vectorized mismatch. If either buffer is a StringCharBuffer + // (order is null) then the slow path is taken + if (length > 3 && a.charRegionOrder() == b.charRegionOrder() + && a.charRegionOrder() != null && b.charRegionOrder() != null) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE); + if (i >= 0) return i; + i = length - ~i; + } + for (; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + static int mismatch(ShortBuffer a, int aOff, ShortBuffer b, int bOff, int length) { + int i = 0; + if (length > 3 && a.order() == b.order()) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE); + if (i >= 0) return i; + i = length - ~i; + } + for (; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + static int mismatch(IntBuffer a, int aOff, IntBuffer b, int bOff, int length) { + int i = 0; + if (length > 1 && a.order() == b.order()) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE); + if (i >= 0) return i; + i = length - ~i; + } + for (; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + static int mismatch(FloatBuffer a, int aOff, FloatBuffer b, int bOff, int length) { + int i = 0; + if (length > 1 && a.order() == b.order()) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE); + // Mismatched + if (i >= 0) { + // Check if mismatch is not associated with two NaN values; and + // is not associated with +0 and -0 + float av = a.get(aOff + i); + float bv = b.get(bOff + i); + if (av != bv && (!Float.isNaN(av) || !Float.isNaN(bv))) + return i; + + // Fall back to slow mechanism + // ISSUE: Consider looping over vectorizedMismatch adjusting ranges + // However, requires that returned value be relative to input ranges + i++; + } + // Matched + else { + i = length - ~i; + } + } + for (; i < length; i++) { + float av = a.get(aOff + i); + float bv = b.get(bOff + i); + if (av != bv && (!Float.isNaN(av) || !Float.isNaN(bv))) + return i; + } + return -1; + } + + static int mismatch(LongBuffer a, int aOff, LongBuffer b, int bOff, int length) { + int i = 0; + if (length > 0 && a.order() == b.order()) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE); + return i >= 0 ? i : -1; + } + for (; i < length; i++) { + if (a.get(aOff + i) != b.get(bOff + i)) + return i; + } + return -1; + } + + static int mismatch(DoubleBuffer a, int aOff, DoubleBuffer b, int bOff, int length) { + int i = 0; + if (length > 0 && a.order() == b.order()) { + i = ArraysSupport.vectorizedMismatch( + a.base(), a.address + (aOff << ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE), + b.base(), b.address + (bOff << ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE), + length, + ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE); + // Mismatched + if (i >= 0) { + // Check if mismatch is not associated with two NaN values; and + // is not associated with +0 and -0 + double av = a.get(aOff + i); + double bv = b.get(bOff + i); + if (av != bv && (!Double.isNaN(av) || !Double.isNaN(bv))) + return i; + + // Fall back to slow mechanism + // ISSUE: Consider looping over vectorizedMismatch adjusting ranges + // However, requires that returned value be relative to input ranges + i++; + } + // Matched + else { + return -1; + } + } + for (; i < length; i++) { + double av = a.get(aOff + i); + double bv = b.get(bOff + i); + if (av != bv && (!Double.isNaN(av) || !Double.isNaN(bv))) + return i; + } + return -1; + } +} diff --git a/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template b/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template index 3ceb4122b62..b390448b110 100644 --- a/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template +++ b/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template @@ -36,9 +36,6 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private #if[rw] - // Cached unsafe-access object - private static final Unsafe unsafe = Bits.unsafe(); - protected final ByteBuffer bb; #end[rw] @@ -74,6 +71,11 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private #end[rw] } + @Override + Object base() { + return bb.hb; + } + public $Type$Buffer slice() { int pos = this.position(); int lim = this.limit(); @@ -117,20 +119,20 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private } public $type$ get() { - $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(nextGetIndex()), + $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(nextGetIndex()), {#if[boB]?true:false}); return $fromBits$(x); } public $type$ get(int i) { - $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), + $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), {#if[boB]?true:false}); return $fromBits$(x); } #if[streamableType] $type$ getUnchecked(int i) { - $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(i), + $memtype$ x = UNSAFE.get$Memtype$Unaligned(bb.hb, byteOffset(i), {#if[boB]?true:false}); return $fromBits$(x); } @@ -141,7 +143,7 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private public $Type$Buffer put($type$ x) { #if[rw] $memtype$ y = $toBits$(x); - unsafe.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y, + UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y, {#if[boB]?true:false}); return this; #else[rw] @@ -152,7 +154,7 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private public $Type$Buffer put(int i, $type$ x) { #if[rw] $memtype$ y = $toBits$(x); - unsafe.put$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), y, + UNSAFE.put$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), y, {#if[boB]?true:false}); return this; #else[rw] @@ -241,4 +243,9 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private #end[boL] } +#if[char] + ByteOrder charRegionOrder() { + return order(); + } +#end[char] } diff --git a/src/java.base/share/classes/java/nio/Direct-X-Buffer-bin.java.template b/src/java.base/share/classes/java/nio/Direct-X-Buffer-bin.java.template index 6179776100d..cacadb101df 100644 --- a/src/java.base/share/classes/java/nio/Direct-X-Buffer-bin.java.template +++ b/src/java.base/share/classes/java/nio/Direct-X-Buffer-bin.java.template @@ -32,7 +32,7 @@ class XXX { #if[rw] private $type$ get$Type$(long a) { - $memtype$ x = unsafe.get$Memtype$Unaligned(null, a, bigEndian); + $memtype$ x = UNSAFE.get$Memtype$Unaligned(null, a, bigEndian); return $fromBits$(x); } @@ -49,7 +49,7 @@ class XXX { private ByteBuffer put$Type$(long a, $type$ x) { #if[rw] $memtype$ y = $toBits$(x); - unsafe.put$Memtype$Unaligned(null, a, y, bigEndian); + UNSAFE.put$Memtype$Unaligned(null, a, y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -81,7 +81,7 @@ class XXX { int rem = (off <= lim ? lim - off : 0); int size = rem >> $LG_BYTES_PER_VALUE$; - if (!unaligned && ((address + off) % $BYTES_PER_VALUE$ != 0)) { + if (!UNALIGNED && ((address + off) % $BYTES_PER_VALUE$ != 0)) { return (bigEndian ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this, -1, diff --git a/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template b/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template index 68ec8340e0d..5fa9be47b20 100644 --- a/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template +++ b/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template @@ -28,7 +28,6 @@ package java.nio; import java.io.FileDescriptor; -import jdk.internal.misc.Unsafe; import jdk.internal.misc.VM; import jdk.internal.ref.Cleaner; import sun.nio.ch.DirectBuffer; @@ -45,14 +44,11 @@ class Direct$Type$Buffer$RW$$BO$ #if[rw] - // Cached unsafe-access object - protected static final Unsafe unsafe = Bits.unsafe(); - // Cached array base offset - private static final long arrayBaseOffset = (long)unsafe.arrayBaseOffset($type$[].class); + private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class); // Cached unaligned-access capability - protected static final boolean unaligned = Bits.unaligned(); + protected static final boolean UNALIGNED = Bits.unaligned(); // Base address, used in all indexing calculations // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress @@ -73,8 +69,6 @@ class Direct$Type$Buffer$RW$$BO$ implements Runnable { - private static Unsafe unsafe = Unsafe.getUnsafe(); - private long address; private long size; private int capacity; @@ -91,7 +85,7 @@ class Direct$Type$Buffer$RW$$BO$ // Paranoia return; } - unsafe.freeMemory(address); + UNSAFE.freeMemory(address); address = 0; Bits.unreserveMemory(size, capacity); } @@ -124,12 +118,12 @@ class Direct$Type$Buffer$RW$$BO$ long base = 0; try { - base = unsafe.allocateMemory(size); + base = UNSAFE.allocateMemory(size); } catch (OutOfMemoryError x) { Bits.unreserveMemory(size, cap); throw x; } - unsafe.setMemory(base, size, (byte) 0); + UNSAFE.setMemory(base, size, (byte) 0); if (pa && (base % ps != 0)) { // Round up to page boundary address = base + ps - (base & (ps - 1)); @@ -206,6 +200,11 @@ class Direct$Type$Buffer$RW$$BO$ #end[rw] } + @Override + Object base() { + return null; + } + public $Type$Buffer slice() { int pos = this.position(); int lim = this.limit(); @@ -258,16 +257,16 @@ class Direct$Type$Buffer$RW$$BO$ } public $type$ get() { - return $fromBits$($swap$(unsafe.get$Swaptype$(ix(nextGetIndex())))); + return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(nextGetIndex())))); } public $type$ get(int i) { - return $fromBits$($swap$(unsafe.get$Swaptype$(ix(checkIndex(i))))); + return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(checkIndex(i))))); } #if[streamableType] $type$ getUnchecked(int i) { - return $fromBits$($swap$(unsafe.get$Swaptype$(ix(i)))); + return $fromBits$($swap$(UNSAFE.get$Swaptype$(ix(i)))); } #end[streamableType] @@ -282,10 +281,10 @@ class Direct$Type$Buffer$RW$$BO$ if (length > rem) throw new BufferUnderflowException(); - long dstOffset = arrayBaseOffset + ((long)offset << $LG_BYTES_PER_VALUE$); + long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$); #if[!byte] if (order() != ByteOrder.nativeOrder()) - unsafe.copySwapMemory(null, + UNSAFE.copySwapMemory(null, ix(pos), dst, dstOffset, @@ -293,7 +292,7 @@ class Direct$Type$Buffer$RW$$BO$ (long)1 << $LG_BYTES_PER_VALUE$); else #end[!byte] - unsafe.copyMemory(null, + UNSAFE.copyMemory(null, ix(pos), dst, dstOffset, @@ -312,7 +311,7 @@ class Direct$Type$Buffer$RW$$BO$ public $Type$Buffer put($type$ x) { #if[rw] - unsafe.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x))); + UNSAFE.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x))); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -321,7 +320,7 @@ class Direct$Type$Buffer$RW$$BO$ public $Type$Buffer put(int i, $type$ x) { #if[rw] - unsafe.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x))); + UNSAFE.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x))); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -347,7 +346,7 @@ class Direct$Type$Buffer$RW$$BO$ if (srem > rem) throw new BufferOverflowException(); - unsafe.copyMemory(sb.ix(spos), ix(pos), (long)srem << $LG_BYTES_PER_VALUE$); + UNSAFE.copyMemory(sb.ix(spos), ix(pos), (long)srem << $LG_BYTES_PER_VALUE$); sb.position(spos + srem); position(pos + srem); } else if (src.hb != null) { @@ -380,10 +379,10 @@ class Direct$Type$Buffer$RW$$BO$ if (length > rem) throw new BufferOverflowException(); - long srcOffset = arrayBaseOffset + ((long)offset << $LG_BYTES_PER_VALUE$); + long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$); #if[!byte] if (order() != ByteOrder.nativeOrder()) - unsafe.copySwapMemory(src, + UNSAFE.copySwapMemory(src, srcOffset, null, ix(pos), @@ -391,7 +390,7 @@ class Direct$Type$Buffer$RW$$BO$ (long)1 << $LG_BYTES_PER_VALUE$); else #end[!byte] - unsafe.copyMemory(src, + UNSAFE.copyMemory(src, srcOffset, null, ix(pos), @@ -413,7 +412,7 @@ class Direct$Type$Buffer$RW$$BO$ assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); - unsafe.copyMemory(ix(pos), ix(0), (long)rem << $LG_BYTES_PER_VALUE$); + UNSAFE.copyMemory(ix(pos), ix(0), (long)rem << $LG_BYTES_PER_VALUE$); position(rem); limit(capacity()); discardMark(); @@ -490,17 +489,22 @@ class Direct$Type$Buffer$RW$$BO$ #end[!byte] +#if[char] + ByteOrder charRegionOrder() { + return order(); + } +#end[char] #if[byte] byte _get(int i) { // package-private - return unsafe.getByte(address + i); + return UNSAFE.getByte(address + i); } void _put(int i, byte b) { // package-private #if[rw] - unsafe.putByte(address + i, b); + UNSAFE.putByte(address + i, b); #else[rw] throw new ReadOnlyBufferException(); #end[rw] diff --git a/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template b/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template index 69e65a099c7..7f2a2597ba3 100644 --- a/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template +++ b/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template @@ -27,8 +27,6 @@ package java.nio; -import jdk.internal.misc.Unsafe; - /** #if[rw] * A read/write Heap$Type$Buffer. @@ -43,6 +41,11 @@ import jdk.internal.misc.Unsafe; class Heap$Type$Buffer$RW$ extends {#if[ro]?Heap}$Type$Buffer { + // Cached array base offset + private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class); + + // Cached array base offset + private static final long ARRAY_INDEX_SCALE = UNSAFE.arrayIndexScale($type$[].class); // For speed these fields are actually declared in X-Buffer; // these declarations are here as documentation @@ -53,16 +56,6 @@ class Heap$Type$Buffer$RW$ #end[rw] */ -#if[byte] - - // Cached unsafe-access object - private static final Unsafe unsafe = Bits.unsafe(); - - // Cached array base offset - private static final long arrayBaseOffset = unsafe.arrayBaseOffset($type$[].class); - -#end[byte] - Heap$Type$Buffer$RW$(int cap, int lim) { // package-private #if[rw] super(-1, 0, lim, cap, new $type$[cap], 0); @@ -70,13 +63,11 @@ class Heap$Type$Buffer$RW$ hb = new $type$[cap]; offset = 0; */ + this.address = ARRAY_BASE_OFFSET; #else[rw] super(cap, lim); this.isReadOnly = true; #end[rw] -#if[byte] - this.address = arrayBaseOffset; -#end[byte] } Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private @@ -86,13 +77,11 @@ class Heap$Type$Buffer$RW$ hb = buf; offset = 0; */ + this.address = ARRAY_BASE_OFFSET; #else[rw] super(buf, off, len); this.isReadOnly = true; #end[rw] -#if[byte] - this.address = arrayBaseOffset; -#end[byte] } protected Heap$Type$Buffer$RW$($type$[] buf, @@ -105,13 +94,11 @@ class Heap$Type$Buffer$RW$ hb = buf; offset = off; */ + this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE; #else[rw] super(buf, mark, pos, lim, cap, off); this.isReadOnly = true; #end[rw] -#if[byte] - this.address = arrayBaseOffset + off; -#end[byte] } public $Type$Buffer slice() { @@ -296,18 +283,18 @@ class Heap$Type$Buffer$RW$ #if[rw] public char getChar() { - return unsafe.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); + return UNSAFE.getCharUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); } public char getChar(int i) { - return unsafe.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); + return UNSAFE.getCharUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); } #end[rw] public $Type$Buffer putChar(char x) { #if[rw] - unsafe.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); + UNSAFE.putCharUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -316,7 +303,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putChar(int i, char x) { #if[rw] - unsafe.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); + UNSAFE.putCharUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -347,18 +334,18 @@ class Heap$Type$Buffer$RW$ #if[rw] public short getShort() { - return unsafe.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); + return UNSAFE.getShortUnaligned(hb, byteOffset(nextGetIndex(2)), bigEndian); } public short getShort(int i) { - return unsafe.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); + return UNSAFE.getShortUnaligned(hb, byteOffset(checkIndex(i, 2)), bigEndian); } #end[rw] public $Type$Buffer putShort(short x) { #if[rw] - unsafe.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); + UNSAFE.putShortUnaligned(hb, byteOffset(nextPutIndex(2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -367,7 +354,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putShort(int i, short x) { #if[rw] - unsafe.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); + UNSAFE.putShortUnaligned(hb, byteOffset(checkIndex(i, 2)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -398,18 +385,18 @@ class Heap$Type$Buffer$RW$ #if[rw] public int getInt() { - return unsafe.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); + return UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); } public int getInt(int i) { - return unsafe.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); + return UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); } #end[rw] public $Type$Buffer putInt(int x) { #if[rw] - unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); + UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -418,7 +405,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putInt(int i, int x) { #if[rw] - unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); + UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -449,18 +436,18 @@ class Heap$Type$Buffer$RW$ #if[rw] public long getLong() { - return unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); + return UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); } public long getLong(int i) { - return unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); + return UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); } #end[rw] public $Type$Buffer putLong(long x) { #if[rw] - unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); + UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -469,7 +456,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putLong(int i, long x) { #if[rw] - unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); + UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), x, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -500,12 +487,12 @@ class Heap$Type$Buffer$RW$ #if[rw] public float getFloat() { - int x = unsafe.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); + int x = UNSAFE.getIntUnaligned(hb, byteOffset(nextGetIndex(4)), bigEndian); return Float.intBitsToFloat(x); } public float getFloat(int i) { - int x = unsafe.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); + int x = UNSAFE.getIntUnaligned(hb, byteOffset(checkIndex(i, 4)), bigEndian); return Float.intBitsToFloat(x); } @@ -514,7 +501,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putFloat(float x) { #if[rw] int y = Float.floatToRawIntBits(x); - unsafe.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); + UNSAFE.putIntUnaligned(hb, byteOffset(nextPutIndex(4)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -524,7 +511,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putFloat(int i, float x) { #if[rw] int y = Float.floatToRawIntBits(x); - unsafe.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); + UNSAFE.putIntUnaligned(hb, byteOffset(checkIndex(i, 4)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -555,12 +542,12 @@ class Heap$Type$Buffer$RW$ #if[rw] public double getDouble() { - long x = unsafe.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); + long x = UNSAFE.getLongUnaligned(hb, byteOffset(nextGetIndex(8)), bigEndian); return Double.longBitsToDouble(x); } public double getDouble(int i) { - long x = unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); + long x = UNSAFE.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); return Double.longBitsToDouble(x); } @@ -569,7 +556,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putDouble(double x) { #if[rw] long y = Double.doubleToRawLongBits(x); - unsafe.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); + UNSAFE.putLongUnaligned(hb, byteOffset(nextPutIndex(8)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -579,7 +566,7 @@ class Heap$Type$Buffer$RW$ public $Type$Buffer putDouble(int i, double x) { #if[rw] long y = Double.doubleToRawLongBits(x); - unsafe.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); + UNSAFE.putLongUnaligned(hb, byteOffset(checkIndex(i, 8)), y, bigEndian); return this; #else[rw] throw new ReadOnlyBufferException(); @@ -643,7 +630,11 @@ class Heap$Type$Buffer$RW$ public ByteOrder order() { return ByteOrder.nativeOrder(); } - #end[!byte] +#if[char] + ByteOrder charRegionOrder() { + return order(); + } +#end[char] } diff --git a/src/java.base/share/classes/java/nio/StringCharBuffer.java b/src/java.base/share/classes/java/nio/StringCharBuffer.java index 71f4b368d29..26b355bc819 100644 --- a/src/java.base/share/classes/java/nio/StringCharBuffer.java +++ b/src/java.base/share/classes/java/nio/StringCharBuffer.java @@ -127,4 +127,30 @@ class StringCharBuffer // package-private return ByteOrder.nativeOrder(); } + ByteOrder charRegionOrder() { + return null; + } + + public boolean equals(Object ob) { + if (this == ob) + return true; + if (!(ob instanceof CharBuffer)) + return false; + CharBuffer that = (CharBuffer)ob; + if (this.remaining() != that.remaining()) + return false; + return BufferMismatch.mismatch(this, this.position(), + that, that.position(), + this.remaining()) < 0; + } + + public int compareTo(CharBuffer that) { + int i = BufferMismatch.mismatch(this, this.position(), + that, that.position(), + Math.min(this.remaining(), that.remaining())); + if (i >= 0) { + return Character.compare(this.get(this.position() + i), that.get(this.position() + i)); + } + return this.remaining() - that.remaining(); + } } diff --git a/src/java.base/share/classes/java/nio/X-Buffer.java.template b/src/java.base/share/classes/java/nio/X-Buffer.java.template index 0a39543a88e..96e05d6a663 100644 --- a/src/java.base/share/classes/java/nio/X-Buffer.java.template +++ b/src/java.base/share/classes/java/nio/X-Buffer.java.template @@ -36,6 +36,8 @@ import java.util.stream.StreamSupport; import java.util.stream.$Streamtype$Stream; #end[streamableType] +import jdk.internal.util.ArraysSupport; + /** * $A$ $type$ buffer. * @@ -287,6 +289,11 @@ public abstract class $Type$Buffer this(mark, pos, lim, cap, null, 0); } + @Override + Object base() { + return hb; + } + #if[byte] /** @@ -1297,19 +1304,9 @@ public abstract class $Type$Buffer $Type$Buffer that = ($Type$Buffer)ob; if (this.remaining() != that.remaining()) return false; - int p = this.position(); - for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) - if (!equals(this.get(i), that.get(j))) - return false; - return true; - } - - private static boolean equals($type$ x, $type$ y) { -#if[floatingPointType] - return (x == y) || ($Fulltype$.isNaN(x) && $Fulltype$.isNaN(y)); -#else[floatingPointType] - return x == y; -#end[floatingPointType] + return BufferMismatch.mismatch(this, this.position(), + that, that.position(), + this.remaining()) < 0; } /** @@ -1336,11 +1333,11 @@ public abstract class $Type$Buffer * is less than, equal to, or greater than the given buffer */ public int compareTo($Type$Buffer that) { - int n = this.position() + Math.min(this.remaining(), that.remaining()); - for (int i = this.position(), j = that.position(); i < n; i++, j++) { - int cmp = compare(this.get(i), that.get(j)); - if (cmp != 0) - return cmp; + int i = BufferMismatch.mismatch(this, this.position(), + that, that.position(), + Math.min(this.remaining(), that.remaining())); + if (i >= 0) { + return compare(this.get(this.position() + i), that.get(this.position() + i)); } return this.remaining() - that.remaining(); } @@ -1571,6 +1568,12 @@ public abstract class $Type$Buffer #end[!byte] +#if[char] + // The order or null if the buffer does not cover a memory region, + // such as StringCharBuffer + abstract ByteOrder charRegionOrder(); +#end[char] + #if[byte] boolean bigEndian // package-private diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index c7e0dcf9938..41ac57fa3cf 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -2954,22 +2954,6 @@ public final class Files { return newBufferedWriter(path, StandardCharsets.UTF_8, options); } - /** - * Reads all bytes from an input stream and writes them to an output stream. - */ - private static long copy(InputStream source, OutputStream sink) - throws IOException - { - long nread = 0L; - byte[] buf = new byte[BUFFER_SIZE]; - int n; - while ((n = source.read(buf)) > 0) { - sink.write(buf, 0, n); - nread += n; - } - return nread; - } - /** * Copies all bytes from an input stream to a file. On return, the input * stream will be at end of stream. @@ -3082,7 +3066,7 @@ public final class Files { // do the copy try (OutputStream out = ostream) { - return copy(in, out); + return in.transferTo(out); } } @@ -3124,7 +3108,7 @@ public final class Files { Objects.requireNonNull(out); try (InputStream in = newInputStream(source)) { - return copy(in, out); + return in.transferTo(out); } } diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java index e1571cc613f..74011566f26 100644 --- a/src/java.base/share/classes/java/util/Arrays.java +++ b/src/java.base/share/classes/java/util/Arrays.java @@ -26,6 +26,7 @@ package java.util; import jdk.internal.HotSpotIntrinsicCandidate; +import jdk.internal.util.ArraysSupport; import java.lang.reflect.Array; import java.util.concurrent.ForkJoinPool; diff --git a/src/java.base/share/classes/java/util/ResourceBundle.java b/src/java.base/share/classes/java/util/ResourceBundle.java index b361ceefff4..e902b3e45e8 100644 --- a/src/java.base/share/classes/java/util/ResourceBundle.java +++ b/src/java.base/share/classes/java/util/ResourceBundle.java @@ -204,58 +204,70 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; * known concrete subclasses {@code ListResourceBundle} and * {@code PropertyResourceBundle} are thread-safe. * - *

Resource Bundles in Named Modules

+ *

Resource Bundles and Named Modules

* - * When resource bundles are deployed in named modules, the following - * module-specific requirements and restrictions are applied. + * Resource bundles can be deployed in modules in the following ways: * - *
    - *
  • Code in a named module that calls {@link #getBundle(String, Locale)} - * will locate resource bundles in the caller's module (caller module).
  • - *
  • If resource bundles are deployed in named modules separate from - * the caller module, those resource bundles need to be loaded from service - * providers of {@link ResourceBundleProvider}. The caller module must declare - * "{@code uses}" and the service interface name is the concatenation of the - * package name of the base name, string "{@code .spi.}", the simple class - * name of the base name, and the string "{@code Provider}". The - * bundle provider modules containing resource bundles must - * declare "{@code provides}" with the service interface name and - * its implementation class name. For example, if the base name is - * "{@code com.example.app.MyResources}", the caller module must declare - * "{@code uses com.example.app.spi.MyResourcesProvider;}" and a module containing resource - * bundles must declare "{@code provides com.example.app.spi.MyResourcesProvider - * with com.example.app.internal.MyResourcesProviderImpl;}" - * where {@code com.example.app.internal.MyResourcesProviderImpl} is an - * implementation class of {@code com.example.app.spi.MyResourcesProvider}.
  • - *
  • If you want to use non-standard formats in named modules, such as XML, - * {@link ResourceBundleProvider} needs to be used.
  • - *
  • The {@code getBundle} method with a {@code ClassLoader} may not be able to - * find resource bundles using the given {@code ClassLoader} in named modules. - * The {@code getBundle} method with a {@code Module} can be used, instead.
  • - *
  • {@code ResourceBundle.Control} is not supported in named modules. - * If the {@code getBundle} method with a {@code ResourceBundle.Control} is called - * in a named module, the method will throw an {@code UnsupportedOperationException}. - * Any service providers of {@link ResourceBundleControlProvider} are ignored in - * named modules. - *
  • - *
+ *

Resource bundles together with an application

* - *

ResourceBundleProvider Service Providers

+ * Resource bundles can be deployed together with an application in the same + * module. In that case, the resource bundles are loaded + * by code in the module by calling the {@link #getBundle(String)} + * or {@link #getBundle(String, Locale)} method. * - * The {@code getBundle} factory methods load service providers of - * {@link ResourceBundleProvider}, if available, using {@link ServiceLoader}. - * The service type is designated by - * {@code + ".spi." + + "Provider"}. For - * example, if the base name is "{@code com.example.app.MyResources}", the service - * type is {@code com.example.app.spi.MyResourcesProvider}. - *

- * In named modules, the loaded service providers for the given base name are - * used to load resource bundles. If no service provider is available, or if - * none of the service providers returns a resource bundle and the caller module - * doesn't have its own service provider, the {@code getBundle} factory method - * searches for resource bundles that are local in the caller module and that - * are visible to the class loader of the caller module. The resource bundle - * formats for local module searching are "java.class" and "java.properties". + *

Resource bundles as service providers

+ * + * Resource bundles can be deployed in one or more service provider modules + * and they can be located using {@link ServiceLoader}. + * A {@linkplain ResourceBundleProvider service} interface or class must be + * defined. The caller module declares that it uses the service, the service + * provider modules declare that they provide implementations of the service. + * Refer to {@link ResourceBundleProvider} for developing resource bundle + * services and deploying resource bundle providers. + * The module obtaining the resource bundle can be a resource bundle + * provider itself; in which case this module only locates the resource bundle + * via service provider mechanism. + * + *

A {@linkplain ResourceBundleProvider resource bundle provider} can + * provide resource bundles in any format such XML which replaces the need + * of {@link Control ResourceBundle.Control}. + * + *

Resource bundles in other modules and class path

+ * + * Resource bundles in a named module may be encapsulated so that + * it cannot be located by code in other modules. Resource bundles + * in unnamed modules and class path are open for any module to access. + * Resource bundle follows the resource encapsulation rules as specified + * in {@link Module#getResourceAsStream(String)}. + * + *

The {@code getBundle} factory methods with no {@code Control} parameter + * locate and load resource bundles from + * {@linkplain ResourceBundleProvider service providers}. + * It may continue the search as if calling {@link Module#getResourceAsStream(String)} + * to find the named resource from a given module and calling + * {@link ClassLoader#getResourceAsStream(String)}; refer to + * the specification of the {@code getBundle} method for details. + * Only non-encapsulated resource bundles of "{@code java.class}" + * or "{@code java.properties}" format are searched. + * + *

If the caller module is a + * + * resource bundle provider, it does not fall back to the + * class loader search. + * + *

Resource bundles in automatic modules

+ * + * A common format of resource bundles is in {@linkplain PropertyResourceBundle + * .properties} file format. Typically {@code .properties} resource bundles + * are packaged in a JAR file. Resource bundle only JAR file can be readily + * deployed as an + * automatic module. For example, if the JAR file contains the + * entry "{@code p/q/Foo_ja.properties}" and no {@code .class} entry, + * when resolved and defined as an automatic module, no package is derived + * for this module. This allows resource bundles in {@code .properties} + * format packaged in one or more JAR files that may contain entries + * in the same directory and can be resolved successfully as + * automatic modules. * *

ResourceBundle.Control

* @@ -268,6 +280,14 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; * {@link #getBundle(String, Locale, ClassLoader, Control) getBundle} * factory method for details. * + *

{@link ResourceBundle.Control} is designed for an application deployed + * in an unnamed module, for example to support resource bundles in + * non-standard formats or package localized resources in a non-traditional + * convention. {@link ResourceBundleProvider} is the replacement for + * {@code ResourceBundle.Control} when migrating to modules. + * {@code UnsupportedOperationException} will be thrown when a factory + * method that takes the {@code ResourceBundle.Control} parameter is called. + * *

For the {@code getBundle} factory * methods that take no {@link Control} instance, their default behavior of resource bundle loading @@ -815,14 +835,10 @@ public abstract class ResourceBundle { /** * Gets a resource bundle using the specified base name, the default locale, - * and the caller's class loader. Calling this method is equivalent to calling + * and the caller module. Calling this method is equivalent to calling *

- * getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader()), + * getBundle(baseName, Locale.getDefault(), callerModule), *
- * except that getClassLoader() is run with the security - * privileges of ResourceBundle. - * See {@link #getBundle(String, Locale, ClassLoader) getBundle} - * for a complete description of the search and instantiation strategy. * * @param baseName the base name of the resource bundle, a fully qualified class name * @exception java.lang.NullPointerException @@ -830,6 +846,9 @@ public abstract class ResourceBundle { * @exception MissingResourceException * if no resource bundle for the specified base name can be found * @return a resource bundle for the given base name and the default locale + * + * @see Resource Bundle Search and Loading Strategy + * @see Resource Bundles and Named Modules */ @CallerSensitive public static final ResourceBundle getBundle(String baseName) @@ -887,14 +906,10 @@ public abstract class ResourceBundle { /** * Gets a resource bundle using the specified base name and locale, - * and the caller's class loader. Calling this method is equivalent to calling + * and the caller module. Calling this method is equivalent to calling *
- * getBundle(baseName, locale, this.getClass().getClassLoader()), + * getBundle(baseName, locale, callerModule), *
- * except that getClassLoader() is run with the security - * privileges of ResourceBundle. - * See {@link #getBundle(String, Locale, ClassLoader) getBundle} - * for a complete description of the search and instantiation strategy. * * @param baseName * the base name of the resource bundle, a fully qualified class name @@ -905,6 +920,9 @@ public abstract class ResourceBundle { * @exception MissingResourceException * if no resource bundle for the specified base name can be found * @return a resource bundle for the given base name and locale + * + * @see Resource Bundle Search and Loading Strategy + * @see Resource Bundles and Named Modules */ @CallerSensitive public static final ResourceBundle getBundle(String baseName, @@ -922,19 +940,6 @@ public abstract class ResourceBundle { * getBundle(baseName, Locale.getDefault(), module) * * - *

Resource bundles in named modules may be encapsulated. When - * the resource bundle is loaded from a provider, the caller module - * must have an appropriate uses clause in its module descriptor - * to declare that the module uses implementations of - * {@code + ".spi." + + "Provider"}. - * Otherwise, it will load the resource bundles that are local in the - * given module or that are visible to the class loader of the given module - * (refer to the Resource Bundles in Named Modules - * section for details). - * When the resource bundle is loaded from the specified module, it is - * subject to the encapsulation rules specified by - * {@link Module#getResourceAsStream Module.getResourceAsStream}. - * * @param baseName the base name of the resource bundle, * a fully qualified class name * @param module the module for which the resource bundle is searched @@ -950,6 +955,8 @@ public abstract class ResourceBundle { * @since 9 * @spec JPMS * @see ResourceBundleProvider + * @see Resource Bundle Search and Loading Strategy + * @see Resource Bundles and Named Modules */ @CallerSensitive public static ResourceBundle getBundle(String baseName, Module module) { @@ -963,14 +970,15 @@ public abstract class ResourceBundle { * on behalf of the specified module. * *

Resource bundles in named modules may be encapsulated. When - * the resource bundle is loaded from a provider, the caller module + * the resource bundle is loaded from a + * {@linkplain ResourceBundleProvider service provider}, the caller module * must have an appropriate uses clause in its module descriptor - * to declare that the module uses implementations of - * {@code + ".spi." + + "Provider"}. + * to declare that the module uses of {@link ResourceBundleProvider} + * for the named resource bundle. * Otherwise, it will load the resource bundles that are local in the - * given module or that are visible to the class loader of the given module - * (refer to the Resource Bundles in Named Modules - * section for details). + * given module as if calling {@link Module#getResourceAsStream(String)} + * or that are visible to the class loader of the given module + * as if calling {@link ClassLoader#getResourceAsStream(String)}. * When the resource bundle is loaded from the specified module, it is * subject to the encapsulation rules specified by * {@link Module#getResourceAsStream Module.getResourceAsStream}. @@ -1000,6 +1008,8 @@ public abstract class ResourceBundle { * @return a resource bundle for the given base name and locale in the module * @since 9 * @spec JPMS + * @see Resource Bundle Search and Loading Strategy + * @see Resource Bundles and Named Modules */ @CallerSensitive public static ResourceBundle getBundle(String baseName, Locale targetLocale, Module module) { @@ -1060,28 +1070,25 @@ public abstract class ResourceBundle { * Gets a resource bundle using the specified base name, locale, and class * loader. * - *

This method behaves the same as calling - * {@link #getBundle(String, Locale, ClassLoader, Control)} passing a - * default instance of {@link Control} unless another {@link Control} is - * provided with the {@link ResourceBundleControlProvider} SPI. Refer to the - * description of modifying the default - * behavior. + *

When this method is called from a named module and the given + * loader is the class loader of the caller module, this is equivalent + * to calling: + *

+     * getBundle(baseName, targetLocale, callerModule)
+     * 
* - *

The following describes the default - * behavior. + * otherwise, this is equivalent to calling: + *

+     * getBundle(baseName, targetLocale, loader, control)
+     * 
+ * where {@code control} is the default instance of {@link Control} unless + * a {@code Control} instance is provided by + * {@link ResourceBundleControlProvider} SPI. Refer to the + * description of modifying the default + * behavior. The following describes the default behavior. * *

- * Resource bundles in a named module are private to that module. If - * the caller is in a named module, this method will find resource bundles - * from the service providers of {@link java.util.spi.ResourceBundleProvider} - * if any. Otherwise, it will load the resource bundles that are visible to - * the given {@code loader} (refer to the - * Resource Bundles in Named Modules section - * for details). - * If the caller is in a named module and the given {@code loader} is - * different than the caller's class loader, or if the caller is not in - * a named module, this method will not find resource bundles from named - * modules. + * Resource Bundle Search and Loading Strategy * *

getBundle uses the base name, the specified locale, and * the default locale (obtained from {@link java.util.Locale#getDefault() @@ -1201,7 +1208,7 @@ public abstract class ResourceBundle { * *

Note:The baseName argument should be a fully * qualified class name. However, for compatibility with earlier versions, - * Sun's Java SE Runtime Environments do not verify this, and so it is + * Java SE Runtime Environments do not verify this, and so it is * possible to access PropertyResourceBundles by specifying a * path name (using "/") instead of a fully qualified class name (using * "."). @@ -1248,7 +1255,7 @@ public abstract class ResourceBundle { * * @apiNote If the caller module is a named module and the given * {@code loader} is the caller module's class loader, this method is - * equivalent to {@code getBundle(baseName, locale)}; otherwise, it will not + * equivalent to {@code getBundle(baseName, locale)}; otherwise, it may not * find resource bundles from named modules. * Use {@link #getBundle(String, Locale, Module)} to load resource bundles * on behalf on a specific module instead. @@ -1264,6 +1271,7 @@ public abstract class ResourceBundle { * @since 1.2 * @revised 9 * @spec JPMS + * @see Resource Bundles and Named Modules */ @CallerSensitive public static ResourceBundle getBundle(String baseName, Locale locale, @@ -1278,9 +1286,9 @@ public abstract class ResourceBundle { /** * Returns a resource bundle using the specified base name, target - * locale, class loader and control. Unlike the {@linkplain - * #getBundle(String, Locale, ClassLoader) getBundle - * factory methods with no control argument}, the given + * locale, class loader and control. Unlike the {@link + * #getBundle(String, Locale, ClassLoader) getBundle} + * factory methods with no {@code control} argument, the given * control specifies how to locate and instantiate resource * bundles. Conceptually, the bundle loading process with the given * control is performed in the following steps. @@ -2365,7 +2373,14 @@ public abstract class ResourceBundle { * the callback methods provides the information necessary for the * factory methods to perform the default behavior. - * Note that this class is not supported in named modules. + * + *

{@link ResourceBundle.Control} is designed for an application deployed + * in an unnamed module, for example to support resource bundles in + * non-standard formats or package localized resources in a non-traditional + * convention. {@link ResourceBundleProvider} is the replacement for + * {@code ResourceBundle.Control} when migrating to modules. + * {@code UnsupportedOperationException} will be thrown when a factory + * method that takes the {@code ResourceBundle.Control} parameter is called. * *

In addition to the callback methods, the {@link * #toBundleName(String, Locale) toBundleName} and {@link @@ -2501,8 +2516,8 @@ public abstract class ResourceBundle { * } * * - * @apiNote {@code ResourceBundle.Control} is not supported - * in named modules. If the {@code ResourceBundle.getBundle} method with + * @apiNote {@code ResourceBundle.Control} is not supported + * in named modules. If the {@code ResourceBundle.getBundle} method with * a {@code ResourceBundle.Control} is called in a named module, the method * will throw an {@link UnsupportedOperationException}. Any service providers * of {@link ResourceBundleControlProvider} are ignored in named modules. diff --git a/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java b/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java index 937d233e267..2c543c63bcf 100644 --- a/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java +++ b/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java @@ -45,42 +45,46 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; * *

* Resource bundles can be packaged in one or more - * named modules, bundle modules. The consumer of the + * named modules, service provider modules. The consumer of the * resource bundle is the one calling {@link ResourceBundle#getBundle(String)}. * In order for the consumer module to load a resource bundle * "{@code com.example.app.MyResources}" provided by another module, * it will use the {@linkplain java.util.ServiceLoader service loader} - * mechanism. A service interface named "{@code com.example.app.MyResourcesProvider}" - * must be defined and a bundle provider module will provide an - * implementation class of "{@code com.example.app.MyResourcesProvider}" + * mechanism. A service interface named "{@code com.example.app.spi.MyResourcesProvider}" + * must be defined and a service provider module will provide an + * implementation class of "{@code com.example.app.spi.MyResourcesProvider}" * as follows: * - *


- * import com.example.app.MyResourcesProvider;
+ * 
+ * {@code import com.example.app.spi.MyResourcesProvider;
  * class MyResourcesProviderImpl extends AbstractResourceBundleProvider
  *     implements MyResourcesProvider
  * {
+ *     public MyResourcesProviderImpl() {
+ *         super("java.properties");
+ *     }
+ *     // this provider maps the resource bundle to per-language package
  *     protected String toBundleName(String baseName, Locale locale) {
- *         // return the bundle name per the naming of the resource bundle
- *         :
+ *         return "p." + locale.getLanguage() + "." + baseName;
  *     }
  *
  *     public ResourceBundle getBundle(String baseName, Locale locale) {
- *         // this module only provides bundles in french
+ *         // this module only provides bundles in French
  *         if (locale.equals(Locale.FRENCH)) {
  *              return super.getBundle(baseName, locale);
  *         }
+ *         // otherwise return null
  *         return null;
  *     }
- * }
+ * }}
* - * @see - * Resource Bundles in Named Modules - * @see - * ResourceBundleProvider Service Providers + * Refer to {@link ResourceBundleProvider} for details. * + * @see + * Resource Bundles and Named Modules * @since 9 * @spec JPMS + */ public abstract class AbstractResourceBundleProvider implements ResourceBundleProvider { private static final JavaUtilResourceBundleAccess RB_ACCESS = diff --git a/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java b/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java index 0cb0bccd4a6..62fa501c538 100644 --- a/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java +++ b/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java @@ -29,33 +29,117 @@ import java.util.Locale; import java.util.ResourceBundle; /** - * {@code ResourceBundleProvider} is a provider interface that is used for - * loading resource bundles for named modules. Implementation classes of - * this interface are loaded with {@link java.util.ServiceLoader ServiceLoader} - * during a call to the - * {@link ResourceBundle#getBundle(String, Locale, ClassLoader) - * ResourceBundle.getBundle} method. The provider service type is determined by - * {@code + ".spi." + + "Provider"}. + * {@code ResourceBundleProvider} is a service provider interface for + * resource bundles. It is used by + * {@link ResourceBundle#getBundle(String) ResourceBundle.getBundle} + * factory methods to locate and load the service providers that are deployed as + * modules via {@link java.util.ServiceLoader ServiceLoader}. * - *

- * For example, if the base name is "com.example.app.MyResources", - * {@code com.example.app.spi.MyResourcesProvider} will be the provider service type: - *

{@code
+ * 

Developing resource bundle services

+ * + * A service for a resource bundle of a given {@code baseName} must have + * a fully-qualified class name of the form: + *
+ * {@code + ".spi." + + "Provider"} + *
+ * + * The service type is in a {@code spi} subpackage as it may be packaged in + * a module separate from the resource bundle providers. + * For example, the service for a resource bundle named + * {@code com.example.app.MyResources} must be + * {@code com.example.app.spi.MyResourcesProvider}: + * + *
+ * {@code package com.example.app.spi;
  * public interface MyResourcesProvider extends ResourceBundleProvider {
  * }
- * }
+ * }
* - *

- * This providers's {@link #getBundle(String, Locale) getBundle} method is called - * through the resource bundle loading process instead of {@link - * java.util.ResourceBundle.Control#newBundle(String, Locale, String, ClassLoader, boolean) - * ResourceBundle.Control.newBundle()}. Refer to {@link ResourceBundle} for - * details. + *

Deploying resource bundle service providers

* - * @see - * Resource Bundles in Named Modules - * @see - * ResourceBundleProvider Service Providers + * Resource bundles can be deployed in one or more service providers + * in modules. For example, a provider for a service + * named "{@code com.example.app.spi.MyResourcesProvider}" + * has the following implementation class: + * + *
+ * {@code import com.example.app.spi.MyResourcesProvider;
+ * class MyResourcesProviderImpl extends AbstractResourceBundleProvider
+ *     implements MyResourcesProvider
+ * {
+ *     public MyResourcesProviderImpl() {
+ *         super("java.properties");
+ *     }
+ *     // this provider maps the resource bundle to per-language package
+ *     protected String toBundleName(String baseName, Locale locale) {
+ *         return "p." + locale.getLanguage() + "." + baseName;
+ *     }
+ *
+ *     public ResourceBundle getBundle(String baseName, Locale locale) {
+ *         // this module only provides bundles in French
+ *         if (locale.equals(Locale.FRENCH)) {
+ *              return super.getBundle(baseName, locale);
+ *         }
+ *         // otherwise return null
+ *         return null;
+ *     }
+ * }}
+ * + * This example provides "{@code com.example.app.MyResources}" + * resource bundle of the French locale. Traditionally resource bundles of + * all locales are packaged in the same package as the resource bundle base name. + * When deploying resource bundles in more than one modules and two modules + * containing a package of the same name, split package, + * is not supported, resource bundles in each module can be packaged in + * a different package as shown in this example where this provider packages + * the resource bundles in per-language package, i.e. {@code com.example.app.fr} + * for French locale. + * + *

A provider can provide more than one services, each of which is a service + * for a resource bundle of a different base name. + * + *

{@link AbstractResourceBundleProvider} + * provides the basic implementation for {@code ResourceBundleProvider} + * and a subclass can override the {@link + * AbstractResourceBundleProvider#toBundleName(String, Locale) toBundleName} + * method to return a provider-specific location of the resource to be loaded, + * for example, per-language package. + * A provider can override {@link #getBundle ResourceBundleProvider.getBundle} + * method for example to only search the known supported locales or + * return resource bundles in other formats such as XML. + * + *

The module declaration of this provider module specifies the following + * directive: + *

+ *     provides com.example.app.spi.MyResourcesProvider with com.example.impl.MyResourcesProviderImpl;
+ * 
+ * + *

Obtaining resource bundles from providers

+ * + * The module declaration of the consumer module that calls one of the + * {@code ResourceBundle.getBundle} factory methods to obtain a resource + * bundle from service providers must specify the following directive: + *
+ *     uses com.example.app.spi.MyResourcesProvider;
+ * 
+ * + * {@link ResourceBundle#getBundle(String, Locale) + * ResourceBundle.getBundle("com.example.app.MyResource", locale)} + * locates and loads the providers for {@code com.example.app.spi.MyResourcesProvider} + * service and then invokes {@link #getBundle(String, Locale) + * ResourceBundleProvider.getBundle("com.example.app.MyResource", locale)} to + * find the resource bundle of the given base name and locale. + * If the consumer module is a resource bundle service provider for + * {@code com.example.app.spi.MyResourcesProvider}, {@code ResourceBundle.getBundle} + * will locate resource bundles only from service providers. + * Otherwise, {@code ResourceBundle.getBundle} may continue the search of + * the resource bundle in other modules and class path per the specification + * of the {@code ResourceBundle.getBundle} method being called. + * + * @see AbstractResourceBundleProvider + * @see + * Resource Bundles and Named Modules + * @see java.util.ServiceLoader * @since 9 * @spec JPMS */ diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java index 942af76b69d..230695206f0 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java @@ -64,7 +64,7 @@ import static jdk.internal.module.ClassFileConstants.*; public final class ModuleInfo { private final int JAVA_MIN_SUPPORTED_VERSION = 53; - private final int JAVA_MAX_SUPPORTED_VERSION = 54; + private final int JAVA_MAX_SUPPORTED_VERSION = 55; private static final JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess(); diff --git a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/ClassReader.java b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/ClassReader.java index 47e1f6d4b15..22b475f9db9 100644 --- a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/ClassReader.java +++ b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/ClassReader.java @@ -185,7 +185,7 @@ public class ClassReader { public ClassReader(final byte[] b, final int off, final int len) { this.b = b; // checks the class version - if (readShort(off + 6) > Opcodes.V10) { + if (readShort(off + 6) > Opcodes.V11) { throw new IllegalArgumentException(); } // parses the constant pool diff --git a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/Opcodes.java b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/Opcodes.java index 7ce9d9210c8..8b3ab18626c 100644 --- a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/Opcodes.java +++ b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/Opcodes.java @@ -90,6 +90,7 @@ public interface Opcodes { int V1_8 = 0 << 16 | 52; int V9 = 0 << 16 | 53; int V10 = 0 << 16 | 54; + int V11 = 0 << 16 | 55; // access flags diff --git a/src/java.base/share/classes/java/util/ArraysSupport.java b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java similarity index 83% rename from src/java.base/share/classes/java/util/ArraysSupport.java rename to src/java.base/share/classes/jdk/internal/util/ArraysSupport.java index 31612a7d4f8..cc051df7d31 100644 --- a/src/java.base/share/classes/java/util/ArraysSupport.java +++ b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.util; +package jdk.internal.util; import jdk.internal.HotSpotIntrinsicCandidate; import jdk.internal.misc.Unsafe; @@ -50,19 +50,19 @@ import jdk.internal.misc.Unsafe; * responsibility of the caller (direct or otherwise) to perform such checks * before calling this method. */ -class ArraysSupport { +public class ArraysSupport { static final Unsafe U = Unsafe.getUnsafe(); private static final boolean BIG_ENDIAN = U.isBigEndian(); - private static final int LOG2_ARRAY_BOOLEAN_INDEX_SCALE = exactLog2(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE); - private static final int LOG2_ARRAY_BYTE_INDEX_SCALE = exactLog2(Unsafe.ARRAY_BYTE_INDEX_SCALE); - private static final int LOG2_ARRAY_CHAR_INDEX_SCALE = exactLog2(Unsafe.ARRAY_CHAR_INDEX_SCALE); - private static final int LOG2_ARRAY_SHORT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_SHORT_INDEX_SCALE); - private static final int LOG2_ARRAY_INT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_INT_INDEX_SCALE); - private static final int LOG2_ARRAY_LONG_INDEX_SCALE = exactLog2(Unsafe.ARRAY_LONG_INDEX_SCALE); - private static final int LOG2_ARRAY_FLOAT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_FLOAT_INDEX_SCALE); - private static final int LOG2_ARRAY_DOUBLE_INDEX_SCALE = exactLog2(Unsafe.ARRAY_DOUBLE_INDEX_SCALE); + public static final int LOG2_ARRAY_BOOLEAN_INDEX_SCALE = exactLog2(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE); + public static final int LOG2_ARRAY_BYTE_INDEX_SCALE = exactLog2(Unsafe.ARRAY_BYTE_INDEX_SCALE); + public static final int LOG2_ARRAY_CHAR_INDEX_SCALE = exactLog2(Unsafe.ARRAY_CHAR_INDEX_SCALE); + public static final int LOG2_ARRAY_SHORT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_SHORT_INDEX_SCALE); + public static final int LOG2_ARRAY_INT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_INT_INDEX_SCALE); + public static final int LOG2_ARRAY_LONG_INDEX_SCALE = exactLog2(Unsafe.ARRAY_LONG_INDEX_SCALE); + public static final int LOG2_ARRAY_FLOAT_INDEX_SCALE = exactLog2(Unsafe.ARRAY_FLOAT_INDEX_SCALE); + public static final int LOG2_ARRAY_DOUBLE_INDEX_SCALE = exactLog2(Unsafe.ARRAY_DOUBLE_INDEX_SCALE); private static final int LOG2_BYTE_BIT_SIZE = exactLog2(Byte.SIZE); @@ -107,10 +107,10 @@ class ArraysSupport { * the tail of the two arrays. */ @HotSpotIntrinsicCandidate - static int vectorizedMismatch(Object a, long aOffset, - Object b, long bOffset, - int length, - int log2ArrayIndexScale) { + public static int vectorizedMismatch(Object a, long aOffset, + Object b, long bOffset, + int length, + int log2ArrayIndexScale) { // assert a.getClass().isArray(); // assert b.getClass().isArray(); // assert 0 <= length <= sizeOf(a) @@ -161,9 +161,9 @@ class ArraysSupport { // Booleans // Each boolean element takes up one byte - static int mismatch(boolean[] a, - boolean[] b, - int length) { + public static int mismatch(boolean[] a, + boolean[] b, + int length) { int i = 0; if (length > 7) { i = vectorizedMismatch( @@ -181,9 +181,9 @@ class ArraysSupport { return -1; } - static int mismatch(boolean[] a, int aFromIndex, - boolean[] b, int bFromIndex, - int length) { + public static int mismatch(boolean[] a, int aFromIndex, + boolean[] b, int bFromIndex, + int length) { int i = 0; if (length > 7) { int aOffset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET + aFromIndex; @@ -219,9 +219,9 @@ class ArraysSupport { * no mismatch. The index will be within the range of (inclusive) 0 to * (exclusive) the smaller of the two array lengths. */ - static int mismatch(byte[] a, - byte[] b, - int length) { + public static int mismatch(byte[] a, + byte[] b, + int length) { // ISSUE: defer to index receiving methods if performance is good // assert length <= a.length // assert length <= b.length @@ -264,9 +264,9 @@ class ArraysSupport { * otherwise -1 if no mismatch. The index will be within the range of * (inclusive) 0 to (exclusive) the smaller of the two array bounds. */ - static int mismatch(byte[] a, int aFromIndex, - byte[] b, int bFromIndex, - int length) { + public static int mismatch(byte[] a, int aFromIndex, + byte[] b, int bFromIndex, + int length) { // assert 0 <= aFromIndex < a.length // assert 0 <= aFromIndex + length <= a.length // assert 0 <= bFromIndex < b.length @@ -295,9 +295,9 @@ class ArraysSupport { // Chars - static int mismatch(char[] a, - char[] b, - int length) { + public static int mismatch(char[] a, + char[] b, + int length) { int i = 0; if (length > 3) { i = vectorizedMismatch( @@ -315,9 +315,9 @@ class ArraysSupport { return -1; } - static int mismatch(char[] a, int aFromIndex, - char[] b, int bFromIndex, - int length) { + public static int mismatch(char[] a, int aFromIndex, + char[] b, int bFromIndex, + int length) { int i = 0; if (length > 3) { int aOffset = Unsafe.ARRAY_CHAR_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_CHAR_INDEX_SCALE); @@ -340,9 +340,9 @@ class ArraysSupport { // Shorts - static int mismatch(short[] a, - short[] b, - int length) { + public static int mismatch(short[] a, + short[] b, + int length) { int i = 0; if (length > 3) { i = vectorizedMismatch( @@ -360,9 +360,9 @@ class ArraysSupport { return -1; } - static int mismatch(short[] a, int aFromIndex, - short[] b, int bFromIndex, - int length) { + public static int mismatch(short[] a, int aFromIndex, + short[] b, int bFromIndex, + int length) { int i = 0; if (length > 3) { int aOffset = Unsafe.ARRAY_SHORT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_SHORT_INDEX_SCALE); @@ -385,9 +385,9 @@ class ArraysSupport { // Ints - static int mismatch(int[] a, - int[] b, - int length) { + public static int mismatch(int[] a, + int[] b, + int length) { int i = 0; if (length > 1) { i = vectorizedMismatch( @@ -405,9 +405,9 @@ class ArraysSupport { return -1; } - static int mismatch(int[] a, int aFromIndex, - int[] b, int bFromIndex, - int length) { + public static int mismatch(int[] a, int aFromIndex, + int[] b, int bFromIndex, + int length) { int i = 0; if (length > 1) { int aOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_INT_INDEX_SCALE); @@ -430,15 +430,15 @@ class ArraysSupport { // Floats - static int mismatch(float[] a, - float[] b, - int length) { + public static int mismatch(float[] a, + float[] b, + int length) { return mismatch(a, 0, b, 0, length); } - static int mismatch(float[] a, int aFromIndex, - float[] b, int bFromIndex, - int length) { + public static int mismatch(float[] a, int aFromIndex, + float[] b, int bFromIndex, + int length) { int i = 0; if (length > 1) { int aOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_FLOAT_INDEX_SCALE); @@ -475,9 +475,9 @@ class ArraysSupport { // Long - static int mismatch(long[] a, - long[] b, - int length) { + public static int mismatch(long[] a, + long[] b, + int length) { if (length == 0) { return -1; } @@ -488,9 +488,9 @@ class ArraysSupport { return i >= 0 ? i : -1; } - static int mismatch(long[] a, int aFromIndex, - long[] b, int bFromIndex, - int length) { + public static int mismatch(long[] a, int aFromIndex, + long[] b, int bFromIndex, + int length) { if (length == 0) { return -1; } @@ -506,15 +506,15 @@ class ArraysSupport { // Double - static int mismatch(double[] a, - double[] b, - int length) { + public static int mismatch(double[] a, + double[] b, + int length) { return mismatch(a, 0, b, 0, length); } - static int mismatch(double[] a, int aFromIndex, - double[] b, int bFromIndex, - int length) { + public static int mismatch(double[] a, int aFromIndex, + double[] b, int bFromIndex, + int length) { if (length == 0) { return -1; } diff --git a/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java b/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java index 2a3775da7df..ba86dd87875 100644 --- a/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java +++ b/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -108,7 +108,29 @@ final class HandshakeHash { * a hash for the certificate verify message is required. */ HandshakeHash(boolean needCertificateVerify) { - clonesNeeded = needCertificateVerify ? 4 : 3; + // We may rework the code later, but for now we use hard-coded number + // of clones if the underlying MessageDigests are not cloneable. + // + // The number used here is based on the current handshake protocols and + // implementation. It may be changed if the handshake processe gets + // changed in the future, for example adding a new extension that + // requires handshake hash. Please be careful about the number of + // clones if additional handshak hash is required in the future. + // + // For the current implementation, the handshake hash is required for + // the following items: + // . CertificateVerify handshake message (optional) + // . client Finished handshake message + // . server Finished Handshake message + // . the extended Master Secret extension [RFC 7627] + // + // Note that a late call to server setNeedClientAuth dose not update + // the number of clones. We may address the issue later. + // + // Note for safety, we allocate one more clone for the current + // implementation. We may consider it more carefully in the future + // for the exact number or rework the code in a different way. + clonesNeeded = needCertificateVerify ? 5 : 4; } void reserve(ByteBuffer input) { @@ -335,7 +357,8 @@ final class HandshakeHash { if (finMD != null) return; try { - finMD = CloneableDigest.getDigest(normalizeAlgName(s), 2); + // See comment in the contructor. + finMD = CloneableDigest.getDigest(normalizeAlgName(s), 4); } catch (NoSuchAlgorithmException e) { throw new Error(e); } diff --git a/src/java.base/share/native/include/classfile_constants.h b/src/java.base/share/native/include/classfile_constants.h.template similarity index 99% rename from src/java.base/share/native/include/classfile_constants.h rename to src/java.base/share/native/include/classfile_constants.h.template index 3b63f31c6e8..1046b54b37a 100644 --- a/src/java.base/share/native/include/classfile_constants.h +++ b/src/java.base/share/native/include/classfile_constants.h.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,8 +31,8 @@ extern "C" { #endif /* Classfile version number for this information */ -#define JVM_CLASSFILE_MAJOR_VERSION 54 -#define JVM_CLASSFILE_MINOR_VERSION 0 +#define JVM_CLASSFILE_MAJOR_VERSION @@VERSION_CLASSFILE_MAJOR@@ +#define JVM_CLASSFILE_MINOR_VERSION @@VERSION_CLASSFILE_MINOR@@ /* Flags */ diff --git a/src/java.base/share/native/libjava/System.c b/src/java.base/share/native/libjava/System.c index 9116b8d8265..5c5060af124 100644 --- a/src/java.base/share/native/libjava/System.c +++ b/src/java.base/share/native/libjava/System.c @@ -114,9 +114,6 @@ Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x) #define VENDOR_URL_BUG "http://bugreport.java.com/bugreport/" #endif -#define JAVA_MAX_SUPPORTED_VERSION 54 -#define JAVA_MAX_SUPPORTED_MINOR_VERSION 0 - #ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */ #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed" #else @@ -222,8 +219,8 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props) PUTPROP(props, "java.vendor.url", VENDOR_URL); PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG); - jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION, - JAVA_MAX_SUPPORTED_MINOR_VERSION); + jio_snprintf(buf, sizeof(buf), "%d.%d", JVM_CLASSFILE_MAJOR_VERSION, + JVM_CLASSFILE_MINOR_VERSION); PUTPROP(props, "java.class.version", buf); if (sprops->awt_toolkit) { diff --git a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java index 5d8124aeda6..6a0c8f55e6e 100644 --- a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java +++ b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java @@ -57,6 +57,7 @@ public enum SourceVersion { * 1.8: lambda expressions and default methods * 9: modules, small cleanups to 1.7 and 1.8 changes * 10: local-variable type inference (var) + * 11: to be determined changes */ /** @@ -162,7 +163,15 @@ public enum SourceVersion { * * @since 10 */ - RELEASE_10; + RELEASE_10, + + /** + * The version recognized by the Java Platform, Standard Edition + * 11. + * + * @since 11 + */ + RELEASE_11; // Note that when adding constants for newer releases, the // behavior of latest() and latestSupported() must be updated too. @@ -173,7 +182,7 @@ public enum SourceVersion { * @return the latest source version that can be modeled */ public static SourceVersion latest() { - return RELEASE_10; + return RELEASE_11; } private static final SourceVersion latestSupported = getLatestSupported(); @@ -183,6 +192,8 @@ public enum SourceVersion { String specVersion = System.getProperty("java.specification.version"); switch (specVersion) { + case "11": + return RELEASE_11; case "10": return RELEASE_10; case "9": diff --git a/src/java.desktop/share/classes/java/awt/Toolkit.java b/src/java.desktop/share/classes/java/awt/Toolkit.java index 8a36c2977b1..7a4372ace66 100644 --- a/src/java.desktop/share/classes/java/awt/Toolkit.java +++ b/src/java.desktop/share/classes/java/awt/Toolkit.java @@ -678,6 +678,11 @@ public abstract class Toolkit { * If the connection to the specified URL requires * either {@code URLPermission} or {@code SocketPermission}, * then {@code URLPermission} is used for security checks. + * For compatibility with pre-1.2 security managers, if the access + * is denied with {@code FilePermission} or {@code SocketPermission}, + * the method throws the {@code SecurityException} + * if the corresponding 1.1-style SecurityManager.checkXXX method + * also denies permission. * @param url the URL to use in fetching the pixel data. * @return an image which gets its pixel data from * the specified URL. @@ -719,6 +724,11 @@ public abstract class Toolkit { * If the connection to the specified URL requires * either {@code URLPermission} or {@code SocketPermission}, * then {@code URLPermission} is used for security checks. + * For compatibility with pre-1.2 security managers, if the access + * is denied with {@code FilePermission} or {@code SocketPermission}, + * the method throws {@code SecurityException} + * if the corresponding 1.1-style SecurityManager.checkXXX method + * also denies permission. * @param url the URL to use in fetching the pixel data. * @return an image which gets its pixel data from * the specified URL. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java index 23447f62aae..107b94598ca 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java @@ -78,8 +78,11 @@ public enum Source { /** 1.9 modularity. */ JDK9("9"), - /** 1.10 covers the to be determined language features that will be added in JDK 10. */ - JDK10("10"); + /** 1.10 local-variable type inference (var). */ + JDK10("10"), + + /** 1.11 covers the to be determined language features that will be added in JDK 11. */ + JDK11("11"); private static final Context.Key sourceKey = new Context.Key<>(); @@ -108,6 +111,7 @@ public enum Source { tab.put("1.8", JDK8); // Make 8 an alias for 1.8 tab.put("1.9", JDK9); // Make 9 an alias for 1.9 tab.put("1.10", JDK10); // Make 10 an alias for 1.10 + // Decline to make 1.11 an alias for 11. } private Source(String name) { @@ -125,6 +129,7 @@ public enum Source { } public Target requiredTarget() { + if (this.compareTo(JDK11) >= 0) return Target.JDK1_11; if (this.compareTo(JDK10) >= 0) return Target.JDK1_10; if (this.compareTo(JDK9) >= 0) return Target.JDK1_9; if (this.compareTo(JDK8) >= 0) return Target.JDK1_8; @@ -247,6 +252,8 @@ public enum Source { return RELEASE_9; case JDK10: return RELEASE_10; + case JDK11: + return RELEASE_11; default: return null; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java index 0f4d3fecd07..fcaad5c2d0e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java @@ -1628,9 +1628,6 @@ public abstract class Symbol extends AnnoConstruct implements Element { /** The parameters of the method. */ public List params = null; - /** The names of the parameters */ - public List savedParameterNames; - /** For an annotation type element, its default value if any. * The value is null if none appeared in the method * declaration. @@ -1886,57 +1883,18 @@ public abstract class Symbol extends AnnoConstruct implements Element { public List params() { owner.complete(); if (params == null) { - // If ClassReader.saveParameterNames has been set true, then - // savedParameterNames will be set to a list of names that - // matches the types in type.getParameterTypes(). If any names - // were not found in the class file, those names in the list will - // be set to the empty name. - // If ClassReader.saveParameterNames has been set false, then - // savedParameterNames will be null. - List paramNames = savedParameterNames; - savedParameterNames = null; - // discard the provided names if the list of names is the wrong size. - if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) { - paramNames = List.nil(); - } - ListBuffer buf = new ListBuffer<>(); - List remaining = paramNames; - // assert: remaining and paramNames are both empty or both - // have same cardinality as type.getParameterTypes() + ListBuffer newParams = new ListBuffer<>(); int i = 0; for (Type t : type.getParameterTypes()) { - Name paramName; - if (remaining.isEmpty()) { - // no names for any parameters available - paramName = createArgName(i, paramNames); - } else { - paramName = remaining.head; - remaining = remaining.tail; - if (paramName.isEmpty()) { - // no name for this specific parameter - paramName = createArgName(i, paramNames); - } - } - buf.append(new VarSymbol(PARAMETER, paramName, t, this)); - i++; - } - params = buf.toList(); - } - return params; - } + Name paramName = name.table.fromString("arg" + i); + VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this); + newParams.append(param); - // Create a name for the argument at position 'index' that is not in - // the exclude list. In normal use, either no names will have been - // provided, in which case the exclude list is empty, or all the names - // will have been provided, in which case this method will not be called. - private Name createArgName(int index, List exclude) { - String prefix = "arg"; - while (true) { - Name argName = name.table.fromString(prefix + index); - if (!exclude.contains(argName)) - return argName; - prefix += "$"; + } + params = newParams.toList(); } + Assert.checkNonNull(params); + return params; } public Symbol asMemberOf(Type site, Types types) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 4f1d7142bbb..b3999f56571 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -1976,8 +1976,8 @@ public class Check { types.covariantReturnType(rt2, rt1, types.noWarnings)) || checkCommonOverriderIn(s1,s2,site); if (!compat) { - log.error(pos, Errors.TypesIncompatibleDiffRet(t1, t2, s2.name + - "(" + types.memberType(t2, s2).getParameterTypes() + ")")); + log.error(pos, Errors.TypesIncompatible(t1, t2, + Fragments.IncompatibleDiffRet(s2.name, types.memberType(t2, s2).getParameterTypes()))); return s2; } } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) && @@ -2563,20 +2563,22 @@ public class Check { //strong semantics - issue an error if two sibling interfaces //have two override-equivalent defaults - or if one is abstract //and the other is default - String errKey; + Fragment diagKey; Symbol s1 = defaults.first(); Symbol s2; if (defaults.size() > 1) { - errKey = "types.incompatible.unrelated.defaults"; s2 = defaults.toList().tail.head; + diagKey = Fragments.IncompatibleUnrelatedDefaults(Kinds.kindName(site.tsym), site, + m.name, types.memberType(site, m).getParameterTypes(), + s1.location(), s2.location()); + } else { - errKey = "types.incompatible.abstract.default"; s2 = abstracts.first(); + diagKey = Fragments.IncompatibleAbstractDefault(Kinds.kindName(site.tsym), site, + m.name, types.memberType(site, m).getParameterTypes(), + s1.location(), s2.location()); } - log.error(pos, errKey, - Kinds.kindName(site.tsym), site, - m.name, types.memberType(site, m).getParameterTypes(), - s1.location(), s2.location()); + log.error(pos, Errors.TypesIncompatible(s1.location().type, s2.location().type, diagKey)); break; } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java index fe4cb8529de..ec60235650e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -421,6 +421,12 @@ public class Enter extends JCTree.Visitor { // We are seeing a member class. c = syms.enterClass(env.toplevel.modle, tree.name, (TypeSymbol)owner); if (c.owner != owner) { + if (c.name != tree.name) { + log.error(tree.pos(), Errors.SameBinaryName(c.name, tree.name)); + result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType); + tree.sym = (ClassSymbol)result.tsym; + return; + } //anonymous class loaded from a classfile may be recreated from source (see below) //if this class is a member of such an anonymous class, fix the owner: Assert.check(owner.owner.kind != TYP, owner::toString); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java index 6e80995e509..bdb8a8bafa3 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java @@ -111,7 +111,8 @@ public class ClassFile { V51(51, 0), // JDK 1.7 V52(52, 0), // JDK 1.8: lambda, type annos, param names V53(53, 0), // JDK 1.9: modules, indy string concat - V54(54, 0); // JDK 10 + V54(54, 0), // JDK 10 + V55(55, 0); // JDK 11: constant dynamic Version(int major, int minor) { this.major = major; this.minor = minor; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 90cd8bee4aa..e8c48acc45e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -192,6 +192,26 @@ public class ClassReader { */ int[] parameterNameIndices; + /** + * A table to hold annotations for method parameters. + */ + ParameterAnnotations[] parameterAnnotations; + + /** + * A holder for parameter annotations. + */ + static class ParameterAnnotations { + List proxies; + + void add(List newAnnotations) { + if (proxies == null) { + proxies = newAnnotations; + } else { + proxies = proxies.prependList(newAnnotations); + } + } + } + /** * Whether or not any parameter names have been found. */ @@ -1218,7 +1238,7 @@ public class ClassReader { new AttributeReader(names.RuntimeInvisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) { protected void read(Symbol sym, int attrLen) { - attachParameterAnnotations(sym); + readParameterAnnotations(sym); } }, @@ -1230,7 +1250,7 @@ public class ClassReader { new AttributeReader(names.RuntimeVisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) { protected void read(Symbol sym, int attrLen) { - attachParameterAnnotations(sym); + readParameterAnnotations(sym); } }, @@ -1288,10 +1308,14 @@ public class ClassReader { int numEntries = nextByte(); parameterNameIndices = new int[numEntries]; haveParameterNameIndices = true; + int index = 0; for (int i = 0; i < numEntries; i++) { int nameIndex = nextChar(); int flags = nextChar(); - parameterNameIndices[i] = nameIndex; + if ((flags & (Flags.MANDATED | Flags.SYNTHETIC)) != 0) { + continue; + } + parameterNameIndices[index++] = nameIndex; } } bp = newbp; @@ -1580,66 +1604,83 @@ public class ClassReader { * Reading Java-language annotations ***********************************************************************/ + /** + * Save annotations. + */ + List readAnnotations() { + int numAttributes = nextChar(); + ListBuffer annotations = new ListBuffer<>(); + for (int i = 0; i < numAttributes; i++) { + annotations.append(readCompoundAnnotation()); + } + return annotations.toList(); + } + /** Attach annotations. */ void attachAnnotations(final Symbol sym) { - int numAttributes = nextChar(); - if (numAttributes != 0) { - ListBuffer proxies = new ListBuffer<>(); - for (int i = 0; i v: proxy.values) { - if (v.fst == names.value && v.snd instanceof Attribute.Constant) { - Attribute.Constant c = (Attribute.Constant) v.snd; - if (c.type == syms.intType && ((Integer) c.value) > profile.value) { - sym.flags_field |= NOT_IN_PROFILE; - } - } - } - } - } else { - if (proxy.type.tsym == syms.annotationTargetType.tsym) { - target = proxy; - } else if (proxy.type.tsym == syms.repeatableType.tsym) { - repeatable = proxy; - } else if (proxy.type.tsym == syms.deprecatedType.tsym) { - sym.flags_field |= (DEPRECATED | DEPRECATED_ANNOTATION); - for (Pair v : proxy.values) { - if (v.fst == names.forRemoval && v.snd instanceof Attribute.Constant) { - Attribute.Constant c = (Attribute.Constant) v.snd; - if (c.type == syms.booleanType && ((Integer) c.value) != 0) { - sym.flags_field |= DEPRECATED_REMOVAL; - } - } - } - } - - proxies.append(proxy); - } - } - annotate.normal(new AnnotationCompleter(sym, proxies.toList())); - } + attachAnnotations(sym, readAnnotations()); } - /** Attach parameter annotations. + /** + * Attach annotations. */ - void attachParameterAnnotations(final Symbol method) { - final MethodSymbol meth = (MethodSymbol)method; - int numParameters = buf[bp++] & 0xFF; - List parameters = meth.params(); - int pnum = 0; - while (parameters.tail != null) { - attachAnnotations(parameters.head); - parameters = parameters.tail; - pnum++; + void attachAnnotations(final Symbol sym, List annotations) { + if (annotations.isEmpty()) { + return; } - if (pnum != numParameters) { + ListBuffer proxies = new ListBuffer<>(); + for (CompoundAnnotationProxy proxy : annotations) { + if (proxy.type.tsym == syms.proprietaryType.tsym) + sym.flags_field |= PROPRIETARY; + else if (proxy.type.tsym == syms.profileType.tsym) { + if (profile != Profile.DEFAULT) { + for (Pair v : proxy.values) { + if (v.fst == names.value && v.snd instanceof Attribute.Constant) { + Attribute.Constant c = (Attribute.Constant)v.snd; + if (c.type == syms.intType && ((Integer)c.value) > profile.value) { + sym.flags_field |= NOT_IN_PROFILE; + } + } + } + } + } else { + if (proxy.type.tsym == syms.annotationTargetType.tsym) { + target = proxy; + } else if (proxy.type.tsym == syms.repeatableType.tsym) { + repeatable = proxy; + } else if (proxy.type.tsym == syms.deprecatedType.tsym) { + sym.flags_field |= (DEPRECATED | DEPRECATED_ANNOTATION); + for (Pair v : proxy.values) { + if (v.fst == names.forRemoval && v.snd instanceof Attribute.Constant) { + Attribute.Constant c = (Attribute.Constant)v.snd; + if (c.type == syms.booleanType && ((Integer)c.value) != 0) { + sym.flags_field |= DEPRECATED_REMOVAL; + } + } + } + } + proxies.append(proxy); + } + } + annotate.normal(new AnnotationCompleter(sym, proxies.toList())); + } + + /** Read parameter annotations. + */ + void readParameterAnnotations(Symbol meth) { + int numParameters = buf[bp++] & 0xFF; + if (parameterAnnotations == null) { + parameterAnnotations = new ParameterAnnotations[numParameters]; + } else if (parameterAnnotations.length != numParameters) { throw badClassFile("bad.runtime.invisible.param.annotations", meth); } + for (int pnum = 0; pnum < numParameters; pnum++) { + if (parameterAnnotations[pnum] == null) { + parameterAnnotations[pnum] = new ParameterAnnotations(); + } + parameterAnnotations[pnum].add(readAnnotations()); + } } void attachTypeAnnotations(final Symbol sym) { @@ -2403,8 +2444,7 @@ public class ClassReader { } finally { currentOwner = prevOwner; } - if (saveParameterNames) - setParameterNames(m, type); + setParameters(m, type); if ((flags & VARARGS) != 0) { final Type last = type.getParameterTypes().last(); @@ -2457,22 +2497,17 @@ public class ClassReader { } /** - * Set the parameter names for a symbol from the name index in the - * parameterNameIndicies array. The type of the symbol may have changed - * while reading the method attributes (see the Signature attribute). - * This may be because of generic information or because anonymous - * synthetic parameters were added. The original type (as read from - * the method descriptor) is used to help guess the existence of + * Set the parameters for a method symbol, including any names and + * annotations that were read. + * + *

The type of the symbol may have changed while reading the + * method attributes (see the Signature attribute). This may be + * because of generic information or because anonymous synthetic + * parameters were added. The original type (as read from the + * method descriptor) is used to help guess the existence of * anonymous synthetic parameters. - * On completion, sym.savedParameter names will either be null (if - * no parameter names were found in the class file) or will be set to a - * list of names, one per entry in sym.type.getParameterTypes, with - * any missing names represented by the empty name. */ - void setParameterNames(MethodSymbol sym, Type jvmType) { - // if no names were found in the class file, there's nothing more to do - if (!haveParameterNameIndices) - return; + void setParameters(MethodSymbol sym, Type jvmType) { // If we get parameter names from MethodParameters, then we // don't need to skip. int firstParam = 0; @@ -2483,16 +2518,16 @@ public class ClassReader { // make a corresponding allowance here for the position of // the first parameter. Note that this assumes the // skipped parameter has a width of 1 -- i.e. it is not - // a double width type (long or double.) - if (sym.name == names.init && currentOwner.hasOuterInstance()) { - // Sometimes anonymous classes don't have an outer - // instance, however, there is no reliable way to tell so - // we never strip this$n - if (!currentOwner.name.isEmpty()) - firstParam += 1; - } + // a double width type (long or double.) + if (sym.name == names.init && currentOwner.hasOuterInstance()) { + // Sometimes anonymous classes don't have an outer + // instance, however, there is no reliable way to tell so + // we never strip this$n + if (!currentOwner.name.isEmpty()) + firstParam += 1; + } - if (sym.type != jvmType) { + if (sym.type != jvmType) { // reading the method attributes has caused the // symbol's type to be changed. (i.e. the Signature // attribute.) This may happen if there are hidden @@ -2502,21 +2537,55 @@ public class ClassReader { // at the beginning, and so skip over them. The // primary case for this is two hidden parameters // passed into Enum constructors. - int skip = Code.width(jvmType.getParameterTypes()) - - Code.width(sym.type.getParameterTypes()); - firstParam += skip; - } + int skip = Code.width(jvmType.getParameterTypes()) + - Code.width(sym.type.getParameterTypes()); + firstParam += skip; + } } List paramNames = List.nil(); - int index = firstParam; + ListBuffer params = new ListBuffer<>(); + int nameIndex = firstParam; + int annotationIndex = 0; for (Type t: sym.type.getParameterTypes()) { - int nameIdx = (index < parameterNameIndices.length - ? parameterNameIndices[index] : 0); - Name name = nameIdx == 0 ? names.empty : readName(nameIdx); + Name name = parameterName(nameIndex, paramNames); paramNames = paramNames.prepend(name); - index += sawMethodParameters ? 1 : Code.width(t); + VarSymbol param = new VarSymbol(PARAMETER, name, t, sym); + params.append(param); + if (parameterAnnotations != null) { + ParameterAnnotations annotations = parameterAnnotations[annotationIndex]; + if (annotations != null && annotations.proxies != null + && !annotations.proxies.isEmpty()) { + annotate.normal(new AnnotationCompleter(param, annotations.proxies)); + } + } + nameIndex += sawMethodParameters ? 1 : Code.width(t); + annotationIndex++; + } + if (parameterAnnotations != null && parameterAnnotations.length != annotationIndex) { + throw badClassFile("bad.runtime.invisible.param.annotations", sym); + } + Assert.checkNull(sym.params); + sym.params = params.toList(); + parameterAnnotations = null; + parameterNameIndices = null; + } + + + // Returns the name for the parameter at position 'index', either using + // names read from the MethodParameters, or by synthesizing a name that + // is not on the 'exclude' list. + private Name parameterName(int index, List exclude) { + if (parameterNameIndices != null && index < parameterNameIndices.length + && parameterNameIndices[index] != 0) { + return readName(parameterNameIndices[index]); + } + String prefix = "arg"; + while (true) { + Name argName = names.fromString(prefix + exclude.size()); + if (!exclude.contains(argName)) + return argName; + prefix += "$"; } - sym.savedParameterNames = paramNames.reverse(); } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Profile.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Profile.java index 1dceec9f725..c05c2f6488f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Profile.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Profile.java @@ -40,9 +40,9 @@ import static com.sun.tools.javac.main.Option.PROFILE; * deletion without notice. */ public enum Profile { - COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10), - COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10), - COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10), + COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10, Target.JDK1_11), + COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10, Target.JDK1_11), + COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10, Target.JDK1_11), DEFAULT { @Override diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java index b0413afb743..2c7654df778 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java @@ -64,7 +64,10 @@ public enum Target { JDK1_9("1.9", 53, 0), /** JDK 10. */ - JDK1_10("1.10", 54, 0); + JDK1_10("1.10", 54, 0), + + /** JDK 11. */ + JDK1_11("11", 55, 0); private static final Context.Key targetKey = new Context.Key<>(); @@ -95,6 +98,7 @@ public enum Target { tab.put("8", JDK1_8); tab.put("9", JDK1_9); tab.put("10", JDK1_10); + tab.put("11", JDK1_11); } public final String name; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java index a723d811ed5..c410067db8c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java @@ -712,20 +712,20 @@ public class JavacFiler implements Filer, Closeable { } private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo) throws FilerException { - // TODO: Check if type already exists on source or class path? - // If so, use warning message key proc.type.already.exists checkName(typename, allowUnnamedPackageInfo); - ClassSymbol existing; + ClassSymbol existing = elementUtils.getTypeElement(typename); boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) || aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) || initialClassNames.contains(typename) || - ((existing = elementUtils.getTypeElement(typename)) != null && - initialInputs.contains(existing.sourcefile)); + (existing != null && initialInputs.contains(existing.sourcefile)); if (alreadySeen) { if (lint) log.warning(Warnings.ProcTypeRecreate(typename)); throw new FilerException("Attempt to recreate a file for type " + typename); } + if (lint && existing != null) { + log.warning("proc.type.already.exists", typename); + } if (!mod.isUnnamed() && !typename.contains(".")) { throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java index ecfc372fa6b..df339a0b150 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java @@ -55,7 +55,7 @@ import com.sun.tools.javac.util.StringUtils; * deletion without notice. */ @SupportedAnnotationTypes("*") -@SupportedSourceVersion(SourceVersion.RELEASE_10) +@SupportedSourceVersion(SourceVersion.RELEASE_11) public class PrintingProcessor extends AbstractProcessor { PrintWriter writer; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index a8052159762..d4f3b1f08c7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -443,6 +443,10 @@ compiler.err.invalid.repeatable.annotation.not.applicable.in.context=\ compiler.err.duplicate.class=\ duplicate class: {0} +# 0: name, 1: name +compiler.err.same.binary.name=\ + classes: {0} and {1} have the same binary name + compiler.err.duplicate.case.label=\ duplicate case label @@ -1140,16 +1144,21 @@ compiler.err.type.var.more.than.once=\ compiler.err.type.var.more.than.once.in.result=\ type variable {0} occurs more than once in type of {1}; cannot be left uninstantiated -# 0: type, 1: type, 2: string -compiler.err.types.incompatible.diff.ret=\ - types {0} and {1} are incompatible; both define {2}, but with unrelated return types +# 0: type, 1: type, 2: fragment +compiler.err.types.incompatible=\ + types {0} and {1} are incompatible;\n\ + {2} + +# 0: name, 1: list of type +compiler.misc.incompatible.diff.ret=\ + both define {0}({1}), but with unrelated return types # 0: kind name, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol -compiler.err.types.incompatible.unrelated.defaults=\ +compiler.misc.incompatible.unrelated.defaults=\ {0} {1} inherits unrelated defaults for {2}({3}) from types {4} and {5} # 0: kind name, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol -compiler.err.types.incompatible.abstract.default=\ +compiler.misc.incompatible.abstract.default=\ {0} {1} inherits abstract and default for {2}({3}) from types {4} and {5} # 0: name, 1: kind name, 2: symbol diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/classfile/Classfile.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/classfile/Classfile.java index bdc74fb15dc..48cacb64383 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/classfile/Classfile.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/classfile/Classfile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,8 +46,8 @@ public class Classfile { private final ResolvedJavaType type; private final List codeAttributes; - private static final int MAJOR_VERSION_JAVA7 = 51; - private static final int MAJOR_VERSION_JAVA10 = 54; + private static final int MAJOR_VERSION_JAVA_MIN = 51; + private static final int MAJOR_VERSION_JAVA_MAX = 55; private static final int MAGIC = 0xCAFEBABE; /** @@ -65,7 +65,7 @@ public class Classfile { int minor = stream.readUnsignedShort(); int major = stream.readUnsignedShort(); - if (major < MAJOR_VERSION_JAVA7 || major > MAJOR_VERSION_JAVA10) { + if (major < MAJOR_VERSION_JAVA_MIN || major > MAJOR_VERSION_JAVA_MAX) { throw new UnsupportedClassVersionError("Unsupported class file version: " + major + "." + minor); } diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/LoadProc.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/LoadProc.java index 8f0c761d6cf..9cac709031f 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/LoadProc.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/LoadProc.java @@ -50,7 +50,7 @@ import javax.lang.model.util.Elements; import javax.tools.Diagnostic; -import static javax.lang.model.SourceVersion.RELEASE_10; +import static javax.lang.model.SourceVersion.RELEASE_11; /** * Annotation processor for the Deprecation Scanner tool. @@ -58,7 +58,7 @@ import static javax.lang.model.SourceVersion.RELEASE_10; * */ @SupportedAnnotationTypes("java.lang.Deprecated") -@SupportedSourceVersion(RELEASE_10) +@SupportedSourceVersion(RELEASE_11) public class LoadProc extends AbstractProcessor { Elements elements; Messager messager; diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java index 7dfbb31499a..115075264fd 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java @@ -106,7 +106,7 @@ public class Main implements DiagnosticListener { // Keep these updated manually until there's a compiler API // that allows querying of supported releases. final Set releasesWithoutForRemoval = Set.of("6", "7", "8"); - final Set releasesWithForRemoval = Set.of("9", "10"); + final Set releasesWithForRemoval = Set.of("9", "10", "11"); final Set validReleases; { @@ -358,14 +358,15 @@ public class Main implements DiagnosticListener { * Process classes from a particular JDK release, using only information * in this JDK. * - * @param release "6", "7", "8", "9", or "10" + * @param release "6", "7", "8", "9", "10", or "11" * @param classes collection of classes to process, may be empty * @return success value */ boolean processRelease(String release, Collection classes) throws IOException { options.addAll(List.of("--release", release)); - if (release.equals("9") || release.equals("10")) { + if (release.equals("9") || release.equals("10") || + release.equals("11")) { List rootMods = List.of("java.se", "java.se.ee"); TraverseProc proc = new TraverseProc(rootMods); JavaCompiler.CompilationTask task = @@ -481,7 +482,7 @@ public class Main implements DiagnosticListener { String dir = null; String jar = null; String jdkHome = null; - String release = "10"; + String release = "11"; List loadClasses = new ArrayList<>(); String csvFile = null; diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java index 79a0a1f71f8..8fc94b1b47b 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java @@ -1817,7 +1817,7 @@ public class JShellTool implements MessageHandler { // Documentation pseudo-commands registerCommand(new Command("/", - "help.id", + "help.slashID", arg -> cmdHelp("rerun"), EMPTY_COMPLETION_PROVIDER, CommandKind.HELP_ONLY)); @@ -1829,6 +1829,9 @@ public class JShellTool implements MessageHandler { registerCommand(new Command("intro", "help.intro", CommandKind.HELP_SUBJECT)); + registerCommand(new Command("id", + "help.id", + CommandKind.HELP_SUBJECT)); registerCommand(new Command("shortcuts", "help.shortcuts", CommandKind.HELP_SUBJECT)); diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties index 0d7e517f185..5c405b6e821 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties @@ -46,7 +46,7 @@ jshell.err.file.not.found = File ''{1}'' for ''{0}'' is not found. jshell.err.file.exception = File ''{1}'' for ''{0}'' threw exception: {2} jshell.err.file.filename = ''{0}'' requires a filename argument. -jshell.err.startup.unexpected.exception = Unexpected exception reading start-up: {0} +jshell.err.startup.unexpected.exception = Unexpected exception reading startup: {0} jshell.err.unexpected.exception = Unexpected exception: {0} jshell.err.invalid.command = Invalid command: {0} @@ -104,9 +104,9 @@ For example ''/help /list'' or ''/help intro''.\n\ Subjects:\n\ \n -jshell.err.no.snippet.with.id = No snippet with id: {0} +jshell.err.no.snippet.with.id = No snippet with ID: {0} jshell.err.end.snippet.range.less.than.start = End of snippet range less than start: {0} - {1} -jshell.err.range.requires.id = Snippet ranges require snippet ids: {0} +jshell.err.range.requires.id = Snippet ranges require snippet IDs: {0} jshell.err.exit.not.expression = The argument to /exit must be a valid integer expression, it is not an expression: {0} jshell.err.exit.bad.type = The argument to /exit must be a valid integer expression. The type is {1} : {0} @@ -114,7 +114,7 @@ jshell.err.exit.bad.value = The argument to /exit has bad value is {1} : {0} jshell.err.drop.arg =\ In the /drop argument, please specify an import, variable, method, or class to drop.\n\ -Specify by id or name. Use /list to see ids. Use /reset to reset all state. +Specify by ID or name. Use /list to see IDs. Use /reset to reset all state. jshell.err.failed = Failed. jshell.msg.native.method = Native Method jshell.msg.unknown.source = Unknown Source @@ -193,15 +193,15 @@ For more information see:\n\ /help shortcuts help.usage = \ -Usage: jshell