8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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_LOADERCONSTRAINTS_HPP 26 #define SHARE_VM_CLASSFILE_LOADERCONSTRAINTS_HPP 27 28 #include "classfile/dictionary.hpp" 29 #include "classfile/placeholders.hpp" 30 #include "utilities/hashtable.hpp" 31 32 class LoaderConstraintEntry; 33 class Symbol; 34 35 class LoaderConstraintTable : public Hashtable<InstanceKlass*, mtClass> { 36 friend class VMStructs; 37 private: 38 39 enum Constants { 40 _loader_constraint_size = 107, // number of entries in constraint table 41 _nof_buckets = 1009 // number of buckets in hash table 42 }; 43 44 LoaderConstraintEntry** find_loader_constraint(Symbol* name, 45 Handle loader); 46 47 public: 48 49 LoaderConstraintTable(int nof_buckets); 50 51 LoaderConstraintEntry* new_entry(unsigned int hash, Symbol* name, 52 InstanceKlass* klass, int num_loaders, 53 int max_loaders); 54 void free_entry(LoaderConstraintEntry *entry); 55 56 LoaderConstraintEntry* bucket(int i) { 57 return (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i); 58 } 59 60 LoaderConstraintEntry** bucket_addr(int i) { 61 return (LoaderConstraintEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i); 62 } 63 64 // Check class loader constraints 65 bool add_entry(Symbol* name, InstanceKlass* klass1, Handle loader1, 66 InstanceKlass* klass2, Handle loader2); 67 68 // Note: The main entry point for this module is via SystemDictionary. 69 // SystemDictionary::check_signature_loaders(Symbol* signature, 70 // Handle loader1, Handle loader2, 71 // bool is_method, TRAPS) 72 73 InstanceKlass* find_constrained_klass(Symbol* name, Handle loader); 74 75 // Class loader constraints 76 77 void ensure_loader_constraint_capacity(LoaderConstraintEntry *p, int nfree); 78 void extend_loader_constraint(LoaderConstraintEntry* p, Handle loader, 79 InstanceKlass* klass); 80 void merge_loader_constraints(LoaderConstraintEntry** pp1, 81 LoaderConstraintEntry** pp2, InstanceKlass* klass); 82 83 bool check_or_update(InstanceKlass* k, Handle loader, Symbol* name); 84 85 void purge_loader_constraints(); 86 87 void verify(Dictionary* dictionary, PlaceholderTable* placeholders); 88 #ifndef PRODUCT 89 void print(); 90 #endif 91 }; 92 93 class LoaderConstraintEntry : public HashtableEntry<InstanceKlass*, mtClass> { 94 friend class VMStructs; 95 private: 96 Symbol* _name; // class name 97 int _num_loaders; 98 int _max_loaders; 99 // Loader constraints enforce correct linking behavior. 100 // Thus, it really operates on ClassLoaderData which represents linking domain, 101 // not class loaders. 102 ClassLoaderData** _loaders; // initiating loaders 103 104 public: 105 106 InstanceKlass* klass() { return literal(); } 107 InstanceKlass** klass_addr() { return literal_addr(); } 108 void set_klass(InstanceKlass* k) { set_literal(k); } 109 110 LoaderConstraintEntry* next() { 111 return (LoaderConstraintEntry*)HashtableEntry<InstanceKlass*, mtClass>::next(); 112 } 113 114 LoaderConstraintEntry** next_addr() { | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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_LOADERCONSTRAINTS_HPP 26 #define SHARE_VM_CLASSFILE_LOADERCONSTRAINTS_HPP 27 28 #include "classfile/placeholders.hpp" 29 #include "utilities/hashtable.hpp" 30 31 class ClassLoaderData; 32 class LoaderConstraintEntry; 33 class Symbol; 34 35 class LoaderConstraintTable : public Hashtable<InstanceKlass*, mtClass> { 36 37 private: 38 LoaderConstraintEntry** find_loader_constraint(Symbol* name, 39 Handle loader); 40 41 public: 42 43 LoaderConstraintTable(int table_size); 44 45 LoaderConstraintEntry* new_entry(unsigned int hash, Symbol* name, 46 InstanceKlass* klass, int num_loaders, 47 int max_loaders); 48 void free_entry(LoaderConstraintEntry *entry); 49 50 LoaderConstraintEntry* bucket(int i) { 51 return (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i); 52 } 53 54 LoaderConstraintEntry** bucket_addr(int i) { 55 return (LoaderConstraintEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i); 56 } 57 58 // Check class loader constraints 59 bool add_entry(Symbol* name, InstanceKlass* klass1, Handle loader1, 60 InstanceKlass* klass2, Handle loader2); 61 62 // Note: The main entry point for this module is via SystemDictionary. 63 // SystemDictionary::check_signature_loaders(Symbol* signature, 64 // Handle loader1, Handle loader2, 65 // bool is_method, TRAPS) 66 67 InstanceKlass* find_constrained_klass(Symbol* name, Handle loader); 68 69 // Class loader constraints 70 71 void ensure_loader_constraint_capacity(LoaderConstraintEntry *p, int nfree); 72 void extend_loader_constraint(LoaderConstraintEntry* p, Handle loader, 73 InstanceKlass* klass); 74 void merge_loader_constraints(LoaderConstraintEntry** pp1, 75 LoaderConstraintEntry** pp2, InstanceKlass* klass); 76 77 bool check_or_update(InstanceKlass* k, Handle loader, Symbol* name); 78 79 void purge_loader_constraints(); 80 81 void verify(PlaceholderTable* placeholders); 82 #ifndef PRODUCT 83 void print(); 84 #endif 85 }; 86 87 class LoaderConstraintEntry : public HashtableEntry<InstanceKlass*, mtClass> { 88 private: 89 Symbol* _name; // class name 90 int _num_loaders; 91 int _max_loaders; 92 // Loader constraints enforce correct linking behavior. 93 // Thus, it really operates on ClassLoaderData which represents linking domain, 94 // not class loaders. 95 ClassLoaderData** _loaders; // initiating loaders 96 97 public: 98 99 InstanceKlass* klass() { return literal(); } 100 InstanceKlass** klass_addr() { return literal_addr(); } 101 void set_klass(InstanceKlass* k) { set_literal(k); } 102 103 LoaderConstraintEntry* next() { 104 return (LoaderConstraintEntry*)HashtableEntry<InstanceKlass*, mtClass>::next(); 105 } 106 107 LoaderConstraintEntry** next_addr() { |