71 bool is_modules_image() { return _type == modules_image_entry; } 72 bool is_jar() { return _type == jar_entry; } 73 bool is_signed() { return _type == signed_jar_entry; } 74 void set_is_signed() { 75 _type = signed_jar_entry; 76 } 77 time_t timestamp() const { return _timestamp; } 78 long filesize() const { return _filesize; } 79 const char* name() const { return _name->data(); } 80 const char* manifest() const { 81 return (_manifest == NULL) ? NULL : (const char*)_manifest->data(); 82 } 83 int manifest_size() const { 84 return (_manifest == NULL) ? 0 : _manifest->length(); 85 } 86 void set_manifest(Array<u1>* manifest) { 87 _manifest = manifest; 88 } 89 }; 90 91 struct FileMapHeader : public CDSFileMapHeaderBase { 92 size_t _alignment; // how shared archive should be aligned 93 int _obj_alignment; // value of ObjectAlignmentInBytes 94 address _narrow_oop_base; // compressed oop encoding base 95 int _narrow_oop_shift; // compressed oop encoding shift 96 bool _compact_strings; // value of CompactStrings 97 uintx _max_heap_size; // java max heap size during dumping 98 Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode 99 int _narrow_klass_shift; // save narrow klass base and shift 100 address _narrow_klass_base; 101 char* _misc_data_patching_start; 102 char* _read_only_tables_start; 103 address _cds_i2i_entry_code_buffers; 104 size_t _cds_i2i_entry_code_buffers_size; 105 size_t _core_spaces_size; // number of bytes allocated by the core spaces 106 // (mc, md, ro, rw and od). 107 108 // The following fields are all sanity checks for whether this archive 109 // will function correctly with this JVM and the bootclasspath it's 110 // invoked with. 111 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm 112 113 // The _paths_misc_info is a variable-size structure that records "miscellaneous" 114 // information during dumping. It is generated and validated by the 115 // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for 116 // detailed description. 117 // 118 // The _paths_misc_info data is stored as a byte array in the archive file header, 119 // immediately after the _header field. This information is used only when 120 // checking the validity of the archive and is deallocated after the archive is loaded. 121 // 122 // Note that the _paths_misc_info does NOT include information for JAR files 123 // that existed during dump time. Their information is stored in _shared_path_table. 124 int _paths_misc_info_size; 125 126 // The following is a table of all the class path entries that were used 135 // they should be removed from this table, to save space and to avoid spurious 136 // loading failures during runtime. 137 int _shared_path_table_size; 138 size_t _shared_path_entry_size; 139 Array<u8>* _shared_path_table; 140 141 jshort _app_class_paths_start_index; // Index of first app classpath entry 142 jshort _app_module_paths_start_index; // Index of first module path entry 143 jshort _max_used_path_index; // max path index referenced during CDS dump 144 bool _verify_local; // BytecodeVerificationLocal setting 145 bool _verify_remote; // BytecodeVerificationRemote setting 146 bool _has_platform_or_app_classes; // Archive contains app classes 147 148 void set_has_platform_or_app_classes(bool v) { 149 _has_platform_or_app_classes = v; 150 } 151 bool has_platform_or_app_classes() { return _has_platform_or_app_classes; } 152 jshort max_used_path_index() { return _max_used_path_index; } 153 jshort app_module_paths_start_index() { return _app_module_paths_start_index; } 154 155 char* region_addr(int idx); 156 157 bool validate(); 158 void populate(FileMapInfo* info, size_t alignment); 159 int compute_crc(); 160 }; 161 162 163 class FileMapInfo : public CHeapObj<mtInternal> { 164 private: 165 friend class ManifestStream; 166 friend class VMStructs; 167 friend struct FileMapHeader; 168 169 bool _file_open; 170 int _fd; 171 size_t _file_offset; 172 173 private: 174 static Array<u8>* _shared_path_table; 175 static int _shared_path_table_size; 176 static size_t _shared_path_entry_size; 177 static bool _validating_shared_path_table; 178 179 // FileMapHeader describes the shared space data in the file to be 180 // mapped. This structure gets written to a file. It is not a class, so 181 // that the compilers don't add any compiler-private data to it. 182 183 public: 184 struct FileMapHeaderBase : public CHeapObj<mtClass> { 185 // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual 186 // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc. 187 intx _dummy; 188 }; 189 190 191 FileMapHeader * _header; 192 193 const char* _full_path; 194 char* _paths_misc_info; 195 196 static FileMapInfo* _current_info; 197 198 bool init_from_file(int fd); 199 void align_file_position(); 200 bool validate_header_impl(); 201 static void metaspace_pointers_do(MetaspaceClosure* it); 202 203 public: 204 FileMapInfo(); 205 ~FileMapInfo(); 206 207 int compute_header_crc() { return _header->compute_crc(); } 208 void set_header_crc(int crc) { _header->_crc = crc; } 209 void populate_header(size_t alignment); 210 bool validate_header(); 211 void invalidate(); 212 int version() { return _header->_version; } 213 size_t alignment() { return _header->_alignment; } 214 Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; } 215 address narrow_oop_base() const { return _header->_narrow_oop_base; } 216 int narrow_oop_shift() const { return _header->_narrow_oop_shift; } 236 _header->_cds_i2i_entry_code_buffers_size = s; 237 } 238 void set_core_spaces_size(size_t s) { _header->_core_spaces_size = s; } 239 size_t core_spaces_size() { return _header->_core_spaces_size; } 240 241 static FileMapInfo* current_info() { 242 CDS_ONLY(return _current_info;) 243 NOT_CDS(return NULL;) 244 } 245 246 static void assert_mark(bool check); 247 248 // File manipulation. 249 bool initialize() NOT_CDS_RETURN_(false); 250 bool open_for_read(); 251 void open_for_write(); 252 void write_header(); 253 void write_region(int region, char* base, size_t size, 254 bool read_only, bool allow_exec); 255 size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem, 256 int first_region_id, int max_num_regions); 257 void write_bytes(const void* buffer, size_t count); 258 void write_bytes_aligned(const void* buffer, size_t count); 259 char* map_region(int i, char** top_ret); 260 void map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; 261 void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; 262 void unmap_region(int i); 263 bool verify_region_checksum(int i); 264 void close(); 265 bool is_open() { return _file_open; } 266 ReservedSpace reserve_shared_memory(); 267 268 // JVM/TI RedefineClasses() support: 269 // Remap the shared readonly space to shared readwrite, private. 270 bool remap_shared_readonly_as_readwrite(); 271 272 // Errors. 273 static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); 274 static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); 275 276 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); 277 void print_shared_spaces() NOT_CDS_RETURN; 278 279 // Stop CDS sharing and unmap CDS regions. 280 static void stop_sharing_and_unmap(const char* msg); 281 282 static void allocate_shared_path_table(); 283 static void check_nonempty_dir_in_shared_path_table(); 284 bool validate_shared_path_table(); 285 static void update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS); 286 287 static SharedClassPathEntry* shared_path(int index) { 288 if (index < 0) { 289 return NULL; 290 } 291 assert(index < _shared_path_table_size, "sanity"); 292 char* p = (char*)_shared_path_table->data(); 293 p += _shared_path_entry_size * index; 294 return (SharedClassPathEntry*)p; 295 } 296 297 static const char* shared_path_name(int index) { 298 assert(index >= 0, "Sanity"); 299 return shared_path(index)->name(); 300 } 301 302 static int get_number_of_shared_paths() { 303 return _shared_path_table_size; 304 } 305 306 private: 307 bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, 308 bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false); 309 bool verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false); 310 void dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN; 311 312 CDSFileMapRegion* space_at(int i) { 313 assert(i >= 0 && i < NUM_CDS_REGIONS, "invalid region"); 314 return &_header->_space[i]; 315 } 316 }; 317 318 #endif // SHARE_VM_MEMORY_FILEMAP_HPP | 71 bool is_modules_image() { return _type == modules_image_entry; } 72 bool is_jar() { return _type == jar_entry; } 73 bool is_signed() { return _type == signed_jar_entry; } 74 void set_is_signed() { 75 _type = signed_jar_entry; 76 } 77 time_t timestamp() const { return _timestamp; } 78 long filesize() const { return _filesize; } 79 const char* name() const { return _name->data(); } 80 const char* manifest() const { 81 return (_manifest == NULL) ? NULL : (const char*)_manifest->data(); 82 } 83 int manifest_size() const { 84 return (_manifest == NULL) ? 0 : _manifest->length(); 85 } 86 void set_manifest(Array<u1>* manifest) { 87 _manifest = manifest; 88 } 89 }; 90 91 struct ArchiveHeapOopmapInfo { 92 address _oopmap; // bitmap for relocating embedded oops 93 size_t _oopmap_size_in_bits; 94 }; 95 96 struct FileMapHeader : public CDSFileMapHeaderBase { 97 size_t _alignment; // how shared archive should be aligned 98 int _obj_alignment; // value of ObjectAlignmentInBytes 99 address _narrow_oop_base; // compressed oop encoding base 100 int _narrow_oop_shift; // compressed oop encoding shift 101 bool _compact_strings; // value of CompactStrings 102 uintx _max_heap_size; // java max heap size during dumping 103 Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode 104 int _narrow_klass_shift; // save narrow klass base and shift 105 address _narrow_klass_base; 106 char* _misc_data_patching_start; 107 char* _read_only_tables_start; 108 address _cds_i2i_entry_code_buffers; 109 size_t _cds_i2i_entry_code_buffers_size; 110 size_t _core_spaces_size; // number of bytes allocated by the core spaces 111 // (mc, md, ro, rw and od). 112 MemRegion _heap_reserved; // reserved region for the entire heap at dump time. 113 114 // The following fields are all sanity checks for whether this archive 115 // will function correctly with this JVM and the bootclasspath it's 116 // invoked with. 117 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm 118 119 // The _paths_misc_info is a variable-size structure that records "miscellaneous" 120 // information during dumping. It is generated and validated by the 121 // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for 122 // detailed description. 123 // 124 // The _paths_misc_info data is stored as a byte array in the archive file header, 125 // immediately after the _header field. This information is used only when 126 // checking the validity of the archive and is deallocated after the archive is loaded. 127 // 128 // Note that the _paths_misc_info does NOT include information for JAR files 129 // that existed during dump time. Their information is stored in _shared_path_table. 130 int _paths_misc_info_size; 131 132 // The following is a table of all the class path entries that were used 141 // they should be removed from this table, to save space and to avoid spurious 142 // loading failures during runtime. 143 int _shared_path_table_size; 144 size_t _shared_path_entry_size; 145 Array<u8>* _shared_path_table; 146 147 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 149 jshort _max_used_path_index; // max path index referenced during CDS dump 150 bool _verify_local; // BytecodeVerificationLocal setting 151 bool _verify_remote; // BytecodeVerificationRemote setting 152 bool _has_platform_or_app_classes; // Archive contains app classes 153 154 void set_has_platform_or_app_classes(bool v) { 155 _has_platform_or_app_classes = v; 156 } 157 bool has_platform_or_app_classes() { return _has_platform_or_app_classes; } 158 jshort max_used_path_index() { return _max_used_path_index; } 159 jshort app_module_paths_start_index() { return _app_module_paths_start_index; } 160 161 bool validate(); 162 void populate(FileMapInfo* info, size_t alignment); 163 int compute_crc(); 164 165 CDSFileMapRegion* space_at(int i) { 166 assert(i >= 0 && i < NUM_CDS_REGIONS, "invalid region"); 167 return &_space[i]; 168 } 169 }; 170 171 class FileMapInfo : public CHeapObj<mtInternal> { 172 private: 173 friend class ManifestStream; 174 friend class VMStructs; 175 friend struct FileMapHeader; 176 177 bool _file_open; 178 int _fd; 179 size_t _file_offset; 180 181 private: 182 static Array<u8>* _shared_path_table; 183 static int _shared_path_table_size; 184 static size_t _shared_path_entry_size; 185 static bool _validating_shared_path_table; 186 187 // FileMapHeader describes the shared space data in the file to be 188 // mapped. This structure gets written to a file. It is not a class, so 189 // that the compilers don't add any compiler-private data to it. 190 191 public: 192 struct FileMapHeaderBase : public CHeapObj<mtClass> { 193 // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual 194 // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc. 195 intx _dummy; 196 }; 197 198 199 FileMapHeader * _header; 200 201 const char* _full_path; 202 char* _paths_misc_info; 203 204 static FileMapInfo* _current_info; 205 static bool _heap_pointers_need_patching; 206 207 bool init_from_file(int fd); 208 void align_file_position(); 209 bool validate_header_impl(); 210 static void metaspace_pointers_do(MetaspaceClosure* it); 211 212 public: 213 FileMapInfo(); 214 ~FileMapInfo(); 215 216 int compute_header_crc() { return _header->compute_crc(); } 217 void set_header_crc(int crc) { _header->_crc = crc; } 218 void populate_header(size_t alignment); 219 bool validate_header(); 220 void invalidate(); 221 int version() { return _header->_version; } 222 size_t alignment() { return _header->_alignment; } 223 Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; } 224 address narrow_oop_base() const { return _header->_narrow_oop_base; } 225 int narrow_oop_shift() const { return _header->_narrow_oop_shift; } 245 _header->_cds_i2i_entry_code_buffers_size = s; 246 } 247 void set_core_spaces_size(size_t s) { _header->_core_spaces_size = s; } 248 size_t core_spaces_size() { return _header->_core_spaces_size; } 249 250 static FileMapInfo* current_info() { 251 CDS_ONLY(return _current_info;) 252 NOT_CDS(return NULL;) 253 } 254 255 static void assert_mark(bool check); 256 257 // File manipulation. 258 bool initialize() NOT_CDS_RETURN_(false); 259 bool open_for_read(); 260 void open_for_write(); 261 void write_header(); 262 void write_region(int region, char* base, size_t size, 263 bool read_only, bool allow_exec); 264 size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem, 265 GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, 266 int first_region_id, int max_num_regions); 267 void write_bytes(const void* buffer, size_t count); 268 void write_bytes_aligned(const void* buffer, size_t count); 269 char* map_region(int i, char** top_ret); 270 void map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN; 271 void map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; 272 void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN; 273 void patch_archived_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN; 274 void patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges, 275 int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN; 276 bool has_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false); 277 MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion()); 278 void unmap_region(int i); 279 bool verify_region_checksum(int i); 280 void close(); 281 bool is_open() { return _file_open; } 282 ReservedSpace reserve_shared_memory(); 283 284 // JVM/TI RedefineClasses() support: 285 // Remap the shared readonly space to shared readwrite, private. 286 bool remap_shared_readonly_as_readwrite(); 287 288 // Errors. 289 static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); 290 static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2); 291 292 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); 293 294 // Stop CDS sharing and unmap CDS regions. 295 static void stop_sharing_and_unmap(const char* msg); 296 297 static void allocate_shared_path_table(); 298 static void check_nonempty_dir_in_shared_path_table(); 299 bool validate_shared_path_table(); 300 static void update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS); 301 302 static SharedClassPathEntry* shared_path(int index) { 303 if (index < 0) { 304 return NULL; 305 } 306 assert(index < _shared_path_table_size, "sanity"); 307 char* p = (char*)_shared_path_table->data(); 308 p += _shared_path_entry_size * index; 309 return (SharedClassPathEntry*)p; 310 } 311 312 static const char* shared_path_name(int index) { 313 assert(index >= 0, "Sanity"); 314 return shared_path(index)->name(); 315 } 316 317 static int get_number_of_shared_paths() { 318 return _shared_path_table_size; 319 } 320 321 char* region_addr(int idx); 322 323 private: 324 bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, 325 bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false); 326 bool verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false); 327 void dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN; 328 329 CDSFileMapRegion* space_at(int i) { 330 return _header->space_at(i); 331 } 332 333 narrowOop offset_of_space(CDSFileMapRegion* spc) { 334 return (narrowOop)(spc->_addr._offset); 335 } 336 337 // The starting address of spc, as calculated with CompressedOop::decode_non_null() 338 address start_address_with_current_oop_encoding_mode(CDSFileMapRegion* spc) { 339 return decode_start_address(spc, true); 340 } 341 342 // The starting address of spc, as calculated with HeapShared::decode_with_archived_oop_encoding_mode() 343 address start_address_with_archived_oop_encoding_mode(CDSFileMapRegion* spc) { 344 return decode_start_address(spc, false); 345 } 346 347 address decode_start_address(CDSFileMapRegion* spc, bool with_current_oop_encoding_mode); 348 }; 349 350 #endif // SHARE_VM_MEMORY_FILEMAP_HPP |