< prev index next >

src/share/vm/classfile/dictionary.hpp

Print this page




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP
  26 #define SHARE_VM_CLASSFILE_DICTIONARY_HPP
  27 
  28 #include "classfile/protectionDomainCache.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "oops/instanceKlass.hpp"
  31 #include "oops/oop.hpp"
  32 #include "utilities/hashtable.hpp"
  33 #include "utilities/ostream.hpp"
  34 
  35 class DictionaryEntry;
  36 class BoolObjectClosure;
  37 
  38 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39 // The data structure for the system dictionary (and the shared system
  40 // dictionary).
  41 
  42 class Dictionary : public TwoOopHashtable<InstanceKlass*, mtClass> {
  43   friend class VMStructs;
  44 private:
  45   // current iteration index.
  46   static int                    _current_class_index;
  47   // pointer to the current hash table entry.
  48   static DictionaryEntry*       _current_class_entry;
  49 
  50   ProtectionDomainCacheTable*   _pd_cache_table;

  51 
  52   DictionaryEntry* get_entry(int index, unsigned int hash,
  53                              Symbol* name, ClassLoaderData* loader_data);
  54 
  55 protected:
  56   DictionaryEntry* bucket(int i) const {
  57     return (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i);
  58   }
  59 
  60   // The following method is not MT-safe and must be done under lock.
  61   DictionaryEntry** bucket_addr(int i) {
  62     return (DictionaryEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
  63   }
  64 
  65   void add_entry(int index, DictionaryEntry* new_entry) {
  66     Hashtable<InstanceKlass*, mtClass>::add_entry(index, (HashtableEntry<InstanceKlass*, mtClass>*)new_entry);
  67   }
  68 


  69   static size_t entry_size();
  70 public:
  71   Dictionary(int table_size);
  72   Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);

  73 
  74   DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass, ClassLoaderData* loader_data);
  75 
  76   void free_entry(DictionaryEntry* entry);
  77 
  78   void add_klass(Symbol* class_name, ClassLoaderData* loader_data, InstanceKlass* obj);
  79 
  80   InstanceKlass* find_class(int index, unsigned int hash,
  81                             Symbol* name, ClassLoaderData* loader_data);
  82 
  83   InstanceKlass* find_shared_class(int index, unsigned int hash, Symbol* name);
  84 
  85   // Compiler support
  86   InstanceKlass* try_get_next_class();
  87 
  88   // GC support
  89   void oops_do(OopClosure* f);
  90   void roots_oops_do(OopClosure* strong, OopClosure* weak);
  91 
  92   void classes_do(void f(Klass*));
  93   void classes_do(void f(Klass*, TRAPS), TRAPS);
  94   void classes_do(void f(Klass*, ClassLoaderData*));
  95 
  96   void unlink(BoolObjectClosure* is_alive);
  97   void remove_classes_in_error_state();
  98 
  99   // Classes loaded by the bootstrap loader are always strongly reachable.
 100   // If we're not doing class unloading, all classes are strongly reachable.
 101   static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) {
 102     assert (klass != NULL, "should have non-null klass");
 103     return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
 104   }
 105 
 106   // Unload (that is, break root links to) all unmarked classes and loaders.
 107   void do_unloading();
 108 
 109   // Protection domains
 110   InstanceKlass* find(int index, unsigned int hash, Symbol* name,
 111                       ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
 112   bool is_valid_protection_domain(int index, unsigned int hash,
 113                                   Symbol* name, ClassLoaderData* loader_data,
 114                                   Handle protection_domain);
 115   void add_protection_domain(int index, unsigned int hash,
 116                              InstanceKlass* klass, ClassLoaderData* loader_data,
 117                              Handle protection_domain, TRAPS);
 118 
 119   // Sharing support
 120   void reorder_dictionary();
 121 
 122   ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
 123 
 124   void print(bool details = true);
 125 #ifdef ASSERT
 126   void printPerformanceInfoDetails();
 127 #endif // ASSERT
 128   void verify();
 129 };
 130 
 131 // An entry in the system dictionary, this describes a class as
 132 // { InstanceKlass*, loader, protection_domain }.
 133 
 134 class DictionaryEntry : public HashtableEntry<InstanceKlass*, mtClass> {
 135   friend class VMStructs;
 136  private:
 137   // Contains the set of approved protection domains that can access
 138   // this system dictionary entry.
 139   //
 140   // This protection domain set is a set of tuples:
 141   //
 142   // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
 143   //
 144   // [Note that C.protection_domain(), which is stored in the java.lang.Class
 145   // mirror of C, is NOT the same as PD]
 146   //
 147   // If such an entry (C, ICL, PD) exists in the table, it means that
 148   // it is okay for a class Foo to reference C, where
 149   //
 150   //    Foo.protection_domain() == PD, and
 151   //    Foo's defining class loader == ICL
 152   //
 153   // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
 154   // It is essentially a cache to avoid repeated Java up-calls to
 155   // ClassLoader.checkPackageAccess().
 156   //
 157   ProtectionDomainEntry* _pd_set;
 158   ClassLoaderData*       _loader_data;
 159 
 160  public:
 161   // Tells whether a protection is in the approved set.
 162   bool contains_protection_domain(oop protection_domain) const;
 163   // Adds a protection domain to the approved set.
 164   void add_protection_domain(Dictionary* dict, Handle protection_domain);
 165 
 166   InstanceKlass* klass() const { return (InstanceKlass*)literal(); }
 167 
 168   DictionaryEntry* next() const {
 169     return (DictionaryEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
 170   }
 171 
 172   DictionaryEntry** next_addr() {
 173     return (DictionaryEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr();
 174   }
 175 
 176   ClassLoaderData* loader_data() const { return _loader_data; }
 177   void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
 178 
 179   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 180   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 181 
 182   // Tells whether the initiating class' protection can access the this _klass
 183   bool is_valid_protection_domain(Handle protection_domain) {
 184     if (!ProtectionDomainVerification) return true;
 185     if (!SystemDictionary::has_checkPackageAccess()) return true;
 186 
 187     return protection_domain() == NULL
 188          ? true
 189          : contains_protection_domain(protection_domain());
 190   }
 191 
 192   void verify_protection_domain_set() {
 193     for (ProtectionDomainEntry* current = _pd_set;
 194                                 current != NULL;
 195                                 current = current->_next) {
 196       current->_pd_cache->protection_domain()->verify();
 197     }
 198   }
 199 
 200   bool equals(const Symbol* class_name, ClassLoaderData* loader_data) const {
 201     InstanceKlass* klass = (InstanceKlass*)literal();
 202     return (klass->name() == class_name && _loader_data == loader_data);
 203   }
 204 
 205   void print_count(outputStream *st) {
 206     int count = 0;
 207     for (ProtectionDomainEntry* current = _pd_set;
 208                                 current != NULL;
 209                                 current = current->_next) {
 210       count++;
 211     }
 212     st->print_cr("pd set count = #%d", count);
 213   }
 214 
 215   void verify();
 216 };
 217 
 218 // Entry in a SymbolPropertyTable, mapping a single Symbol*
 219 // to a managed and an unmanaged pointer.
 220 class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
 221   friend class VMStructs;
 222  private:




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP
  26 #define SHARE_VM_CLASSFILE_DICTIONARY_HPP
  27 
  28 #include "classfile/protectionDomainCache.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "oops/instanceKlass.hpp"
  31 #include "oops/oop.hpp"
  32 #include "utilities/hashtable.hpp"
  33 #include "utilities/ostream.hpp"
  34 
  35 class DictionaryEntry;
  36 class BoolObjectClosure;
  37 
  38 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39 // The data structure for the class loader data dictionaries (and the shared system
  40 // dictionary).
  41 
  42 class Dictionary : public Hashtable<InstanceKlass*, mtClass> {
  43   friend class VMStructs;





  44 
  45   ClassLoaderData* _loader_data;  // backpointer to owning loader
  46   ClassLoaderData* loader_data() const { return _loader_data; }
  47 
  48   DictionaryEntry* get_entry(int index, unsigned int hash, Symbol* name);

  49 
  50 protected:
  51   DictionaryEntry* bucket(int i) const {
  52     return (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i);
  53   }
  54 
  55   // The following method is not MT-safe and must be done under lock.
  56   DictionaryEntry** bucket_addr(int i) {
  57     return (DictionaryEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
  58   }
  59 
  60   void add_entry(int index, DictionaryEntry* new_entry) {
  61     Hashtable<InstanceKlass*, mtClass>::add_entry(index, (HashtableEntry<InstanceKlass*, mtClass>*)new_entry);
  62   }
  63 
  64   void free_entry(DictionaryEntry* entry);
  65 
  66   static size_t entry_size();
  67 public:
  68   Dictionary(ClassLoaderData* loader_data, int table_size);
  69   Dictionary(ClassLoaderData* loader_data, int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
  70   ~Dictionary();
  71 
  72   DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass);
  73 
  74   void add_klass(int index, unsigned int hash, Symbol* class_name, InstanceKlass* obj);


  75 
  76   InstanceKlass* find_class(int index, unsigned int hash, Symbol* name);

  77 
  78   InstanceKlass* find_shared_class(int index, unsigned int hash, Symbol* name);
  79 



  80   // GC support
  81   void oops_do(OopClosure* f);
  82   void roots_oops_do(OopClosure* strong, OopClosure* weak);
  83 
  84   void classes_do(void f(InstanceKlass*));
  85   void classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
  86   void all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
  87 
  88   void unlink(BoolObjectClosure* is_alive);
  89   void remove_classes_in_error_state();
  90 
  91   // Unload classes whose defining loaders are unloaded







  92   void do_unloading();
  93 
  94   // Protection domains
  95   InstanceKlass* find(int index, unsigned int hash, Symbol* name, Handle protection_domain);

  96   bool is_valid_protection_domain(int index, unsigned int hash,
  97                                   Symbol* name,
  98                                   Handle protection_domain);
  99   void add_protection_domain(int index, unsigned int hash,
 100                              InstanceKlass* klass,
 101                              Handle protection_domain, TRAPS);
 102 
 103   // Sharing support
 104   void reorder_dictionary();
 105 


 106   void print(bool details = true);
 107 #ifdef ASSERT
 108   void printPerformanceInfoDetails();
 109 #endif // ASSERT
 110   void verify();
 111 };
 112 
 113 // An entry in the class loader data dictionaries, this describes a class as
 114 // { InstanceKlass*, protection_domain }.
 115 
 116 class DictionaryEntry : public HashtableEntry<InstanceKlass*, mtClass> {
 117   friend class VMStructs;
 118  private:
 119   // Contains the set of approved protection domains that can access
 120   // this dictionary entry.
 121   //
 122   // This protection domain set is a set of tuples:
 123   //
 124   // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
 125   //
 126   // [Note that C.protection_domain(), which is stored in the java.lang.Class
 127   // mirror of C, is NOT the same as PD]
 128   //
 129   // If such an entry (C, ICL, PD) exists in the table, it means that
 130   // it is okay for a class Foo to reference C, where
 131   //
 132   //    Foo.protection_domain() == PD, and
 133   //    Foo's defining class loader == ICL
 134   //
 135   // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
 136   // It is essentially a cache to avoid repeated Java up-calls to
 137   // ClassLoader.checkPackageAccess().
 138   //
 139   ProtectionDomainEntry* _pd_set;

 140 
 141  public:
 142   // Tells whether a protection is in the approved set.
 143   bool contains_protection_domain(oop protection_domain) const;
 144   // Adds a protection domain to the approved set.
 145   void add_protection_domain(Dictionary* dict, Handle protection_domain);
 146 
 147   InstanceKlass* instance_klass() const { return (InstanceKlass*)literal(); }
 148 
 149   DictionaryEntry* next() const {
 150     return (DictionaryEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
 151   }
 152 
 153   DictionaryEntry** next_addr() {
 154     return (DictionaryEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr();
 155   }
 156 



 157   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 158   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 159 
 160   // Tells whether the initiating class' protection domain can access the klass in this entry
 161   bool is_valid_protection_domain(Handle protection_domain) {
 162     if (!ProtectionDomainVerification) return true;
 163     if (!SystemDictionary::has_checkPackageAccess()) return true;
 164 
 165     return protection_domain() == NULL
 166          ? true
 167          : contains_protection_domain(protection_domain());
 168   }
 169 
 170   void verify_protection_domain_set() {
 171     for (ProtectionDomainEntry* current = _pd_set;
 172                                 current != NULL;
 173                                 current = current->_next) {
 174       current->_pd_cache->protection_domain()->verify();
 175     }
 176   }
 177 
 178   bool equals(const Symbol* class_name) const {
 179     InstanceKlass* klass = (InstanceKlass*)literal();
 180     return (klass->name() == class_name);
 181   }
 182 
 183   void print_count(outputStream *st) {
 184     int count = 0;
 185     for (ProtectionDomainEntry* current = _pd_set;
 186                                 current != NULL;
 187                                 current = current->_next) {
 188       count++;
 189     }
 190     st->print_cr("pd set count = #%d", count);
 191   }
 192 
 193   void verify();
 194 };
 195 
 196 // Entry in a SymbolPropertyTable, mapping a single Symbol*
 197 // to a managed and an unmanaged pointer.
 198 class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
 199   friend class VMStructs;
 200  private:


< prev index next >