536 buf[i] = '\0'; |
536 buf[i] = '\0'; |
537 return true; |
537 return true; |
538 } |
538 } |
539 |
539 |
540 #define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
540 #define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
|
541 #define SHARED_BASE_ADDRESS_SYM "SharedBaseAddress" |
541 // mangled symbol name for Arguments::SharedArchivePath |
542 // mangled symbol name for Arguments::SharedArchivePath |
542 #define SHARED_ARCHIVE_PATH_SYM "__1cJArgumentsRSharedArchivePath_" |
543 #define SHARED_ARCHIVE_PATH_SYM "__1cJArgumentsRSharedArchivePath_" |
543 |
544 |
|
545 static uintptr_t sharedBaseAddress = 0; |
544 static int |
546 static int |
545 init_classsharing_workaround(void *cd, const prmap_t* pmap, const char* obj_name) { |
547 init_classsharing_workaround(void *cd, const prmap_t* pmap, const char* obj_name) { |
546 Debugger* dbg = (Debugger*) cd; |
548 Debugger* dbg = (Debugger*) cd; |
547 JNIEnv* env = dbg->env; |
549 JNIEnv* env = dbg->env; |
548 jobject this_obj = dbg->this_obj; |
550 jobject this_obj = dbg->this_obj; |
575 } else if ((int)value == 0) { |
577 } else if ((int)value == 0) { |
576 print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
578 print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
577 return 1; |
579 return 1; |
578 } |
580 } |
579 |
581 |
|
582 psaddr_t sharedBaseAddressAddr = 0; |
|
583 ps_pglobal_lookup(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM, &sharedBaseAddressAddr); |
|
584 if (sharedBaseAddressAddr == 0) { |
|
585 print_debug("can't find symbol 'SharedBaseAddress'\n"); |
|
586 THROW_NEW_DEBUGGER_EXCEPTION_("can't find 'SharedBaseAddress' flag\n", 1); |
|
587 } |
|
588 |
|
589 sharedBaseAddress = 0; |
|
590 if (read_pointer(ph, sharedBaseAddressAddr, &sharedBaseAddress) != true) { |
|
591 print_debug("can't read the value of 'SharedBaseAddress' flag\n"); |
|
592 THROW_NEW_DEBUGGER_EXCEPTION_("can't get SharedBaseAddress from debuggee", 1); |
|
593 } |
|
594 |
580 char classes_jsa[PATH_MAX]; |
595 char classes_jsa[PATH_MAX]; |
581 psaddr_t sharedArchivePathAddrAddr = 0; |
596 psaddr_t sharedArchivePathAddrAddr = 0; |
582 ps_pglobal_lookup(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM, &sharedArchivePathAddrAddr); |
597 ps_pglobal_lookup(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM, &sharedArchivePathAddrAddr); |
583 if (sharedArchivePathAddrAddr == 0) { |
598 if (sharedArchivePathAddrAddr == 0) { |
584 print_debug("can't find symbol 'Arguments::SharedArchivePath'\n"); |
599 print_debug("can't find symbol 'Arguments::SharedArchivePath'\n"); |
646 THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
661 THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1); |
647 } |
662 } |
648 |
663 |
649 if (_libsaproc_debug) { |
664 if (_libsaproc_debug) { |
650 for (int m = 0; m < NUM_CDS_REGIONS; m++) { |
665 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", |
666 if (!pheader->_space[m]._is_heap_region && |
652 pheader->_space[m]._file_offset, pheader->_space[m]._addr._base, |
667 !pheader->_space[m]._is_bitmap_region) { |
653 pheader->_space[m]._used, pheader->_space[m]._read_only); |
668 jlong mapping_offset = pheader->_space[m]._mapping_offset; |
|
669 jlong baseAddress = mapping_offset + (jlong)sharedBaseAddress; |
|
670 print_debug("shared file offset %d mapped at 0x%lx, size = %ld, read only? = %d\n", |
|
671 pheader->_space[m]._file_offset, baseAddress, |
|
672 pheader->_space[m]._used, pheader->_space[m]._read_only); |
|
673 } |
654 } |
674 } |
655 } |
675 } |
656 |
676 |
657 // FIXME: For now, omitting other checks such as VM version etc. |
677 // FIXME: For now, omitting other checks such as VM version etc. |
658 |
678 |
1050 for (int m = 0; m < NUM_CDS_REGIONS; m++) { |
1070 for (int m = 0; m < NUM_CDS_REGIONS; m++) { |
1051 |
1071 |
1052 // We can skip the non-read-only maps. These are mapped as MAP_PRIVATE |
1072 // 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 |
1073 // and hence will be read by libproc. Besides, the file copy may be |
1054 // stale because the process might have modified those pages. |
1074 // stale because the process might have modified those pages. |
1055 if (pheader->_space[m]._read_only) { |
1075 if (pheader->_space[m]._read_only && |
1056 jlong baseAddress = (jlong) (uintptr_t) pheader->_space[m]._addr._base; |
1076 !pheader->_space[m]._is_heap_region && |
1057 size_t usedSize = pheader->_space[m]._used; |
1077 !pheader->_space[m]._is_bitmap_region) { |
1058 if (address >= baseAddress && address < (baseAddress + usedSize)) { |
1078 jlong mapping_offset = (jlong) (uintptr_t) pheader->_space[m]._mapping_offset; |
1059 // the given address falls in this shared heap area |
1079 jlong baseAddress = mapping_offset + (jlong)sharedBaseAddress; |
|
1080 size_t usedSize = pheader->_space[m]._used; |
|
1081 if (address >= baseAddress && address < (baseAddress + usedSize)) { |
|
1082 // the given address falls in this shared metadata area |
1060 print_debug("found shared map at 0x%lx\n", (long) baseAddress); |
1083 print_debug("found shared map at 0x%lx\n", (long) baseAddress); |
1061 |
1084 |
1062 |
1085 |
1063 // If more data is asked than actually mapped from file, we need to zero fill |
1086 // 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 |
1087 // till the end-of-page boundary. But, java array new does that for us. we just |