< prev index next >

src/share/vm/classfile/dictionary.hpp

Print this page




  24 
  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 #include "utilities/ostream.hpp"
  33 
  34 class DictionaryEntry;
  35 class PSPromotionManager;
  36 class ProtectionDomainCacheTable;
  37 class ProtectionDomainCacheEntry;
  38 class BoolObjectClosure;
  39 
  40 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41 // The data structure for the system dictionary (and the shared system
  42 // dictionary).
  43 
  44 class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
  45   friend class VMStructs;
  46 private:
  47   // current iteration index.
  48   static int                    _current_class_index;
  49   // pointer to the current hash table entry.
  50   static DictionaryEntry*       _current_class_entry;
  51 
  52   ProtectionDomainCacheTable*   _pd_cache_table;
  53 
  54   DictionaryEntry* get_entry(int index, unsigned int hash,
  55                              Symbol* name, ClassLoaderData* loader_data);
  56 
  57 protected:
  58   DictionaryEntry* bucket(int i) const {
  59     return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
  60   }
  61 
  62   // The following method is not MT-safe and must be done under lock.
  63   DictionaryEntry** bucket_addr(int i) {
  64     return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
  65   }
  66 
  67   void add_entry(int index, DictionaryEntry* new_entry) {
  68     Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
  69   }
  70 
  71   static size_t entry_size();
  72 public:
  73   Dictionary(int table_size);
  74   Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
  75 
  76   DictionaryEntry* new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data);
  77 
  78   DictionaryEntry* new_entry();
  79 
  80   void free_entry(DictionaryEntry* entry);
  81 
  82   void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
  83 
  84   Klass* find_class(int index, unsigned int hash,
  85                       Symbol* name, ClassLoaderData* loader_data);
  86 
  87   Klass* find_shared_class(int index, unsigned int hash, Symbol* name);
  88 
  89   // Compiler support
  90   Klass* try_get_next_class();
  91 
  92   // GC support
  93   void oops_do(OopClosure* f);
  94   void always_strong_oops_do(OopClosure* blk);
  95   void roots_oops_do(OopClosure* strong, OopClosure* weak);
  96 
  97   void always_strong_classes_do(KlassClosure* closure);
  98 
  99   void classes_do(void f(Klass*));
 100   void classes_do(void f(Klass*, TRAPS), TRAPS);
 101   void classes_do(void f(Klass*, ClassLoaderData*));
 102 
 103   void methods_do(void f(Method*));
 104 
 105   void unlink(BoolObjectClosure* is_alive);
 106   void remove_classes_in_error_state();
 107 
 108   // Classes loaded by the bootstrap loader are always strongly reachable.
 109   // If we're not doing class unloading, all classes are strongly reachable.
 110   static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) {
 111     assert (klass != NULL, "should have non-null klass");
 112     return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
 113   }
 114 
 115   // Unload (that is, break root links to) all unmarked classes and loaders.
 116   void do_unloading();
 117 
 118   // Protection domains
 119   Klass* find(int index, unsigned int hash, Symbol* name,
 120                 ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
 121   bool is_valid_protection_domain(int index, unsigned int hash,
 122                                   Symbol* name, ClassLoaderData* loader_data,
 123                                   Handle protection_domain);
 124   void add_protection_domain(int index, unsigned int hash,
 125                              instanceKlassHandle klass, ClassLoaderData* loader_data,
 126                              Handle protection_domain, TRAPS);
 127 
 128   // Sharing support
 129   void reorder_dictionary();
 130 
 131   ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
 132 
 133   void print(bool details = true);
 134 #ifdef ASSERT
 135   void printPerformanceInfoDetails();
 136 #endif // ASSERT
 137   void verify();
 138 };
 139 
 140 // The following classes can be in dictionary.cpp, but we need these
 141 // to be in header file so that SA's vmStructs can access them.
 142 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
 143   friend class VMStructs;
 144  private:
 145   // Flag indicating whether this protection domain entry is strongly reachable.


 226   void verify();
 227 };
 228 
 229 
 230 class ProtectionDomainEntry :public CHeapObj<mtClass> {
 231   friend class VMStructs;
 232  public:
 233   ProtectionDomainEntry* _next;
 234   ProtectionDomainCacheEntry* _pd_cache;
 235 
 236   ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
 237     _pd_cache = pd_cache;
 238     _next     = next;
 239   }
 240 
 241   ProtectionDomainEntry* next() { return _next; }
 242   oop protection_domain() { return _pd_cache->protection_domain(); }
 243 };
 244 
 245 // An entry in the system dictionary, this describes a class as
 246 // { Klass*, loader, protection_domain }.
 247 
 248 class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
 249   friend class VMStructs;
 250  private:
 251   // Contains the set of approved protection domains that can access
 252   // this system dictionary entry.
 253   //
 254   // This protection domain set is a set of tuples:
 255   //
 256   // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
 257   //
 258   // [Note that C.protection_domain(), which is stored in the java.lang.Class
 259   // mirror of C, is NOT the same as PD]
 260   //
 261   // If such an entry (C, ICL, PD) exists in the table, it means that
 262   // it is okay for a class Foo to reference C, where
 263   //
 264   //    Foo.protection_domain() == PD, and
 265   //    Foo's defining class loader == ICL
 266   //
 267   // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
 268   // It is essentially a cache to avoid repeated Java up-calls to
 269   // ClassLoader.checkPackageAccess().
 270   //
 271   ProtectionDomainEntry* _pd_set;
 272   ClassLoaderData*       _loader_data;
 273 
 274  public:
 275   // Tells whether a protection is in the approved set.
 276   bool contains_protection_domain(oop protection_domain) const;
 277   // Adds a protection domain to the approved set.
 278   void add_protection_domain(Dictionary* dict, Handle protection_domain);
 279 
 280   Klass* klass() const { return (Klass*)literal(); }
 281   Klass** klass_addr() { return (Klass**)literal_addr(); }
 282 
 283   DictionaryEntry* next() const {
 284     return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
 285   }
 286 
 287   DictionaryEntry** next_addr() {
 288     return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
 289   }
 290 
 291   ClassLoaderData* loader_data() const { return _loader_data; }
 292   void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
 293 
 294   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 295   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 296 
 297   bool has_protection_domain() { return _pd_set != NULL; }
 298 
 299   // Tells whether the initiating class' protection can access the this _klass
 300   bool is_valid_protection_domain(Handle protection_domain) {
 301     if (!ProtectionDomainVerification) return true;
 302     if (!SystemDictionary::has_checkPackageAccess()) return true;
 303 
 304     return protection_domain() == NULL
 305          ? true
 306          : contains_protection_domain(protection_domain());
 307   }
 308 
 309   void set_strongly_reachable() {
 310     for (ProtectionDomainEntry* current = _pd_set;
 311                                 current != NULL;
 312                                 current = current->_next) {
 313       current->_pd_cache->set_strongly_reachable();
 314     }
 315   }
 316 
 317   void verify_protection_domain_set() {
 318     for (ProtectionDomainEntry* current = _pd_set;
 319                                 current != NULL;
 320                                 current = current->_next) {
 321       current->_pd_cache->protection_domain()->verify();
 322     }
 323   }
 324 
 325   bool equals(const Symbol* class_name, ClassLoaderData* loader_data) const {
 326     Klass* klass = (Klass*)literal();
 327     return (klass->name() == class_name && _loader_data == loader_data);
 328   }
 329 
 330   void print_count(outputStream *st) {
 331     int count = 0;
 332     for (ProtectionDomainEntry* current = _pd_set;
 333                                 current != NULL;
 334                                 current = current->_next) {
 335       count++;
 336     }
 337     st->print_cr("pd set count = #%d", count);
 338   }
 339 };
 340 
 341 // Entry in a SymbolPropertyTable, mapping a single Symbol*
 342 // to a managed and an unmanaged pointer.
 343 class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
 344   friend class VMStructs;
 345  private:
 346   intptr_t _symbol_mode;  // secondary key




  24 
  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 #include "utilities/ostream.hpp"
  33 
  34 class DictionaryEntry;
  35 class PSPromotionManager;
  36 class ProtectionDomainCacheTable;
  37 class ProtectionDomainCacheEntry;
  38 class BoolObjectClosure;
  39 
  40 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41 // The data structure for the system dictionary (and the shared system
  42 // dictionary).
  43 
  44 class Dictionary : public TwoOopHashtable<InstanceKlass*, mtClass> {
  45   friend class VMStructs;
  46 private:
  47   // current iteration index.
  48   static int                    _current_class_index;
  49   // pointer to the current hash table entry.
  50   static DictionaryEntry*       _current_class_entry;
  51 
  52   ProtectionDomainCacheTable*   _pd_cache_table;
  53 
  54   DictionaryEntry* get_entry(int index, unsigned int hash,
  55                              Symbol* name, ClassLoaderData* loader_data);
  56 
  57 protected:
  58   DictionaryEntry* bucket(int i) const {
  59     return (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i);
  60   }
  61 
  62   // The following method is not MT-safe and must be done under lock.
  63   DictionaryEntry** bucket_addr(int i) {
  64     return (DictionaryEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
  65   }
  66 
  67   void add_entry(int index, DictionaryEntry* new_entry) {
  68     Hashtable<InstanceKlass*, mtClass>::add_entry(index, (HashtableEntry<InstanceKlass*, mtClass>*)new_entry);
  69   }
  70 
  71   static size_t entry_size();
  72 public:
  73   Dictionary(int table_size);
  74   Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
  75 
  76   DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass, ClassLoaderData* loader_data);
  77 
  78   DictionaryEntry* new_entry();
  79 
  80   void free_entry(DictionaryEntry* entry);
  81 
  82   void add_klass(Symbol* class_name, ClassLoaderData* loader_data, InstanceKlass* obj);
  83 
  84   InstanceKlass* find_class(int index, unsigned int hash,
  85                             Symbol* name, ClassLoaderData* loader_data);
  86 
  87   InstanceKlass* find_shared_class(int index, unsigned int hash, Symbol* name);
  88 
  89   // Compiler support
  90   InstanceKlass* try_get_next_class();
  91 
  92   // GC support
  93   void oops_do(OopClosure* f);
  94   void always_strong_oops_do(OopClosure* blk);
  95   void roots_oops_do(OopClosure* strong, OopClosure* weak);
  96 
  97   void always_strong_classes_do(KlassClosure* closure);
  98 
  99   void classes_do(void f(Klass*));
 100   void classes_do(void f(Klass*, TRAPS), TRAPS);
 101   void classes_do(void f(Klass*, ClassLoaderData*));
 102 
 103   void methods_do(void f(Method*));
 104 
 105   void unlink(BoolObjectClosure* is_alive);
 106   void remove_classes_in_error_state();
 107 
 108   // Classes loaded by the bootstrap loader are always strongly reachable.
 109   // If we're not doing class unloading, all classes are strongly reachable.
 110   static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) {
 111     assert (klass != NULL, "should have non-null klass");
 112     return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
 113   }
 114 
 115   // Unload (that is, break root links to) all unmarked classes and loaders.
 116   void do_unloading();
 117 
 118   // Protection domains
 119   InstanceKlass* find(int index, unsigned int hash, Symbol* name,
 120                       ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
 121   bool is_valid_protection_domain(int index, unsigned int hash,
 122                                   Symbol* name, ClassLoaderData* loader_data,
 123                                   Handle protection_domain);
 124   void add_protection_domain(int index, unsigned int hash,
 125                              InstanceKlass* klass, ClassLoaderData* loader_data,
 126                              Handle protection_domain, TRAPS);
 127 
 128   // Sharing support
 129   void reorder_dictionary();
 130 
 131   ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
 132 
 133   void print(bool details = true);
 134 #ifdef ASSERT
 135   void printPerformanceInfoDetails();
 136 #endif // ASSERT
 137   void verify();
 138 };
 139 
 140 // The following classes can be in dictionary.cpp, but we need these
 141 // to be in header file so that SA's vmStructs can access them.
 142 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
 143   friend class VMStructs;
 144  private:
 145   // Flag indicating whether this protection domain entry is strongly reachable.


 226   void verify();
 227 };
 228 
 229 
 230 class ProtectionDomainEntry :public CHeapObj<mtClass> {
 231   friend class VMStructs;
 232  public:
 233   ProtectionDomainEntry* _next;
 234   ProtectionDomainCacheEntry* _pd_cache;
 235 
 236   ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
 237     _pd_cache = pd_cache;
 238     _next     = next;
 239   }
 240 
 241   ProtectionDomainEntry* next() { return _next; }
 242   oop protection_domain() { return _pd_cache->protection_domain(); }
 243 };
 244 
 245 // An entry in the system dictionary, this describes a class as
 246 // { InstanceKlass*, loader, protection_domain }.
 247 
 248 class DictionaryEntry : public HashtableEntry<InstanceKlass*, mtClass> {
 249   friend class VMStructs;
 250  private:
 251   // Contains the set of approved protection domains that can access
 252   // this system dictionary entry.
 253   //
 254   // This protection domain set is a set of tuples:
 255   //
 256   // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
 257   //
 258   // [Note that C.protection_domain(), which is stored in the java.lang.Class
 259   // mirror of C, is NOT the same as PD]
 260   //
 261   // If such an entry (C, ICL, PD) exists in the table, it means that
 262   // it is okay for a class Foo to reference C, where
 263   //
 264   //    Foo.protection_domain() == PD, and
 265   //    Foo's defining class loader == ICL
 266   //
 267   // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
 268   // It is essentially a cache to avoid repeated Java up-calls to
 269   // ClassLoader.checkPackageAccess().
 270   //
 271   ProtectionDomainEntry* _pd_set;
 272   ClassLoaderData*       _loader_data;
 273 
 274  public:
 275   // Tells whether a protection is in the approved set.
 276   bool contains_protection_domain(oop protection_domain) const;
 277   // Adds a protection domain to the approved set.
 278   void add_protection_domain(Dictionary* dict, Handle protection_domain);
 279 
 280   InstanceKlass* klass() const { return (InstanceKlass*)literal(); }
 281   InstanceKlass** klass_addr() { return (InstanceKlass**)literal_addr(); }
 282 
 283   DictionaryEntry* next() const {
 284     return (DictionaryEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
 285   }
 286 
 287   DictionaryEntry** next_addr() {
 288     return (DictionaryEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr();
 289   }
 290 
 291   ClassLoaderData* loader_data() const { return _loader_data; }
 292   void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
 293 
 294   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 295   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 296 
 297   bool has_protection_domain() { return _pd_set != NULL; }
 298 
 299   // Tells whether the initiating class' protection can access the this _klass
 300   bool is_valid_protection_domain(Handle protection_domain) {
 301     if (!ProtectionDomainVerification) return true;
 302     if (!SystemDictionary::has_checkPackageAccess()) return true;
 303 
 304     return protection_domain() == NULL
 305          ? true
 306          : contains_protection_domain(protection_domain());
 307   }
 308 
 309   void set_strongly_reachable() {
 310     for (ProtectionDomainEntry* current = _pd_set;
 311                                 current != NULL;
 312                                 current = current->_next) {
 313       current->_pd_cache->set_strongly_reachable();
 314     }
 315   }
 316 
 317   void verify_protection_domain_set() {
 318     for (ProtectionDomainEntry* current = _pd_set;
 319                                 current != NULL;
 320                                 current = current->_next) {
 321       current->_pd_cache->protection_domain()->verify();
 322     }
 323   }
 324 
 325   bool equals(const Symbol* class_name, ClassLoaderData* loader_data) const {
 326     InstanceKlass* klass = (InstanceKlass*)literal();
 327     return (klass->name() == class_name && _loader_data == loader_data);
 328   }
 329 
 330   void print_count(outputStream *st) {
 331     int count = 0;
 332     for (ProtectionDomainEntry* current = _pd_set;
 333                                 current != NULL;
 334                                 current = current->_next) {
 335       count++;
 336     }
 337     st->print_cr("pd set count = #%d", count);
 338   }
 339 };
 340 
 341 // Entry in a SymbolPropertyTable, mapping a single Symbol*
 342 // to a managed and an unmanaged pointer.
 343 class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
 344   friend class VMStructs;
 345  private:
 346   intptr_t _symbol_mode;  // secondary key


< prev index next >