32 #include "oops/oop.hpp"
33 #include "utilities/macros.hpp"
34
35 class ArchiveBuilder;
36 class ArchiveMappedHeapInfo;
37 class ArchiveStreamedHeapInfo;
38 class FileMapInfo;
39 class Method;
40 class outputStream;
41 class SerializeClosure;
42 class StaticArchiveBuilder;
43
44 template<class E> class Array;
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 AOTMetaspace : 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* _aot_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
68 ro = 1, // read-only
69 bm = 2, // relocation bitmaps (freed after file mapping is finished)
70 hp = 3, // heap region
71 ac = 4, // aot code
72 num_core_region = 2, // rw and ro
73 n_regions = 5 // total number of regions
74 };
75
76 static void dump_static_archive(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 dump_static_archive_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
84 static void load_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 in_aot_cache(const void* p) {
106 return MetaspaceObj::in_aot_cache((const MetaspaceObj*)p);
107 }
108
109 static void set_aot_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
110
111 // inside the metaspace of the AOT cache, or the static CDS archive
112 static bool in_aot_cache_static_region(void* p) NOT_CDS_RETURN_(false);
113
114 // inside the metaspace of the dynamic static CDS archive
115 static bool in_aot_cache_dynamic_region(void* p) NOT_CDS_RETURN_(false);
116
117 static void unrecoverable_loading_error(const char* message = "unrecoverable error");
118 static void report_loading_error(const char* format, ...) ATTRIBUTE_PRINTF(1, 0);
119 static void unrecoverable_writing_error(const char* message = nullptr);
120 static void writing_error(const char* message = nullptr);
121
122 static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
123 static void write_method_handle_intrinsics() NOT_CDS_RETURN;
124 static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
125 static void early_serialize(SerializeClosure* sc) NOT_CDS_RETURN;
126 static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
127
128 // JVM/TI RedefineClasses() support:
129 // Remap the shared readonly space to shared readwrite, private if
130 // sharing is enabled. Simply returns true if sharing is not enabled
131 // or if the remapping has already been done by a prior call.
132 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
133 static bool remapped_readwrite() {
134 CDS_ONLY(return _remapped_readwrite);
135 NOT_CDS(return false);
136 }
172 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
173 static intx relocation_delta() { return _relocation_delta; }
174
175 static bool use_windows_memory_mapping() {
176 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
177 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
178 return is_windows;
179 }
180
181 // Can we skip some expensive operations related to modules?
182 static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
183 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
184
185 private:
186 static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
187 static void fork_and_dump_final_static_archive(TRAPS);
188 static bool write_static_archive(ArchiveBuilder* builder,
189 FileMapInfo* map_info,
190 ArchiveMappedHeapInfo* mapped_heap_info,
191 ArchiveStreamedHeapInfo* streamed_heap_info);
192 static FileMapInfo* open_static_archive();
193 static FileMapInfo* open_dynamic_archive();
194 // use_requested_addr: If true (default), attempt to map at the address the
195 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
196 bool use_requested_addr);
197 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
198 FileMapInfo* dynamic_mapinfo,
199 bool use_archive_base_addr,
200 ReservedSpace& total_space_rs,
201 ReservedSpace& archive_space_rs,
202 ReservedSpace& class_space_rs);
203 static void release_reserved_spaces(ReservedSpace& total_space_rs,
204 ReservedSpace& archive_space_rs,
205 ReservedSpace& class_space_rs);
206 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
207 static void unmap_archive(FileMapInfo* mapinfo);
208 static void get_default_classlist(char* default_classlist, const size_t buf_size);
209 };
210 #endif // SHARE_CDS_AOTMETASPACE_HPP
|
32 #include "oops/oop.hpp"
33 #include "utilities/macros.hpp"
34
35 class ArchiveBuilder;
36 class ArchiveMappedHeapInfo;
37 class ArchiveStreamedHeapInfo;
38 class FileMapInfo;
39 class Method;
40 class outputStream;
41 class SerializeClosure;
42 class StaticArchiveBuilder;
43
44 template<class E> class Array;
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 AOTMetaspace : 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* _aot_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 static jlong _preimage_static_archive_recording_duration;
67
68 public:
69 enum {
70 // core archive spaces
71 rw = 0, // read-write
72 ro = 1, // read-only
73 bm = 2, // relocation bitmaps (freed after file mapping is finished)
74 hp = 3, // heap region
75 ac = 4, // aot code
76 num_core_region = 2, // rw and ro
77 n_regions = 5 // total number of regions
78 };
79
80 static void dump_static_archive(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 dump_static_archive_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
88 static void load_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 in_aot_cache(const void* p) {
111 return MetaspaceObj::in_aot_cache((const MetaspaceObj*)p);
112 }
113
114 static void set_aot_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
115
116 // inside the metaspace of the AOT cache, or the static CDS archive
117 static bool in_aot_cache_static_region(void* p) NOT_CDS_RETURN_(false);
118
119 // inside the metaspace of the dynamic static CDS archive
120 static bool in_aot_cache_dynamic_region(void* p) NOT_CDS_RETURN_(false);
121
122 static bool is_recording_preimage_static_archive() NOT_CDS_RETURN_(false);
123 static jlong get_preimage_static_archive_recording_duration() NOT_CDS_RETURN_(0);
124
125 static void unrecoverable_loading_error(const char* message = "unrecoverable error");
126 static void report_loading_error(const char* format, ...) ATTRIBUTE_PRINTF(1, 0);
127 static void unrecoverable_writing_error(const char* message = nullptr);
128 static void writing_error(const char* message = nullptr);
129
130 static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
131 static void write_method_handle_intrinsics() NOT_CDS_RETURN;
132 static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
133 static void early_serialize(SerializeClosure* sc) NOT_CDS_RETURN;
134 static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
135
136 // JVM/TI RedefineClasses() support:
137 // Remap the shared readonly space to shared readwrite, private if
138 // sharing is enabled. Simply returns true if sharing is not enabled
139 // or if the remapping has already been done by a prior call.
140 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
141 static bool remapped_readwrite() {
142 CDS_ONLY(return _remapped_readwrite);
143 NOT_CDS(return false);
144 }
180 // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
181 static intx relocation_delta() { return _relocation_delta; }
182
183 static bool use_windows_memory_mapping() {
184 const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
185 //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
186 return is_windows;
187 }
188
189 // Can we skip some expensive operations related to modules?
190 static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
191 static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
192
193 private:
194 static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
195 static void fork_and_dump_final_static_archive(TRAPS);
196 static bool write_static_archive(ArchiveBuilder* builder,
197 FileMapInfo* map_info,
198 ArchiveMappedHeapInfo* mapped_heap_info,
199 ArchiveStreamedHeapInfo* streamed_heap_info);
200 static FileMapInfo* open_dynamic_archive();
201 // use_requested_addr: If true (default), attempt to map at the address the
202 static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
203 bool use_requested_addr);
204 static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
205 FileMapInfo* dynamic_mapinfo,
206 bool use_archive_base_addr,
207 ReservedSpace& total_space_rs,
208 ReservedSpace& archive_space_rs,
209 ReservedSpace& class_space_rs);
210 static void release_reserved_spaces(ReservedSpace& total_space_rs,
211 ReservedSpace& archive_space_rs,
212 ReservedSpace& class_space_rs);
213 static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
214 static void unmap_archive(FileMapInfo* mapinfo);
215 static void get_default_classlist(char* default_classlist, const size_t buf_size);
216 };
217 #endif // SHARE_CDS_AOTMETASPACE_HPP
|