168
169 // CDS support
170
171 // Note: _shared_rs and _symbol_rs are only used at dump time.
172 static ReservedSpace _shared_rs;
173 static VirtualSpace _shared_vs;
174 static ReservedSpace _symbol_rs;
175 static VirtualSpace _symbol_vs;
176 static int _max_alignment;
177 static MetaspaceSharedStats _stats;
178 static bool _has_error_classes;
179 static bool _archive_loading_failed;
180 static bool _remapped_readwrite;
181 static address _i2i_entry_code_buffers;
182 static size_t _i2i_entry_code_buffers_size;
183 static size_t _core_spaces_size;
184 static void* _shared_metaspace_static_top;
185 static intx _relocation_delta;
186 static char* _requested_base_address;
187 static bool _use_optimized_module_handling;
188 public:
189 enum {
190 // core archive spaces
191 mc = 0, // miscellaneous code for method trampolines
192 rw = 1, // read-write shared space in the heap
193 ro = 2, // read-only shared space in the heap
194 bm = 3, // relocation bitmaps (freed after file mapping is finished)
195 num_core_region = 3,
196 num_non_heap_spaces = 4,
197
198 // mapped java heap regions
199 first_closed_archive_heap_region = bm + 1,
200 max_closed_archive_heap_region = 2,
201 last_closed_archive_heap_region = first_closed_archive_heap_region + max_closed_archive_heap_region - 1,
202 first_open_archive_heap_region = last_closed_archive_heap_region + 1,
203 max_open_archive_heap_region = 2,
204 last_open_archive_heap_region = first_open_archive_heap_region + max_open_archive_heap_region - 1,
205
206 last_valid_region = last_open_archive_heap_region,
207 n_regions = last_valid_region + 1 // total number of regions
305 static void link_and_cleanup_shared_classes(TRAPS) NOT_CDS_RETURN;
306
307 #if INCLUDE_CDS
308 static size_t reserved_space_alignment();
309 static void init_shared_dump_space(DumpRegion* first_space);
310 static DumpRegion* misc_code_dump_space();
311 static DumpRegion* read_write_dump_space();
312 static DumpRegion* read_only_dump_space();
313 static void pack_dump_space(DumpRegion* current, DumpRegion* next,
314 ReservedSpace* rs);
315
316 static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
317 #endif
318
319 // Allocate a block of memory from the temporary "symbol" region.
320 static char* symbol_space_alloc(size_t num_bytes);
321
322 // Allocate a block of memory from the "mc" or "ro" regions.
323 static char* misc_code_space_alloc(size_t num_bytes);
324 static char* read_only_space_alloc(size_t num_bytes);
325
326 template <typename T>
327 static Array<T>* new_ro_array(int length) {
328 #if INCLUDE_CDS
329 size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
330 Array<T>* array = (Array<T>*)read_only_space_alloc(byte_size);
331 array->initialize(length);
332 return array;
333 #else
334 return NULL;
335 #endif
336 }
337
338 template <typename T>
339 static size_t ro_array_bytesize(int length) {
340 size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
341 return align_up(byte_size, BytesPerWord);
342 }
343
344 static address i2i_entry_code_buffers(size_t total_size);
345
346 static address i2i_entry_code_buffers() {
347 return _i2i_entry_code_buffers;
348 }
349 static size_t i2i_entry_code_buffers_size() {
350 return _i2i_entry_code_buffers_size;
351 }
352 static void relocate_klass_ptr(oop o);
353
354 static Klass* get_relocated_klass(Klass *k, bool is_final=false);
355
356 static void allocate_cloned_cpp_vtptrs();
357 static intptr_t* get_archived_cpp_vtable(MetaspaceObj::Type msotype, address obj);
358 static void initialize_ptr_marker(CHeapBitMap* ptrmap);
359
360 // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
361 // Both the base/top archives are written using this as their base address.
362 static char* requested_base_address() {
363 return _requested_base_address;
364 }
365
366 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
367 static intx relocation_delta() { return _relocation_delta; }
368 static intx final_delta();
369 static bool use_windows_memory_mapping() {
370 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
371 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
372 return is_windows;
373 }
374
375 static void write_core_archive_regions(FileMapInfo* mapinfo,
376 GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
377 GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps);
378
379 // Can we skip some expensive operations related to modules?
380 static bool use_optimized_module_handling() { return _use_optimized_module_handling; }
381 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
382
383 private:
384 #if INCLUDE_CDS
385 static void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
386 bool read_only, bool allow_exec);
387 #endif
388 static void read_extra_data(const char* filename, TRAPS) NOT_CDS_RETURN;
389 static FileMapInfo* open_static_archive();
390 static FileMapInfo* open_dynamic_archive();
391 // use_requested_addr: If true (default), attempt to map at the address the
392 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
393 bool use_requested_addr);
394 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
395 FileMapInfo* dynamic_mapinfo,
396 bool use_archive_base_addr,
397 ReservedSpace& archive_space_rs,
398 ReservedSpace& class_space_rs);
399 static void release_reserved_spaces(ReservedSpace& archive_space_rs,
400 ReservedSpace& class_space_rs);
401 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
|
168
169 // CDS support
170
171 // Note: _shared_rs and _symbol_rs are only used at dump time.
172 static ReservedSpace _shared_rs;
173 static VirtualSpace _shared_vs;
174 static ReservedSpace _symbol_rs;
175 static VirtualSpace _symbol_vs;
176 static int _max_alignment;
177 static MetaspaceSharedStats _stats;
178 static bool _has_error_classes;
179 static bool _archive_loading_failed;
180 static bool _remapped_readwrite;
181 static address _i2i_entry_code_buffers;
182 static size_t _i2i_entry_code_buffers_size;
183 static size_t _core_spaces_size;
184 static void* _shared_metaspace_static_top;
185 static intx _relocation_delta;
186 static char* _requested_base_address;
187 static bool _use_optimized_module_handling;
188 static bool _use_full_module_graph;
189 public:
190 enum {
191 // core archive spaces
192 mc = 0, // miscellaneous code for method trampolines
193 rw = 1, // read-write shared space in the heap
194 ro = 2, // read-only shared space in the heap
195 bm = 3, // relocation bitmaps (freed after file mapping is finished)
196 num_core_region = 3,
197 num_non_heap_spaces = 4,
198
199 // mapped java heap regions
200 first_closed_archive_heap_region = bm + 1,
201 max_closed_archive_heap_region = 2,
202 last_closed_archive_heap_region = first_closed_archive_heap_region + max_closed_archive_heap_region - 1,
203 first_open_archive_heap_region = last_closed_archive_heap_region + 1,
204 max_open_archive_heap_region = 2,
205 last_open_archive_heap_region = first_open_archive_heap_region + max_open_archive_heap_region - 1,
206
207 last_valid_region = last_open_archive_heap_region,
208 n_regions = last_valid_region + 1 // total number of regions
306 static void link_and_cleanup_shared_classes(TRAPS) NOT_CDS_RETURN;
307
308 #if INCLUDE_CDS
309 static size_t reserved_space_alignment();
310 static void init_shared_dump_space(DumpRegion* first_space);
311 static DumpRegion* misc_code_dump_space();
312 static DumpRegion* read_write_dump_space();
313 static DumpRegion* read_only_dump_space();
314 static void pack_dump_space(DumpRegion* current, DumpRegion* next,
315 ReservedSpace* rs);
316
317 static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
318 #endif
319
320 // Allocate a block of memory from the temporary "symbol" region.
321 static char* symbol_space_alloc(size_t num_bytes);
322
323 // Allocate a block of memory from the "mc" or "ro" regions.
324 static char* misc_code_space_alloc(size_t num_bytes);
325 static char* read_only_space_alloc(size_t num_bytes);
326 static char* read_write_space_alloc(size_t num_bytes);
327
328 template <typename T>
329 static Array<T>* new_ro_array(int length) {
330 size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
331 Array<T>* array = (Array<T>*)read_only_space_alloc(byte_size);
332 array->initialize(length);
333 return array;
334 }
335
336 template <typename T>
337 static Array<T>* new_rw_array(int length) {
338 size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
339 Array<T>* array = (Array<T>*)read_write_space_alloc(byte_size);
340 array->initialize(length);
341 return array;
342 }
343
344 template <typename T>
345 static size_t ro_array_bytesize(int length) {
346 size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
347 return align_up(byte_size, BytesPerWord);
348 }
349
350 static address i2i_entry_code_buffers(size_t total_size);
351
352 static address i2i_entry_code_buffers() {
353 return _i2i_entry_code_buffers;
354 }
355 static size_t i2i_entry_code_buffers_size() {
356 return _i2i_entry_code_buffers_size;
357 }
358 static void relocate_klass_ptr(oop o);
359
360 static Klass* get_relocated_klass(Klass *k, bool is_final=false);
361 static Symbol* get_relocated_symbol(Symbol* orig_symbol);
362
363 static void allocate_cloned_cpp_vtptrs();
364 static intptr_t* get_archived_cpp_vtable(MetaspaceObj::Type msotype, address obj);
365 static void initialize_ptr_marker(CHeapBitMap* ptrmap);
366
367 // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
368 // Both the base/top archives are written using this as their base address.
369 static char* requested_base_address() {
370 return _requested_base_address;
371 }
372
373 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
374 static intx relocation_delta() { return _relocation_delta; }
375 static intx final_delta();
376 static bool use_windows_memory_mapping() {
377 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
378 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
379 return is_windows;
380 }
381
382 static void write_core_archive_regions(FileMapInfo* mapinfo,
383 GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
384 GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps);
385
386 // Can we skip some expensive operations related to modules?
387 static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
388 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
389
390 // Can we use the full archived modue graph?
391 static bool use_full_module_graph() NOT_CDS_RETURN_(false);
392 static void disable_full_module_graph() { _use_full_module_graph = false; }
393
394 private:
395 #if INCLUDE_CDS
396 static void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
397 bool read_only, bool allow_exec);
398 #endif
399 static void read_extra_data(const char* filename, TRAPS) NOT_CDS_RETURN;
400 static FileMapInfo* open_static_archive();
401 static FileMapInfo* open_dynamic_archive();
402 // use_requested_addr: If true (default), attempt to map at the address the
403 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
404 bool use_requested_addr);
405 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
406 FileMapInfo* dynamic_mapinfo,
407 bool use_archive_base_addr,
408 ReservedSpace& archive_space_rs,
409 ReservedSpace& class_space_rs);
410 static void release_reserved_spaces(ReservedSpace& archive_space_rs,
411 ReservedSpace& class_space_rs);
412 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
|