diff --git a/make/ModuleWrapper.gmk b/make/ModuleWrapper.gmk index e99f34cdd71..51208432ea0 100644 --- a/make/ModuleWrapper.gmk +++ b/make/ModuleWrapper.gmk @@ -51,7 +51,7 @@ ifeq ($(MAKEFILE_PREFIX), Lib) # which static library files to include. The variable $(MODULE)_INCLUDED_LIBS is # added to for each call to SetupJdkLibrary. The file module-included-libs.txt is then # read in StaticLibs.gmk. - ifneq ($($(MODULE)_JDK_LIBS), ) + ifneq ($($(MODULE)_INCLUDED_LIBS), ) LIBLIST := $(SUPPORT_OUTPUTDIR)/modules_static-libs/$(MODULE)/module-included-libs.txt $(LIBLIST): $(TARGETS) diff --git a/make/autoconf/util.m4 b/make/autoconf/util.m4 index 5a6142d5092..aa9662e2100 100644 --- a/make/autoconf/util.m4 +++ b/make/autoconf/util.m4 @@ -575,7 +575,7 @@ AC_DEFUN([UTIL_CHECK_TYPE_directory], if test "[x]ARG_CHECK_FOR_FILES" != "x:"; then for file in ARG_CHECK_FOR_FILES; do - found_files=$($ECHO $(ls $1/$file 2> /dev/null)) + found_files=$($ECHO $($LS -d $1/$file 2> /dev/null)) if test "x$found_files" = x; then FAILURE="Directory $1 does not contain $file" break diff --git a/make/test/BuildMicrobenchmark.gmk b/make/test/BuildMicrobenchmark.gmk index 0a4c2d9a48d..da9ff2029e8 100644 --- a/make/test/BuildMicrobenchmark.gmk +++ b/make/test/BuildMicrobenchmark.gmk @@ -89,6 +89,7 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \ SRC := $(MICROBENCHMARK_SRC), \ BIN := $(MICROBENCHMARK_CLASSES), \ JAVAC_FLAGS := \ + --add-exports java.base/jdk.internal.classfile.components=ALL-UNNAMED \ --add-exports java.base/jdk.internal.classfile.impl=ALL-UNNAMED \ --add-exports java.base/jdk.internal.event=ALL-UNNAMED \ --add-exports java.base/jdk.internal.foreign=ALL-UNNAMED \ diff --git a/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp index 3b0c8ae432c..5cc57976296 100644 --- a/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp @@ -206,8 +206,8 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, Register // Handle existing monitor. bind(object_has_monitor); - // Try to CAS owner (no owner => current thread's _lock_id). - ldr(rscratch2, Address(rthread, JavaThread::lock_id_offset())); + // Try to CAS owner (no owner => current thread's _monitor_owner_id). + ldr(rscratch2, Address(rthread, JavaThread::monitor_owner_id_offset())); add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset())-markWord::monitor_value)); cmpxchg(tmp, zr, rscratch2, Assembler::xword, /*acquire*/ true, /*release*/ true, /*weak*/ false, tmp3Reg); // Sets flags for result @@ -469,8 +469,8 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist // Compute owner address. lea(t2_owner_addr, owner_address); - // Try to CAS owner (no owner => current thread's _lock_id). - ldr(rscratch2, Address(rthread, JavaThread::lock_id_offset())); + // Try to CAS owner (no owner => current thread's _monitor_owner_id). + ldr(rscratch2, Address(rthread, JavaThread::monitor_owner_id_offset())); cmpxchg(t2_owner_addr, zr, rscratch2, Assembler::xword, /*acquire*/ true, /*release*/ false, /*weak*/ false, t3_owner); br(Assembler::EQ, monitor_locked); diff --git a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp index 994521ba48f..511f0f2e96c 100644 --- a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp @@ -2664,10 +2664,10 @@ void MacroAssembler::compiler_fast_lock_object(ConditionRegister flag, Register // Handle existing monitor. bind(object_has_monitor); - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). addi(temp, displaced_header, in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value); Register thread_id = displaced_header; - ld(thread_id, in_bytes(JavaThread::lock_id_offset()), R16_thread); + ld(thread_id, in_bytes(JavaThread::monitor_owner_id_offset()), R16_thread); cmpxchgd(/*flag=*/flag, /*current_value=*/current_header, /*compare_value=*/(intptr_t)0, @@ -2944,9 +2944,9 @@ void MacroAssembler::compiler_fast_lock_lightweight_object(ConditionRegister fla addi(owner_addr, monitor, in_bytes(ObjectMonitor::owner_offset())); } - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). assert_different_registers(thread_id, monitor, owner_addr, box, R0); - ld(thread_id, in_bytes(JavaThread::lock_id_offset()), R16_thread); + ld(thread_id, in_bytes(JavaThread::monitor_owner_id_offset()), R16_thread); cmpxchgd(/*flag=*/CCR0, /*current_value=*/R0, /*compare_value=*/(intptr_t)0, diff --git a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp index 2125f67cf9d..122ea7352fe 100644 --- a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp @@ -116,10 +116,10 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, // Handle existing monitor. bind(object_has_monitor); - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value)); Register tid = tmp4Reg; - ld(tid, Address(xthread, JavaThread::lock_id_offset())); + ld(tid, Address(xthread, JavaThread::monitor_owner_id_offset())); cmpxchg(/*memory address*/tmp, /*expected value*/zr, /*new value*/tid, Assembler::int64, Assembler::aq, Assembler::rl, /*result*/tmp3Reg); // cas succeeds if tmp3Reg == zr(expected) @@ -400,9 +400,9 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, // Compute owner address. la(tmp2_owner_addr, owner_address); - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). Register tid = tmp4; - ld(tid, Address(xthread, JavaThread::lock_id_offset())); + ld(tid, Address(xthread, JavaThread::monitor_owner_id_offset())); cmpxchg(/*addr*/ tmp2_owner_addr, /*expected*/ zr, /*new*/ tid, Assembler::int64, /*acquire*/ Assembler::aq, /*release*/ Assembler::relaxed, /*result*/ tmp3_owner); beqz(tmp3_owner, monitor_locked); diff --git a/src/hotspot/cpu/s390/macroAssembler_s390.cpp b/src/hotspot/cpu/s390/macroAssembler_s390.cpp index c297c66b02b..e8a04e9063b 100644 --- a/src/hotspot/cpu/s390/macroAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/macroAssembler_s390.cpp @@ -3825,11 +3825,11 @@ void MacroAssembler::compiler_fast_lock_object(Register oop, Register box, Regis Register zero = temp; Register monitor_tagged = displacedHeader; // Tagged with markWord::monitor_value. - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). // If csg succeeds then CR=EQ, otherwise, register zero is filled // with the current owner. z_lghi(zero, 0); - z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::lock_id_offset())); + z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::monitor_owner_id_offset())); z_csg(zero, Z_R0_scratch, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), monitor_tagged); // Store a non-null value into the box. @@ -3904,7 +3904,7 @@ void MacroAssembler::compiler_fast_unlock_object(Register oop, Register box, Reg // Handle existing monitor. bind(object_has_monitor); - z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::lock_id_offset())); + z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::monitor_owner_id_offset())); z_cg(Z_R0_scratch, Address(currentHeader, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner))); z_brne(done); @@ -6608,11 +6608,11 @@ void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Registe const Address recursions_address(tmp1_monitor, ObjectMonitor::recursions_offset() - monitor_tag); - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). // If csg succeeds then CR=EQ, otherwise, register zero is filled // with the current owner. z_lghi(zero, 0); - z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::lock_id_offset())); + z_lg(Z_R0_scratch, Address(Z_thread, JavaThread::monitor_owner_id_offset())); z_csg(zero, Z_R0_scratch, owner_address); z_bre(monitor_locked); diff --git a/src/hotspot/cpu/s390/vm_version_s390.cpp b/src/hotspot/cpu/s390/vm_version_s390.cpp index ee3f97f26ef..a5195e753bb 100644 --- a/src/hotspot/cpu/s390/vm_version_s390.cpp +++ b/src/hotspot/cpu/s390/vm_version_s390.cpp @@ -57,7 +57,7 @@ unsigned int VM_Version::_Icache_lineSize = DEFAULT // The following list contains the (approximate) announcement/availability // dates of the many System z generations in existence as of now. -// Information compiled from https://www.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/TD105503 +// Information compiled from https://www.ibm.com/support/pages/ibm-mainframe-life-cycle-history // z900: 2000-10 // z990: 2003-06 // z9: 2005-09 @@ -68,12 +68,13 @@ unsigned int VM_Version::_Icache_lineSize = DEFAULT // z13: 2015-03 // z14: 2017-09 // z15: 2019-09 +// z16: 2022-05 -static const char* z_gen[] = {" ", "G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8", "G9" }; -static const char* z_machine[] = {" ", "2064", "2084", "2094", "2097", "2817", "2827", "2964", "3906", "8561" }; -static const char* z_name[] = {" ", "z900", "z990", "z9 EC", "z10 EC", "z196 EC", "ec12", "z13", "z14", "z15" }; -static const char* z_WDFM[] = {" ", "2006-06-30", "2008-06-30", "2010-06-30", "2012-06-30", "2014-06-30", "2016-12-31", "2019-06-30", "2021-06-30", "tbd" }; -static const char* z_EOS[] = {" ", "2014-12-31", "2014-12-31", "2017-10-31", "2019-12-31", "2021-12-31", "tbd", "tbd", "tbd", "tbd" }; +static const char* z_gen[] = {" ", "G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8", "G9", "G10" }; +static const char* z_machine[] = {" ", "2064", "2084", "2094", "2097", "2817", "2827", "2964", "3906", "8561", "3931" }; +static const char* z_name[] = {" ", "z900", "z990", "z9 EC", "z10 EC", "z196 EC", "ec12", "z13", "z14", "z15", "z16" }; +static const char* z_WDFM[] = {" ", "2006-06-30", "2008-06-30", "2010-06-30", "2012-06-30", "2014-06-30", "2016-12-31", "2019-06-30", "2021-06-30", "2024-12-31", "tbd" }; +static const char* z_EOS[] = {" ", "2014-12-31", "2014-12-31", "2017-10-31", "2019-12-31", "2021-12-31", "2023-12-31", "2024-12-31", "tbd", "tbd", "tbd" }; static const char* z_features[] = {" ", "system-z, g1-z900, ldisp", "system-z, g2-z990, ldisp_fast", @@ -83,7 +84,9 @@ static const char* z_features[] = {" ", "system-z, g6-ec12, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm", "system-z, g7-z13, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr", "system-z, g8-z14, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1", - "system-z, g9-z15, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1, instrext3, venh2" + "system-z, g9-z15, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1, instrext3, venh2", + "system-z, g10-z16, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1, instrext3, venh2," + "bear_enh, sort_enh, nnpa_assist, storage_key_removal, vpack_decimal_enh" }; void VM_Version::initialize() { @@ -337,6 +340,11 @@ int VM_Version::get_model_index() { // is the index of the oldest detected model. int ambiguity = 0; int model_ix = 0; + if (is_z16()) { + model_ix = 10; + ambiguity++; + } + if (is_z15()) { model_ix = 9; ambiguity++; diff --git a/src/hotspot/cpu/s390/vm_version_s390.hpp b/src/hotspot/cpu/s390/vm_version_s390.hpp index 31fdedc59f6..49e6f5686f6 100644 --- a/src/hotspot/cpu/s390/vm_version_s390.hpp +++ b/src/hotspot/cpu/s390/vm_version_s390.hpp @@ -48,8 +48,8 @@ class VM_Version: public Abstract_VM_Version { #define StoreFacilityListExtendedMask 0x0100000000000000UL // z9 #define ETF2Mask 0x0000800000000000UL // z900 #define CryptoFacilityMask 0x0000400000000000UL // z990 (aka message-security assist) -#define LongDispFacilityMask 0x0000200000000000UL // z900 with microcode update -#define LongDispFacilityHighPerfMask 0x0000300000000000UL // z990 +#define LongDispFacilityMask 0x0000200000000000UL // z900 with microcode update, Bit: 18 +#define LongDispFacilityHighPerfMask 0x0000100000000000UL // z990, Bit: 19 #define HFPMultiplyAndAddMask 0x0000080000000000UL // z990 #define ExtImmedFacilityMask 0x0000040000000000UL // z9 #define ETF3Mask 0x0000020000000000UL // z990/z9 (?) @@ -64,7 +64,8 @@ class VM_Version: public Abstract_VM_Version { #define ExecuteExtensionsMask 0x0000000010000000UL // z10 #define FPExtensionsMask 0x0000000004000000UL // z196 #define FPSupportEnhancementsMask 0x0000000000400000UL // z10 -#define DecimalFloatingPointMask 0x0000000000300000UL // z10 +#define DecimalFloatingPointMask 0x0000000000200000UL // z10, Bit: 42 +#define DecimalFloatingPointHighPerfMask 0x0000000000100000UL // z10, Bit: 43 // z196 begin #define DistinctOpndsMask 0x0000000000040000UL // z196 #define FastBCRSerializationMask DistinctOpndsMask @@ -114,6 +115,12 @@ class VM_Version: public Abstract_VM_Version { #define VectorPackedDecimalEnhMask 0x0000008000000000UL // z15 #define CryptoExtension9Mask 0x0000001000000000UL // z15 (aka message-security assist extension 9) #define DeflateMask 0x0000010000000000UL // z15 +#define NNPAssistFacilityMask 0x0000000004000000UL // z16, Neural-network-processing-assist facility, Bit: 165 + +// ---------------------------------------------- +// --- FeatureBitString Bits 193..200 (DW[3]) --- +// ---------------------------------------------- +#define BEAREnhFacilityMask 0x4000000000000000UL // z16, BEAR-enhancement facility, Bit: 193 enum { _max_cache_levels = 8, // As limited by ECAG instruction. @@ -179,9 +186,10 @@ class VM_Version: public Abstract_VM_Version { static bool is_z10() { return has_GnrlInstrExtensions() && !has_DistinctOpnds(); } static bool is_z196() { return has_DistinctOpnds() && !has_MiscInstrExt(); } static bool is_ec12() { return has_MiscInstrExt() && !has_CryptoExt5(); } - static bool is_z13() { return has_CryptoExt5() && !has_MiscInstrExt2();} - static bool is_z14() { return has_MiscInstrExt2() && !has_MiscInstrExt3();} - static bool is_z15() { return has_MiscInstrExt3();} + static bool is_z13() { return has_CryptoExt5() && !has_MiscInstrExt2(); } + static bool is_z14() { return has_MiscInstrExt2() && !has_MiscInstrExt3(); } + static bool is_z15() { return has_MiscInstrExt3() && !has_BEAR_Enh_Facility(); } + static bool is_z16() { return has_BEAR_Enh_Facility(); } // Need to use nested class with unscoped enum. // C++11 declaration "enum class Cipher { ... } is not supported. @@ -455,6 +463,7 @@ class VM_Version: public Abstract_VM_Version { static bool has_FPExtensions() { return (_features[0] & FPExtensionsMask) == FPExtensionsMask; } static bool has_FPSupportEnhancements() { return (_features[0] & FPSupportEnhancementsMask) == FPSupportEnhancementsMask; } static bool has_DecimalFloatingPoint() { return (_features[0] & DecimalFloatingPointMask) == DecimalFloatingPointMask; } + static bool has_DecimalFloatingPointHighPerf() { return (_features[0] & DecimalFloatingPointHighPerfMask) == DecimalFloatingPointHighPerfMask; } static bool has_InterlockedAccessV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; } static bool has_LoadAndALUAtomicV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; } static bool has_PopCount() { return (_features[0] & PopulationCountMask) == PopulationCountMask; } @@ -486,6 +495,9 @@ class VM_Version: public Abstract_VM_Version { static bool has_VectorPackedDecimal() { return (_features[2] & VectorPackedDecimalMask) == VectorPackedDecimalMask; } static bool has_VectorPackedDecimalEnh() { return (_features[2] & VectorPackedDecimalEnhMask) == VectorPackedDecimalEnhMask; } + static bool has_BEAR_Enh_Facility() { return (_features[3] & BEAREnhFacilityMask) == BEAREnhFacilityMask; } + static bool has_NNP_Assist_Facility() { return (_features[2] & NNPAssistFacilityMask) == NNPAssistFacilityMask; } + // Crypto features query functions. static bool has_Crypto_AES_GCM128() { return has_Crypto() && test_feature_bit(&_cipher_features_KMA[0], Cipher::_AES128, Cipher::_featureBits); } static bool has_Crypto_AES_GCM192() { return has_Crypto() && test_feature_bit(&_cipher_features_KMA[0], Cipher::_AES192, Cipher::_featureBits); } @@ -508,6 +520,7 @@ class VM_Version: public Abstract_VM_Version { // CPU feature setters (to force model-specific behaviour). Test/debugging only. static void set_has_DecimalFloatingPoint() { _features[0] |= DecimalFloatingPointMask; } + static void set_has_DecimalFloatingPointHighPerf() { _features[0] |= DecimalFloatingPointHighPerfMask; } static void set_has_FPSupportEnhancements() { _features[0] |= FPSupportEnhancementsMask; } static void set_has_ExecuteExtensions() { _features[0] |= ExecuteExtensionsMask; } static void set_has_MemWithImmALUOps() { _features[0] |= GnrlInstrExtFacilityMask; } @@ -558,6 +571,8 @@ class VM_Version: public Abstract_VM_Version { static void set_has_VectorEnhancements2() { _features[2] |= VectorEnhancements2Mask; } static void set_has_VectorPackedDecimal() { _features[2] |= VectorPackedDecimalMask; } static void set_has_VectorPackedDecimalEnh() { _features[2] |= VectorPackedDecimalEnhMask; } + static void set_has_BEAR_Enh_Facility() { _features[3] |= BEAREnhFacilityMask;} + static void set_has_NNP_Assist_Facility() { _features[2] |= NNPAssistFacilityMask;} static void reset_has_VectorFacility() { _features[2] &= ~VectorFacilityMask; } diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp index 8d0af29e91d..008d52dcb1c 100644 --- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp @@ -319,7 +319,7 @@ void C2_MacroAssembler::fast_lock(Register objReg, Register boxReg, Register tmp movptr(Address(boxReg, 0), checked_cast(markWord::unused_mark().value())); // It's inflated and we use scrReg for ObjectMonitor* in this section. - movptr(boxReg, Address(r15_thread, JavaThread::lock_id_offset())); + movptr(boxReg, Address(r15_thread, JavaThread::monitor_owner_id_offset())); movq(scrReg, tmpReg); xorq(tmpReg, tmpReg); lock(); @@ -625,9 +625,9 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist movptr(Address(box, BasicLock::object_monitor_cache_offset_in_bytes()), monitor); } - // Try to CAS owner (no owner => current thread's _lock_id). + // Try to CAS owner (no owner => current thread's _monitor_owner_id). xorptr(rax_reg, rax_reg); - movptr(box, Address(thread, JavaThread::lock_id_offset())); + movptr(box, Address(thread, JavaThread::monitor_owner_id_offset())); lock(); cmpxchgptr(box, owner_address); jccb(Assembler::equal, monitor_locked); diff --git a/src/hotspot/cpu/x86/x86_64.ad b/src/hotspot/cpu/x86/x86_64.ad index 550c8047034..4667922505c 100644 --- a/src/hotspot/cpu/x86/x86_64.ad +++ b/src/hotspot/cpu/x86/x86_64.ad @@ -4424,21 +4424,21 @@ instruct maxF_reg(legRegF dst, legRegF a, legRegF b, legRegF tmp, legRegF atmp, predicate(UseAVX > 0 && !VLoopReductions::is_reduction(n)); match(Set dst (MaxF a b)); effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp); - format %{ "maxF $dst, $a, $b \t! using tmp, atmp and btmp as TEMP" %} + format %{ "maxF $dst, $a, $b \t! using $tmp, $atmp and $btmp as TEMP" %} ins_encode %{ __ vminmax_fp(Op_MaxV, T_FLOAT, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, Assembler::AVX_128bit); %} ins_pipe( pipe_slow ); %} -instruct maxF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xmmt, rRegI tmp, rFlagsReg cr) %{ +instruct maxF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xtmp, rRegI rtmp, rFlagsReg cr) %{ predicate(UseAVX > 0 && VLoopReductions::is_reduction(n)); match(Set dst (MaxF a b)); - effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr); + effect(USE a, USE b, TEMP xtmp, TEMP rtmp, KILL cr); - format %{ "$dst = max($a, $b)\t# intrinsic (float)" %} + format %{ "maxF_reduction $dst, $a, $b \t!using $xtmp and $rtmp as TEMP" %} ins_encode %{ - emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register, + emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xtmp$$XMMRegister, $rtmp$$Register, false /*min*/, true /*single*/); %} ins_pipe( pipe_slow ); @@ -4449,21 +4449,21 @@ instruct maxD_reg(legRegD dst, legRegD a, legRegD b, legRegD tmp, legRegD atmp, predicate(UseAVX > 0 && !VLoopReductions::is_reduction(n)); match(Set dst (MaxD a b)); effect(USE a, USE b, TEMP atmp, TEMP btmp, TEMP tmp); - format %{ "maxD $dst, $a, $b \t! using tmp, atmp and btmp as TEMP" %} + format %{ "maxD $dst, $a, $b \t! using $tmp, $atmp and $btmp as TEMP" %} ins_encode %{ __ vminmax_fp(Op_MaxV, T_DOUBLE, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, Assembler::AVX_128bit); %} ins_pipe( pipe_slow ); %} -instruct maxD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xmmt, rRegL tmp, rFlagsReg cr) %{ +instruct maxD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xtmp, rRegL rtmp, rFlagsReg cr) %{ predicate(UseAVX > 0 && VLoopReductions::is_reduction(n)); match(Set dst (MaxD a b)); - effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr); + effect(USE a, USE b, TEMP xtmp, TEMP rtmp, KILL cr); - format %{ "$dst = max($a, $b)\t# intrinsic (double)" %} + format %{ "maxD_reduction $dst, $a, $b \t! using $xtmp and $rtmp as TEMP" %} ins_encode %{ - emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register, + emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xtmp$$XMMRegister, $rtmp$$Register, false /*min*/, false /*single*/); %} ins_pipe( pipe_slow ); @@ -4474,21 +4474,21 @@ instruct minF_reg(legRegF dst, legRegF a, legRegF b, legRegF tmp, legRegF atmp, predicate(UseAVX > 0 && !VLoopReductions::is_reduction(n)); match(Set dst (MinF a b)); effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp); - format %{ "minF $dst, $a, $b \t! using tmp, atmp and btmp as TEMP" %} + format %{ "minF $dst, $a, $b \t! using $tmp, $atmp and $btmp as TEMP" %} ins_encode %{ __ vminmax_fp(Op_MinV, T_FLOAT, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, Assembler::AVX_128bit); %} ins_pipe( pipe_slow ); %} -instruct minF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xmmt, rRegI tmp, rFlagsReg cr) %{ +instruct minF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xtmp, rRegI rtmp, rFlagsReg cr) %{ predicate(UseAVX > 0 && VLoopReductions::is_reduction(n)); match(Set dst (MinF a b)); - effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr); + effect(USE a, USE b, TEMP xtmp, TEMP rtmp, KILL cr); - format %{ "$dst = min($a, $b)\t# intrinsic (float)" %} + format %{ "minF_reduction $dst, $a, $b \t! using $xtmp and $rtmp as TEMP" %} ins_encode %{ - emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register, + emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xtmp$$XMMRegister, $rtmp$$Register, true /*min*/, true /*single*/); %} ins_pipe( pipe_slow ); @@ -4499,21 +4499,21 @@ instruct minD_reg(legRegD dst, legRegD a, legRegD b, legRegD tmp, legRegD atmp, predicate(UseAVX > 0 && !VLoopReductions::is_reduction(n)); match(Set dst (MinD a b)); effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp); - format %{ "minD $dst, $a, $b \t! using tmp, atmp and btmp as TEMP" %} + format %{ "minD $dst, $a, $b \t! using $tmp, $atmp and $btmp as TEMP" %} ins_encode %{ __ vminmax_fp(Op_MinV, T_DOUBLE, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, Assembler::AVX_128bit); %} ins_pipe( pipe_slow ); %} -instruct minD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xmmt, rRegL tmp, rFlagsReg cr) %{ +instruct minD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xtmp, rRegL rtmp, rFlagsReg cr) %{ predicate(UseAVX > 0 && VLoopReductions::is_reduction(n)); match(Set dst (MinD a b)); - effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr); + effect(USE a, USE b, TEMP xtmp, TEMP rtmp, KILL cr); - format %{ "$dst = min($a, $b)\t# intrinsic (double)" %} + format %{ "maxD_reduction $dst, $a, $b \t! using $xtmp and $rtmp as TEMP" %} ins_encode %{ - emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register, + emit_fp_min_max(masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xtmp$$XMMRegister, $rtmp$$Register, true /*min*/, false /*single*/); %} ins_pipe( pipe_slow ); diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp index a7b0627c0a4..30956b6c793 100644 --- a/src/hotspot/share/compiler/compileBroker.cpp +++ b/src/hotspot/share/compiler/compileBroker.cpp @@ -1448,7 +1448,7 @@ nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci, // do the compilation if (method->is_native()) { if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) { -#if defined(X86) && !defined(ZERO) +#if defined(IA32) && !defined(ZERO) // The following native methods: // // java.lang.Float.intBitsToFloat @@ -1470,7 +1470,7 @@ nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci, method->intrinsic_id() == vmIntrinsics::_doubleToRawLongBits))) { return nullptr; } -#endif // X86 && !ZERO +#endif // IA32 && !ZERO // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime). diff --git a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp index bde157a34e1..ba47e559957 100644 --- a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp +++ b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp @@ -227,7 +227,7 @@ nonstatic_field(JavaThread, _vthread, OopHandle) \ nonstatic_field(JavaThread, _scopedValueCache, OopHandle) \ nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \ - nonstatic_field(JavaThread, _lock_id, int64_t) \ + nonstatic_field(JavaThread, _monitor_owner_id, int64_t) \ nonstatic_field(JavaThread, _vm_result, oop) \ nonstatic_field(JavaThread, _stack_overflow_state._stack_overflow_limit, address) \ volatile_nonstatic_field(JavaThread, _exception_oop, oop) \ diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp index 39bac0bc14f..1072a5d6a24 100644 --- a/src/hotspot/share/opto/library_call.cpp +++ b/src/hotspot/share/opto/library_call.cpp @@ -3682,10 +3682,10 @@ bool LibraryCallKit::inline_native_setCurrentThread() { const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr(); access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED); - // Change the lock_id of the JavaThread + // Change the _monitor_owner_id of the JavaThread Node* tid = load_field_from_object(arr, "tid", "J"); - Node* thread_id_offset = basic_plus_adr(thread, in_bytes(JavaThread::lock_id_offset())); - Node* tid_memory = store_to_memory(control(), thread_id_offset, tid, T_LONG, MemNode::unordered, true); + Node* monitor_owner_id_offset = basic_plus_adr(thread, in_bytes(JavaThread::monitor_owner_id_offset())); + store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true); JFR_ONLY(extend_setCurrentThread(thread, arr);) return true; diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index b8e7f9c1ea2..6192ff064a9 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -2977,8 +2977,8 @@ JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread, oop threadObj = JNIHandles::resolve(theThread); thread->set_vthread(threadObj); - // Set lock id of new current Thread - thread->set_lock_id(java_lang_Thread::thread_id(threadObj)); + // Set _monitor_owner_id of new current Thread + thread->set_monitor_owner_id(java_lang_Thread::thread_id(threadObj)); JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);) JVM_END diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 8df81ca0f94..11481954e10 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -1775,14 +1775,20 @@ bool Arguments::sun_java_launcher_is_altjvm() { //=========================================================================================================== // Parsing of main arguments -unsigned int addreads_count = 0; -unsigned int addexports_count = 0; -unsigned int addopens_count = 0; -unsigned int patch_mod_count = 0; -unsigned int enable_native_access_count = 0; +static unsigned int addreads_count = 0; +static unsigned int addexports_count = 0; +static unsigned int addopens_count = 0; +static unsigned int patch_mod_count = 0; +static unsigned int enable_native_access_count = 0; +static bool patch_mod_javabase = false; // Check the consistency of vm_init_args bool Arguments::check_vm_args_consistency() { + // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency() + if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) { + return false; + } + // Method for adding checks for flag consistency. // The intent is to warn the user of all possible conflicts, // before returning an error. @@ -1953,8 +1959,6 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args, const JavaVMInitArgs *java_tool_options_args, const JavaVMInitArgs *java_options_args, const JavaVMInitArgs *cmd_line_args) { - bool patch_mod_javabase = false; - // Save default settings for some mode flags Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; Arguments::_UseOnStackReplacement = UseOnStackReplacement; @@ -1968,27 +1972,27 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args, set_mode_flags(_mixed); // Parse args structure generated from java.base vm options resource - jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE); + jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE); if (result != JNI_OK) { return result; } // Parse args structure generated from JAVA_TOOL_OPTIONS environment // variable (if present). - result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR); + result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR); if (result != JNI_OK) { return result; } // Parse args structure generated from the command line flags. - result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE); + result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE); if (result != JNI_OK) { return result; } // Parse args structure generated from the _JAVA_OPTIONS environment // variable (if present) (mimics classic VM) - result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR); + result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR); if (result != JNI_OK) { return result; } @@ -2009,7 +2013,7 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args, SystemMemoryBarrier::initialize(); // Do final processing now that all arguments have been parsed - result = finalize_vm_init_args(patch_mod_javabase); + result = finalize_vm_init_args(); if (result != JNI_OK) { return result; } @@ -2064,7 +2068,7 @@ static bool valid_jdwp_agent(char *name, bool is_path) { } #endif -int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) { +int Arguments::process_patch_mod_option(const char* patch_mod_tail) { // --patch-module==()* assert(patch_mod_tail != nullptr, "Unexpected null patch-module value"); // Find the equal sign between the module name and the path specification @@ -2080,7 +2084,7 @@ int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_ memcpy(module_name, patch_mod_tail, module_len); *(module_name + module_len) = '\0'; // The path piece begins one past the module_equal sign - add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase); + add_patch_mod_prefix(module_name, module_equal + 1); FREE_C_HEAP_ARRAY(char, module_name); if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) { return JNI_ENOMEM; @@ -2146,7 +2150,7 @@ jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* ou return JNI_OK; } -jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) { +jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) { // For match_option to return remaining or value part of option string const char* tail; @@ -2273,7 +2277,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m } } else if (match_option(option, "--patch-module=", &tail)) { // --patch-module==()* - int res = process_patch_mod_option(tail, patch_mod_javabase); + int res = process_patch_mod_option(tail); if (res != JNI_OK) { return res; } @@ -2822,16 +2826,16 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m return JNI_OK; } -void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) { +void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) { // For java.base check for duplicate --patch-module options being specified on the command line. // This check is only required for java.base, all other duplicate module specifications // will be checked during module system initialization. The module system initialization // will throw an ExceptionInInitializerError if this situation occurs. if (strcmp(module_name, JAVA_BASE_NAME) == 0) { - if (*patch_mod_javabase) { + if (patch_mod_javabase) { vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module"); } else { - *patch_mod_javabase = true; + patch_mod_javabase = true; } } @@ -2883,7 +2887,7 @@ void Arguments::fix_appclasspath() { } } -jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { +jint Arguments::finalize_vm_init_args() { // check if the default lib/endorsed directory exists; if so, error char path[JVM_MAXPATHLEN]; const char* fileSep = os::file_separator(); @@ -2957,9 +2961,6 @@ jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { return JNI_ERR; } - if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) { - return JNI_ERR; - } #ifndef CAN_SHOW_REGISTERS_ON_ASSERT UNSUPPORTED_OPTION(ShowRegistersOnAssert); diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index cac0296b327..f18e44bbb55 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -290,7 +290,7 @@ class Arguments : AllStatic { static bool create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal); static bool create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count); - static int process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase); + static int process_patch_mod_option(const char* patch_mod_tail); // Aggressive optimization flags. static jint set_aggressive_opts_flags(); @@ -325,8 +325,8 @@ class Arguments : AllStatic { const JavaVMInitArgs *java_tool_options_args, const JavaVMInitArgs *java_options_args, const JavaVMInitArgs *cmd_line_args); - static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin); - static jint finalize_vm_init_args(bool patch_mod_javabase); + static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin); + static jint finalize_vm_init_args(); static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type); static bool is_bad_option(const JavaVMOption* option, jboolean ignore) { @@ -474,7 +474,7 @@ class Arguments : AllStatic { static void set_ext_dirs(char *value) { _ext_dirs = os::strdup_check_oom(value); } // Set up the underlying pieces of the boot class path - static void add_patch_mod_prefix(const char *module_name, const char *path, bool* patch_mod_javabase); + static void add_patch_mod_prefix(const char *module_name, const char *path); static void set_boot_class_path(const char *value, bool has_jimage) { // During start up, set by os::set_boot_path() assert(get_boot_class_path() == nullptr, "Boot class path previously set"); diff --git a/src/hotspot/share/runtime/continuationFreezeThaw.cpp b/src/hotspot/share/runtime/continuationFreezeThaw.cpp index 18beb10f0b4..a6c8e64e55e 100644 --- a/src/hotspot/share/runtime/continuationFreezeThaw.cpp +++ b/src/hotspot/share/runtime/continuationFreezeThaw.cpp @@ -256,7 +256,9 @@ class Config { using OopT = std::conditional_t; static freeze_result freeze(JavaThread* thread, intptr_t* const sp) { - return freeze_internal(thread, sp); + freeze_result res = freeze_internal(thread, sp); + JFR_ONLY(assert((res == freeze_ok) || (res == thread->last_freeze_fail_result()), "freeze failure not set")); + return res; } static freeze_result freeze_preempt(JavaThread* thread, intptr_t* const sp) { @@ -1722,6 +1724,9 @@ static inline freeze_result freeze_internal(JavaThread* current, intptr_t* const log_develop_debug(continuations)("PINNED due to critical section/hold monitor"); verify_continuation(cont.continuation()); freeze_result res = entry->is_pinned() ? freeze_pinned_cs : freeze_pinned_monitor; + if (!preempt) { + JFR_ONLY(current->set_last_freeze_fail_result(res);) + } log_develop_trace(continuations)("=== end of freeze (fail %d)", res); // Avoid Thread.yield() loops without safepoint polls. if (SafepointMechanism::should_process(current) && !preempt) { diff --git a/src/hotspot/share/runtime/javaThread.cpp b/src/hotspot/share/runtime/javaThread.cpp index fd9f75c41b4..7f332638ee0 100644 --- a/src/hotspot/share/runtime/javaThread.cpp +++ b/src/hotspot/share/runtime/javaThread.cpp @@ -236,8 +236,8 @@ void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name // constructor calls Thread.current(), which must be set here. java_lang_Thread::set_thread(thread_oop(), this); set_threadOopHandles(thread_oop()); - // Set the lock_id to the next thread_id temporarily while initialization runs. - set_lock_id(ThreadIdentifier::next()); + // Set the _monitor_owner_id to the next thread_id temporarily while initialization runs. + set_monitor_owner_id(ThreadIdentifier::next()); JavaValue result(T_VOID); if (thread_name != nullptr) { @@ -263,8 +263,8 @@ void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name Handle(), CHECK); } - // Update the lock_id with the tid value. - set_lock_id(java_lang_Thread::thread_id(thread_oop())); + // Update the _monitor_owner_id with the tid value. + set_monitor_owner_id(java_lang_Thread::thread_id(thread_oop())); os::set_priority(this, NormPriority); @@ -435,7 +435,7 @@ JavaThread::JavaThread(MemTag mem_tag) : _current_waiting_monitor(nullptr), _active_handles(nullptr), _free_handle_block(nullptr), - _lock_id(0), + _monitor_owner_id(0), _suspend_flags(0), @@ -518,6 +518,10 @@ JavaThread::JavaThread(MemTag mem_tag) : _SleepEvent(ParkEvent::Allocate(this)), +#if INCLUDE_JFR + _last_freeze_fail_result(freeze_ok), +#endif + _lock_stack(this), _om_cache(this) { set_jni_functions(jni_functions()); @@ -1540,8 +1544,7 @@ void JavaThread::print_on(outputStream *st, bool print_extended_info) const { st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12)); if (thread_oop != nullptr) { if (is_vthread_mounted()) { - // _lock_id is the thread ID of the mounted virtual thread - st->print_cr(" Carrying virtual thread #" INT64_FORMAT, lock_id()); + st->print_cr(" Carrying virtual thread #" INT64_FORMAT, java_lang_Thread::thread_id(vthread())); } else { st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop)); } @@ -1725,7 +1728,7 @@ void JavaThread::prepare(jobject jni_thread, ThreadPriority prio) { assert(InstanceKlass::cast(thread_oop->klass())->is_linked(), "must be initialized"); set_threadOopHandles(thread_oop()); - set_lock_id(java_lang_Thread::thread_id(thread_oop())); + set_monitor_owner_id(java_lang_Thread::thread_id(thread_oop())); if (prio == NoPriority) { prio = java_lang_Thread::priority(thread_oop()); @@ -2230,7 +2233,7 @@ void JavaThread::start_internal_daemon(JavaThread* current, JavaThread* target, // Now bind the thread_oop to the target JavaThread. target->set_threadOopHandles(thread_oop()); - target->set_lock_id(java_lang_Thread::thread_id(thread_oop())); + target->set_monitor_owner_id(java_lang_Thread::thread_id(thread_oop())); Threads::add(target); // target is now visible for safepoint/handshake // Publish the JavaThread* in java.lang.Thread after the JavaThread* is @@ -2361,4 +2364,4 @@ void JavaThread::post_vthread_pinned_event(EventVirtualThreadPinned* event, cons event->commit(); } } -#endif \ No newline at end of file +#endif diff --git a/src/hotspot/share/runtime/javaThread.hpp b/src/hotspot/share/runtime/javaThread.hpp index e24138583b8..9a74a6248d0 100644 --- a/src/hotspot/share/runtime/javaThread.hpp +++ b/src/hotspot/share/runtime/javaThread.hpp @@ -166,14 +166,14 @@ class JavaThread: public Thread { // ID used as owner for inflated monitors. Same as the j.l.Thread.tid of the // current _vthread object, except during creation of the primordial and JNI // attached thread cases where this field can have a temporary value. - int64_t _lock_id; + int64_t _monitor_owner_id; public: - void set_lock_id(int64_t tid) { - assert(tid >= ThreadIdentifier::initial() && tid < ThreadIdentifier::current(), "invalid tid"); - _lock_id = tid; + void set_monitor_owner_id(int64_t id) { + assert(id >= ThreadIdentifier::initial() && id < ThreadIdentifier::current(), ""); + _monitor_owner_id = id; } - int64_t lock_id() const { return _lock_id; } + int64_t monitor_owner_id() const { return _monitor_owner_id; } // For tracking the heavyweight monitor the thread is pending on. ObjectMonitor* current_pending_monitor() { @@ -884,7 +884,7 @@ class JavaThread: public Thread { static ByteSize doing_unsafe_access_offset() { return byte_offset_of(JavaThread, _doing_unsafe_access); } NOT_PRODUCT(static ByteSize requires_cross_modify_fence_offset() { return byte_offset_of(JavaThread, _requires_cross_modify_fence); }) - static ByteSize lock_id_offset() { return byte_offset_of(JavaThread, _lock_id); } + static ByteSize monitor_owner_id_offset() { return byte_offset_of(JavaThread, _monitor_owner_id); } static ByteSize cont_entry_offset() { return byte_offset_of(JavaThread, _cont_entry); } static ByteSize cont_fastpath_offset() { return byte_offset_of(JavaThread, _cont_fastpath); } diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp index 82473489f68..c95fb5d5f0c 100644 --- a/src/hotspot/share/runtime/objectMonitor.cpp +++ b/src/hotspot/share/runtime/objectMonitor.cpp @@ -124,7 +124,7 @@ ParkEvent* ObjectMonitor::_vthread_unparker_ParkEvent = nullptr; // // * A thread acquires ownership of a monitor by successfully // CAS()ing the _owner field from NO_OWNER/DEFLATER_MARKER to -// its tid (return value from owner_from()). +// its owner_id (return value from owner_id_from()). // // * Invariant: A thread appears on at most one monitor list -- // cxq, EntryList or WaitSet -- at any one time. @@ -331,7 +331,7 @@ bool ObjectMonitor::TryLockWithContentionMark(JavaThread* locking_thread, Object if (prev_owner == NO_OWNER) { assert(_recursions == 0, "invariant"); success = true; - } else if (prev_owner == owner_from(locking_thread)) { + } else if (prev_owner == owner_id_from(locking_thread)) { _recursions++; success = true; } else if (prev_owner == DEFLATER_MARKER) { @@ -1548,7 +1548,7 @@ void ObjectMonitor::ExitEpilog(JavaThread* current, ObjectWaiter* Wakee) { } // Exits the monitor returning recursion count. _owner should -// be set to current's tid, i.e. no ANONYMOUS_OWNER allowed. +// be set to current's owner_id, i.e. no ANONYMOUS_OWNER allowed. intx ObjectMonitor::complete_exit(JavaThread* current) { assert(InitDone, "Unexpectedly not initialized"); guarantee(has_owner(current), "complete_exit not owner"); @@ -1580,7 +1580,7 @@ intx ObjectMonitor::complete_exit(JavaThread* current) { bool ObjectMonitor::check_owner(TRAPS) { JavaThread* current = THREAD; int64_t cur = owner_raw(); - if (cur == owner_from(current)) { + if (cur == owner_id_from(current)) { return true; } THROW_MSG_(vmSymbols::java_lang_IllegalMonitorStateException(), diff --git a/src/hotspot/share/runtime/objectMonitor.hpp b/src/hotspot/share/runtime/objectMonitor.hpp index c205eedf684..cf364cc012d 100644 --- a/src/hotspot/share/runtime/objectMonitor.hpp +++ b/src/hotspot/share/runtime/objectMonitor.hpp @@ -170,7 +170,7 @@ class ObjectMonitor : public CHeapObj { static const int64_t ANONYMOUS_OWNER = 1; static const int64_t DEFLATER_MARKER = 2; - int64_t volatile _owner; // Either tid of owner, NO_OWNER, ANONYMOUS_OWNER or DEFLATER_MARKER. + int64_t volatile _owner; // Either owner_id of owner, NO_OWNER, ANONYMOUS_OWNER or DEFLATER_MARKER. volatile uint64_t _previous_owner_tid; // thread id of the previous owner of the monitor // Separate _owner and _next_om on different cache lines since // both can have busy multi-threaded access. _previous_owner_tid is only @@ -284,25 +284,25 @@ class ObjectMonitor : public CHeapObj { int64_t owner_raw() const; // These methods return the value we set in _owner when acquiring - // the monitor with the given thread/vthread (tid). - static int64_t owner_from(JavaThread* thread); - static int64_t owner_from(oop vthread); + // the monitor with the given thread/vthread, AKA owner_id. + static int64_t owner_id_from(JavaThread* thread); + static int64_t owner_id_from(oop vthread); // Returns true if owner field == DEFLATER_MARKER and false otherwise. bool owner_is_DEFLATER_MARKER() const; // Returns true if 'this' is being async deflated and false otherwise. bool is_being_async_deflated(); - // Clear _owner field; current value must match thread's tid. + // Clear _owner field; current value must match thread's owner_id. void release_clear_owner(JavaThread* thread); // Simply set _owner field to new_value; current value must match old_value. void set_owner_from_raw(int64_t old_value, int64_t new_value); - // Same as above but uses tid of current as new value. + // Same as above but uses owner_id of current as new value. void set_owner_from(int64_t old_value, JavaThread* current); // Try to set _owner field to new_value if the current value matches // old_value, using Atomic::cmpxchg(). Otherwise, does not change the // _owner field. Returns the prior value of the _owner field. int64_t try_set_owner_from_raw(int64_t old_value, int64_t new_value); - // Same as above but uses tid of current as new_value. + // Same as above but uses owner_id of current as new_value. int64_t try_set_owner_from(int64_t old_value, JavaThread* current); // Methods to check and set _succ. The successor is the thread selected @@ -316,11 +316,11 @@ class ObjectMonitor : public CHeapObj { void clear_successor(); int64_t successor() const; - // Returns true if _owner field == tid of thread, false otherwise. - bool has_owner(JavaThread* thread) const { return owner() == owner_from(thread); } - // Set _owner field to tid of thread; current value must be NO_OWNER. + // Returns true if _owner field == owner_id of thread, false otherwise. + bool has_owner(JavaThread* thread) const { return owner() == owner_id_from(thread); } + // Set _owner field to owner_id of thread; current value must be NO_OWNER. void set_owner(JavaThread* thread) { set_owner_from(NO_OWNER, thread); } - // Try to set _owner field from NO_OWNER to tid of thread. + // Try to set _owner field from NO_OWNER to owner_id of thread. bool try_set_owner(JavaThread* thread) { return try_set_owner_from(NO_OWNER, thread) == NO_OWNER; } diff --git a/src/hotspot/share/runtime/objectMonitor.inline.hpp b/src/hotspot/share/runtime/objectMonitor.inline.hpp index 64e233a1ff5..ed34af8dca3 100644 --- a/src/hotspot/share/runtime/objectMonitor.inline.hpp +++ b/src/hotspot/share/runtime/objectMonitor.inline.hpp @@ -39,16 +39,16 @@ #include "utilities/checkedCast.hpp" #include "utilities/globalDefinitions.hpp" -inline int64_t ObjectMonitor::owner_from(JavaThread* thread) { - int64_t tid = thread->lock_id(); - assert(tid >= ThreadIdentifier::initial() && tid < ThreadIdentifier::current(), "must be reasonable"); - return tid; +inline int64_t ObjectMonitor::owner_id_from(JavaThread* thread) { + int64_t id = thread->monitor_owner_id(); + assert(id >= ThreadIdentifier::initial() && id < ThreadIdentifier::current(), "must be reasonable"); + return id; } -inline int64_t ObjectMonitor::owner_from(oop vthread) { - int64_t tid = java_lang_Thread::thread_id(vthread); - assert(tid >= ThreadIdentifier::initial() && tid < ThreadIdentifier::current(), "must be reasonable"); - return tid; +inline int64_t ObjectMonitor::owner_id_from(oop vthread) { + int64_t id = java_lang_Thread::thread_id(vthread); + assert(id >= ThreadIdentifier::initial() && id < ThreadIdentifier::current(), "must be reasonable"); + return id; } inline bool ObjectMonitor::is_entered(JavaThread* current) const { @@ -153,7 +153,7 @@ inline void ObjectMonitor::set_recursions(size_t recursions) { // Clear _owner field; current value must match old_value. inline void ObjectMonitor::release_clear_owner(JavaThread* old_owner) { - int64_t old_value = owner_from(old_owner); + int64_t old_value = owner_id_from(old_owner); #ifdef ASSERT int64_t prev = Atomic::load(&_owner); assert(prev == old_value, "unexpected prev owner=" INT64_FORMAT @@ -182,7 +182,7 @@ inline void ObjectMonitor::set_owner_from_raw(int64_t old_value, int64_t new_val } inline void ObjectMonitor::set_owner_from(int64_t old_value, JavaThread* current) { - set_owner_from_raw(old_value, owner_from(current)); + set_owner_from_raw(old_value, owner_id_from(current)); } // Try to set _owner field to new_value if the current value matches @@ -201,7 +201,7 @@ inline int64_t ObjectMonitor::try_set_owner_from_raw(int64_t old_value, int64_t } inline int64_t ObjectMonitor::try_set_owner_from(int64_t old_value, JavaThread* current) { - return try_set_owner_from_raw(old_value, owner_from(current)); + return try_set_owner_from_raw(old_value, owner_id_from(current)); } inline bool ObjectMonitor::has_successor() const { @@ -209,11 +209,11 @@ inline bool ObjectMonitor::has_successor() const { } inline bool ObjectMonitor::has_successor(JavaThread* thread) const { - return owner_from(thread) == Atomic::load(&_succ); + return owner_id_from(thread) == Atomic::load(&_succ); } inline void ObjectMonitor::set_successor(JavaThread* thread) { - Atomic::store(&_succ, owner_from(thread)); + Atomic::store(&_succ, owner_id_from(thread)); } inline void ObjectMonitor::set_successor(oop vthread) { diff --git a/src/hotspot/share/runtime/synchronizer.cpp b/src/hotspot/share/runtime/synchronizer.cpp index cba1918529c..941309ca2ac 100644 --- a/src/hotspot/share/runtime/synchronizer.cpp +++ b/src/hotspot/share/runtime/synchronizer.cpp @@ -1243,13 +1243,13 @@ void ObjectSynchronizer::owned_monitors_iterate_filtered(MonitorClosure* closure // Iterate ObjectMonitors where the owner == thread; this does NOT include // ObjectMonitors where owner is set to a stack-lock address in thread. void ObjectSynchronizer::owned_monitors_iterate(MonitorClosure* closure, JavaThread* thread) { - int64_t key = ObjectMonitor::owner_from(thread); + int64_t key = ObjectMonitor::owner_id_from(thread); auto thread_filter = [&](ObjectMonitor* monitor) { return monitor->owner() == key; }; return owned_monitors_iterate_filtered(closure, thread_filter); } void ObjectSynchronizer::owned_monitors_iterate(MonitorClosure* closure, oop vthread) { - int64_t key = ObjectMonitor::owner_from(vthread); + int64_t key = ObjectMonitor::owner_id_from(vthread); auto thread_filter = [&](ObjectMonitor* monitor) { return monitor->owner() == key; }; return owned_monitors_iterate_filtered(closure, thread_filter); } diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index f6b7b7956e2..7b39161090d 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -171,7 +171,7 @@ static void create_initial_thread(Handle thread_group, JavaThread* thread, DEBUG_ONLY(int64_t main_thread_tid = java_lang_Thread::thread_id(thread_oop());) assert(main_thread_tid == ThreadIdentifier::initial(), ""); - assert(main_thread_tid == thread->lock_id(), ""); + assert(main_thread_tid == thread->monitor_owner_id(), ""); JFR_ONLY(assert(JFR_JVM_THREAD_ID(thread) == static_cast(main_thread_tid), "initial tid mismatch");) // Set thread status to running since main thread has @@ -548,9 +548,9 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { main_thread->set_active_handles(JNIHandleBlock::allocate_block()); MACOS_AARCH64_ONLY(main_thread->init_wx()); - // Set the lock_id now since we will run Java code before the Thread instance + // Set the _monitor_owner_id now since we will run Java code before the Thread instance // is even created. The same value will be assigned to the Thread instance on init. - main_thread->set_lock_id(ThreadIdentifier::next()); + main_thread->set_monitor_owner_id(ThreadIdentifier::next()); if (!Thread::set_as_starting_thread(main_thread)) { vm_shutdown_during_initialization( @@ -1360,8 +1360,7 @@ void Threads::print_on(outputStream* st, bool print_stacks, } else { p->print_stack_on(st); if (p->is_vthread_mounted()) { - // _lock_id is the thread ID of the mounted virtual thread - st->print_cr(" Mounted virtual thread #" INT64_FORMAT, p->lock_id()); + st->print_cr(" Mounted virtual thread #" INT64_FORMAT, java_lang_Thread::thread_id(p->vthread())); p->print_vthread_stack_on(st); } } diff --git a/src/hotspot/share/runtime/vmOperations.cpp b/src/hotspot/share/runtime/vmOperations.cpp index 1f5d63a917e..a3f632ca496 100644 --- a/src/hotspot/share/runtime/vmOperations.cpp +++ b/src/hotspot/share/runtime/vmOperations.cpp @@ -368,7 +368,7 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView { // Implements the ObjectMonitorsView interface void visit(MonitorClosure* closure, JavaThread* thread) override { - int64_t key = ObjectMonitor::owner_from(thread); + int64_t key = ObjectMonitor::owner_id_from(thread); ObjectMonitorLinkedList* list = get_list(key); LinkedListIterator iter(list != nullptr ? list->head() : nullptr); while (!iter.is_empty()) { diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp index 6fa57acf3ce..eaf259cedba 100644 --- a/src/hotspot/share/runtime/vmStructs.cpp +++ b/src/hotspot/share/runtime/vmStructs.cpp @@ -664,7 +664,7 @@ nonstatic_field(JavaThread, _vframe_array_head, vframeArray*) \ nonstatic_field(JavaThread, _vframe_array_last, vframeArray*) \ nonstatic_field(JavaThread, _active_handles, JNIHandleBlock*) \ - nonstatic_field(JavaThread, _lock_id, int64_t) \ + nonstatic_field(JavaThread, _monitor_owner_id, int64_t) \ volatile_nonstatic_field(JavaThread, _terminated, JavaThread::TerminatedTypes) \ nonstatic_field(Thread, _osthread, OSThread*) \ nonstatic_field(Thread, _resource_area, ResourceArea*) \ diff --git a/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java b/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java index 38be8628fb4..17bc60ef863 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java +++ b/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, 2022, Red Hat Inc. + * Copyright (c) 2024, 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 @@ -28,8 +29,8 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.math.BigInteger; +import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -61,13 +62,13 @@ public interface CgroupSubsystemController { public static String getStringValue(CgroupSubsystemController controller, String param) { if (controller == null) return null; - try { - return CgroupUtil.readStringValue(controller, param); - } - catch (IOException e) { + Path filePath = Path.of(controller.path(), param); + try (Stream lines = Files.lines(filePath)) { + Optional firstLine = lines.findFirst(); + return firstLine.orElse(null); + } catch (UncheckedIOException | IOException e) { return null; } - } /** @@ -92,8 +93,8 @@ public static long getLongValueMatchingLine(CgroupSubsystemController controller return retval; } try { - Path filePath = Paths.get(controller.path(), param); - List lines = CgroupUtil.readAllLinesPrivileged(filePath); + Path filePath = Path.of(controller.path(), param); + List lines = Files.readAllLines(filePath); for (String line : lines) { if (line.startsWith(match)) { retval = conversion.apply(line); @@ -161,7 +162,7 @@ public static double getDoubleValue(CgroupSubsystemController controller, String public static long getLongEntry(CgroupSubsystemController controller, String param, String entryname, long defaultRetval) { if (controller == null) return defaultRetval; - try (Stream lines = CgroupUtil.readFilePrivileged(Paths.get(controller.path(), param))) { + try (Stream lines = Files.lines(Path.of(controller.path(), param))) { Optional result = lines.map(line -> line.split(" ")) .filter(line -> (line.length == 2 && diff --git a/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java b/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java index 0a6d9958d11..d963c46f079 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java +++ b/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, 2022, Red Hat Inc. + * Copyright (c) 2024, 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 @@ -29,8 +30,8 @@ import java.io.UncheckedIOException; import java.lang.System.Logger; import java.lang.System.Logger.Level; +import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -140,7 +141,7 @@ public static Optional determineType(String mountInfo, String cgroups, String selfCgroup) throws IOException { final Map infos = new HashMap<>(); - List lines = CgroupUtil.readAllLinesPrivileged(Paths.get(cgroups)); + List lines = Files.readAllLines(Path.of(cgroups)); for (String line : lines) { if (line.startsWith("#")) { continue; @@ -180,7 +181,7 @@ public static Optional determineType(String mountInfo, // However, continuing in that case does not make sense as we'd need // information from mountinfo for the mounted controller paths which we wouldn't // find anyway in that case. - lines = CgroupUtil.readAllLinesPrivileged(Paths.get(mountInfo)); + lines = Files.readAllLines(Path.of(mountInfo)); boolean anyCgroupMounted = false; for (String line: lines) { boolean cgroupsControllerFound = amendCgroupInfos(line, infos, isCgroupsV2); @@ -196,8 +197,7 @@ public static Optional determineType(String mountInfo, // See: // setCgroupV1Path() for the action run for cgroups v1 systems // setCgroupV2Path() for the action run for cgroups v2 systems - try (Stream selfCgroupLines = - CgroupUtil.readFilePrivileged(Paths.get(selfCgroup))) { + try (Stream selfCgroupLines = Files.lines(Path.of(selfCgroup))) { Consumer action = (tokens -> setCgroupV1Path(infos, tokens)); if (isCgroupsV2) { action = (tokens -> setCgroupV2Path(infos, tokens)); @@ -311,7 +311,7 @@ private static boolean amendCgroupInfos(String mntInfoLine, String mountPath = lineMatcher.group(2); String fsType = lineMatcher.group(3); if (fsType.equals("cgroup")) { - Path p = Paths.get(mountPath); + Path p = Path.of(mountPath); String[] controllerNames = p.getFileName().toString().split(","); for (String controllerName: controllerNames) { switch (controllerName) { diff --git a/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java b/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java deleted file mode 100644 index dbe8a85b2b2..00000000000 --- a/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2020, Red Hat Inc. - * 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 jdk.internal.platform; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.List; -import java.util.stream.Stream; - -public final class CgroupUtil { - - @SuppressWarnings("removal") - public static Stream readFilePrivileged(Path path) throws IOException { - try { - PrivilegedExceptionAction> pea = () -> Files.lines(path); - return AccessController.doPrivileged(pea); - } catch (PrivilegedActionException e) { - unwrapIOExceptionAndRethrow(e); - throw new InternalError(e.getCause()); - } catch (UncheckedIOException e) { - throw e.getCause(); - } - } - - static void unwrapIOExceptionAndRethrow(PrivilegedActionException pae) throws IOException { - Throwable x = pae.getCause(); - if (x instanceof IOException) - throw (IOException) x; - if (x instanceof RuntimeException) - throw (RuntimeException) x; - if (x instanceof Error) - throw (Error) x; - } - - static String readStringValue(CgroupSubsystemController controller, String param) throws IOException { - PrivilegedExceptionAction pea = () -> - Files.newBufferedReader(Paths.get(controller.path(), param)); - try (@SuppressWarnings("removal") BufferedReader bufferedReader = - AccessController.doPrivileged(pea)) { - String line = bufferedReader.readLine(); - return line; - } catch (PrivilegedActionException e) { - unwrapIOExceptionAndRethrow(e); - throw new InternalError(e.getCause()); - } catch (UncheckedIOException e) { - throw e.getCause(); - } - } - - @SuppressWarnings("removal") - public static List readAllLinesPrivileged(Path path) throws IOException { - try { - PrivilegedExceptionAction> pea = () -> Files.readAllLines(path); - return AccessController.doPrivileged(pea); - } catch (PrivilegedActionException e) { - unwrapIOExceptionAndRethrow(e); - throw new InternalError(e.getCause()); - } catch (UncheckedIOException e) { - throw e.getCause(); - } - } -} diff --git a/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java b/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java index ddb4d8e2718..aa618766b38 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java +++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, 2022, Red Hat Inc. + * Copyright (c) 2024, 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 @@ -27,15 +28,16 @@ import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.file.Paths; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import jdk.internal.platform.CgroupInfo; import jdk.internal.platform.CgroupSubsystem; import jdk.internal.platform.CgroupSubsystemController; -import jdk.internal.platform.CgroupUtil; public class CgroupV2Subsystem implements CgroupSubsystem { @@ -328,10 +330,9 @@ public long getBlkIOServiced() { } private long sumTokensIOStat(Function mapFunc) { - try { - return CgroupUtil.readFilePrivileged(Paths.get(unified.path(), "io.stat")) - .map(mapFunc) - .collect(Collectors.summingLong(e -> e)); + try (Stream lines = Files.lines(Path.of(unified.path(), "io.stat"))) { + return lines.map(mapFunc) + .collect(Collectors.summingLong(e -> e)); } catch (UncheckedIOException | IOException e) { return CgroupSubsystem.LONG_RETVAL_UNLIMITED; } diff --git a/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM.java b/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM.java index 40bbc6c56cc..9808a013303 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM.java @@ -71,249 +71,6 @@ public final class ML_KEM { -1599, -709, -789, -1317, -57, 1049, -584 }; - private static final short[] MONT_ZETAS_FOR_VECTOR_NTT_ARR = new short[]{ - // level 0 - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - -758, -758, -758, -758, -758, -758, -758, -758, - // level 1 - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -359, -359, -359, -359, -359, -359, -359, -359, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517, - // level 2 - 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, - 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, - 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, - 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, - 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422, - 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422, - 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422, - 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422, - 287, 287, 287, 287, 287, 287, 287, 287, - 287, 287, 287, 287, 287, 287, 287, 287, - 287, 287, 287, 287, 287, 287, 287, 287, - 287, 287, 287, 287, 287, 287, 287, 287, - 202, 202, 202, 202, 202, 202, 202, 202, - 202, 202, 202, 202, 202, 202, 202, 202, - 202, 202, 202, 202, 202, 202, 202, 202, - 202, 202, 202, 202, 202, 202, 202, 202, - // level 3 - -171, -171, -171, -171, -171, -171, -171, -171, - -171, -171, -171, -171, -171, -171, -171, -171, - 622, 622, 622, 622, 622, 622, 622, 622, - 622, 622, 622, 622, 622, 622, 622, 622, - 1577, 1577, 1577, 1577, 1577, 1577, 1577, 1577, - 1577, 1577, 1577, 1577, 1577, 1577, 1577, 1577, - 182, 182, 182, 182, 182, 182, 182, 182, - 182, 182, 182, 182, 182, 182, 182, 182, - 962, 962, 962, 962, 962, 962, 962, 962, - 962, 962, 962, 962, 962, 962, 962, 962, - -1202, -1202, -1202, -1202, -1202, -1202, -1202, -1202, - -1202, -1202, -1202, -1202, -1202, -1202, -1202, -1202, - -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, - -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, - 1468, 1468, 1468, 1468, 1468, 1468, 1468, 1468, - 1468, 1468, 1468, 1468, 1468, 1468, 1468, 1468, - // level 4 - 573, 573, 573, 573, 573, 573, 573, 573, - -1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, - 264, 264, 264, 264, 264, 264, 264, 264, - 383, 383, 383, 383, 383, 383, 383, 383, - -829, -829, -829, -829, -829, -829, -829, -829, - 1458, 1458, 1458, 1458, 1458, 1458, 1458, 1458, - -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, - -130, -130, -130, -130, -130, -130, -130, -130, - -681, -681, -681, -681, -681, -681, -681, -681, - 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, - 732, 732, 732, 732, 732, 732, 732, 732, - 608, 608, 608, 608, 608, 608, 608, 608, - -1542, -1542, -1542, -1542, -1542, -1542, -1542, -1542, - 411, 411, 411, 411, 411, 411, 411, 411, - -205, -205, -205, -205, -205, -205, -205, -205, - -1571, -1571, -1571, -1571, -1571, -1571, -1571, -1571, - // level 5 - 1223, 1223, 1223, 1223, 652, 652, 652, 652, - -552, -552, -552, -552, 1015, 1015, 1015, 1015, - -1293, -1293, -1293, -1293, 1491, 1491, 1491, 1491, - -282, -282, -282, -282, -1544, -1544, -1544, -1544, - 516, 516, 516, 516, -8, -8, -8, -8, - -320, -320, -320, -320, -666, -666, -666, -666, - 1711, 1711, 1711, 1711, -1162, -1162, -1162, -1162, - 126, 126, 126, 126, 1469, 1469, 1469, 1469, - -853, -853, -853, -853, -90, -90, -90, -90, - -271, -271, -271, -271, 830, 830, 830, 830, - 107, 107, 107, 107, -1421, -1421, -1421, -1421, - -247, -247, -247, -247, -951, -951, -951, -951, - -398, -398, -398, -398, 961, 961, 961, 961, - -1508, -1508, -1508, -1508, -725, -725, -725, -725, - 448, 448, 448, 448, -1065, -1065, -1065, -1065, - 677, 677, 677, 677, -1275, -1275, -1275, -1275, - // level 6 - -1103, -1103, 430, 430, 555, 555, 843, 843, - -1251, -1251, 871, 871, 1550, 1550, 105, 105, - 422, 422, 587, 587, 177, 177, -235, -235, - -291, -291, -460, -460, 1574, 1574, 1653, 1653, - -246, -246, 778, 778, 1159, 1159, -147, -147, - -777, -777, 1483, 1483, -602, -602, 1119, 1119, - -1590, -1590, 644, 644, -872, -872, 349, 349, - 418, 418, 329, 329, -156, -156, -75, -75, - 817, 817, 1097, 1097, 603, 603, 610, 610, - 1322, 1322, -1285, -1285, -1465, -1465, 384, 384, - -1215, -1215, -136, -136, 1218, 1218, -1335, -1335, - -874, -874, 220, 220, -1187, -1187, 1670, 1670, - -1185, -1185, -1530, -1530, -1278, -1278, 794, 794, - -1510, -1510, -854, -854, -870, -870, 478, 478, - -108, -108, -308, -308, 996, 996, 991, 991, - 958, 958, -1460, -1460, 1522, 1522, 1628, 1628 - }; - private static final short[] MONT_ZETAS_FOR_VECTOR_INVERSE_NTT_ARR = new short[]{ - // level 0 - -1628, -1628, -1522, -1522, 1460, 1460, -958, -958, - -991, -991, -996, -996, 308, 308, 108, 108, - -478, -478, 870, 870, 854, 854, 1510, 1510, - -794, -794, 1278, 1278, 1530, 1530, 1185, 1185, - 1659, 1659, 1187, 1187, -220, -220, 874, 874, - 1335, 1335, -1218, -1218, 136, 136, 1215, 1215, - -384, -384, 1465, 1465, 1285, 1285, -1322, -1322, - -610, -610, -603, -603, -1097, -1097, -817, -817, - 75, 75, 156, 156, -329, -329, -418, -418, - -349, -349, 872, 872, -644, -644, 1590, 1590, - -1119, -1119, 602, 602, -1483, -1483, 777, 777, - 147, 147, -1159, -1159, -778, -778, 246, 246, - -1653, -1653, -1574, -1574, 460, 460, 291, 291, - 235, 235, -177, -177, -587, -587, -422, -422, - -105, -105, -1550, -1550, -871, -871, 1251, 1251, - -843, -843, -555, -555, -430, -430, 1103, 1103, - // level 1 - 1275, 1275, 1275, 1275, -677, -677, -677, -677, - 1065, 1065, 1065, 1065, -448, -448, -448, -448, - 725, 725, 725, 725, 1508, 1508, 1508, 1508, - -961, -961, -961, -961, 398, 398, 398, 398, - 951, 951, 951, 951, 247, 247, 247, 247, - 1421, 1421, 1421, 1421, -107, -107, -107, -107, - -830, -830, -830, -830, 271, 271, 271, 271, - 90, 90, 90, 90, 853, 853, 853, 853, - -1469, -1469, -1469, -1469, -126, -126, -126, -126, - 1162, 1162, 1162, 1162, 1618, 1618, 1618, 1618, - 666, 666, 666, 666, 320, 320, 320, 320, - 8, 8, 8, 8, -516, -516, -516, -516, - 1544, 1544, 1544, 1544, 282, 282, 282, 282, - -1491, -1491, -1491, -1491, 1293, 1293, 1293, 1293, - -1015, -1015, -1015, -1015, 552, 552, 552, 552, - -652, -652, -652, -652, -1223, -1223, -1223, -1223, - // level 2 - 1571, 1571, 1571, 1571, 1571, 1571, 1571, 1571, - 205, 205, 205, 205, 205, 205, 205, 205, - -411, -411, -411, -411, -411, -411, -411, -411, - 1542, 1542, 1542, 1542, 1542, 1542, 1542, 1542, - -608, -608, -608, -608, -608, -608, -608, -608, - -732, -732, -732, -732, -732, -732, -732, -732, - -1017, -1017, -1017, -1017, -1017, -1017, -1017, -1017, - 681, 681, 681, 681, 681, 681, 681, 681, - 130, 130, 130, 130, 130, 130, 130, 130, - 1602, 1602, 1602, 1602, 1602, 1602, 1602, 1602, - -1458, -1458, -1458, -1458, -1458, -1458, -1458, -1458, - 829, 829, 829, 829, 829, 829, 829, 829, - -383, -383, -383, -383, -383, -383, -383, -383, - -264, -264, -264, -264, -264, -264, -264, -264, - 1325, 1325, 1325, 1325, 1325, 1325, 1325, 1325, - -573, -573, -573, -573, -573, -573, -573, -573, - // level 3 - -1468, -1468, -1468, -1468, -1468, -1468, -1468, -1468, - -1468, -1468, -1468, -1468, -1468, -1468, -1468, -1468, - 1474, 1474, 1474, 1474, 1474, 1474, 1474, 1474, - 1474, 1474, 1474, 1474, 1474, 1474, 1474, 1474, - 1202, 1202, 1202, 1202, 1202, 1202, 1202, 1202, - 1202, 1202, 1202, 1202, 1202, 1202, 1202, 1202, - -962, -962, -962, -962, -962, -962, -962, -962, - -962, -962, -962, -962, -962, -962, -962, -962, - -182, -182, -182, -182, -182, -182, -182, -182, - -182, -182, -182, -182, -182, -182, -182, -182, - -1577, -1577, -1577, -1577, -1577, -1577, -1577, -1577, - -1577, -1577, -1577, -1577, -1577, -1577, -1577, -1577, - -622, -622, -622, -622, -622, -622, -622, -622, - -622, -622, -622, -622, -622, -622, -622, -622, - 171, 171, 171, 171, 171, 171, 171, 171, - 171, 171, 171, 171, 171, 171, 171, 171, - // level 4 - -202, -202, -202, -202, -202, -202, -202, -202, - -202, -202, -202, -202, -202, -202, -202, -202, - -202, -202, -202, -202, -202, -202, -202, -202, - -202, -202, -202, -202, -202, -202, -202, -202, - -287, -287, -287, -287, -287, -287, -287, -287, - -287, -287, -287, -287, -287, -287, -287, -287, - -287, -287, -287, -287, -287, -287, -287, -287, - -287, -287, -287, -287, -287, -287, -287, -287, - -1422, -1422, -1422, -1422, -1422, -1422, -1422, -1422, - -1422, -1422, -1422, -1422, -1422, -1422, -1422, -1422, - -1422, -1422, -1422, -1422, -1422, -1422, -1422, -1422, - -1422, -1422, -1422, -1422, -1422, -1422, -1422, -1422, - -1493, -1493, -1493, -1493, -1493, -1493, -1493, -1493, - -1493, -1493, -1493, -1493, -1493, -1493, -1493, -1493, - -1493, -1493, -1493, -1493, -1493, -1493, -1493, -1493, - -1493, -1493, -1493, -1493, -1493, -1493, -1493, -1493, - // level 5 - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 1517, 1517, 1517, 1517, 1517, 1517, 1517, 1517, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - 359, 359, 359, 359, 359, 359, 359, 359, - // level 6 - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 758, 758, 758 - }; - private static final int[] MONT_ZETAS_FOR_NTT_MULT = new int[]{ -1003, 1003, 222, -222, -1107, 1107, 172, -172, -42, 42, 620, -620, 1497, -1497, -1649, 1649, @@ -333,25 +90,6 @@ public final class ML_KEM { -1317, 1317, -57, 57, 1049, -1049, -584, 584 }; - private static final short[] MONT_ZETAS_FOR_VECTOR_NTT_MULT_ARR = new short[]{ - -1103, 1103, 430, -430, 555, -555, 843, -843, - -1251, 1251, 871, -871, 1550, -1550, 105, -105, - 422, -422, 587, -587, 177, -177, -235, 235, - -291, 291, -460, 460, 1574, -1574, 1653, -1653, - -246, 246, 778, -778, 1159, -1159, -147, 147, - -777, 777, 1483, -1483, -602, 602, 1119, -1119, - -1590, 1590, 644, -644, -872, 872, 349, -349, - 418, -418, 329, -329, -156, 156, -75, 75, - 817, -817, 1097, -1097, 603, -603, 610, -610, - 1322, -1322, -1285, 1285, -1465, 1465, 384, -384, - -1215, 1215, -136, 136, 1218, -1218, -1335, 1335, - -874, 874, 220, -220, -1187, 1187, 1670, 1659, - -1185, 1185, -1530, 1530, -1278, 1278, 794, -794, - -1510, 1510, -854, 854, -870, 870, 478, -478, - -108, 108, -308, 308, 996, -996, 991, -991, - 958, -958, -1460, 1460, 1522, -1522, 1628, -1628 - }; - private final int mlKem_k; private final int mlKem_eta1; private final int mlKem_eta2; @@ -499,7 +237,7 @@ protected ML_KEM_KeyPair generateKemKeyPair(byte[] kem_d, byte[] kem_z) { System.arraycopy(kPkePrivateKey, 0, decapsKey, 0, kPkePrivateKey.length); Arrays.fill(kPkePrivateKey, (byte)0); System.arraycopy(encapsKey, 0, decapsKey, - kPkePrivateKey.length, encapsKey.length); + kPkePrivateKey.length, encapsKey.length); mlKemH.update(encapsKey); try { @@ -534,7 +272,7 @@ protected ML_KEM_EncapsulateResult encapsulate( var kHatAndRandomCoins = mlKemG.digest(); var randomCoins = Arrays.copyOfRange(kHatAndRandomCoins, 32, 64); var cipherText = kPkeEncrypt(new K_PKE_EncryptionKey(encapsulationKey.keyBytes), - randomMessage, randomCoins); + randomMessage, randomCoins); Arrays.fill(randomCoins, (byte) 0); byte[] sharedSecret = Arrays.copyOfRange(kHatAndRandomCoins, 0, 32); Arrays.fill(kHatAndRandomCoins, (byte) 0); @@ -564,7 +302,7 @@ protected byte[] decapsulate(ML_KEM_DecapsulationKey decapsulationKey, byte[] kPkePrivateKeyBytes = new byte[mlKem_k * encode12PolyLen]; System.arraycopy(decapsKeyBytes, 0, kPkePrivateKeyBytes, 0, - kPkePrivateKeyBytes.length); + kPkePrivateKeyBytes.length); byte[] encapsKeyBytes = new byte[mlKem_k * encode12PolyLen + 32]; System.arraycopy(decapsKeyBytes, mlKem_k * encode12PolyLen, @@ -678,8 +416,8 @@ private K_PKE_KeyPair generateK_PkeKeyPair(byte[] seed) { pkEncoded, (mlKem_k * ML_KEM_N * 12) / 8, rho.length); return new K_PKE_KeyPair( - new K_PKE_EncryptionKey(pkEncoded), - new K_PKE_DecryptionKey(skEncoded)); + new K_PKE_EncryptionKey(pkEncoded), + new K_PKE_DecryptionKey(skEncoded)); } private K_PKE_CipherText kPkeEncrypt( @@ -969,11 +707,9 @@ private short[][] mlKemVectorInverseNTT(short[][] vector) { return vector; } - static void implMlKemNtt(short[] poly, short[] ntt_zetas) { - implMlKemNttJava(poly); - } - - private static void implMlKemNttJava(short[] poly) { + // The elements of poly should be in the range [-ML_KEM_Q, ML_KEM_Q] + // The elements of poly at return will be in the range of [0, ML_KEM_Q] + private void mlKemNTT(short[] poly) { int[] coeffs = new int[ML_KEM_N]; for (int m = 0; m < ML_KEM_N; m++) { coeffs[m] = poly[m]; @@ -982,20 +718,12 @@ private static void implMlKemNttJava(short[] poly) { for (int m = 0; m < ML_KEM_N; m++) { poly[m] = (short) coeffs[m]; } - } - - // The elements of poly should be in the range [-ML_KEM_Q, ML_KEM_Q] - // The elements of poly at return will be in the range of [0, ML_KEM_Q] - private void mlKemNTT(short[] poly) { - implMlKemNtt(poly, MONT_ZETAS_FOR_VECTOR_NTT_ARR); mlKemBarrettReduce(poly); } - static void implMlKemInverseNtt(short[] poly, short[] zetas) { - implMlKemInverseNttJava(poly); - } - - private static void implMlKemInverseNttJava(short[] poly) { + // Works in place, but also returns its (modified) input so that it can + // be used in expressions + private short[] mlKemInverseNTT(short[] poly) { int[] coeffs = new int[ML_KEM_N]; for (int m = 0; m < ML_KEM_N; m++) { coeffs[m] = poly[m]; @@ -1004,12 +732,6 @@ private static void implMlKemInverseNttJava(short[] poly) { for (int m = 0; m < ML_KEM_N; m++) { poly[m] = (short) coeffs[m]; } - } - - // Works in place, but also returns its (modified) input so that it can - // be used in expressions - private short[] mlKemInverseNTT(short[] poly) { - implMlKemInverseNtt(poly, MONT_ZETAS_FOR_VECTOR_INVERSE_NTT_ARR); return poly; } @@ -1100,14 +822,10 @@ private short[] mlKemVectorScalarMult(short[][] a, short[][] b) { return result; } - static void implMlKemNttMult(short[] result, short[] ntta, short[] nttb, - short[] zetas) { - implMlKemNttMultJava(result, ntta, nttb); - } - - private static void implMlKemNttMultJava(short[] result, - short[] ntta, short[] nttb) { - + // Multiplies two polynomials represented in the NTT domain. + // The result is a representation of the product still in the NTT domain. + // The coefficients in the result are in the range (-ML_KEM_Q, ML_KEM_Q). + private void nttMult(short[] result, short[] ntta, short[] nttb) { for (int m = 0; m < ML_KEM_N / 2; m++) { int a0 = ntta[2 * m]; int a1 = ntta[2 * m + 1]; @@ -1121,13 +839,6 @@ private static void implMlKemNttMultJava(short[] result, } } - // Multiplies two polynomials represented in the NTT domain. - // The result is a representation of the product still in the NTT domain. - // The coefficients in the result are in the range (-ML_KEM_Q, ML_KEM_Q). - private void nttMult(short[] result, short[] ntta, short[] nttb) { - implMlKemNttMult(result, ntta, nttb, MONT_ZETAS_FOR_VECTOR_NTT_MULT_ARR); - } - // Adds the vector of polynomials b to a in place, i.e. a will hold // the result. It also returns (the modified) a so that it can be used // in an expression. @@ -1142,36 +853,15 @@ private short[][] mlKemAddVec(short[][] a, short[][] b) { return a; } - static void implMlKemAddPoly(short[] result, short[] a, short[] b) { - implMlKemAddPolyJava(result, a, b); - } - - private static void implMlKemAddPolyJava(short[] result, short[] a, short[] b) { - for (int m = 0; m < ML_KEM_N; m++) { - int r = a[m] + b[m] + ML_KEM_Q; // This makes r > -ML_KEM_Q - result[m] = (short) r; - } - } - // Adds the polynomial b to a in place, i.e. (the modified) a will hold // the result. // The coefficients are supposed be greater than -ML_KEM_Q in a and // greater than -ML_KEM_Q and less than ML_KEM_Q in b. // The coefficients in the result are greater than -ML_KEM_Q. private void mlKemAddPoly(short[] a, short[] b) { - implMlKemAddPoly(a, a, b); - } - - static void implMlKemAddPoly(short[] result, short[] a, short[] b, short[] c) { - implMlKemAddPolyJava(result, a, b, c); - } - - private static void implMlKemAddPolyJava(short[] result, short[] a, - short[] b, short[] c) { - for (int m = 0; m < ML_KEM_N; m++) { - int r = a[m] + b[m] + c[m] + 2 * ML_KEM_Q; // This makes r > - ML_KEM_Q - result[m] = (short) r; + int r = a[m] + b[m] + ML_KEM_Q; // This makes r > -ML_KEM_Q + a[m] = (short) r; } } @@ -1181,7 +871,10 @@ private static void implMlKemAddPolyJava(short[] result, short[] a, // greater than -ML_KEM_Q and less than ML_KEM_Q. // The coefficients in the result are nonnegative and less than ML_KEM_Q. private short[] mlKemAddPoly(short[] a, short[] b, short[] c) { - implMlKemAddPoly(a, a, b, c); + for (int m = 0; m < ML_KEM_N; m++) { + int r = a[m] + b[m] + c[m] + 2 * ML_KEM_Q; // This makes r > - ML_KEM_Q + a[m] = (short) r; + } mlKemBarrettReduce(a); return a; } @@ -1304,23 +997,6 @@ private short[][] decodeVector(int l, byte[] encodedVector) { return result; } - private static void implMlKem12To16(byte[] condensed, int index, - short[] parsed, int parsedLength) { - - implMlKem12To16Java(condensed, index, parsed, parsedLength); - } - - private static void implMlKem12To16Java(byte[] condensed, int index, - short[] parsed, int parsedLength) { - - for (int i = 0; i < parsedLength * 3 / 2; i += 3) { - parsed[(i / 3) * 2] = (short) ((condensed[i + index] & 0xff) + - 256 * (condensed[i + index + 1] & 0xf)); - parsed[(i / 3) * 2 + 1] = (short) (((condensed[i + index + 1] >>> 4) & 0xf) + - 16 * (condensed[i + index + 2] & 0xff)); - } - } - // The intrinsic implementations assume that the input and output buffers // are such that condensed can be read in 192-byte chunks and // parsed can be written in 128 shorts chunks. In other words, @@ -1330,7 +1006,12 @@ private static void implMlKem12To16Java(byte[] condensed, int index, private void twelve2Sixteen(byte[] condensed, int index, short[] parsed, int parsedLength) { - implMlKem12To16(condensed, index, parsed, parsedLength); + for (int i = 0; i < parsedLength * 3 / 2; i += 3) { + parsed[(i / 3) * 2] = (short) ((condensed[i + index] & 0xff) + + 256 * (condensed[i + index + 1] & 0xf)); + parsed[(i / 3) * 2 + 1] = (short) (((condensed[i + index + 1] >>> 4) & 0xf) + + 16 * (condensed[i + index + 2] & 0xff)); + } } private static void decodePoly5(byte[] condensed, int index, short[] parsed) { @@ -1471,18 +1152,6 @@ private static short[] decompressDecode(byte[] input) { return result; } - static void implMlKemBarrettReduce(short[] coeffs) { - implMlKemBarrettReduceJava(coeffs); - } - - private static void implMlKemBarrettReduceJava(short[] coeffs) { - for (int m = 0; m < ML_KEM_N; m++) { - int tmp = ((int) coeffs[m] * BARRETT_MULTIPLIER) >> - BARRETT_SHIFT; - coeffs[m] = (short) (coeffs[m] - tmp * ML_KEM_Q); - } - } - // The input elements can have any short value. // Modifies poly such that upon return poly[i] will be // in the range [0, ML_KEM_Q] and will be congruent with the original @@ -1493,7 +1162,10 @@ private static void implMlKemBarrettReduceJava(short[] coeffs) { // will be in the range [0, ML_KEM_Q), i.e. it will be the canonical // representative of its residue class. private void mlKemBarrettReduce(short[] poly) { - implMlKemBarrettReduce(poly); + for (int m = 0; m < ML_KEM_N; m++) { + int tmp = ((int) poly[m] * BARRETT_MULTIPLIER) >> BARRETT_SHIFT; + poly[m] = (short) (poly[m] - tmp * ML_KEM_Q); + } } // Precondition: -(2^MONT_R_BITS -1) * MONT_Q <= b * c < (2^MONT_R_BITS - 1) * MONT_Q @@ -1503,8 +1175,8 @@ private static int montMul(int b, int c) { int a = b * c; int aHigh = a >> MONT_R_BITS; int aLow = a & ((1 << MONT_R_BITS) - 1); - int m = ((MONT_Q_INV_MOD_R * aLow) << (32 - MONT_R_BITS)) >> - (32 - MONT_R_BITS); // signed low product + // signed low product + int m = ((MONT_Q_INV_MOD_R * aLow) << (32 - MONT_R_BITS)) >> (32 - MONT_R_BITS); return (aHigh - ((m * MONT_Q) >> MONT_R_BITS)); // subtract signed high product } diff --git a/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM_Impls.java b/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM_Impls.java index f59883a410e..2ce5b3324e7 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM_Impls.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/ML_KEM_Impls.java @@ -37,19 +37,6 @@ public final class ML_KEM_Impls { - static int name2int(String name) { - if (name.endsWith("512")) { - return 512; - } else if (name.endsWith("768")) { - return 768; - } else if (name.endsWith("1024")) { - return 1024; - } else { - // should not happen - throw new ProviderException("Unknown name " + name); - } - } - public sealed static class KPG extends NamedKeyPairGenerator permits KPG2, KPG3, KPG5 { @@ -164,17 +151,8 @@ protected byte[] implDecapsulate(String name, byte[] decapsulationKey, ML_KEM mlKem = new ML_KEM(name); var kpkeCipherText = new ML_KEM.K_PKE_CipherText(cipherText); - - byte[] decapsulateResult; - try { - decapsulateResult = mlKem.decapsulate( - new ML_KEM.ML_KEM_DecapsulationKey( - decapsulationKey), kpkeCipherText); - } catch (DecapsulateException e) { - throw new DecapsulateException("Decapsulate error", e) ; - } - - return decapsulateResult; + return mlKem.decapsulate(new ML_KEM.ML_KEM_DecapsulationKey( + decapsulationKey), kpkeCipherText); } @Override diff --git a/src/java.base/share/classes/java/io/FilePermission.java b/src/java.base/share/classes/java/io/FilePermission.java index 30fa3978638..1330766b078 100644 --- a/src/java.base/share/classes/java/io/FilePermission.java +++ b/src/java.base/share/classes/java/io/FilePermission.java @@ -283,7 +283,6 @@ public FilePermission newPermUsingAltPath(FilePermission input) { * @param mask the actions mask to use. * */ - @SuppressWarnings("removal") private void init(int mask) { if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java index e497e8faa6c..033d32611b0 100644 --- a/src/java.base/share/classes/java/lang/String.java +++ b/src/java.base/share/classes/java/lang/String.java @@ -549,7 +549,6 @@ public String(byte[] bytes, int offset, int length, Charset charset) { * Important: parameter order of this method is deliberately changed in order to * disambiguate it against other similar methods of this class. */ - @SuppressWarnings("removal") private String(Charset charset, byte[] bytes, int offset, int length) { if (length == 0) { this.value = "".value; @@ -787,7 +786,6 @@ static String newStringNoRepl(byte[] src, Charset cs) throws CharacterCodingExce } } - @SuppressWarnings("removal") private static String newStringNoRepl1(byte[] src, Charset cs) { int len = src.length; if (len == 0) { diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 11c77d48bf0..87aca3e1ffd 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -1379,7 +1379,6 @@ public static LoggerFinder getLoggerFinder() { private static volatile LoggerFinder service; - @SuppressWarnings("removal") static LoggerFinder accessProvider() { // We do not need to synchronize: LoggerFinderLoader will // always return the same instance, so if we don't have it, @@ -1483,7 +1482,6 @@ public static Logger getLogger(String name) { * * @since 9 */ - @SuppressWarnings("removal") @CallerSensitive public static Logger getLogger(String name, ResourceBundle bundle) { final ResourceBundle rb = Objects.requireNonNull(bundle); diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java b/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java index 9fdafdf4331..7d9385eed68 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java @@ -60,12 +60,7 @@ * its state must be reset for each traversal; this will happen automatically if * the transform is created with {@link ClassTransform#ofStateful(Supplier)} (or * corresponding methods for other classfile locations.) - *

