201 // With class sharing, pages are mapped from classes.jsa file. |
202 // With class sharing, pages are mapped from classes.jsa file. |
202 // The read-only class sharing pages are mapped as MAP_SHARED, |
203 // The read-only class sharing pages are mapped as MAP_SHARED, |
203 // PROT_READ pages. These pages are not dumped into core dump. |
204 // PROT_READ pages. These pages are not dumped into core dump. |
204 // With this workaround, these pages are read from classes.jsa. |
205 // With this workaround, these pages are read from classes.jsa. |
205 |
206 |
206 // FIXME: !HACK ALERT! |
|
207 // The format of sharing achive file header is needed to read shared heap |
|
208 // file mappings. For now, I am hard coding portion of FileMapHeader here. |
|
209 // Refer to filemap.hpp. |
|
210 |
|
211 // FileMapHeader describes the shared space data in the file to be |
|
212 // mapped. This structure gets written to a file. It is not a class, |
|
213 // so that the compilers don't add any compiler-private data to it. |
|
214 |
|
215 #define NUM_SHARED_MAPS 9 |
|
216 |
|
217 // Refer to FileMapInfo::_current_version in filemap.hpp |
|
218 #define CURRENT_ARCHIVE_VERSION 3 |
|
219 |
|
220 typedef unsigned char* address; |
|
221 typedef uintptr_t uintx; |
|
222 typedef intptr_t intx; |
|
223 |
|
224 struct FileMapHeader { |
|
225 int _magic; // identify file type. |
|
226 int _crc; // header crc checksum. |
|
227 int _version; // (from enum, above.) |
|
228 size_t _alignment; // how shared archive should be aligned |
|
229 int _obj_alignment; // value of ObjectAlignmentInBytes |
|
230 address _narrow_oop_base; // compressed oop encoding base |
|
231 int _narrow_oop_shift; // compressed oop encoding shift |
|
232 bool _compact_strings; // value of CompactStrings |
|
233 uintx _max_heap_size; // java max heap size during dumping |
|
234 int _narrow_oop_mode; // compressed oop encoding mode |
|
235 int _narrow_klass_shift; // save narrow klass base and shift |
|
236 address _narrow_klass_base; |
|
237 char* _misc_data_patching_start; |
|
238 char* _read_only_tables_start; |
|
239 address _cds_i2i_entry_code_buffers; |
|
240 size_t _cds_i2i_entry_code_buffers_size; |
|
241 size_t _core_spaces_size; // number of bytes allocated by the core spaces |
|
242 // (mc, md, ro, rw and od). |
|
243 |
|
244 |
|
245 struct space_info { |
|
246 int _crc; // crc checksum of the current space |
|
247 size_t _file_offset; // sizeof(this) rounded to vm page size |
|
248 union { |
|
249 char* _base; // copy-on-write base address |
|
250 intx _offset; // offset from the compressed oop encoding base, only used |
|
251 // by archive heap space |
|
252 } _addr; |
|
253 size_t _used; // for setting space top on read |
|
254 // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with |
|
255 // the C type matching the C++ bool type on any given platform. |
|
256 // We assume the corresponding C type is char but licensees |
|
257 // may need to adjust the type of these fields. |
|
258 char _read_only; // read only space? |
|
259 char _allow_exec; // executable code in space? |
|
260 } _space[NUM_SHARED_MAPS]; |
|
261 |
|
262 // Ignore the rest of the FileMapHeader. We don't need those fields here. |
|
263 }; |
|
264 |
|
265 static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) { |
207 static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) { |
266 jboolean i; |
208 jboolean i; |
267 if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) { |
209 if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) { |
268 *pvalue = i; |
210 *pvalue = i; |
269 return true; |
211 return true; |
315 // we are iterating over shared objects from the core dump. look for |
257 // we are iterating over shared objects from the core dump. look for |
316 // libjvm.so. |
258 // libjvm.so. |
317 const char *jvm_name = 0; |
259 const char *jvm_name = 0; |
318 if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { |
260 if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { |
319 char classes_jsa[PATH_MAX]; |
261 char classes_jsa[PATH_MAX]; |
320 struct FileMapHeader header; |
262 CDSFileMapHeaderBase header; |
321 int fd = -1; |
263 int fd = -1; |
322 int m = 0; |
264 int m = 0; |
323 size_t n = 0; |
265 size_t n = 0; |
324 uintptr_t base = 0, useSharedSpacesAddr = 0; |
266 uintptr_t base = 0, useSharedSpacesAddr = 0; |
325 uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0; |
267 uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0; |
372 return false; |
314 return false; |
373 } else { |
315 } else { |
374 print_debug("opened %s\n", classes_jsa); |
316 print_debug("opened %s\n", classes_jsa); |
375 } |
317 } |
376 |
318 |
377 // read FileMapHeader from the file |
319 // read CDSFileMapHeaderBase from the file |
378 memset(&header, 0, sizeof(struct FileMapHeader)); |
320 memset(&header, 0, sizeof(CDSFileMapHeaderBase)); |
379 if ((n = read(fd, &header, sizeof(struct FileMapHeader))) |
321 if ((n = read(fd, &header, sizeof(CDSFileMapHeaderBase))) |
380 != sizeof(struct FileMapHeader)) { |
322 != sizeof(CDSFileMapHeaderBase)) { |
381 print_debug("can't read shared archive file map header from %s\n", classes_jsa); |
323 print_debug("can't read shared archive file map header from %s\n", classes_jsa); |
382 close(fd); |
324 close(fd); |
383 return false; |
325 return false; |
384 } |
326 } |
385 |
327 |
386 // check file magic |
328 // check file magic |
387 if (header._magic != 0xf00baba2) { |
329 if (header._magic != CDS_ARCHIVE_MAGIC) { |
388 print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n", |
330 print_debug("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n", |
389 classes_jsa, header._magic); |
331 classes_jsa, header._magic, CDS_ARCHIVE_MAGIC); |
390 close(fd); |
332 close(fd); |
391 return false; |
333 return false; |
392 } |
334 } |
393 |
335 |
394 // check version |
336 // check version |
395 if (header._version != CURRENT_ARCHIVE_VERSION) { |
337 if (header._version != CURRENT_CDS_ARCHIVE_VERSION) { |
396 print_debug("%s has wrong shared archive file version %d, expecting %d\n", |
338 print_debug("%s has wrong shared archive file version %d, expecting %d\n", |
397 classes_jsa, header._version, CURRENT_ARCHIVE_VERSION); |
339 classes_jsa, header._version, CURRENT_CDS_ARCHIVE_VERSION); |
398 close(fd); |
340 close(fd); |
399 return false; |
341 return false; |
400 } |
342 } |
401 |
343 |
402 ph->core->classes_jsa_fd = fd; |
344 ph->core->classes_jsa_fd = fd; |
403 // add read-only maps from classes.jsa to the list of maps |
345 // add read-only maps from classes.jsa to the list of maps |
404 for (m = 0; m < NUM_SHARED_MAPS; m++) { |
346 for (m = 0; m < NUM_CDS_REGIONS; m++) { |
405 if (header._space[m]._read_only) { |
347 if (header._space[m]._read_only) { |
406 base = (uintptr_t) header._space[m]._addr._base; |
348 base = (uintptr_t) header._space[m]._addr._base; |
407 // no need to worry about the fractional pages at-the-end. |
349 // no need to worry about the fractional pages at-the-end. |
408 // possible fractional pages are handled by core_read_data. |
350 // possible fractional pages are handled by core_read_data. |
409 add_class_share_map_info(ph, (off_t) header._space[m]._file_offset, |
351 add_class_share_map_info(ph, (off_t) header._space[m]._file_offset, |