91 struct ArchiveHeapOopmapInfo { |
91 struct ArchiveHeapOopmapInfo { |
92 address _oopmap; // bitmap for relocating embedded oops |
92 address _oopmap; // bitmap for relocating embedded oops |
93 size_t _oopmap_size_in_bits; |
93 size_t _oopmap_size_in_bits; |
94 }; |
94 }; |
95 |
95 |
|
96 class SharedPathTable { |
|
97 Array<u8>* _table; |
|
98 int _size; |
|
99 public: |
|
100 void dumptime_init(ClassLoaderData* loader_data, Thread* THREAD); |
|
101 void metaspace_pointers_do(MetaspaceClosure* it); |
|
102 |
|
103 int size() { |
|
104 return _size; |
|
105 } |
|
106 SharedClassPathEntry* path_at(int index) { |
|
107 if (index < 0) { |
|
108 return NULL; |
|
109 } |
|
110 assert(index < _size, "sanity"); |
|
111 char* p = (char*)_table->data(); |
|
112 p += sizeof(SharedClassPathEntry) * index; |
|
113 return (SharedClassPathEntry*)p; |
|
114 } |
|
115 Array<u8>* table() {return _table;} |
|
116 void set_table(Array<u8>* table) {_table = table;} |
|
117 |
|
118 }; |
|
119 |
96 struct FileMapHeader : public CDSFileMapHeaderBase { |
120 struct FileMapHeader : public CDSFileMapHeaderBase { |
|
121 size_t _header_size; |
97 size_t _alignment; // how shared archive should be aligned |
122 size_t _alignment; // how shared archive should be aligned |
98 int _obj_alignment; // value of ObjectAlignmentInBytes |
123 int _obj_alignment; // value of ObjectAlignmentInBytes |
99 address _narrow_oop_base; // compressed oop encoding base |
124 address _narrow_oop_base; // compressed oop encoding base |
100 int _narrow_oop_shift; // compressed oop encoding shift |
125 int _narrow_oop_shift; // compressed oop encoding shift |
101 bool _compact_strings; // value of CompactStrings |
126 bool _compact_strings; // value of CompactStrings |
108 address _cds_i2i_entry_code_buffers; |
133 address _cds_i2i_entry_code_buffers; |
109 size_t _cds_i2i_entry_code_buffers_size; |
134 size_t _cds_i2i_entry_code_buffers_size; |
110 size_t _core_spaces_size; // number of bytes allocated by the core spaces |
135 size_t _core_spaces_size; // number of bytes allocated by the core spaces |
111 // (mc, md, ro, rw and od). |
136 // (mc, md, ro, rw and od). |
112 MemRegion _heap_reserved; // reserved region for the entire heap at dump time. |
137 MemRegion _heap_reserved; // reserved region for the entire heap at dump time. |
|
138 bool _base_archive_is_default; // indicates if the base archive is the system default one |
113 |
139 |
114 // The following fields are all sanity checks for whether this archive |
140 // The following fields are all sanity checks for whether this archive |
115 // will function correctly with this JVM and the bootclasspath it's |
141 // will function correctly with this JVM and the bootclasspath it's |
116 // invoked with. |
142 // invoked with. |
117 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm |
143 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm |
|
144 |
|
145 // size of the base archive name including NULL terminator |
|
146 int _base_archive_name_size; |
118 |
147 |
119 // The _paths_misc_info is a variable-size structure that records "miscellaneous" |
148 // The _paths_misc_info is a variable-size structure that records "miscellaneous" |
120 // information during dumping. It is generated and validated by the |
149 // information during dumping. It is generated and validated by the |
121 // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for |
150 // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for |
122 // detailed description. |
151 // detailed description. |
138 // it is checked by the _paths_misc_info as described above. |
167 // it is checked by the _paths_misc_info as described above. |
139 // |
168 // |
140 // FIXME -- if JAR files in the tail of the list were specified but not used during dumping, |
169 // FIXME -- if JAR files in the tail of the list were specified but not used during dumping, |
141 // they should be removed from this table, to save space and to avoid spurious |
170 // they should be removed from this table, to save space and to avoid spurious |
142 // loading failures during runtime. |
171 // loading failures during runtime. |
143 int _shared_path_table_size; |
172 SharedPathTable _shared_path_table; |
144 size_t _shared_path_entry_size; |
|
145 Array<u8>* _shared_path_table; |
|
146 |
173 |
147 jshort _app_class_paths_start_index; // Index of first app classpath entry |
174 jshort _app_class_paths_start_index; // Index of first app classpath entry |
148 jshort _app_module_paths_start_index; // Index of first module path entry |
175 jshort _app_module_paths_start_index; // Index of first module path entry |
|
176 jshort _num_module_paths; // number of module path entries |
149 jshort _max_used_path_index; // max path index referenced during CDS dump |
177 jshort _max_used_path_index; // max path index referenced during CDS dump |
150 bool _verify_local; // BytecodeVerificationLocal setting |
178 bool _verify_local; // BytecodeVerificationLocal setting |
151 bool _verify_remote; // BytecodeVerificationRemote setting |
179 bool _verify_remote; // BytecodeVerificationRemote setting |
152 bool _has_platform_or_app_classes; // Archive contains app classes |
180 bool _has_platform_or_app_classes; // Archive contains app classes |
153 size_t _shared_base_address; // SharedBaseAddress used at dump time |
181 size_t _shared_base_address; // SharedBaseAddress used at dump time |
159 bool has_platform_or_app_classes() { return _has_platform_or_app_classes; } |
187 bool has_platform_or_app_classes() { return _has_platform_or_app_classes; } |
160 jshort max_used_path_index() { return _max_used_path_index; } |
188 jshort max_used_path_index() { return _max_used_path_index; } |
161 jshort app_module_paths_start_index() { return _app_module_paths_start_index; } |
189 jshort app_module_paths_start_index() { return _app_module_paths_start_index; } |
162 |
190 |
163 bool validate(); |
191 bool validate(); |
164 void populate(FileMapInfo* info, size_t alignment); |
|
165 int compute_crc(); |
192 int compute_crc(); |
166 |
193 |
167 CDSFileMapRegion* space_at(int i) { |
194 CDSFileMapRegion* space_at(int i) { |
168 assert(i >= 0 && i < NUM_CDS_REGIONS, "invalid region"); |
195 assert(i >= 0 && i < NUM_CDS_REGIONS, "invalid region"); |
169 return &_space[i]; |
196 return &_space[i]; |
170 } |
197 } |
|
198 public: |
|
199 void populate(FileMapInfo* info, size_t alignment); |
171 }; |
200 }; |
172 |
201 |
173 class FileMapInfo : public CHeapObj<mtInternal> { |
202 class FileMapInfo : public CHeapObj<mtInternal> { |
174 private: |
203 private: |
175 friend class ManifestStream; |
204 friend class ManifestStream; |
176 friend class VMStructs; |
205 friend class VMStructs; |
177 friend struct FileMapHeader; |
206 friend struct FileMapHeader; |
178 |
207 |
|
208 bool _is_static; |
179 bool _file_open; |
209 bool _file_open; |
180 int _fd; |
210 int _fd; |
181 size_t _file_offset; |
211 size_t _file_offset; |
182 |
212 |
183 private: |
213 private: |
184 static Array<u8>* _shared_path_table; |
214 // TODO: Probably change the following to be non-static |
185 static int _shared_path_table_size; |
215 static SharedPathTable _shared_path_table; |
186 static size_t _shared_path_entry_size; |
|
187 static bool _validating_shared_path_table; |
216 static bool _validating_shared_path_table; |
188 |
217 |
189 // FileMapHeader describes the shared space data in the file to be |
218 // FileMapHeader describes the shared space data in the file to be |
190 // mapped. This structure gets written to a file. It is not a class, so |
219 // mapped. This structure gets written to a file. It is not a class, so |
191 // that the compilers don't add any compiler-private data to it. |
220 // that the compilers don't add any compiler-private data to it. |
200 |
229 |
201 FileMapHeader * _header; |
230 FileMapHeader * _header; |
202 |
231 |
203 const char* _full_path; |
232 const char* _full_path; |
204 char* _paths_misc_info; |
233 char* _paths_misc_info; |
|
234 char* _base_archive_name; |
205 |
235 |
206 static FileMapInfo* _current_info; |
236 static FileMapInfo* _current_info; |
|
237 static FileMapInfo* _dynamic_archive_info; |
207 static bool _heap_pointers_need_patching; |
238 static bool _heap_pointers_need_patching; |
208 |
239 static bool _memory_mapping_failed; |
209 bool init_from_file(int fd); |
240 static bool get_base_archive_name_from_header(const char* archive_name, |
210 void align_file_position(); |
241 int* size, char** base_archive_name); |
211 bool validate_header_impl(); |
242 static bool check_archive(const char* archive_name, bool is_static); |
|
243 static bool same_files(const char* file1, const char* file2); |
|
244 void restore_shared_path_table(); |
|
245 bool init_from_file(int fd, bool is_static); |
212 static void metaspace_pointers_do(MetaspaceClosure* it); |
246 static void metaspace_pointers_do(MetaspaceClosure* it); |
213 |
247 |
214 public: |
248 public: |
215 FileMapInfo(); |
249 FileMapInfo(bool is_static); |
216 ~FileMapInfo(); |
250 ~FileMapInfo(); |
217 |
251 |
218 int compute_header_crc() { return _header->compute_crc(); } |
252 int compute_header_crc() { return _header->compute_crc(); } |
219 void set_header_crc(int crc) { _header->_crc = crc; } |
253 void set_header_crc(int crc) { _header->_crc = crc; } |
|
254 int space_crc(int i) { return space_at(i)->_crc; } |
220 void populate_header(size_t alignment); |
255 void populate_header(size_t alignment); |
221 bool validate_header(); |
256 bool validate_header(bool is_static); |
222 void invalidate(); |
257 void invalidate(); |
|
258 int crc() { return _header->_crc; } |
223 int version() { return _header->_version; } |
259 int version() { return _header->_version; } |
224 size_t alignment() { return _header->_alignment; } |
260 size_t alignment() { return _header->_alignment; } |
225 CompressedOops::Mode narrow_oop_mode() { return _header->_narrow_oop_mode; } |
261 CompressedOops::Mode narrow_oop_mode() { return _header->_narrow_oop_mode; } |
226 address narrow_oop_base() const { return _header->_narrow_oop_base; } |
262 address narrow_oop_base() const { return _header->_narrow_oop_base; } |
227 int narrow_oop_shift() const { return _header->_narrow_oop_shift; } |
263 int narrow_oop_shift() const { return _header->_narrow_oop_shift; } |
232 char* misc_data_patching_start() { return _header->_misc_data_patching_start; } |
268 char* misc_data_patching_start() { return _header->_misc_data_patching_start; } |
233 void set_misc_data_patching_start(char* p) { _header->_misc_data_patching_start = p; } |
269 void set_misc_data_patching_start(char* p) { _header->_misc_data_patching_start = p; } |
234 char* read_only_tables_start() { return _header->_read_only_tables_start; } |
270 char* read_only_tables_start() { return _header->_read_only_tables_start; } |
235 void set_read_only_tables_start(char* p) { _header->_read_only_tables_start = p; } |
271 void set_read_only_tables_start(char* p) { _header->_read_only_tables_start = p; } |
236 |
272 |
|
273 bool is_file_position_aligned() const; |
|
274 void align_file_position(); |
|
275 |
237 address cds_i2i_entry_code_buffers() { |
276 address cds_i2i_entry_code_buffers() { |
238 return _header->_cds_i2i_entry_code_buffers; |
277 return _header->_cds_i2i_entry_code_buffers; |
239 } |
278 } |
240 void set_cds_i2i_entry_code_buffers(address addr) { |
279 void set_cds_i2i_entry_code_buffers(address addr) { |
241 _header->_cds_i2i_entry_code_buffers = addr; |
280 _header->_cds_i2i_entry_code_buffers = addr; |
252 static FileMapInfo* current_info() { |
291 static FileMapInfo* current_info() { |
253 CDS_ONLY(return _current_info;) |
292 CDS_ONLY(return _current_info;) |
254 NOT_CDS(return NULL;) |
293 NOT_CDS(return NULL;) |
255 } |
294 } |
256 |
295 |
|
296 static void set_current_info(FileMapInfo* info) { |
|
297 CDS_ONLY(_current_info = info;) |
|
298 } |
|
299 |
|
300 static FileMapInfo* dynamic_info() { |
|
301 CDS_ONLY(return _dynamic_archive_info;) |
|
302 NOT_CDS(return NULL;) |
|
303 } |
|
304 |
257 static void assert_mark(bool check); |
305 static void assert_mark(bool check); |
258 |
306 |
259 // File manipulation. |
307 // File manipulation. |
260 bool initialize() NOT_CDS_RETURN_(false); |
308 bool initialize(bool is_static) NOT_CDS_RETURN_(false); |
261 bool open_for_read(); |
309 bool open_for_read(const char* path = NULL); |
262 void open_for_write(); |
310 void open_for_write(const char* path = NULL); |
263 void write_header(); |
311 void write_header(); |
264 void write_region(int region, char* base, size_t size, |
312 void write_region(int region, char* base, size_t size, |
265 bool read_only, bool allow_exec); |
313 bool read_only, bool allow_exec); |
266 size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem, |
314 size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem, |
267 GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, |
315 GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, |
268 int first_region_id, int max_num_regions, |
316 int first_region_id, int max_num_regions, |
269 bool print_log); |
317 bool print_log); |
270 void write_bytes(const void* buffer, size_t count); |
318 void write_bytes(const void* buffer, size_t count); |
271 void write_bytes_aligned(const void* buffer, size_t count); |
319 void write_bytes_aligned(const void* buffer, size_t count); |
|
320 size_t read_bytes(void* buffer, size_t count); |
|
321 char* map_regions(int regions[], char* saved_base[], size_t len); |
272 char* map_region(int i, char** top_ret); |
322 char* map_region(int i, char** top_ret); |
273 void map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN; |
323 void map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN; |
274 void map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; |
324 void map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; |
275 void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; |
325 void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; |
276 void patch_archived_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN; |
326 void patch_archived_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN; |
277 void patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges, |
327 void patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges, |
278 int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN; |
328 int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN; |
279 bool has_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false); |
329 bool has_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false); |
280 MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion()); |
330 MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion()); |
|
331 void unmap_regions(int regions[], char* saved_base[], size_t len); |
281 void unmap_region(int i); |
332 void unmap_region(int i); |
282 bool verify_region_checksum(int i); |
333 bool verify_region_checksum(int i); |
283 void close(); |
334 void close(); |
284 bool is_open() { return _file_open; } |
335 bool is_open() { return _file_open; } |
285 ReservedSpace reserve_shared_memory(); |
336 ReservedSpace reserve_shared_memory(); |
289 bool remap_shared_readonly_as_readwrite(); |
340 bool remap_shared_readonly_as_readwrite(); |
290 |
341 |
291 // Errors. |
342 // Errors. |
292 static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); |
343 static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); |
293 static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); |
344 static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); |
294 |
345 static bool memory_mapping_failed() { |
|
346 CDS_ONLY(return _memory_mapping_failed;) |
|
347 NOT_CDS(return false;) |
|
348 } |
295 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
349 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
296 |
350 |
297 // Stop CDS sharing and unmap CDS regions. |
351 // Stop CDS sharing and unmap CDS regions. |
298 static void stop_sharing_and_unmap(const char* msg); |
352 static void stop_sharing_and_unmap(const char* msg); |
299 |
353 |
305 #if INCLUDE_JVMTI |
359 #if INCLUDE_JVMTI |
306 static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS); |
360 static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS); |
307 #endif |
361 #endif |
308 |
362 |
309 static SharedClassPathEntry* shared_path(int index) { |
363 static SharedClassPathEntry* shared_path(int index) { |
310 if (index < 0) { |
364 return _shared_path_table.path_at(index); |
311 return NULL; |
|
312 } |
|
313 assert(index < _shared_path_table_size, "sanity"); |
|
314 char* p = (char*)_shared_path_table->data(); |
|
315 p += _shared_path_entry_size * index; |
|
316 return (SharedClassPathEntry*)p; |
|
317 } |
365 } |
318 |
366 |
319 static const char* shared_path_name(int index) { |
367 static const char* shared_path_name(int index) { |
320 assert(index >= 0, "Sanity"); |
368 assert(index >= 0, "Sanity"); |
321 return shared_path(index)->name(); |
369 return shared_path(index)->name(); |
322 } |
370 } |
323 |
371 |
324 static int get_number_of_shared_paths() { |
372 static int get_number_of_shared_paths() { |
325 return _shared_path_table_size; |
373 return _shared_path_table.size(); |
326 } |
374 } |
327 |
375 |
328 char* region_addr(int idx); |
376 char* region_addr(int idx); |
329 |
377 |
330 private: |
378 private: |
331 bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, |
379 bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, |
332 bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false); |
380 bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false); |
333 bool verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false); |
381 bool region_crc_check(char* buf, size_t size, int expected_crc) NOT_CDS_RETURN_(false); |
334 void dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN; |
382 void dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN; |
335 |
383 |
336 CDSFileMapRegion* space_at(int i) { |
384 CDSFileMapRegion* space_at(int i) { |
337 return _header->space_at(i); |
385 return _header->space_at(i); |
338 } |
386 } |