Wed, 06 Jul 2011 18:15:21 -0700
7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
Summary: do explicit lookup emulating old LD_LIBRARY_PATH search
Reviewed-by: kvn, jrose
src/share/tools/hsdis/README | file | annotate | diff | comparison | revisions | |
src/share/vm/compiler/disassembler.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/tools/hsdis/README Wed Jul 06 09:27:54 2011 -0700 1.2 +++ b/src/share/tools/hsdis/README Wed Jul 06 18:15:21 2011 -0700 1.3 @@ -75,8 +75,16 @@ 1.4 * Installing 1.5 1.6 Products are named like build/$OS-$LIBARCH/hsdis-$LIBARCH.so. You can 1.7 -install them on your LD_LIBRARY_PATH, or inside of your JRE next to 1.8 -$LIBARCH/libjvm.so. 1.9 +install them on your LD_LIBRARY_PATH, or inside of your JRE/JDK. The 1.10 +search path in the JVM is: 1.11 + 1.12 +1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so 1.13 +2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so 1.14 +3. <home>/jre/lib/<arch>/hsdis-<arch>.so 1.15 +4. hsdis-<arch>.so (using LD_LIBRARY_PATH) 1.16 + 1.17 +Note that there's a bug in hotspot versions prior to hs22 that causes 1.18 +steps 2 and 3 to fail when used with JDK7. 1.19 1.20 Now test: 1.21
2.1 --- a/src/share/vm/compiler/disassembler.cpp Wed Jul 06 09:27:54 2011 -0700 2.2 +++ b/src/share/vm/compiler/disassembler.cpp Wed Jul 06 18:15:21 2011 -0700 2.3 @@ -78,21 +78,46 @@ 2.4 char buf[JVM_MAXPATHLEN]; 2.5 os::jvm_path(buf, sizeof(buf)); 2.6 int jvm_offset = -1; 2.7 + int lib_offset = -1; 2.8 { 2.9 // Match "jvm[^/]*" in jvm_path. 2.10 const char* base = buf; 2.11 const char* p = strrchr(buf, '/'); 2.12 + if (p != NULL) lib_offset = p - base + 1; 2.13 p = strstr(p ? p : base, "jvm"); 2.14 if (p != NULL) jvm_offset = p - base; 2.15 } 2.16 + // Find the disassembler shared library. 2.17 + // Search for several paths derived from libjvm, in this order: 2.18 + // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so (for compatibility) 2.19 + // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so 2.20 + // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so 2.21 + // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) 2.22 if (jvm_offset >= 0) { 2.23 - // Find the disassembler next to libjvm.so. 2.24 + // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so 2.25 strcpy(&buf[jvm_offset], hsdis_library_name); 2.26 strcat(&buf[jvm_offset], os::dll_file_extension()); 2.27 _library = os::dll_load(buf, ebuf, sizeof ebuf); 2.28 + if (_library == NULL) { 2.29 + // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so 2.30 + strcpy(&buf[lib_offset], hsdis_library_name); 2.31 + strcat(&buf[lib_offset], os::dll_file_extension()); 2.32 + _library = os::dll_load(buf, ebuf, sizeof ebuf); 2.33 + } 2.34 + if (_library == NULL) { 2.35 + // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so 2.36 + buf[lib_offset - 1] = '\0'; 2.37 + const char* p = strrchr(buf, '/'); 2.38 + if (p != NULL) { 2.39 + lib_offset = p - buf + 1; 2.40 + strcpy(&buf[lib_offset], hsdis_library_name); 2.41 + strcat(&buf[lib_offset], os::dll_file_extension()); 2.42 + _library = os::dll_load(buf, ebuf, sizeof ebuf); 2.43 + } 2.44 + } 2.45 } 2.46 if (_library == NULL) { 2.47 - // Try a free-floating lookup. 2.48 + // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) 2.49 strcpy(&buf[0], hsdis_library_name); 2.50 strcat(&buf[0], os::dll_file_extension()); 2.51 _library = os::dll_load(buf, ebuf, sizeof ebuf); 2.52 @@ -249,7 +274,13 @@ 2.53 return arg; 2.54 } 2.55 } else if (match(event, "mach")) { 2.56 - output()->print_cr("[Disassembling for mach='%s']", arg); 2.57 + static char buffer[32] = { 0, }; 2.58 + if (strcmp(buffer, (const char*)arg) != 0 || 2.59 + strlen((const char*)arg) > sizeof(buffer) - 1) { 2.60 + // Only print this when the mach changes 2.61 + strncpy(buffer, (const char*)arg, sizeof(buffer) - 1); 2.62 + output()->print_cr("[Disassembling for mach='%s']", arg); 2.63 + } 2.64 } else if (match(event, "format bytes-per-line")) { 2.65 _bytes_per_line = (int) (intptr_t) arg; 2.66 } else {