author | rehn |
Thu, 01 Sep 2016 08:30:17 +0200 | |
changeset 40899 | d7140c75c2c6 |
parent 39616 | f82b1f888578 |
child 43471 | bfb383279a16 |
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 |
#ifndef SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP |
|
26 |
#define SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP |
|
27 |
||
28 |
#include "classfile/moduleEntry.hpp" |
|
29 |
#include "oops/symbol.hpp" |
|
30 |
#include "utilities/growableArray.hpp" |
|
31 |
#include "utilities/hashtable.hpp" |
|
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
32 |
#include "utilities/ostream.hpp" |
36508 | 33 |
|
34 |
// A PackageEntry basically represents a Java package. It contains: |
|
35 |
// - Symbol* containing the package's name. |
|
36 |
// - ModuleEntry* for this package's containing module. |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
37 |
// - a flag indicating if package is exported unqualifiedly |
36508 | 38 |
// - a flag indicating if this package is exported to all unnamed modules. |
39 |
// - a growable array containing other module entries that this |
|
40 |
// package is exported to. |
|
41 |
// |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
42 |
// Packages can be exported in the following 3 ways: |
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
43 |
// - not exported: the package does not have qualified or unqualified exports. |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
44 |
// - qualified exports: the package has been explicitly qualified to at least |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
45 |
// one particular module or has been qualifiedly exported |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
46 |
// to all unnamed modules. |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
47 |
// Note: _is_exported_allUnnamed is a form of a qualified |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
48 |
// export. It is equivalent to the package being |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
49 |
// explicitly exported to all current and future unnamed modules. |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
50 |
// - unqualified exports: the package is exported to all modules. |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
51 |
// |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
52 |
// A package can transition from: |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
53 |
// - being not exported, to being exported either in a qualified or unqualified manner |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
54 |
// - being qualifiedly exported, to unqualifiedly exported. Its exported scope is widened. |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
55 |
// |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
56 |
// A package cannot transition from: |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
57 |
// - being unqualifiedly exported, to exported qualifiedly to a specific module. |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
58 |
// This transition attempt is silently ignored in set_exported. |
36508 | 59 |
// |
60 |
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either |
|
61 |
// data structure. |
|
38733 | 62 |
class PackageEntry : public HashtableEntry<Symbol*, mtModule> { |
36508 | 63 |
private: |
64 |
ModuleEntry* _module; |
|
65 |
// Used to indicate for packages with classes loaded by the boot loader that |
|
66 |
// a class in that package has been loaded. And, for packages with classes |
|
67 |
// loaded by the boot loader from -Xbootclasspath/a in an unnamed module, it |
|
68 |
// indicates from which class path entry. |
|
69 |
s2 _classpath_index; |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
70 |
bool _is_exported_unqualified; |
36508 | 71 |
bool _is_exported_allUnnamed; |
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
|
72 |
bool _must_walk_exports; |
36508 | 73 |
GrowableArray<ModuleEntry*>* _exported_pending_delete; // transitioned from qualified to unqualified, delete at safepoint |
74 |
GrowableArray<ModuleEntry*>* _qualified_exports; |
|
75 |
TRACE_DEFINE_TRACE_ID_FIELD; |
|
76 |
||
77 |
// Initial size of a package entry's list of qualified exports. |
|
78 |
enum {QUAL_EXP_SIZE = 43}; |
|
79 |
||
80 |
public: |
|
81 |
void init() { |
|
82 |
_module = NULL; |
|
83 |
_classpath_index = -1; |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
84 |
_is_exported_unqualified = false; |
36508 | 85 |
_is_exported_allUnnamed = false; |
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
|
86 |
_must_walk_exports = false; |
36508 | 87 |
_exported_pending_delete = NULL; |
88 |
_qualified_exports = NULL; |
|
89 |
} |
|
90 |
||
91 |
// package name |
|
92 |
Symbol* name() const { return literal(); } |
|
93 |
void set_name(Symbol* n) { set_literal(n); } |
|
94 |
||
95 |
// the module containing the package definition |
|
96 |
ModuleEntry* module() const { return _module; } |
|
97 |
void set_module(ModuleEntry* m) { _module = m; } |
|
98 |
||
99 |
// package's export state |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
100 |
bool is_exported() const { // qualifiedly or unqualifiedly exported |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
101 |
return (is_unqual_exported() || has_qual_exports_list() || is_exported_allUnnamed()); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
102 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
103 |
// Returns true if the package has any explicit qualified exports or is exported to all unnamed |
36508 | 104 |
bool is_qual_exported() const { |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
105 |
return (has_qual_exports_list() || is_exported_allUnnamed()); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
106 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
107 |
// Returns true if there are any explicit qualified exports |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
108 |
bool has_qual_exports_list() const { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
109 |
assert(!(_qualified_exports != NULL && _is_exported_unqualified), |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
110 |
"_qualified_exports set at same time as _is_exported_unqualified"); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
111 |
return (_qualified_exports != NULL); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
112 |
} |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
113 |
bool is_exported_allUnnamed() const { |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
114 |
assert(!(_is_exported_allUnnamed && _is_exported_unqualified), |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
115 |
"_is_exported_allUnnamed set at same time as _is_exported_unqualified"); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
116 |
return _is_exported_allUnnamed; |
36508 | 117 |
} |
118 |
bool is_unqual_exported() const { |
|
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
119 |
assert(!(_qualified_exports != NULL && _is_exported_unqualified), |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
120 |
"_qualified_exports set at same time as _is_exported_unqualified"); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
121 |
assert(!(_is_exported_allUnnamed && _is_exported_unqualified), |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
122 |
"_is_exported_allUnnamed set at same time as _is_exported_unqualified"); |
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
123 |
return _is_exported_unqualified; |
36508 | 124 |
} |
125 |
void set_unqual_exported() { |
|
39290
0cc9f5028562
8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents:
38940
diff
changeset
|
126 |
assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
127 |
_is_exported_unqualified = true; |
36508 | 128 |
_is_exported_allUnnamed = false; |
129 |
_qualified_exports = NULL; |
|
130 |
} |
|
131 |
bool exported_pending_delete() const { return (_exported_pending_delete != NULL); } |
|
132 |
||
133 |
void set_exported(ModuleEntry* m); |
|
134 |
||
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
135 |
void set_is_exported_allUnnamed(); |
36508 | 136 |
|
137 |
void set_classpath_index(s2 classpath_index) { |
|
138 |
_classpath_index = classpath_index; |
|
139 |
} |
|
140 |
s2 classpath_index() const { return _classpath_index; } |
|
141 |
||
142 |
bool has_loaded_class() const { return _classpath_index != -1; } |
|
143 |
||
144 |
// returns true if the package is defined in the unnamed module |
|
145 |
bool in_unnamed_module() const { return !_module->is_named(); } |
|
146 |
||
38940
7de797f32b5f
8152404: Stabilize PackageEntry::package_exports_do
rprotacio
parents:
38733
diff
changeset
|
147 |
// returns true if the package specifies m as a qualified export, including through an unnamed export |
36508 | 148 |
bool is_qexported_to(ModuleEntry* m) const; |
149 |
||
150 |
// add the module to the package's qualified exports |
|
151 |
void add_qexport(ModuleEntry* m); |
|
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 |
void set_export_walk_required(ClassLoaderData* m_loader_data); |
36508 | 153 |
|
154 |
PackageEntry* next() const { |
|
38733 | 155 |
return (PackageEntry*)HashtableEntry<Symbol*, mtModule>::next(); |
36508 | 156 |
} |
157 |
||
158 |
PackageEntry** next_addr() { |
|
38733 | 159 |
return (PackageEntry**)HashtableEntry<Symbol*, mtModule>::next_addr(); |
36508 | 160 |
} |
161 |
||
162 |
// iteration of qualified exports |
|
163 |
void package_exports_do(ModuleClosure* const f); |
|
164 |
||
165 |
TRACE_DEFINE_TRACE_ID_METHODS; |
|
166 |
||
167 |
// Purge dead weak references out of exported list when any given class loader is unloaded. |
|
168 |
void purge_qualified_exports(); |
|
169 |
void delete_qualified_exports(); |
|
170 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
171 |
void print(outputStream* st = tty); |
36508 | 172 |
void verify(); |
173 |
}; |
|
174 |
||
175 |
// The PackageEntryTable is a Hashtable containing a list of all packages defined |
|
176 |
// by a particular class loader. Each package is represented as a PackageEntry node. |
|
177 |
// The PackageEntryTable's lookup is lock free. |
|
178 |
// |
|
38733 | 179 |
class PackageEntryTable : public Hashtable<Symbol*, mtModule> { |
36508 | 180 |
friend class VMStructs; |
181 |
public: |
|
182 |
enum Constants { |
|
183 |
_packagetable_entry_size = 1009 // number of entries in package entry table |
|
184 |
}; |
|
185 |
||
186 |
private: |
|
187 |
PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module); |
|
188 |
void add_entry(int index, PackageEntry* new_entry); |
|
189 |
||
38733 | 190 |
int entry_size() const { return BasicHashtable<mtModule>::entry_size(); } |
36508 | 191 |
|
192 |
PackageEntry** bucket_addr(int i) { |
|
38733 | 193 |
return (PackageEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i); |
36508 | 194 |
} |
195 |
||
196 |
static unsigned int compute_hash(Symbol* name) { return (unsigned int)(name->identity_hash()); } |
|
197 |
int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); } |
|
198 |
||
199 |
public: |
|
200 |
PackageEntryTable(int table_size); |
|
201 |
~PackageEntryTable(); |
|
202 |
||
203 |
PackageEntry* bucket(int i) { |
|
38733 | 204 |
return (PackageEntry*)Hashtable<Symbol*, mtModule>::bucket(i); |
36508 | 205 |
} |
206 |
||
207 |
// Create package in loader's package entry table and return the entry. |
|
208 |
// If entry already exists, return null. Assume Module lock was taken by caller. |
|
209 |
PackageEntry* locked_create_entry_or_null(Symbol* name, ModuleEntry* module); |
|
210 |
||
211 |
// lookup Package with loader's package entry table, if not found add |
|
212 |
PackageEntry* lookup(Symbol* name, ModuleEntry* module); |
|
213 |
||
214 |
// Only lookup Package within loader's package entry table. The table read is lock-free. |
|
215 |
PackageEntry* lookup_only(Symbol* Package); |
|
216 |
||
217 |
void verify_javabase_packages(GrowableArray<Symbol*> *pkg_list); |
|
218 |
||
219 |
// purge dead weak references out of exported list |
|
220 |
void purge_all_package_exports(); |
|
221 |
||
37503
77531df4dad3
8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents:
36508
diff
changeset
|
222 |
void print(outputStream* st = tty); |
36508 | 223 |
void verify(); |
224 |
}; |
|
225 |
||
226 |
#endif // SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP |