| 1 | /* | 
|---|
| 2 | * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. | 
|---|
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 
|---|
| 4 | * | 
|---|
| 5 | * This code is free software; you can redistribute it and/or modify it | 
|---|
| 6 | * under the terms of the GNU General Public License version 2 only, as | 
|---|
| 7 | * published by the Free Software Foundation. | 
|---|
| 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_CLASSFILE_LOADERCONSTRAINTS_HPP | 
|---|
| 26 | #define SHARE_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) const { | 
|---|
| 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 | void print_on(outputStream* st) const; | 
|---|
| 83 | }; | 
|---|
| 84 |  | 
|---|
| 85 | class LoaderConstraintEntry : public HashtableEntry<InstanceKlass*, mtClass> { | 
|---|
| 86 | private: | 
|---|
| 87 | Symbol*                _name;                   // class name | 
|---|
| 88 | int                    _num_loaders; | 
|---|
| 89 | int                    _max_loaders; | 
|---|
| 90 | // Loader constraints enforce correct linking behavior. | 
|---|
| 91 | // Thus, it really operates on ClassLoaderData which represents linking domain, | 
|---|
| 92 | // not class loaders. | 
|---|
| 93 | ClassLoaderData**              _loaders;                // initiating loaders | 
|---|
| 94 |  | 
|---|
| 95 | public: | 
|---|
| 96 |  | 
|---|
| 97 | InstanceKlass* klass() { return literal(); } | 
|---|
| 98 | InstanceKlass** klass_addr() { return literal_addr(); } | 
|---|
| 99 | void set_klass(InstanceKlass* k) { set_literal(k); } | 
|---|
| 100 |  | 
|---|
| 101 | LoaderConstraintEntry* next() { | 
|---|
| 102 | return (LoaderConstraintEntry*)HashtableEntry<InstanceKlass*, mtClass>::next(); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | LoaderConstraintEntry** next_addr() { | 
|---|
| 106 | return (LoaderConstraintEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr(); | 
|---|
| 107 | } | 
|---|
| 108 | void set_next(LoaderConstraintEntry* next) { | 
|---|
| 109 | HashtableEntry<InstanceKlass*, mtClass>::set_next(next); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | Symbol* name() { return _name; } | 
|---|
| 113 | void set_name(Symbol* name) { | 
|---|
| 114 | _name = name; | 
|---|
| 115 | if (name != NULL) name->increment_refcount(); | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | int num_loaders() { return _num_loaders; } | 
|---|
| 119 | void set_num_loaders(int i) { _num_loaders = i; } | 
|---|
| 120 |  | 
|---|
| 121 | int max_loaders() { return _max_loaders; } | 
|---|
| 122 | void set_max_loaders(int i) { _max_loaders = i; } | 
|---|
| 123 |  | 
|---|
| 124 | ClassLoaderData** loaders() { return _loaders; } | 
|---|
| 125 | void set_loaders(ClassLoaderData** loaders) { _loaders = loaders; } | 
|---|
| 126 |  | 
|---|
| 127 | ClassLoaderData* loader_data(int i) { return _loaders[i]; } | 
|---|
| 128 | void set_loader_data(int i, ClassLoaderData* p) { _loaders[i] = p; } | 
|---|
| 129 | // convenience | 
|---|
| 130 | void set_loader(int i, oop p); | 
|---|
| 131 | }; | 
|---|
| 132 |  | 
|---|
| 133 | #endif // SHARE_CLASSFILE_LOADERCONSTRAINTS_HPP | 
|---|
| 134 |  | 
|---|