35 #include "utilities/resourceHash.hpp" |
35 #include "utilities/resourceHash.hpp" |
36 |
36 |
37 #define MAX_SHARED_DELTA (0x7FFFFFFF) |
37 #define MAX_SHARED_DELTA (0x7FFFFFFF) |
38 |
38 |
39 class FileMapInfo; |
39 class FileMapInfo; |
|
40 class CHeapBitMap; |
|
41 |
|
42 enum MapArchiveResult { |
|
43 MAP_ARCHIVE_SUCCESS, |
|
44 MAP_ARCHIVE_MMAP_FAILURE, |
|
45 MAP_ARCHIVE_OTHER_FAILURE |
|
46 }; |
40 |
47 |
41 class MetaspaceSharedStats { |
48 class MetaspaceSharedStats { |
42 public: |
49 public: |
43 MetaspaceSharedStats() { |
50 MetaspaceSharedStats() { |
44 memset(this, 0, sizeof(*this)); |
51 memset(this, 0, sizeof(*this)); |
60 DumpRegion(const char* name) : _name(name), _base(NULL), _top(NULL), _end(NULL), _is_packed(false) {} |
67 DumpRegion(const char* name) : _name(name), _base(NULL), _top(NULL), _end(NULL), _is_packed(false) {} |
61 |
68 |
62 char* expand_top_to(char* newtop); |
69 char* expand_top_to(char* newtop); |
63 char* allocate(size_t num_bytes, size_t alignment=BytesPerWord); |
70 char* allocate(size_t num_bytes, size_t alignment=BytesPerWord); |
64 |
71 |
65 void append_intptr_t(intptr_t n) { |
72 void append_intptr_t(intptr_t n, bool need_to_mark = false); |
66 assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment"); |
|
67 intptr_t *p = (intptr_t*)_top; |
|
68 char* newtop = _top + sizeof(intptr_t); |
|
69 expand_top_to(newtop); |
|
70 *p = n; |
|
71 } |
|
72 |
73 |
73 char* base() const { return _base; } |
74 char* base() const { return _base; } |
74 char* top() const { return _top; } |
75 char* top() const { return _top; } |
75 char* end() const { return _end; } |
76 char* end() const { return _end; } |
76 size_t reserved() const { return _end - _base; } |
77 size_t reserved() const { return _end - _base; } |
115 WriteClosure(DumpRegion* r) { |
116 WriteClosure(DumpRegion* r) { |
116 _dump_region = r; |
117 _dump_region = r; |
117 } |
118 } |
118 |
119 |
119 void do_ptr(void** p) { |
120 void do_ptr(void** p) { |
120 _dump_region->append_intptr_t((intptr_t)*p); |
121 _dump_region->append_intptr_t((intptr_t)*p, true); |
121 } |
122 } |
122 |
123 |
123 void do_u4(u4* p) { |
124 void do_u4(u4* p) { |
124 void* ptr = (void*)(uintx(*p)); |
125 _dump_region->append_intptr_t((intptr_t)(*p)); |
125 do_ptr(&ptr); |
|
126 } |
126 } |
127 |
127 |
128 void do_bool(bool *p) { |
128 void do_bool(bool *p) { |
129 void* ptr = (void*)(uintx(*p)); |
129 _dump_region->append_intptr_t((intptr_t)(*p)); |
130 do_ptr(&ptr); |
|
131 } |
130 } |
132 |
131 |
133 void do_tag(int tag) { |
132 void do_tag(int tag) { |
134 _dump_region->append_intptr_t((intptr_t)tag); |
133 _dump_region->append_intptr_t((intptr_t)tag); |
135 } |
134 } |
185 static bool _remapped_readwrite; |
184 static bool _remapped_readwrite; |
186 static address _i2i_entry_code_buffers; |
185 static address _i2i_entry_code_buffers; |
187 static size_t _i2i_entry_code_buffers_size; |
186 static size_t _i2i_entry_code_buffers_size; |
188 static size_t _core_spaces_size; |
187 static size_t _core_spaces_size; |
189 static void* _shared_metaspace_static_top; |
188 static void* _shared_metaspace_static_top; |
|
189 static intx _relocation_delta; |
190 public: |
190 public: |
191 enum { |
191 enum { |
192 // core archive spaces |
192 // core archive spaces |
193 mc = 0, // miscellaneous code for method trampolines |
193 mc = 0, // miscellaneous code for method trampolines |
194 rw = 1, // read-write shared space in the heap |
194 rw = 1, // read-write shared space in the heap |
195 ro = 2, // read-only shared space in the heap |
195 ro = 2, // read-only shared space in the heap |
196 md = 3, // miscellaneous data for initializing tables, etc. |
196 md = 3, // miscellaneous data for initializing tables, etc. |
197 num_core_spaces = 4, // number of non-string regions |
197 bm = 4, // relocation bitmaps (freed after file mapping is finished) |
198 num_non_heap_spaces = 4, |
198 num_core_region = 4, |
|
199 num_non_heap_spaces = 5, |
199 |
200 |
200 // mapped java heap regions |
201 // mapped java heap regions |
201 first_closed_archive_heap_region = md + 1, |
202 first_closed_archive_heap_region = bm + 1, |
202 max_closed_archive_heap_region = 2, |
203 max_closed_archive_heap_region = 2, |
203 last_closed_archive_heap_region = first_closed_archive_heap_region + max_closed_archive_heap_region - 1, |
204 last_closed_archive_heap_region = first_closed_archive_heap_region + max_closed_archive_heap_region - 1, |
204 first_open_archive_heap_region = last_closed_archive_heap_region + 1, |
205 first_open_archive_heap_region = last_closed_archive_heap_region + 1, |
205 max_open_archive_heap_region = 2, |
206 max_open_archive_heap_region = 2, |
206 last_open_archive_heap_region = first_open_archive_heap_region + max_open_archive_heap_region - 1, |
207 last_open_archive_heap_region = first_open_archive_heap_region + max_open_archive_heap_region - 1, |
218 |
219 |
219 static ReservedSpace* shared_rs() { |
220 static ReservedSpace* shared_rs() { |
220 CDS_ONLY(return &_shared_rs); |
221 CDS_ONLY(return &_shared_rs); |
221 NOT_CDS(return NULL); |
222 NOT_CDS(return NULL); |
222 } |
223 } |
|
224 |
|
225 static void set_shared_rs(ReservedSpace rs) { |
|
226 CDS_ONLY(_shared_rs = rs); |
|
227 } |
|
228 |
223 static void commit_shared_space_to(char* newtop) NOT_CDS_RETURN; |
229 static void commit_shared_space_to(char* newtop) NOT_CDS_RETURN; |
224 static size_t core_spaces_size() { |
|
225 assert(DumpSharedSpaces || UseSharedSpaces, "sanity"); |
|
226 assert(_core_spaces_size != 0, "sanity"); |
|
227 return _core_spaces_size; |
|
228 } |
|
229 static void initialize_dumptime_shared_and_meta_spaces() NOT_CDS_RETURN; |
230 static void initialize_dumptime_shared_and_meta_spaces() NOT_CDS_RETURN; |
230 static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN; |
231 static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN; |
231 static char* initialize_dynamic_runtime_shared_spaces( |
|
232 char* static_start, char* static_end) NOT_CDS_RETURN_(NULL); |
|
233 static void post_initialize(TRAPS) NOT_CDS_RETURN; |
232 static void post_initialize(TRAPS) NOT_CDS_RETURN; |
234 |
233 |
235 // Delta of this object from SharedBaseAddress |
234 // Delta of this object from SharedBaseAddress |
236 static uintx object_delta_uintx(void* obj); |
235 static uintx object_delta_uintx(void* obj); |
237 |
236 |
243 } |
242 } |
244 |
243 |
245 static void set_archive_loading_failed() { |
244 static void set_archive_loading_failed() { |
246 _archive_loading_failed = true; |
245 _archive_loading_failed = true; |
247 } |
246 } |
|
247 static bool is_in_output_space(void* ptr) { |
|
248 assert(DumpSharedSpaces, "must be"); |
|
249 return shared_rs()->contains(ptr); |
|
250 } |
|
251 |
248 static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false); |
252 static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false); |
249 static void initialize_shared_spaces() NOT_CDS_RETURN; |
253 static void initialize_shared_spaces() NOT_CDS_RETURN; |
250 |
254 |
251 // Return true if given address is in the shared metaspace regions (i.e., excluding any |
255 // Return true if given address is in the shared metaspace regions (i.e., excluding any |
252 // mapped shared heap regions.) |
256 // mapped shared heap regions.) |
253 static bool is_in_shared_metaspace(const void* p) { |
257 static bool is_in_shared_metaspace(const void* p) { |
254 // If no shared metaspace regions are mapped, MetaspceObj::_shared_metaspace_{base,top} will |
258 return MetaspaceObj::is_shared((const MetaspaceObj*)p); |
255 // both be NULL and all values of p will be rejected quickly. |
|
256 return (p < MetaspaceObj::shared_metaspace_top() && p >= MetaspaceObj::shared_metaspace_base()); |
|
257 } |
259 } |
258 |
260 |
259 static address shared_metaspace_top() { |
261 static address shared_metaspace_top() { |
260 return (address)MetaspaceObj::shared_metaspace_top(); |
262 return (address)MetaspaceObj::shared_metaspace_top(); |
261 } |
263 } |
262 |
264 |
263 static void set_shared_metaspace_range(void* base, void* top) NOT_CDS_RETURN; |
265 static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN; |
264 |
266 |
265 // Return true if given address is in the shared region corresponding to the idx |
267 // Return true if given address is in the shared region corresponding to the idx |
266 static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
268 static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
267 |
269 |
268 static bool is_in_trampoline_frame(address addr) NOT_CDS_RETURN_(false); |
270 static bool is_in_trampoline_frame(address addr) NOT_CDS_RETURN_(false); |
296 |
298 |
297 static bool try_link_class(InstanceKlass* ik, TRAPS); |
299 static bool try_link_class(InstanceKlass* ik, TRAPS); |
298 static void link_and_cleanup_shared_classes(TRAPS); |
300 static void link_and_cleanup_shared_classes(TRAPS); |
299 |
301 |
300 #if INCLUDE_CDS |
302 #if INCLUDE_CDS |
301 static ReservedSpace* reserve_shared_rs(size_t size, size_t alignment, |
303 static ReservedSpace reserve_shared_space(size_t size, char* requested_address = NULL); |
302 bool large, char* requested_address); |
304 static size_t reserved_space_alignment(); |
303 static void init_shared_dump_space(DumpRegion* first_space, address first_space_bottom = NULL); |
305 static void init_shared_dump_space(DumpRegion* first_space, address first_space_bottom = NULL); |
304 static DumpRegion* misc_code_dump_space(); |
306 static DumpRegion* misc_code_dump_space(); |
305 static DumpRegion* read_write_dump_space(); |
307 static DumpRegion* read_write_dump_space(); |
306 static DumpRegion* read_only_dump_space(); |
308 static DumpRegion* read_only_dump_space(); |
307 static void pack_dump_space(DumpRegion* current, DumpRegion* next, |
309 static void pack_dump_space(DumpRegion* current, DumpRegion* next, |
340 static size_t i2i_entry_code_buffers_size() { |
342 static size_t i2i_entry_code_buffers_size() { |
341 return _i2i_entry_code_buffers_size; |
343 return _i2i_entry_code_buffers_size; |
342 } |
344 } |
343 static void relocate_klass_ptr(oop o); |
345 static void relocate_klass_ptr(oop o); |
344 |
346 |
345 static Klass* get_relocated_klass(Klass *k); |
347 static Klass* get_relocated_klass(Klass *k, bool is_final=false); |
346 |
348 |
347 static intptr_t* fix_cpp_vtable_for_dynamic_archive(MetaspaceObj::Type msotype, address obj); |
349 static intptr_t* fix_cpp_vtable_for_dynamic_archive(MetaspaceObj::Type msotype, address obj); |
348 |
350 static void initialize_ptr_marker(CHeapBitMap* ptrmap); |
|
351 |
|
352 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR. |
|
353 static intx relocation_delta() { return _relocation_delta; } |
|
354 static intx final_delta(); |
|
355 static bool use_windows_memory_mapping() { |
|
356 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true)); |
|
357 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc. |
|
358 return is_windows; |
|
359 } |
349 private: |
360 private: |
350 static void read_extra_data(const char* filename, TRAPS) NOT_CDS_RETURN; |
361 static void read_extra_data(const char* filename, TRAPS) NOT_CDS_RETURN; |
|
362 static FileMapInfo* open_static_archive(); |
|
363 static FileMapInfo* open_dynamic_archive(); |
|
364 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo, |
|
365 bool use_requested_addr); |
|
366 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo, |
|
367 FileMapInfo* dynamic_mapinfo, |
|
368 bool use_requested_addr, |
|
369 ReservedSpace& main_rs, |
|
370 ReservedSpace& archive_space_rs, |
|
371 ReservedSpace& class_space_rs); |
|
372 static void release_reserved_spaces(ReservedSpace& main_rs, |
|
373 ReservedSpace& archive_space_rs, |
|
374 ReservedSpace& class_space_rs); |
|
375 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs); |
|
376 static void unmap_archive(FileMapInfo* mapinfo); |
351 }; |
377 }; |
352 #endif // SHARE_MEMORY_METASPACESHARED_HPP |
378 #endif // SHARE_MEMORY_METASPACESHARED_HPP |