Skip to content

Commit c463264

Browse files
committed
8258048: Placeholder hash code is the same as Dictionary hash code
Reviewed-by: dholmes, hseigel, lfoltan
1 parent ab5d581 commit c463264

File tree

8 files changed

+102
-128
lines changed

8 files changed

+102
-128
lines changed

src/hotspot/share/classfile/dictionary.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ InstanceKlass* Dictionary::find(unsigned int hash, Symbol* name,
296296
}
297297
}
298298

299-
InstanceKlass* Dictionary::find_class(int index, unsigned int hash,
299+
InstanceKlass* Dictionary::find_class(unsigned int hash,
300300
Symbol* name) {
301301
assert_locked_or_safepoint(SystemDictionary_lock);
302+
303+
int index = hash_to_index(hash);
302304
assert (index == index_for(name), "incorrect index?");
303305

304306
DictionaryEntry* entry = get_entry(index, hash, name);

src/hotspot/share/classfile/dictionary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Dictionary : public Hashtable<InstanceKlass*, mtClass> {
6060

6161
void add_klass(unsigned int hash, Symbol* class_name, InstanceKlass* obj);
6262

63-
InstanceKlass* find_class(int index, unsigned int hash, Symbol* name);
63+
InstanceKlass* find_class(unsigned int hash, Symbol* name);
6464

6565
void classes_do(void f(InstanceKlass*));
6666
void classes_do(void f(InstanceKlass*, TRAPS), TRAPS);

src/hotspot/share/classfile/loaderConstraints.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -440,20 +440,16 @@ void LoaderConstraintTable::verify(PlaceholderTable* placeholders) {
440440
Symbol* name = ik->name();
441441
ClassLoaderData* loader_data = ik->class_loader_data();
442442
Dictionary* dictionary = loader_data->dictionary();
443-
unsigned int d_hash = dictionary->compute_hash(name);
444-
int d_index = dictionary->hash_to_index(d_hash);
445-
InstanceKlass* k = dictionary->find_class(d_index, d_hash, name);
443+
unsigned int name_hash = dictionary->compute_hash(name);
444+
InstanceKlass* k = dictionary->find_class(name_hash, name);
446445
if (k != NULL) {
447446
// We found the class in the dictionary, so we should
448447
// make sure that the Klass* matches what we already have.
449448
guarantee(k == probe->klass(), "klass should be in dictionary");
450449
} else {
451450
// If we don't find the class in the dictionary, it
452451
// has to be in the placeholders table.
453-
unsigned int p_hash = placeholders->compute_hash(name);
454-
int p_index = placeholders->hash_to_index(p_hash);
455-
PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash,
456-
name, loader_data);
452+
PlaceholderEntry* entry = placeholders->get_entry(name_hash, name, loader_data);
457453

458454
// The InstanceKlass might not be on the entry, so the only
459455
// thing we can check here is whether we were successful in

src/hotspot/share/classfile/placeholders.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include "precompiled.hpp"
2626
#include "classfile/classLoaderData.inline.hpp"
2727
#include "classfile/placeholders.hpp"
28-
#include "classfile/systemDictionary.hpp"
29-
#include "oops/oop.inline.hpp"
28+
#include "runtime/mutexLocker.hpp"
3029
#include "utilities/hashtable.inline.hpp"
3130

3231
// Placeholder methods
@@ -61,26 +60,29 @@ void PlaceholderTable::free_entry(PlaceholderEntry* entry) {
6160
// All threads examining the placeholder table must hold the
6261
// SystemDictionary_lock, so we don't need special precautions
6362
// on store ordering here.
64-
void PlaceholderTable::add_entry(int index, unsigned int hash,
65-
Symbol* class_name, ClassLoaderData* loader_data,
66-
bool havesupername, Symbol* supername){
63+
PlaceholderEntry* PlaceholderTable::add_entry(unsigned int hash,
64+
Symbol* class_name, ClassLoaderData* loader_data,
65+
bool havesupername, Symbol* supername){
6766
assert_locked_or_safepoint(SystemDictionary_lock);
6867
assert(class_name != NULL, "adding NULL obj");
6968

7069
// Both readers and writers are locked so it's safe to just
7170
// create the placeholder and insert it in the list without a membar.
7271
PlaceholderEntry* entry = new_entry(hash, class_name, loader_data, havesupername, supername);
73-
add_entry(index, entry);
72+
int index = hash_to_index(hash);
73+
Hashtable<Symbol*, mtClass>::add_entry(index, entry);
74+
return entry;
7475
}
7576

7677

7778
// Remove a placeholder object.
78-
void PlaceholderTable::remove_entry(int index, unsigned int hash,
79+
void PlaceholderTable::remove_entry(unsigned int hash,
7980
Symbol* class_name,
8081
ClassLoaderData* loader_data) {
8182
assert_locked_or_safepoint(SystemDictionary_lock);
83+
int index = hash_to_index(hash);
8284
PlaceholderEntry** p = bucket_addr(index);
83-
while (*p) {
85+
while (*p != NULL) {
8486
PlaceholderEntry *probe = *p;
8587
if (probe->hash() == hash && probe->equals(class_name, loader_data)) {
8688
// Delete entry
@@ -92,11 +94,12 @@ void PlaceholderTable::remove_entry(int index, unsigned int hash,
9294
}
9395
}
9496

95-
PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash,
96-
Symbol* class_name,
97-
ClassLoaderData* loader_data) {
97+
PlaceholderEntry* PlaceholderTable::get_entry(unsigned int hash,
98+
Symbol* class_name,
99+
ClassLoaderData* loader_data) {
98100
assert_locked_or_safepoint(SystemDictionary_lock);
99101

102+
int index = hash_to_index(hash);
100103
for (PlaceholderEntry *place_probe = bucket(index);
101104
place_probe != NULL;
102105
place_probe = place_probe->next()) {
@@ -108,36 +111,35 @@ PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash,
108111
return NULL;
109112
}
110113

111-
Symbol* PlaceholderTable::find_entry(int index, unsigned int hash,
112-
Symbol* class_name,
113-
ClassLoaderData* loader_data) {
114-
PlaceholderEntry* probe = get_entry(index, hash, class_name, loader_data);
115-
return (probe? probe->klassname(): (Symbol*)NULL);
114+
Symbol* PlaceholderTable::find_entry(unsigned int hash,
115+
Symbol* class_name,
116+
ClassLoaderData* loader_data) {
117+
PlaceholderEntry* probe = get_entry(hash, class_name, loader_data);
118+
return (probe != NULL ? probe->klassname() : NULL);
116119
}
117120

118121
// find_and_add returns probe pointer - old or new
119122
// If no entry exists, add a placeholder entry
120123
// If entry exists, reuse entry
121124
// For both, push SeenThread for classloadAction
122125
// if havesupername: this is used for circularity for instanceklass loading
123-
PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash,
126+
PlaceholderEntry* PlaceholderTable::find_and_add(unsigned int hash,
124127
Symbol* name,
125128
ClassLoaderData* loader_data,
126129
classloadAction action,
127130
Symbol* supername,
128131
Thread* thread) {
129-
PlaceholderEntry* probe = get_entry(index, hash, name, loader_data);
132+
PlaceholderEntry* probe = get_entry(hash, name, loader_data);
130133
if (probe == NULL) {
131134
// Nothing found, add place holder
132-
add_entry(index, hash, name, loader_data, (action == LOAD_SUPER), supername);
133-
probe = get_entry(index, hash, name, loader_data);
135+
probe = add_entry(hash, name, loader_data, (action == LOAD_SUPER), supername);
134136
} else {
135137
if (action == LOAD_SUPER) {
136138
probe->set_havesupername(true);
137139
probe->set_supername(supername);
138140
}
139141
}
140-
if (probe) probe->add_seen_thread(thread, action);
142+
probe->add_seen_thread(thread, action);
141143
return probe;
142144
}
143145

@@ -155,18 +157,18 @@ PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash,
155157
// Note: you can be in both placeholders and systemDictionary
156158
// Therefore - must always check SD first
157159
// Ignores the case where entry is not found
158-
void PlaceholderTable::find_and_remove(int index, unsigned int hash,
160+
void PlaceholderTable::find_and_remove(unsigned int hash,
159161
Symbol* name, ClassLoaderData* loader_data,
160162
classloadAction action,
161163
Thread* thread) {
162164
assert_locked_or_safepoint(SystemDictionary_lock);
163-
PlaceholderEntry *probe = get_entry(index, hash, name, loader_data);
165+
PlaceholderEntry *probe = get_entry(hash, name, loader_data);
164166
if (probe != NULL) {
165167
probe->remove_seen_thread(thread, action);
166168
// If no other threads using this entry, and this thread is not using this entry for other states
167169
if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL)
168170
&& (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) {
169-
remove_entry(index, hash, name, loader_data);
171+
remove_entry(hash, name, loader_data);
170172
}
171173
}
172174
}

src/hotspot/share/classfile/placeholders.hpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,19 +50,16 @@ class PlaceholderTable : public Hashtable<Symbol*, mtClass> {
5050
return (PlaceholderEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
5151
}
5252

53-
void add_entry(int index, PlaceholderEntry* new_entry) {
54-
Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
55-
}
56-
57-
void add_entry(int index, unsigned int hash, Symbol* name,
58-
ClassLoaderData* loader_data, bool havesupername, Symbol* supername);
53+
PlaceholderEntry* add_entry(unsigned int hash, Symbol* name,
54+
ClassLoaderData* loader_data,
55+
bool havesupername, Symbol* supername);
5956

6057
// This returns a Symbol* to match type for SystemDictionary
61-
Symbol* find_entry(int index, unsigned int hash,
62-
Symbol* name, ClassLoaderData* loader_data);
58+
Symbol* find_entry(unsigned int hash,
59+
Symbol* name, ClassLoaderData* loader_data);
6360

64-
PlaceholderEntry* get_entry(int index, unsigned int hash,
65-
Symbol* name, ClassLoaderData* loader_data);
61+
PlaceholderEntry* get_entry(unsigned int hash,
62+
Symbol* name, ClassLoaderData* loader_data);
6663

6764
// caller to create a placeholder entry must enumerate an action
6865
// caller claims ownership of that action
@@ -83,17 +80,17 @@ class PlaceholderTable : public Hashtable<Symbol*, mtClass> {
8380
// find_and_add returns probe pointer - old or new
8481
// If no entry exists, add a placeholder entry and push SeenThread for classloadAction
8582
// If entry exists, reuse entry and push SeenThread for classloadAction
86-
PlaceholderEntry* find_and_add(int index, unsigned int hash,
83+
PlaceholderEntry* find_and_add(unsigned int hash,
8784
Symbol* name, ClassLoaderData* loader_data,
8885
classloadAction action, Symbol* supername,
8986
Thread* thread);
9087

91-
void remove_entry(int index, unsigned int hash,
88+
void remove_entry(unsigned int hash,
9289
Symbol* name, ClassLoaderData* loader_data);
9390

9491
// find_and_remove first removes SeenThread for classloadAction
9592
// If all queues are empty and definer is null, remove the PlacheholderEntry completely
96-
void find_and_remove(int index, unsigned int hash,
93+
void find_and_remove(unsigned int hash,
9794
Symbol* name, ClassLoaderData* loader_data,
9895
classloadAction action, Thread* thread);
9996

0 commit comments

Comments
 (0)