duke@435: /* duke@435: * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: class DictionaryEntry; duke@435: duke@435: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ duke@435: // The data structure for the system dictionary (and the shared system duke@435: // dictionary). duke@435: duke@435: class Dictionary : public TwoOopHashtable { duke@435: friend class VMStructs; duke@435: private: duke@435: // current iteration index. duke@435: static int _current_class_index; duke@435: // pointer to the current hash table entry. duke@435: static DictionaryEntry* _current_class_entry; duke@435: duke@435: DictionaryEntry* get_entry(int index, unsigned int hash, duke@435: symbolHandle name, Handle loader); duke@435: duke@435: DictionaryEntry* bucket(int i) { duke@435: return (DictionaryEntry*)Hashtable::bucket(i); duke@435: } duke@435: duke@435: // The following method is not MT-safe and must be done under lock. duke@435: DictionaryEntry** bucket_addr(int i) { duke@435: return (DictionaryEntry**)Hashtable::bucket_addr(i); duke@435: } duke@435: duke@435: void add_entry(int index, DictionaryEntry* new_entry) { duke@435: Hashtable::add_entry(index, (HashtableEntry*)new_entry); duke@435: } duke@435: duke@435: duke@435: public: duke@435: Dictionary(int table_size); duke@435: Dictionary(int table_size, HashtableBucket* t, int number_of_entries); duke@435: duke@435: DictionaryEntry* new_entry(unsigned int hash, klassOop klass, oop loader); duke@435: duke@435: DictionaryEntry* new_entry(); duke@435: duke@435: void free_entry(DictionaryEntry* entry); duke@435: duke@435: void add_klass(symbolHandle class_name, Handle class_loader,KlassHandle obj); duke@435: duke@435: klassOop find_class(int index, unsigned int hash, duke@435: symbolHandle name, Handle loader); duke@435: duke@435: klassOop find_shared_class(int index, unsigned int hash, symbolHandle name); duke@435: duke@435: // Compiler support duke@435: klassOop try_get_next_class(); duke@435: duke@435: // GC support duke@435: duke@435: void oops_do(OopClosure* f); duke@435: void always_strong_classes_do(OopClosure* blk); duke@435: void classes_do(void f(klassOop)); duke@435: void classes_do(void f(klassOop, TRAPS), TRAPS); duke@435: void classes_do(void f(klassOop, oop)); duke@435: void classes_do(void f(klassOop, oop, TRAPS), TRAPS); duke@435: duke@435: void methods_do(void f(methodOop)); duke@435: duke@435: duke@435: // Classes loaded by the bootstrap loader are always strongly reachable. duke@435: // If we're not doing class unloading, all classes are strongly reachable. duke@435: static bool is_strongly_reachable(oop class_loader, oop klass) { duke@435: assert (klass != NULL, "should have non-null klass"); duke@435: return (class_loader == NULL || !ClassUnloading); duke@435: } duke@435: duke@435: // Unload (that is, break root links to) all unmarked classes and duke@435: // loaders. Returns "true" iff something was unloaded. duke@435: bool do_unloading(BoolObjectClosure* is_alive); duke@435: duke@435: // Protection domains duke@435: klassOop find(int index, unsigned int hash, symbolHandle name, duke@435: Handle loader, Handle protection_domain, TRAPS); duke@435: bool is_valid_protection_domain(int index, unsigned int hash, duke@435: symbolHandle name, Handle class_loader, duke@435: Handle protection_domain); duke@435: void add_protection_domain(int index, unsigned int hash, duke@435: instanceKlassHandle klass, Handle loader, duke@435: Handle protection_domain, TRAPS); duke@435: duke@435: // Sharing support duke@435: void dump(SerializeOopClosure* soc); duke@435: void restore(SerializeOopClosure* soc); duke@435: void reorder_dictionary(); duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: void print(); duke@435: #endif duke@435: void verify(); duke@435: }; duke@435: duke@435: // The following classes can be in dictionary.cpp, but we need these duke@435: // to be in header file so that SA's vmStructs can access. duke@435: duke@435: class ProtectionDomainEntry :public CHeapObj { duke@435: friend class VMStructs; duke@435: public: duke@435: ProtectionDomainEntry* _next; duke@435: oop _protection_domain; duke@435: duke@435: ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) { duke@435: _protection_domain = protection_domain; duke@435: _next = next; duke@435: } duke@435: duke@435: ProtectionDomainEntry* next() { return _next; } duke@435: oop protection_domain() { return _protection_domain; } duke@435: }; duke@435: duke@435: // An entry in the system dictionary, this describes a class as duke@435: // { klassOop, loader, protection_domain }. duke@435: duke@435: class DictionaryEntry : public HashtableEntry { duke@435: friend class VMStructs; duke@435: private: duke@435: // Contains the set of approved protection domains that can access duke@435: // this system dictionary entry. duke@435: ProtectionDomainEntry* _pd_set; duke@435: oop _loader; duke@435: duke@435: duke@435: public: duke@435: // Tells whether a protection is in the approved set. duke@435: bool contains_protection_domain(oop protection_domain) const; duke@435: // Adds a protection domain to the approved set. duke@435: void add_protection_domain(oop protection_domain); duke@435: duke@435: klassOop klass() const { return (klassOop)literal(); } duke@435: klassOop* klass_addr() { return (klassOop*)literal_addr(); } duke@435: duke@435: DictionaryEntry* next() const { duke@435: return (DictionaryEntry*)HashtableEntry::next(); duke@435: } duke@435: duke@435: DictionaryEntry** next_addr() { duke@435: return (DictionaryEntry**)HashtableEntry::next_addr(); duke@435: } duke@435: duke@435: oop loader() const { return _loader; } duke@435: void set_loader(oop loader) { _loader = loader; } duke@435: oop* loader_addr() { return &_loader; } duke@435: duke@435: ProtectionDomainEntry* pd_set() const { return _pd_set; } duke@435: void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; } duke@435: duke@435: bool has_protection_domain() { return _pd_set != NULL; } duke@435: duke@435: // Tells whether the initiating class' protection can access the this _klass duke@435: bool is_valid_protection_domain(Handle protection_domain) { duke@435: if (!ProtectionDomainVerification) return true; duke@435: if (!SystemDictionary::has_checkPackageAccess()) return true; duke@435: duke@435: return protection_domain() == NULL duke@435: ? true duke@435: : contains_protection_domain(protection_domain()); duke@435: } duke@435: duke@435: duke@435: void protection_domain_set_oops_do(OopClosure* f) { duke@435: for (ProtectionDomainEntry* current = _pd_set; duke@435: current != NULL; duke@435: current = current->_next) { duke@435: f->do_oop(&(current->_protection_domain)); duke@435: } duke@435: } duke@435: duke@435: void verify_protection_domain_set() { duke@435: for (ProtectionDomainEntry* current = _pd_set; duke@435: current != NULL; duke@435: current = current->_next) { duke@435: current->_protection_domain->verify(); duke@435: } duke@435: } duke@435: duke@435: bool equals(symbolOop class_name, oop class_loader) const { duke@435: klassOop klass = (klassOop)literal(); duke@435: return (instanceKlass::cast(klass)->name() == class_name && duke@435: _loader == class_loader); duke@435: } duke@435: duke@435: void print() { duke@435: int count = 0; duke@435: for (ProtectionDomainEntry* current = _pd_set; duke@435: current != NULL; duke@435: current = current->_next) { duke@435: count++; duke@435: } duke@435: tty->print_cr("pd set = #%d", count); duke@435: } duke@435: };