author | zgu |
Thu, 28 Jun 2012 17:03:16 -0400 | |
changeset 13195 | be27e1b6a4b9 |
parent 8921 | 14bfe81f2a9d |
child 13728 | 882756847a04 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8076
diff
changeset
|
2 |
* Copyright (c) 2003, 2011, 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:
5420
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5420
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:
5420
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP |
26 |
#define SHARE_VM_CLASSFILE_DICTIONARY_HPP |
|
27 |
||
28 |
#include "classfile/systemDictionary.hpp" |
|
29 |
#include "oops/instanceKlass.hpp" |
|
30 |
#include "oops/oop.hpp" |
|
31 |
#include "utilities/hashtable.hpp" |
|
32 |
||
1 | 33 |
class DictionaryEntry; |
34 |
||
35 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
36 |
// The data structure for the system dictionary (and the shared system |
|
37 |
// dictionary). |
|
38 |
||
13195 | 39 |
class Dictionary : public TwoOopHashtable<klassOop, mtClass> { |
1 | 40 |
friend class VMStructs; |
41 |
private: |
|
42 |
// current iteration index. |
|
43 |
static int _current_class_index; |
|
44 |
// pointer to the current hash table entry. |
|
45 |
static DictionaryEntry* _current_class_entry; |
|
46 |
||
47 |
DictionaryEntry* get_entry(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
48 |
Symbol* name, Handle loader); |
1 | 49 |
|
50 |
DictionaryEntry* bucket(int i) { |
|
13195 | 51 |
return (DictionaryEntry*)Hashtable<klassOop, mtClass>::bucket(i); |
1 | 52 |
} |
53 |
||
54 |
// The following method is not MT-safe and must be done under lock. |
|
55 |
DictionaryEntry** bucket_addr(int i) { |
|
13195 | 56 |
return (DictionaryEntry**)Hashtable<klassOop, mtClass>::bucket_addr(i); |
1 | 57 |
} |
58 |
||
59 |
void add_entry(int index, DictionaryEntry* new_entry) { |
|
13195 | 60 |
Hashtable<klassOop, mtClass>::add_entry(index, (HashtableEntry<oop, mtClass>*)new_entry); |
1 | 61 |
} |
62 |
||
63 |
||
64 |
public: |
|
65 |
Dictionary(int table_size); |
|
13195 | 66 |
Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries); |
1 | 67 |
|
68 |
DictionaryEntry* new_entry(unsigned int hash, klassOop klass, oop loader); |
|
69 |
||
70 |
DictionaryEntry* new_entry(); |
|
71 |
||
72 |
void free_entry(DictionaryEntry* entry); |
|
73 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
74 |
void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj); |
1 | 75 |
|
76 |
klassOop find_class(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
77 |
Symbol* name, Handle loader); |
1 | 78 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
79 |
klassOop find_shared_class(int index, unsigned int hash, Symbol* name); |
1 | 80 |
|
81 |
// Compiler support |
|
82 |
klassOop try_get_next_class(); |
|
83 |
||
84 |
// GC support |
|
85 |
||
86 |
void oops_do(OopClosure* f); |
|
87 |
void always_strong_classes_do(OopClosure* blk); |
|
88 |
void classes_do(void f(klassOop)); |
|
89 |
void classes_do(void f(klassOop, TRAPS), TRAPS); |
|
90 |
void classes_do(void f(klassOop, oop)); |
|
91 |
void classes_do(void f(klassOop, oop, TRAPS), TRAPS); |
|
92 |
||
93 |
void methods_do(void f(methodOop)); |
|
94 |
||
95 |
||
96 |
// Classes loaded by the bootstrap loader are always strongly reachable. |
|
97 |
// If we're not doing class unloading, all classes are strongly reachable. |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
98 |
static bool is_strongly_reachable(oop class_loader, klassOop klass) { |
1 | 99 |
assert (klass != NULL, "should have non-null klass"); |
100 |
return (class_loader == NULL || !ClassUnloading); |
|
101 |
} |
|
102 |
||
103 |
// Unload (that is, break root links to) all unmarked classes and |
|
104 |
// loaders. Returns "true" iff something was unloaded. |
|
105 |
bool do_unloading(BoolObjectClosure* is_alive); |
|
106 |
||
107 |
// Protection domains |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
108 |
klassOop find(int index, unsigned int hash, Symbol* name, |
1 | 109 |
Handle loader, Handle protection_domain, TRAPS); |
110 |
bool is_valid_protection_domain(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
111 |
Symbol* name, Handle class_loader, |
1 | 112 |
Handle protection_domain); |
113 |
void add_protection_domain(int index, unsigned int hash, |
|
114 |
instanceKlassHandle klass, Handle loader, |
|
115 |
Handle protection_domain, TRAPS); |
|
116 |
||
117 |
// Sharing support |
|
118 |
void dump(SerializeOopClosure* soc); |
|
119 |
void restore(SerializeOopClosure* soc); |
|
120 |
void reorder_dictionary(); |
|
121 |
||
122 |
||
123 |
#ifndef PRODUCT |
|
124 |
void print(); |
|
125 |
#endif |
|
126 |
void verify(); |
|
127 |
}; |
|
128 |
||
129 |
// The following classes can be in dictionary.cpp, but we need these |
|
130 |
// to be in header file so that SA's vmStructs can access. |
|
131 |
||
13195 | 132 |
class ProtectionDomainEntry :public CHeapObj<mtClass> { |
1 | 133 |
friend class VMStructs; |
134 |
public: |
|
135 |
ProtectionDomainEntry* _next; |
|
136 |
oop _protection_domain; |
|
137 |
||
138 |
ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) { |
|
139 |
_protection_domain = protection_domain; |
|
140 |
_next = next; |
|
141 |
} |
|
142 |
||
143 |
ProtectionDomainEntry* next() { return _next; } |
|
144 |
oop protection_domain() { return _protection_domain; } |
|
145 |
}; |
|
146 |
||
147 |
// An entry in the system dictionary, this describes a class as |
|
148 |
// { klassOop, loader, protection_domain }. |
|
149 |
||
13195 | 150 |
class DictionaryEntry : public HashtableEntry<klassOop, mtClass> { |
1 | 151 |
friend class VMStructs; |
152 |
private: |
|
153 |
// Contains the set of approved protection domains that can access |
|
154 |
// this system dictionary entry. |
|
155 |
ProtectionDomainEntry* _pd_set; |
|
156 |
oop _loader; |
|
157 |
||
158 |
||
159 |
public: |
|
160 |
// Tells whether a protection is in the approved set. |
|
161 |
bool contains_protection_domain(oop protection_domain) const; |
|
162 |
// Adds a protection domain to the approved set. |
|
163 |
void add_protection_domain(oop protection_domain); |
|
164 |
||
165 |
klassOop klass() const { return (klassOop)literal(); } |
|
166 |
klassOop* klass_addr() { return (klassOop*)literal_addr(); } |
|
167 |
||
168 |
DictionaryEntry* next() const { |
|
13195 | 169 |
return (DictionaryEntry*)HashtableEntry<klassOop, mtClass>::next(); |
1 | 170 |
} |
171 |
||
172 |
DictionaryEntry** next_addr() { |
|
13195 | 173 |
return (DictionaryEntry**)HashtableEntry<klassOop, mtClass>::next_addr(); |
1 | 174 |
} |
175 |
||
176 |
oop loader() const { return _loader; } |
|
177 |
void set_loader(oop loader) { _loader = loader; } |
|
178 |
oop* loader_addr() { return &_loader; } |
|
179 |
||
180 |
ProtectionDomainEntry* pd_set() const { return _pd_set; } |
|
181 |
void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; } |
|
182 |
||
183 |
bool has_protection_domain() { return _pd_set != NULL; } |
|
184 |
||
185 |
// Tells whether the initiating class' protection can access the this _klass |
|
186 |
bool is_valid_protection_domain(Handle protection_domain) { |
|
187 |
if (!ProtectionDomainVerification) return true; |
|
188 |
if (!SystemDictionary::has_checkPackageAccess()) return true; |
|
189 |
||
190 |
return protection_domain() == NULL |
|
191 |
? true |
|
192 |
: contains_protection_domain(protection_domain()); |
|
193 |
} |
|
194 |
||
195 |
||
196 |
void protection_domain_set_oops_do(OopClosure* f) { |
|
197 |
for (ProtectionDomainEntry* current = _pd_set; |
|
198 |
current != NULL; |
|
199 |
current = current->_next) { |
|
200 |
f->do_oop(&(current->_protection_domain)); |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
void verify_protection_domain_set() { |
|
205 |
for (ProtectionDomainEntry* current = _pd_set; |
|
206 |
current != NULL; |
|
207 |
current = current->_next) { |
|
208 |
current->_protection_domain->verify(); |
|
209 |
} |
|
210 |
} |
|
211 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
212 |
bool equals(Symbol* class_name, oop class_loader) const { |
1 | 213 |
klassOop klass = (klassOop)literal(); |
214 |
return (instanceKlass::cast(klass)->name() == class_name && |
|
215 |
_loader == class_loader); |
|
216 |
} |
|
217 |
||
218 |
void print() { |
|
219 |
int count = 0; |
|
220 |
for (ProtectionDomainEntry* current = _pd_set; |
|
221 |
current != NULL; |
|
222 |
current = current->_next) { |
|
223 |
count++; |
|
224 |
} |
|
225 |
tty->print_cr("pd set = #%d", count); |
|
226 |
} |
|
227 |
}; |
|
2534 | 228 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
229 |
// Entry in a SymbolPropertyTable, mapping a single Symbol* |
2534 | 230 |
// to a managed and an unmanaged pointer. |
13195 | 231 |
class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> { |
2534 | 232 |
friend class VMStructs; |
233 |
private: |
|
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
234 |
intptr_t _symbol_mode; // secondary key |
2534 | 235 |
oop _property_oop; |
236 |
address _property_data; |
|
237 |
||
238 |
public: |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
239 |
Symbol* symbol() const { return literal(); } |
2534 | 240 |
|
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
241 |
intptr_t symbol_mode() const { return _symbol_mode; } |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
242 |
void set_symbol_mode(intptr_t m) { _symbol_mode = m; } |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
243 |
|
2534 | 244 |
oop property_oop() const { return _property_oop; } |
245 |
void set_property_oop(oop p) { _property_oop = p; } |
|
246 |
||
247 |
address property_data() const { return _property_data; } |
|
248 |
void set_property_data(address p) { _property_data = p; } |
|
249 |
||
250 |
SymbolPropertyEntry* next() const { |
|
13195 | 251 |
return (SymbolPropertyEntry*)HashtableEntry<Symbol*, mtSymbol>::next(); |
2534 | 252 |
} |
253 |
||
254 |
SymbolPropertyEntry** next_addr() { |
|
13195 | 255 |
return (SymbolPropertyEntry**)HashtableEntry<Symbol*, mtSymbol>::next_addr(); |
2534 | 256 |
} |
257 |
||
258 |
oop* property_oop_addr() { return &_property_oop; } |
|
259 |
||
260 |
void print_on(outputStream* st) const { |
|
261 |
symbol()->print_value_on(st); |
|
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
262 |
st->print("/mode="INTX_FORMAT, symbol_mode()); |
2534 | 263 |
st->print(" -> "); |
264 |
bool printed = false; |
|
265 |
if (property_oop() != NULL) { |
|
266 |
property_oop()->print_value_on(st); |
|
267 |
printed = true; |
|
268 |
} |
|
269 |
if (property_data() != NULL) { |
|
270 |
if (printed) st->print(" and "); |
|
271 |
st->print(INTPTR_FORMAT, property_data()); |
|
272 |
printed = true; |
|
273 |
} |
|
274 |
st->print_cr(printed ? "" : "(empty)"); |
|
275 |
} |
|
276 |
}; |
|
277 |
||
278 |
// A system-internal mapping of symbols to pointers, both managed |
|
279 |
// and unmanaged. Used to record the auto-generation of each method |
|
280 |
// MethodHandle.invoke(S)T, for all signatures (S)T. |
|
13195 | 281 |
class SymbolPropertyTable : public Hashtable<Symbol*, mtSymbol> { |
2534 | 282 |
friend class VMStructs; |
283 |
private: |
|
284 |
SymbolPropertyEntry* bucket(int i) { |
|
13195 | 285 |
return (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::bucket(i); |
2534 | 286 |
} |
287 |
||
288 |
// The following method is not MT-safe and must be done under lock. |
|
289 |
SymbolPropertyEntry** bucket_addr(int i) { |
|
13195 | 290 |
return (SymbolPropertyEntry**) Hashtable<Symbol*, mtSymbol>::bucket_addr(i); |
2534 | 291 |
} |
292 |
||
293 |
void add_entry(int index, SymbolPropertyEntry* new_entry) { |
|
294 |
ShouldNotReachHere(); |
|
295 |
} |
|
296 |
void set_entry(int index, SymbolPropertyEntry* new_entry) { |
|
297 |
ShouldNotReachHere(); |
|
298 |
} |
|
299 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
300 |
SymbolPropertyEntry* new_entry(unsigned int hash, Symbol* symbol, intptr_t symbol_mode) { |
13195 | 301 |
SymbolPropertyEntry* entry = (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::new_entry(hash, symbol); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
302 |
// 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
|
303 |
symbol->increment_refcount(); |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
304 |
entry->set_symbol_mode(symbol_mode); |
2534 | 305 |
entry->set_property_oop(NULL); |
306 |
entry->set_property_data(NULL); |
|
307 |
return entry; |
|
308 |
} |
|
309 |
||
310 |
public: |
|
311 |
SymbolPropertyTable(int table_size); |
|
13195 | 312 |
SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, int number_of_entries); |
2534 | 313 |
|
314 |
void free_entry(SymbolPropertyEntry* entry) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
315 |
// decrement Symbol refcount here because hashtable doesn't. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
316 |
entry->literal()->decrement_refcount(); |
13195 | 317 |
Hashtable<Symbol*, mtSymbol>::free_entry(entry); |
2534 | 318 |
} |
319 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
320 |
unsigned int compute_hash(Symbol* sym, intptr_t symbol_mode) { |
2534 | 321 |
// Use the regular identity_hash. |
13195 | 322 |
return Hashtable<Symbol*, mtSymbol>::compute_hash(sym) ^ symbol_mode; |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
323 |
} |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
324 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
325 |
int index_for(Symbol* name, intptr_t symbol_mode) { |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
326 |
return hash_to_index(compute_hash(name, symbol_mode)); |
2534 | 327 |
} |
328 |
||
329 |
// need not be locked; no state change |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
330 |
SymbolPropertyEntry* find_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode); |
2534 | 331 |
|
332 |
// must be done under SystemDictionary_lock |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
333 |
SymbolPropertyEntry* add_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode); |
2534 | 334 |
|
335 |
// GC support |
|
336 |
void oops_do(OopClosure* f); |
|
337 |
void methods_do(void f(methodOop)); |
|
338 |
||
339 |
// Sharing support |
|
340 |
void dump(SerializeOopClosure* soc); |
|
341 |
void restore(SerializeOopClosure* soc); |
|
342 |
void reorder_dictionary(); |
|
343 |
||
344 |
#ifndef PRODUCT |
|
345 |
void print(); |
|
346 |
#endif |
|
347 |
void verify(); |
|
348 |
}; |
|
7397 | 349 |
#endif // SHARE_VM_CLASSFILE_DICTIONARY_HPP |