author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46961 | hotspot/src/share/vm/classfile/moduleEntry.cpp@c9094b1e5f87 |
child 47659 | a8e9aff89f7b |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
44084
501b6d07e6dd
8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents:
42866
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 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/classLoaderData.hpp" |
|
27 |
#include "classfile/javaClasses.hpp" |
|
28 |
#include "classfile/moduleEntry.hpp" |
|
29 |
#include "logging/log.hpp" |
|
30 |
#include "memory/resourceArea.hpp" |
|
31 |
#include "oops/symbol.hpp" |
|
32 |
#include "prims/jni.h" |
|
33 |
#include "runtime/handles.inline.hpp" |
|
34 |
#include "runtime/safepoint.hpp" |
|
35 |
#include "trace/traceMacros.hpp" |
|
36 |
#include "utilities/events.hpp" |
|
37 |
#include "utilities/growableArray.hpp" |
|
38 |
#include "utilities/hashtable.inline.hpp" |
|
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
39 |
#include "utilities/ostream.hpp" |
36508 | 40 |
|
41 |
ModuleEntry* ModuleEntryTable::_javabase_module = NULL; |
|
42 |
||
43 |
void ModuleEntry::set_location(Symbol* location) { |
|
44 |
if (_location != NULL) { |
|
45 |
// _location symbol's refcounts are managed by ModuleEntry, |
|
46 |
// must decrement the old one before updating. |
|
47 |
_location->decrement_refcount(); |
|
48 |
} |
|
49 |
||
50 |
_location = location; |
|
51 |
||
52 |
if (location != NULL) { |
|
53 |
location->increment_refcount(); |
|
54 |
} |
|
55 |
} |
|
56 |
||
42575
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
57 |
bool ModuleEntry::is_non_jdk_module() { |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
58 |
ResourceMark rm; |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
59 |
if (location() != NULL) { |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
60 |
const char* loc = location()->as_C_string(); |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
61 |
if (strncmp(loc, "jrt:/java.", 10) != 0 && strncmp(loc, "jrt:/jdk.", 9) != 0) { |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
62 |
return true; |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
63 |
} |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
64 |
} |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
65 |
return false; |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
66 |
} |
bd1618170c93
8165550: Add class loader names to ClassCastException message
rprotacio
parents:
42073
diff
changeset
|
67 |
|
36508 | 68 |
void ModuleEntry::set_version(Symbol* version) { |
69 |
if (_version != NULL) { |
|
70 |
// _version symbol's refcounts are managed by ModuleEntry, |
|
71 |
// must decrement the old one before updating. |
|
72 |
_version->decrement_refcount(); |
|
73 |
} |
|
74 |
||
75 |
_version = version; |
|
76 |
||
77 |
if (version != NULL) { |
|
78 |
version->increment_refcount(); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
// Returns the shared ProtectionDomain |
|
46961
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46729
diff
changeset
|
83 |
oop ModuleEntry::shared_protection_domain() { |
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46729
diff
changeset
|
84 |
return _pd.resolve(); |
36508 | 85 |
} |
86 |
||
87 |
// Set the shared ProtectionDomain atomically |
|
88 |
void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data, |
|
89 |
Handle pd_h) { |
|
44084
501b6d07e6dd
8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents:
42866
diff
changeset
|
90 |
// Create a handle for the shared ProtectionDomain and save it atomically. |
46961
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46729
diff
changeset
|
91 |
// init_handle_locked checks if someone beats us setting the _pd cache. |
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46729
diff
changeset
|
92 |
loader_data->init_handle_locked(_pd, pd_h); |
36508 | 93 |
} |
94 |
||
95 |
// Returns true if this module can read module m |
|
96 |
bool ModuleEntry::can_read(ModuleEntry* m) const { |
|
97 |
assert(m != NULL, "No module to lookup in this module's reads list"); |
|
98 |
||
99 |
// Unnamed modules read everyone and all modules |
|
100 |
// read java.base. If either of these conditions |
|
101 |
// hold, readability has been established. |
|
102 |
if (!this->is_named() || |
|
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39625
diff
changeset
|
103 |
(m == ModuleEntryTable::javabase_moduleEntry())) { |
36508 | 104 |
return true; |
105 |
} |
|
106 |
||
107 |
MutexLocker m1(Module_lock); |
|
42866
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
108 |
// This is a guard against possible race between agent threads that redefine |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
109 |
// or retransform classes in this module. Only one of them is adding the |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
110 |
// default read edges to the unnamed modules of the boot and app class loaders |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
111 |
// with an upcall to jdk.internal.module.Modules.transformedByAgent. |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
112 |
// At the same time, another thread can instrument the module classes by |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
113 |
// injecting dependencies that require the default read edges for resolution. |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
114 |
if (this->has_default_read_edges() && !m->is_named()) { |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
115 |
ClassLoaderData* cld = m->loader_data(); |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
116 |
if (cld->is_the_null_class_loader_data() || cld->is_system_class_loader_data()) { |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
117 |
return true; // default read edge |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
118 |
} |
97de8ed6c6b3
8139566: need proper sync for adding default read edges
sspitsyn
parents:
42639
diff
changeset
|
119 |
} |
46387 | 120 |
if (!has_reads_list()) { |
36508 | 121 |
return false; |
122 |
} else { |
|
123 |
return _reads->contains(m); |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
// Add a new module to this module's reads list |
|
128 |
void ModuleEntry::add_read(ModuleEntry* m) { |
|
46387 | 129 |
// Unnamed module is special cased and can read all modules |
130 |
if (!is_named()) { |
|
131 |
return; |
|
132 |
} |
|
133 |
||
36508 | 134 |
MutexLocker m1(Module_lock); |
135 |
if (m == NULL) { |
|
136 |
set_can_read_all_unnamed(); |
|
137 |
} else { |
|
138 |
if (_reads == NULL) { |
|
139 |
// Lazily create a module's reads list |
|
38733 | 140 |
_reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true); |
36508 | 141 |
} |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
142 |
|
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
143 |
// Determine, based on this newly established read edge to module m, |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
144 |
// if this module's read list should be walked at a GC safepoint. |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
145 |
set_read_walk_required(m->loader_data()); |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
146 |
|
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
147 |
// Establish readability to module m |
36508 | 148 |
_reads->append_if_missing(m); |
149 |
} |
|
150 |
} |
|
151 |
||
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
152 |
// If the module's loader, that a read edge is being established to, is |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
153 |
// not the same loader as this module's and is not one of the 3 builtin |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
154 |
// class loaders, then this module's reads list must be walked at GC |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
155 |
// safepoint. Modules have the same life cycle as their defining class |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
156 |
// loaders and should be removed if dead. |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
157 |
void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) { |
46387 | 158 |
assert(is_named(), "Cannot call set_read_walk_required on unnamed module"); |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
159 |
assert_locked_or_safepoint(Module_lock); |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
160 |
if (!_must_walk_reads && |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
161 |
loader_data() != m_loader_data && |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
162 |
!m_loader_data->is_builtin_class_loader_data()) { |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
163 |
_must_walk_reads = true; |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
164 |
if (log_is_enabled(Trace, module)) { |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
165 |
ResourceMark rm; |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
166 |
log_trace(module)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
167 |
(name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE); |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
168 |
} |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
169 |
} |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
170 |
} |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
171 |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
172 |
// Set whether the module is open, i.e. all its packages are unqualifiedly exported |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
173 |
void ModuleEntry::set_is_open(bool is_open) { |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
174 |
assert_lock_strong(Module_lock); |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
175 |
_is_open = is_open; |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
176 |
} |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
177 |
|
46387 | 178 |
// Returns true if the module has a non-empty reads list. As such, the unnamed |
179 |
// module will return false. |
|
180 |
bool ModuleEntry::has_reads_list() const { |
|
36508 | 181 |
assert_locked_or_safepoint(Module_lock); |
182 |
return ((_reads != NULL) && !_reads->is_empty()); |
|
183 |
} |
|
184 |
||
185 |
// Purge dead module entries out of reads list. |
|
186 |
void ModuleEntry::purge_reads() { |
|
187 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
188 |
|
46387 | 189 |
if (_must_walk_reads && has_reads_list()) { |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
190 |
// This module's _must_walk_reads flag will be reset based |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
191 |
// on the remaining live modules on the reads list. |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
192 |
_must_walk_reads = false; |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
193 |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
194 |
if (log_is_enabled(Trace, module)) { |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
195 |
ResourceMark rm; |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
196 |
log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked", |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
197 |
(name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE); |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
198 |
} |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
199 |
|
36508 | 200 |
// Go backwards because this removes entries that are dead. |
201 |
int len = _reads->length(); |
|
202 |
for (int idx = len - 1; idx >= 0; idx--) { |
|
203 |
ModuleEntry* module_idx = _reads->at(idx); |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
204 |
ClassLoaderData* cld_idx = module_idx->loader_data(); |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
205 |
if (cld_idx->is_unloading()) { |
36508 | 206 |
_reads->delete_at(idx); |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
207 |
} else { |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
208 |
// Update the need to walk this module's reads based on live modules |
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
209 |
set_read_walk_required(cld_idx); |
36508 | 210 |
} |
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
void ModuleEntry::module_reads_do(ModuleClosure* const f) { |
|
216 |
assert_locked_or_safepoint(Module_lock); |
|
217 |
assert(f != NULL, "invariant"); |
|
218 |
||
46387 | 219 |
if (has_reads_list()) { |
36508 | 220 |
int reads_len = _reads->length(); |
221 |
for (int i = 0; i < reads_len; ++i) { |
|
222 |
f->do_module(_reads->at(i)); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
void ModuleEntry::delete_reads() { |
|
228 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
229 |
delete _reads; |
|
230 |
_reads = NULL; |
|
231 |
} |
|
232 |
||
46387 | 233 |
ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) { |
234 |
// The java.lang.Module for this loader's |
|
235 |
// corresponding unnamed module can be found in the java.lang.ClassLoader object. |
|
236 |
oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader()); |
|
237 |
ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld); |
|
238 |
||
239 |
// Store pointer to the ModuleEntry in the unnamed module's java.lang.Module |
|
240 |
// object. |
|
46388 | 241 |
java_lang_Module::set_module_entry(module, unnamed_module); |
46387 | 242 |
|
243 |
return unnamed_module; |
|
244 |
} |
|
245 |
||
246 |
ModuleEntry* ModuleEntry::create_boot_unnamed_module(ClassLoaderData* cld) { |
|
247 |
// For the boot loader, the java.lang.Module for the unnamed module |
|
248 |
// is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At |
|
249 |
// this point initially create the ModuleEntry for the unnamed module. |
|
250 |
ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(), cld); |
|
251 |
assert(unnamed_module != NULL, "boot loader unnamed module should not be null"); |
|
252 |
return unnamed_module; |
|
253 |
} |
|
254 |
||
255 |
// When creating an unnamed module, this is called without holding the Module_lock. |
|
256 |
// This is okay because the unnamed module gets created before the ClassLoaderData |
|
257 |
// is available to other threads. |
|
258 |
ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) { |
|
259 |
ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, sizeof(ModuleEntry), mtModule); |
|
260 |
||
261 |
// Initialize everything BasicHashtable would |
|
262 |
entry->set_next(NULL); |
|
263 |
entry->set_hash(0); |
|
264 |
entry->set_literal(NULL); |
|
265 |
||
266 |
// Initialize fields specific to a ModuleEntry |
|
267 |
entry->init(); |
|
268 |
||
269 |
// Unnamed modules can read all other unnamed modules. |
|
270 |
entry->set_can_read_all_unnamed(); |
|
271 |
||
272 |
if (!module_handle.is_null()) { |
|
273 |
entry->set_module(cld->add_handle(module_handle)); |
|
274 |
} |
|
275 |
||
276 |
entry->set_loader_data(cld); |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
277 |
entry->_is_open = true; |
46387 | 278 |
|
279 |
TRACE_INIT_ID(entry); |
|
280 |
||
281 |
return entry; |
|
282 |
} |
|
283 |
||
284 |
void ModuleEntry::delete_unnamed_module() { |
|
285 |
// Do not need unlink_entry() since the unnamed module is not in the hashtable |
|
286 |
FREE_C_HEAP_ARRAY(char, this); |
|
287 |
} |
|
288 |
||
36508 | 289 |
ModuleEntryTable::ModuleEntryTable(int table_size) |
46387 | 290 |
: Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry)) |
36508 | 291 |
{ |
292 |
} |
|
293 |
||
294 |
ModuleEntryTable::~ModuleEntryTable() { |
|
295 |
assert_locked_or_safepoint(Module_lock); |
|
296 |
||
297 |
// Walk through all buckets and all entries in each bucket, |
|
298 |
// freeing each entry. |
|
299 |
for (int i = 0; i < table_size(); ++i) { |
|
300 |
for (ModuleEntry* m = bucket(i); m != NULL;) { |
|
301 |
ModuleEntry* to_remove = m; |
|
302 |
// read next before freeing. |
|
303 |
m = m->next(); |
|
304 |
||
305 |
ResourceMark rm; |
|
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
306 |
if (to_remove->name() != NULL) { |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
307 |
log_info(module, unload)("unloading module %s", to_remove->name()->as_C_string()); |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
308 |
} |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
309 |
log_debug(module)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ? |
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
310 |
to_remove->name()->as_C_string() : UNNAMED_MODULE); |
36508 | 311 |
|
312 |
// Clean out the C heap allocated reads list first before freeing the entry |
|
313 |
to_remove->delete_reads(); |
|
314 |
if (to_remove->name() != NULL) { |
|
315 |
to_remove->name()->decrement_refcount(); |
|
316 |
} |
|
317 |
if (to_remove->version() != NULL) { |
|
318 |
to_remove->version()->decrement_refcount(); |
|
319 |
} |
|
320 |
if (to_remove->location() != NULL) { |
|
321 |
to_remove->location()->decrement_refcount(); |
|
322 |
} |
|
323 |
||
324 |
// Unlink from the Hashtable prior to freeing |
|
325 |
unlink_entry(to_remove); |
|
326 |
FREE_C_HEAP_ARRAY(char, to_remove); |
|
327 |
} |
|
328 |
} |
|
329 |
assert(number_of_entries() == 0, "should have removed all entries"); |
|
330 |
assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list"); |
|
331 |
free_buckets(); |
|
332 |
} |
|
333 |
||
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
334 |
ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle, |
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
335 |
bool is_open, Symbol* name, |
36508 | 336 |
Symbol* version, Symbol* location, |
337 |
ClassLoaderData* loader_data) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
338 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
46729 | 339 |
ModuleEntry* entry = (ModuleEntry*)Hashtable<Symbol*, mtModule>::allocate_new_entry(hash, name); |
36508 | 340 |
|
341 |
// Initialize fields specific to a ModuleEntry |
|
342 |
entry->init(); |
|
343 |
if (name != NULL) { |
|
344 |
name->increment_refcount(); |
|
345 |
} else { |
|
346 |
// Unnamed modules can read all other unnamed modules. |
|
347 |
entry->set_can_read_all_unnamed(); |
|
348 |
} |
|
349 |
||
350 |
if (!module_handle.is_null()) { |
|
351 |
entry->set_module(loader_data->add_handle(module_handle)); |
|
352 |
} |
|
353 |
||
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
354 |
entry->set_loader_data(loader_data); |
36508 | 355 |
entry->set_version(version); |
356 |
entry->set_location(location); |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
357 |
entry->set_is_open(is_open); |
36508 | 358 |
|
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
359 |
if (ClassLoader::is_in_patch_mod_entries(name)) { |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
360 |
entry->set_is_patched(); |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
361 |
if (log_is_enabled(Trace, module, patch)) { |
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
362 |
ResourceMark rm; |
44993
f61bcd80ec1f
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44520
diff
changeset
|
363 |
log_trace(module, patch)("Marked module %s as patched from --patch-module", name->as_C_string()); |
42634
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
364 |
} |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
365 |
} |
7459867ebf98
8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents:
42575
diff
changeset
|
366 |
|
42639
762117d57d05
8170672: Event-based tracing to support classloader instances
mgronlun
parents:
42636
diff
changeset
|
367 |
TRACE_INIT_ID(entry); |
36508 | 368 |
|
369 |
return entry; |
|
370 |
} |
|
371 |
||
372 |
void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
373 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
38733 | 374 |
Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry); |
36508 | 375 |
} |
376 |
||
377 |
ModuleEntry* ModuleEntryTable::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
|
378 |
bool is_open, |
36508 | 379 |
Symbol* module_name, |
380 |
Symbol* module_version, |
|
381 |
Symbol* module_location, |
|
382 |
ClassLoaderData* loader_data) { |
|
383 |
assert(module_name != NULL, "ModuleEntryTable locked_create_entry_or_null should never be called for unnamed module."); |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
384 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
36508 | 385 |
// Check if module already exists. |
386 |
if (lookup_only(module_name) != NULL) { |
|
387 |
return NULL; |
|
388 |
} else { |
|
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
46388
diff
changeset
|
389 |
ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, is_open, module_name, |
36508 | 390 |
module_version, module_location, loader_data); |
391 |
add_entry(index_for(module_name), entry); |
|
392 |
return entry; |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
// lookup_only by Symbol* to find a ModuleEntry. |
|
397 |
ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) { |
|
46387 | 398 |
assert(name != NULL, "name cannot be NULL"); |
36508 | 399 |
int index = index_for(name); |
400 |
for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) { |
|
401 |
if (m->name()->fast_compare(name) == 0) { |
|
402 |
return m; |
|
403 |
} |
|
404 |
} |
|
405 |
return NULL; |
|
406 |
} |
|
407 |
||
408 |
// Remove dead modules from all other alive modules' reads list. |
|
409 |
// This should only occur at class unloading. |
|
410 |
void ModuleEntryTable::purge_all_module_reads() { |
|
411 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
412 |
for (int i = 0; i < table_size(); i++) { |
|
413 |
for (ModuleEntry* entry = bucket(i); |
|
414 |
entry != NULL; |
|
415 |
entry = entry->next()) { |
|
416 |
entry->purge_reads(); |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
420 |
||
421 |
void ModuleEntryTable::finalize_javabase(Handle module_handle, Symbol* version, Symbol* location) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38733
diff
changeset
|
422 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
36508 | 423 |
ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data(); |
424 |
ModuleEntryTable* module_table = boot_loader_data->modules(); |
|
425 |
||
426 |
assert(module_table != NULL, "boot loader's ModuleEntryTable not defined"); |
|
427 |
||
428 |
if (module_handle.is_null()) { |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
42634
diff
changeset
|
429 |
fatal("Unable to finalize module definition for " JAVA_BASE_NAME); |
36508 | 430 |
} |
431 |
||
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
432 |
// Set java.lang.Module, version and location for java.base |
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39625
diff
changeset
|
433 |
ModuleEntry* jb_module = javabase_moduleEntry(); |
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
42634
diff
changeset
|
434 |
assert(jb_module != NULL, JAVA_BASE_NAME " ModuleEntry not defined"); |
36508 | 435 |
jb_module->set_version(version); |
436 |
jb_module->set_location(location); |
|
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39625
diff
changeset
|
437 |
// Once java.base's ModuleEntry _module field is set with the known |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
438 |
// java.lang.Module, java.base is considered "defined" to the VM. |
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39625
diff
changeset
|
439 |
jb_module->set_module(boot_loader_data->add_handle(module_handle)); |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39625
diff
changeset
|
440 |
|
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
441 |
// Store pointer to the ModuleEntry for java.base in the java.lang.Module object. |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
442 |
java_lang_Module::set_module_entry(module_handle(), jb_module); |
36508 | 443 |
} |
444 |
||
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
445 |
// Within java.lang.Class instances there is a java.lang.Module field that must |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
446 |
// be set with the defining module. During startup, prior to java.base's definition, |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
447 |
// classes needing their module field set are added to the fixup_module_list. |
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
448 |
// Their module field is set once java.base's java.lang.Module is known to the VM. |
36508 | 449 |
void ModuleEntryTable::patch_javabase_entries(Handle module_handle) { |
450 |
if (module_handle.is_null()) { |
|
42636
aafc434ba580
8169734: Update uses of string "java.base" to macro
rprotacio
parents:
42634
diff
changeset
|
451 |
fatal("Unable to patch the module field of classes loaded prior to " |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44084
diff
changeset
|
452 |
JAVA_BASE_NAME "'s definition, invalid java.lang.Module"); |
36508 | 453 |
} |
454 |
||
455 |
// Do the fixups for the basic primitive types |
|
456 |
java_lang_Class::set_module(Universe::int_mirror(), module_handle()); |
|
457 |
java_lang_Class::set_module(Universe::float_mirror(), module_handle()); |
|
458 |
java_lang_Class::set_module(Universe::double_mirror(), module_handle()); |
|
459 |
java_lang_Class::set_module(Universe::byte_mirror(), module_handle()); |
|
460 |
java_lang_Class::set_module(Universe::bool_mirror(), module_handle()); |
|
461 |
java_lang_Class::set_module(Universe::char_mirror(), module_handle()); |
|
462 |
java_lang_Class::set_module(Universe::long_mirror(), module_handle()); |
|
463 |
java_lang_Class::set_module(Universe::short_mirror(), module_handle()); |
|
464 |
java_lang_Class::set_module(Universe::void_mirror(), module_handle()); |
|
465 |
||
466 |
// Do the fixups for classes that have already been created. |
|
467 |
GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list(); |
|
468 |
int list_length = list->length(); |
|
469 |
for (int i = 0; i < list_length; i++) { |
|
470 |
Klass* k = list->at(i); |
|
471 |
assert(k->is_klass(), "List should only hold classes"); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
472 |
java_lang_Class::fixup_module_field(k, module_handle); |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37503
diff
changeset
|
473 |
k->class_loader_data()->dec_keep_alive(); |
36508 | 474 |
} |
475 |
||
476 |
delete java_lang_Class::fixup_module_field_list(); |
|
477 |
java_lang_Class::set_fixup_module_field_list(NULL); |
|
478 |
} |
|
479 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
480 |
void ModuleEntryTable::print(outputStream* st) { |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
481 |
st->print_cr("Module Entry Table (table_size=%d, entries=%d)", |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
482 |
table_size(), number_of_entries()); |
36508 | 483 |
for (int i = 0; i < table_size(); i++) { |
484 |
for (ModuleEntry* probe = bucket(i); |
|
485 |
probe != NULL; |
|
486 |
probe = probe->next()) { |
|
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
487 |
probe->print(st); |
36508 | 488 |
} |
489 |
} |
|
490 |
} |
|
491 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
492 |
void ModuleEntry::print(outputStream* st) { |
36508 | 493 |
ResourceMark rm; |
39625
8702e5b9bfed
8160356: invalid suffix on literal warning is occurred with GCC 6
kbarrett
parents:
39616
diff
changeset
|
494 |
st->print_cr("entry " PTR_FORMAT " name %s module " PTR_FORMAT " loader %s version %s location %s strict %s next " PTR_FORMAT, |
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
495 |
p2i(this), |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
496 |
name() == NULL ? UNNAMED_MODULE : name()->as_C_string(), |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
497 |
p2i(module()), |
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
498 |
loader_data()->loader_name(), |
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
499 |
version() != NULL ? version()->as_C_string() : "NULL", |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
500 |
location() != NULL ? location()->as_C_string() : "NULL", |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
501 |
BOOL_TO_STR(!can_read_all_unnamed()), p2i(next())); |
36508 | 502 |
} |
503 |
||
504 |
void ModuleEntryTable::verify() { |
|
46475
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46458
diff
changeset
|
505 |
verify_table<ModuleEntry>("Module Entry Table"); |
36508 | 506 |
} |
507 |
||
508 |
void ModuleEntry::verify() { |
|
39616
f82b1f888578
8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents:
39290
diff
changeset
|
509 |
guarantee(loader_data() != NULL, "A module entry must be associated with a loader."); |
36508 | 510 |
} |