< prev index next >

src/jdk.hotspot.agent/solaris/native/libsaproc/saproc.cpp

Print this page




  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  *
  23  */
  24 
  25 #include "salibproc.h"
  26 #include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h"
  27 #include <thread_db.h>
  28 #include <strings.h>
  29 #include <limits.h>
  30 #include <demangle.h>
  31 #include <stdarg.h>
  32 #include <stdlib.h>
  33 #include <errno.h>

  34 
  35 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
  36 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
  37 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; }
  38 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;}
  39 
  40 #define SYMBOL_BUF_SIZE  256
  41 #define ERR_MSG_SIZE     (PATH_MAX + 256)
  42 
  43 // debug modes
  44 static int _libsaproc_debug = 0;
  45 
  46 static void print_debug(const char* format,...) {
  47   if (_libsaproc_debug) {
  48     va_list alist;
  49 
  50     va_start(alist, format);
  51     fputs("libsaproc DEBUG: ", stderr);
  52     vfprintf(stderr, format, alist);
  53     va_end(alist);


 156   env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)0);
 157   env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)0);
 158 }
 159 
 160 
 161 static void detach_internal(JNIEnv* env, jobject this_obj) {
 162   // clear libthread_db stuff
 163   clear_libthread_db_ptrs(env, this_obj);
 164 
 165   // release ptr to ps_prochandle
 166   jlong p_ps_prochandle;
 167   p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
 168   if (p_ps_prochandle != 0L) {
 169     Prelease((struct ps_prochandle*) p_ps_prochandle, PRELEASE_CLEAR);
 170   }
 171 
 172   // part of the class sharing workaround
 173   int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
 174   if (classes_jsa_fd != -1) {
 175     close(classes_jsa_fd);
 176     struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID);
 177     if (pheader != NULL) {
 178       free(pheader);
 179     }
 180   }
 181 }
 182 
 183 // Is it okay to ignore libthread_db failure? Set env var to ignore
 184 // libthread_db failure. You can still debug, but will miss threads
 185 // related functionality.
 186 static bool sa_ignore_threaddb = (getenv("SA_IGNORE_THREADDB") != 0);
 187 
 188 #define HANDLE_THREADDB_FAILURE(msg)          \
 189   if (sa_ignore_threaddb) {                   \
 190      printf("libsaproc WARNING: %s\n", msg);  \
 191      return;                                  \
 192   } else {                                    \
 193      THROW_NEW_DEBUGGER_EXCEPTION(msg);       \
 194   }
 195 
 196 #define HANDLE_THREADDB_FAILURE_(msg, ret)    \


 467   jlong pc = (jlong) (uintptr_t) regs[pcRegIndex];
 468   jlong fp = (jlong) (uintptr_t) regs[fpRegIndex];
 469 
 470   dbgo2->obj2 = env->CallObjectMethod(this_obj, createSenderFrame_ID,
 471                                     curFrame, pc, fp);
 472   CHECK_EXCEPTION_(1);
 473   if (dbgo2->obj == 0) {
 474      dbgo2->obj = dbgo2->obj2;
 475   }
 476   return 0;
 477 }
 478 
 479 // Pstack_iter() proc_stack_f callback in Nevada-B159 or later
 480 /*ARGSUSED*/
 481 static int
 482 wrapper_fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc,
 483                          const long *argv, int frame_flags, int sig) {
 484   return(fill_cframe_list(cd, regs, argc, argv));
 485 }
 486 
 487 // part of the class sharing workaround
 488 
 489 // FIXME: !!HACK ALERT!!
 490 
 491 // The format of sharing achive file header is needed to read shared heap
 492 // file mappings. For now, I am hard coding portion of FileMapHeader here.
 493 // Refer to filemap.hpp.
 494 
 495 // FileMapHeader describes the shared space data in the file to be
 496 // mapped.  This structure gets written to a file.  It is not a class, so
 497 // that the compilers don't add any compiler-private data to it.
 498 
 499 const int NUM_SHARED_MAPS = 9;
 500 
 501 // Refer to FileMapInfo::_current_version in filemap.hpp
 502 const int CURRENT_ARCHIVE_VERSION = 3;
 503 
 504 typedef unsigned char* address;
 505 typedef uintptr_t      uintx;
 506 typedef intptr_t       intx;
 507 
 508 struct FileMapHeader {
 509   int     _magic;                   // identify file type.
 510   int     _crc;                     // header crc checksum.
 511   int     _version;                 // (from enum, above.)
 512   size_t  _alignment;               // how shared archive should be aligned
 513   int     _obj_alignment;           // value of ObjectAlignmentInBytes
 514   address _narrow_oop_base;         // compressed oop encoding base
 515   int     _narrow_oop_shift;        // compressed oop encoding shift
 516   bool    _compact_strings;         // value of CompactStrings
 517   uintx   _max_heap_size;           // java max heap size during dumping
 518   int     _narrow_oop_mode;         // compressed oop encoding mode
 519   int     _narrow_klass_shift;      // save narrow klass base and shift
 520   address _narrow_klass_base;
 521   char*   _misc_data_patching_start;
 522   char*   _read_only_tables_start;
 523   address _cds_i2i_entry_code_buffers;
 524   size_t  _cds_i2i_entry_code_buffers_size;
 525   size_t  _core_spaces_size;        // number of bytes allocated by the core spaces
 526                                     // (mc, md, ro, rw and od).
 527 
 528 
 529   struct space_info {
 530     int     _crc;          // crc checksum of the current space
 531     size_t  _file_offset;  // sizeof(this) rounded to vm page size
 532     union {
 533       char*  _base;        // copy-on-write base address
 534       intx   _offset;      // offset from the compressed oop encoding base, only used
 535                            // by archive heap space
 536     } _addr;
 537     size_t _used;          // for setting space top on read
 538     // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
 539     // the C type matching the C++ bool type on any given platform.
 540     // We assume the corresponding C type is char but licensees
 541     // may need to adjust the type of these fields.
 542     char   _read_only;     // read only space?
 543     char   _allow_exec;    // executable code in space?
 544   } _space[NUM_SHARED_MAPS];
 545 
 546 // Ignore the rest of the FileMapHeader. We don't need those fields here.
 547 };
 548 
 549 static bool
 550 read_jboolean(struct ps_prochandle* ph, psaddr_t addr, jboolean* pvalue) {
 551   jboolean i;
 552   if (ps_pread(ph, addr, &i, sizeof(i)) == PS_OK) {
 553     *pvalue = i;
 554     return true;
 555   } else {
 556     return false;
 557   }
 558 }
 559 
 560 static bool
 561 read_pointer(struct ps_prochandle* ph, psaddr_t addr, uintptr_t* pvalue) {
 562   uintptr_t uip;
 563   if (ps_pread(ph, addr, &uip, sizeof(uip)) == PS_OK) {
 564     *pvalue = uip;
 565     return true;
 566   } else {
 567     return false;


 645   }
 646 
 647   if (read_string(ph, (psaddr_t)sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
 648     print_debug("can't find read 'Arguments::SharedArchivePath' value\n");
 649     THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1);
 650   }
 651 
 652   print_debug("looking for %s\n", classes_jsa);
 653 
 654   // open the classes.jsa
 655   int fd = libsaproc_open(classes_jsa, O_RDONLY);
 656   if (fd < 0) {
 657     char errMsg[ERR_MSG_SIZE];
 658     sprintf(errMsg, "can't open shared archive file %s", classes_jsa);
 659     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 660   } else {
 661     print_debug("opened shared archive file %s\n", classes_jsa);
 662   }
 663 
 664   // parse classes.jsa
 665   struct FileMapHeader* pheader = (struct FileMapHeader*) malloc(sizeof(struct FileMapHeader));
 666   if (pheader == NULL) {
 667     close(fd);
 668     THROW_NEW_DEBUGGER_EXCEPTION_("can't allocate memory for shared file map header", 1);
 669   }
 670 
 671   memset(pheader, 0, sizeof(struct FileMapHeader));
 672   // read FileMapHeader
 673   size_t n = read(fd, pheader, sizeof(struct FileMapHeader));
 674   if (n != sizeof(struct FileMapHeader)) {
 675     char errMsg[ERR_MSG_SIZE];
 676     sprintf(errMsg, "unable to read shared archive file map header from %s", classes_jsa);
 677     close(fd);
 678     free(pheader);
 679     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 680   }
 681 
 682   // check file magic
 683   if (pheader->_magic != 0xf00baba2) {
 684     char errMsg[ERR_MSG_SIZE];
 685     sprintf(errMsg, "%s has bad shared archive magic 0x%x, expecting 0xf00baba2",
 686                    classes_jsa, pheader->_magic);
 687     close(fd);
 688     free(pheader);
 689     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 690   }
 691 
 692   // check version
 693   if (pheader->_version != CURRENT_ARCHIVE_VERSION) {
 694     char errMsg[ERR_MSG_SIZE];
 695     sprintf(errMsg, "%s has wrong shared archive version %d, expecting %d",
 696                    classes_jsa, pheader->_version, CURRENT_ARCHIVE_VERSION);
 697     close(fd);
 698     free(pheader);
 699     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 700   }
 701 
 702   if (_libsaproc_debug) {
 703     for (int m = 0; m < NUM_SHARED_MAPS; m++) {
 704        print_debug("shared file offset %d mapped at 0x%lx, size = %ld, read only? = %d\n",
 705           pheader->_space[m]._file_offset, pheader->_space[m]._addr._base,
 706           pheader->_space[m]._used, pheader->_space[m]._read_only);
 707     }
 708   }
 709 
 710   // FIXME: For now, omitting other checks such as VM version etc.
 711 
 712   // store class archive file fd and map header in debugger object fields
 713   dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, fd);
 714   dbg->env->SetLongField(this_obj, p_file_map_header_ID, (jlong)(uintptr_t) pheader);
 715   return 1;
 716 }
 717 
 718 } // extern "C"
 719 
 720 // error messages for proc_arg_grab failure codes. The messages are
 721 // modified versions of comments against corresponding #defines in
 722 // libproc.h.
 723 static const char* proc_arg_grab_errmsgs[] = {


1080  */
1081 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_readBytesFromProcess0
1082   (JNIEnv *env, jobject this_obj, jlong address, jlong numBytes) {
1083 
1084   jbyteArray array = env->NewByteArray(numBytes);
1085   CHECK_EXCEPTION_(0);
1086   jboolean isCopy;
1087   jbyte* bufPtr = env->GetByteArrayElements(array, &isCopy);
1088   CHECK_EXCEPTION_(0);
1089 
1090   jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
1091   ps_err_e ret = ps_pread((struct ps_prochandle*) p_ps_prochandle,
1092                        (psaddr_t)address, bufPtr, (size_t)numBytes);
1093 
1094   if (ret != PS_OK) {
1095     // part of the class sharing workaround. try shared heap area
1096     int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
1097     if (classes_jsa_fd != -1 && address != (jlong)0) {
1098       print_debug("read failed at 0x%lx, attempting shared heap area\n", (long) address);
1099 
1100       struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID);
1101       // walk through the shared mappings -- we just have 9 of them.
1102       // so, linear walking is okay.
1103       for (int m = 0; m < NUM_SHARED_MAPS; m++) {
1104 
1105         // We can skip the non-read-only maps. These are mapped as MAP_PRIVATE
1106         // and hence will be read by libproc. Besides, the file copy may be
1107         // stale because the process might have modified those pages.
1108         if (pheader->_space[m]._read_only) {
1109           jlong baseAddress = (jlong) (uintptr_t) pheader->_space[m]._addr._base;
1110           size_t usedSize = pheader->_space[m]._used;
1111           if (address >= baseAddress && address < (baseAddress + usedSize)) {
1112             // the given address falls in this shared heap area
1113             print_debug("found shared map at 0x%lx\n", (long) baseAddress);
1114 
1115 
1116             // If more data is asked than actually mapped from file, we need to zero fill
1117             // till the end-of-page boundary. But, java array new does that for us. we just
1118             // need to read as much as data available.
1119 
1120 #define MIN2(x, y) (((x) < (y))? (x) : (y))
1121 
1122             jlong diff = address - baseAddress;
1123             jlong bytesToRead = MIN2(numBytes, usedSize - diff);




  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  *
  23  */
  24 
  25 #include "salibproc.h"
  26 #include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h"
  27 #include <thread_db.h>
  28 #include <strings.h>
  29 #include <limits.h>
  30 #include <demangle.h>
  31 #include <stdarg.h>
  32 #include <stdlib.h>
  33 #include <errno.h>
  34 #include "cds.h"
  35 
  36 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
  37 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
  38 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; }
  39 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;}
  40 
  41 #define SYMBOL_BUF_SIZE  256
  42 #define ERR_MSG_SIZE     (PATH_MAX + 256)
  43 
  44 // debug modes
  45 static int _libsaproc_debug = 0;
  46 
  47 static void print_debug(const char* format,...) {
  48   if (_libsaproc_debug) {
  49     va_list alist;
  50 
  51     va_start(alist, format);
  52     fputs("libsaproc DEBUG: ", stderr);
  53     vfprintf(stderr, format, alist);
  54     va_end(alist);


 157   env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)0);
 158   env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)0);
 159 }
 160 
 161 
 162 static void detach_internal(JNIEnv* env, jobject this_obj) {
 163   // clear libthread_db stuff
 164   clear_libthread_db_ptrs(env, this_obj);
 165 
 166   // release ptr to ps_prochandle
 167   jlong p_ps_prochandle;
 168   p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
 169   if (p_ps_prochandle != 0L) {
 170     Prelease((struct ps_prochandle*) p_ps_prochandle, PRELEASE_CLEAR);
 171   }
 172 
 173   // part of the class sharing workaround
 174   int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
 175   if (classes_jsa_fd != -1) {
 176     close(classes_jsa_fd);
 177     CDSFileMapHeaderBase* pheader = (CDSFileMapHeaderBase*) env->GetLongField(this_obj, p_file_map_header_ID);
 178     if (pheader != NULL) {
 179       free(pheader);
 180     }
 181   }
 182 }
 183 
 184 // Is it okay to ignore libthread_db failure? Set env var to ignore
 185 // libthread_db failure. You can still debug, but will miss threads
 186 // related functionality.
 187 static bool sa_ignore_threaddb = (getenv("SA_IGNORE_THREADDB") != 0);
 188 
 189 #define HANDLE_THREADDB_FAILURE(msg)          \
 190   if (sa_ignore_threaddb) {                   \
 191      printf("libsaproc WARNING: %s\n", msg);  \
 192      return;                                  \
 193   } else {                                    \
 194      THROW_NEW_DEBUGGER_EXCEPTION(msg);       \
 195   }
 196 
 197 #define HANDLE_THREADDB_FAILURE_(msg, ret)    \


 468   jlong pc = (jlong) (uintptr_t) regs[pcRegIndex];
 469   jlong fp = (jlong) (uintptr_t) regs[fpRegIndex];
 470 
 471   dbgo2->obj2 = env->CallObjectMethod(this_obj, createSenderFrame_ID,
 472                                     curFrame, pc, fp);
 473   CHECK_EXCEPTION_(1);
 474   if (dbgo2->obj == 0) {
 475      dbgo2->obj = dbgo2->obj2;
 476   }
 477   return 0;
 478 }
 479 
 480 // Pstack_iter() proc_stack_f callback in Nevada-B159 or later
 481 /*ARGSUSED*/
 482 static int
 483 wrapper_fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc,
 484                          const long *argv, int frame_flags, int sig) {
 485   return(fill_cframe_list(cd, regs, argc, argv));
 486 }
 487 
 488 //---------------------------------------------------------------
 489 // Part of the class sharing workaround:
 490 //
 491 // With class sharing, pages are mapped from classes.jsa file.
 492 // The read-only class sharing pages are mapped as MAP_SHARED,
 493 // PROT_READ pages. These pages are not dumped into core dump.
 494 // With this workaround, these pages are read from classes.jsa.






















































 495 
 496 static bool
 497 read_jboolean(struct ps_prochandle* ph, psaddr_t addr, jboolean* pvalue) {
 498   jboolean i;
 499   if (ps_pread(ph, addr, &i, sizeof(i)) == PS_OK) {
 500     *pvalue = i;
 501     return true;
 502   } else {
 503     return false;
 504   }
 505 }
 506 
 507 static bool
 508 read_pointer(struct ps_prochandle* ph, psaddr_t addr, uintptr_t* pvalue) {
 509   uintptr_t uip;
 510   if (ps_pread(ph, addr, &uip, sizeof(uip)) == PS_OK) {
 511     *pvalue = uip;
 512     return true;
 513   } else {
 514     return false;


 592   }
 593 
 594   if (read_string(ph, (psaddr_t)sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
 595     print_debug("can't find read 'Arguments::SharedArchivePath' value\n");
 596     THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1);
 597   }
 598 
 599   print_debug("looking for %s\n", classes_jsa);
 600 
 601   // open the classes.jsa
 602   int fd = libsaproc_open(classes_jsa, O_RDONLY);
 603   if (fd < 0) {
 604     char errMsg[ERR_MSG_SIZE];
 605     sprintf(errMsg, "can't open shared archive file %s", classes_jsa);
 606     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 607   } else {
 608     print_debug("opened shared archive file %s\n", classes_jsa);
 609   }
 610 
 611   // parse classes.jsa
 612   CDSFileMapHeaderBase* pheader = (CDSFileMapHeaderBase*) malloc(sizeof(CDSFileMapHeaderBase));
 613   if (pheader == NULL) {
 614     close(fd);
 615     THROW_NEW_DEBUGGER_EXCEPTION_("can't allocate memory for shared file map header", 1);
 616   }
 617 
 618   memset(pheader, 0, sizeof(CDSFileMapHeaderBase));
 619   // read CDSFileMapHeaderBase
 620   size_t n = read(fd, pheader, sizeof(CDSFileMapHeaderBase));
 621   if (n != sizeof(CDSFileMapHeaderBase)) {
 622     char errMsg[ERR_MSG_SIZE];
 623     sprintf(errMsg, "unable to read shared archive file map header from %s", classes_jsa);
 624     close(fd);
 625     free(pheader);
 626     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 627   }
 628 
 629   // check file magic
 630   if (pheader->_magic != CDS_ARCHIVE_MAGIC) {
 631     char errMsg[ERR_MSG_SIZE];
 632     sprintf(errMsg, "%s has bad shared archive magic 0x%x, expecting 0x%x",
 633             classes_jsa, pheader->_magic, CDS_ARCHIVE_MAGIC);
 634     close(fd);
 635     free(pheader);
 636     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 637   }
 638 
 639   // check version
 640   if (pheader->_version != CURRENT_CDS_ARCHIVE_VERSION) {
 641     char errMsg[ERR_MSG_SIZE];
 642     sprintf(errMsg, "%s has wrong shared archive version %d, expecting %d",
 643                    classes_jsa, pheader->_version, CURRENT_CDS_ARCHIVE_VERSION);
 644     close(fd);
 645     free(pheader);
 646     THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
 647   }
 648 
 649   if (_libsaproc_debug) {
 650     for (int m = 0; m < NUM_CDS_REGIONS; m++) {
 651        print_debug("shared file offset %d mapped at 0x%lx, size = %ld, read only? = %d\n",
 652           pheader->_space[m]._file_offset, pheader->_space[m]._addr._base,
 653           pheader->_space[m]._used, pheader->_space[m]._read_only);
 654     }
 655   }
 656 
 657   // FIXME: For now, omitting other checks such as VM version etc.
 658 
 659   // store class archive file fd and map header in debugger object fields
 660   dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, fd);
 661   dbg->env->SetLongField(this_obj, p_file_map_header_ID, (jlong)(uintptr_t) pheader);
 662   return 1;
 663 }
 664 
 665 } // extern "C"
 666 
 667 // error messages for proc_arg_grab failure codes. The messages are
 668 // modified versions of comments against corresponding #defines in
 669 // libproc.h.
 670 static const char* proc_arg_grab_errmsgs[] = {


1027  */
1028 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_readBytesFromProcess0
1029   (JNIEnv *env, jobject this_obj, jlong address, jlong numBytes) {
1030 
1031   jbyteArray array = env->NewByteArray(numBytes);
1032   CHECK_EXCEPTION_(0);
1033   jboolean isCopy;
1034   jbyte* bufPtr = env->GetByteArrayElements(array, &isCopy);
1035   CHECK_EXCEPTION_(0);
1036 
1037   jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
1038   ps_err_e ret = ps_pread((struct ps_prochandle*) p_ps_prochandle,
1039                        (psaddr_t)address, bufPtr, (size_t)numBytes);
1040 
1041   if (ret != PS_OK) {
1042     // part of the class sharing workaround. try shared heap area
1043     int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
1044     if (classes_jsa_fd != -1 && address != (jlong)0) {
1045       print_debug("read failed at 0x%lx, attempting shared heap area\n", (long) address);
1046 
1047       CDSFileMapHeaderBase* pheader = (CDSFileMapHeaderBase*) env->GetLongField(this_obj, p_file_map_header_ID);
1048       // walk through the shared mappings -- we just have 9 of them.
1049       // so, linear walking is okay.
1050       for (int m = 0; m < NUM_CDS_REGIONS; m++) {
1051 
1052         // We can skip the non-read-only maps. These are mapped as MAP_PRIVATE
1053         // and hence will be read by libproc. Besides, the file copy may be
1054         // stale because the process might have modified those pages.
1055         if (pheader->_space[m]._read_only) {
1056           jlong baseAddress = (jlong) (uintptr_t) pheader->_space[m]._addr._base;
1057           size_t usedSize = pheader->_space[m]._used;
1058           if (address >= baseAddress && address < (baseAddress + usedSize)) {
1059             // the given address falls in this shared heap area
1060             print_debug("found shared map at 0x%lx\n", (long) baseAddress);
1061 
1062 
1063             // If more data is asked than actually mapped from file, we need to zero fill
1064             // till the end-of-page boundary. But, java array new does that for us. we just
1065             // need to read as much as data available.
1066 
1067 #define MIN2(x, y) (((x) < (y))? (x) : (y))
1068 
1069             jlong diff = address - baseAddress;
1070             jlong bytesToRead = MIN2(numBytes, usedSize - diff);


< prev index next >