Thu, 31 Mar 2016 14:23:12 -0700
Merge
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP |
stefank@2314 | 26 | #define SHARE_VM_CLASSFILE_DICTIONARY_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 29 | #include "oops/instanceKlass.hpp" |
tschatzl@5862 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "utilities/hashtable.hpp" |
stefank@2314 | 32 | |
duke@435 | 33 | class DictionaryEntry; |
coleenp@4037 | 34 | class PSPromotionManager; |
tschatzl@5862 | 35 | class ProtectionDomainCacheTable; |
tschatzl@5862 | 36 | class ProtectionDomainCacheEntry; |
tschatzl@5862 | 37 | class BoolObjectClosure; |
duke@435 | 38 | |
duke@435 | 39 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
duke@435 | 40 | // The data structure for the system dictionary (and the shared system |
duke@435 | 41 | // dictionary). |
duke@435 | 42 | |
coleenp@4037 | 43 | class Dictionary : public TwoOopHashtable<Klass*, mtClass> { |
duke@435 | 44 | friend class VMStructs; |
duke@435 | 45 | private: |
duke@435 | 46 | // current iteration index. |
duke@435 | 47 | static int _current_class_index; |
duke@435 | 48 | // pointer to the current hash table entry. |
duke@435 | 49 | static DictionaryEntry* _current_class_entry; |
duke@435 | 50 | |
tschatzl@5862 | 51 | ProtectionDomainCacheTable* _pd_cache_table; |
tschatzl@5862 | 52 | |
duke@435 | 53 | DictionaryEntry* get_entry(int index, unsigned int hash, |
coleenp@4037 | 54 | Symbol* name, ClassLoaderData* loader_data); |
duke@435 | 55 | |
duke@435 | 56 | DictionaryEntry* bucket(int i) { |
coleenp@4037 | 57 | return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i); |
duke@435 | 58 | } |
duke@435 | 59 | |
duke@435 | 60 | // The following method is not MT-safe and must be done under lock. |
duke@435 | 61 | DictionaryEntry** bucket_addr(int i) { |
coleenp@4037 | 62 | return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i); |
duke@435 | 63 | } |
duke@435 | 64 | |
duke@435 | 65 | void add_entry(int index, DictionaryEntry* new_entry) { |
coleenp@4037 | 66 | Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry); |
duke@435 | 67 | } |
duke@435 | 68 | |
duke@435 | 69 | public: |
duke@435 | 70 | Dictionary(int table_size); |
zgu@3900 | 71 | Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries); |
duke@435 | 72 | |
coleenp@4037 | 73 | DictionaryEntry* new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data); |
duke@435 | 74 | |
duke@435 | 75 | DictionaryEntry* new_entry(); |
duke@435 | 76 | |
duke@435 | 77 | void free_entry(DictionaryEntry* entry); |
duke@435 | 78 | |
coleenp@4037 | 79 | void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj); |
duke@435 | 80 | |
coleenp@4037 | 81 | Klass* find_class(int index, unsigned int hash, |
coleenp@4037 | 82 | Symbol* name, ClassLoaderData* loader_data); |
duke@435 | 83 | |
coleenp@4037 | 84 | Klass* find_shared_class(int index, unsigned int hash, Symbol* name); |
duke@435 | 85 | |
duke@435 | 86 | // Compiler support |
coleenp@4037 | 87 | Klass* try_get_next_class(); |
duke@435 | 88 | |
duke@435 | 89 | // GC support |
coleenp@4037 | 90 | void oops_do(OopClosure* f); |
coleenp@4037 | 91 | void always_strong_oops_do(OopClosure* blk); |
stefank@6992 | 92 | void roots_oops_do(OopClosure* strong, OopClosure* weak); |
duke@435 | 93 | |
coleenp@4037 | 94 | void always_strong_classes_do(KlassClosure* closure); |
duke@435 | 95 | |
coleenp@4037 | 96 | void classes_do(void f(Klass*)); |
coleenp@4037 | 97 | void classes_do(void f(Klass*, TRAPS), TRAPS); |
coleenp@4037 | 98 | void classes_do(void f(Klass*, ClassLoaderData*)); |
coleenp@4037 | 99 | |
coleenp@4037 | 100 | void methods_do(void f(Method*)); |
duke@435 | 101 | |
tschatzl@5862 | 102 | void unlink(BoolObjectClosure* is_alive); |
iklam@7089 | 103 | void remove_classes_in_error_state(); |
duke@435 | 104 | |
duke@435 | 105 | // Classes loaded by the bootstrap loader are always strongly reachable. |
duke@435 | 106 | // If we're not doing class unloading, all classes are strongly reachable. |
coleenp@4037 | 107 | static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) { |
duke@435 | 108 | assert (klass != NULL, "should have non-null klass"); |
coleenp@4037 | 109 | return (loader_data->is_the_null_class_loader_data() || !ClassUnloading); |
duke@435 | 110 | } |
duke@435 | 111 | |
thartmann@7064 | 112 | // Unload (that is, break root links to) all unmarked classes and loaders. |
thartmann@7064 | 113 | void do_unloading(); |
duke@435 | 114 | |
duke@435 | 115 | // Protection domains |
coleenp@4037 | 116 | Klass* find(int index, unsigned int hash, Symbol* name, |
coleenp@4037 | 117 | ClassLoaderData* loader_data, Handle protection_domain, TRAPS); |
duke@435 | 118 | bool is_valid_protection_domain(int index, unsigned int hash, |
coleenp@4037 | 119 | Symbol* name, ClassLoaderData* loader_data, |
duke@435 | 120 | Handle protection_domain); |
duke@435 | 121 | void add_protection_domain(int index, unsigned int hash, |
coleenp@4037 | 122 | instanceKlassHandle klass, ClassLoaderData* loader_data, |
duke@435 | 123 | Handle protection_domain, TRAPS); |
duke@435 | 124 | |
duke@435 | 125 | // Sharing support |
duke@435 | 126 | void reorder_dictionary(); |
duke@435 | 127 | |
tschatzl@5862 | 128 | ProtectionDomainCacheEntry* cache_get(oop protection_domain); |
duke@435 | 129 | |
iklam@7089 | 130 | void print(bool details = true); |
duke@435 | 131 | void verify(); |
duke@435 | 132 | }; |
duke@435 | 133 | |
duke@435 | 134 | // The following classes can be in dictionary.cpp, but we need these |
tschatzl@5862 | 135 | // to be in header file so that SA's vmStructs can access them. |
tschatzl@5862 | 136 | class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> { |
tschatzl@5862 | 137 | friend class VMStructs; |
tschatzl@5862 | 138 | private: |
tschatzl@5862 | 139 | // Flag indicating whether this protection domain entry is strongly reachable. |
tschatzl@5862 | 140 | // Used during iterating over the system dictionary to remember oops that need |
tschatzl@5862 | 141 | // to be updated. |
tschatzl@5862 | 142 | bool _strongly_reachable; |
tschatzl@5862 | 143 | public: |
tschatzl@5862 | 144 | oop protection_domain() { return literal(); } |
tschatzl@5862 | 145 | |
tschatzl@5862 | 146 | void init() { |
tschatzl@5862 | 147 | _strongly_reachable = false; |
tschatzl@5862 | 148 | } |
tschatzl@5862 | 149 | |
tschatzl@5862 | 150 | ProtectionDomainCacheEntry* next() { |
tschatzl@5862 | 151 | return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next(); |
tschatzl@5862 | 152 | } |
tschatzl@5862 | 153 | |
tschatzl@5862 | 154 | ProtectionDomainCacheEntry** next_addr() { |
tschatzl@5862 | 155 | return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr(); |
tschatzl@5862 | 156 | } |
tschatzl@5862 | 157 | |
tschatzl@5862 | 158 | void oops_do(OopClosure* f) { |
tschatzl@5862 | 159 | f->do_oop(literal_addr()); |
tschatzl@5862 | 160 | } |
tschatzl@5862 | 161 | |
tschatzl@5862 | 162 | void set_strongly_reachable() { _strongly_reachable = true; } |
tschatzl@5862 | 163 | bool is_strongly_reachable() { return _strongly_reachable; } |
tschatzl@5862 | 164 | void reset_strongly_reachable() { _strongly_reachable = false; } |
tschatzl@5862 | 165 | |
tschatzl@5862 | 166 | void print() PRODUCT_RETURN; |
tschatzl@5862 | 167 | void verify(); |
tschatzl@5862 | 168 | }; |
tschatzl@5862 | 169 | |
tschatzl@5862 | 170 | // The ProtectionDomainCacheTable contains all protection domain oops. The system |
tschatzl@5862 | 171 | // dictionary entries reference its entries instead of having references to oops |
tschatzl@5862 | 172 | // directly. |
tschatzl@5862 | 173 | // This is used to speed up system dictionary iteration: the oops in the |
tschatzl@5862 | 174 | // protection domain are the only ones referring the Java heap. So when there is |
tschatzl@5862 | 175 | // need to update these, instead of going over every entry of the system dictionary, |
tschatzl@5862 | 176 | // we only need to iterate over this set. |
tschatzl@5862 | 177 | // The amount of different protection domains used is typically magnitudes smaller |
tschatzl@5862 | 178 | // than the number of system dictionary entries (loaded classes). |
tschatzl@5862 | 179 | class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> { |
tschatzl@5862 | 180 | friend class VMStructs; |
tschatzl@5862 | 181 | private: |
tschatzl@5862 | 182 | ProtectionDomainCacheEntry* bucket(int i) { |
tschatzl@5862 | 183 | return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i); |
tschatzl@5862 | 184 | } |
tschatzl@5862 | 185 | |
tschatzl@5862 | 186 | // The following method is not MT-safe and must be done under lock. |
tschatzl@5862 | 187 | ProtectionDomainCacheEntry** bucket_addr(int i) { |
tschatzl@5862 | 188 | return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i); |
tschatzl@5862 | 189 | } |
tschatzl@5862 | 190 | |
tschatzl@5862 | 191 | ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) { |
tschatzl@5862 | 192 | ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain); |
tschatzl@5862 | 193 | entry->init(); |
tschatzl@5862 | 194 | return entry; |
tschatzl@5862 | 195 | } |
tschatzl@5862 | 196 | |
tschatzl@5862 | 197 | static unsigned int compute_hash(oop protection_domain) { |
tschatzl@5862 | 198 | return (unsigned int)(protection_domain->identity_hash()); |
tschatzl@5862 | 199 | } |
tschatzl@5862 | 200 | |
tschatzl@5862 | 201 | int index_for(oop protection_domain) { |
tschatzl@5862 | 202 | return hash_to_index(compute_hash(protection_domain)); |
tschatzl@5862 | 203 | } |
tschatzl@5862 | 204 | |
tschatzl@5862 | 205 | ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain); |
tschatzl@5862 | 206 | ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain); |
tschatzl@5862 | 207 | |
tschatzl@5862 | 208 | public: |
tschatzl@5862 | 209 | |
tschatzl@5862 | 210 | ProtectionDomainCacheTable(int table_size); |
tschatzl@5862 | 211 | |
tschatzl@5862 | 212 | ProtectionDomainCacheEntry* get(oop protection_domain); |
tschatzl@5862 | 213 | void free(ProtectionDomainCacheEntry* entry); |
tschatzl@5862 | 214 | |
tschatzl@5862 | 215 | void unlink(BoolObjectClosure* cl); |
tschatzl@5862 | 216 | |
tschatzl@5862 | 217 | // GC support |
tschatzl@5862 | 218 | void oops_do(OopClosure* f); |
tschatzl@5862 | 219 | void always_strong_oops_do(OopClosure* f); |
stefank@6992 | 220 | void roots_oops_do(OopClosure* strong, OopClosure* weak); |
tschatzl@5862 | 221 | |
tschatzl@5862 | 222 | static uint bucket_size(); |
tschatzl@5862 | 223 | |
tschatzl@5862 | 224 | void print() PRODUCT_RETURN; |
tschatzl@5862 | 225 | void verify(); |
tschatzl@5862 | 226 | }; |
tschatzl@5862 | 227 | |
duke@435 | 228 | |
zgu@3900 | 229 | class ProtectionDomainEntry :public CHeapObj<mtClass> { |
duke@435 | 230 | friend class VMStructs; |
duke@435 | 231 | public: |
duke@435 | 232 | ProtectionDomainEntry* _next; |
tschatzl@5862 | 233 | ProtectionDomainCacheEntry* _pd_cache; |
duke@435 | 234 | |
tschatzl@5862 | 235 | ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) { |
tschatzl@5862 | 236 | _pd_cache = pd_cache; |
tschatzl@5862 | 237 | _next = next; |
duke@435 | 238 | } |
duke@435 | 239 | |
duke@435 | 240 | ProtectionDomainEntry* next() { return _next; } |
tschatzl@5862 | 241 | oop protection_domain() { return _pd_cache->protection_domain(); } |
duke@435 | 242 | }; |
duke@435 | 243 | |
duke@435 | 244 | // An entry in the system dictionary, this describes a class as |
coleenp@4037 | 245 | // { Klass*, loader, protection_domain }. |
duke@435 | 246 | |
coleenp@4037 | 247 | class DictionaryEntry : public HashtableEntry<Klass*, mtClass> { |
duke@435 | 248 | friend class VMStructs; |
duke@435 | 249 | private: |
duke@435 | 250 | // Contains the set of approved protection domains that can access |
duke@435 | 251 | // this system dictionary entry. |
tschatzl@5862 | 252 | // |
tschatzl@5862 | 253 | // This protection domain set is a set of tuples: |
tschatzl@5862 | 254 | // |
tschatzl@5862 | 255 | // (InstanceKlass C, initiating class loader ICL, Protection Domain PD) |
tschatzl@5862 | 256 | // |
tschatzl@5862 | 257 | // [Note that C.protection_domain(), which is stored in the java.lang.Class |
tschatzl@5862 | 258 | // mirror of C, is NOT the same as PD] |
tschatzl@5862 | 259 | // |
tschatzl@5862 | 260 | // If such an entry (C, ICL, PD) exists in the table, it means that |
tschatzl@5862 | 261 | // it is okay for a class Foo to reference C, where |
tschatzl@5862 | 262 | // |
tschatzl@5862 | 263 | // Foo.protection_domain() == PD, and |
tschatzl@5862 | 264 | // Foo's defining class loader == ICL |
tschatzl@5862 | 265 | // |
tschatzl@5862 | 266 | // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain() |
tschatzl@5862 | 267 | // It is essentially a cache to avoid repeated Java up-calls to |
tschatzl@5862 | 268 | // ClassLoader.checkPackageAccess(). |
tschatzl@5862 | 269 | // |
duke@435 | 270 | ProtectionDomainEntry* _pd_set; |
coleenp@4037 | 271 | ClassLoaderData* _loader_data; |
duke@435 | 272 | |
duke@435 | 273 | public: |
duke@435 | 274 | // Tells whether a protection is in the approved set. |
duke@435 | 275 | bool contains_protection_domain(oop protection_domain) const; |
duke@435 | 276 | // Adds a protection domain to the approved set. |
tschatzl@5862 | 277 | void add_protection_domain(Dictionary* dict, oop protection_domain); |
duke@435 | 278 | |
coleenp@4037 | 279 | Klass* klass() const { return (Klass*)literal(); } |
coleenp@4037 | 280 | Klass** klass_addr() { return (Klass**)literal_addr(); } |
duke@435 | 281 | |
duke@435 | 282 | DictionaryEntry* next() const { |
coleenp@4037 | 283 | return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next(); |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | DictionaryEntry** next_addr() { |
coleenp@4037 | 287 | return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr(); |
duke@435 | 288 | } |
duke@435 | 289 | |
coleenp@4037 | 290 | ClassLoaderData* loader_data() const { return _loader_data; } |
coleenp@4037 | 291 | void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; } |
duke@435 | 292 | |
duke@435 | 293 | ProtectionDomainEntry* pd_set() const { return _pd_set; } |
duke@435 | 294 | void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; } |
duke@435 | 295 | |
duke@435 | 296 | bool has_protection_domain() { return _pd_set != NULL; } |
duke@435 | 297 | |
duke@435 | 298 | // Tells whether the initiating class' protection can access the this _klass |
duke@435 | 299 | bool is_valid_protection_domain(Handle protection_domain) { |
duke@435 | 300 | if (!ProtectionDomainVerification) return true; |
duke@435 | 301 | if (!SystemDictionary::has_checkPackageAccess()) return true; |
duke@435 | 302 | |
duke@435 | 303 | return protection_domain() == NULL |
duke@435 | 304 | ? true |
duke@435 | 305 | : contains_protection_domain(protection_domain()); |
duke@435 | 306 | } |
duke@435 | 307 | |
tschatzl@5862 | 308 | void set_strongly_reachable() { |
duke@435 | 309 | for (ProtectionDomainEntry* current = _pd_set; |
duke@435 | 310 | current != NULL; |
duke@435 | 311 | current = current->_next) { |
tschatzl@5862 | 312 | current->_pd_cache->set_strongly_reachable(); |
duke@435 | 313 | } |
duke@435 | 314 | } |
duke@435 | 315 | |
duke@435 | 316 | void verify_protection_domain_set() { |
duke@435 | 317 | for (ProtectionDomainEntry* current = _pd_set; |
duke@435 | 318 | current != NULL; |
duke@435 | 319 | current = current->_next) { |
tschatzl@5862 | 320 | current->_pd_cache->protection_domain()->verify(); |
duke@435 | 321 | } |
duke@435 | 322 | } |
duke@435 | 323 | |
coleenp@4037 | 324 | bool equals(Symbol* class_name, ClassLoaderData* loader_data) const { |
coleenp@4037 | 325 | Klass* klass = (Klass*)literal(); |
coleenp@4037 | 326 | return (InstanceKlass::cast(klass)->name() == class_name && |
coleenp@4037 | 327 | _loader_data == loader_data); |
duke@435 | 328 | } |
duke@435 | 329 | |
duke@435 | 330 | void print() { |
duke@435 | 331 | int count = 0; |
duke@435 | 332 | for (ProtectionDomainEntry* current = _pd_set; |
duke@435 | 333 | current != NULL; |
duke@435 | 334 | current = current->_next) { |
duke@435 | 335 | count++; |
duke@435 | 336 | } |
duke@435 | 337 | tty->print_cr("pd set = #%d", count); |
duke@435 | 338 | } |
duke@435 | 339 | }; |
jrose@1145 | 340 | |
coleenp@2497 | 341 | // Entry in a SymbolPropertyTable, mapping a single Symbol* |
jrose@1145 | 342 | // to a managed and an unmanaged pointer. |
zgu@3900 | 343 | class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> { |
jrose@1145 | 344 | friend class VMStructs; |
jrose@1145 | 345 | private: |
jrose@1862 | 346 | intptr_t _symbol_mode; // secondary key |
coleenp@4037 | 347 | Method* _method; |
coleenp@4037 | 348 | oop _method_type; |
jrose@1145 | 349 | |
jrose@1145 | 350 | public: |
coleenp@2497 | 351 | Symbol* symbol() const { return literal(); } |
jrose@1145 | 352 | |
jrose@1862 | 353 | intptr_t symbol_mode() const { return _symbol_mode; } |
jrose@1862 | 354 | void set_symbol_mode(intptr_t m) { _symbol_mode = m; } |
jrose@1862 | 355 | |
coleenp@4037 | 356 | Method* method() const { return _method; } |
coleenp@4037 | 357 | void set_method(Method* p) { _method = p; } |
jrose@1145 | 358 | |
coleenp@4037 | 359 | oop method_type() const { return _method_type; } |
coleenp@4037 | 360 | oop* method_type_addr() { return &_method_type; } |
coleenp@4037 | 361 | void set_method_type(oop p) { _method_type = p; } |
jrose@1145 | 362 | |
jrose@1145 | 363 | SymbolPropertyEntry* next() const { |
zgu@3900 | 364 | return (SymbolPropertyEntry*)HashtableEntry<Symbol*, mtSymbol>::next(); |
jrose@1145 | 365 | } |
jrose@1145 | 366 | |
jrose@1145 | 367 | SymbolPropertyEntry** next_addr() { |
zgu@3900 | 368 | return (SymbolPropertyEntry**)HashtableEntry<Symbol*, mtSymbol>::next_addr(); |
jrose@1145 | 369 | } |
jrose@1145 | 370 | |
jrose@1145 | 371 | void print_on(outputStream* st) const { |
jrose@1145 | 372 | symbol()->print_value_on(st); |
jrose@1862 | 373 | st->print("/mode="INTX_FORMAT, symbol_mode()); |
jrose@1145 | 374 | st->print(" -> "); |
jrose@1145 | 375 | bool printed = false; |
coleenp@4037 | 376 | if (method() != NULL) { |
coleenp@4037 | 377 | method()->print_value_on(st); |
jrose@1145 | 378 | printed = true; |
jrose@1145 | 379 | } |
coleenp@4037 | 380 | if (method_type() != NULL) { |
jrose@1145 | 381 | if (printed) st->print(" and "); |
drchase@6680 | 382 | st->print(INTPTR_FORMAT, p2i((void *)method_type())); |
jrose@1145 | 383 | printed = true; |
jrose@1145 | 384 | } |
jrose@1145 | 385 | st->print_cr(printed ? "" : "(empty)"); |
jrose@1145 | 386 | } |
jrose@1145 | 387 | }; |
jrose@1145 | 388 | |
jrose@1145 | 389 | // A system-internal mapping of symbols to pointers, both managed |
jrose@1145 | 390 | // and unmanaged. Used to record the auto-generation of each method |
jrose@1145 | 391 | // MethodHandle.invoke(S)T, for all signatures (S)T. |
zgu@3900 | 392 | class SymbolPropertyTable : public Hashtable<Symbol*, mtSymbol> { |
jrose@1145 | 393 | friend class VMStructs; |
jrose@1145 | 394 | private: |
jrose@1145 | 395 | SymbolPropertyEntry* bucket(int i) { |
zgu@3900 | 396 | return (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::bucket(i); |
jrose@1145 | 397 | } |
jrose@1145 | 398 | |
jrose@1145 | 399 | // The following method is not MT-safe and must be done under lock. |
jrose@1145 | 400 | SymbolPropertyEntry** bucket_addr(int i) { |
zgu@3900 | 401 | return (SymbolPropertyEntry**) Hashtable<Symbol*, mtSymbol>::bucket_addr(i); |
jrose@1145 | 402 | } |
jrose@1145 | 403 | |
jrose@1145 | 404 | void add_entry(int index, SymbolPropertyEntry* new_entry) { |
jrose@1145 | 405 | ShouldNotReachHere(); |
jrose@1145 | 406 | } |
jrose@1145 | 407 | void set_entry(int index, SymbolPropertyEntry* new_entry) { |
jrose@1145 | 408 | ShouldNotReachHere(); |
jrose@1145 | 409 | } |
jrose@1145 | 410 | |
coleenp@2497 | 411 | SymbolPropertyEntry* new_entry(unsigned int hash, Symbol* symbol, intptr_t symbol_mode) { |
zgu@3900 | 412 | SymbolPropertyEntry* entry = (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::new_entry(hash, symbol); |
coleenp@2497 | 413 | // Hashtable with Symbol* literal must increment and decrement refcount. |
coleenp@2497 | 414 | symbol->increment_refcount(); |
jrose@1862 | 415 | entry->set_symbol_mode(symbol_mode); |
coleenp@4037 | 416 | entry->set_method(NULL); |
coleenp@4037 | 417 | entry->set_method_type(NULL); |
jrose@1145 | 418 | return entry; |
jrose@1145 | 419 | } |
jrose@1145 | 420 | |
jrose@1145 | 421 | public: |
jrose@1145 | 422 | SymbolPropertyTable(int table_size); |
zgu@3900 | 423 | SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, int number_of_entries); |
jrose@1145 | 424 | |
jrose@1145 | 425 | void free_entry(SymbolPropertyEntry* entry) { |
coleenp@2497 | 426 | // decrement Symbol refcount here because hashtable doesn't. |
coleenp@2497 | 427 | entry->literal()->decrement_refcount(); |
zgu@3900 | 428 | Hashtable<Symbol*, mtSymbol>::free_entry(entry); |
jrose@1145 | 429 | } |
jrose@1145 | 430 | |
coleenp@2497 | 431 | unsigned int compute_hash(Symbol* sym, intptr_t symbol_mode) { |
jrose@1145 | 432 | // Use the regular identity_hash. |
zgu@3900 | 433 | return Hashtable<Symbol*, mtSymbol>::compute_hash(sym) ^ symbol_mode; |
jrose@1862 | 434 | } |
jrose@1862 | 435 | |
coleenp@2497 | 436 | int index_for(Symbol* name, intptr_t symbol_mode) { |
jrose@1862 | 437 | return hash_to_index(compute_hash(name, symbol_mode)); |
jrose@1145 | 438 | } |
jrose@1145 | 439 | |
jrose@1145 | 440 | // need not be locked; no state change |
coleenp@2497 | 441 | SymbolPropertyEntry* find_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode); |
jrose@1145 | 442 | |
jrose@1145 | 443 | // must be done under SystemDictionary_lock |
coleenp@2497 | 444 | SymbolPropertyEntry* add_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode); |
jrose@1145 | 445 | |
jrose@1145 | 446 | // GC support |
jrose@1145 | 447 | void oops_do(OopClosure* f); |
coleenp@4037 | 448 | |
coleenp@4037 | 449 | void methods_do(void f(Method*)); |
jrose@1145 | 450 | |
jrose@1145 | 451 | // Sharing support |
jrose@1145 | 452 | void reorder_dictionary(); |
jrose@1145 | 453 | |
jrose@1145 | 454 | #ifndef PRODUCT |
jrose@1145 | 455 | void print(); |
jrose@1145 | 456 | #endif |
jrose@1145 | 457 | void verify(); |
jrose@1145 | 458 | }; |
stefank@2314 | 459 | #endif // SHARE_VM_CLASSFILE_DICTIONARY_HPP |