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