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"
|
|
32 |
|
|
33 |
// A PackageEntry basically represents a Java package. It contains:
|
|
34 |
// - Symbol* containing the package's name.
|
|
35 |
// - ModuleEntry* for this package's containing module.
|
|
36 |
// - a flag indicating if package is exported, either qualifiedly or
|
|
37 |
// unqualifiedly.
|
|
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 |
//
|
|
42 |
// Packages that are:
|
|
43 |
// - not exported: _qualified_exports = NULL && _is_exported is false
|
|
44 |
// - qualified exports: (_qualified_exports != NULL || _is_exported_allUnnamed is true) && _is_exported is true
|
|
45 |
// - unqualified exports: (_qualified_exports = NULL && _is_exported_allUnnamed is false) && _is_exported is true
|
|
46 |
//
|
|
47 |
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
|
|
48 |
// data structure.
|
|
49 |
class PackageEntry : public HashtableEntry<Symbol*, mtClass> {
|
|
50 |
private:
|
|
51 |
ModuleEntry* _module;
|
|
52 |
// Used to indicate for packages with classes loaded by the boot loader that
|
|
53 |
// a class in that package has been loaded. And, for packages with classes
|
|
54 |
// loaded by the boot loader from -Xbootclasspath/a in an unnamed module, it
|
|
55 |
// indicates from which class path entry.
|
|
56 |
s2 _classpath_index;
|
|
57 |
bool _is_exported;
|
|
58 |
bool _is_exported_allUnnamed;
|
|
59 |
GrowableArray<ModuleEntry*>* _exported_pending_delete; // transitioned from qualified to unqualified, delete at safepoint
|
|
60 |
GrowableArray<ModuleEntry*>* _qualified_exports;
|
|
61 |
TRACE_DEFINE_TRACE_ID_FIELD;
|
|
62 |
|
|
63 |
// Initial size of a package entry's list of qualified exports.
|
|
64 |
enum {QUAL_EXP_SIZE = 43};
|
|
65 |
|
|
66 |
public:
|
|
67 |
void init() {
|
|
68 |
_module = NULL;
|
|
69 |
_classpath_index = -1;
|
|
70 |
_is_exported = false;
|
|
71 |
_is_exported_allUnnamed = false;
|
|
72 |
_exported_pending_delete = NULL;
|
|
73 |
_qualified_exports = NULL;
|
|
74 |
}
|
|
75 |
|
|
76 |
// package name
|
|
77 |
Symbol* name() const { return literal(); }
|
|
78 |
void set_name(Symbol* n) { set_literal(n); }
|
|
79 |
|
|
80 |
// the module containing the package definition
|
|
81 |
ModuleEntry* module() const { return _module; }
|
|
82 |
void set_module(ModuleEntry* m) { _module = m; }
|
|
83 |
|
|
84 |
// package's export state
|
|
85 |
bool is_exported() const { return _is_exported; } // qualifiedly or unqualifiedly exported
|
|
86 |
bool is_qual_exported() const {
|
|
87 |
return (_is_exported && (_qualified_exports != NULL || _is_exported_allUnnamed));
|
|
88 |
}
|
|
89 |
bool is_unqual_exported() const {
|
|
90 |
return (_is_exported && (_qualified_exports == NULL && !_is_exported_allUnnamed));
|
|
91 |
}
|
|
92 |
void set_unqual_exported() {
|
|
93 |
_is_exported = true;
|
|
94 |
_is_exported_allUnnamed = false;
|
|
95 |
_qualified_exports = NULL;
|
|
96 |
}
|
|
97 |
bool exported_pending_delete() const { return (_exported_pending_delete != NULL); }
|
|
98 |
|
|
99 |
void set_exported(bool e) { _is_exported = e; }
|
|
100 |
void set_exported(ModuleEntry* m);
|
|
101 |
|
|
102 |
void set_is_exported_allUnnamed() {
|
|
103 |
if (!is_unqual_exported()) {
|
|
104 |
_is_exported_allUnnamed = true;
|
|
105 |
_is_exported = true;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
bool is_exported_allUnnamed() const {
|
|
109 |
assert(_is_exported || !_is_exported_allUnnamed,
|
|
110 |
"is_allUnnamed set without is_exported being set");
|
|
111 |
return _is_exported_allUnnamed;
|
|
112 |
}
|
|
113 |
|
|
114 |
void set_classpath_index(s2 classpath_index) {
|
|
115 |
_classpath_index = classpath_index;
|
|
116 |
}
|
|
117 |
s2 classpath_index() const { return _classpath_index; }
|
|
118 |
|
|
119 |
bool has_loaded_class() const { return _classpath_index != -1; }
|
|
120 |
|
|
121 |
// returns true if the package is defined in the unnamed module
|
|
122 |
bool in_unnamed_module() const { return !_module->is_named(); }
|
|
123 |
|
|
124 |
// returns true if the package specifies m as a qualified export
|
|
125 |
bool is_qexported_to(ModuleEntry* m) const;
|
|
126 |
|
|
127 |
// add the module to the package's qualified exports
|
|
128 |
void add_qexport(ModuleEntry* m);
|
|
129 |
|
|
130 |
PackageEntry* next() const {
|
|
131 |
return (PackageEntry*)HashtableEntry<Symbol*, mtClass>::next();
|
|
132 |
}
|
|
133 |
|
|
134 |
PackageEntry** next_addr() {
|
|
135 |
return (PackageEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
|
|
136 |
}
|
|
137 |
|
|
138 |
// iteration of qualified exports
|
|
139 |
void package_exports_do(ModuleClosure* const f);
|
|
140 |
|
|
141 |
TRACE_DEFINE_TRACE_ID_METHODS;
|
|
142 |
|
|
143 |
// Purge dead weak references out of exported list when any given class loader is unloaded.
|
|
144 |
void purge_qualified_exports();
|
|
145 |
void delete_qualified_exports();
|
|
146 |
|
|
147 |
void print() PRODUCT_RETURN;
|
|
148 |
void verify();
|
|
149 |
};
|
|
150 |
|
|
151 |
// The PackageEntryTable is a Hashtable containing a list of all packages defined
|
|
152 |
// by a particular class loader. Each package is represented as a PackageEntry node.
|
|
153 |
// The PackageEntryTable's lookup is lock free.
|
|
154 |
//
|
|
155 |
class PackageEntryTable : public Hashtable<Symbol*, mtClass> {
|
|
156 |
friend class VMStructs;
|
|
157 |
public:
|
|
158 |
enum Constants {
|
|
159 |
_packagetable_entry_size = 1009 // number of entries in package entry table
|
|
160 |
};
|
|
161 |
|
|
162 |
private:
|
|
163 |
PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module);
|
|
164 |
void add_entry(int index, PackageEntry* new_entry);
|
|
165 |
|
|
166 |
int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
|
|
167 |
|
|
168 |
PackageEntry** bucket_addr(int i) {
|
|
169 |
return (PackageEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
|
|
170 |
}
|
|
171 |
|
|
172 |
static unsigned int compute_hash(Symbol* name) { return (unsigned int)(name->identity_hash()); }
|
|
173 |
int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); }
|
|
174 |
|
|
175 |
public:
|
|
176 |
PackageEntryTable(int table_size);
|
|
177 |
~PackageEntryTable();
|
|
178 |
|
|
179 |
PackageEntry* bucket(int i) {
|
|
180 |
return (PackageEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
|
|
181 |
}
|
|
182 |
|
|
183 |
// Create package in loader's package entry table and return the entry.
|
|
184 |
// If entry already exists, return null. Assume Module lock was taken by caller.
|
|
185 |
PackageEntry* locked_create_entry_or_null(Symbol* name, ModuleEntry* module);
|
|
186 |
|
|
187 |
// lookup Package with loader's package entry table, if not found add
|
|
188 |
PackageEntry* lookup(Symbol* name, ModuleEntry* module);
|
|
189 |
|
|
190 |
// Only lookup Package within loader's package entry table. The table read is lock-free.
|
|
191 |
PackageEntry* lookup_only(Symbol* Package);
|
|
192 |
|
|
193 |
void verify_javabase_packages(GrowableArray<Symbol*> *pkg_list);
|
|
194 |
|
|
195 |
// purge dead weak references out of exported list
|
|
196 |
void purge_all_package_exports();
|
|
197 |
|
|
198 |
void print() PRODUCT_RETURN;
|
|
199 |
void verify();
|
|
200 |
};
|
|
201 |
|
|
202 |
#endif // SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP
|