40 // misc data (block offset table, string table, symbols, dictionary, etc.) |
40 // misc data (block offset table, string table, symbols, dictionary, etc.) |
41 // tag(666) |
41 // tag(666) |
42 |
42 |
43 static const int JVM_IDENT_MAX = 256; |
43 static const int JVM_IDENT_MAX = 256; |
44 |
44 |
45 class Metaspace; |
|
46 |
|
47 class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC { |
45 class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC { |
48 public: |
46 protected: |
49 const char *_name; |
47 bool _is_dir; |
50 time_t _timestamp; // jar/jimage timestamp, 0 if is directory or other |
48 time_t _timestamp; // jar/jimage timestamp, 0 if is directory or other |
51 long _filesize; // jar/jimage file size, -1 if is directory, -2 if other |
49 long _filesize; // jar/jimage file size, -1 if is directory, -2 if other |
|
50 Array<char>* _name; |
|
51 Array<u1>* _manifest; |
|
52 |
|
53 public: |
|
54 void init(const char* name, TRAPS); |
|
55 void metaspace_pointers_do(MetaspaceClosure* it); |
|
56 bool validate(); |
52 |
57 |
53 // The _timestamp only gets set for jar files and "modules" jimage. |
58 // The _timestamp only gets set for jar files and "modules" jimage. |
54 bool is_jar_or_bootimage() { |
59 bool is_jar_or_bootimage() { |
55 return _timestamp != 0; |
60 return _timestamp != 0; |
56 } |
61 } |
57 bool is_dir() { |
62 bool is_dir() { return _is_dir; } |
58 return _filesize == -1; |
63 bool is_jrt() { return ClassLoader::is_jrt(name()); } |
59 } |
64 time_t timestamp() const { return _timestamp; } |
60 |
65 long filesize() const { return _filesize; } |
61 bool is_jrt() { |
66 const char* name() const { return _name->data(); } |
62 return ClassLoader::is_jrt(_name); |
67 const char* manifest() const { |
|
68 return (_manifest == NULL) ? NULL : (const char*)_manifest->data(); |
|
69 } |
|
70 int manifest_size() const { |
|
71 return (_manifest == NULL) ? 0 : _manifest->length(); |
63 } |
72 } |
64 }; |
73 }; |
65 |
74 |
66 class FileMapInfo : public CHeapObj<mtInternal> { |
75 class FileMapInfo : public CHeapObj<mtInternal> { |
67 private: |
76 private: |
68 friend class ManifestStream; |
77 friend class ManifestStream; |
69 enum { |
78 enum { |
70 _invalid_version = -1, |
79 _invalid_version = -1, |
71 _current_version = 2 |
80 _current_version = 3 |
72 }; |
81 }; |
73 |
82 |
74 bool _file_open; |
83 bool _file_open; |
75 int _fd; |
84 int _fd; |
76 size_t _file_offset; |
85 size_t _file_offset; |
77 |
86 |
78 private: |
87 private: |
79 static SharedClassPathEntry* _classpath_entry_table; |
88 static Array<u8>* _classpath_entry_table; |
80 static int _classpath_entry_table_size; |
89 static int _classpath_entry_table_size; |
81 static size_t _classpath_entry_size; |
90 static size_t _classpath_entry_size; |
82 static bool _validating_classpath_entry_table; |
91 static bool _validating_classpath_entry_table; |
83 |
92 |
84 // FileMapHeader describes the shared space data in the file to be |
93 // FileMapHeader describes the shared space data in the file to be |
108 uintx _max_heap_size; // java max heap size during dumping |
117 uintx _max_heap_size; // java max heap size during dumping |
109 Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode |
118 Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode |
110 int _narrow_klass_shift; // save narrow klass base and shift |
119 int _narrow_klass_shift; // save narrow klass base and shift |
111 address _narrow_klass_base; |
120 address _narrow_klass_base; |
112 char* _misc_data_patching_start; |
121 char* _misc_data_patching_start; |
|
122 char* _read_only_tables_start; |
113 address _cds_i2i_entry_code_buffers; |
123 address _cds_i2i_entry_code_buffers; |
114 size_t _cds_i2i_entry_code_buffers_size; |
124 size_t _cds_i2i_entry_code_buffers_size; |
|
125 size_t _core_spaces_size; // number of bytes allocated by the core spaces |
|
126 // (mc, md, ro, rw and od). |
115 |
127 |
116 struct space_info { |
128 struct space_info { |
117 int _crc; // crc checksum of the current space |
129 int _crc; // crc checksum of the current space |
118 size_t _file_offset; // sizeof(this) rounded to vm page size |
130 size_t _file_offset; // sizeof(this) rounded to vm page size |
119 union { |
131 union { |
120 char* _base; // copy-on-write base address |
132 char* _base; // copy-on-write base address |
121 intx _offset; // offset from the compressed oop encoding base, only used |
133 intx _offset; // offset from the compressed oop encoding base, only used |
122 // by string space |
134 // by string space |
123 } _addr; |
135 } _addr; |
124 size_t _capacity; // for validity checking |
|
125 size_t _used; // for setting space top on read |
136 size_t _used; // for setting space top on read |
126 bool _read_only; // read only space? |
137 bool _read_only; // read only space? |
127 bool _allow_exec; // executable code in space? |
138 bool _allow_exec; // executable code in space? |
128 } _space[MetaspaceShared::n_regions]; |
139 } _space[MetaspaceShared::n_regions]; |
129 |
140 |
156 // FIXME -- if JAR files in the tail of the list were specified but not used during dumping, |
167 // FIXME -- if JAR files in the tail of the list were specified but not used during dumping, |
157 // they should be removed from this table, to save space and to avoid spurious |
168 // they should be removed from this table, to save space and to avoid spurious |
158 // loading failures during runtime. |
169 // loading failures during runtime. |
159 int _classpath_entry_table_size; |
170 int _classpath_entry_table_size; |
160 size_t _classpath_entry_size; |
171 size_t _classpath_entry_size; |
161 SharedClassPathEntry* _classpath_entry_table; |
172 Array<u8>* _classpath_entry_table; |
162 |
173 |
163 char* region_addr(int idx); |
174 char* region_addr(int idx); |
164 |
175 |
165 virtual bool validate(); |
176 virtual bool validate(); |
166 virtual void populate(FileMapInfo* info, size_t alignment); |
177 virtual void populate(FileMapInfo* info, size_t alignment); |
193 Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; } |
205 Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; } |
194 int narrow_oop_shift() { return _header->_narrow_oop_shift; } |
206 int narrow_oop_shift() { return _header->_narrow_oop_shift; } |
195 uintx max_heap_size() { return _header->_max_heap_size; } |
207 uintx max_heap_size() { return _header->_max_heap_size; } |
196 address narrow_klass_base() const { return _header->_narrow_klass_base; } |
208 address narrow_klass_base() const { return _header->_narrow_klass_base; } |
197 int narrow_klass_shift() const { return _header->_narrow_klass_shift; } |
209 int narrow_klass_shift() const { return _header->_narrow_klass_shift; } |
198 size_t space_capacity(int i) { return _header->_space[i]._capacity; } |
|
199 struct FileMapHeader* header() { return _header; } |
210 struct FileMapHeader* header() { return _header; } |
200 char* misc_data_patching_start() { return _header->_misc_data_patching_start; } |
211 char* misc_data_patching_start() { return _header->_misc_data_patching_start; } |
201 void set_misc_data_patching_start(char* p) { _header->_misc_data_patching_start = p; } |
212 void set_misc_data_patching_start(char* p) { _header->_misc_data_patching_start = p; } |
|
213 char* read_only_tables_start() { return _header->_read_only_tables_start; } |
|
214 void set_read_only_tables_start(char* p) { _header->_read_only_tables_start = p; } |
202 |
215 |
203 address cds_i2i_entry_code_buffers() { |
216 address cds_i2i_entry_code_buffers() { |
204 return _header->_cds_i2i_entry_code_buffers; |
217 return _header->_cds_i2i_entry_code_buffers; |
205 } |
218 } |
206 void set_cds_i2i_entry_code_buffers(address addr) { |
219 void set_cds_i2i_entry_code_buffers(address addr) { |
210 return _header->_cds_i2i_entry_code_buffers_size; |
223 return _header->_cds_i2i_entry_code_buffers_size; |
211 } |
224 } |
212 void set_cds_i2i_entry_code_buffers_size(size_t s) { |
225 void set_cds_i2i_entry_code_buffers_size(size_t s) { |
213 _header->_cds_i2i_entry_code_buffers_size = s; |
226 _header->_cds_i2i_entry_code_buffers_size = s; |
214 } |
227 } |
|
228 void set_core_spaces_size(size_t s) { _header->_core_spaces_size = s; } |
|
229 size_t core_spaces_size() { return _header->_core_spaces_size; } |
215 |
230 |
216 static FileMapInfo* current_info() { |
231 static FileMapInfo* current_info() { |
217 CDS_ONLY(return _current_info;) |
232 CDS_ONLY(return _current_info;) |
218 NOT_CDS(return NULL;) |
233 NOT_CDS(return NULL;) |
219 } |
234 } |
223 // File manipulation. |
238 // File manipulation. |
224 bool initialize() NOT_CDS_RETURN_(false); |
239 bool initialize() NOT_CDS_RETURN_(false); |
225 bool open_for_read(); |
240 bool open_for_read(); |
226 void open_for_write(); |
241 void open_for_write(); |
227 void write_header(); |
242 void write_header(); |
228 void write_space(int i, Metaspace* space, bool read_only); |
|
229 void write_region(int region, char* base, size_t size, |
243 void write_region(int region, char* base, size_t size, |
230 size_t capacity, bool read_only, bool allow_exec); |
244 bool read_only, bool allow_exec); |
231 void write_string_regions(GrowableArray<MemRegion> *regions); |
245 void write_string_regions(GrowableArray<MemRegion> *regions, |
|
246 char** s0_start, char** s0_top, char** s0_end, |
|
247 char** s1_start, char** s1_top, char** s1_end); |
232 void write_bytes(const void* buffer, int count); |
248 void write_bytes(const void* buffer, int count); |
233 void write_bytes_aligned(const void* buffer, int count); |
249 void write_bytes_aligned(const void* buffer, int count); |
234 char* map_region(int i); |
250 char* map_region(int i); |
235 bool map_string_regions(); |
251 bool map_string_regions(); |
236 bool verify_string_regions(); |
252 bool verify_string_regions(); |
253 // Return true if given address is in the mapped shared space. |
269 // Return true if given address is in the mapped shared space. |
254 bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false); |
270 bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false); |
255 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
271 bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false); |
256 void print_shared_spaces() NOT_CDS_RETURN; |
272 void print_shared_spaces() NOT_CDS_RETURN; |
257 |
273 |
258 // The ro+rw+md+mc spaces size |
|
259 static size_t core_spaces_size() { |
|
260 return align_up((SharedReadOnlySize + SharedReadWriteSize + |
|
261 SharedMiscDataSize + SharedMiscCodeSize), |
|
262 os::vm_allocation_granularity()); |
|
263 } |
|
264 |
|
265 // The estimated optional space size. |
|
266 // |
|
267 // Currently the optional space only has archived class bytes. |
|
268 // The core_spaces_size is the size of all class metadata, which is a good |
|
269 // estimate of the total class bytes to be archived. Only the portion |
|
270 // containing data is written out to the archive and mapped at runtime. |
|
271 // There is no memory waste due to unused portion in optional space. |
|
272 static size_t optional_space_size() { |
|
273 return core_spaces_size(); |
|
274 } |
|
275 |
|
276 // Total shared_spaces size includes the ro, rw, md, mc and od spaces |
|
277 static size_t shared_spaces_size() { |
|
278 return core_spaces_size() + optional_space_size(); |
|
279 } |
|
280 |
|
281 // Stop CDS sharing and unmap CDS regions. |
274 // Stop CDS sharing and unmap CDS regions. |
282 static void stop_sharing_and_unmap(const char* msg); |
275 static void stop_sharing_and_unmap(const char* msg); |
283 |
276 |
284 static void allocate_classpath_entry_table(); |
277 static void allocate_classpath_entry_table(); |
285 bool validate_classpath_entry_table(); |
278 bool validate_classpath_entry_table(); |
286 |
279 |
287 static SharedClassPathEntry* shared_classpath(int index) { |
280 static SharedClassPathEntry* shared_classpath(int index) { |
288 if (index < 0) { |
281 if (index < 0) { |
289 return NULL; |
282 return NULL; |
290 } |
283 } |
291 char* p = (char*)_classpath_entry_table; |
284 assert(index < _classpath_entry_table_size, "sanity"); |
|
285 char* p = (char*)_classpath_entry_table->data(); |
292 p += _classpath_entry_size * index; |
286 p += _classpath_entry_size * index; |
293 return (SharedClassPathEntry*)p; |
287 return (SharedClassPathEntry*)p; |
294 } |
288 } |
295 static const char* shared_classpath_name(int index) { |
289 static const char* shared_classpath_name(int index) { |
296 assert(index >= 0, "Sanity"); |
290 assert(index >= 0, "Sanity"); |
297 return shared_classpath(index)->_name; |
291 return shared_classpath(index)->name(); |
298 } |
292 } |
299 |
293 |
300 static int get_number_of_share_classpaths() { |
294 static int get_number_of_share_classpaths() { |
301 return _classpath_entry_table_size; |
295 return _classpath_entry_table_size; |
302 } |
296 } |