Mercurial > hg > truffle
annotate src/share/vm/classfile/placeholders.cpp @ 17870:a0eb3f61d34a
8039497: Testlibrary should be updated to provide information about all VM types as well as access to Unsafe
Reviewed-by: kvn, iignatyev
Contributed-by: filipp.zhinkin@oracle.com
author | iignatyev |
---|---|
date | Fri, 11 Apr 2014 00:34:56 +0400 |
parents | aefb345d3f5e |
children |
rev | line source |
---|---|
0 | 1 /* |
7582
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/placeholders.hpp" | |
27 #include "classfile/systemDictionary.hpp" | |
28 #include "oops/oop.inline.hpp" | |
29 #include "runtime/fieldType.hpp" | |
30 #include "utilities/hashtable.inline.hpp" | |
0 | 31 |
32 // Placeholder methods | |
33 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
34 PlaceholderEntry* PlaceholderTable::new_entry(int hash, Symbol* name, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
35 ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
36 bool havesupername, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
37 Symbol* supername) { |
6197 | 38 PlaceholderEntry* entry = (PlaceholderEntry*)Hashtable<Symbol*, mtClass>::new_entry(hash, name); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
39 // Hashtable with Symbol* literal must increment and decrement refcount. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
40 name->increment_refcount(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
41 entry->set_loader_data(loader_data); |
0 | 42 entry->set_havesupername(havesupername); |
43 entry->set_supername(supername); | |
44 entry->set_superThreadQ(NULL); | |
45 entry->set_loadInstanceThreadQ(NULL); | |
46 entry->set_defineThreadQ(NULL); | |
47 entry->set_definer(NULL); | |
6983 | 48 entry->set_instance_klass(NULL); |
0 | 49 return entry; |
50 } | |
51 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
52 void PlaceholderTable::free_entry(PlaceholderEntry* entry) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
53 // decrement Symbol refcount here because Hashtable doesn't. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
54 entry->literal()->decrement_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
55 if (entry->supername() != NULL) entry->supername()->decrement_refcount(); |
6197 | 56 Hashtable<Symbol*, mtClass>::free_entry(entry); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
57 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
58 |
0 | 59 |
60 // Placeholder objects represent classes currently being loaded. | |
61 // All threads examining the placeholder table must hold the | |
62 // SystemDictionary_lock, so we don't need special precautions | |
63 // on store ordering here. | |
64 void PlaceholderTable::add_entry(int index, unsigned int hash, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
65 Symbol* class_name, ClassLoaderData* loader_data, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
66 bool havesupername, Symbol* supername){ |
0 | 67 assert_locked_or_safepoint(SystemDictionary_lock); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
68 assert(class_name != NULL, "adding NULL obj"); |
0 | 69 |
70 // Both readers and writers are locked so it's safe to just | |
71 // create the placeholder and insert it in the list without a membar. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
72 PlaceholderEntry* entry = new_entry(hash, class_name, loader_data, havesupername, supername); |
0 | 73 add_entry(index, entry); |
74 } | |
75 | |
76 | |
77 // Remove a placeholder object. | |
78 void PlaceholderTable::remove_entry(int index, unsigned int hash, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
79 Symbol* class_name, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
80 ClassLoaderData* loader_data) { |
0 | 81 assert_locked_or_safepoint(SystemDictionary_lock); |
82 PlaceholderEntry** p = bucket_addr(index); | |
83 while (*p) { | |
84 PlaceholderEntry *probe = *p; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
85 if (probe->hash() == hash && probe->equals(class_name, loader_data)) { |
0 | 86 // Delete entry |
87 *p = probe->next(); | |
88 free_entry(probe); | |
89 return; | |
90 } | |
91 p = probe->next_addr(); | |
92 } | |
93 } | |
94 | |
95 PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
96 Symbol* class_name, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
97 ClassLoaderData* loader_data) { |
0 | 98 assert_locked_or_safepoint(SystemDictionary_lock); |
99 | |
100 for (PlaceholderEntry *place_probe = bucket(index); | |
101 place_probe != NULL; | |
102 place_probe = place_probe->next()) { | |
103 if (place_probe->hash() == hash && | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
104 place_probe->equals(class_name, loader_data)) { |
0 | 105 return place_probe; |
106 } | |
107 } | |
108 return NULL; | |
109 } | |
110 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
111 Symbol* PlaceholderTable::find_entry(int index, unsigned int hash, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
112 Symbol* class_name, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
113 ClassLoaderData* loader_data) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
114 PlaceholderEntry* probe = get_entry(index, hash, class_name, loader_data); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
115 return (probe? probe->klassname(): (Symbol*)NULL); |
0 | 116 } |
117 | |
118 // find_and_add returns probe pointer - old or new | |
119 // If no entry exists, add a placeholder entry | |
120 // If entry exists, reuse entry | |
121 // For both, push SeenThread for classloadAction | |
122 // if havesupername: this is used for circularity for instanceklass loading | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
123 PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
124 Symbol* name, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
125 ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
126 classloadAction action, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
127 Symbol* supername, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
128 Thread* thread) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
129 PlaceholderEntry* probe = get_entry(index, hash, name, loader_data); |
0 | 130 if (probe == NULL) { |
131 // Nothing found, add place holder | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
132 add_entry(index, hash, name, loader_data, (action == LOAD_SUPER), supername); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
133 probe = get_entry(index, hash, name, loader_data); |
0 | 134 } else { |
135 if (action == LOAD_SUPER) { | |
136 probe->set_havesupername(true); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
137 probe->set_supername(supername); |
0 | 138 } |
139 } | |
140 if (probe) probe->add_seen_thread(thread, action); | |
141 return probe; | |
142 } | |
143 | |
144 | |
7582
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
145 // placeholder is used to track class loading internal states |
0 | 146 // placeholder existence now for loading superclass/superinterface |
147 // superthreadQ tracks class circularity, while loading superclass/superinterface | |
148 // loadInstanceThreadQ tracks load_instance_class calls | |
149 // definer() tracks the single thread that owns define token | |
150 // defineThreadQ tracks waiters on defining thread's results | |
151 // 1st claimant creates placeholder | |
152 // find_and_add adds SeenThread entry for appropriate queue | |
153 // All claimants remove SeenThread after completing action | |
154 // On removal: if definer and all queues empty, remove entry | |
155 // Note: you can be in both placeholders and systemDictionary | |
156 // Therefore - must always check SD first | |
157 // Ignores the case where entry is not found | |
158 void PlaceholderTable::find_and_remove(int index, unsigned int hash, | |
7582
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
159 Symbol* name, ClassLoaderData* loader_data, |
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
160 classloadAction action, |
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
161 Thread* thread) { |
0 | 162 assert_locked_or_safepoint(SystemDictionary_lock); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
163 PlaceholderEntry *probe = get_entry(index, hash, name, loader_data); |
0 | 164 if (probe != NULL) { |
7582
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
165 probe->remove_seen_thread(thread, action); |
aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
acorn
parents:
6983
diff
changeset
|
166 // If no other threads using this entry, and this thread is not using this entry for other states |
0 | 167 if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL) |
168 && (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
169 remove_entry(index, hash, name, loader_data); |
0 | 170 } |
171 } | |
172 } | |
173 | |
174 PlaceholderTable::PlaceholderTable(int table_size) | |
6197 | 175 : TwoOopHashtable<Symbol*, mtClass>(table_size, sizeof(PlaceholderEntry)) { |
0 | 176 } |
177 | |
178 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
179 void PlaceholderTable::classes_do(KlassClosure* f) { |
0 | 180 for (int index = 0; index < table_size(); index++) { |
181 for (PlaceholderEntry* probe = bucket(index); | |
182 probe != NULL; | |
183 probe = probe->next()) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
184 probe->classes_do(f); |
0 | 185 } |
186 } | |
187 } | |
188 | |
189 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
190 void PlaceholderEntry::classes_do(KlassClosure* closure) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
191 assert(klassname() != NULL, "should have a non-null klass"); |
0 | 192 if (_instanceKlass != NULL) { |
6983 | 193 closure->do_klass(instance_klass()); |
0 | 194 } |
195 } | |
196 | |
197 // do all entries in the placeholder table | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
198 void PlaceholderTable::entries_do(void f(Symbol*)) { |
0 | 199 for (int index = 0; index < table_size(); index++) { |
200 for (PlaceholderEntry* probe = bucket(index); | |
201 probe != NULL; | |
202 probe = probe->next()) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
203 f(probe->klassname()); |
0 | 204 } |
205 } | |
206 } | |
207 | |
208 | |
209 #ifndef PRODUCT | |
210 // Note, doesn't append a cr | |
211 void PlaceholderEntry::print() const { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
212 klassname()->print_value(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
213 if (loader_data() != NULL) { |
0 | 214 tty->print(", loader "); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
215 loader_data()->print_value(); |
0 | 216 } |
217 if (supername() != NULL) { | |
218 tty->print(", supername "); | |
219 supername()->print_value(); | |
220 } | |
221 if (definer() != NULL) { | |
222 tty->print(", definer "); | |
223 definer()->print_value(); | |
224 } | |
6983 | 225 if (instance_klass() != NULL) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
226 tty->print(", InstanceKlass "); |
6983 | 227 instance_klass()->print_value(); |
0 | 228 } |
229 tty->print("\n"); | |
230 tty->print("loadInstanceThreadQ threads:"); | |
231 loadInstanceThreadQ()->printActionQ(); | |
232 tty->print("\n"); | |
233 tty->print("superThreadQ threads:"); | |
234 superThreadQ()->printActionQ(); | |
235 tty->print("\n"); | |
236 tty->print("defineThreadQ threads:"); | |
237 defineThreadQ()->printActionQ(); | |
238 tty->print("\n"); | |
239 } | |
240 #endif | |
241 | |
242 void PlaceholderEntry::verify() const { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
243 guarantee(loader_data() != NULL, "Must have been setup."); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
244 guarantee(loader_data()->class_loader() == NULL || loader_data()->class_loader()->is_instance(), |
0 | 245 "checking type of _loader"); |
6983 | 246 guarantee(instance_klass() == NULL |
247 || instance_klass()->oop_is_instance(), | |
248 "checking type of instance_klass result"); | |
0 | 249 } |
250 | |
251 void PlaceholderTable::verify() { | |
252 int element_count = 0; | |
253 for (int pindex = 0; pindex < table_size(); pindex++) { | |
254 for (PlaceholderEntry* probe = bucket(pindex); | |
255 probe != NULL; | |
256 probe = probe->next()) { | |
257 probe->verify(); | |
258 element_count++; // both klasses and place holders count | |
259 } | |
260 } | |
261 guarantee(number_of_entries() == element_count, | |
262 "Verify of system dictionary failed"); | |
263 } | |
264 | |
265 | |
266 #ifndef PRODUCT | |
267 void PlaceholderTable::print() { | |
268 for (int pindex = 0; pindex < table_size(); pindex++) { | |
269 for (PlaceholderEntry* probe = bucket(pindex); | |
270 probe != NULL; | |
271 probe = probe->next()) { | |
272 if (Verbose) tty->print("%4d: ", pindex); | |
273 tty->print(" place holder "); | |
274 | |
275 probe->print(); | |
276 tty->cr(); | |
277 } | |
278 } | |
279 } | |
280 #endif |