author | redestad |
Sun, 11 Dec 2016 12:20:45 +0100 | |
changeset 42469 | d1c0a9123f87 |
parent 42073 | 89e056fd82cc |
child 42636 | aafc434ba580 |
permissions | -rw-r--r-- |
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 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/moduleEntry.hpp" |
|
27 |
#include "classfile/packageEntry.hpp" |
|
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
|
28 |
#include "logging/log.hpp" |
36508 | 29 |
#include "memory/resourceArea.hpp" |
30 |
#include "oops/symbol.hpp" |
|
31 |
#include "runtime/handles.inline.hpp" |
|
32 |
#include "trace/traceMacros.hpp" |
|
33 |
#include "utilities/events.hpp" |
|
34 |
#include "utilities/growableArray.hpp" |
|
35 |
#include "utilities/hashtable.inline.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 |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
38 |
// Returns true if this package specifies m as a qualified export, including through an unnamed export |
36508 | 39 |
bool PackageEntry::is_qexported_to(ModuleEntry* m) const { |
40 |
assert(m != NULL, "No module to lookup in this package's qualified exports list"); |
|
41 |
MutexLocker m1(Module_lock); |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
42 |
if (is_exported_allUnnamed() && !m->is_named()) { |
36508 | 43 |
return true; |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
44 |
} else if (!has_qual_exports_list()) { |
36508 | 45 |
return false; |
46 |
} else { |
|
47 |
return _qualified_exports->contains(m); |
|
48 |
} |
|
49 |
} |
|
50 |
||
51 |
// Add a module to the package's qualified export list. |
|
52 |
void PackageEntry::add_qexport(ModuleEntry* m) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
53 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
54 |
if (!has_qual_exports_list()) { |
36508 | 55 |
// Lazily create a package's qualified exports list. |
56 |
// Initial size is small, do not anticipate export lists to be large. |
|
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
|
57 |
_qualified_exports = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleEntry*>(QUAL_EXP_SIZE, true); |
36508 | 58 |
} |
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
|
59 |
|
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
|
60 |
// Determine, based on this newly established export 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
|
61 |
// if this package's export 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
|
62 |
set_export_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
|
63 |
|
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
|
64 |
// Establish exportability to module m |
36508 | 65 |
_qualified_exports->append_if_missing(m); |
66 |
} |
|
67 |
||
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
|
68 |
// If the module's loader, that an export 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
|
69 |
// 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
|
70 |
// class loaders, then this package's export 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
|
71 |
// 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
|
72 |
// 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
|
73 |
void PackageEntry::set_export_walk_required(ClassLoaderData* 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
|
74 |
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
|
75 |
ModuleEntry* this_pkg_mod = module(); |
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
|
76 |
if (!_must_walk_exports && |
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
|
77 |
(this_pkg_mod == NULL || this_pkg_mod->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
|
78 |
!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
|
79 |
_must_walk_exports = true; |
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
|
80 |
if (log_is_enabled(Trace, 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
|
81 |
ResourceMark rm; |
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
|
82 |
assert(name() != NULL, "PackageEntry without a valid name"); |
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
|
83 |
log_trace(modules)("PackageEntry::set_export_walk_required(): package %s defined in module %s, exports list must be walked", |
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
|
84 |
name()->as_C_string(), |
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
|
85 |
(this_pkg_mod == NULL || this_pkg_mod->name() == NULL) ? |
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
|
86 |
UNNAMED_MODULE : this_pkg_mod->name()->as_C_string()); |
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
|
87 |
} |
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
|
88 |
} |
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
|
89 |
} |
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
|
90 |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
91 |
// Set the package's exported states based on the value of the ModuleEntry. |
36508 | 92 |
void PackageEntry::set_exported(ModuleEntry* m) { |
93 |
MutexLocker m1(Module_lock); |
|
94 |
if (is_unqual_exported()) { |
|
95 |
// An exception could be thrown, but choose to simply ignore. |
|
96 |
// Illegal to convert an unqualified exported package to be qualifiedly exported |
|
97 |
return; |
|
98 |
} |
|
99 |
||
100 |
if (m == NULL) { |
|
101 |
// NULL indicates the package is being unqualifiedly exported |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
102 |
if (has_qual_exports_list()) { |
36508 | 103 |
// Legit to transition a package from being qualifiedly exported |
104 |
// to unqualified. Clean up the qualified lists at the next |
|
105 |
// safepoint. |
|
106 |
_exported_pending_delete = _qualified_exports; |
|
107 |
} |
|
108 |
||
109 |
// Mark package as unqualifiedly exported |
|
110 |
set_unqual_exported(); |
|
111 |
||
112 |
} else { |
|
113 |
// Add the exported module |
|
114 |
add_qexport(m); |
|
115 |
} |
|
116 |
} |
|
117 |
||
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
118 |
void PackageEntry::set_is_exported_allUnnamed() { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
119 |
MutexLocker m1(Module_lock); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
120 |
if (!is_unqual_exported()) { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
121 |
_is_exported_allUnnamed = true; |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
122 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
123 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
124 |
|
36508 | 125 |
// Remove dead module entries within the package's exported list. |
126 |
void PackageEntry::purge_qualified_exports() { |
|
127 |
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
|
128 |
if (_must_walk_exports && |
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
|
129 |
_qualified_exports != NULL && |
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
|
130 |
!_qualified_exports->is_empty()) { |
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
|
131 |
ModuleEntry* pkg_module = module(); |
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
|
132 |
|
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
|
133 |
// This package's _must_walk_exports 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
|
134 |
// on the remaining live modules on the exports 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
|
135 |
_must_walk_exports = 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
|
136 |
|
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
|
137 |
if (log_is_enabled(Trace, 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
|
138 |
ResourceMark rm; |
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
|
139 |
assert(name() != NULL, "PackageEntry without a valid name"); |
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
|
140 |
ModuleEntry* pkg_mod = module(); |
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
|
141 |
log_trace(modules)("PackageEntry::purge_qualified_exports(): package %s defined in module %s, exports list being walked", |
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 |
name()->as_C_string(), |
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 |
(pkg_mod == NULL || pkg_mod->name() == NULL) ? UNNAMED_MODULE : pkg_mod->name()->as_C_string()); |
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 |
} |
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 |
|
36508 | 146 |
// Go backwards because this removes entries that are dead. |
147 |
int len = _qualified_exports->length(); |
|
148 |
for (int idx = len - 1; idx >= 0; idx--) { |
|
149 |
ModuleEntry* module_idx = _qualified_exports->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
|
150 |
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
|
151 |
if (cld_idx->is_unloading()) { |
36508 | 152 |
_qualified_exports->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
|
153 |
} 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
|
154 |
// Update the need to walk this package's exports 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
|
155 |
set_export_walk_required(cld_idx); |
36508 | 156 |
} |
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
void PackageEntry::delete_qualified_exports() { |
|
162 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
163 |
if (_exported_pending_delete != NULL) { |
|
164 |
// If a transition occurred from qualified to unqualified, the _qualified_exports |
|
165 |
// field should have been NULL'ed out. |
|
166 |
assert(_qualified_exports == NULL, "Package's exported pending delete, exported list should not be active"); |
|
167 |
delete _exported_pending_delete; |
|
168 |
} |
|
169 |
||
170 |
if (_qualified_exports != NULL) { |
|
171 |
delete _qualified_exports; |
|
172 |
} |
|
173 |
||
174 |
_exported_pending_delete = NULL; |
|
175 |
_qualified_exports = NULL; |
|
176 |
} |
|
177 |
||
178 |
PackageEntryTable::PackageEntryTable(int table_size) |
|
38733 | 179 |
: Hashtable<Symbol*, mtModule>(table_size, sizeof(PackageEntry)) |
36508 | 180 |
{ |
181 |
} |
|
182 |
||
183 |
PackageEntryTable::~PackageEntryTable() { |
|
184 |
assert_locked_or_safepoint(Module_lock); |
|
185 |
||
186 |
// Walk through all buckets and all entries in each bucket, |
|
187 |
// freeing each entry. |
|
188 |
for (int i = 0; i < table_size(); ++i) { |
|
189 |
for (PackageEntry* p = bucket(i); p != NULL;) { |
|
190 |
PackageEntry* to_remove = p; |
|
191 |
// read next before freeing. |
|
192 |
p = p->next(); |
|
193 |
||
194 |
// Clean out the C heap allocated qualified exports list first before freeing the entry |
|
195 |
to_remove->delete_qualified_exports(); |
|
196 |
to_remove->name()->decrement_refcount(); |
|
197 |
||
198 |
// Unlink from the Hashtable prior to freeing |
|
199 |
unlink_entry(to_remove); |
|
200 |
FREE_C_HEAP_ARRAY(char, to_remove); |
|
201 |
} |
|
202 |
} |
|
203 |
assert(number_of_entries() == 0, "should have removed all entries"); |
|
204 |
assert(new_entry_free_list() == NULL, "entry present on PackageEntryTable's free list"); |
|
205 |
free_buckets(); |
|
206 |
} |
|
207 |
||
208 |
PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
209 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
38733 | 210 |
PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule); |
36508 | 211 |
|
212 |
// Initialize everything BasicHashtable would |
|
213 |
entry->set_next(NULL); |
|
214 |
entry->set_hash(hash); |
|
215 |
entry->set_literal(name); |
|
216 |
||
217 |
TRACE_INIT_PACKAGE_ID(entry); |
|
218 |
||
219 |
// Initialize fields specific to a PackageEntry |
|
220 |
entry->init(); |
|
221 |
entry->name()->increment_refcount(); |
|
222 |
if (!module->is_named()) { |
|
223 |
// Set the exported state to true because all packages |
|
224 |
// within the unnamed module are unqualifiedly exported |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
225 |
entry->set_unqual_exported(); |
36508 | 226 |
} |
227 |
entry->set_module(module); |
|
228 |
return entry; |
|
229 |
} |
|
230 |
||
231 |
void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
232 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
38733 | 233 |
Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry); |
36508 | 234 |
} |
235 |
||
236 |
// Create package in loader's package entry table and return the entry. |
|
237 |
// If entry already exists, return null. Assume Module lock was taken by caller. |
|
238 |
PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, ModuleEntry* module) { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
239 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
36508 | 240 |
// Check if package already exists. Return NULL if it does. |
241 |
if (lookup_only(name) != NULL) { |
|
242 |
return NULL; |
|
243 |
} else { |
|
244 |
PackageEntry* entry = new_entry(compute_hash(name), name, module); |
|
245 |
add_entry(index_for(name), entry); |
|
246 |
return entry; |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
PackageEntry* PackageEntryTable::lookup(Symbol* name, ModuleEntry* module) { |
|
251 |
PackageEntry* p = lookup_only(name); |
|
252 |
if (p != NULL) { |
|
253 |
return p; |
|
254 |
} else { |
|
255 |
// If not found, add to table. Grab the PackageEntryTable lock first. |
|
256 |
MutexLocker ml(Module_lock); |
|
257 |
||
258 |
// Since look-up was done lock-free, we need to check if another thread beat |
|
259 |
// us in the race to insert the package. |
|
260 |
PackageEntry* test = lookup_only(name); |
|
261 |
if (test != NULL) { |
|
262 |
// A race occurred and another thread introduced the package. |
|
263 |
return test; |
|
264 |
} else { |
|
265 |
assert(module != NULL, "module should never be null"); |
|
266 |
PackageEntry* entry = new_entry(compute_hash(name), name, module); |
|
267 |
add_entry(index_for(name), entry); |
|
268 |
return entry; |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
PackageEntry* PackageEntryTable::lookup_only(Symbol* name) { |
|
274 |
int index = index_for(name); |
|
275 |
for (PackageEntry* p = bucket(index); p != NULL; p = p->next()) { |
|
276 |
if (p->name()->fast_compare(name) == 0) { |
|
277 |
return p; |
|
278 |
} |
|
279 |
} |
|
280 |
return NULL; |
|
281 |
} |
|
282 |
||
283 |
// Called when a define module for java.base is being processed. |
|
284 |
// Verify the packages loaded thus far are in java.base's package list. |
|
285 |
void PackageEntryTable::verify_javabase_packages(GrowableArray<Symbol*> *pkg_list) { |
|
286 |
for (int i = 0; i < table_size(); i++) { |
|
287 |
for (PackageEntry* entry = bucket(i); |
|
288 |
entry != NULL; |
|
289 |
entry = entry->next()) { |
|
290 |
ModuleEntry* m = entry->module(); |
|
291 |
Symbol* module_name = (m == NULL ? NULL : m->name()); |
|
292 |
if (module_name != NULL && |
|
293 |
(module_name->fast_compare(vmSymbols::java_base()) == 0) && |
|
294 |
!pkg_list->contains(entry->name())) { |
|
295 |
ResourceMark rm; |
|
296 |
vm_exit_during_initialization("A non-java.base package was loaded prior to module system initialization", entry->name()->as_C_string()); |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
} |
|
302 |
||
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
303 |
// iteration of qualified exports |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
304 |
void PackageEntry::package_exports_do(ModuleClosure* const f) { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
305 |
assert_locked_or_safepoint(Module_lock); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
306 |
assert(f != NULL, "invariant"); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
307 |
|
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
308 |
if (has_qual_exports_list()) { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
309 |
int qe_len = _qualified_exports->length(); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
310 |
|
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
311 |
for (int i = 0; i < qe_len; ++i) { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
312 |
f->do_module(_qualified_exports->at(i)); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
313 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
314 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
315 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
316 |
|
36508 | 317 |
// Remove dead entries from all packages' exported list |
318 |
void PackageEntryTable::purge_all_package_exports() { |
|
319 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
320 |
for (int i = 0; i < table_size(); i++) { |
|
321 |
for (PackageEntry* entry = bucket(i); |
|
322 |
entry != NULL; |
|
323 |
entry = entry->next()) { |
|
324 |
if (entry->exported_pending_delete()) { |
|
325 |
// exported list is pending deletion due to a transition |
|
326 |
// from qualified to unqualified |
|
327 |
entry->delete_qualified_exports(); |
|
328 |
} else if (entry->is_qual_exported()) { |
|
329 |
entry->purge_qualified_exports(); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
335 |
void PackageEntryTable::print(outputStream* st) { |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
336 |
st->print_cr("Package Entry Table (table_size=%d, entries=%d)", |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
337 |
table_size(), number_of_entries()); |
36508 | 338 |
for (int i = 0; i < table_size(); i++) { |
339 |
for (PackageEntry* probe = bucket(i); |
|
340 |
probe != NULL; |
|
341 |
probe = probe->next()) { |
|
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
342 |
probe->print(st); |
36508 | 343 |
} |
344 |
} |
|
345 |
} |
|
346 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
347 |
void PackageEntry::print(outputStream* st) { |
36508 | 348 |
ResourceMark rm; |
39625
8702e5b9bfed
8160356: invalid suffix on literal warning is occurred with GCC 6
kbarrett
parents:
39616
diff
changeset
|
349 |
st->print_cr("package entry " PTR_FORMAT " name %s module %s classpath_index " |
8702e5b9bfed
8160356: invalid suffix on literal warning is occurred with GCC 6
kbarrett
parents:
39616
diff
changeset
|
350 |
INT32_FORMAT " is_exported_unqualified %d is_exported_allUnnamed %d " "next " PTR_FORMAT, |
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
351 |
p2i(this), name()->as_C_string(), |
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
352 |
(module()->is_named() ? module()->name()->as_C_string() : UNNAMED_MODULE), |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
353 |
_classpath_index, _is_exported_unqualified, _is_exported_allUnnamed, p2i(next())); |
36508 | 354 |
} |
355 |
||
356 |
void PackageEntryTable::verify() { |
|
357 |
int element_count = 0; |
|
358 |
for (int index = 0; index < table_size(); index++) { |
|
359 |
for (PackageEntry* probe = bucket(index); |
|
360 |
probe != NULL; |
|
361 |
probe = probe->next()) { |
|
362 |
probe->verify(); |
|
363 |
element_count++; |
|
364 |
} |
|
365 |
} |
|
366 |
guarantee(number_of_entries() == element_count, |
|
367 |
"Verify of Package Entry Table failed"); |
|
42073
89e056fd82cc
8166145: runtime/threads/ThreadInterruptTest3 fails with ExitCode 0
gziemski
parents:
39625
diff
changeset
|
368 |
DEBUG_ONLY(verify_lookup_length((double)number_of_entries() / table_size(), "Package Entry Table")); |
36508 | 369 |
} |
370 |
||
371 |
void PackageEntry::verify() { |
|
372 |
guarantee(name() != NULL, "A package entry must have a corresponding symbol name."); |
|
373 |
} |