Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/classfile/moduleEntry.hpp
40949 views
1
/*
2
* Copyright (c) 2016, 2021, 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_CLASSFILE_MODULEENTRY_HPP
26
#define SHARE_CLASSFILE_MODULEENTRY_HPP
27
28
#include "jni.h"
29
#include "oops/oopHandle.hpp"
30
#include "oops/symbol.hpp"
31
#include "runtime/mutexLocker.hpp"
32
#include "utilities/growableArray.hpp"
33
#include "utilities/hashtable.hpp"
34
#include "utilities/macros.hpp"
35
#include "utilities/ostream.hpp"
36
#if INCLUDE_JFR
37
#include "jfr/support/jfrTraceIdExtension.hpp"
38
#endif
39
40
#define UNNAMED_MODULE "unnamed module"
41
#define UNNAMED_MODULE_LEN 14
42
#define JAVAPKG "java"
43
#define JAVAPKG_LEN 4
44
#define JAVA_BASE_NAME "java.base"
45
#define JAVA_BASE_NAME_LEN 9
46
47
template <class T> class Array;
48
class ClassLoaderData;
49
class MetaspaceClosure;
50
class ModuleClosure;
51
52
// A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
53
// It contains:
54
// - Symbol* containing the module's name.
55
// - pointer to the java.lang.Module for this module.
56
// - pointer to the java.security.ProtectionDomain shared by classes defined to this module.
57
// - ClassLoaderData*, class loader of this module.
58
// - a growable array containg other module entries that this module can read.
59
// - a flag indicating if this module can read all unnamed modules.
60
//
61
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
62
// data structure.
63
class ModuleEntry : public HashtableEntry<Symbol*, mtModule> {
64
private:
65
OopHandle _module; // java.lang.Module
66
OopHandle _shared_pd; // java.security.ProtectionDomain, cached
67
// for shared classes from this module
68
ClassLoaderData* _loader_data;
69
GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
70
Symbol* _version; // module version number
71
Symbol* _location; // module location
72
CDS_ONLY(int _shared_path_index;) // >=0 if classes in this module are in CDS archive
73
bool _can_read_all_unnamed;
74
bool _has_default_read_edges; // JVMTI redefine/retransform support
75
bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules
76
bool _is_open; // whether the packages in the module are all unqualifiedly exported
77
bool _is_patched; // whether the module is patched via --patch-module
78
CDS_JAVA_HEAP_ONLY(int _archived_module_index;)
79
80
JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
81
enum {MODULE_READS_SIZE = 101}; // Initial size of list of modules that the module can read.
82
83
public:
84
void init() {
85
_module = OopHandle();
86
_shared_pd = OopHandle();
87
_loader_data = NULL;
88
_reads = NULL;
89
_version = NULL;
90
_location = NULL;
91
_can_read_all_unnamed = false;
92
_has_default_read_edges = false;
93
_must_walk_reads = false;
94
_is_patched = false;
95
_is_open = false;
96
CDS_ONLY(_shared_path_index = -1);
97
}
98
99
Symbol* name() const { return literal(); }
100
void set_name(Symbol* n) { set_literal(n); }
101
102
oop module() const;
103
OopHandle module_handle() const { return _module; }
104
void set_module(OopHandle j) { _module = j; }
105
106
// The shared ProtectionDomain reference is set once the VM loads a shared class
107
// originated from the current Module. The referenced ProtectionDomain object is
108
// created by the ClassLoader when loading a class (shared or non-shared) from the
109
// Module for the first time. This ProtectionDomain object is used for all
110
// classes from the Module loaded by the same ClassLoader.
111
oop shared_protection_domain();
112
void set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
113
114
ClassLoaderData* loader_data() const { return _loader_data; }
115
void set_loader_data(ClassLoaderData* cld);
116
117
Symbol* version() const { return _version; }
118
void set_version(Symbol* version);
119
120
Symbol* location() const { return _location; }
121
void set_location(Symbol* location);
122
bool should_show_version();
123
124
bool can_read(ModuleEntry* m) const;
125
bool has_reads_list() const;
126
void add_read(ModuleEntry* m);
127
void set_read_walk_required(ClassLoaderData* m_loader_data);
128
129
bool is_open() const { return _is_open; }
130
void set_is_open(bool is_open);
131
132
bool is_named() const { return (name() != NULL); }
133
134
bool can_read_all_unnamed() const {
135
assert(is_named() || _can_read_all_unnamed == true,
136
"unnamed modules can always read all unnamed modules");
137
return _can_read_all_unnamed;
138
}
139
140
// Modules can only go from strict to loose.
141
void set_can_read_all_unnamed() { _can_read_all_unnamed = true; }
142
143
bool has_default_read_edges() const {
144
return _has_default_read_edges;
145
}
146
147
// Sets true and returns the previous value.
148
bool set_has_default_read_edges() {
149
MutexLocker ml(Module_lock);
150
bool prev = _has_default_read_edges;
151
_has_default_read_edges = true;
152
return prev;
153
}
154
155
void set_is_patched() {
156
_is_patched = true;
157
CDS_ONLY(_shared_path_index = -1); // Mark all shared classes in this module invisible.
158
}
159
bool is_patched() {
160
return _is_patched;
161
}
162
163
ModuleEntry* next() const {
164
return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next();
165
}
166
ModuleEntry** next_addr() {
167
return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
168
}
169
170
// iteration support for readability
171
void module_reads_do(ModuleClosure* const f);
172
173
// Purge dead weak references out of reads list when any given class loader is unloaded.
174
void purge_reads();
175
void delete_reads();
176
177
// Special handling for unnamed module, one per class loader
178
static ModuleEntry* create_unnamed_module(ClassLoaderData* cld);
179
static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld);
180
static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld);
181
void delete_unnamed_module();
182
183
void print(outputStream* st = tty);
184
void verify();
185
186
CDS_ONLY(int shared_path_index() { return _shared_path_index;})
187
188
JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
189
190
#if INCLUDE_CDS_JAVA_HEAP
191
void iterate_symbols(MetaspaceClosure* closure);
192
ModuleEntry* allocate_archived_entry() const;
193
void init_as_archived_entry();
194
void init_archived_oops();
195
static ModuleEntry* get_archived_entry(ModuleEntry* orig_entry);
196
static Array<ModuleEntry*>* write_growable_array(GrowableArray<ModuleEntry*>* array);
197
static GrowableArray<ModuleEntry*>* restore_growable_array(Array<ModuleEntry*>* archived_array);
198
void load_from_archive(ClassLoaderData* loader_data);
199
void restore_archived_oops(ClassLoaderData* loader_data);
200
void clear_archived_oops();
201
#endif
202
};
203
204
// Iterator interface
205
class ModuleClosure: public StackObj {
206
public:
207
virtual void do_module(ModuleEntry* module) = 0;
208
};
209
210
211
// The ModuleEntryTable is a Hashtable containing a list of all modules defined
212
// by a particular class loader. Each module is represented as a ModuleEntry node.
213
//
214
// Each ModuleEntryTable contains a _javabase_module field which allows for the
215
// creation of java.base's ModuleEntry very early in bootstrapping before the
216
// corresponding JVM_DefineModule call for java.base occurs during module system
217
// initialization. Setting up java.base's ModuleEntry early enables classes,
218
// loaded prior to the module system being initialized to be created with their
219
// PackageEntry node's correctly pointing at java.base's ModuleEntry. No class
220
// outside of java.base is allowed to be loaded pre-module system initialization.
221
//
222
// The ModuleEntryTable's lookup is lock free.
223
//
224
class ModuleEntryTable : public Hashtable<Symbol*, mtModule> {
225
friend class VMStructs;
226
public:
227
enum Constants {
228
_moduletable_entry_size = 109 // number of entries in module entry table
229
};
230
231
private:
232
static ModuleEntry* _javabase_module;
233
234
ModuleEntry* new_entry(unsigned int hash, Handle module_handle, bool is_open,
235
Symbol* name, Symbol* version, Symbol* location, ClassLoaderData* loader_data);
236
void add_entry(int index, ModuleEntry* new_entry);
237
238
int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
239
240
ModuleEntry** bucket_addr(int i) {
241
return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
242
}
243
244
static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
245
int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); }
246
247
public:
248
ModuleEntryTable(int table_size);
249
~ModuleEntryTable();
250
251
ModuleEntry* bucket(int i) {
252
return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
253
}
254
255
// Create module in loader's module entry table. Assume Module_lock
256
// has been locked by caller.
257
ModuleEntry* locked_create_entry(Handle module_handle,
258
bool is_open,
259
Symbol* module_name,
260
Symbol* module_version,
261
Symbol* module_location,
262
ClassLoaderData* loader_data);
263
264
// Only lookup module within loader's module entry table. The table read is lock-free.
265
ModuleEntry* lookup_only(Symbol* name);
266
267
// purge dead weak references out of reads list
268
void purge_all_module_reads();
269
270
// Special handling for java.base
271
static ModuleEntry* javabase_moduleEntry() { return _javabase_module; }
272
static void set_javabase_moduleEntry(ModuleEntry* java_base) {
273
assert(_javabase_module == NULL, "_javabase_module is already defined");
274
_javabase_module = java_base;
275
}
276
277
static bool javabase_defined() { return ((_javabase_module != NULL) &&
278
(_javabase_module->module() != NULL)); }
279
static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
280
static void patch_javabase_entries(Handle module_handle);
281
282
void print(outputStream* st = tty);
283
void verify();
284
285
#if INCLUDE_CDS_JAVA_HEAP
286
void iterate_symbols(MetaspaceClosure* closure);
287
Array<ModuleEntry*>* allocate_archived_entries();
288
void init_archived_entries(Array<ModuleEntry*>* archived_modules);
289
void init_archived_oops(Array<ModuleEntry*>* archived_modules);
290
void load_archived_entries(ClassLoaderData* loader_data,
291
Array<ModuleEntry*>* archived_modules);
292
void restore_archived_oops(ClassLoaderData* loader_data,
293
Array<ModuleEntry*>* archived_modules);
294
#endif
295
};
296
297
#endif // SHARE_CLASSFILE_MODULEENTRY_HPP
298
299