src/share/vm/classfile/dictionary.hpp

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 5100
43083e670adf
child 5865
aa6f2ea19d8f
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

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

mercurial