--- old/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c 2018-08-17 13:58:45.295787900 -0700 +++ new/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c 2018-08-17 13:58:44.907773026 -0700 @@ -32,6 +32,7 @@ #include #include "libproc_impl.h" #include "salibelf.h" +#include "../../../../hotspot/share/include/cds.h" // This file has the libproc implementation to read core files. // For live processes, refer to ps_proc.c. Portions of this is adapted @@ -203,64 +204,7 @@ // PROT_READ pages. These pages are not dumped into core dump. // With this workaround, these pages are read from classes.jsa. -// FIXME: !HACK ALERT! -// The format of sharing achive file header is needed to read shared heap -// file mappings. For now, I am hard coding portion of FileMapHeader here. -// Refer to filemap.hpp. - -// FileMapHeader describes the shared space data in the file to be -// mapped. This structure gets written to a file. It is not a class, -// so that the compilers don't add any compiler-private data to it. - -#define NUM_SHARED_MAPS 9 - -// Refer to FileMapInfo::_current_version in filemap.hpp -#define CURRENT_ARCHIVE_VERSION 3 - -typedef unsigned char* address; -typedef uintptr_t uintx; -typedef intptr_t intx; - -struct FileMapHeader { - int _magic; // identify file type. - int _crc; // header crc checksum. - int _version; // (from enum, above.) - size_t _alignment; // how shared archive should be aligned - int _obj_alignment; // value of ObjectAlignmentInBytes - address _narrow_oop_base; // compressed oop encoding base - int _narrow_oop_shift; // compressed oop encoding shift - bool _compact_strings; // value of CompactStrings - uintx _max_heap_size; // java max heap size during dumping - int _narrow_oop_mode; // compressed oop encoding mode - int _narrow_klass_shift; // save narrow klass base and shift - address _narrow_klass_base; - char* _misc_data_patching_start; - char* _read_only_tables_start; - address _cds_i2i_entry_code_buffers; - size_t _cds_i2i_entry_code_buffers_size; - size_t _core_spaces_size; // number of bytes allocated by the core spaces - // (mc, md, ro, rw and od). - - - struct space_info { - int _crc; // crc checksum of the current space - size_t _file_offset; // sizeof(this) rounded to vm page size - union { - char* _base; // copy-on-write base address - intx _offset; // offset from the compressed oop encoding base, only used - // by archive heap space - } _addr; - size_t _used; // for setting space top on read - // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with - // the C type matching the C++ bool type on any given platform. - // We assume the corresponding C type is char but licensees - // may need to adjust the type of these fields. - char _read_only; // read only space? - char _allow_exec; // executable code in space? - } _space[NUM_SHARED_MAPS]; - - // Ignore the rest of the FileMapHeader. We don't need those fields here. -}; +typedef struct CDSFileMapHeaderBase FileMapHeader; static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) { jboolean i; @@ -317,7 +261,7 @@ const char *jvm_name = 0; if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { char classes_jsa[PATH_MAX]; - struct FileMapHeader header; + FileMapHeader header; int fd = -1; int m = 0; size_t n = 0; @@ -375,33 +319,33 @@ } // read FileMapHeader from the file - memset(&header, 0, sizeof(struct FileMapHeader)); - if ((n = read(fd, &header, sizeof(struct FileMapHeader))) - != sizeof(struct FileMapHeader)) { + memset(&header, 0, sizeof(FileMapHeader)); + if ((n = read(fd, &header, sizeof(FileMapHeader))) + != sizeof(FileMapHeader)) { print_debug("can't read shared archive file map header from %s\n", classes_jsa); close(fd); return false; } // check file magic - if (header._magic != 0xf00baba2) { - print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n", - classes_jsa, header._magic); + if (header._magic != CDS_ARCHIVE_MAGIC) { + print_debug("%s has bad shared archive file magic number 0x%x, expecing 0x%x\n", + classes_jsa, header._magic, CDS_ARCHIVE_MAGIC); close(fd); return false; } // check version - if (header._version != CURRENT_ARCHIVE_VERSION) { + if (header._version != CURRENT_CDS_ARCHIVE_VERSION) { print_debug("%s has wrong shared archive file version %d, expecting %d\n", - classes_jsa, header._version, CURRENT_ARCHIVE_VERSION); + classes_jsa, header._version, CURRENT_CDS_ARCHIVE_VERSION); close(fd); return false; } ph->core->classes_jsa_fd = fd; // add read-only maps from classes.jsa to the list of maps - for (m = 0; m < NUM_SHARED_MAPS; m++) { + for (m = 0; m < NUM_CDS_REGIONS; m++) { if (header._space[m]._read_only) { base = (uintptr_t) header._space[m]._addr._base; // no need to worry about the fractional pages at-the-end.