32 #include "oops/oop.hpp"
33 #include "utilities/macros.hpp"
34
35 class ArchiveBuilder;
36 class ArchiveHeapInfo;
37 class FileMapInfo;
38 class Method;
39 class outputStream;
40 class SerializeClosure;
41 class StaticArchiveBuilder;
42
43 template<class E> class Array;
44 template<class E> class GrowableArray;
45
46 enum MapArchiveResult {
47 MAP_ARCHIVE_SUCCESS,
48 MAP_ARCHIVE_MMAP_FAILURE,
49 MAP_ARCHIVE_OTHER_FAILURE
50 };
51
52 // Class Data Sharing Support
53 class MetaspaceShared : AllStatic {
54 static ReservedSpace _symbol_rs; // used only during -Xshare:dump
55 static VirtualSpace _symbol_vs; // used only during -Xshare:dump
56 static bool _archive_loading_failed;
57 static bool _remapped_readwrite;
58 static void* _shared_metaspace_static_top;
59 static intx _relocation_delta;
60 static char* _requested_base_address;
61 static bool _use_optimized_module_handling;
62 static Array<Method*>* _archived_method_handle_intrinsics;
63
64 public:
65 enum {
66 // core archive spaces
67 rw = 0, // read-write shared space
68 ro = 1, // read-only shared space
69 bm = 2, // relocation bitmaps (freed after file mapping is finished)
70 hp = 3, // heap region
71 num_core_region = 2, // rw and ro
72 n_regions = 4 // total number of regions
73 };
74
75 static void prepare_for_dumping() NOT_CDS_RETURN;
76 static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
77 #ifdef _LP64
78 static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
79 #endif
80
81 private:
82 static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN;
83 static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
84 static void preload_classes(TRAPS) NOT_CDS_RETURN;
85
86 public:
87 static Symbol* symbol_rs_base() {
88 return (Symbol*)_symbol_rs.base();
89 }
90
91 static void initialize_for_static_dump() NOT_CDS_RETURN;
92 static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
93 static void post_initialize(TRAPS) NOT_CDS_RETURN;
94
95 static void print_on(outputStream* st);
96
97 static void set_archive_loading_failed() {
98 _archive_loading_failed = true;
99 }
100
101 static void initialize_shared_spaces() NOT_CDS_RETURN;
102
103 // Return true if given address is in the shared metaspace regions (i.e., excluding the
104 // mapped heap region.)
105 static bool is_in_shared_metaspace(const void* p) {
106 return MetaspaceObj::is_shared((const MetaspaceObj*)p);
107 }
108
109 static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
110
111 static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
112 static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
113
114 static void unrecoverable_loading_error(const char* message = nullptr);
115 static void unrecoverable_writing_error(const char* message = nullptr);
116 static void writing_error(const char* message = nullptr);
117
118 static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
119 static void write_method_handle_intrinsics() NOT_CDS_RETURN;
120 static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
121 static void early_serialize(SerializeClosure* sc) NOT_CDS_RETURN;
122 static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
123
124 // JVM/TI RedefineClasses() support:
125 // Remap the shared readonly space to shared readwrite, private if
126 // sharing is enabled. Simply returns true if sharing is not enabled
127 // or if the remapping has already been done by a prior call.
128 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
129 static bool remapped_readwrite() {
130 CDS_ONLY(return _remapped_readwrite);
131 NOT_CDS(return false);
132 }
133
134 static bool try_link_class(JavaThread* current, InstanceKlass* ik);
135 static void link_shared_classes(bool jcmd_request, TRAPS) NOT_CDS_RETURN;
136 static bool link_class_for_cds(InstanceKlass* ik, TRAPS) NOT_CDS_RETURN_(false);
137 static bool may_be_eagerly_linked(InstanceKlass* ik) NOT_CDS_RETURN_(false);
138
139 #if INCLUDE_CDS
140 // Alignment for the 2 core CDS regions (RW/RO) only.
141 // (Heap region alignments are decided by GC).
142 static size_t core_region_alignment();
143 static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
144 // print loaded classes names to file.
145 static void dump_loaded_classes(const char* file_name, TRAPS);
146 #endif
147
148 // Allocate a block of memory from the temporary "symbol" region.
149 static char* symbol_space_alloc(size_t num_bytes);
150
151 // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
152 // Both the base/top archives are written using this as their base address.
153 //
154 // During static dump: _requested_base_address == SharedBaseAddress.
155 //
156 // During dynamic dump: _requested_base_address is not always the same as SharedBaseAddress:
162 // 0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
163 static char* requested_base_address() {
164 return _requested_base_address;
165 }
166
167 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
168 static intx relocation_delta() { return _relocation_delta; }
169
170 static bool use_windows_memory_mapping() {
171 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
172 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
173 return is_windows;
174 }
175
176 // Can we skip some expensive operations related to modules?
177 static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
178 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
179
180 private:
181 static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
182 static bool write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info);
183 static FileMapInfo* open_static_archive();
184 static FileMapInfo* open_dynamic_archive();
185 // use_requested_addr: If true (default), attempt to map at the address the
186 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
187 bool use_requested_addr);
188 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
189 FileMapInfo* dynamic_mapinfo,
190 bool use_archive_base_addr,
191 ReservedSpace& total_space_rs,
192 ReservedSpace& archive_space_rs,
193 ReservedSpace& class_space_rs);
194 static void release_reserved_spaces(ReservedSpace& total_space_rs,
195 ReservedSpace& archive_space_rs,
196 ReservedSpace& class_space_rs);
197 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
198 static void unmap_archive(FileMapInfo* mapinfo);
199 static void get_default_classlist(char* default_classlist, const size_t buf_size);
200 };
201 #endif // SHARE_CDS_METASPACESHARED_HPP
|
32 #include "oops/oop.hpp"
33 #include "utilities/macros.hpp"
34
35 class ArchiveBuilder;
36 class ArchiveHeapInfo;
37 class FileMapInfo;
38 class Method;
39 class outputStream;
40 class SerializeClosure;
41 class StaticArchiveBuilder;
42
43 template<class E> class Array;
44 template<class E> class GrowableArray;
45
46 enum MapArchiveResult {
47 MAP_ARCHIVE_SUCCESS,
48 MAP_ARCHIVE_MMAP_FAILURE,
49 MAP_ARCHIVE_OTHER_FAILURE
50 };
51
52 class StaticArchiveBuilder;
53
54 // Class Data Sharing Support
55 class MetaspaceShared : AllStatic {
56 static ReservedSpace _symbol_rs; // used only during -Xshare:dump
57 static VirtualSpace _symbol_vs; // used only during -Xshare:dump
58 static bool _archive_loading_failed;
59 static bool _remapped_readwrite;
60 static void* _shared_metaspace_static_top;
61 static intx _relocation_delta;
62 static char* _requested_base_address;
63 static bool _use_optimized_module_handling;
64 static Array<Method*>* _archived_method_handle_intrinsics;
65 static int volatile _preimage_static_archive_dumped;
66
67 public:
68 enum {
69 // core archive spaces
70 rw = 0, // read-write shared space
71 ro = 1, // read-only shared space
72 bm = 2, // relocation bitmaps (freed after file mapping is finished)
73 hp = 3, // heap region
74 cc = 4, // cached code
75 num_core_region = 2, // rw and ro
76 n_regions = 5 // total number of regions
77 };
78
79 static void prepare_for_dumping() NOT_CDS_RETURN;
80 static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
81 #ifdef _LP64
82 static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
83 #endif
84
85 private:
86 static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN;
87 static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
88 static void preload_classes(TRAPS) NOT_CDS_RETURN;
89
90 public:
91 static Symbol* symbol_rs_base() {
92 return (Symbol*)_symbol_rs.base();
93 }
94
95 static void initialize_for_static_dump() NOT_CDS_RETURN;
96 static void open_static_archive() NOT_CDS_RETURN;
97 static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
98 static void post_initialize(TRAPS) NOT_CDS_RETURN;
99
100 static void print_on(outputStream* st);
101
102 static void set_archive_loading_failed() {
103 _archive_loading_failed = true;
104 }
105
106 static void initialize_shared_spaces() NOT_CDS_RETURN;
107
108 // Return true if given address is in the shared metaspace regions (i.e., excluding the
109 // mapped heap region.)
110 static bool is_in_shared_metaspace(const void* p) {
111 return MetaspaceObj::is_shared((const MetaspaceObj*)p);
112 }
113
114 static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
115
116 static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
117 static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
118
119 static bool is_recording_preimage_static_archive() NOT_CDS_RETURN_(false);
120
121 static void unrecoverable_loading_error(const char* message = nullptr);
122 static void unrecoverable_writing_error(const char* message = nullptr);
123 static void writing_error(const char* message = nullptr);
124
125 static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
126 static void write_method_handle_intrinsics() NOT_CDS_RETURN;
127 static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
128 static void early_serialize(SerializeClosure* sc) NOT_CDS_RETURN;
129 static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
130
131 // JVM/TI RedefineClasses() support:
132 // Remap the shared readonly space to shared readwrite, private if
133 // sharing is enabled. Simply returns true if sharing is not enabled
134 // or if the remapping has already been done by a prior call.
135 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
136 static bool remapped_readwrite() {
137 CDS_ONLY(return _remapped_readwrite);
138 NOT_CDS(return false);
139 }
140
141 static bool try_link_class(JavaThread* current, InstanceKlass* ik);
142 static void link_shared_classes(bool jcmd_request, TRAPS) NOT_CDS_RETURN;
143 static bool may_be_eagerly_linked(InstanceKlass* ik) NOT_CDS_RETURN_(false);
144
145 #if INCLUDE_CDS
146 // Alignment for the 2 core CDS regions (RW/RO) only.
147 // (Heap region alignments are decided by GC).
148 static size_t core_region_alignment();
149 static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
150 // print loaded classes names to file.
151 static void dump_loaded_classes(const char* file_name, TRAPS);
152 #endif
153
154 // Allocate a block of memory from the temporary "symbol" region.
155 static char* symbol_space_alloc(size_t num_bytes);
156
157 // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
158 // Both the base/top archives are written using this as their base address.
159 //
160 // During static dump: _requested_base_address == SharedBaseAddress.
161 //
162 // During dynamic dump: _requested_base_address is not always the same as SharedBaseAddress:
168 // 0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
169 static char* requested_base_address() {
170 return _requested_base_address;
171 }
172
173 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
174 static intx relocation_delta() { return _relocation_delta; }
175
176 static bool use_windows_memory_mapping() {
177 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
178 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
179 return is_windows;
180 }
181
182 // Can we skip some expensive operations related to modules?
183 static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
184 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
185
186 private:
187 static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
188 static void fork_and_dump_final_static_archive();
189 static bool write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info);
190 static FileMapInfo* open_dynamic_archive();
191 // use_requested_addr: If true (default), attempt to map at the address the
192 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
193 bool use_requested_addr);
194 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
195 FileMapInfo* dynamic_mapinfo,
196 bool use_archive_base_addr,
197 ReservedSpace& total_space_rs,
198 ReservedSpace& archive_space_rs,
199 ReservedSpace& class_space_rs);
200 static void release_reserved_spaces(ReservedSpace& total_space_rs,
201 ReservedSpace& archive_space_rs,
202 ReservedSpace& class_space_rs);
203 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
204 static void unmap_archive(FileMapInfo* mapinfo);
205 static void get_default_classlist(char* default_classlist, const size_t buf_size);
206 };
207 #endif // SHARE_CDS_METASPACESHARED_HPP
|