author | lfoltan |
Mon, 21 Oct 2019 13:13:16 -0400 | |
changeset 58722 | cba8afa5cfed |
parent 49824 | e242740a92b8 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
47216
diff
changeset
|
26 |
#include "classfile/classLoaderData.inline.hpp" |
7397 | 27 |
#include "classfile/placeholders.hpp" |
28 |
#include "classfile/systemDictionary.hpp" |
|
29 |
#include "oops/oop.inline.hpp" |
|
30 |
#include "runtime/fieldType.hpp" |
|
31 |
#include "utilities/hashtable.inline.hpp" |
|
1 | 32 |
|
33 |
// Placeholder methods |
|
34 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
35 |
PlaceholderEntry* PlaceholderTable::new_entry(int hash, Symbol* name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
36 |
ClassLoaderData* loader_data, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
37 |
bool havesupername, |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
38 |
Symbol* supername) { |
13195 | 39 |
PlaceholderEntry* entry = (PlaceholderEntry*)Hashtable<Symbol*, mtClass>::new_entry(hash, name); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
40 |
// Hashtable with Symbol* literal must increment and decrement refcount. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
41 |
name->increment_refcount(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
42 |
entry->set_loader_data(loader_data); |
1 | 43 |
entry->set_havesupername(havesupername); |
44 |
entry->set_supername(supername); |
|
45 |
entry->set_superThreadQ(NULL); |
|
46 |
entry->set_loadInstanceThreadQ(NULL); |
|
47 |
entry->set_defineThreadQ(NULL); |
|
48 |
entry->set_definer(NULL); |
|
14488 | 49 |
entry->set_instance_klass(NULL); |
1 | 50 |
return entry; |
51 |
} |
|
52 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
53 |
void PlaceholderTable::free_entry(PlaceholderEntry* entry) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
54 |
// decrement Symbol refcount here because Hashtable doesn't. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
55 |
entry->literal()->decrement_refcount(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
56 |
if (entry->supername() != NULL) entry->supername()->decrement_refcount(); |
13195 | 57 |
Hashtable<Symbol*, mtClass>::free_entry(entry); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
58 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
59 |
|
1 | 60 |
|
61 |
// Placeholder objects represent classes currently being loaded. |
|
62 |
// All threads examining the placeholder table must hold the |
|
63 |
// SystemDictionary_lock, so we don't need special precautions |
|
64 |
// on store ordering here. |
|
65 |
void PlaceholderTable::add_entry(int index, unsigned int hash, |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
66 |
Symbol* class_name, ClassLoaderData* loader_data, |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
67 |
bool havesupername, Symbol* supername){ |
1 | 68 |
assert_locked_or_safepoint(SystemDictionary_lock); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
69 |
assert(class_name != NULL, "adding NULL obj"); |
1 | 70 |
|
71 |
// Both readers and writers are locked so it's safe to just |
|
72 |
// create the placeholder and insert it in the list without a membar. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
73 |
PlaceholderEntry* entry = new_entry(hash, class_name, loader_data, havesupername, supername); |
1 | 74 |
add_entry(index, entry); |
75 |
} |
|
76 |
||
77 |
||
78 |
// Remove a placeholder object. |
|
79 |
void PlaceholderTable::remove_entry(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
80 |
Symbol* class_name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
81 |
ClassLoaderData* loader_data) { |
1 | 82 |
assert_locked_or_safepoint(SystemDictionary_lock); |
83 |
PlaceholderEntry** p = bucket_addr(index); |
|
84 |
while (*p) { |
|
85 |
PlaceholderEntry *probe = *p; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
86 |
if (probe->hash() == hash && probe->equals(class_name, loader_data)) { |
1 | 87 |
// Delete entry |
88 |
*p = probe->next(); |
|
89 |
free_entry(probe); |
|
90 |
return; |
|
91 |
} |
|
92 |
p = probe->next_addr(); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
97 |
Symbol* class_name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
98 |
ClassLoaderData* loader_data) { |
1 | 99 |
assert_locked_or_safepoint(SystemDictionary_lock); |
100 |
||
101 |
for (PlaceholderEntry *place_probe = bucket(index); |
|
102 |
place_probe != NULL; |
|
103 |
place_probe = place_probe->next()) { |
|
104 |
if (place_probe->hash() == hash && |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
105 |
place_probe->equals(class_name, loader_data)) { |
1 | 106 |
return place_probe; |
107 |
} |
|
108 |
} |
|
109 |
return NULL; |
|
110 |
} |
|
111 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
112 |
Symbol* PlaceholderTable::find_entry(int index, unsigned int hash, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
113 |
Symbol* class_name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
114 |
ClassLoaderData* loader_data) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
115 |
PlaceholderEntry* probe = get_entry(index, hash, class_name, loader_data); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
116 |
return (probe? probe->klassname(): (Symbol*)NULL); |
1 | 117 |
} |
118 |
||
119 |
// find_and_add returns probe pointer - old or new |
|
120 |
// If no entry exists, add a placeholder entry |
|
121 |
// If entry exists, reuse entry |
|
122 |
// For both, push SeenThread for classloadAction |
|
123 |
// if havesupername: this is used for circularity for instanceklass loading |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
124 |
PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
125 |
Symbol* name, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
126 |
ClassLoaderData* loader_data, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
127 |
classloadAction action, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
128 |
Symbol* supername, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
129 |
Thread* thread) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
130 |
PlaceholderEntry* probe = get_entry(index, hash, name, loader_data); |
1 | 131 |
if (probe == NULL) { |
132 |
// Nothing found, add place holder |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
133 |
add_entry(index, hash, name, loader_data, (action == LOAD_SUPER), supername); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
134 |
probe = get_entry(index, hash, name, loader_data); |
1 | 135 |
} else { |
136 |
if (action == LOAD_SUPER) { |
|
137 |
probe->set_havesupername(true); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
138 |
probe->set_supername(supername); |
1 | 139 |
} |
140 |
} |
|
141 |
if (probe) probe->add_seen_thread(thread, action); |
|
142 |
return probe; |
|
143 |
} |
|
144 |
||
145 |
||
15188
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
146 |
// placeholder is used to track class loading internal states |
1 | 147 |
// placeholder existence now for loading superclass/superinterface |
148 |
// superthreadQ tracks class circularity, while loading superclass/superinterface |
|
149 |
// loadInstanceThreadQ tracks load_instance_class calls |
|
150 |
// definer() tracks the single thread that owns define token |
|
151 |
// defineThreadQ tracks waiters on defining thread's results |
|
152 |
// 1st claimant creates placeholder |
|
153 |
// find_and_add adds SeenThread entry for appropriate queue |
|
154 |
// All claimants remove SeenThread after completing action |
|
155 |
// On removal: if definer and all queues empty, remove entry |
|
156 |
// Note: you can be in both placeholders and systemDictionary |
|
157 |
// Therefore - must always check SD first |
|
158 |
// Ignores the case where entry is not found |
|
159 |
void PlaceholderTable::find_and_remove(int index, unsigned int hash, |
|
15188
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
160 |
Symbol* name, ClassLoaderData* loader_data, |
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
161 |
classloadAction action, |
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
162 |
Thread* thread) { |
1 | 163 |
assert_locked_or_safepoint(SystemDictionary_lock); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
164 |
PlaceholderEntry *probe = get_entry(index, hash, name, loader_data); |
1 | 165 |
if (probe != NULL) { |
15188
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
166 |
probe->remove_seen_thread(thread, action); |
3916ac601e04
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
14488
diff
changeset
|
167 |
// If no other threads using this entry, and this thread is not using this entry for other states |
1 | 168 |
if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL) |
169 |
&& (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
170 |
remove_entry(index, hash, name, loader_data); |
1 | 171 |
} |
172 |
} |
|
173 |
} |
|
174 |
||
175 |
PlaceholderTable::PlaceholderTable(int table_size) |
|
46729 | 176 |
: Hashtable<Symbol*, mtClass>(table_size, sizeof(PlaceholderEntry)) { |
1 | 177 |
} |
178 |
||
179 |
void PlaceholderEntry::verify() const { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
180 |
guarantee(loader_data() != NULL, "Must have been setup."); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
181 |
guarantee(loader_data()->class_loader() == NULL || loader_data()->class_loader()->is_instance(), |
1 | 182 |
"checking type of _loader"); |
14488 | 183 |
guarantee(instance_klass() == NULL |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
15188
diff
changeset
|
184 |
|| instance_klass()->is_instance_klass(), |
14488 | 185 |
"checking type of instance_klass result"); |
1 | 186 |
} |
187 |
||
188 |
void PlaceholderTable::verify() { |
|
46545 | 189 |
verify_table<PlaceholderEntry>("Placeholder Table"); |
1 | 190 |
} |
191 |
||
192 |
||
46742 | 193 |
// Note, doesn't append a cr |
194 |
// Can't call this print_on because HashtableEntry doesn't initialize its vptr |
|
195 |
// and print_on is a virtual function so the vptr call crashes. |
|
196 |
void PlaceholderEntry::print_entry(outputStream* st) const { |
|
197 |
klassname()->print_value_on(st); |
|
198 |
if (loader_data() != NULL) { |
|
199 |
st->print(", loader "); |
|
200 |
loader_data()->print_value_on(st); |
|
201 |
} |
|
202 |
if (supername() != NULL) { |
|
203 |
st->print(", supername "); |
|
204 |
supername()->print_value_on(st); |
|
205 |
} |
|
206 |
if (definer() != NULL) { |
|
207 |
st->print(", definer "); |
|
208 |
definer()->print_value_on(st); |
|
209 |
} |
|
210 |
if (instance_klass() != NULL) { |
|
211 |
st->print(", InstanceKlass "); |
|
212 |
instance_klass()->print_value_on(st); |
|
213 |
} |
|
214 |
st->cr(); |
|
215 |
st->print("loadInstanceThreadQ threads:"); |
|
216 |
loadInstanceThreadQ()->print_action_queue(st); |
|
217 |
st->cr(); |
|
218 |
st->print("superThreadQ threads:"); |
|
219 |
superThreadQ()->print_action_queue(st); |
|
220 |
st->cr(); |
|
221 |
st->print("defineThreadQ threads:"); |
|
222 |
defineThreadQ()->print_action_queue(st); |
|
223 |
st->cr(); |
|
224 |
} |
|
225 |
||
226 |
void PlaceholderTable::print_on(outputStream* st) const { |
|
227 |
st->print_cr("Placeholder table (table_size=%d, placeholders=%d)", |
|
46545 | 228 |
table_size(), number_of_entries()); |
1 | 229 |
for (int pindex = 0; pindex < table_size(); pindex++) { |
230 |
for (PlaceholderEntry* probe = bucket(pindex); |
|
231 |
probe != NULL; |
|
232 |
probe = probe->next()) { |
|
46742 | 233 |
st->print("%4d: placeholder ", pindex); |
234 |
probe->print_entry(st); |
|
1 | 235 |
} |
236 |
} |
|
237 |
} |