src/share/vm/classfile/dictionary.hpp

Print this page
rev 5310 : imported patch ioi_original_patch
rev 5311 : imported patch cleanup


 118   void add_protection_domain(int index, unsigned int hash,
 119                              instanceKlassHandle klass, ClassLoaderData* loader_data,
 120                              Handle protection_domain, TRAPS);
 121 
 122   // Sharing support
 123   void reorder_dictionary();
 124 
 125   ProtectionDomainCacheEntry* cache_get(oop protection_domain);
 126 
 127 #ifndef PRODUCT
 128   void print();
 129 #endif
 130   void verify();
 131 };
 132 
 133 // The following classes can be in dictionary.cpp, but we need these
 134 // to be in header file so that SA's vmStructs can access them.
 135 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
 136   friend class VMStructs;
 137  private:

 138   int _refcount;
 139   int _scan_generation;



 140  public:
 141   oop protection_domain() { return literal(); }
 142 
 143   void increment_refcount() {
 144     assert(_refcount >= 0, "sanity");
 145     _refcount++;
 146   }
 147 
 148   int refcount() { return _refcount; }
 149   int decrement_refcount() {
 150     assert(_refcount > 0, "sanity");
 151     _refcount--;
 152     return _refcount;
 153   }
 154 
 155   void init() {
 156     _refcount = 0;
 157     _scan_generation = 0;
 158   }
 159 
 160   ProtectionDomainCacheEntry* next() {
 161     return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
 162   }
 163 
 164   ProtectionDomainCacheEntry** next_addr() {
 165     return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
 166   }
 167 
 168   void oops_do(OopClosure* f) {
 169     f->do_oop(literal_addr());
 170   }
 171 
 172   void set_strongly_reachable(int gen) { _scan_generation = gen; }
 173 
 174   bool is_strongly_reachable(int gen) { return _scan_generation == gen; }





 175 };
 176 









 177 class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
 178   friend class VMStructs;
 179 private:
 180   ProtectionDomainCacheEntry* bucket(int i) {
 181     return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
 182   }
 183 
 184   // The following method is not MT-safe and must be done under lock.
 185   ProtectionDomainCacheEntry** bucket_addr(int i) {
 186     return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
 187   }
 188 
 189   ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
 190     ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
 191     entry->init();
 192     return entry;
 193   }
 194 
 195   unsigned int compute_hash(oop protection_domain) {
 196     return (unsigned int)(protection_domain->identity_hash());
 197   }
 198 
 199   int index_for(oop protection_domain) {
 200     return hash_to_index(compute_hash(protection_domain));
 201   }
 202 
 203   ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
 204   ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
 205 
 206 public:
 207 
 208   ProtectionDomainCacheTable(int table_size);
 209 
 210   ProtectionDomainCacheEntry* get(oop protection_domain);
 211   void free(ProtectionDomainCacheEntry* entry);
 212 
 213   // GC support
 214   void oops_do(OopClosure* f);
 215   void always_strong_oops_do(OopClosure* f, int gen);
 216 
 217 #ifndef PRODUCT
 218   void print();
 219 #endif
 220   void verify();
 221 };
 222 
 223 
 224 class ProtectionDomainEntry :public CHeapObj<mtClass> {
 225   friend class VMStructs;
 226  public:
 227   ProtectionDomainEntry* _next;
 228   ProtectionDomainCacheEntry* _pd_cache;
 229 
 230   ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
 231     _pd_cache = pd_cache;
 232     _next     = next;
 233     _pd_cache->increment_refcount();
 234   }
 235 
 236   ProtectionDomainEntry* next() { return _next; }
 237   oop protection_domain() { return _pd_cache->protection_domain(); }

 238   ProtectionDomainCacheEntry * release_pd_cache() {
 239     if (_pd_cache->decrement_refcount() == 0) {
 240       return _pd_cache;
 241     } else {
 242       return NULL;
 243     }
 244   }
 245 };
 246 
 247 // An entry in the system dictionary, this describes a class as
 248 // { Klass*, loader, protection_domain }.
 249 
 250 class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
 251   friend class VMStructs;
 252  private:
 253   // Contains the set of approved protection domains that can access
 254   // this system dictionary entry.
 255   ProtectionDomainEntry* _pd_set;
 256   ClassLoaderData*       _loader_data;
 257 


 273   }
 274 
 275   ClassLoaderData* loader_data() const { return _loader_data; }
 276   void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
 277 
 278   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 279   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 280 
 281   bool has_protection_domain() { return _pd_set != NULL; }
 282 
 283   // Tells whether the initiating class' protection can access the this _klass
 284   bool is_valid_protection_domain(Handle protection_domain) {
 285     if (!ProtectionDomainVerification) return true;
 286     if (!SystemDictionary::has_checkPackageAccess()) return true;
 287 
 288     return protection_domain() == NULL
 289          ? true
 290          : contains_protection_domain(protection_domain());
 291   }
 292 
 293   void set_strongly_reachable(int gen) {
 294     for (ProtectionDomainEntry* current = _pd_set;
 295                                 current != NULL;
 296                                 current = current->_next) {
 297       current->_pd_cache->set_strongly_reachable(gen);
 298     }
 299   }
 300 
 301   void verify_protection_domain_set() {
 302     for (ProtectionDomainEntry* current = _pd_set;
 303                                 current != NULL;
 304                                 current = current->_next) {
 305       current->_pd_cache->protection_domain()->verify();
 306     }
 307   }
 308 
 309   bool equals(Symbol* class_name, ClassLoaderData* loader_data) const {
 310     Klass* klass = (Klass*)literal();
 311     return (InstanceKlass::cast(klass)->name() == class_name &&
 312             _loader_data == loader_data);
 313   }
 314 
 315   void print() {
 316     int count = 0;
 317     for (ProtectionDomainEntry* current = _pd_set;




 118   void add_protection_domain(int index, unsigned int hash,
 119                              instanceKlassHandle klass, ClassLoaderData* loader_data,
 120                              Handle protection_domain, TRAPS);
 121 
 122   // Sharing support
 123   void reorder_dictionary();
 124 
 125   ProtectionDomainCacheEntry* cache_get(oop protection_domain);
 126 
 127 #ifndef PRODUCT
 128   void print();
 129 #endif
 130   void verify();
 131 };
 132 
 133 // The following classes can be in dictionary.cpp, but we need these
 134 // to be in header file so that SA's vmStructs can access them.
 135 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
 136   friend class VMStructs;
 137  private:
 138   // the number of system dictionary entries referring to this entry
 139   int _refcount;
 140   // flag indicating whether this protection domain entry is strongly reachable.
 141   // Used during iterating over the system dictionary to remember oops that need
 142   // to be updated.
 143   bool _strongly_reachable;
 144  public:
 145   oop protection_domain() { return literal(); }
 146 
 147   void increment_refcount() {
 148     assert(_refcount >= 0, "sanity");
 149     _refcount++;
 150   }
 151 
 152   int refcount() { return _refcount; }
 153   int decrement_refcount() {
 154     assert(_refcount > 0, "sanity");
 155     _refcount--;
 156     return _refcount;
 157   }
 158 
 159   void init() {
 160     _refcount = 0;
 161     _strongly_reachable = false;
 162   }
 163 
 164   ProtectionDomainCacheEntry* next() {
 165     return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
 166   }
 167 
 168   ProtectionDomainCacheEntry** next_addr() {
 169     return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
 170   }
 171 
 172   void oops_do(OopClosure* f) {
 173     f->do_oop(literal_addr());
 174   }
 175 
 176   void set_strongly_reachable() { _strongly_reachable = true; }
 177 
 178   bool is_strongly_reachable() { return _strongly_reachable; }
 179 
 180   void reset_strongly_reachable() { _strongly_reachable = false; }
 181 
 182   void print() PRODUCT_RETURN;
 183   void verify();
 184 };
 185 
 186 // the ProtectionDomainCacheTable contains all protection domain oops. The system
 187 // dictionary entries reference its entries instead of having references to oops
 188 // directly.
 189 // This is used to speed up system dictionary iteration: the oops in the
 190 // protection domain are the only ones referring the Java heap. So when there is
 191 // need to update these, instead of going over every entry of the system dictionary,
 192 // we only need to iterate over this set.
 193 // The amount of different protection domains used is typically magnitudes smaller
 194 // than the number of system dictionary entries (loaded classes).
 195 class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
 196   friend class VMStructs;
 197 private:
 198   ProtectionDomainCacheEntry* bucket(int i) {
 199     return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
 200   }
 201 
 202   // The following method is not MT-safe and must be done under lock.
 203   ProtectionDomainCacheEntry** bucket_addr(int i) {
 204     return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
 205   }
 206 
 207   ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
 208     ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
 209     entry->init();
 210     return entry;
 211   }
 212 
 213   static unsigned int compute_hash(oop protection_domain) {
 214     return (unsigned int)(protection_domain->identity_hash());
 215   }
 216 
 217   int index_for(oop protection_domain) {
 218     return hash_to_index(compute_hash(protection_domain));
 219   }
 220 
 221   ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
 222   ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
 223 
 224 public:
 225 
 226   ProtectionDomainCacheTable(int table_size);
 227 
 228   ProtectionDomainCacheEntry* get(oop protection_domain);
 229   void free(ProtectionDomainCacheEntry* entry);
 230 
 231   // GC support
 232   void oops_do(OopClosure* f);
 233   void always_strong_oops_do(OopClosure* f);
 234 
 235   static uint bucket_size();
 236 
 237   void print() PRODUCT_RETURN;
 238   void verify();
 239 };
 240 
 241 
 242 class ProtectionDomainEntry :public CHeapObj<mtClass> {
 243   friend class VMStructs;
 244  public:
 245   ProtectionDomainEntry* _next;
 246   ProtectionDomainCacheEntry* _pd_cache;
 247 
 248   ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
 249     _pd_cache = pd_cache;
 250     _next     = next;
 251     _pd_cache->increment_refcount();
 252   }
 253 
 254   ProtectionDomainEntry* next() { return _next; }
 255   oop protection_domain() { return _pd_cache->protection_domain(); }
 256 
 257   ProtectionDomainCacheEntry * release_pd_cache() {
 258     if (_pd_cache->decrement_refcount() == 0) {
 259       return _pd_cache;
 260     } else {
 261       return NULL;
 262     }
 263   }
 264 };
 265 
 266 // An entry in the system dictionary, this describes a class as
 267 // { Klass*, loader, protection_domain }.
 268 
 269 class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
 270   friend class VMStructs;
 271  private:
 272   // Contains the set of approved protection domains that can access
 273   // this system dictionary entry.
 274   ProtectionDomainEntry* _pd_set;
 275   ClassLoaderData*       _loader_data;
 276 


 292   }
 293 
 294   ClassLoaderData* loader_data() const { return _loader_data; }
 295   void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
 296 
 297   ProtectionDomainEntry* pd_set() const { return _pd_set; }
 298   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 299 
 300   bool has_protection_domain() { return _pd_set != NULL; }
 301 
 302   // Tells whether the initiating class' protection can access the this _klass
 303   bool is_valid_protection_domain(Handle protection_domain) {
 304     if (!ProtectionDomainVerification) return true;
 305     if (!SystemDictionary::has_checkPackageAccess()) return true;
 306 
 307     return protection_domain() == NULL
 308          ? true
 309          : contains_protection_domain(protection_domain());
 310   }
 311 
 312   void set_strongly_reachable() {
 313     for (ProtectionDomainEntry* current = _pd_set;
 314                                 current != NULL;
 315                                 current = current->_next) {
 316       current->_pd_cache->set_strongly_reachable();
 317     }
 318   }
 319 
 320   void verify_protection_domain_set() {
 321     for (ProtectionDomainEntry* current = _pd_set;
 322                                 current != NULL;
 323                                 current = current->_next) {
 324       current->_pd_cache->protection_domain()->verify();
 325     }
 326   }
 327 
 328   bool equals(Symbol* class_name, ClassLoaderData* loader_data) const {
 329     Klass* klass = (Klass*)literal();
 330     return (InstanceKlass::cast(klass)->name() == class_name &&
 331             _loader_data == loader_data);
 332   }
 333 
 334   void print() {
 335     int count = 0;
 336     for (ProtectionDomainEntry* current = _pd_set;