diff --git a/src/hotspot/cpu/riscv/assembler_riscv.hpp b/src/hotspot/cpu/riscv/assembler_riscv.hpp index 8d60d7a046daa..22554972583e3 100644 --- a/src/hotspot/cpu/riscv/assembler_riscv.hpp +++ b/src/hotspot/cpu/riscv/assembler_riscv.hpp @@ -2942,6 +2942,17 @@ enum Nf { return uabs(target - branch) < branch_range; } + // Decode the given instruction, checking if it's a 16-bit compressed + // instruction and return the address of the next instruction. + static address locate_next_instruction(address inst) { + // Instruction wider than 16 bits has the two least-significant bits set. + if ((0x3 & *inst) == 0x3) { + return inst + instruction_size; + } else { + return inst + compressed_instruction_size; + } + } + Assembler(CodeBuffer* code) : AbstractAssembler(code), _in_compressible_region(true) {} }; diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index 18f3cd2b38d49..93cf1f3896d51 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -979,7 +979,7 @@ bool os::dll_address_to_library_name(address addr, char* buf, // in case of error it checks if .dll/.so was built for the // same architecture as Hotspot is running on -void *os::Bsd::dlopen_helper(const char *filename, int mode) { +void *os::Bsd::dlopen_helper(const char *filename, int mode, char *ebuf, int ebuflen) { #ifndef IA32 bool ieee_handling = IEEE_subnormal_handling_OK(); if (!ieee_handling) { @@ -1005,27 +1005,44 @@ void *os::Bsd::dlopen_helper(const char *filename, int mode) { assert(rtn == 0, "fegetenv must succeed"); #endif // IA32 - void * result= ::dlopen(filename, RTLD_LAZY); - + void* result; + JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);) + result = ::dlopen(filename, RTLD_LAZY); + if (result == nullptr) { + const char* error_report = ::dlerror(); + if (error_report == nullptr) { + error_report = "dlerror returned no error description"; + } + if (ebuf != nullptr && ebuflen > 0) { + ::strncpy(ebuf, error_report, ebuflen-1); + ebuf[ebuflen-1]='\0'; + } + Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report); + log_info(os)("shared library load of %s failed, %s", filename, error_report); + JFR_ONLY(load_event.set_error_msg(error_report);) + } else { + Events::log_dll_message(nullptr, "Loaded shared library %s", filename); + log_info(os)("shared library load of %s was successful", filename); #ifndef IA32 - if (result != nullptr && ! IEEE_subnormal_handling_OK()) { - // We just dlopen()ed a library that mangled the floating-point - // flags. Silently fix things now. - int rtn = fesetenv(&default_fenv); - assert(rtn == 0, "fesetenv must succeed"); - bool ieee_handling_after_issue = IEEE_subnormal_handling_OK(); - - if (ieee_handling_after_issue) { - Events::log_dll_message(nullptr, "IEEE subnormal handling had to be corrected after loading %s", filename); - log_info(os)("IEEE subnormal handling had to be corrected after loading %s", filename); - } else { - Events::log_dll_message(nullptr, "IEEE subnormal handling could not be corrected after loading %s", filename); - log_info(os)("IEEE subnormal handling could not be corrected after loading %s", filename); + if (! IEEE_subnormal_handling_OK()) { + // We just dlopen()ed a library that mangled the floating-point + // flags. Silently fix things now. + JFR_ONLY(load_event.set_fp_env_correction_attempt(true);) + int rtn = fesetenv(&default_fenv); + assert(rtn == 0, "fesetenv must succeed"); + + if (IEEE_subnormal_handling_OK()) { + Events::log_dll_message(nullptr, "IEEE subnormal handling had to be corrected after loading %s", filename); + log_info(os)("IEEE subnormal handling had to be corrected after loading %s", filename); + JFR_ONLY(load_event.set_fp_env_correction_success(true);) + } else { + Events::log_dll_message(nullptr, "IEEE subnormal handling could not be corrected after loading %s", filename); + log_info(os)("IEEE subnormal handling could not be corrected after loading %s", filename); + assert(false, "fesetenv didn't work"); + } } - - assert(ieee_handling_after_issue, "fesetenv didn't work"); - } #endif // IA32 + } return result; } @@ -1037,30 +1054,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { #else log_info(os)("attempting shared library load of %s", filename); - void* result; - JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);) - result = os::Bsd::dlopen_helper(filename, RTLD_LAZY); - if (result != nullptr) { - Events::log_dll_message(nullptr, "Loaded shared library %s", filename); - // Successful loading - log_info(os)("shared library load of %s was successful", filename); - return result; - } - - const char* error_report = ::dlerror(); - if (error_report == nullptr) { - error_report = "dlerror returned no error description"; - } - if (ebuf != nullptr && ebuflen > 0) { - // Read system error message into ebuf - ::strncpy(ebuf, error_report, ebuflen-1); - ebuf[ebuflen-1]='\0'; - } - Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report); - log_info(os)("shared library load of %s failed, %s", filename, error_report); - JFR_ONLY(load_event.set_error_msg(error_report);) - - return nullptr; + return os::Bsd::dlopen_helper(filename, RTLD_LAZY, ebuf, ebuflen); #endif // STATIC_BUILD } #else @@ -1071,29 +1065,13 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { log_info(os)("attempting shared library load of %s", filename); void* result; - JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);) - result = os::Bsd::dlopen_helper(filename, RTLD_LAZY); + result = os::Bsd::dlopen_helper(filename, RTLD_LAZY, ebuf, ebuflen); if (result != nullptr) { - Events::log_dll_message(nullptr, "Loaded shared library %s", filename); - // Successful loading - log_info(os)("shared library load of %s was successful", filename); return result; } - Elf32_Ehdr elf_head; - - const char* const error_report = ::dlerror(); - if (error_report == nullptr) { - error_report = "dlerror returned no error description"; - } - if (ebuf != nullptr && ebuflen > 0) { - // Read system error message into ebuf - ::strncpy(ebuf, error_report, ebuflen-1); - ebuf[ebuflen-1]='\0'; - } Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report); log_info(os)("shared library load of %s failed, %s", filename, error_report); - JFR_ONLY(load_event.set_error_msg(error_report);) int diag_msg_max_length=ebuflen-strlen(ebuf); char* diag_msg_buf=ebuf+strlen(ebuf); @@ -1102,7 +1080,6 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { return nullptr; } - int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK); if (file_descriptor < 0) { @@ -1110,6 +1087,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { return nullptr; } + Elf32_Ehdr elf_head; bool failed_to_read_elf_head= (sizeof(elf_head)!= (::read(file_descriptor, &elf_head,sizeof(elf_head)))); diff --git a/src/hotspot/os/bsd/os_bsd.hpp b/src/hotspot/os/bsd/os_bsd.hpp index f79212bc43c0f..72de9ca597195 100644 --- a/src/hotspot/os/bsd/os_bsd.hpp +++ b/src/hotspot/os/bsd/os_bsd.hpp @@ -70,7 +70,7 @@ class os::Bsd { // Real-time clock functions static void clock_init(void); - static void *dlopen_helper(const char *path, int mode); + static void *dlopen_helper(const char *path, int mode, char *ebuf, int ebuflen); // Stack repair handling diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index e94e366acc741..0f426eff64ce4 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -1856,18 +1856,19 @@ void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { if (! IEEE_subnormal_handling_OK()) { // We just dlopen()ed a library that mangled the floating-point flags. // Attempt to fix things now. + JFR_ONLY(load_event.set_fp_env_correction_attempt(true);) int rtn = fesetenv(&default_fenv); assert(rtn == 0, "fesetenv must succeed"); - bool ieee_handling_after_issue = IEEE_subnormal_handling_OK(); - if (ieee_handling_after_issue) { + if (IEEE_subnormal_handling_OK()) { Events::log_dll_message(nullptr, "IEEE subnormal handling had to be corrected after loading %s", filename); log_info(os)("IEEE subnormal handling had to be corrected after loading %s", filename); + JFR_ONLY(load_event.set_fp_env_correction_success(true);) } else { Events::log_dll_message(nullptr, "IEEE subnormal handling could not be corrected after loading %s", filename); log_info(os)("IEEE subnormal handling could not be corrected after loading %s", filename); + assert(false, "fesetenv didn't work"); } - assert(ieee_handling_after_issue, "fesetenv didn't work"); } #endif // IA32 } diff --git a/src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp b/src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp index 8b9d1178ca567..282467bc9e096 100644 --- a/src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp +++ b/src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp @@ -232,7 +232,7 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info, CompiledMethod* nm = (cb != nullptr) ? cb->as_compiled_method_or_null() : nullptr; bool is_unsafe_arraycopy = (thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc)); if ((nm != nullptr && nm->has_unsafe_access()) || is_unsafe_arraycopy) { - address next_pc = pc + NativeCall::instruction_size; + address next_pc = Assembler::locate_next_instruction(pc); if (is_unsafe_arraycopy) { next_pc = UnsafeCopyMemory::page_error_continue_pc(pc); } @@ -271,7 +271,7 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info, thread->thread_state() == _thread_in_native) && sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ thread->doing_unsafe_access()) { - address next_pc = pc + NativeCall::instruction_size; + address next_pc = Assembler::locate_next_instruction(pc); if (UnsafeCopyMemory::contains_pc(pc)) { next_pc = UnsafeCopyMemory::page_error_continue_pc(pc); } diff --git a/src/hotspot/share/gc/parallel/gcAdaptivePolicyCounters.hpp b/src/hotspot/share/gc/parallel/gcAdaptivePolicyCounters.hpp index 57b48d49f9516..e83813c78f48f 100644 --- a/src/hotspot/share/gc/parallel/gcAdaptivePolicyCounters.hpp +++ b/src/hotspot/share/gc/parallel/gcAdaptivePolicyCounters.hpp @@ -60,7 +60,6 @@ class GCAdaptivePolicyCounters : public GCPolicyCounters { PerfVariable* _decrease_for_footprint_counter; PerfVariable* _minor_pause_young_slope_counter; - PerfVariable* _major_pause_old_slope_counter; PerfVariable* _decide_at_full_gc_counter; diff --git a/src/hotspot/share/jfr/metadata/metadata.xml b/src/hotspot/share/jfr/metadata/metadata.xml index c1f626a819201..53fa17555c687 100644 --- a/src/hotspot/share/jfr/metadata/metadata.xml +++ b/src/hotspot/share/jfr/metadata/metadata.xml @@ -957,6 +957,8 @@ + + (); } @@ -90,8 +90,17 @@ void NativeLibraryUnloadEvent::set_result(bool result) { _result = result; } +static void set_additional_data(EventNativeLibraryLoad& event, const NativeLibraryLoadEvent& helper) { + event.set_fpEnvCorrectionAttempt(helper.get_fp_env_correction_attempt()); + event.set_fpEnvCorrectionSuccess(helper.get_fp_env_correction_success()); +} + +static void set_additional_data(EventNativeLibraryUnload& event, const NativeLibraryUnloadEvent& helper) { + // no additional entries atm. for the unload event +} + template -static void commit(HelperType& helper) { +static void commit(const HelperType& helper) { if (!helper.has_start_time()) { return; } @@ -101,6 +110,7 @@ static void commit(HelperType& helper) { event.set_name(helper.name()); event.set_errorMessage(helper.error_msg()); event.set_success(helper.success()); + set_additional_data(event, helper); Thread* thread = Thread::current(); assert(thread != nullptr, "invariant"); if (thread->is_Java_thread()) { diff --git a/src/hotspot/share/jfr/support/jfrNativeLibraryLoadEvent.hpp b/src/hotspot/share/jfr/support/jfrNativeLibraryLoadEvent.hpp index fe8431fdc438e..30281ad4d0540 100644 --- a/src/hotspot/share/jfr/support/jfrNativeLibraryLoadEvent.hpp +++ b/src/hotspot/share/jfr/support/jfrNativeLibraryLoadEvent.hpp @@ -52,10 +52,16 @@ class JfrNativeLibraryEventBase : public StackObj { class NativeLibraryLoadEvent : public JfrNativeLibraryEventBase { private: void** _result; + bool _fp_env_correction_attempt; + bool _fp_env_correction_success; public: NativeLibraryLoadEvent(const char* name, void** result); ~NativeLibraryLoadEvent(); bool success() const; + bool get_fp_env_correction_attempt() const { return _fp_env_correction_attempt; } + bool get_fp_env_correction_success() const { return _fp_env_correction_success; } + void set_fp_env_correction_attempt(bool v) { _fp_env_correction_attempt = v; } + void set_fp_env_correction_success(bool v) { _fp_env_correction_success = v; } }; class NativeLibraryUnloadEvent : public JfrNativeLibraryEventBase { diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index 25ec68cf8fec5..dfeb6b11f6f21 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -338,7 +338,7 @@ void Universe::genesis(TRAPS) { // Initialization of the fillerArrayKlass must come before regular // int-TypeArrayKlass so that the int-Array mirror points to the // int-TypeArrayKlass. - _fillerArrayKlassObj = TypeArrayKlass::create_klass(T_INT, "Ljdk/internal/vm/FillerArray;", CHECK); + _fillerArrayKlassObj = TypeArrayKlass::create_klass(T_INT, "[Ljdk/internal/vm/FillerElement;", CHECK); for (int i = T_BOOLEAN; i < T_LONG+1; i++) { _typeArrayKlassObjs[i] = TypeArrayKlass::create_klass((BasicType)i, CHECK); } diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index bd6eda2d4681a..9a8a9a5bec0b0 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -3933,8 +3933,6 @@ JVM_ENTRY(void, JVM_VirtualThreadStart(JNIEnv* env, jobject vthread)) // set VTMS transition bit value in JavaThread and java.lang.VirtualThread object JvmtiVTMSTransitionDisabler::set_is_in_VTMS_transition(thread, vthread, false); } -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END @@ -3950,8 +3948,6 @@ JVM_ENTRY(void, JVM_VirtualThreadEnd(JNIEnv* env, jobject vthread)) // set VTMS transition bit value in JavaThread and java.lang.VirtualThread object JvmtiVTMSTransitionDisabler::set_is_in_VTMS_transition(thread, vthread, true); } -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END @@ -3969,8 +3965,6 @@ JVM_ENTRY(void, JVM_VirtualThreadMount(JNIEnv* env, jobject vthread, jboolean hi // set VTMS transition bit value in JavaThread and java.lang.VirtualThread object JvmtiVTMSTransitionDisabler::set_is_in_VTMS_transition(thread, vthread, hide); } -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END @@ -3988,8 +3982,6 @@ JVM_ENTRY(void, JVM_VirtualThreadUnmount(JNIEnv* env, jobject vthread, jboolean // set VTMS transition bit value in JavaThread and java.lang.VirtualThread object JvmtiVTMSTransitionDisabler::set_is_in_VTMS_transition(thread, vthread, hide); } -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END @@ -4003,8 +3995,6 @@ JVM_ENTRY(void, JVM_VirtualThreadHideFrames(JNIEnv* env, jobject vthread, jboole assert(!thread->is_in_VTMS_transition(), "sanity check"); assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check"); thread->toggle_is_in_tmp_VTMS_transition(); -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END @@ -4019,8 +4009,6 @@ JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jobject vthread, jb assert(thread->is_disable_suspend() != (bool)enter, "nested or unbalanced monitor enter/exit is not allowed"); thread->toggle_is_disable_suspend(); -#else - fatal("Should only be called with JVMTI enabled"); #endif JVM_END diff --git a/src/java.base/share/classes/java/io/SequenceInputStream.java b/src/java.base/share/classes/java/io/SequenceInputStream.java index de3fafc884d7e..b89d9ca80b0fa 100644 --- a/src/java.base/share/classes/java/io/SequenceInputStream.java +++ b/src/java.base/share/classes/java/io/SequenceInputStream.java @@ -242,11 +242,14 @@ public long transferTo(OutputStream out) throws IOException { if (getClass() == SequenceInputStream.class) { long transferred = 0; while (in != null) { + long numTransferred = in.transferTo(out); + // increment the total transferred byte count + // only if we haven't already reached the Long.MAX_VALUE if (transferred < Long.MAX_VALUE) { try { - transferred = Math.addExact(transferred, in.transferTo(out)); + transferred = Math.addExact(transferred, numTransferred); } catch (ArithmeticException ignore) { - return Long.MAX_VALUE; + transferred = Long.MAX_VALUE; } } nextStream(); diff --git a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKeyStore.java b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKeyStore.java index ad32c9aef4d60..4e352bf495011 100644 --- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKeyStore.java +++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKeyStore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, 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 @@ -636,7 +636,7 @@ public String engineGetCertificateAlias(Certificate cert) { if (entry.certChain != null && entry.certChain.length > 0 && entry.certChain[0].equals(cert)) { - return entry.getAlias(); + return mapEntry.getKey(); } } diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 6e01458b34897..2aa0c54a95537 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -85,6 +85,11 @@ gc/epsilon/TestMemoryMXBeans.java 8206434 generic-all gc/g1/humongousObjects/objectGraphTest/TestObjectGraphAfterGC.java 8156755 generic-all gc/g1/logging/TestG1LoggingFailure.java 8169634 generic-all gc/g1/humongousObjects/TestHeapCounters.java 8178918 generic-all +gc/TestAllocHumongousFragment.java#adaptive 8298781 generic-all +gc/TestAllocHumongousFragment.java#aggressive 8298781 generic-all +gc/TestAllocHumongousFragment.java#iu-aggressive 8298781 generic-all +gc/TestAllocHumongousFragment.java#g1 8298781 generic-all +gc/TestAllocHumongousFragment.java#static 8298781 generic-all gc/stress/gclocker/TestExcessGCLockerCollections.java 8229120 generic-all gc/stress/gclocker/TestGCLockerWithParallel.java 8180622 generic-all gc/stress/gclocker/TestGCLockerWithSerial.java 8180622 generic-all diff --git a/test/hotspot/jtreg/gc/TestFillerObjectInstantiation.java b/test/hotspot/jtreg/gc/TestFillerObjectInstantiation.java index bec7c4858f5a9..edb63f88af279 100644 --- a/test/hotspot/jtreg/gc/TestFillerObjectInstantiation.java +++ b/test/hotspot/jtreg/gc/TestFillerObjectInstantiation.java @@ -45,6 +45,6 @@ private static void testInstantiationFails(String classname) throws Exception { public static void main(String[] args) throws Exception { testInstantiationFails("jdk.internal.vm.FillerObject"); - testInstantiationFails("jdk.internal.vm.FillerArray"); + testInstantiationFails("jdk.internal.vm.FillerElement"); } } diff --git a/test/jdk/java/io/SequenceInputStream/TransferTo.java b/test/jdk/java/io/SequenceInputStream/TransferTo.java index a39d2c1e0136b..4c8ff71a4f3cc 100644 --- a/test/jdk/java/io/SequenceInputStream/TransferTo.java +++ b/test/jdk/java/io/SequenceInputStream/TransferTo.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.io.SequenceInputStream; import java.util.Arrays; @@ -39,6 +40,7 @@ import static java.lang.String.format; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertThrows; import static org.testng.Assert.assertTrue; @@ -126,6 +128,49 @@ public void testStreamContents() throws Exception { outputStreamProvider, createRandomBytes(4096, 0), 0, 4096); } + /* + * Special case: Assert subsequent input stream is read when preceding stream already was MAX_VALUE long. + * Note: Not testing actual content as it requires multiple GBs of memory and long time. + */ + @Test + public void testHugeStream() throws Exception { + InputStream is1 = repeat(0, Long.MAX_VALUE); + InputStream is2 = repeat(0, 1); + assertNotEquals(is1.available(), 0); + assertNotEquals(is2.available(), 0); + SequenceInputStream sis = new SequenceInputStream(is1, is2); + OutputStream nos = OutputStream.nullOutputStream(); + sis.transferTo(nos); + assertEquals(is1.available(), 0); + assertEquals(is2.available(), 0); + } + + /* + * Produces an input stream that returns b count times. + * Builds a dysfunctional mock that solely implements + * available() and transferTo() particually, + * but fails with any other operation. + */ + private static InputStream repeat(int b, long count) { + return new InputStream() { + private long pos; + @Override + public int available() throws IOException { + return (int) Math.min(count - pos, Integer.MAX_VALUE); + } + @Override + public int read() throws IOException { + throw new UnsupportedOperationException(); + } + @Override + public long transferTo(OutputStream os) throws IOException { + // skipping actual writing to os to spare time + pos += count; + return count; + } + }; + } + /* * Asserts that the transferred content is correct, i.e., compares the bytes * actually transferred to those expected. The position of the input and diff --git a/test/jdk/java/util/zip/ZipFile/ZipSourceCache.java b/test/jdk/java/util/zip/ZipFile/ZipSourceCache.java index 8cb1051a87c77..0f0b0725b7d43 100644 --- a/test/jdk/java/util/zip/ZipFile/ZipSourceCache.java +++ b/test/jdk/java/util/zip/ZipFile/ZipSourceCache.java @@ -25,6 +25,7 @@ * @bug 8317678 * @modules java.base/java.util.zip:open * @summary Fix up hashCode() for ZipFile.Source.Key + * @library /test/lib * @run junit/othervm ZipSourceCache */ @@ -34,6 +35,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.*; import java.util.zip.*; +import jdk.test.lib.util.FileUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeAll; @@ -62,7 +64,7 @@ public static void setup() throws Exception { @AfterAll public static void cleanup() throws IOException { - Files.deleteIfExists(Path.of(ZIPFILE_NAME)); + FileUtils.deleteFileIfExistsWithRetry(Path.of(ZIPFILE_NAME)); } /* diff --git a/test/jdk/sun/security/mscapi/DupAlias.java b/test/jdk/sun/security/mscapi/DupAlias.java new file mode 100644 index 0000000000000..84c70cbbee232 --- /dev/null +++ b/test/jdk/sun/security/mscapi/DupAlias.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * 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. + */ +import jdk.test.lib.Asserts; +import sun.security.tools.keytool.CertAndKeyGen; +import sun.security.x509.X500Name; + +import java.security.KeyStore; +import java.security.MessageDigest; +import java.security.cert.X509Certificate; +import java.util.HexFormat; + +/** + * @test + * @bug 8187634 + * @requires os.family == "windows" + * @library /test/lib + * @modules java.base/sun.security.tools.keytool + * java.base/sun.security.x509 + * @summary getCertificateAlias should return correct alias + */ +public class DupAlias { + public static void main(String[] args) throws Exception { + + String nn = "8187634"; + String na = nn + "a"; + String nb = nn + "b"; + String n1 = nn + " (1)"; + + CertAndKeyGen g = new CertAndKeyGen("EC", "SHA256withECDSA"); + g.generate(-1); + X509Certificate a = g.getSelfCertificate(new X500Name("CN=" + na), 1000); + g.generate(-1); + X509Certificate b = g.getSelfCertificate(new X500Name("CN=" + nb), 1000); + + KeyStore ks = KeyStore.getInstance("Windows-MY-CURRENTUSER"); + try { + ks.load(null, null); + ks.deleteEntry(na); + ks.deleteEntry(nb); + ks.deleteEntry(nn); + ks.deleteEntry(n1); + ks.setCertificateEntry(na, a); + ks.setCertificateEntry(nb, b); + + ps(String.format(""" + $cert = Get-Item Cert:/CurrentUser/My/%s; + $cert.FriendlyName = %s; + $cert = Get-Item Cert:/CurrentUser/My/%s; + $cert.FriendlyName = %s; + """, thumbprint(a), nn, thumbprint(b), nn)); + + ks.load(null, null); + Asserts.assertFalse(ks.containsAlias(na)); + Asserts.assertFalse(ks.containsAlias(nb)); + Asserts.assertEquals(ks.getCertificateAlias(ks.getCertificate(nn)), nn); + Asserts.assertEquals(ks.getCertificateAlias(ks.getCertificate(n1)), n1); + } finally { + ks.deleteEntry(na); + ks.deleteEntry(nb); + ks.deleteEntry(nn); + ks.deleteEntry(n1); + } + } + + static void ps(String f) throws Exception { + ProcessBuilder pb = new ProcessBuilder("powershell", "-Command", f); + pb.inheritIO(); + if (pb.start().waitFor() != 0) { + throw new RuntimeException("Failed"); + } + } + + static String thumbprint(X509Certificate c) throws Exception { + return HexFormat.of().formatHex( + MessageDigest.getInstance("SHA-1").digest(c.getEncoded())); + } +}