Skip to content

Commit 1748737

Browse files
author
David Holmes
committed
8372988: Test runtime/Nestmates/membership/TestNestHostErrorWithMultiThread.java failed: Unexpected interrupt
Reviewed-by: coleenp, iklam, jsjolen
1 parent 317788f commit 1748737

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/hotspot/share/classfile/resolutionErrors.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ ResolutionErrorEntry::~ResolutionErrorEntry() {
127127
}
128128

129129
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
130-
// If a message is already set, free it.
131-
if (nest_host_error() != nullptr) {
132-
FREE_C_HEAP_ARRAY(char, _nest_host_error);
133-
}
130+
assert(_nest_host_error == nullptr, "caller should have checked");
131+
assert_lock_strong(SystemDictionary_lock);
134132
_nest_host_error = message;
135133
}
136134

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool,
18591859

18601860
void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18611861
int which,
1862-
const char* message) {
1862+
const stringStream& message) {
18631863
{
18641864
MutexLocker ml(Thread::current(), SystemDictionary_lock);
18651865
ResolutionErrorEntry* entry = ResolutionErrorTable::find_entry(pool, which);
@@ -1868,14 +1868,19 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18681868
// constant pool index. In this case resolution succeeded but there's an error in this nest host
18691869
// that we use the table to record.
18701870
assert(pool->resolved_klass_at(which) != nullptr, "klass should be resolved if there is no entry");
1871-
ResolutionErrorTable::add_entry(pool, which, message);
1871+
ResolutionErrorTable::add_entry(pool, which, message.as_string(true /* on C-heap */));
18721872
} else {
18731873
// An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
18741874
// still want to add the error message for the higher-level access checks to report. We should
18751875
// only reach here under the same error condition, so we can ignore the potential race with setting
1876-
// the message, and set it again.
1877-
assert(entry->nest_host_error() == nullptr || strcmp(entry->nest_host_error(), message) == 0, "should be the same message");
1878-
entry->set_nest_host_error(message);
1876+
// the message.
1877+
const char* nhe = entry->nest_host_error();
1878+
if (nhe == nullptr) {
1879+
entry->set_nest_host_error(message.as_string(true /* on C-heap */));
1880+
} else {
1881+
DEBUG_ONLY(const char* msg = message.base();)
1882+
assert(strcmp(nhe, msg) == 0, "New message %s, differs from original %s", msg, nhe);
1883+
}
18791884
}
18801885
}
18811886
}

src/hotspot/share/classfile/systemDictionary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class SystemDictionary : AllStatic {
280280

281281
// Record a nest host resolution/validation error
282282
static void add_nest_host_error(const constantPoolHandle& pool, int which,
283-
const char* message);
283+
const stringStream& message);
284284
static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
285285

286286
static void add_to_initiating_loader(JavaThread* current, InstanceKlass* k,

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,11 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
312312
ss.print("Nest host resolution of %s with host %s failed: ",
313313
this->external_name(), target_host_class);
314314
java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
315-
const char* msg = ss.as_string(true /* on C-heap */);
316315
constantPoolHandle cph(THREAD, constants());
317-
SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg);
316+
SystemDictionary::add_nest_host_error(cph, _nest_host_index, ss);
318317
CLEAR_PENDING_EXCEPTION;
319318

320-
log_trace(class, nestmates)("%s", msg);
319+
log_trace(class, nestmates)("%s", ss.base());
321320
} else {
322321
// A valid nest-host is an instance class in the current package that lists this
323322
// class as a nest member. If any of these conditions are not met the class is
@@ -356,10 +355,9 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
356355
k->external_name(),
357356
k->class_loader_data()->loader_name_and_id(),
358357
error);
359-
const char* msg = ss.as_string(true /* on C-heap */);
360358
constantPoolHandle cph(THREAD, constants());
361-
SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg);
362-
log_trace(class, nestmates)("%s", msg);
359+
SystemDictionary::add_nest_host_error(cph, _nest_host_index, ss);
360+
log_trace(class, nestmates)("%s", ss.base());
363361
}
364362
}
365363
} else {

0 commit comments

Comments
 (0)