36508
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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_VM_CLASSFILE_MODULEENTRY_HPP
|
|
26 |
#define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
|
|
27 |
|
|
28 |
#include "classfile/classLoaderData.hpp"
|
|
29 |
#include "classfile/vmSymbols.hpp"
|
|
30 |
#include "oops/symbol.hpp"
|
|
31 |
#include "prims/jni.h"
|
|
32 |
#include "runtime/mutexLocker.hpp"
|
|
33 |
#include "trace/traceMacros.hpp"
|
|
34 |
#include "utilities/growableArray.hpp"
|
|
35 |
#include "utilities/hashtable.hpp"
|
|
36 |
|
|
37 |
#define UNNAMED_MODULE "Unnamed Module"
|
|
38 |
|
|
39 |
class ModuleClosure;
|
|
40 |
|
|
41 |
// A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
|
|
42 |
// It contains:
|
|
43 |
// - Symbol* containing the module's name.
|
|
44 |
// - pointer to the java.lang.reflect.Module for this module.
|
|
45 |
// - ClassLoaderData*, class loader of this module.
|
|
46 |
// - a growable array containg other module entries that this module can read.
|
|
47 |
// - a flag indicating if this module can read all unnamed modules.
|
|
48 |
//
|
|
49 |
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
|
|
50 |
// data structure.
|
|
51 |
class ModuleEntry : public HashtableEntry<Symbol*, mtClass> {
|
|
52 |
private:
|
|
53 |
jobject _module; // java.lang.reflect.Module
|
|
54 |
jobject _pd; // java.security.ProtectionDomain, cached
|
|
55 |
// for shared classes from this module
|
|
56 |
ClassLoaderData* _loader;
|
|
57 |
GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
|
|
58 |
Symbol* _version; // module version number
|
|
59 |
Symbol* _location; // module location
|
|
60 |
bool _can_read_all_unnamed;
|
|
61 |
bool _has_default_read_edges; // JVMTI redefine/retransform support
|
|
62 |
TRACE_DEFINE_TRACE_ID_FIELD;
|
|
63 |
enum {MODULE_READS_SIZE = 101}; // Initial size of list of modules that the module can read.
|
|
64 |
|
|
65 |
public:
|
|
66 |
void init() {
|
|
67 |
_module = NULL;
|
|
68 |
_loader = NULL;
|
|
69 |
_pd = NULL;
|
|
70 |
_reads = NULL;
|
|
71 |
_version = NULL;
|
|
72 |
_location = NULL;
|
|
73 |
_can_read_all_unnamed = false;
|
|
74 |
_has_default_read_edges = false;
|
|
75 |
}
|
|
76 |
|
|
77 |
Symbol* name() const { return literal(); }
|
|
78 |
void set_name(Symbol* n) { set_literal(n); }
|
|
79 |
|
|
80 |
jobject module() const { return _module; }
|
|
81 |
void set_module(jobject j) { _module = j; }
|
|
82 |
|
|
83 |
// The shared ProtectionDomain reference is set once the VM loads a shared class
|
|
84 |
// originated from the current Module. The referenced ProtectionDomain object is
|
|
85 |
// created by the ClassLoader when loading a class (shared or non-shared) from the
|
|
86 |
// Module for the first time. This ProtectionDomain object is used for all
|
|
87 |
// classes from the Module loaded by the same ClassLoader.
|
|
88 |
Handle shared_protection_domain();
|
|
89 |
void set_shared_protection_domain(ClassLoaderData *loader_data,
|
|
90 |
Handle pd);
|
|
91 |
|
|
92 |
ClassLoaderData* loader() const { return _loader; }
|
|
93 |
void set_loader(ClassLoaderData* l) { _loader = l; }
|
|
94 |
|
|
95 |
Symbol* version() const { return _version; }
|
|
96 |
void set_version(Symbol* version);
|
|
97 |
|
|
98 |
Symbol* location() const { return _location; }
|
|
99 |
void set_location(Symbol* location);
|
|
100 |
|
|
101 |
bool can_read(ModuleEntry* m) const;
|
|
102 |
bool has_reads() const;
|
|
103 |
void add_read(ModuleEntry* m);
|
|
104 |
|
|
105 |
bool is_named() const { return (literal() != NULL); }
|
|
106 |
|
|
107 |
bool can_read_all_unnamed() const {
|
|
108 |
assert(is_named() || _can_read_all_unnamed == true,
|
|
109 |
"unnamed modules can always read all unnamed modules");
|
|
110 |
return _can_read_all_unnamed;
|
|
111 |
}
|
|
112 |
|
|
113 |
// Modules can only go from strict to loose.
|
|
114 |
void set_can_read_all_unnamed() { _can_read_all_unnamed = true; }
|
|
115 |
|
|
116 |
bool has_default_read_edges() const {
|
|
117 |
return _has_default_read_edges;
|
|
118 |
}
|
|
119 |
|
|
120 |
// Sets true and returns the previous value.
|
|
121 |
bool set_has_default_read_edges() {
|
|
122 |
MutexLocker ml(Module_lock);
|
|
123 |
bool prev = _has_default_read_edges;
|
|
124 |
_has_default_read_edges = true;
|
|
125 |
return prev;
|
|
126 |
}
|
|
127 |
|
|
128 |
ModuleEntry* next() const {
|
|
129 |
return (ModuleEntry*)HashtableEntry<Symbol*, mtClass>::next();
|
|
130 |
}
|
|
131 |
ModuleEntry** next_addr() {
|
|
132 |
return (ModuleEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
|
|
133 |
}
|
|
134 |
|
|
135 |
// iteration support for readability
|
|
136 |
void module_reads_do(ModuleClosure* const f);
|
|
137 |
|
|
138 |
TRACE_DEFINE_TRACE_ID_METHODS;
|
|
139 |
|
|
140 |
// Purge dead weak references out of reads list when any given class loader is unloaded.
|
|
141 |
void purge_reads();
|
|
142 |
void delete_reads();
|
|
143 |
|
|
144 |
void print() PRODUCT_RETURN;
|
|
145 |
void verify();
|
|
146 |
};
|
|
147 |
|
|
148 |
// Iterator interface
|
|
149 |
class ModuleClosure: public StackObj {
|
|
150 |
public:
|
|
151 |
virtual void do_module(ModuleEntry* const module) = 0;
|
|
152 |
};
|
|
153 |
|
|
154 |
|
|
155 |
// The ModuleEntryTable is a Hashtable containing a list of all modules defined
|
|
156 |
// by a particular class loader. Each module is represented as a ModuleEntry node.
|
|
157 |
//
|
|
158 |
// Each ModuleEntryTable contains a _javabase_module field which allows for the
|
|
159 |
// creation of java.base's ModuleEntry very early in bootstrapping before the
|
|
160 |
// corresponding JVM_DefineModule call for java.base occurs during module system
|
|
161 |
// initialization. Setting up java.base's ModuleEntry early enables classes,
|
|
162 |
// loaded prior to the module system being initialized to be created with their
|
|
163 |
// PackageEntry node's correctly pointing at java.base's ModuleEntry. No class
|
|
164 |
// outside of java.base is allowed to be loaded pre-module system initialization.
|
|
165 |
//
|
|
166 |
// The ModuleEntryTable's lookup is lock free.
|
|
167 |
//
|
|
168 |
class ModuleEntryTable : public Hashtable<Symbol*, mtClass> {
|
|
169 |
friend class VMStructs;
|
|
170 |
public:
|
|
171 |
enum Constants {
|
|
172 |
_moduletable_entry_size = 109 // number of entries in module entry table
|
|
173 |
};
|
|
174 |
|
|
175 |
private:
|
|
176 |
static ModuleEntry* _javabase_module;
|
|
177 |
ModuleEntry* _unnamed_module;
|
|
178 |
|
|
179 |
ModuleEntry* new_entry(unsigned int hash, Handle module_handle, Symbol* name, Symbol* version,
|
|
180 |
Symbol* location, ClassLoaderData* class_loader);
|
|
181 |
void add_entry(int index, ModuleEntry* new_entry);
|
|
182 |
|
|
183 |
int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
|
|
184 |
|
|
185 |
ModuleEntry** bucket_addr(int i) {
|
|
186 |
return (ModuleEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
|
|
187 |
}
|
|
188 |
|
|
189 |
static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
|
|
190 |
int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); }
|
|
191 |
|
|
192 |
public:
|
|
193 |
ModuleEntryTable(int table_size);
|
|
194 |
~ModuleEntryTable();
|
|
195 |
|
|
196 |
ModuleEntry* bucket(int i) {
|
|
197 |
return (ModuleEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
|
|
198 |
}
|
|
199 |
|
|
200 |
// Create module in loader's module entry table, if already exists then
|
|
201 |
// return null. Assume Module_lock has been locked by caller.
|
|
202 |
ModuleEntry* locked_create_entry_or_null(Handle module_handle,
|
|
203 |
Symbol* module_name,
|
|
204 |
Symbol* module_version,
|
|
205 |
Symbol* module_location,
|
|
206 |
ClassLoaderData* loader_data);
|
|
207 |
|
|
208 |
// Only lookup module within loader's module entry table. The table read is lock-free.
|
|
209 |
ModuleEntry* lookup_only(Symbol* name);
|
|
210 |
|
|
211 |
// purge dead weak references out of reads list
|
|
212 |
void purge_all_module_reads();
|
|
213 |
|
|
214 |
// Special handling for unnamed module, one per class loader's ModuleEntryTable
|
|
215 |
void create_unnamed_module(ClassLoaderData* loader_data);
|
|
216 |
ModuleEntry* unnamed_module() { return _unnamed_module; }
|
|
217 |
|
|
218 |
// Special handling for java.base
|
|
219 |
static ModuleEntry* javabase_module() { return _javabase_module; }
|
|
220 |
static void set_javabase_module(ModuleEntry* java_base) { _javabase_module = java_base; }
|
|
221 |
static bool javabase_defined() { return ((_javabase_module != NULL) &&
|
|
222 |
(_javabase_module->module() != NULL)); }
|
|
223 |
static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
|
|
224 |
static void patch_javabase_entries(Handle module_handle);
|
|
225 |
|
|
226 |
void print() PRODUCT_RETURN;
|
|
227 |
void verify();
|
|
228 |
};
|
|
229 |
|
|
230 |
#endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP
|