- * Class transformation sample where code transformation is stateful: - * {@snippet lang="java" class="PackageSnippets" region="codeRelabeling"} - *

- * Complex class instrumentation sample chaining multiple transformations: - * {@snippet lang="java" class="PackageSnippets" region="classInstrumentation"} + * * @param the transform type * @param the element type * @param the builder type diff --git a/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java b/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java index c6956d6d23a..7a58da7f6ce 100644 --- a/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java +++ b/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java @@ -25,21 +25,13 @@ package java.lang.classfile.snippets; import java.lang.classfile.*; -import java.lang.classfile.components.ClassRemapper; -import java.lang.classfile.components.CodeLocalsShifter; -import java.lang.classfile.components.CodeRelabeler; import java.lang.classfile.instruction.*; import java.lang.constant.ClassDesc; import java.lang.constant.ConstantDescs; import java.lang.constant.MethodTypeDesc; import java.lang.invoke.MethodHandles; -import java.lang.reflect.AccessFlag; -import java.util.ArrayDeque; import java.util.HashSet; -import java.util.Map; import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.stream.Collectors.toSet; @@ -326,82 +318,6 @@ void fooToBarUnrolled(ClassModel classModel) { // @end } - void codeRelabeling(ClassModel classModel) { - // @start region="codeRelabeling" - byte[] newBytes = ClassFile.of().transformClass(classModel, - ClassTransform.transformingMethodBodies( - CodeTransform.ofStateful(CodeRelabeler::of))); - // @end - } - - // @start region="classInstrumentation" - byte[] classInstrumentation(ClassModel target, ClassModel instrumentor, Predicate instrumentedMethodsFilter) { - var instrumentorCodeMap = instrumentor.methods().stream() - .filter(instrumentedMethodsFilter) - .collect(Collectors.toMap(mm -> mm.methodName().stringValue() + mm.methodType().stringValue(), mm -> mm.code().orElseThrow())); - var targetFieldNames = target.fields().stream().map(f -> f.fieldName().stringValue()).collect(Collectors.toSet()); - var targetMethods = target.methods().stream().map(m -> m.methodName().stringValue() + m.methodType().stringValue()).collect(Collectors.toSet()); - var instrumentorClassRemapper = ClassRemapper.of(Map.of(instrumentor.thisClass().asSymbol(), target.thisClass().asSymbol())); - return ClassFile.of().transformClass(target, - ClassTransform.transformingMethods( - instrumentedMethodsFilter, - (mb, me) -> { - if (me instanceof CodeModel targetCodeModel) { - var mm = targetCodeModel.parent().get(); - //instrumented methods code is taken from instrumentor - mb.transformCode(instrumentorCodeMap.get(mm.methodName().stringValue() + mm.methodType().stringValue()), - //all references to the instrumentor class are remapped to target class - instrumentorClassRemapper.asCodeTransform() - .andThen((codeBuilder, instrumentorCodeElement) -> { - //all invocations of target methods from instrumentor are inlined - if (instrumentorCodeElement instanceof InvokeInstruction inv - && target.thisClass().asInternalName().equals(inv.owner().asInternalName()) - && mm.methodName().stringValue().equals(inv.name().stringValue()) - && mm.methodType().stringValue().equals(inv.type().stringValue())) { - - //store stacked method parameters into locals - var storeStack = new ArrayDeque(); - int slot = 0; - if (!mm.flags().has(AccessFlag.STATIC)) - storeStack.push(StoreInstruction.of(TypeKind.REFERENCE, slot++)); - for (var pt : mm.methodTypeSymbol().parameterList()) { - var tk = TypeKind.from(pt); - storeStack.push(StoreInstruction.of(tk, slot)); - slot += tk.slotSize(); - } - storeStack.forEach(codeBuilder::with); - - //inlined target locals must be shifted based on the actual instrumentor locals - codeBuilder.block(inlinedBlockBuilder -> inlinedBlockBuilder - .transform(targetCodeModel, CodeLocalsShifter.of(mm.flags(), mm.methodTypeSymbol()) - .andThen(CodeRelabeler.of()) - .andThen((innerBuilder, shiftedTargetCode) -> { - //returns must be replaced with jump to the end of the inlined method - if (shiftedTargetCode instanceof ReturnInstruction) - innerBuilder.goto_(inlinedBlockBuilder.breakLabel()); - else - innerBuilder.with(shiftedTargetCode); - }))); - } else - codeBuilder.with(instrumentorCodeElement); - })); - } else - mb.with(me); - }) - .andThen(ClassTransform.endHandler(clb -> - //remaining instrumentor fields and methods are injected at the end - clb.transform(instrumentor, - ClassTransform.dropping(cle -> - !(cle instanceof FieldModel fm - && !targetFieldNames.contains(fm.fieldName().stringValue())) - && !(cle instanceof MethodModel mm - && !ConstantDescs.INIT_NAME.equals(mm.methodName().stringValue()) - && !targetMethods.contains(mm.methodName().stringValue() + mm.methodType().stringValue()))) - //and instrumentor class references remapped to target class - .andThen(instrumentorClassRemapper))))); - } - // @end - void resolverExample() { // @start region="lookup-class-hierarchy-resolver" MethodHandles.Lookup lookup = MethodHandles.lookup(); // @replace regex="MethodHandles\.lookup\(\)" replacement="..." diff --git a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java index cd38bd19227..024dfacb71b 100644 --- a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java +++ b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java @@ -1277,9 +1277,9 @@ MemorySegment reinterpret(long newSize, * @throws IllegalArgumentException if the size of the string is greater than the * largest string supported by the platform * @throws IndexOutOfBoundsException if {@code offset < 0} - * @throws IndexOutOfBoundsException if {@code offset > byteSize() - (B + 1)}, where - * {@code B} is the size, in bytes, of the string encoded using UTF-8 charset - * {@code str.getBytes(StandardCharsets.UTF_8).length}) + * @throws IndexOutOfBoundsException if no string terminator (e.g. {@code '\0'}) is + * present in this segment between the given {@code offset} and the end of + * this segment. * @throws IllegalStateException if the {@linkplain #scope() scope} associated with * this segment is not {@linkplain Scope#isAlive() alive} * @throws WrongThreadException if this method is called from a thread {@code T}, @@ -1315,14 +1315,11 @@ MemorySegment reinterpret(long newSize, * @throws IllegalArgumentException if the size of the string is greater than the * largest string supported by the platform * @throws IndexOutOfBoundsException if {@code offset < 0} - * @throws IndexOutOfBoundsException if {@code offset > byteSize() - (B + N)}, where: - *

    - *
  • {@code B} is the size, in bytes, of the string encoded using the - * provided charset (e.g. {@code str.getBytes(charset).length});
  • - *
  • {@code N} is the size (in bytes) of the terminator char according - * to the provided charset. For instance, this is 1 for - * {@link StandardCharsets#US_ASCII} and 2 for {@link StandardCharsets#UTF_16}.
  • - *
+ * @throws IndexOutOfBoundsException if no string terminator (e.g. {@code '\0'}) is + * present in this segment between the given {@code offset} and the end of + * this segment. The byte size of the string terminator depends on the + * selected {@code charset}. For instance, this is 1 for + * {@link StandardCharsets#US_ASCII} and 2 for {@link StandardCharsets#UTF_16} * @throws IllegalStateException if the {@linkplain #scope() scope} associated with * this segment is not {@linkplain Scope#isAlive() alive} * @throws WrongThreadException if this method is called from a thread {@code T}, diff --git a/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java b/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java index 8f934d6d67c..e03504a749b 100644 --- a/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java +++ b/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java @@ -578,7 +578,6 @@ S loadSpecies(S speciesData) { * @param speciesData what species we are generating * @return the generated concrete TopClass class */ - @SuppressWarnings("removal") Class generateConcreteSpeciesCode(String className, ClassSpecializer.SpeciesData speciesData) { byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData); var lookup = new MethodHandles.Lookup(topClass); diff --git a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java index 96e0a7e729f..3b34453bc3f 100644 --- a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java +++ b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java @@ -103,7 +103,6 @@ final class ProxyGenerator { /** * debugging flag for saving generated class files */ - @SuppressWarnings("removal") private static final boolean SAVE_GENERATED_FILES = Boolean.getBoolean("jdk.proxy.ProxyGenerator.saveGeneratedFiles"); diff --git a/src/java.base/share/classes/java/net/Inet6Address.java b/src/java.base/share/classes/java/net/Inet6Address.java index ca73a6e1cc1..06a74ca3adc 100644 --- a/src/java.base/share/classes/java/net/Inet6Address.java +++ b/src/java.base/share/classes/java/net/Inet6Address.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -554,6 +554,10 @@ public static InetAddress ofLiteral(String ipv6AddressLiteral) { */ static InetAddress parseAddressString(String addressLiteral, boolean removeSqBrackets) throws UnknownHostException { + // Empty strings are not parseable + if (addressLiteral.isEmpty()) { + return null; + } // Remove trailing and leading square brackets if requested if (removeSqBrackets && addressLiteral.charAt(0) == '[' && addressLiteral.length() > 2 && diff --git a/src/java.base/share/classes/java/net/InetAddress.java b/src/java.base/share/classes/java/net/InetAddress.java index e94df5a9e0a..4bceebdcd0e 100644 --- a/src/java.base/share/classes/java/net/InetAddress.java +++ b/src/java.base/share/classes/java/net/InetAddress.java @@ -1618,6 +1618,9 @@ static InetAddress[] getAllByName0(String host) throws UnknownHostException { */ public static InetAddress ofLiteral(String ipAddressLiteral) { Objects.requireNonNull(ipAddressLiteral); + if (ipAddressLiteral.isEmpty()) { + throw IPAddressUtil.invalidIpAddressLiteral(ipAddressLiteral); + } InetAddress inetAddress; try { // First try to parse the input as an IPv4 address literal diff --git a/src/java.base/share/classes/java/net/URLConnection.java b/src/java.base/share/classes/java/net/URLConnection.java index 209b84de200..69f71942561 100644 --- a/src/java.base/share/classes/java/net/URLConnection.java +++ b/src/java.base/share/classes/java/net/URLConnection.java @@ -1388,7 +1388,6 @@ private ContentHandler lookupContentHandlerClassFor(String contentType) { return UnknownContentHandler.INSTANCE; } - @SuppressWarnings("removal") private ContentHandler lookupContentHandlerViaProvider(String contentType) { ClassLoader cl = ClassLoader.getSystemClassLoader(); diff --git a/src/java.base/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java b/src/java.base/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java index 1d9e32c31d3..b198f977dd5 100644 --- a/src/java.base/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java +++ b/src/java.base/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java @@ -90,7 +90,6 @@ private static AsynchronousChannelProvider loadProviderAsService() { ServiceLoader sl = ServiceLoader.load(AsynchronousChannelProvider.class, ClassLoader.getSystemClassLoader()); - Iterator i = sl.iterator(); return sl.findFirst().orElse(null); } } 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 fa8ff8029e9..17d6eebbcb8 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -1509,7 +1509,7 @@ public static boolean isHidden(Path path) throws IOException { } // lazy loading of default and installed file type detectors - private static class FileTypeDetectors{ + private static class FileTypeDetectors { static final FileTypeDetector defaultFileTypeDetector = createDefaultFileTypeDetector(); static final List installedDetectors = @@ -1522,13 +1522,11 @@ private static FileTypeDetector createDefaultFileTypeDetector() { // loads all installed file type detectors private static List loadInstalledDetectors() { - List list = new ArrayList<>(); - ServiceLoader loader = ServiceLoader - .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader()); - for (FileTypeDetector detector: loader) { - list.add(detector); - } - return list; + return ServiceLoader.load(FileTypeDetector.class, + ClassLoader.getSystemClassLoader()) + .stream() + .map(ServiceLoader.Provider::get) + .toList(); } } diff --git a/src/java.base/share/classes/java/security/DomainCombiner.java b/src/java.base/share/classes/java/security/DomainCombiner.java index 704c6315bb1..1594a48783f 100644 --- a/src/java.base/share/classes/java/security/DomainCombiner.java +++ b/src/java.base/share/classes/java/security/DomainCombiner.java @@ -46,8 +46,7 @@ public interface DomainCombiner { * set of Permissions, for example). * * @param currentDomains the ProtectionDomains associated with the - * current execution thread, up to the most recent - * privileged {@code ProtectionDomain}. + * current execution thread. * The ProtectionDomains are listed in order of execution, * with the most recently executing {@code ProtectionDomain} * residing at the beginning of the array. This parameter may @@ -55,8 +54,6 @@ public interface DomainCombiner { * has no associated ProtectionDomains. * * @param assignedDomains an array of inherited ProtectionDomains. - * ProtectionDomains may be inherited from a parent thread, - * or from a privileged {@code AccessControlContext}. * This parameter may be {@code null} * if there are no inherited ProtectionDomains. * diff --git a/src/java.base/share/classes/java/security/Policy.java b/src/java.base/share/classes/java/security/Policy.java index 5bf590623f4..89876498cf5 100644 --- a/src/java.base/share/classes/java/security/Policy.java +++ b/src/java.base/share/classes/java/security/Policy.java @@ -43,7 +43,7 @@ * supported. Installing a system-wide {@code Policy} object is no longer * supported. The {@linkplain #setPolicy setPolicy} method has been * changed to always throw {@code UnsupportedOperationException}. The - * {@linkplain getPolicy getPolicy} method has been changed to always + * {@linkplain #getPolicy getPolicy} method has been changed to always * return a {@code Policy} object that grants no permissions. There is no * replacement for the Security Manager or this class. */ diff --git a/src/java.base/share/classes/java/security/PrivilegedAction.java b/src/java.base/share/classes/java/security/PrivilegedAction.java index 39db3492c01..56f7878bc6a 100644 --- a/src/java.base/share/classes/java/security/PrivilegedAction.java +++ b/src/java.base/share/classes/java/security/PrivilegedAction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -27,8 +27,8 @@ /** - * A computation to be performed with privileges enabled. The computation is - * performed by invoking {@code AccessController.doPrivileged} on the + * A computation to be performed by invoking + * {@code AccessController.doPrivileged} on the * {@code PrivilegedAction} object. This interface is used only for * computations that do not throw checked exceptions; computations that * throw checked exceptions must use {@code PrivilegedExceptionAction} @@ -44,7 +44,7 @@ public interface PrivilegedAction { /** * Performs the computation. This method will be called by - * {@code AccessController.doPrivileged} after enabling privileges. + * {@code AccessController.doPrivileged}. * * @return a class-dependent value that may represent the results of the * computation. Each class that implements diff --git a/src/java.base/share/classes/java/security/PrivilegedActionException.java b/src/java.base/share/classes/java/security/PrivilegedActionException.java index 9c52d8739b8..1c1418f4267 100644 --- a/src/java.base/share/classes/java/security/PrivilegedActionException.java +++ b/src/java.base/share/classes/java/security/PrivilegedActionException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -63,7 +63,7 @@ public PrivilegedActionException(Exception exception) { } /** - * Returns the exception thrown by the privileged computation that + * Returns the exception thrown by the computation that * resulted in this {@code PrivilegedActionException}. * * @apiNote @@ -71,7 +71,7 @@ public PrivilegedActionException(Exception exception) { * The {@link Throwable#getCause()} method is now the preferred means of * obtaining this information. * - * @return the exception thrown by the privileged computation that + * @return the exception thrown by the computation that * resulted in this {@code PrivilegedActionException}. * @see PrivilegedExceptionAction * @see AccessController#doPrivileged(PrivilegedExceptionAction) @@ -90,7 +90,7 @@ public String toString() { /** - * The exception thrown by the privileged computation that resulted + * The exception thrown by the computation that resulted * in this {@code PrivilegedActionException}. * * @serialField exception Exception the thrown Exception diff --git a/src/java.base/share/classes/java/security/PrivilegedExceptionAction.java b/src/java.base/share/classes/java/security/PrivilegedExceptionAction.java index 00863ddf4a1..d875a2a4159 100644 --- a/src/java.base/share/classes/java/security/PrivilegedExceptionAction.java +++ b/src/java.base/share/classes/java/security/PrivilegedExceptionAction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -27,8 +27,8 @@ /** - * A computation to be performed with privileges enabled, that throws one or - * more checked exceptions. The computation is performed by invoking + * A computation to be performed that throws one or more checked exceptions. + * The computation is performed by invoking * {@code AccessController.doPrivileged} on the * {@code PrivilegedExceptionAction} object. This interface is * used only for computations that throw checked exceptions; @@ -47,7 +47,7 @@ public interface PrivilegedExceptionAction { /** * Performs the computation. This method will be called by - * {@code AccessController.doPrivileged} after enabling privileges. + * {@code AccessController.doPrivileged}. * * @return a class-dependent value that may represent the results of the * computation. Each class that implements diff --git a/src/java.base/share/classes/java/security/ProtectionDomain.java b/src/java.base/share/classes/java/security/ProtectionDomain.java index 231f998edb3..19ee5815db0 100644 --- a/src/java.base/share/classes/java/security/ProtectionDomain.java +++ b/src/java.base/share/classes/java/security/ProtectionDomain.java @@ -25,9 +25,6 @@ package java.security; -import jdk.internal.access.JavaSecurityAccess; -import jdk.internal.access.SharedSecrets; - /** * The {@code ProtectionDomain} class encapsulates the characteristics of a * domain, which encloses a set of classes whose instances are granted a set @@ -51,39 +48,6 @@ public class ProtectionDomain { - private static class JavaSecurityAccessImpl implements JavaSecurityAccess { - - private JavaSecurityAccessImpl() { - } - - @SuppressWarnings("removal") - @Override - public T doIntersectionPrivilege( - PrivilegedAction action, - final AccessControlContext stack, - final AccessControlContext context) { - if (action == null) { - throw new NullPointerException(); - } - - return AccessController.doPrivileged(action); - } - - @SuppressWarnings("removal") - @Override - public T doIntersectionPrivilege( - PrivilegedAction action, - AccessControlContext context) { - return doIntersectionPrivilege(action, - AccessController.getContext(), context); - } - } - - static { - // Set up JavaSecurityAccess in SharedSecrets - SharedSecrets.setJavaSecurityAccess(new JavaSecurityAccessImpl()); - } - /* CodeSource */ private final CodeSource codesource ; diff --git a/src/java.base/share/classes/java/util/Locale.java b/src/java.base/share/classes/java/util/Locale.java index c055c160367..d0d42e7199e 100644 --- a/src/java.base/share/classes/java/util/Locale.java +++ b/src/java.base/share/classes/java/util/Locale.java @@ -45,7 +45,7 @@ import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; -import java.text.DateFormat; +import java.text.NumberFormat; import java.text.MessageFormat; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -70,131 +70,151 @@ import sun.util.locale.provider.TimeZoneNameUtility; /** - * A {@code Locale} object represents a specific geographical, political, - * or cultural region. An operation that requires a {@code Locale} to perform - * its task is called locale-sensitive and uses the {@code Locale} - * to tailor information for the user. For example, displaying a number - * is a locale-sensitive operation— the number should be formatted - * according to the customs and conventions of the user's native country, - * region, or culture. - * - *

The {@code Locale} class implements IETF BCP 47 which is composed of + * A {@code Locale} represents a specific geographical, political, + * or cultural region. An API that requires a {@code Locale} to perform + * its task is {@index "locale-sensitive"} and uses the {@code Locale} + * to tailor information for the user. These locale-sensitive APIs + * are principally in the java.text and java.util packages. + * For example, displaying a number is a locale-sensitive operation— + * the number should be formatted according to the customs and conventions of the + * user's native country, region, or culture. + * + *

The {@code Locale} class implements IETF BCP 47 which is composed of * RFC 4647 "Matching of Language * Tags" and RFC 5646 "Tags * for Identifying Languages" with support for the LDML (UTS#35, "Unicode * Locale Data Markup Language") BCP 47-compatible extensions for locale data - * exchange. - * - *

A {@code Locale} object logically consists of the fields - * described below. + * exchange. Each {@code Locale} is associated with locale data which is provided + * by the Java runtime environment or any deployed {@link + * java.util.spi.LocaleServiceProvider LocaleServiceProvider} implementations. + * The locale data provided by the Java runtime environment may vary by release. + * + *

Locale Composition

+ *

A {@code Locale} is composed of the bolded fields described below; note that a + * {@code Locale} need not have all such fields. For example, {@link + * Locale#ENGLISH Locale.ENGLISH} is only comprised of the language field. + * In contrast, a {@code Locale} such as the one returned by {@code + * Locale.forLanguageTag("en-Latn-US-POSIX-u-nu-latn")} would be comprised of all + * the fields below. This particular {@code Locale} would represent English in + * the United States using the Latin script and numerics for use in POSIX + * environments. + *

+ * {@code Locale} implements IETF BCP 47 and any deviations should be observed + * by the comments prefixed by "BCP 47 deviation:". + * RFC 5646 + * combines subtags from various ISO (639, 3166, 15924) standards which are also + * included in the composition of {@code Locale}. + * Additionally, the full list of valid codes for each field can be found in the + * + * IANA Language Subtag Registry (e.g. search for "Type: region"). * *

*
language
- * - *
ISO 639 alpha-2 or alpha-3 language code, or registered - * language subtags up to 8 alpha letters (for future enhancements). + *
ISO 639 alpha-2/alpha-3 language code or a registered + * language subtag up to 8 alpha letters (for future enhancements). * When a language has both an alpha-2 code and an alpha-3 code, the - * alpha-2 code must be used. You can find a full list of valid - * language codes in the IANA Language Subtag Registry (search for - * "Type: language"). The language field is case insensitive, but + * alpha-2 code must be used.
+ * + *
Case convention: {@code language} is case insensitive, but * {@code Locale} always canonicalizes to lower case.
* - *
Well-formed language values have the form - * [a-zA-Z]{2,8}. Note that this is not the full - * BCP47 language production, since it excludes extlang. They are - * not needed since modern three-letter language codes replace - * them.
+ *
Syntax: Well-formed {@code language} values have the form {@code [a-zA-Z]{2,8}}.
+ *
BCP 47 deviation: this is not the full BCP 47 language production, since it excludes + * extlang + * (as modern three-letter language codes are preferred).
* - *
Example: "en" (English), "ja" (Japanese), "kok" (Konkani)
+ *
Example: "en" (English), "ja" (Japanese), "kok" (Konkani)
* *
script
* - *
ISO 15924 alpha-4 script code. You can find a full list of - * valid script codes in the IANA Language Subtag Registry (search - * for "Type: script"). The script field is case insensitive, but + *
ISO 15924 alpha-4 script code.
+ * + *
Case convention: {@code script} is case insensitive, but * {@code Locale} always canonicalizes to title case (the first * letter is upper case and the rest of the letters are lower * case).
* - *
Well-formed script values have the form - * [a-zA-Z]{4}
+ *
Syntax: Well-formed {@code script} values have the form {@code + * [a-zA-Z]{4}}
* - *
Example: "Latn" (Latin), "Cyrl" (Cyrillic)
+ *
Example: "Latn" (Latin), "Cyrl" (Cyrillic)
* *
country (region)
* - *
ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code. - * You can find a full list of valid country and region codes in the - * IANA Language Subtag Registry (search for "Type: region"). The - * country (region) field is case insensitive, but + *
ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code.
+ * + *
Case convention: {@code country (region)} is case insensitive, but * {@code Locale} always canonicalizes to upper case.
* - *
Well-formed country/region values have - * the form [a-zA-Z]{2} | [0-9]{3}
+ *
Syntax: Well-formed {@code country (region)} values have the form {@code + * [a-zA-Z]{2} | [0-9]{3}}
* - *
Example: "US" (United States), "FR" (France), "029" + *
Example: "US" (United States), "FR" (France), "029" * (Caribbean)
* *
variant
* - *
Any arbitrary value used to indicate a variation of a - * {@code Locale}. Where there are two or more variant values - * each indicating its own semantics, these values should be ordered - * by importance, with most important first, separated by - * underscore('_'). The variant field is case sensitive.
- * - *
Note: IETF BCP 47 places syntactic restrictions on variant - * subtags. Also BCP 47 subtags are strictly used to indicate + *
Any arbitrary value used to indicate a variation of a + * {@code Locale}. When multiple variants exist, they should be separated by + * {@code ('_'|'-')}. Variants of higher importance should precede the others.
+ *
BCP 47 deviation: BCP 47 subtags are strictly used to indicate * additional variations that define a language or its dialects that * are not covered by any combinations of language, script and - * region subtags. You can find a full list of valid variant codes - * in the IANA Language Subtag Registry (search for "Type: variant"). - * - *

However, the variant field in {@code Locale} has + * region subtags. However, the variant field in {@code Locale} has * historically been used for any kind of variation, not just * language variations. For example, some supported variants * available in Java SE Runtime Environments indicate alternative * cultural behaviors such as calendar type or number script. In - * BCP 47 this kind of information, which does not identify the + * BCP 47, this kind of information which does not identify the * language, is supported by extension subtags or private use * subtags.

* - *
Well-formed variant values have the form SUBTAG - * (('_'|'-') SUBTAG)* where SUBTAG = - * [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}. (Note: BCP 47 only - * uses hyphen ('-') as a delimiter, this is more lenient).
+ *
Case convention: {@code variant} is case sensitive. BCP 47 + * deviation: BCP 47 treats the variant field as case insensitive.
* - *
Example: "polyton" (Polytonic Greek), "POSIX"
+ *
Syntax: Well-formed {@code variant} values have the form {@code + * SUBTAG (('_'|'-') SUBTAG)*} where {@code SUBTAG = + * [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}}.
+ *
BCP 47 deviation: BCP 47 only + * uses hyphen ('-') as a delimiter, {@code Locale} is more lenient.
+ * + *
Example: "polyton" (Polytonic Greek), "POSIX"
* *
extensions
* - *
A map from single character keys to string values, indicating - * extensions apart from language identification. The extensions in - * {@code Locale} implement the semantics and syntax of BCP 47 - * extension subtags and private use subtags. The extensions are + *
A map from single character keys to string values, indicating + * extensions apart from language identification.
+ *
BCP 47 deviation: The {@code + * extensions} in {@code Locale} implement the semantics and syntax of BCP 47 + * extension subtags and private use subtags. The {@code extensions} + * field cannot have empty values.
+ * + *
Case convention: {@code extensions} are * case insensitive, but {@code Locale} canonicalizes all - * extension keys and values to lower case. Note that extensions - * cannot have empty values.
+ * extension keys and values to lower case. * - *
Well-formed keys are single characters from the set + *
Syntax: Well-formed keys are single characters from the set * {@code [0-9a-zA-Z]}. Well-formed values have the form * {@code SUBTAG ('-' SUBTAG)*} where for the key 'x' - * SUBTAG = [0-9a-zA-Z]{1,8} and for other keys - * SUBTAG = [0-9a-zA-Z]{2,8} (that is, 'x' allows + * {@code SUBTAG = [0-9a-zA-Z]{1,8}} and for other keys + * {@code SUBTAG = [0-9a-zA-Z]{2,8}} (that is, 'x' allows * single-character subtags).
* - *
Example: key="u"/value="ca-japanese" (Japanese Calendar), + *
Example: key="u"/value="ca-japanese" (Japanese Calendar), * key="x"/value="java-1-7"
*
* - * Note: Although BCP 47 requires field values to be registered + * BCP 47 deviation: Although BCP 47 requires field values to be registered * in the IANA Language Subtag Registry, the {@code Locale} class - * does not provide any validation features. The {@code Builder} + * does not validate this requirement. For example, the variant code "foobar" + * is well-formed since it is composed of 5 to 8 alphanumerics, but is not defined + * the IANA Language Subtag Registry. The {@link Builder} * only checks if an individual field satisfies the syntactic * requirement (is well-formed), but does not validate the value - * itself. See {@link Builder} for details. + * itself. Conversely, {@link #of(String, String, String) Locale::of} and its + * overloads do not make any syntactic checks on the input. * - *

Unicode locale/language extension

+ *

Unicode BCP 47 U Extension

* *

UTS#35, "Unicode Locale Data Markup Language" defines optional * attributes and keywords to override or refine the default behavior @@ -213,7 +233,7 @@ * String representing this information, for example, "nu-thai". The * {@code Locale} class also provides {@link * #getUnicodeLocaleAttributes}, {@link #getUnicodeLocaleKeys}, and - * {@link #getUnicodeLocaleType} which allow you to access Unicode + * {@link #getUnicodeLocaleType(String)} which provides access to the Unicode * locale attributes and key/type pairs directly. When represented as * a string, the Unicode Locale Extension lists attributes * alphabetically, followed by key/type sequences with keys listed @@ -221,11 +241,11 @@ * fixed when the type is defined) * *

A well-formed locale key has the form - * [0-9a-zA-Z]{2}. A well-formed locale type has the - * form "" | [0-9a-zA-Z]{3,8} ('-' [0-9a-zA-Z]{3,8})* (it + * {@code [0-9a-zA-Z]{2}}. A well-formed locale type has the + * form {@code "" | [0-9a-zA-Z]{3,8} ('-' [0-9a-zA-Z]{3,8})*} (it * can be empty, or a series of subtags 3-8 alphanums in length). A * well-formed locale attribute has the form - * [0-9a-zA-Z]{3,8} (it is a single subtag with the same + * {@code [0-9a-zA-Z]{3,8}} (it is a single subtag with the same * form as a locale type subtag). * *

The Unicode locale extension specifies optional behavior in @@ -234,36 +254,11 @@ * implementations in a Java Runtime Environment might not support any * particular Unicode locale attributes or key/type pairs. * - *

Obtaining a Locale

- * - *

There are several ways to obtain a {@code Locale} - * object. - * - *

Builder

- * - *

Using {@link Builder} you can construct a {@code Locale} object - * that conforms to BCP 47 syntax. - * - *

Factory Methods

- * - *

The method {@link #forLanguageTag} obtains a {@code Locale} - * object for a well-formed BCP 47 language tag. The method - * {@link #of(String, String, String)} and its overloads obtain a - * {@code Locale} object from given {@code language}, {@code country}, - * and/or {@code variant} defined above. - * - *

Locale Constants

- * - *

The {@code Locale} class provides a number of convenient constants - * that you can use to obtain {@code Locale} objects for commonly used - * locales. For example, {@code Locale.US} is the {@code Locale} object - * for the United States. - * - *

Default Locale

+ *

Default Locale

* - *

The default Locale is provided for any locale-sensitive methods if no + *

The default Locale is provided for any locale-sensitive methods if no * {@code Locale} is explicitly specified as an argument, such as - * {@link DateFormat#getInstance()}. The default Locale is determined at startup + * {@link NumberFormat#getInstance()}. The default Locale is determined at startup * of the Java runtime and established in the following three phases: *

    *
  1. The locale-related system properties listed below are established from the @@ -316,6 +311,7 @@ * system properties are not altered. It is not recommended that applications read * these system properties and parse or interpret them as their values may be out of date. * + *

    Locale Category

    *

    There are finer-grained default Locales specific for each {@link Locale.Category}. * These category specific default Locales can be queried by {@link #getDefault(Category)}, * and set by {@link #setDefault(Category, Locale)}. Construction of these category @@ -327,19 +323,87 @@ * category. In the absence of category specific system properties, the "category-less" * system properties are used, such as {@code user.language} in the previous example. * - *

    Locale Matching

    + *

    Obtaining a Locale

    * - *

    If an application or a system is internationalized and provides localized + *

    There are several ways to obtain a {@code Locale} object. + * It is advised against using the deprecated {@code Locale} constructors. + * + *

    + *
    Locale Constants
    + *
    A number of convenient constants are provided that return {@code Locale} + * objects for commonly used locales. For example, {@link #US Locale.US} is the + * {@code Locale} object for the United States.
    + *
    Factory Methods
    + *
    {@link #of(String, String, String) Locale::of} and its overloads obtain a + * {@code Locale} object from the given {@code language}, {@code country}, + * and/or {@code variant}. {@link #forLanguageTag(String)} obtains a {@code Locale} + * object for a well-formed BCP 47 language tag.
    + *
    Builder
    + *
    {@link Builder} is used to construct a {@code Locale} object that conforms + * to BCP 47 syntax. Use a builder to enforce syntactic restrictions on the input.
    + *
    + *

    The following invocations produce Locale objects that are all equivalent: + * {@snippet lang=java : + * Locale.US; + * Locale.of("en", "US"); + * Locale.forLanguageTag("en-US"); + * new Locale.Builder().setLanguage("en").setRegion("US").build(); + * } + * + *

    Usage Examples

    + * + *

    Once a {@code Locale} is {@linkplain ##ObtainingLocale obtained}, + * it can be queried for information about itself. For example, use {@link + * #getCountry} to get the country (or region) code and {@link #getLanguage} to + * get the language. {@link #getDisplayCountry} can be used to get the + * name of the country suitable for displaying to the user. Similarly, + * use {@link #getDisplayLanguage()} to get the name of + * the language suitable for displaying to the user. The {@code getDisplayXXX} + * methods are themselves locale-sensitive and have two variants; one with an explicit + * locale parameter, and one without. The latter uses the default {@link + * Locale.Category#DISPLAY DISPLAY} locale, so the following are equivalent : + * {@snippet lang=java : + * Locale.getDefault().getDisplayCountry(); + * Locale.getDefault().getDisplayCountry(Locale.getDefault(Locale.Category.DISPLAY)); + * } + * + *

    The Java Platform provides a number of classes that perform locale-sensitive + * operations. For example, the {@code NumberFormat} class formats + * numbers, currency, and percentages in a locale-sensitive manner. Classes such + * as {@code NumberFormat} have several factory methods for creating a default object + * of that type. These methods generally have two variants; one with an explicit + * locale parameter, and one without. The latter uses the default {@link + * Locale.Category#FORMAT FORMAT} locale, so the following are equivalent : + * {@snippet lang=java : + * NumberFormat.getCurrencyInstance(); + * NumberFormat.getCurrencyInstance(Locale.getDefault(Locale.Category.FORMAT)); + * } + * + *

    + * The following example demonstrates locale-sensitive currency and + * date related operations under different locales : + * {@snippet lang = java: + * var number = 1000; + * NumberFormat.getCurrencyInstance(Locale.US).format(number); // returns "$1,000.00" + * NumberFormat.getCurrencyInstance(Locale.JAPAN).format(number); // returns "\u00A51,000"" + * var date = LocalDate.of(2024, 1, 1); + * DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).localizedBy(Locale.US).format(date); // returns "January 1, 2024" + * DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).localizedBy(Locale.JAPAN).format(date); // returns "2024\u5e741\u67081\u65e5" + * } + * + *

    Locale Matching

    + * + *

    If an application is internationalized and provides localized * resources for multiple locales, it sometimes needs to find one or more * locales (or language tags) which meet each user's specific preferences. Note - * that a term "language tag" is used interchangeably with "locale" in this - * locale matching documentation. + * that the term "{@index "language tag"}" is used interchangeably + * with "locale" in the following locale matching documentation. * - *

    In order to do matching a user's preferred locales to a set of language + *

    In order to match a user's preferred locales to a set of language * tags, RFC 4647 Matching of * Language Tags defines two mechanisms: filtering and lookup. * Filtering is used to get all matching locales, whereas - * lookup is to choose the best matching locale. + * lookup is to select the best matching locale. * Matching is done case-insensitively. These matching mechanisms are described * in the following sections. * @@ -348,7 +412,8 @@ * language ranges: basic and extended. See * {@link Locale.LanguageRange Locale.LanguageRange} for details. * - *

    Filtering

    + * + *

    Filtering

    * *

    The filtering operation returns all matching language tags. It is defined * in RFC 4647 as follows: @@ -366,7 +431,7 @@ * {@link Locale.FilteringMode} is a parameter to specify how filtering should * be done. * - *

    Lookup

    + *

    Lookup

    * *

    The lookup operation returns the best matching language tags. It is * defined in RFC 4647 as follows: @@ -398,76 +463,50 @@ * an {@link Iterator} over a {@link Collection} of language tags is treated as * the best matching one. * - *

    Use of Locale

    + *

    Serialization

    * - *

    Once you've obtained a {@code Locale} you can query it for information - * about itself. Use {@code getCountry} to get the country (or region) - * code and {@code getLanguage} to get the language code. - * You can use {@code getDisplayCountry} to get the - * name of the country suitable for displaying to the user. Similarly, - * you can use {@code getDisplayLanguage} to get the name of - * the language suitable for displaying to the user. Interestingly, - * the {@code getDisplayXXX} methods are themselves locale-sensitive - * and have two versions: one that uses the default - * {@link Locale.Category#DISPLAY DISPLAY} locale and one - * that uses the locale specified as an argument. + *

    During serialization, writeObject writes all fields to the output + * stream, including extensions. * - *

    The Java Platform provides a number of classes that perform locale-sensitive - * operations. For example, the {@code NumberFormat} class formats - * numbers, currency, and percentages in a locale-sensitive manner. Classes - * such as {@code NumberFormat} have several convenience methods - * for creating a default object of that type. For example, the - * {@code NumberFormat} class provides these three convenience methods - * for creating a default {@code NumberFormat} object: - * {@snippet lang=java : - * NumberFormat.getInstance(); - * NumberFormat.getCurrencyInstance(); - * NumberFormat.getPercentInstance(); - * } - * Each of these methods has two variants; one with an explicit locale - * and one without; the latter uses the default - * {@link Locale.Category#FORMAT FORMAT} locale: - * {@snippet lang=java : - * NumberFormat.getInstance(myLocale); - * NumberFormat.getCurrencyInstance(myLocale); - * NumberFormat.getPercentInstance(myLocale); - * } - * A {@code Locale} is the mechanism for identifying the kind of object - * ({@code NumberFormat}) that you would like to get. The locale is - * just a mechanism for identifying objects, - * not a container for the objects themselves. - * - *

    Compatibility

    - * - *

    In order to maintain compatibility, Locale's - * constructors retain their behavior prior to the Java Runtime - * Environment version 1.7. The same is largely true for the - * {@code toString} method. Thus Locale objects can continue to - * be used as they were. In particular, clients who parse the output - * of toString into language, country, and variant fields can continue - * to do so (although this is strongly discouraged), although the - * variant field will have additional information in it if script or - * extensions are present. + *

    During deserialization, readResolve adds extensions as described + * in {@linkplain ##special_cases_constructor Special Cases}, only + * for the two cases th_TH_TH and ja_JP_JP. + * + * @implNote + *

    Compatibility

    + *

    The following commentary is provided for apps that want to ensure + * interoperability with older releases of {@code Locale} provided by the + * reference implementation. + *

    Locale Behavior

    + * In order to maintain compatibility, Locale's (deprecated) constructors, + * {@link #of(String, String, String)}, and its overloads retain their behavior prior to the Java Runtime + * Environment version 1.7. That is, a length constraint is not imposed on any of + * the input parameters. Similarly, the same preservation of past behavior is largely true + * for the {@link #toString()} method. + * Apps that previously parsed the output of {@link #toString()} into language, + * country, and variant fields can continue to do so (although this is strongly + * discouraged). A caveat is that the variant field will have additional + * information in it if script or extensions are present. * *

    In addition, BCP 47 imposes syntax restrictions that are not * imposed by Locale's constructors. This means that conversions * between some Locales and BCP 47 language tags cannot be made without - * losing information. Thus {@code toLanguageTag} cannot + * losing information. Thus {@link #toLanguageTag} cannot * represent the state of locales whose language, country, or variant * do not conform to BCP 47. * - *

    Because of these issues, it is recommended that clients migrate + *

    Because of these issues, it is recommended that apps migrate * away from constructing non-conforming locales and use the - * {@code forLanguageTag} and {@code Locale.Builder} APIs instead. - * Clients desiring a string representation of the complete locale can - * then always rely on {@code toLanguageTag} for this purpose. + * {@link #forLanguageTag(String)} and {@link Locale.Builder} APIs instead. + * Apps desiring a string representation of the complete locale can + * then always rely on {@link #toLanguageTag} for this purpose. * - *

    Special cases

    + *

    Special cases

    * *

    For compatibility reasons, two * non-conforming locales are treated as special cases. These are * {@code ja_JP_JP} and {@code th_TH_TH}. These are ill-formed - * in BCP 47 since the variants are too short. To ease migration to BCP 47, + * in BCP 47 since the {@linkplain ##def_variant variants} are too short. To ease migration to BCP 47, * these are treated specially during construction. These two cases (and only * these) cause a constructor to generate an extension, all other values behave * exactly as they did prior to Java 7. @@ -487,25 +526,16 @@ * constructor is called with the arguments "th", "TH", "TH", the * extension "u-nu-thai" is automatically added. * - *

    Serialization

    - * - *

    During serialization, writeObject writes all fields to the output - * stream, including extensions. - * - *

    During deserialization, readResolve adds extensions as described - * in {@linkplain ##special_cases_constructor Special Cases}, only - * for the two cases th_TH_TH and ja_JP_JP. - * - *

    Legacy language codes

    + *

    Legacy language codes

    * - *

    Locale's constructor has always converted three language codes to + *

    Locale's constructors have always converted three language codes to * their earlier, obsoleted forms: {@code he} maps to {@code iw}, * {@code yi} maps to {@code ji}, and {@code id} maps to * {@code in}. Since Java SE 17, this is no longer the case. Each * language maps to its new form; {@code iw} maps to {@code he}, {@code ji} * maps to {@code yi}, and {@code in} maps to {@code id}. * - *

    For the backward compatible behavior, the system property + *

    For backwards compatible behavior, the system property * {@systemProperty java.locale.useOldISOCodes} reverts the behavior * back to that of before Java SE 17. If the system property is set to * {@code true}, those three current language codes are mapped to their @@ -524,22 +554,12 @@ * lookup mechanism also implements this mapping, so that resources * can be named using either convention, see {@link ResourceBundle.Control}. * - *

    Three-letter language/country(region) codes

    - * - *

    The Locale constructors have always specified that the language - * and the country param be two characters in length, although in - * practice they have accepted any length. The specification has now - * been relaxed to allow language codes of two to eight characters and - * country (region) codes of two to three characters, and in - * particular, three-letter language codes and three-digit region - * codes as specified in the IANA Language Subtag Registry. For - * compatibility, the implementation still does not impose a length - * constraint. - * * @spec https://www.rfc-editor.org/info/rfc4647 * RFC 4647: Matching of Language Tags * @spec https://www.rfc-editor.org/info/rfc5646 * RFC 5646: Tags for Identifying Languages + * @spec https://unicode.org/reports/tr35/ + * Unicode Locale Data Markup Language * @see Builder * @see ResourceBundle * @see java.text.Format @@ -1229,28 +1249,28 @@ public static synchronized void setDefault(Locale.Category category, } /** - * {@return an array of installed locales} + * {@return an array of available locales} * * The returned array represents the union of locales supported - * by the Java runtime environment and by installed + * by the Java runtime environment and by deployed * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider} * implementations. At a minimum, the returned array must contain a - * {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and - * a {@code Locale} instance equal to {@link Locale#US Locale.US}. + * {@code Locale} instance equal to {@link #ROOT Locale.ROOT} and + * a {@code Locale} instance equal to {@link #US Locale.US}. */ public static Locale[] getAvailableLocales() { return LocaleServiceProviderPool.getAllAvailableLocales(); } /** - * {@return a stream of installed locales} + * {@return a stream of available locales} * * The returned stream represents the union of locales supported - * by the Java runtime environment and by installed + * by the Java runtime environment and by deployed * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider} * implementations. At a minimum, the returned stream must contain a - * {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and - * a {@code Locale} instance equal to {@link Locale#US Locale.US}. + * {@code Locale} instance equal to {@link #ROOT Locale.ROOT} and + * a {@code Locale} instance equal to {@link #US Locale.US}. * * @implNote Unlike {@code getAvailableLocales()}, this method does * not create a defensive copy of the Locale array. @@ -1532,8 +1552,8 @@ LocaleExtensions getLocaleExtensions() { * Java 6 and prior. * *

    If both the language and country fields are missing, this function will return - * the empty string, even if the variant, script, or extensions field is present (you - * can't have a locale with just a variant, the variant must accompany a well-formed + * the empty string, even if the variant, script, or extensions field is present + * (a locale with just a variant is not allowed, the variant must accompany a well-formed * language or country code). * *

    If script or extensions are present and variant is missing, no underscore is @@ -1613,7 +1633,7 @@ public final String toString() { * (delimited by '-' or '_') is emitted as a subtag. Otherwise: *

      * - *
    • if all sub-segments match [0-9a-zA-Z]{1,8} + *
    • if all sub-segments match {@code [0-9a-zA-Z]{1,8}} * (for example "WIN" or "Oracle_JDK_Standard_Edition"), the first * ill-formed sub-segment and all following will be appended to * the private use subtag. The first appended subtag will be @@ -1622,7 +1642,7 @@ public final String toString() { * "Oracle-x-lvariant-JDK-Standard-Edition". * *
    • if any sub-segment does not match - * [0-9a-zA-Z]{1,8}, the variant will be truncated + * {@code [0-9a-zA-Z]{1,8}}, the variant will be truncated * and the problematic sub-segment and all following sub-segments * will be omitted. If the remainder is non-empty, it will be * emitted as a private use subtag as above (even if the remainder @@ -1774,7 +1794,7 @@ public static String caseFoldLanguageTag(String languageTag) { * *

      If the specified language tag contains any ill-formed subtags, * the first such subtag and all following subtags are ignored. Compare - * to {@link Locale.Builder#setLanguageTag} which throws an exception + * to {@link Locale.Builder#setLanguageTag(String)} which throws an exception * in this case. * *

      The following conversions are performed:

        @@ -1994,7 +2014,6 @@ private static String getISO3Code(String iso2Code, String table) { * getDisplayLanguage() will return "anglais". * If the name returned cannot be localized for the default * {@link Locale.Category#DISPLAY DISPLAY} locale, - * (say, we don't have a Japanese name for Croatian), * this function falls back on the English name, and uses the ISO code as a last-resort * value. If the locale doesn't specify a language, this function returns the empty string. * @@ -2012,7 +2031,6 @@ public final String getDisplayLanguage() { * is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and * inLocale is fr_FR, getDisplayLanguage() will return "anglais". * If the name returned cannot be localized according to inLocale, - * (say, we don't have a Japanese name for Croatian), * this function falls back on the English name, and finally * on the ISO code as a last-resort value. If the locale doesn't specify a language, * this function returns the empty string. @@ -2067,7 +2085,6 @@ public String getDisplayScript(Locale inLocale) { * getDisplayCountry() will return "Etats-Unis". * If the name returned cannot be localized for the default * {@link Locale.Category#DISPLAY DISPLAY} locale, - * (say, we don't have a Japanese name for Croatia), * this function falls back on the English name, and uses the ISO code as a last-resort * value. If the locale doesn't specify a country, this function returns the empty string. * @@ -2084,8 +2101,7 @@ public final String getDisplayCountry() { * For example, if the locale is fr_FR and inLocale * is en_US, getDisplayCountry() will return "France"; if the locale is en_US and * inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis". - * If the name returned cannot be localized according to inLocale. - * (say, we don't have a Japanese name for Croatia), + * If the name returned cannot be localized according to inLocale, * this function falls back on the English name, and finally * on the ISO code as a last-resort value. If the locale doesn't specify a country, * this function returns the empty string. @@ -2697,7 +2713,7 @@ public enum Category { * alphanumerics. The method {@code setVariant} throws * {@code IllformedLocaleException} for a variant that does not satisfy * this restriction. If it is necessary to support such a variant, use - * {@link Locale#of(String, String, String)}. However, keep in mind that a {@code Locale} + * {@link #of(String, String, String)}. However, keep in mind that a {@code Locale} * object obtained this way might lose the variant information when * transformed to a BCP 47 language tag. * @@ -2710,7 +2726,7 @@ public enum Category { *

        Builders can be reused; {@code clear()} resets all * fields to their default values. * - * @see Locale#forLanguageTag + * @see Locale#forLanguageTag(String) * @see Locale#of(String, String, String) * @since 1.7 */ @@ -2760,7 +2776,7 @@ public Builder setLocale(Locale locale) { * language tag. Discards the existing state. Null and the * empty string cause the builder to be reset, like {@link * #clear}. Legacy tags (see {@link - * Locale#forLanguageTag}) are converted to their canonical + * Locale#forLanguageTag(String)}) are converted to their canonical * form before being processed. Otherwise, the language tag * must be well-formed (see {@link Locale}) or an exception is * thrown (unlike {@code Locale.forLanguageTag}, which @@ -2862,7 +2878,7 @@ public Builder setRegion(String region) { * the {@code Locale} class does not impose any syntactic * restriction on variant, and the variant value in * {@code Locale} is case sensitive. To set such a variant, - * use {@link Locale#of(String, String, String)}. + * use {@link #of(String, String, String)}. * * @param variant the variant * @return This builder. @@ -2884,12 +2900,12 @@ public Builder setVariant(String variant) { * must be {@linkplain Locale##def_extensions well-formed} or an exception * is thrown. * - *

        Note: The key {@link Locale#UNICODE_LOCALE_EXTENSION + *

        Note: The key {@link #UNICODE_LOCALE_EXTENSION * UNICODE_LOCALE_EXTENSION} ('u') is used for the Unicode locale extension. * Setting a value for this key replaces any existing Unicode locale key/type * pairs with those defined in the extension. * - *

        Note: The key {@link Locale#PRIVATE_USE_EXTENSION + *

        Note: The key {@link #PRIVATE_USE_EXTENSION * PRIVATE_USE_EXTENSION} ('x') is used for the private use code. To be * well-formed, the value for this key needs only to have subtags of one to * eight alphanumeric characters, not two to eight as in the general case. @@ -2918,7 +2934,7 @@ public Builder setExtension(char key, String value) { * *

        Keys and types are converted to lower case. * - *

        Note:Setting the 'u' extension via {@link #setExtension} + *

        Note:Setting the 'u' extension via {@link #setExtension(char, String)} * replaces all Unicode locale keywords with those defined in the * extension. * @@ -3010,9 +3026,9 @@ public Builder clearExtensions() { * Returns an instance of {@code Locale} obtained from the fields set * on this builder. * - *

        This applies the conversions listed in {@link Locale#forLanguageTag} + *

        This applies the conversions listed in {@link #forLanguageTag(String)} * when constructing a Locale. (Legacy tags are handled in - * {@link #setLanguageTag}.) + * {@link #setLanguageTag(String)}.) * * @return A Locale. */ @@ -3193,10 +3209,10 @@ public static enum FilteringMode { * * @spec https://www.rfc-editor.org/info/rfc4234 RFC 4234: Augmented BNF for Syntax Specifications: ABNF * @spec https://www.rfc-editor.org/info/rfc4647 RFC 4647: Matching of Language Tags - * @see #filter - * @see #filterTags - * @see #lookup - * @see #lookupTag + * @see #filter(List, Collection, FilteringMode) + * @see #filterTags(List, Collection, FilteringMode) + * @see #lookup(List, Collection) + * @see #lookupTag(List, Collection) * * @since 1.8 */ @@ -3413,7 +3429,7 @@ public static List parse(String ranges) { * found in the given {@code ranges} is ill-formed * @spec https://www.rfc-editor.org/info/rfc2616 RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 * @see #parse(String) - * @see #mapEquivalents + * @see #mapEquivalents(List, Map) */ public static List parse(String ranges, Map> map) { diff --git a/src/java.base/share/classes/javax/crypto/JceSecurity.java.template b/src/java.base/share/classes/javax/crypto/JceSecurity.java.template index 8b64b452b11..01282394b57 100644 --- a/src/java.base/share/classes/javax/crypto/JceSecurity.java.template +++ b/src/java.base/share/classes/javax/crypto/JceSecurity.java.template @@ -290,7 +290,6 @@ final class JceSecurity { } } - // This is called from within an doPrivileged block. private static void setupJurisdictionPolicies() throws Exception { // Sanity check the crypto.policy Security property. Single diff --git a/src/java.base/share/classes/javax/security/auth/Subject.java b/src/java.base/share/classes/javax/security/auth/Subject.java index 97ab672e1cc..ceb860e653a 100644 --- a/src/java.base/share/classes/javax/security/auth/Subject.java +++ b/src/java.base/share/classes/javax/security/auth/Subject.java @@ -453,7 +453,7 @@ public static T doAs(final Subject subject, } /** - * Perform privileged work as a particular {@code Subject}. + * Perform work as a particular {@code Subject}. * *

        This method launches {@code action} and binds {@code subject} to * the period of its execution. @@ -513,7 +513,7 @@ public static T doAsPrivileged(final Subject subject, } /** - * Perform privileged work as a particular {@code Subject}. + * Perform work as a particular {@code Subject}. * *

        This method launches {@code action} and binds {@code subject} to * the period of its execution. diff --git a/src/java.base/share/classes/javax/security/auth/SubjectDomainCombiner.java b/src/java.base/share/classes/javax/security/auth/SubjectDomainCombiner.java index bab2c5b9da9..643aea9e93c 100644 --- a/src/java.base/share/classes/javax/security/auth/SubjectDomainCombiner.java +++ b/src/java.base/share/classes/javax/security/auth/SubjectDomainCombiner.java @@ -112,21 +112,16 @@ public Subject getSubject() { * In addition, caching of ProtectionDomains may be permitted. * * @param currentDomains the ProtectionDomains associated with the - * current execution Thread, up to the most recent - * privileged {@code ProtectionDomain}. + * current execution Thread. * The ProtectionDomains are listed in order of execution, * with the most recently executing {@code ProtectionDomain} * residing at the beginning of the array. This parameter may * be {@code null} if the current execution Thread * has no associated ProtectionDomains. * - * @param assignedDomains the ProtectionDomains inherited from the - * parent Thread, or the ProtectionDomains from the - * privileged {@code context}, if a call to - * {@code AccessController.doPrivileged(..., context)} - * had occurred This parameter may be {@code null} - * if there were no ProtectionDomains inherited from the - * parent Thread, or from the privileged {@code context}. + * @param assignedDomains the inherited ProtectionDomains. + * This parameter may be {@code null} + * if there were no inherited ProtectionDomains. * * @return a new array consisting of the updated ProtectionDomains, * or {@code null}. diff --git a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java index 43a1daf762c..8d483507203 100644 --- a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java +++ b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java @@ -39,10 +39,7 @@ import java.io.FileDescriptor; import java.io.FilePermission; import java.io.ObjectInputStream; -import java.io.PrintStream; -import java.io.PrintWriter; import java.io.RandomAccessFile; -import java.security.ProtectionDomain; import java.security.Signature; import javax.security.auth.x500.X500Principal; @@ -89,7 +86,6 @@ public class SharedSecrets { private static JavaUtilJarAccess javaUtilJarAccess; private static JavaUtilZipFileAccess javaUtilZipFileAccess; private static JavaUtilResourceBundleAccess javaUtilResourceBundleAccess; - private static JavaSecurityAccess javaSecurityAccess; private static JavaSecurityPropertiesAccess javaSecurityPropertiesAccess; private static JavaSecuritySignatureAccess javaSecuritySignatureAccess; private static JavaSecuritySpecAccess javaSecuritySpecAccess; @@ -313,19 +309,6 @@ public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { return access; } - public static void setJavaSecurityAccess(JavaSecurityAccess jsa) { - javaSecurityAccess = jsa; - } - - public static JavaSecurityAccess getJavaSecurityAccess() { - var access = javaSecurityAccess; - if (access == null) { - ensureClassInitialized(ProtectionDomain.class); - access = javaSecurityAccess; - } - return access; - } - public static void setJavaSecurityPropertiesAccess(JavaSecurityPropertiesAccess jspa) { javaSecurityPropertiesAccess = jspa; } diff --git a/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java b/src/java.base/share/classes/jdk/internal/classfile/components/ClassPrinter.java similarity index 97% rename from src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java rename to src/java.base/share/classes/jdk/internal/classfile/components/ClassPrinter.java index 7237dc54580..cc5a3824936 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/ClassPrinter.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; import java.lang.classfile.ClassModel; import java.lang.classfile.CodeModel; @@ -58,8 +58,6 @@ *

        * Another use case for {@link ClassPrinter} is to simplify writing of automated tests: * {@snippet lang="java" class="PackageSnippets" region="printNodesInTest"} - * - * @since 24 */ public final class ClassPrinter { @@ -68,8 +66,6 @@ private ClassPrinter() { /** * Level of detail to print or export. - * - * @since 24 */ public enum Verbosity { @@ -102,8 +98,6 @@ public enum Verbosity { /** * Named, traversable, and printable node parent. - * - * @since 24 */ public sealed interface Node { @@ -146,8 +140,6 @@ default void toYaml(Consumer out) { /** * A leaf node holding single printable value. - * - * @since 24 */ public sealed interface LeafNode extends Node permits ClassPrinterImpl.LeafNodeImpl { @@ -161,8 +153,6 @@ public sealed interface LeafNode extends Node /** * A tree node holding {@link List} of nested nodes. - * - * @since 24 */ public sealed interface ListNode extends Node, List permits ClassPrinterImpl.ListNodeImpl { @@ -172,8 +162,6 @@ public sealed interface ListNode extends Node, List * A tree node holding {@link Map} of nested nodes. *

        * Each {@link Map.Entry#getKey()} == {@link Map.Entry#getValue()}.{@link #name()}. - * - * @since 24 */ public sealed interface MapNode extends Node, Map permits ClassPrinterImpl.MapNodeImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java b/src/java.base/share/classes/jdk/internal/classfile/components/ClassRemapper.java similarity index 98% rename from src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java rename to src/java.base/share/classes/jdk/internal/classfile/components/ClassRemapper.java index 4a2808ad4f0..ad116cd9dc4 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/ClassRemapper.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; import java.lang.classfile.ClassFile; import java.lang.classfile.ClassModel; @@ -53,8 +53,6 @@ *

        * Arrays of reference types are always decomposed, mapped as the base reference * types and composed back to arrays. - * - * @since 24 */ public sealed interface ClassRemapper extends ClassTransform permits ClassRemapperImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java b/src/java.base/share/classes/jdk/internal/classfile/components/CodeLocalsShifter.java similarity index 97% rename from src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java rename to src/java.base/share/classes/jdk/internal/classfile/components/CodeLocalsShifter.java index 9db85f54a45..f06b4694953 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/CodeLocalsShifter.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; import java.lang.classfile.AccessFlags; import java.lang.classfile.CodeTransform; @@ -37,8 +37,6 @@ * newly allocated positions to avoid conflicts during code injection. * Locals pointing to the receiver or to method arguments slots are never shifted. * All locals pointing beyond the method arguments are re-indexed in order of appearance. - * - * @since 24 */ public sealed interface CodeLocalsShifter extends CodeTransform permits CodeLocalsShifterImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java b/src/java.base/share/classes/jdk/internal/classfile/components/CodeRelabeler.java similarity index 98% rename from src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java rename to src/java.base/share/classes/jdk/internal/classfile/components/CodeRelabeler.java index 4ef82adfdb9..6a16b6a00dd 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/CodeRelabeler.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeTransform; @@ -44,8 +44,6 @@ * Primary purpose of CodeRelabeler is for repeated injections of the same code blocks. * Repeated injection of the same code block must be relabeled, so each instance of * {@link java.lang.classfile.Label} is bound in the target bytecode exactly once. - * - * @since 24 */ public sealed interface CodeRelabeler extends CodeTransform permits CodeRelabelerImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java b/src/java.base/share/classes/jdk/internal/classfile/components/CodeStackTracker.java similarity index 98% rename from src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java rename to src/java.base/share/classes/jdk/internal/classfile/components/CodeStackTracker.java index 3761e53ff19..eb7f58702eb 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/CodeStackTracker.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; import java.lang.classfile.CodeTransform; import java.lang.classfile.Label; @@ -49,8 +49,6 @@ * int maxStack = stackTracker.maxStackSize().get(); * }); * } - * - * @since 24 */ public sealed interface CodeStackTracker extends CodeTransform permits CodeStackTrackerImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/components/package-info.java b/src/java.base/share/classes/jdk/internal/classfile/components/package-info.java similarity index 98% rename from src/java.base/share/classes/java/lang/classfile/components/package-info.java rename to src/java.base/share/classes/jdk/internal/classfile/components/package-info.java index be650f4c77c..30fb5fc07e5 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/package-info.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/package-info.java @@ -110,8 +110,6 @@ * CodeLocalsShifter} and {@link CodeRelabeler} into fully functional class * instrumenting transformation: * {@snippet lang="java" class="PackageSnippets" region="classInstrumentation"} - * - * @since 24 */ -package java.lang.classfile.components; +package jdk.internal.classfile.components; diff --git a/src/java.base/share/classes/java/lang/classfile/components/snippet-files/PackageSnippets.java b/src/java.base/share/classes/jdk/internal/classfile/components/snippet-files/PackageSnippets.java similarity index 97% rename from src/java.base/share/classes/java/lang/classfile/components/snippet-files/PackageSnippets.java rename to src/java.base/share/classes/jdk/internal/classfile/components/snippet-files/PackageSnippets.java index 87c2146a7ac..452e0188115 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/snippet-files/PackageSnippets.java +++ b/src/java.base/share/classes/jdk/internal/classfile/components/snippet-files/PackageSnippets.java @@ -25,10 +25,10 @@ package java.lang.classfile.components.snippets; import java.lang.classfile.*; -import java.lang.classfile.components.ClassPrinter; -import java.lang.classfile.components.ClassRemapper; -import java.lang.classfile.components.CodeLocalsShifter; -import java.lang.classfile.components.CodeRelabeler; +import jdk.internal.classfile.components.ClassPrinter; +import jdk.internal.classfile.components.ClassRemapper; +import jdk.internal.classfile.components.CodeLocalsShifter; +import jdk.internal.classfile.components.CodeRelabeler; import java.lang.classfile.instruction.InvokeInstruction; import java.lang.classfile.instruction.ReturnInstruction; import java.lang.classfile.instruction.StoreInstruction; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java index 183ee323b52..8a44890fe66 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java @@ -31,11 +31,11 @@ import java.lang.classfile.attribute.StackMapFrameInfo.SimpleVerificationTypeInfo; import java.lang.classfile.attribute.StackMapFrameInfo.UninitializedVerificationTypeInfo; import java.lang.classfile.attribute.StackMapFrameInfo.VerificationTypeInfo; -import java.lang.classfile.components.ClassPrinter.LeafNode; -import java.lang.classfile.components.ClassPrinter.ListNode; -import java.lang.classfile.components.ClassPrinter.MapNode; -import java.lang.classfile.components.ClassPrinter.Node; -import java.lang.classfile.components.ClassPrinter.Verbosity; +import jdk.internal.classfile.components.ClassPrinter.LeafNode; +import jdk.internal.classfile.components.ClassPrinter.ListNode; +import jdk.internal.classfile.components.ClassPrinter.MapNode; +import jdk.internal.classfile.components.ClassPrinter.Node; +import jdk.internal.classfile.components.ClassPrinter.Verbosity; import java.lang.classfile.constantpool.*; import java.lang.classfile.instruction.*; import java.lang.constant.ConstantDesc; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java index cd9faaf2f9a..6dbde898ee5 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java @@ -26,7 +26,7 @@ import java.lang.classfile.*; import java.lang.classfile.attribute.*; -import java.lang.classfile.components.ClassRemapper; +import jdk.internal.classfile.components.ClassRemapper; import java.lang.classfile.constantpool.Utf8Entry; import java.lang.classfile.instruction.ConstantInstruction.LoadConstantInstruction; import java.lang.classfile.instruction.*; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java index 7b7d04a8f1d..eac66b7cb5e 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java @@ -28,7 +28,7 @@ import java.lang.classfile.CodeElement; import java.lang.classfile.Signature; import java.lang.classfile.TypeKind; -import java.lang.classfile.components.CodeLocalsShifter; +import jdk.internal.classfile.components.CodeLocalsShifter; import java.lang.classfile.instruction.IncrementInstruction; import java.lang.classfile.instruction.LoadInstruction; import java.lang.classfile.instruction.LocalVariable; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java index af0a59978d7..1e7e5262af4 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java @@ -27,7 +27,7 @@ import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeElement; import java.lang.classfile.Label; -import java.lang.classfile.components.CodeRelabeler; +import jdk.internal.classfile.components.CodeRelabeler; import java.lang.classfile.instruction.*; import java.util.function.BiFunction; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeStackTrackerImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeStackTrackerImpl.java index 2746caae004..5441f78518e 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeStackTrackerImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeStackTrackerImpl.java @@ -29,7 +29,7 @@ import java.lang.classfile.Label; import java.lang.classfile.Opcode; import java.lang.classfile.TypeKind; -import java.lang.classfile.components.CodeStackTracker; +import jdk.internal.classfile.components.CodeStackTracker; import java.lang.classfile.instruction.*; import java.util.*; import java.util.function.Consumer; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java index fc6099f3e5b..b0234fb88cc 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java @@ -26,7 +26,7 @@ import java.lang.classfile.*; import java.lang.classfile.attribute.CodeAttribute; -import java.lang.classfile.components.ClassPrinter; +import jdk.internal.classfile.components.ClassPrinter; import java.lang.classfile.constantpool.ClassEntry; import java.lang.classfile.constantpool.ModuleEntry; import java.lang.classfile.constantpool.PoolEntry; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerifierImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerifierImpl.java index ed93ff1fc5d..4c2104c5a78 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerifierImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerifierImpl.java @@ -26,7 +26,7 @@ import java.lang.classfile.ClassHierarchyResolver; import java.lang.classfile.ClassModel; -import java.lang.classfile.components.ClassPrinter; +import jdk.internal.classfile.components.ClassPrinter; import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java index 02dc79f0288..44eaab0e83a 100644 --- a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java +++ b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java @@ -30,8 +30,6 @@ import java.io.File; import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayDeque; import java.util.Deque; import java.util.function.BiFunction; @@ -323,18 +321,13 @@ boolean open() { return load(this, name, isBuiltin, throwExceptionIfFail()); } - @SuppressWarnings("removal") private boolean throwExceptionIfFail() { if (loadLibraryOnlyIfPresent) return true; // If the file exists but fails to load, UnsatisfiedLinkException thrown by the VM // will include the error message from dlopen to provide diagnostic information - return AccessController.doPrivileged(new PrivilegedAction<>() { - public Boolean run() { - File file = new File(name); - return file.exists(); - } - }); + File file = new File(name); + return file.exists(); } /* diff --git a/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java b/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java index 885e2e8c4d7..628d768d9ce 100644 --- a/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java +++ b/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java @@ -342,8 +342,6 @@ private static LoggerFinder accessLoggerFinder() { // no need to lock: it doesn't matter if we call // getLoggerFinder() twice - since LoggerFinder already caches // the result. - // This is just an optimization to avoid the cost of calling - // doPrivileged every time. prov = LoggerFinder.getLoggerFinder(); if (prov instanceof TemporaryLoggerFinder) return prov; provider = prov; diff --git a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java index ca2fcf11e99..4f7811faf34 100644 --- a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java +++ b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java @@ -28,10 +28,9 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * A thread that has no permissions, is not a member of any user-defined + * A thread that is not a member of any user-defined * ThreadGroup and supports the ability to erase ThreadLocals. */ -@SuppressWarnings("removal") public final class InnocuousThread extends Thread { private static final jdk.internal.misc.Unsafe UNSAFE; private static final long THREAD_LOCALS; diff --git a/src/java.base/share/classes/jdk/internal/perf/Perf.java b/src/java.base/share/classes/jdk/internal/perf/Perf.java index e764fe79273..ada89dcf2e0 100644 --- a/src/java.base/share/classes/jdk/internal/perf/Perf.java +++ b/src/java.base/share/classes/jdk/internal/perf/Perf.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -25,8 +25,6 @@ package jdk.internal.perf; import java.nio.ByteBuffer; -import java.security.Permission; -import java.security.PrivilegedAction; import java.io.IOException; import sun.nio.cs.UTF_8; @@ -49,7 +47,6 @@ * @author Brian Doherty * @since 1.4.2 * @see #getPerf - * @see jdk.internal.perf.Perf.GetPerfAction * @see java.nio.ByteBuffer */ public final class Perf { @@ -58,46 +55,6 @@ public final class Perf { private Perf() { } // prevent instantiation - /** - * The GetPerfAction class is a convenience class for acquiring access - * to the singleton Perf instance using the - * AccessController.doPrivileged() method. - *

        - * An instance of this class can be used as the argument to - * AccessController.doPrivileged(PrivilegedAction). - *

        Here is a suggested idiom for use of this class: - * - *

        {@code
        -     * class MyTrustedClass {
        -     *   private static final Perf perf =
        -     *       AccessController.doPrivileged(new Perf.GetPerfAction());
        -     *   ...
        -     * }
        -     * }
        - *

        - * In the presence of a security manager, the MyTrustedClass - * class in the above example will need to be granted the - * "sun.misc.Perf.getPerf" RuntimePermission - * permission in order to successfully acquire the singleton Perf instance. - *

        - * Please note that the "sun.misc.Perf.getPerf" permission - * is not a JDK specified permission. - * - * @see java.security.AccessController#doPrivileged(PrivilegedAction) - * @see java.lang.RuntimePermission - */ - public static class GetPerfAction implements PrivilegedAction - { - /** - * Run the Perf.getPerf() method in a privileged context. - * - * @see #getPerf - */ - public Perf run() { - return getPerf(); - } - } - /** * Return a reference to the singleton Perf instance. *

        @@ -106,11 +63,6 @@ public Perf run() { * for accessing the instrumentation buffer for this or another local * Java virtual machine. *

        - * If a security manager is installed, its checkPermission - * method is called with a RuntimePermission with a target - * of "sun.misc.Perf.getPerf". A security exception will result - * if the caller has not been granted this permission. - *

        * Access to the returned Perf object should be protected * by its caller and not passed on to untrusted code. This object can * be used to attach to the instrumentation buffer provided by this Java @@ -119,26 +71,12 @@ public Perf run() { * information. API's built on top of this interface may want to provide * finer grained access control to the contents of individual * instrumentation objects contained within the buffer. - *

        - * Please note that the "sun.misc.Perf.getPerf" permission - * is not a JDK specified permission. * * @return A reference to the singleton Perf instance. - * @throws SecurityException if a security manager exists and its - * checkPermission method doesn't allow access - * to the "jdk.internal.perf.Perf.getPerf"" target. - * @see java.lang.RuntimePermission * @see #attach */ public static Perf getPerf() { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - Permission perm = new RuntimePermission("jdk.internal.perf.Perf.getPerf"); - security.checkPermission(perm); - } - return instance; } diff --git a/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java b/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java index b0a87c207b1..dfe67ce849c 100644 --- a/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java +++ b/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -28,7 +28,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.LongBuffer; -import java.security.AccessController; /** * Performance counter support for internal JRE classes. @@ -48,9 +47,7 @@ * */ public class PerfCounter { - @SuppressWarnings("removal") - private static final Perf perf = - AccessController.doPrivileged(new Perf.GetPerfAction()); + private static final Perf perf = Perf.getPerf(); // Must match values defined in hotspot/src/share/vm/runtime/perfdata.hpp private static final int V_Constant = 1; diff --git a/src/java.base/share/classes/jdk/internal/ref/Cleaner.java b/src/java.base/share/classes/jdk/internal/ref/Cleaner.java index 3a02605577b..ecd1c32167f 100644 --- a/src/java.base/share/classes/jdk/internal/ref/Cleaner.java +++ b/src/java.base/share/classes/jdk/internal/ref/Cleaner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -26,8 +26,6 @@ package jdk.internal.ref; import java.lang.ref.*; -import java.security.AccessController; -import java.security.PrivilegedAction; /** @@ -136,21 +134,17 @@ public static Cleaner create(Object ob, Runnable thunk) { /** * Runs this cleaner, if it has not been run before. */ - @SuppressWarnings("removal") public void clean() { if (!remove(this)) return; try { thunk.run(); } catch (final Throwable x) { - AccessController.doPrivileged(new PrivilegedAction<>() { - public Void run() { - if (System.err != null) - new Error("Cleaner terminated abnormally", x) - .printStackTrace(); - System.exit(1); - return null; - }}); + if (System.err != null) { + new Error("Cleaner terminated abnormally", x) + .printStackTrace(); + } + System.exit(1); } } } diff --git a/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java b/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java index b4565daa466..bb7293e5d2b 100644 --- a/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java +++ b/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java @@ -48,9 +48,9 @@ public final class CleanerImpl implements Runnable { private static Function cleanerImplAccess = null; /** - * Heads of a CleanableList for each reference type. + * Currently active PhantomCleanable-s. */ - final PhantomCleanable phantomCleanableList; + final CleanableList activeList; // The ReferenceQueue of pending cleaning actions final ReferenceQueue queue; @@ -82,7 +82,7 @@ static CleanerImpl getCleanerImpl(Cleaner cleaner) { */ public CleanerImpl() { queue = new ReferenceQueue<>(); - phantomCleanableList = new PhantomCleanableRef(); + activeList = new CleanableList(); } /** @@ -129,7 +129,7 @@ public void run() { InnocuousThread mlThread = (t instanceof InnocuousThread) ? (InnocuousThread) t : null; - while (!phantomCleanableList.isListEmpty()) { + while (!activeList.isEmpty()) { if (mlThread != null) { // Clear the thread locals mlThread.eraseThreadLocals(); @@ -165,14 +165,6 @@ public PhantomCleanableRef(Object obj, Cleaner cleaner, Runnable action) { this.action = action; } - /** - * Constructor used only for root of phantom cleanable list. - */ - PhantomCleanableRef() { - super(); - this.action = null; - } - @Override protected void performCleanup() { action.run(); @@ -231,4 +223,137 @@ protected void performCleanup() { // no action } } + + /** + * A specialized implementation that tracks phantom cleanables. + */ + static final class CleanableList { + /** + * Capacity for a single node in the list. + * This balances memory overheads vs locality vs GC walking costs. + */ + static final int NODE_CAPACITY = 4096; + + /** + * Head node. This is the only node where PhantomCleanables are + * added to or removed from. This is the only node with variable size, + * all other nodes linked from the head are always at full capacity. + */ + private Node head; + + /** + * Cached node instance to provide better behavior near NODE_CAPACITY + * threshold: if list size flips around NODE_CAPACITY, it would reuse + * the cached node instead of wasting and re-allocating a new node all + * the time. + */ + private Node cache; + + public CleanableList() { + reset(); + } + + /** + * Testing support: reset list to initial state. + */ + synchronized void reset() { + this.head = new Node(); + } + + /** + * Returns true if cleanable list is empty. + * + * @return true if the list is empty + */ + public synchronized boolean isEmpty() { + // Head node size is zero only when the entire list is empty. + return head.size == 0; + } + + /** + * Insert this PhantomCleanable in the list. + */ + public synchronized void insert(PhantomCleanable phc) { + if (head.size == NODE_CAPACITY) { + // Head node is full, insert new one. + // If possible, pick a pre-allocated node from cache. + Node newHead; + if (cache != null) { + newHead = cache; + cache = null; + } else { + newHead = new Node(); + } + newHead.next = head; + head = newHead; + } + assert head.size < NODE_CAPACITY; + + // Put the incoming object in head node and record indexes. + final int lastIndex = head.size; + phc.node = head; + phc.index = lastIndex; + head.arr[lastIndex] = phc; + head.size++; + } + + /** + * Remove this PhantomCleanable from the list. + * + * @return true if Cleanable was removed or false if not because + * it had already been removed before + */ + public synchronized boolean remove(PhantomCleanable phc) { + if (phc.node == null) { + // Not in the list. + return false; + } + assert phc.node.arr[phc.index] == phc; + + // Replace with another element from the head node, as long + // as it is not the same element. This keeps all non-head + // nodes at full capacity. + final int lastIndex = head.size - 1; + assert lastIndex >= 0; + if (head != phc.node || (phc.index != lastIndex)) { + PhantomCleanable mover = head.arr[lastIndex]; + mover.node = phc.node; + mover.index = phc.index; + phc.node.arr[phc.index] = mover; + } + + // Now we can unlink the removed element. + phc.node = null; + + // Remove the last element from the head node. + head.arr[lastIndex] = null; + head.size--; + + // If head node becomes empty after this, and there are + // nodes that follow it, replace the head node with another + // full one. If needed, stash the now free node in cache. + if (head.size == 0 && head.next != null) { + Node newHead = head.next; + if (cache == null) { + cache = head; + cache.next = null; + } + head = newHead; + } + + return true; + } + + /** + * Segment node. + */ + static class Node { + // Array of tracked cleanables, and the amount of elements in it. + final PhantomCleanable[] arr = new PhantomCleanable[NODE_CAPACITY]; + int size; + + // Linked list structure. + Node next; + } + } } diff --git a/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java b/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java index 24db6d8ef9a..3564a16d0a0 100644 --- a/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java +++ b/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java @@ -44,14 +44,21 @@ public abstract class PhantomCleanable extends PhantomReference implements Cleaner.Cleanable { /** - * Links to previous and next in a doubly-linked list. + * The list of PhantomCleanable; synchronizes insert and remove. */ - PhantomCleanable prev = this, next = this; + private final CleanerImpl.CleanableList list; /** - * The list of PhantomCleanable; synchronizes insert and remove. + * Node for this PhantomCleanable in the list. + * Synchronized by the same lock as the list itself. */ - private final PhantomCleanable list; + CleanerImpl.CleanableList.Node node; + + /** + * Index of this PhantomCleanable in the list node. + * Synchronized by the same lock as the list itself. + */ + int index; /** * Constructs new {@code PhantomCleanable} with @@ -62,73 +69,29 @@ public abstract class PhantomCleanable extends PhantomReference * @param referent the referent to track * @param cleaner the {@code Cleaner} to register with */ + @SuppressWarnings("this-escape") public PhantomCleanable(T referent, Cleaner cleaner) { super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue); - this.list = CleanerImpl.getCleanerImpl(cleaner).phantomCleanableList; - insert(); + index = -1; + list = CleanerImpl.getCleanerImpl(cleaner).activeList; + list.insert(this); + + // Check that list insertion populated the backlinks. + assert node != null; + assert index >= 0; // Ensure referent and cleaner remain accessible Reference.reachabilityFence(referent); Reference.reachabilityFence(cleaner); } - /** - * Construct a new root of the list; not inserted. - */ - PhantomCleanable() { - super(null, null); - this.list = this; - } - - /** - * Insert this PhantomCleanable after the list head. - */ - private void insert() { - synchronized (list) { - prev = list; - next = list.next; - next.prev = this; - list.next = this; - } - } - - /** - * Remove this PhantomCleanable from the list. - * - * @return true if Cleanable was removed or false if not because - * it had already been removed before - */ - private boolean remove() { - synchronized (list) { - if (next != this) { - next.prev = prev; - prev.next = next; - prev = this; - next = this; - return true; - } - return false; - } - } - - /** - * Returns true if the list's next reference refers to itself. - * - * @return true if the list is empty - */ - boolean isListEmpty() { - synchronized (list) { - return list == list.next; - } - } - /** * Unregister this PhantomCleanable and invoke {@link #performCleanup()}, * ensuring at-most-once semantics. */ @Override public final void clean() { - if (remove()) { + if (list.remove(this)) { super.clear(); performCleanup(); } @@ -140,7 +103,7 @@ public final void clean() { */ @Override public void clear() { - if (remove()) { + if (list.remove(this)) { super.clear(); } } diff --git a/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java b/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java index 687e32cdf61..20b390855c9 100644 --- a/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java +++ b/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java @@ -41,7 +41,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; -import java.security.PrivilegedAction; import java.util.Set; import jdk.internal.access.JavaLangReflectAccess; @@ -75,22 +74,6 @@ private ReflectionFactory() { this.langReflectAccess = SharedSecrets.getJavaLangReflectAccess(); } - /** - * A convenience class for acquiring the capability to instantiate - * reflective objects. Use this instead of a raw call to {@link - * #getReflectionFactory} in order to avoid being limited by the - * permissions of your callers. - * - *

        An instance of this class can be used as the argument of - * AccessController.doPrivileged. - */ - public static final class GetReflectionFactoryAction - implements PrivilegedAction { - public ReflectionFactory run() { - return getReflectionFactory(); - } - } - /** * Provides the caller with the capability to instantiate reflective * objects. diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index c3bcbed4e3b..3c293770003 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -81,7 +81,6 @@ exports java.lang.annotation; exports java.lang.classfile; exports java.lang.classfile.attribute; - exports java.lang.classfile.components; exports java.lang.classfile.constantpool; exports java.lang.classfile.instruction; exports java.lang.constant; @@ -177,6 +176,8 @@ jdk.net, jdk.sctp, jdk.crypto.cryptoki; + exports jdk.internal.classfile.components to + jdk.jfr; exports jdk.internal.foreign to jdk.incubator.vector; exports jdk.internal.event to @@ -315,7 +316,6 @@ exports sun.reflect.misc to java.desktop, java.management, - java.rmi, java.sql.rowset; exports sun.security.internal.interfaces to jdk.crypto.cryptoki; @@ -328,7 +328,6 @@ exports sun.security.pkcs to jdk.jartool; exports sun.security.provider to - java.rmi, java.security.jgss, jdk.crypto.cryptoki, jdk.security.auth; @@ -343,7 +342,6 @@ jdk.jartool; exports sun.security.util to java.naming, - java.rmi, java.security.jgss, java.security.sasl, java.smartcardio, diff --git a/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java b/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java index 4ec81e42c37..de7aa016ea3 100644 --- a/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java +++ b/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java @@ -154,7 +154,6 @@ public boolean hurry() { } } - @SuppressWarnings("removal") private static void queueForCleanup(KeepAliveCleanerEntry kace) { queue.lock(); try { diff --git a/src/java.base/share/classes/sun/security/provider/ML_DSA.java b/src/java.base/share/classes/sun/security/provider/ML_DSA.java index 33ce8d5f52d..f3b72f53a32 100644 --- a/src/java.base/share/classes/sun/security/provider/ML_DSA.java +++ b/src/java.base/share/classes/sun/security/provider/ML_DSA.java @@ -25,7 +25,6 @@ package sun.security.provider; -import jdk.internal.vm.annotation.IntrinsicCandidate; import sun.security.provider.SHA3.SHAKE128; import sun.security.provider.SHA3.SHAKE256; @@ -527,13 +526,13 @@ public int[][] t1Unpack(byte[] v) { int tOffset = j*4; int vOffset = (i*320) + (j*5); t1[i][tOffset] = (v[vOffset] & 0xFF) + - ((v[vOffset+1] << 8) & 0x3FF); + ((v[vOffset+1] << 8) & 0x3FF); t1[i][tOffset+1] = ((v[vOffset+1] >> 2) & 0x3F) + - ((v[vOffset+2] << 6) & 0x3FF); + ((v[vOffset+2] << 6) & 0x3FF); t1[i][tOffset+2] = ((v[vOffset+2] >> 4) & 0xF) + - ((v[vOffset+3] << 4) & 0x3FF); + ((v[vOffset+3] << 4) & 0x3FF); t1[i][tOffset+3] = ((v[vOffset+3] >> 6) & 0x3) + - ((v[vOffset+4] << 2) & 0x3FF); + ((v[vOffset+4] << 2) & 0x3FF); } } return t1; @@ -875,8 +874,8 @@ int[][][] generateA(byte[] seed) { rawOfs = 0; } tmp = (rawAij[rawOfs] & 0xFF) + - ((rawAij[rawOfs + 1] & 0xFF) << 8) + - ((rawAij[rawOfs + 2] & 0x7F) << 16); + ((rawAij[rawOfs + 1] & 0xFF) << 8) + + ((rawAij[rawOfs + 2] & 0x7F) << 16); rawOfs += 3; if (tmp < ML_DSA_Q) { aij[ofs] = tmp; @@ -981,7 +980,7 @@ private void decompose(int[][] input, int[][] lowPart, int[][] highPart) { int multiplier = (gamma2 == 95232 ? 22 : 8); for (int i = 0; i < mlDsa_k; i++) { ML_DSA.mlDsaDecomposePoly(input[i], lowPart[i], - highPart[i], gamma2 * 2, multiplier); + highPart[i], gamma2 * 2, multiplier); } } @@ -1032,12 +1031,6 @@ private int[][] useHint(boolean[][] h, int[][] r) { */ public static int[] mlDsaNtt(int[] coeffs) { - implMlDsaAlmostNttJava(coeffs); - implMlDsaMontMulByConstantJava(coeffs, MONT_R_MOD_Q); - return coeffs; - } - - static void implMlDsaAlmostNttJava(int[] coeffs) { int dimension = ML_DSA_N; int m = 0; for (int l = dimension / 2; l > 0; l /= 2) { @@ -1050,15 +1043,11 @@ static void implMlDsaAlmostNttJava(int[] coeffs) { m++; } } - } - - public static int[] mlDsaInverseNtt(int[] coeffs) { - implMlDsaAlmostInverseNttJava(coeffs); - implMlDsaMontMulByConstantJava(coeffs, MONT_DIM_INVERSE); + montMulByConstant(coeffs, MONT_R_MOD_Q); return coeffs; } - static void implMlDsaAlmostInverseNttJava(int[] coeffs) { + public static int[] mlDsaInverseNtt(int[] coeffs) { int dimension = ML_DSA_N; int m = 0; for (int l = 1; l < dimension; l *= 2) { @@ -1067,11 +1056,13 @@ static void implMlDsaAlmostInverseNttJava(int[] coeffs) { int tmp = coeffs[j]; coeffs[j] = (tmp + coeffs[j + l]); coeffs[j + l] = montMul(tmp - coeffs[j + l], - MONT_ZETAS_FOR_INVERSE_NTT[m]); + MONT_ZETAS_FOR_INVERSE_NTT[m]); } m++; } } + montMulByConstant(coeffs, MONT_DIM_INVERSE); + return coeffs; } void mlDsaVectorNtt(int[][] vector) { @@ -1086,22 +1077,13 @@ void mlDsaVectorInverseNtt(int[][] vector) { } } - //Todo - public static void mlDsaNttMultiply(int[] res, int[] coeffs1, int[] coeffs2) { - implMlDsaNttMultJava(res, coeffs1, coeffs2); - } - - static void implMlDsaNttMultJava(int[] product, int[] coeffs1, int[] coeffs2) { + public static void mlDsaNttMultiply(int[] product, int[] coeffs1, int[] coeffs2) { for (int i = 0; i < ML_DSA_N; i++) { product[i] = montMul(coeffs1[i], toMont(coeffs2[i])); } } public static void montMulByConstant(int[] coeffs, int constant) { - implMlDsaMontMulByConstantJava(coeffs, constant); - } - - static void implMlDsaMontMulByConstantJava(int[] coeffs, int constant) { for (int i = 0; i < ML_DSA_N; i++) { coeffs[i] = montMul((coeffs[i]), constant); } @@ -1109,17 +1091,6 @@ static void implMlDsaMontMulByConstantJava(int[] coeffs, int constant) { public static void mlDsaDecomposePoly(int[] input, int[] lowPart, int[] highPart, int twoGamma2, int multiplier) { - implMlDsaDecomposePoly(input, lowPart, highPart, twoGamma2, multiplier); - } - - @IntrinsicCandidate - static void implMlDsaDecomposePoly(int[] input, int[] lowPart, int[] highPart, - int twoGamma2, int multiplier) { - decomposePolyJava(input, lowPart, highPart, twoGamma2, multiplier); - } - - static void decomposePolyJava(int[] input, int[] lowPart, int[] highPart, - int twoGamma2, int multiplier) { for (int m = 0; m < ML_DSA_N; m++) { int rplus = input[m]; rplus = rplus - ((rplus + 5373807) >> 23) * ML_DSA_Q; diff --git a/src/java.base/share/classes/sun/security/provider/ML_DSA_Impls.java b/src/java.base/share/classes/sun/security/provider/ML_DSA_Impls.java index 3213b1e5a5e..dffe7c5cdb1 100644 --- a/src/java.base/share/classes/sun/security/provider/ML_DSA_Impls.java +++ b/src/java.base/share/classes/sun/security/provider/ML_DSA_Impls.java @@ -41,7 +41,7 @@ public enum Version { // set the version to an older one. The following VM option is required: // // --add-exports java.base/sun.security.provider=ALL-UNNAMED - public static Version version = Version.DRAFT; + public static Version version = Version.FINAL; static int name2int(String name) { if (name.endsWith("44")) { diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java index 15ae425850e..e3f65f82f0c 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java @@ -25,6 +25,8 @@ package sun.nio.ch; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; import java.nio.channels.*; import java.util.concurrent.*; import java.nio.ByteBuffer; @@ -34,6 +36,7 @@ import jdk.internal.access.SharedSecrets; import jdk.internal.access.JavaIOFileDescriptorAccess; import jdk.internal.event.FileForceEvent; +import jdk.internal.invoke.MhUtil; /** * Windows implementation of AsynchronousFileChannel using overlapped I/O. @@ -383,10 +386,13 @@ protected void implRelease(FileLockImpl fli) throws IOException { * Task that initiates read operation and handles completion result. */ private class ReadTask implements Runnable, Iocp.ResultHandler { + private static final VarHandle RELEASED = MhUtil.findVarHandle(MethodHandles.lookup(), + "released", boolean.class); private final ByteBuffer dst; private final int pos, rem; // buffer position/remaining private final long position; // file position private final PendingFuture result; + private volatile boolean released; // set to dst if direct; otherwise set to substituted direct buffer private volatile ByteBuffer buf; @@ -405,8 +411,9 @@ private class ReadTask implements Runnable, Iocp.ResultHandler { } void releaseBufferIfSubstituted() { - if (buf != dst) + if (buf != dst && RELEASED.compareAndSet(this, false, true)) { Util.releaseTemporaryDirectBuffer(buf); + } } void updatePosition(int bytesTransferred) { @@ -569,10 +576,13 @@ Future implRead(ByteBuffer dst, * Task that initiates write operation and handles completion result. */ private class WriteTask implements Runnable, Iocp.ResultHandler { + private static final VarHandle RELEASED = MhUtil.findVarHandle(MethodHandles.lookup(), + "released", boolean.class); private final ByteBuffer src; private final int pos, rem; // buffer position/remaining private final long position; // file position private final PendingFuture result; + private volatile boolean released; // set to src if direct; otherwise set to substituted direct buffer private volatile ByteBuffer buf; @@ -591,8 +601,9 @@ private class WriteTask implements Runnable, Iocp.ResultHandler { } void releaseBufferIfSubstituted() { - if (buf != src) + if (buf != src && RELEASED.compareAndSet(this, false, true)) { Util.releaseTemporaryDirectBuffer(buf); + } } void updatePosition(int bytesTransferred) { diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java index 9f3916bad8c..f8b5fab4316 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java @@ -25,12 +25,15 @@ package sun.nio.ch; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; import java.nio.channels.*; import java.nio.ByteBuffer; import java.nio.BufferOverflowException; import java.net.*; import java.util.concurrent.*; import java.io.IOException; +import jdk.internal.invoke.MhUtil; import jdk.internal.misc.Unsafe; import sun.net.util.SocketExceptions; @@ -367,10 +370,13 @@ Future implConnect(SocketAddress remote, * result when the read completes. */ private class ReadTask implements Runnable, Iocp.ResultHandler { + private static final VarHandle RELEASED = MhUtil.findVarHandle(MethodHandles.lookup(), + "released", boolean.class); private final ByteBuffer[] bufs; private final int numBufs; private final boolean scatteringRead; private final PendingFuture result; + private volatile boolean released; // set by run method private ByteBuffer[] shadow; @@ -461,12 +467,14 @@ void updateBuffers(int bytesRead) { } void releaseBuffers() { - for (int i=0; i implements Runnable, Iocp.ResultHandler { + private static final VarHandle RELEASED = MhUtil.findVarHandle(MethodHandles.lookup(), + "released", boolean.class); private final ByteBuffer[] bufs; private final int numBufs; private final boolean gatheringWrite; private final PendingFuture result; + private volatile boolean released; // set by run method private ByteBuffer[] shadow; @@ -728,12 +739,14 @@ void updateBuffers(int bytesWritten) { } void releaseBuffers() { - for (int i=0; i - T + T - h + h - e + e - + - q + q - u + u - i + i - c + c - k + k - + - b + b - r + r - o + o - w + w - n + n - + - f + f - o + o - x + x diff --git a/src/java.desktop/share/classes/javax/swing/text/doc-files/Document-remove.svg b/src/java.desktop/share/classes/javax/swing/text/doc-files/Document-remove.svg index 2c8e91923f5..e47a5f750d0 100644 --- a/src/java.desktop/share/classes/javax/swing/text/doc-files/Document-remove.svg +++ b/src/java.desktop/share/classes/javax/swing/text/doc-files/Document-remove.svg @@ -1,7 +1,7 @@