< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


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





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

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















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


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


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


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


   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


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


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


< prev index next >