Skip to content

Commit 02e8bc6

Browse files
committed
backport 8ed7c23fa02f7c40cceefb24f92a3df281d12c4f
1 parent d39baa5 commit 02e8bc6

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/hotspot/share/classfile/resolutionErrors.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void ResolutionErrorTable::add_entry(int index, unsigned int hash,
4646
entry->set_cp_index(cp_index);
4747
entry->set_error(error);
4848
entry->set_message(message);
49-
entry->set_nest_host_error(NULL);
49+
entry->init_nest_host_error(NULL);
5050
entry->set_cause(cause);
5151
entry->set_cause_msg(cause_msg);
5252

@@ -62,8 +62,11 @@ void ResolutionErrorTable::add_entry(int index, unsigned int hash,
6262
assert(!pool.is_null() && message != NULL, "adding NULL obj");
6363

6464
ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool());
65+
tty->print("GLGL: %d, " INTPTR_FORMAT ", " INTPTR_FORMAT "\n", entry->cp_index(), p2i(entry->cause_msg()), p2i(entry->nest_host_error()));
66+
67+
6568
entry->set_cp_index(cp_index);
66-
entry->set_nest_host_error(message);
69+
entry->init_nest_host_error(message);
6770
entry->set_error(NULL);
6871
entry->set_message(NULL);
6972
entry->set_cause(NULL);
@@ -112,6 +115,14 @@ void ResolutionErrorEntry::set_cause_msg(const char* c) {
112115

113116
// The incoming nest host error message is already in the C-Heap.
114117
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
118+
// If a message is already set, free it.
119+
if (nest_host_error() != nullptr) {
120+
FREE_C_HEAP_ARRAY(char, _nest_host_error);
121+
}
122+
init_nest_host_error(message);
123+
}
124+
125+
void ResolutionErrorEntry::init_nest_host_error(const char* message) {
115126
_nest_host_error = message;
116127
}
117128

src/hotspot/share/classfile/resolutionErrors.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> {
122122
void set_cause_msg(const char* c);
123123

124124
const char* nest_host_error() const { return _nest_host_error; }
125+
void init_nest_host_error(const char* message);
125126
// The incoming nest host error message is already in the C-Heap.
126127
void set_nest_host_error(const char* message);
127128

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,14 +1895,19 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18951895
{
18961896
MutexLocker ml(Thread::current(), SystemDictionary_lock);
18971897
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1898-
if (entry != NULL && entry->nest_host_error() == NULL) {
1898+
if (entry == NULL) {
1899+
// Only add a new entry to the resolution error table if one hasn't been found for this
1900+
// constant pool index. In this case resolution succeeded but there's an error in this nest host
1901+
// that we use the table to record.
1902+
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);
1904+
} else {
18991905
// An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
19001906
// still want to add the error message for the higher-level access checks to report. We should
19011907
// only reach here under the same error condition, so we can ignore the potential race with setting
1902-
// the message. If we see it is already set then we can ignore it.
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");
19031910
entry->set_nest_host_error(message);
1904-
} else {
1905-
resolution_errors()->add_entry(index, hash, pool, which, message);
19061911
}
19071912
}
19081913
}

0 commit comments

Comments
 (0)