duke@435: /* coleenp@4037: * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CLASSFILE_LOADERCONSTRAINTS_HPP stefank@2314: #define SHARE_VM_CLASSFILE_LOADERCONSTRAINTS_HPP stefank@2314: stefank@2314: #include "classfile/dictionary.hpp" stefank@2314: #include "classfile/placeholders.hpp" stefank@2314: #include "utilities/hashtable.hpp" stefank@2314: duke@435: class LoaderConstraintEntry; coleenp@4037: class Symbol; duke@435: coleenp@4037: class LoaderConstraintTable : public Hashtable { duke@435: friend class VMStructs; duke@435: private: duke@435: duke@435: enum Constants { duke@435: _loader_constraint_size = 107, // number of entries in constraint table duke@435: _nof_buckets = 1009 // number of buckets in hash table duke@435: }; duke@435: coleenp@2497: LoaderConstraintEntry** find_loader_constraint(Symbol* name, duke@435: Handle loader); duke@435: duke@435: public: duke@435: duke@435: LoaderConstraintTable(int nof_buckets); duke@435: coleenp@2497: LoaderConstraintEntry* new_entry(unsigned int hash, Symbol* name, coleenp@4037: Klass* klass, int num_loaders, duke@435: int max_loaders); coleenp@2497: void free_entry(LoaderConstraintEntry *entry); duke@435: duke@435: LoaderConstraintEntry* bucket(int i) { coleenp@4037: return (LoaderConstraintEntry*)Hashtable::bucket(i); duke@435: } duke@435: duke@435: LoaderConstraintEntry** bucket_addr(int i) { coleenp@4037: return (LoaderConstraintEntry**)Hashtable::bucket_addr(i); duke@435: } duke@435: coleenp@4037: // Enhanced Class Redefinition support coleenp@4037: void classes_do(KlassClosure* f); duke@435: duke@435: // Check class loader constraints coleenp@4037: bool add_entry(Symbol* name, Klass* klass1, Handle loader1, coleenp@4037: Klass* klass2, Handle loader2); duke@435: jrose@1100: // Note: The main entry point for this module is via SystemDictionary. coleenp@2497: // SystemDictionary::check_signature_loaders(Symbol* signature, jrose@1100: // Handle loader1, Handle loader2, jrose@1100: // bool is_method, TRAPS) duke@435: coleenp@4037: Klass* find_constrained_klass(Symbol* name, Handle loader); duke@435: duke@435: // Class loader constraints duke@435: duke@435: void ensure_loader_constraint_capacity(LoaderConstraintEntry *p, int nfree); duke@435: void extend_loader_constraint(LoaderConstraintEntry* p, Handle loader, coleenp@4037: Klass* klass); duke@435: void merge_loader_constraints(LoaderConstraintEntry** pp1, coleenp@4037: LoaderConstraintEntry** pp2, Klass* klass); duke@435: duke@435: bool check_or_update(instanceKlassHandle k, Handle loader, coleenp@2497: Symbol* name); duke@435: duke@435: coleenp@4037: void purge_loader_constraints(); duke@435: tonyp@1693: void verify(Dictionary* dictionary, PlaceholderTable* placeholders); duke@435: #ifndef PRODUCT duke@435: void print(); duke@435: #endif duke@435: }; duke@435: coleenp@4037: class LoaderConstraintEntry : public HashtableEntry { duke@435: friend class VMStructs; duke@435: private: coleenp@2497: Symbol* _name; // class name duke@435: int _num_loaders; duke@435: int _max_loaders; coleenp@4037: // Loader constraints enforce correct linking behavior. coleenp@4037: // Thus, it really operates on ClassLoaderData which represents linking domain, coleenp@4037: // not class loaders. coleenp@4037: ClassLoaderData** _loaders; // initiating loaders duke@435: duke@435: public: duke@435: coleenp@4037: Klass* klass() { return literal(); } coleenp@4037: Klass** klass_addr() { return literal_addr(); } coleenp@4037: void set_klass(Klass* k) { set_literal(k); } duke@435: duke@435: LoaderConstraintEntry* next() { coleenp@4037: return (LoaderConstraintEntry*)HashtableEntry::next(); duke@435: } duke@435: duke@435: LoaderConstraintEntry** next_addr() { coleenp@4037: return (LoaderConstraintEntry**)HashtableEntry::next_addr(); duke@435: } duke@435: void set_next(LoaderConstraintEntry* next) { coleenp@4037: HashtableEntry::set_next(next); duke@435: } duke@435: coleenp@2497: Symbol* name() { return _name; } coleenp@2497: void set_name(Symbol* name) { coleenp@2497: _name = name; coleenp@2497: if (name != NULL) name->increment_refcount(); coleenp@2497: } duke@435: duke@435: int num_loaders() { return _num_loaders; } duke@435: void set_num_loaders(int i) { _num_loaders = i; } duke@435: duke@435: int max_loaders() { return _max_loaders; } duke@435: void set_max_loaders(int i) { _max_loaders = i; } duke@435: coleenp@4037: ClassLoaderData** loaders() { return _loaders; } coleenp@4037: void set_loaders(ClassLoaderData** loaders) { _loaders = loaders; } duke@435: coleenp@4037: ClassLoaderData* loader_data(int i) { return _loaders[i]; } coleenp@4037: void set_loader_data(int i, ClassLoaderData* p) { _loaders[i] = p; } coleenp@4037: // convenience coleenp@4037: void set_loader(int i, oop p); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CLASSFILE_LOADERCONSTRAINTS_HPP