Skip to content

Commit 160b21b

Browse files
committed
backport 1748737b99f283f69b4be0910b6623a27d804e68
1 parent 8aff9c2 commit 160b21b

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

src/hotspot/share/classfile/resolutionErrors.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ void ResolutionErrorEntry::set_cause_msg(const char* c) {
112112

113113
// The incoming nest host error message is already in the C-Heap.
114114
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
115-
// If a message is already set, free it.
116-
if (nest_host_error() != nullptr) {
117-
FREE_C_HEAP_ARRAY(char, _nest_host_error);
118-
}
115+
assert(_nest_host_error == nullptr, "caller should have checked");
119116
init_nest_host_error(message);
120117
}
121118

122119
void ResolutionErrorEntry::init_nest_host_error(const char* message) {
120+
assert_lock_strong(SystemDictionary_lock);
123121
_nest_host_error = message;
124122
}
125123

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool,
18891889
// be updated with the nest host error message.
18901890
void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18911891
int which,
1892-
const char* message) {
1892+
const stringStream& message) {
18931893
unsigned int hash = resolution_errors()->compute_hash(pool, which);
18941894
int index = resolution_errors()->hash_to_index(hash);
18951895
{
@@ -1900,14 +1900,19 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
19001900
// constant pool index. In this case resolution succeeded but there's an error in this nest host
19011901
// that we use the table to record.
19021902
assert(pool->resolved_klass_at(which) != nullptr, "klass should be resolved if there is no entry");
1903-
resolution_errors()->add_entry(index, hash, pool, which, message);
1903+
resolution_errors()->add_entry(index, hash, pool, which, message.as_string(true /* on C-heap */));
19041904
} else {
19051905
// An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
19061906
// still want to add the error message for the higher-level access checks to report. We should
19071907
// only reach here under the same error condition, so we can ignore the potential race with setting
1908-
// the message, and set it again.
1909-
assert(entry->nest_host_error() == nullptr || strcmp(entry->nest_host_error(), message) == 0, "should be the same message");
1910-
entry->set_nest_host_error(message);
1908+
// the message.
1909+
const char* nhe = entry->nest_host_error();
1910+
if (nhe == nullptr) {
1911+
entry->set_nest_host_error(message.as_string(true /* on C-heap */));
1912+
} else {
1913+
DEBUG_ONLY(const char* msg = message.base();)
1914+
assert(strcmp(nhe, msg) == 0, "New message %s, differs from original %s", msg, nhe);
1915+
}
19111916
}
19121917
}
19131918
}

src/hotspot/share/classfile/systemDictionary.hpp

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

290290
// Record a nest host resolution/validation error
291291
static void add_nest_host_error(const constantPoolHandle& pool, int which,
292-
const char* message);
292+
const stringStream& message);
293293
static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
294294

295295
private:

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,11 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
280280
ss.print("Nest host resolution of %s with host %s failed: ",
281281
this->external_name(), target_host_class);
282282
java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
283-
const char* msg = ss.as_string(true /* on C-heap */);
284283
constantPoolHandle cph(THREAD, constants());
285-
SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg);
284+
SystemDictionary::add_nest_host_error(cph, _nest_host_index, ss);
286285
CLEAR_PENDING_EXCEPTION;
287286

288-
log_trace(class, nestmates)("%s", msg);
287+
log_trace(class, nestmates)("%s", ss.base());
289288
} else {
290289
// A valid nest-host is an instance class in the current package that lists this
291290
// class as a nest member. If any of these conditions are not met the class is
@@ -324,10 +323,9 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
324323
k->external_name(),
325324
k->class_loader_data()->loader_name_and_id(),
326325
error);
327-
const char* msg = ss.as_string(true /* on C-heap */);
328326
constantPoolHandle cph(THREAD, constants());
329-
SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg);
330-
log_trace(class, nestmates)("%s", msg);
327+
SystemDictionary::add_nest_host_error(cph, _nest_host_index, ss);
328+
log_trace(class, nestmates)("%s", ss.base());
331329
}
332330
}
333331
} else {

0 commit comments

Comments
 (0)