Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/cds/metaspaceShared.hpp
41144 views
1
/*
2
* Copyright (c) 2012, 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_CDS_METASPACESHARED_HPP
26
#define SHARE_CDS_METASPACESHARED_HPP
27
28
#include "memory/allocation.hpp"
29
#include "memory/memRegion.hpp"
30
#include "memory/virtualspace.hpp"
31
#include "oops/oop.hpp"
32
#include "utilities/macros.hpp"
33
#include "utilities/resourceHash.hpp"
34
35
class FileMapInfo;
36
class outputStream;
37
38
template<class E> class GrowableArray;
39
40
enum MapArchiveResult {
41
MAP_ARCHIVE_SUCCESS,
42
MAP_ARCHIVE_MMAP_FAILURE,
43
MAP_ARCHIVE_OTHER_FAILURE
44
};
45
46
// Class Data Sharing Support
47
class MetaspaceShared : AllStatic {
48
static ReservedSpace _symbol_rs; // used only during -Xshare:dump
49
static VirtualSpace _symbol_vs; // used only during -Xshare:dump
50
static bool _has_error_classes;
51
static bool _archive_loading_failed;
52
static bool _remapped_readwrite;
53
static void* _shared_metaspace_static_top;
54
static intx _relocation_delta;
55
static char* _requested_base_address;
56
static bool _use_optimized_module_handling;
57
static bool _use_full_module_graph;
58
public:
59
enum {
60
// core archive spaces
61
rw = 0, // read-write shared space in the heap
62
ro = 1, // read-only shared space in the heap
63
bm = 2, // relocation bitmaps (freed after file mapping is finished)
64
num_core_region = 2, // rw and ro
65
num_non_heap_spaces = 3, // rw and ro and bm
66
67
// mapped java heap regions
68
first_closed_archive_heap_region = bm + 1,
69
max_closed_archive_heap_region = 2,
70
last_closed_archive_heap_region = first_closed_archive_heap_region + max_closed_archive_heap_region - 1,
71
first_open_archive_heap_region = last_closed_archive_heap_region + 1,
72
max_open_archive_heap_region = 2,
73
last_open_archive_heap_region = first_open_archive_heap_region + max_open_archive_heap_region - 1,
74
75
last_valid_region = last_open_archive_heap_region,
76
n_regions = last_valid_region + 1 // total number of regions
77
};
78
79
static void prepare_for_dumping() NOT_CDS_RETURN;
80
static void preload_and_dump() NOT_CDS_RETURN;
81
82
private:
83
static void preload_and_dump_impl(TRAPS) NOT_CDS_RETURN;
84
static void preload_classes(TRAPS) NOT_CDS_RETURN;
85
static int parse_classlist(const char * classlist_path,
86
TRAPS) NOT_CDS_RETURN_(0);
87
88
89
public:
90
static Symbol* symbol_rs_base() {
91
return (Symbol*)_symbol_rs.base();
92
}
93
94
static void initialize_for_static_dump() NOT_CDS_RETURN;
95
static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
96
static void post_initialize(TRAPS) NOT_CDS_RETURN;
97
98
static void print_on(outputStream* st);
99
100
static void set_archive_loading_failed() {
101
_archive_loading_failed = true;
102
}
103
104
static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
105
static void initialize_shared_spaces() NOT_CDS_RETURN;
106
107
// Return true if given address is in the shared metaspace regions (i.e., excluding any
108
// mapped shared heap regions.)
109
static bool is_in_shared_metaspace(const void* p) {
110
return MetaspaceObj::is_shared((const MetaspaceObj*)p);
111
}
112
113
static address shared_metaspace_top() {
114
return (address)MetaspaceObj::shared_metaspace_top();
115
}
116
117
static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
118
119
// Return true if given address is in the shared region corresponding to the idx
120
static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
121
122
static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
123
124
static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
125
126
// JVM/TI RedefineClasses() support:
127
// Remap the shared readonly space to shared readwrite, private if
128
// sharing is enabled. Simply returns true if sharing is not enabled
129
// or if the remapping has already been done by a prior call.
130
static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
131
static bool remapped_readwrite() {
132
CDS_ONLY(return _remapped_readwrite);
133
NOT_CDS(return false);
134
}
135
136
static bool try_link_class(JavaThread* current, InstanceKlass* ik);
137
static void link_and_cleanup_shared_classes(TRAPS) NOT_CDS_RETURN;
138
static bool link_class_for_cds(InstanceKlass* ik, TRAPS) NOT_CDS_RETURN_(false);
139
static bool linking_required(InstanceKlass* ik) NOT_CDS_RETURN_(false);
140
141
#if INCLUDE_CDS
142
// Alignment for the 2 core CDS regions (RW/RO) only.
143
// (Heap region alignments are decided by GC).
144
static size_t core_region_alignment();
145
static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
146
// print loaded classes names to file.
147
static void dump_loaded_classes(const char* file_name, TRAPS);
148
#endif
149
150
// Allocate a block of memory from the temporary "symbol" region.
151
static char* symbol_space_alloc(size_t num_bytes);
152
153
// This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
154
// Both the base/top archives are written using this as their base address.
155
//
156
// During static dump: _requested_base_address == SharedBaseAddress.
157
//
158
// During dynamic dump: _requested_base_address is not always the same as SharedBaseAddress:
159
// - SharedBaseAddress is used for *reading the base archive*. I.e., CompactHashtable uses
160
// it to convert offsets to pointers to Symbols in the base archive.
161
// The base archive may be mapped to an OS-selected address due to ASLR. E.g.,
162
// you may have SharedBaseAddress == 0x00ff123400000000.
163
// - _requested_base_address is used for *writing the output archive*. It's usually
164
// 0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
165
static char* requested_base_address() {
166
return _requested_base_address;
167
}
168
169
// Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
170
static intx relocation_delta() { return _relocation_delta; }
171
172
static bool use_windows_memory_mapping() {
173
const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
174
//const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
175
return is_windows;
176
}
177
178
// Can we skip some expensive operations related to modules?
179
static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
180
static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
181
182
// Can we use the full archived modue graph?
183
static bool use_full_module_graph() NOT_CDS_RETURN_(false);
184
static void disable_full_module_graph() { _use_full_module_graph = false; }
185
186
private:
187
static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
188
static FileMapInfo* open_static_archive();
189
static FileMapInfo* open_dynamic_archive();
190
// use_requested_addr: If true (default), attempt to map at the address the
191
static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
192
bool use_requested_addr);
193
static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
194
FileMapInfo* dynamic_mapinfo,
195
bool use_archive_base_addr,
196
ReservedSpace& total_space_rs,
197
ReservedSpace& archive_space_rs,
198
ReservedSpace& class_space_rs);
199
static void release_reserved_spaces(ReservedSpace& total_space_rs,
200
ReservedSpace& archive_space_rs,
201
ReservedSpace& class_space_rs);
202
static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
203
static void unmap_archive(FileMapInfo* mapinfo);
204
};
205
#endif // SHARE_CDS_METASPACESHARED_HPP
206
207