author | stefank |
Wed, 05 Jul 2017 11:33:17 +0200 | |
changeset 46625 | edefffab74e2 |
parent 46404 | ae62ba99a1a7 |
child 46773 | fb17cc9a6847 |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
44326
6c59cca7ff07
8174823: Module system implementation refresh (3/2017)
alanb
parents:
42647
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
36508 | 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" |
|
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
36 |
#include "utilities/ostream.hpp" |
36508 | 37 |
|
38 |
#define UNNAMED_MODULE "Unnamed Module" |
|
44326
6c59cca7ff07
8174823: Module system implementation refresh (3/2017)
alanb
parents:
42647
diff
changeset
|
39 |
#define JAVAPKG "java" |
6c59cca7ff07
8174823: Module system implementation refresh (3/2017)
alanb
parents:
42647
diff
changeset
|
40 |
#define JAVAPKG_LEN 4 |
42575
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
41183
diff
changeset
|
41 |
#define JAVA_BASE_NAME "java.base" |
36508 | 42 |
|
43 |
class ModuleClosure; |
|
44 |
||
45 |
// A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule. |
|
46 |
// It contains: |
|
47 |
// - Symbol* containing the module's name. |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
48 |
// - pointer to the java.lang.Module for this module. |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
49 |
// - pointer to the java.security.ProtectionDomain shared by classes defined to this module. |
36508 | 50 |
// - ClassLoaderData*, class loader of this module. |
51 |
// - a growable array containg other module entries that this module can read. |
|
52 |
// - a flag indicating if this module can read all unnamed modules. |
|
53 |
// |
|
54 |
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either |
|
55 |
// data structure. |
|
38733 | 56 |
class ModuleEntry : public HashtableEntry<Symbol*, mtModule> { |
36508 | 57 |
private: |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44326
diff
changeset
|
58 |
jobject _module; // java.lang.Module |
36508 | 59 |
jobject _pd; // java.security.ProtectionDomain, cached |
60 |
// for shared classes from this module |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
61 |
ClassLoaderData* _loader_data; |
36508 | 62 |
GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module |
63 |
Symbol* _version; // module version number |
|
64 |
Symbol* _location; // module location |
|
65 |
bool _can_read_all_unnamed; |
|
66 |
bool _has_default_read_edges; // JVMTI redefine/retransform support |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
67 |
bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
68 |
bool _is_open; // whether the packages in the module are all unqualifiedly exported |
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
69 |
bool _is_patched; // whether the module is patched via --patch-module |
36508 | 70 |
TRACE_DEFINE_TRACE_ID_FIELD; |
71 |
enum {MODULE_READS_SIZE = 101}; // Initial size of list of modules that the module can read. |
|
72 |
||
73 |
public: |
|
74 |
void init() { |
|
75 |
_module = NULL; |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
76 |
_loader_data = NULL; |
36508 | 77 |
_pd = NULL; |
78 |
_reads = NULL; |
|
79 |
_version = NULL; |
|
80 |
_location = NULL; |
|
81 |
_can_read_all_unnamed = false; |
|
82 |
_has_default_read_edges = false; |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
83 |
_must_walk_reads = false; |
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
84 |
_is_patched = false; |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
85 |
_is_open = false; |
36508 | 86 |
} |
87 |
||
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
88 |
Symbol* name() const { return literal(); } |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
89 |
void set_name(Symbol* n) { set_literal(n); } |
36508 | 90 |
|
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
91 |
jobject module() const { return _module; } |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
92 |
void set_module(jobject j) { _module = j; } |
36508 | 93 |
|
94 |
// The shared ProtectionDomain reference is set once the VM loads a shared class |
|
95 |
// originated from the current Module. The referenced ProtectionDomain object is |
|
96 |
// created by the ClassLoader when loading a class (shared or non-shared) from the |
|
97 |
// Module for the first time. This ProtectionDomain object is used for all |
|
98 |
// classes from the Module loaded by the same ClassLoader. |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
99 |
Handle shared_protection_domain(); |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
100 |
void set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd); |
36508 | 101 |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
102 |
ClassLoaderData* loader_data() const { return _loader_data; } |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
103 |
void set_loader_data(ClassLoaderData* l) { _loader_data = l; } |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
104 |
|
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
105 |
Symbol* version() const { return _version; } |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
106 |
void set_version(Symbol* version); |
36508 | 107 |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
108 |
Symbol* location() const { return _location; } |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
109 |
void set_location(Symbol* location); |
42575
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
41183
diff
changeset
|
110 |
bool is_non_jdk_module(); |
36508 | 111 |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
112 |
bool can_read(ModuleEntry* m) const; |
46387 | 113 |
bool has_reads_list() const; |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
114 |
void add_read(ModuleEntry* m); |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
115 |
void set_read_walk_required(ClassLoaderData* m_loader_data); |
36508 | 116 |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
117 |
bool is_open() const { return _is_open; } |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
118 |
void set_is_open(bool is_open); |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
119 |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
38733
diff
changeset
|
120 |
bool is_named() const { return (name() != NULL); } |
36508 | 121 |
|
122 |
bool can_read_all_unnamed() const { |
|
123 |
assert(is_named() || _can_read_all_unnamed == true, |
|
124 |
"unnamed modules can always read all unnamed modules"); |
|
125 |
return _can_read_all_unnamed; |
|
126 |
} |
|
127 |
||
128 |
// Modules can only go from strict to loose. |
|
129 |
void set_can_read_all_unnamed() { _can_read_all_unnamed = true; } |
|
130 |
||
131 |
bool has_default_read_edges() const { |
|
132 |
return _has_default_read_edges; |
|
133 |
} |
|
134 |
||
135 |
// Sets true and returns the previous value. |
|
136 |
bool set_has_default_read_edges() { |
|
137 |
MutexLocker ml(Module_lock); |
|
138 |
bool prev = _has_default_read_edges; |
|
139 |
_has_default_read_edges = true; |
|
140 |
return prev; |
|
141 |
} |
|
142 |
||
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
143 |
void set_is_patched() { |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
144 |
_is_patched = true; |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
145 |
} |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
146 |
bool is_patched() { |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
147 |
return _is_patched; |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
148 |
} |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
149 |
|
36508 | 150 |
ModuleEntry* next() const { |
38733 | 151 |
return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next(); |
36508 | 152 |
} |
153 |
ModuleEntry** next_addr() { |
|
38733 | 154 |
return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr(); |
36508 | 155 |
} |
156 |
||
157 |
// iteration support for readability |
|
158 |
void module_reads_do(ModuleClosure* const f); |
|
159 |
||
160 |
TRACE_DEFINE_TRACE_ID_METHODS; |
|
161 |
||
162 |
// Purge dead weak references out of reads list when any given class loader is unloaded. |
|
163 |
void purge_reads(); |
|
164 |
void delete_reads(); |
|
165 |
||
46387 | 166 |
// Special handling for unnamed module, one per class loader |
167 |
static ModuleEntry* create_unnamed_module(ClassLoaderData* cld); |
|
168 |
static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld); |
|
169 |
static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld); |
|
170 |
void delete_unnamed_module(); |
|
171 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
172 |
void print(outputStream* st = tty); |
36508 | 173 |
void verify(); |
174 |
}; |
|
175 |
||
176 |
// Iterator interface |
|
177 |
class ModuleClosure: public StackObj { |
|
178 |
public: |
|
179 |
virtual void do_module(ModuleEntry* const module) = 0; |
|
180 |
}; |
|
181 |
||
182 |
||
183 |
// The ModuleEntryTable is a Hashtable containing a list of all modules defined |
|
184 |
// by a particular class loader. Each module is represented as a ModuleEntry node. |
|
185 |
// |
|
186 |
// Each ModuleEntryTable contains a _javabase_module field which allows for the |
|
187 |
// creation of java.base's ModuleEntry very early in bootstrapping before the |
|
188 |
// corresponding JVM_DefineModule call for java.base occurs during module system |
|
189 |
// initialization. Setting up java.base's ModuleEntry early enables classes, |
|
190 |
// loaded prior to the module system being initialized to be created with their |
|
191 |
// PackageEntry node's correctly pointing at java.base's ModuleEntry. No class |
|
192 |
// outside of java.base is allowed to be loaded pre-module system initialization. |
|
193 |
// |
|
194 |
// The ModuleEntryTable's lookup is lock free. |
|
195 |
// |
|
38733 | 196 |
class ModuleEntryTable : public Hashtable<Symbol*, mtModule> { |
36508 | 197 |
friend class VMStructs; |
198 |
public: |
|
199 |
enum Constants { |
|
200 |
_moduletable_entry_size = 109 // number of entries in module entry table |
|
201 |
}; |
|
202 |
||
203 |
private: |
|
204 |
static ModuleEntry* _javabase_module; |
|
205 |
||
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
206 |
ModuleEntry* new_entry(unsigned int hash, Handle module_handle, bool is_open, |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
207 |
Symbol* name, Symbol* version, Symbol* location, ClassLoaderData* loader_data); |
36508 | 208 |
void add_entry(int index, ModuleEntry* new_entry); |
209 |
||
38733 | 210 |
int entry_size() const { return BasicHashtable<mtModule>::entry_size(); } |
36508 | 211 |
|
212 |
ModuleEntry** bucket_addr(int i) { |
|
38733 | 213 |
return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i); |
36508 | 214 |
} |
215 |
||
216 |
static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); } |
|
217 |
int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); } |
|
218 |
||
219 |
public: |
|
220 |
ModuleEntryTable(int table_size); |
|
221 |
~ModuleEntryTable(); |
|
222 |
||
223 |
ModuleEntry* bucket(int i) { |
|
38733 | 224 |
return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i); |
36508 | 225 |
} |
226 |
||
227 |
// Create module in loader's module entry table, if already exists then |
|
228 |
// return null. Assume Module_lock has been locked by caller. |
|
229 |
ModuleEntry* locked_create_entry_or_null(Handle module_handle, |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
230 |
bool is_open, |
36508 | 231 |
Symbol* module_name, |
232 |
Symbol* module_version, |
|
233 |
Symbol* module_location, |
|
234 |
ClassLoaderData* loader_data); |
|
235 |
||
236 |
// Only lookup module within loader's module entry table. The table read is lock-free. |
|
237 |
ModuleEntry* lookup_only(Symbol* name); |
|
238 |
||
239 |
// purge dead weak references out of reads list |
|
240 |
void purge_all_module_reads(); |
|
241 |
||
242 |
// Special handling for java.base |
|
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
243 |
static ModuleEntry* javabase_moduleEntry() { return _javabase_module; } |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
244 |
static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; } |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
245 |
static bool javabase_defined() { return ((_javabase_module != NULL) && |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39616
diff
changeset
|
246 |
(_javabase_module->module() != NULL)); } |
36508 | 247 |
static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location); |
248 |
static void patch_javabase_entries(Handle module_handle); |
|
249 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
250 |
void print(outputStream* st = tty); |
36508 | 251 |
void verify(); |
252 |
}; |
|
253 |
||
254 |
#endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP |