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