< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c

Print this page




 195   return (NULL);
 196 }
 197 
 198 //---------------------------------------------------------------
 199 // Part of the class sharing workaround:
 200 //
 201 // With class sharing, pages are mapped from classes.jsa file.
 202 // The read-only class sharing pages are mapped as MAP_SHARED,
 203 // PROT_READ pages. These pages are not dumped into core dump.
 204 // With this workaround, these pages are read from classes.jsa.
 205 
 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 4
 216 
 217 // Refer to FileMapInfo::_current_version in filemap.hpp
 218 #define CURRENT_ARCHIVE_VERSION 1




 219 
 220 struct FileMapHeader {
 221   int   _magic;              // identify file type.

 222   int   _version;            // (from enum, above.)
 223   size_t _alignment;         // how shared archive should be aligned















 224 
 225   struct space_info {
 226     int    _file_offset;     // sizeof(this) rounded to vm page size


 227     char*  _base;            // copy-on-write base address
 228     size_t _capacity;        // for validity checking


 229     size_t _used;            // for setting space top on read
 230 
 231     // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
 232     // the C type matching the C++ bool type on any given platform.
 233     // We assume the corresponding C type is char but licensees
 234     // may need to adjust the type of these fields.
 235     char   _read_only;       // read only space?
 236     char   _allow_exec;      // executable code in space?
 237 
 238   } _space[NUM_SHARED_MAPS];
 239 
 240   // Ignore the rest of the FileMapHeader. We don't need those fields here.
 241 };
 242 
 243 static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
 244   jboolean i;
 245   if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
 246     *pvalue = i;
 247     return true;
 248   } else {
 249     return false;
 250   }
 251 }
 252 
 253 static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
 254   uintptr_t uip;
 255   if (ps_pdread(ph, (psaddr_t) addr, (char *)&uip, sizeof(uip)) == PS_OK) {
 256     *pvalue = uip;
 257     return true;


 364       // check file magic
 365       if (header._magic != 0xf00baba2) {
 366         print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n",
 367                      classes_jsa, header._magic);
 368         close(fd);
 369         return false;
 370       }
 371 
 372       // check version
 373       if (header._version != CURRENT_ARCHIVE_VERSION) {
 374         print_debug("%s has wrong shared archive file version %d, expecting %d\n",
 375                      classes_jsa, header._version, CURRENT_ARCHIVE_VERSION);
 376         close(fd);
 377         return false;
 378       }
 379 
 380       ph->core->classes_jsa_fd = fd;
 381       // add read-only maps from classes.jsa to the list of maps
 382       for (m = 0; m < NUM_SHARED_MAPS; m++) {
 383         if (header._space[m]._read_only) {
 384           base = (uintptr_t) header._space[m]._base;
 385           // no need to worry about the fractional pages at-the-end.
 386           // possible fractional pages are handled by core_read_data.
 387           add_class_share_map_info(ph, (off_t) header._space[m]._file_offset,
 388                                    base, (size_t) header._space[m]._used);
 389           print_debug("added a share archive map at 0x%lx\n", base);
 390         }
 391       }
 392       return true;
 393    }
 394    lib = lib->next;
 395   }
 396   return true;
 397 }
 398 
 399 
 400 //---------------------------------------------------------------------------
 401 // functions to handle map_info
 402 
 403 // Order mappings based on virtual address.  We use this function as the
 404 // callback for sorting the array of map_info pointers.




 195   return (NULL);
 196 }
 197 
 198 //---------------------------------------------------------------
 199 // Part of the class sharing workaround:
 200 //
 201 // With class sharing, pages are mapped from classes.jsa file.
 202 // The read-only class sharing pages are mapped as MAP_SHARED,
 203 // PROT_READ pages. These pages are not dumped into core dump.
 204 // With this workaround, these pages are read from classes.jsa.
 205 
 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) {
 266   jboolean i;
 267   if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
 268     *pvalue = i;
 269     return true;
 270   } else {
 271     return false;
 272   }
 273 }
 274 
 275 static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
 276   uintptr_t uip;
 277   if (ps_pdread(ph, (psaddr_t) addr, (char *)&uip, sizeof(uip)) == PS_OK) {
 278     *pvalue = uip;
 279     return true;


 386       // check file magic
 387       if (header._magic != 0xf00baba2) {
 388         print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n",
 389                      classes_jsa, header._magic);
 390         close(fd);
 391         return false;
 392       }
 393 
 394       // check version
 395       if (header._version != CURRENT_ARCHIVE_VERSION) {
 396         print_debug("%s has wrong shared archive file version %d, expecting %d\n",
 397                      classes_jsa, header._version, CURRENT_ARCHIVE_VERSION);
 398         close(fd);
 399         return false;
 400       }
 401 
 402       ph->core->classes_jsa_fd = fd;
 403       // add read-only maps from classes.jsa to the list of maps
 404       for (m = 0; m < NUM_SHARED_MAPS; m++) {
 405         if (header._space[m]._read_only) {
 406           base = (uintptr_t) header._space[m]._addr._base;
 407           // no need to worry about the fractional pages at-the-end.
 408           // possible fractional pages are handled by core_read_data.
 409           add_class_share_map_info(ph, (off_t) header._space[m]._file_offset,
 410                                    base, (size_t) header._space[m]._used);
 411           print_debug("added a share archive map at 0x%lx\n", base);
 412         }
 413       }
 414       return true;
 415    }
 416    lib = lib->next;
 417   }
 418   return true;
 419 }
 420 
 421 
 422 //---------------------------------------------------------------------------
 423 // functions to handle map_info
 424 
 425 // Order mappings based on virtual address.  We use this function as the
 426 // callback for sorting the array of map_info pointers.


< prev index next >