aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoetz Lindenmaier <goetz@openjdk.org>2024-04-17 11:55:46 +0000
committerGoetz Lindenmaier <goetz@openjdk.org>2024-04-17 11:55:46 +0000
commit30ea06c9c4c223f41d8a6bcd12a07cc8a8e1ed76 (patch)
tree915845454a7fac9f322a32f626b358c0a24a233f
parent290fb644baf033dac21bd3935ff6dc1e9b27de3d (diff)
parent1c40f899c9c736998ba38e805d88361e53511c64 (diff)
downloadlibcore-30ea06c9c4c223f41d8a6bcd12a07cc8a8e1ed76.tar.gz
Merge
-rw-r--r--src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp8
-rw-r--r--src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp8
-rw-r--r--src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp8
-rw-r--r--src/hotspot/share/classfile/javaClasses.cpp29
-rw-r--r--src/hotspot/share/classfile/javaClasses.hpp8
-rw-r--r--src/hotspot/share/classfile/resolutionErrors.cpp23
-rw-r--r--src/hotspot/share/classfile/resolutionErrors.hpp21
-rw-r--r--src/hotspot/share/classfile/systemDictionary.cpp6
-rw-r--r--src/hotspot/share/classfile/systemDictionary.hpp4
-rw-r--r--src/hotspot/share/oops/constantPool.cpp38
-rw-r--r--src/hotspot/share/oops/cpCache.cpp4
-rw-r--r--src/hotspot/share/utilities/exceptions.cpp6
-rw-r--r--src/java.base/share/classes/sun/security/rsa/RSAPrivateCrtKeyImpl.java8
-rw-r--r--src/java.base/share/classes/sun/security/rsa/RSAPrivateKeyImpl.java8
-rw-r--r--src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java12
-rw-r--r--src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKey.java18
-rw-r--r--src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPrivateKey.java12
-rw-r--r--src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java19
18 files changed, 114 insertions, 126 deletions
diff --git a/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp
index d2cbdbdba26..209f50efe8f 100644
--- a/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -167,8 +167,10 @@ LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
if (index->is_register()) {
// apply the shift and accumulate the displacement
if (shift > 0) {
- LIR_Opr tmp = new_pointer_register();
- __ shift_left(index, shift, tmp);
+ // Use long register to avoid overflow when shifting large index values left.
+ LIR_Opr tmp = new_register(T_LONG);
+ __ convert(Bytecodes::_i2l, index, tmp);
+ __ shift_left(tmp, shift, tmp);
index = tmp;
}
if (large_disp != 0) {
diff --git a/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp b/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp
index 2c685920367..0a5ab12d3a4 100644
--- a/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp
+++ b/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -164,8 +164,10 @@ LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
if (index->is_register()) {
// Apply the shift and accumulate the displacement.
if (shift > 0) {
- LIR_Opr tmp = new_pointer_register();
- __ shift_left(index, shift, tmp);
+ // Use long register to avoid overflow when shifting large index values left.
+ LIR_Opr tmp = new_register(T_LONG);
+ __ convert(Bytecodes::_i2l, index, tmp);
+ __ shift_left(tmp, shift, tmp);
index = tmp;
}
if (large_disp != 0) {
diff --git a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
index c6d5085079f..67d838bdcea 100644
--- a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
+++ b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -157,8 +157,10 @@ LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
return new LIR_Address(base, index, type);
} else {
if (shift > 0) {
- LIR_Opr tmp = new_pointer_register();
- __ shift_left(index, shift, tmp);
+ // Use long register to avoid overflow when shifting large index values left.
+ LIR_Opr tmp = new_register(T_LONG);
+ __ convert(Bytecodes::_i2l, index, tmp);
+ __ shift_left(tmp, shift, tmp);
index = tmp;
}
return new LIR_Address(base, index, disp, type);
diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp
index d5c31932e31..bf817989dc1 100644
--- a/src/hotspot/share/classfile/javaClasses.cpp
+++ b/src/hotspot/share/classfile/javaClasses.cpp
@@ -2076,18 +2076,17 @@ oop java_lang_Throwable::message(oop throwable) {
return throwable->obj_field(_detailMessage_offset);
}
-oop java_lang_Throwable::cause(oop throwable) {
- return throwable->obj_field(_cause_offset);
+const char* java_lang_Throwable::message_as_utf8(oop throwable) {
+ oop msg = java_lang_Throwable::message(throwable);
+ const char* msg_utf8 = nullptr;
+ if (msg != nullptr) {
+ msg_utf8 = java_lang_String::as_utf8_string(msg);
+ }
+ return msg_utf8;
}
-// Return Symbol for detailed_message or NULL
-Symbol* java_lang_Throwable::detail_message(oop throwable) {
- PreserveExceptionMark pm(Thread::current());
- oop detailed_message = java_lang_Throwable::message(throwable);
- if (detailed_message != NULL) {
- return java_lang_String::as_symbol(detailed_message);
- }
- return NULL;
+oop java_lang_Throwable::cause(oop throwable) {
+ return throwable->obj_field(_cause_offset);
}
void java_lang_Throwable::set_message(oop throwable, oop value) {
@@ -2739,15 +2738,19 @@ Handle java_lang_Throwable::create_initialization_error(JavaThread* current, Han
assert(throwable.not_null(), "shouldn't be");
// Now create the message from the original exception and thread name.
- Symbol* message = java_lang_Throwable::detail_message(throwable());
ResourceMark rm(current);
stringStream st;
+ const char *message = nullptr;
+ oop detailed_message = java_lang_Throwable::message(throwable());
+ if (detailed_message != nullptr) {
+ message = java_lang_String::as_utf8_string(detailed_message);
+ }
st.print("Exception %s%s ", throwable()->klass()->name()->as_klass_external_name(),
message == nullptr ? "" : ":");
- if (message == NULL) {
+ if (message == nullptr) {
st.print("[in thread \"%s\"]", current->name());
} else {
- st.print("%s [in thread \"%s\"]", message->as_C_string(), current->name());
+ st.print("%s [in thread \"%s\"]", message, current->name());
}
Symbol* exception_name = vmSymbols::java_lang_ExceptionInInitializerError();
diff --git a/src/hotspot/share/classfile/javaClasses.hpp b/src/hotspot/share/classfile/javaClasses.hpp
index 4a3d37e50dc..f1883878141 100644
--- a/src/hotspot/share/classfile/javaClasses.hpp
+++ b/src/hotspot/share/classfile/javaClasses.hpp
@@ -549,12 +549,14 @@ class java_lang_Throwable: AllStatic {
static void set_backtrace(oop throwable, oop value);
static int depth(oop throwable);
static void set_depth(oop throwable, int value);
- static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
// Message
+ static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
static oop message(oop throwable);
- static oop cause(oop throwable);
+ static const char* message_as_utf8(oop throwable);
static void set_message(oop throwable, oop value);
- static Symbol* detail_message(oop throwable);
+
+ static oop cause(oop throwable);
+
static void print_stack_element(outputStream *st, Method* method, int bci);
static void compute_offsets();
diff --git a/src/hotspot/share/classfile/resolutionErrors.cpp b/src/hotspot/share/classfile/resolutionErrors.cpp
index 24a5bcab3a8..4e647871d2a 100644
--- a/src/hotspot/share/classfile/resolutionErrors.cpp
+++ b/src/hotspot/share/classfile/resolutionErrors.cpp
@@ -36,8 +36,8 @@
// create new error entry
void ResolutionErrorTable::add_entry(int index, unsigned int hash,
const constantPoolHandle& pool, int cp_index,
- Symbol* error, Symbol* message,
- Symbol* cause, Symbol* cause_msg)
+ Symbol* error, const char* message,
+ Symbol* cause, const char* cause_msg)
{
assert_locked_or_safepoint(SystemDictionary_lock);
assert(!pool.is_null() && error != NULL, "adding NULL obj");
@@ -95,11 +95,8 @@ void ResolutionErrorEntry::set_error(Symbol* e) {
}
}
-void ResolutionErrorEntry::set_message(Symbol* c) {
- _message = c;
- if (_message != NULL) {
- _message->increment_refcount();
- }
+void ResolutionErrorEntry::set_message(const char* c) {
+ _message = c != nullptr ? os::strdup(c) : nullptr;
}
void ResolutionErrorEntry::set_cause(Symbol* c) {
@@ -109,13 +106,11 @@ void ResolutionErrorEntry::set_cause(Symbol* c) {
}
}
-void ResolutionErrorEntry::set_cause_msg(Symbol* c) {
- _cause_msg = c;
- if (_cause_msg != NULL) {
- _cause_msg->increment_refcount();
- }
+void ResolutionErrorEntry::set_cause_msg(const char* c) {
+ _cause_msg = c != nullptr ? os::strdup(c) : nullptr;
}
+// The incoming nest host error message is already in the C-Heap.
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
_nest_host_error = message;
}
@@ -126,13 +121,13 @@ void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
entry->error()->decrement_refcount();
}
if (entry->message() != NULL) {
- entry->message()->decrement_refcount();
+ FREE_C_HEAP_ARRAY(char, entry->message());
}
if (entry->cause() != NULL) {
entry->cause()->decrement_refcount();
}
if (entry->cause_msg() != NULL) {
- entry->cause_msg()->decrement_refcount();
+ FREE_C_HEAP_ARRAY(char, entry->cause_msg());
}
if (entry->nest_host_error() != NULL) {
FREE_C_HEAP_ARRAY(char, entry->nest_host_error());
diff --git a/src/hotspot/share/classfile/resolutionErrors.hpp b/src/hotspot/share/classfile/resolutionErrors.hpp
index 8a9c9951ba1..31a56385860 100644
--- a/src/hotspot/share/classfile/resolutionErrors.hpp
+++ b/src/hotspot/share/classfile/resolutionErrors.hpp
@@ -61,11 +61,11 @@ public:
}
void add_entry(int index, unsigned int hash,
- const constantPoolHandle& pool, int which, Symbol* error, Symbol* message,
- Symbol* cause, Symbol* cause_msg);
+ const constantPoolHandle& pool, int cp_index, Symbol* error, const char* error_msg,
+ Symbol* cause, const char* cause_msg);
void add_entry(int index, unsigned int hash,
- const constantPoolHandle& pool, int which, const char* message);
+ const constantPoolHandle& pool, int cp_index, const char* message);
// find error given the constant pool and constant pool index
ResolutionErrorEntry* find_entry(int index, unsigned int hash,
@@ -96,9 +96,9 @@ class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> {
private:
int _cp_index;
Symbol* _error;
- Symbol* _message;
+ const char* _message;
Symbol* _cause;
- Symbol* _cause_msg;
+ const char* _cause_msg;
const char* _nest_host_error;
public:
@@ -110,16 +110,19 @@ class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> {
Symbol* error() const { return _error; }
void set_error(Symbol* e);
- Symbol* message() const { return _message; }
- void set_message(Symbol* c);
+ const char* message() const { return _message; }
+ // The incoming message is copied to the C-Heap.
+ void set_message(const char* c);
Symbol* cause() const { return _cause; }
void set_cause(Symbol* c);
- Symbol* cause_msg() const { return _cause_msg; }
- void set_cause_msg(Symbol* c);
+ const char* cause_msg() const { return _cause_msg; }
+ // The incoming cause_msg is copied to the C-Heap.
+ void set_cause_msg(const char* c);
const char* nest_host_error() const { return _nest_host_error; }
+ // The incoming nest host error message is already in the C-Heap.
void set_nest_host_error(const char* message);
ResolutionErrorEntry* next() const {
diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp
index 3d476eba09b..96fbf375bca 100644
--- a/src/hotspot/share/classfile/systemDictionary.cpp
+++ b/src/hotspot/share/classfile/systemDictionary.cpp
@@ -1846,8 +1846,8 @@ bool SystemDictionary::add_loader_constraint(Symbol* class_name,
// Add entry to resolution error table to record the error when the first
// attempt to resolve a reference to a class has failed.
void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int which,
- Symbol* error, Symbol* message,
- Symbol* cause, Symbol* cause_msg) {
+ Symbol* error, const char* message,
+ Symbol* cause, const char* cause_msg) {
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
@@ -1866,7 +1866,7 @@ void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
// Lookup resolution error table. Returns error if found, otherwise NULL.
Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool, int which,
- Symbol** message, Symbol** cause, Symbol** cause_msg) {
+ const char** message, Symbol** cause, const char** cause_msg) {
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
diff --git a/src/hotspot/share/classfile/systemDictionary.hpp b/src/hotspot/share/classfile/systemDictionary.hpp
index f4d40685ddc..a075e4de38b 100644
--- a/src/hotspot/share/classfile/systemDictionary.hpp
+++ b/src/hotspot/share/classfile/systemDictionary.hpp
@@ -281,10 +281,10 @@ public:
// Record the error when the first attempt to resolve a reference from a constant
// pool entry to a class fails.
static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error,
- Symbol* message, Symbol* cause = NULL, Symbol* cause_msg = NULL);
+ const char* message, Symbol* cause = NULL, const char* cause_msg = NULL);
static void delete_resolution_error(ConstantPool* pool);
static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
- Symbol** message, Symbol** cause, Symbol** cause_msg);
+ const char** message, Symbol** cause, const char** cause_msg);
// Record a nest host resolution/validation error
diff --git a/src/hotspot/share/oops/constantPool.cpp b/src/hotspot/share/oops/constantPool.cpp
index a97f2fe8d02..53e166c0c69 100644
--- a/src/hotspot/share/oops/constantPool.cpp
+++ b/src/hotspot/share/oops/constantPool.cpp
@@ -767,13 +767,16 @@ void ConstantPool::resolve_string_constants_impl(const constantPoolHandle& this_
}
}
-static Symbol* exception_message(const constantPoolHandle& this_cp, int which, constantTag tag, oop pending_exception) {
+static const char* exception_message(const constantPoolHandle& this_cp, int which, constantTag tag, oop pending_exception) {
+ // Note: caller needs ResourceMark
+
// Dig out the detailed message to reuse if possible
- Symbol* message = java_lang_Throwable::detail_message(pending_exception);
- if (message != NULL) {
- return message;
+ const char* msg = java_lang_Throwable::message_as_utf8(pending_exception);
+ if (msg != nullptr) {
+ return msg;
}
+ Symbol* message = nullptr;
// Return specific message for the tag
switch (tag.value()) {
case JVM_CONSTANT_UnresolvedClass:
@@ -796,49 +799,48 @@ static Symbol* exception_message(const constantPoolHandle& this_cp, int which, c
ShouldNotReachHere();
}
- return message;
+ return message != nullptr ? message->as_C_string() : nullptr;
}
-static void add_resolution_error(const constantPoolHandle& this_cp, int which,
+static void add_resolution_error(JavaThread* current, const constantPoolHandle& this_cp, int which,
constantTag tag, oop pending_exception) {
+ ResourceMark rm(current);
Symbol* error = pending_exception->klass()->name();
oop cause = java_lang_Throwable::cause(pending_exception);
// Also dig out the exception cause, if present.
Symbol* cause_sym = NULL;
- Symbol* cause_msg = NULL;
+ const char* cause_msg = nullptr;
if (cause != NULL && cause != pending_exception) {
cause_sym = cause->klass()->name();
- cause_msg = java_lang_Throwable::detail_message(cause);
+ cause_msg = java_lang_Throwable::message_as_utf8(cause);
}
- Symbol* message = exception_message(this_cp, which, tag, pending_exception);
+ const char* message = exception_message(this_cp, which, tag, pending_exception);
SystemDictionary::add_resolution_error(this_cp, which, error, message, cause_sym, cause_msg);
}
void ConstantPool::throw_resolution_error(const constantPoolHandle& this_cp, int which, TRAPS) {
ResourceMark rm(THREAD);
- Symbol* message = NULL;
+ const char* message = NULL;
Symbol* cause = NULL;
- Symbol* cause_msg = NULL;
+ const char* cause_msg = NULL;
Symbol* error = SystemDictionary::find_resolution_error(this_cp, which, &message, &cause, &cause_msg);
assert(error != NULL, "checking");
- const char* cause_str = cause_msg != NULL ? cause_msg->as_C_string() : NULL;
CLEAR_PENDING_EXCEPTION;
if (message != NULL) {
- char* msg = message->as_C_string();
if (cause != NULL) {
- Handle h_cause = Exceptions::new_exception(THREAD, cause, cause_str);
- THROW_MSG_CAUSE(error, msg, h_cause);
+ Handle h_cause = Exceptions::new_exception(THREAD, cause, cause_msg);
+ THROW_MSG_CAUSE(error, message, h_cause);
} else {
- THROW_MSG(error, msg);
+ THROW_MSG(error, message);
}
} else {
if (cause != NULL) {
- Handle h_cause = Exceptions::new_exception(THREAD, cause, cause_str);
+ Handle h_cause = Exceptions::new_exception(THREAD, cause, cause_msg);
THROW_CAUSE(error, h_cause);
} else {
THROW(error);
@@ -860,7 +862,7 @@ void ConstantPool::save_and_throw_exception(const constantPoolHandle& this_cp, i
// and OutOfMemoryError, etc, or if the thread was hit by stop()
// Needs clarification to section 5.4.3 of the VM spec (see 6308271)
} else if (this_cp->tag_at(which).value() != error_tag) {
- add_resolution_error(this_cp, which, tag, PENDING_EXCEPTION);
+ add_resolution_error(THREAD, this_cp, which, tag, PENDING_EXCEPTION);
// CAS in the tag. If a thread beat us to registering this error that's fine.
// If another thread resolved the reference, this is a race condition. This
// thread may have had a security manager or something temporary.
diff --git a/src/hotspot/share/oops/cpCache.cpp b/src/hotspot/share/oops/cpCache.cpp
index 40ca7d7efc6..9fdf69e057d 100644
--- a/src/hotspot/share/oops/cpCache.cpp
+++ b/src/hotspot/share/oops/cpCache.cpp
@@ -497,9 +497,9 @@ bool ConstantPoolCacheEntry::save_and_throw_indy_exc(
CLEAR_PENDING_EXCEPTION;
return false;
}
-
+ ResourceMark rm(THREAD);
Symbol* error = PENDING_EXCEPTION->klass()->name();
- Symbol* message = java_lang_Throwable::detail_message(PENDING_EXCEPTION);
+ const char* message = java_lang_Throwable::message_as_utf8(PENDING_EXCEPTION);
SystemDictionary::add_resolution_error(cpool, index, error, message);
set_indy_resolution_failed();
diff --git a/src/hotspot/share/utilities/exceptions.cpp b/src/hotspot/share/utilities/exceptions.cpp
index bd95b8306be..d65f5bcfafd 100644
--- a/src/hotspot/share/utilities/exceptions.cpp
+++ b/src/hotspot/share/utilities/exceptions.cpp
@@ -563,11 +563,11 @@ void Exceptions::debug_check_abort_helper(Handle exception, const char* message)
// for logging exceptions
void Exceptions::log_exception(Handle exception, const char* message) {
ResourceMark rm;
- Symbol* detail_message = java_lang_Throwable::detail_message(exception());
- if (detail_message != NULL) {
+ const char* detail_message = java_lang_Throwable::message_as_utf8(exception());
+ if (detail_message != nullptr) {
log_info(exceptions)("Exception <%s: %s>\n thrown in %s",
exception->print_value_string(),
- detail_message->as_C_string(),
+ detail_message,
message);
} else {
log_info(exceptions)("Exception <%s>\n thrown in %s",
diff --git a/src/java.base/share/classes/sun/security/rsa/RSAPrivateCrtKeyImpl.java b/src/java.base/share/classes/sun/security/rsa/RSAPrivateCrtKeyImpl.java
index 4c5af4b953c..dca389eadad 100644
--- a/src/java.base/share/classes/sun/security/rsa/RSAPrivateCrtKeyImpl.java
+++ b/src/java.base/share/classes/sun/security/rsa/RSAPrivateCrtKeyImpl.java
@@ -306,14 +306,6 @@ public final class RSAPrivateCrtKeyImpl
return keyParams;
}
- // return a string representation of this key for debugging
- @Override
- public String toString() {
- return "SunRsaSign " + type.keyAlgo + " private CRT key, "
- + n.bitLength() + " bits" + "\n params: " + keyParams
- + "\n modulus: " + n + "\n private exponent: " + d;
- }
-
// utility method for parsing DER encoding of RSA private keys in PKCS#1
// format as defined in RFC 8017 Appendix A.1.2, i.e. SEQ of version, n,
// e, d, p, q, pe, qe, and coeff, and return the parsed components.
diff --git a/src/java.base/share/classes/sun/security/rsa/RSAPrivateKeyImpl.java b/src/java.base/share/classes/sun/security/rsa/RSAPrivateKeyImpl.java
index 5a645c7e887..a79b01445e9 100644
--- a/src/java.base/share/classes/sun/security/rsa/RSAPrivateKeyImpl.java
+++ b/src/java.base/share/classes/sun/security/rsa/RSAPrivateKeyImpl.java
@@ -143,14 +143,6 @@ public final class RSAPrivateKeyImpl extends PKCS8Key implements RSAPrivateKey {
return keyParams;
}
- // return a string representation of this key for debugging
- @Override
- public String toString() {
- return "Sun " + type.keyAlgo + " private key, " + n.bitLength()
- + " bits" + "\n params: " + keyParams + "\n modulus: " + n
- + "\n private exponent: " + d;
- }
-
/**
* Restores the state of this object from the stream.
* <p>
diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java b/src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java
index 6c31b8b87e4..a13aadd07c7 100644
--- a/src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/ConnectionPool.java
@@ -103,14 +103,10 @@ final class ConnectionPool {
return false;
}
if (secure && destination != null) {
- if (destination.getHostName() != null) {
- if (!destination.getHostName().equalsIgnoreCase(
- other.destination.getHostName())) {
- return false;
- }
- } else {
- if (other.destination.getHostName() != null)
- return false;
+ String hostString = destination.getHostString();
+ if (hostString == null || !hostString.equalsIgnoreCase(
+ other.destination.getHostString())) {
+ return false;
}
}
return true;
diff --git a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKey.java b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKey.java
index fe0fac5f10a..801d2ad0b59 100644
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKey.java
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CKey.java
@@ -75,10 +75,14 @@ abstract class CKey implements Key, Length {
protected final String algorithm;
- protected CKey(String algorithm, NativeHandles handles, int keyLength) {
+ private final boolean isPublic;
+
+ protected CKey(String algorithm, NativeHandles handles, int keyLength,
+ boolean isPublic) {
this.algorithm = algorithm;
this.handles = handles;
this.keyLength = keyLength;
+ this.isPublic = isPublic;
}
// Native method to cleanup the key handle.
@@ -101,6 +105,18 @@ abstract class CKey implements Key, Length {
return algorithm;
}
+ public String toString() {
+ String typeStr;
+ if (handles.hCryptKey != 0) {
+ typeStr = getKeyType(handles.hCryptKey) + ", container=" +
+ getContainerName(handles.hCryptProv);
+ } else {
+ typeStr = "CNG";
+ }
+ return algorithm + " " + (isPublic ? "PublicKey" : "PrivateKey") +
+ " [size=" + keyLength + " bits, type=" + typeStr + "]";
+ }
+
protected native static String getContainerName(long hCryptProv);
protected native static String getKeyType(long hCryptKey);
diff --git a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPrivateKey.java b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPrivateKey.java
index 91a7775b8bd..c3882616615 100644
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPrivateKey.java
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPrivateKey.java
@@ -42,7 +42,7 @@ class CPrivateKey extends CKey implements PrivateKey {
private static final long serialVersionUID = 8113152807912338063L;
private CPrivateKey(String alg, NativeHandles handles, int keyLength) {
- super(alg, handles, keyLength);
+ super(alg, handles, keyLength, false);
}
// Called by native code inside security.cpp
@@ -65,16 +65,6 @@ class CPrivateKey extends CKey implements PrivateKey {
return null;
}
- public String toString() {
- if (handles.hCryptKey != 0) {
- return algorithm + "PrivateKey [size=" + keyLength + " bits, type=" +
- getKeyType(handles.hCryptKey) + ", container=" +
- getContainerName(handles.hCryptProv) + "]";
- } else {
- return algorithm + "PrivateKey [size=" + keyLength + " bits, type=CNG]";
- }
- }
-
// This class is not serializable
@java.io.Serial
private void writeObject(java.io.ObjectOutputStream out)
diff --git a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java
index efbd74c5bb8..7f02aa5c651 100644
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java
@@ -113,9 +113,8 @@ public abstract class CPublicKey extends CKey implements PublicKey {
}
public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(algorithm).append("PublicKey [size=").append(keyLength)
- .append("]\n ECPoint: ").append(getW())
+ StringBuffer sb = new StringBuffer(super.toString());
+ sb.append("\n ECPoint: ").append(getW())
.append("\n params: ").append(getParams());
return sb.toString();
}
@@ -134,16 +133,8 @@ public abstract class CPublicKey extends CKey implements PublicKey {
}
public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(algorithm).append("PublicKey [size=").append(keyLength)
- .append(" bits, type=");
- if (handles.hCryptKey != 0) {
- sb.append(getKeyType(handles.hCryptKey))
- .append(", container=").append(getContainerName(handles.hCryptProv));
- } else {
- sb.append("CNG");
- }
- sb.append("]\n modulus: ").append(getModulus())
+ StringBuffer sb = new StringBuffer(super.toString());
+ sb.append("\n modulus: ").append(getModulus())
.append("\n public exponent: ").append(getPublicExponent());
return sb.toString();
}
@@ -214,7 +205,7 @@ public abstract class CPublicKey extends CKey implements PublicKey {
protected CPublicKey(
String alg, NativeHandles handles, int keyLength) {
- super(alg, handles, keyLength);
+ super(alg, handles, keyLength, true);
}
@Override