Fri, 02 Nov 2012 13:30:47 -0700
8000489: older builds of hsdis don't work anymore after 6879063
Summary: The old function not defined properly, need a definition for export in dll. Also changes made to let new jvm work with old hsdis.
Reviewed-by: jrose, sspitsyn, kmo
Contributed-by: yumin.qi@oracle.com
1.1 --- a/src/share/tools/hsdis/hsdis-demo.c Fri Nov 02 07:44:11 2012 -0700 1.2 +++ b/src/share/tools/hsdis/hsdis-demo.c Fri Nov 02 13:30:47 2012 -0700 1.3 @@ -85,9 +85,11 @@ 1.4 1.5 #include "dlfcn.h" 1.6 1.7 -#define DECODE_INSTRUCTIONS_NAME "decode_instructions_virtual" 1.8 +#define DECODE_INSTRUCTIONS_VIRTUAL_NAME "decode_instructions_virtual" 1.9 +#define DECODE_INSTRUCTIONS_NAME "decode_instructions" 1.10 #define HSDIS_NAME "hsdis" 1.11 static void* decode_instructions_pv = 0; 1.12 +static void* decode_instructions_sv = 0; 1.13 static const char* hsdis_path[] = { 1.14 HSDIS_NAME"-"LIBARCH LIB_EXT, 1.15 "./" HSDIS_NAME"-"LIBARCH LIB_EXT, 1.16 @@ -101,11 +103,12 @@ 1.17 void* dllib = NULL; 1.18 const char* *next_in_path = hsdis_path; 1.19 while (1) { 1.20 - decode_instructions_pv = dlsym(dllib, DECODE_INSTRUCTIONS_NAME); 1.21 - if (decode_instructions_pv != NULL) 1.22 + decode_instructions_pv = dlsym(dllib, DECODE_INSTRUCTIONS_VIRTUAL_NAME); 1.23 + decode_instructions_sv = dlsym(dllib, DECODE_INSTRUCTIONS_NAME); 1.24 + if (decode_instructions_pv != NULL || decode_instructions_sv != NULL) 1.25 return NULL; 1.26 if (dllib != NULL) 1.27 - return "plugin does not defined "DECODE_INSTRUCTIONS_NAME; 1.28 + return "plugin does not defined "DECODE_INSTRUCTIONS_VIRTUAL_NAME" and "DECODE_INSTRUCTIONS_NAME; 1.29 for (dllib = NULL; dllib == NULL; ) { 1.30 const char* next_lib = (*next_in_path++); 1.31 if (next_lib == NULL) 1.32 @@ -213,20 +216,44 @@ 1.33 printf("%s: %s\n", err, dlerror()); 1.34 exit(1); 1.35 } 1.36 - printf("Decoding from %p to %p...\n", from, to); 1.37 - decode_instructions_ftype decode_instructions 1.38 - = (decode_instructions_ftype) decode_instructions_pv; 1.39 + decode_func_vtype decode_instructions_v 1.40 + = (decode_func_vtype) decode_instructions_pv; 1.41 + decode_func_stype decode_instructions_s 1.42 + = (decode_func_stype) decode_instructions_sv; 1.43 void* res; 1.44 - if (raw && xml) { 1.45 - res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options); 1.46 - } else if (raw) { 1.47 - res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options); 1.48 - } else { 1.49 - res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, 1.50 - handle_event, (void*) event_cookie, 1.51 - fprintf_callback, stdout, 1.52 - options); 1.53 + if (decode_instructions_pv != NULL) { 1.54 + printf("\nDecoding from %p to %p...with %s\n", from, to, DECODE_INSTRUCTIONS_VIRTUAL_NAME); 1.55 + if (raw) { 1.56 + res = (*decode_instructions_v)(from, to, 1.57 + (unsigned char*)from, to - from, 1.58 + simple_handle_event, stdout, 1.59 + NULL, stdout, 1.60 + options, 0); 1.61 + } else { 1.62 + res = (*decode_instructions_v)(from, to, 1.63 + (unsigned char*)from, to - from, 1.64 + handle_event, (void*) event_cookie, 1.65 + fprintf_callback, stdout, 1.66 + options, 0); 1.67 + } 1.68 + if (res != (void*)to) 1.69 + printf("*** Result was %p!\n", res); 1.70 } 1.71 - if (res != (void*)to) 1.72 - printf("*** Result was %p!\n", res); 1.73 + void* sres; 1.74 + if (decode_instructions_sv != NULL) { 1.75 + printf("\nDecoding from %p to %p...with old decode_instructions\n", from, to, DECODE_INSTRUCTIONS_NAME); 1.76 + if (raw) { 1.77 + sres = (*decode_instructions_s)(from, to, 1.78 + simple_handle_event, stdout, 1.79 + NULL, stdout, 1.80 + options); 1.81 + } else { 1.82 + sres = (*decode_instructions_s)(from, to, 1.83 + handle_event, (void*) event_cookie, 1.84 + fprintf_callback, stdout, 1.85 + options); 1.86 + } 1.87 + if (sres != (void *)to) 1.88 + printf("*** Result of decode_instructions %p!\n", sres); 1.89 + } 1.90 }
2.1 --- a/src/share/tools/hsdis/hsdis.c Fri Nov 02 07:44:11 2012 -0700 2.2 +++ b/src/share/tools/hsdis/hsdis.c Fri Nov 02 13:30:47 2012 -0700 2.3 @@ -99,7 +99,7 @@ 2.4 unsigned char* buffer, uintptr_t length, 2.5 event_callback_t event_callback_arg, void* event_stream_arg, 2.6 printf_callback_t printf_callback_arg, void* printf_stream_arg, 2.7 - const char* options) { 2.8 + const char* options, int newline) { 2.9 struct hsdis_app_data app_data; 2.10 memset(&app_data, 0, sizeof(app_data)); 2.11 app_data.start_va = start_va; 2.12 @@ -110,7 +110,7 @@ 2.13 app_data.event_stream = event_stream_arg; 2.14 app_data.printf_callback = printf_callback_arg; 2.15 app_data.printf_stream = printf_stream_arg; 2.16 - app_data.do_newline = false; 2.17 + app_data.do_newline = newline == 0 ? false : true; 2.18 2.19 return decode(&app_data, options); 2.20 } 2.21 @@ -132,7 +132,7 @@ 2.22 event_stream_arg, 2.23 printf_callback_arg, 2.24 printf_stream_arg, 2.25 - options); 2.26 + options, false); 2.27 } 2.28 2.29 static void* decode(struct hsdis_app_data* app_data, const char* options) { 2.30 @@ -173,7 +173,7 @@ 2.31 if (!app_data->losing) { 2.32 const char* insn_close = format_insn_close("/insn", &app_data->dinfo, 2.33 buf, sizeof(buf)); 2.34 - (*event_callback)(event_stream, insn_close, (void*) p) != NULL; 2.35 + (*event_callback)(event_stream, insn_close, (void*) p); 2.36 2.37 if (app_data->do_newline) { 2.38 /* follow each complete insn by a nice newline */ 2.39 @@ -182,13 +182,14 @@ 2.40 } 2.41 } 2.42 2.43 - (*event_callback)(event_stream, "/insns", (void*) p); 2.44 + if (app_data->losing) (*event_callback)(event_stream, "/insns", (void*) p); 2.45 return (void*) p; 2.46 } 2.47 } 2.48 2.49 /* take the address of the function, for luck, and also test the typedef: */ 2.50 -const decode_instructions_ftype decode_instructions_address = &decode_instructions_virtual; 2.51 +const decode_func_vtype decode_func_virtual_address = &decode_instructions_virtual; 2.52 +const decode_func_stype decode_func_address = &decode_instructions; 2.53 2.54 static const char* format_insn_close(const char* close, 2.55 disassemble_info* dinfo,
3.1 --- a/src/share/tools/hsdis/hsdis.h Fri Nov 02 07:44:11 2012 -0700 3.2 +++ b/src/share/tools/hsdis/hsdis.h Fri Nov 02 13:30:47 2012 -0700 3.3 @@ -47,6 +47,9 @@ 3.4 where tag is a simple identifier, signifying (as in XML) a element start, 3.5 element end, and standalone element. (To render as XML, add angle brackets.) 3.6 */ 3.7 +#ifndef SHARED_TOOLS_HSDIS_H 3.8 +#define SHARED_TOOLS_HSDIS_H 3.9 + 3.10 extern 3.11 #ifdef DLL_EXPORT 3.12 DLL_EXPORT 3.13 @@ -57,16 +60,37 @@ 3.14 void* event_stream, 3.15 int (*printf_callback)(void*, const char*, ...), 3.16 void* printf_stream, 3.17 - const char* options); 3.18 + const char* options, 3.19 + int newline /* bool value for nice new line */); 3.20 + 3.21 +/* This is the compatability interface for older versions of hotspot */ 3.22 +extern 3.23 +#ifdef DLL_ENTRY 3.24 + DLL_ENTRY 3.25 +#endif 3.26 +void* decode_instructions(void* start_pv, void* end_pv, 3.27 + void* (*event_callback)(void*, const char*, void*), 3.28 + void* event_stream, 3.29 + int (*printf_callback)(void*, const char*, ...), 3.30 + void* printf_stream, 3.31 + const char* options); 3.32 3.33 /* convenience typedefs */ 3.34 3.35 typedef void* (*decode_instructions_event_callback_ftype) (void*, const char*, void*); 3.36 typedef int (*decode_instructions_printf_callback_ftype) (void*, const char*, ...); 3.37 -typedef void* (*decode_instructions_ftype) (uintptr_t start_va, uintptr_t end_va, 3.38 - unsigned char* buffer, uintptr_t length, 3.39 - decode_instructions_event_callback_ftype event_callback, 3.40 - void* event_stream, 3.41 - decode_instructions_printf_callback_ftype printf_callback, 3.42 - void* printf_stream, 3.43 - const char* options); 3.44 +typedef void* (*decode_func_vtype) (uintptr_t start_va, uintptr_t end_va, 3.45 + unsigned char* buffer, uintptr_t length, 3.46 + decode_instructions_event_callback_ftype event_callback, 3.47 + void* event_stream, 3.48 + decode_instructions_printf_callback_ftype printf_callback, 3.49 + void* printf_stream, 3.50 + const char* options, 3.51 + int newline); 3.52 +typedef void* (*decode_func_stype) (void* start_pv, void* end_pv, 3.53 + decode_instructions_event_callback_ftype event_callback, 3.54 + void* event_stream, 3.55 + decode_instructions_printf_callback_ftype printf_callback, 3.56 + void* printf_stream, 3.57 + const char* options); 3.58 +#endif /* SHARED_TOOLS_HSDIS_H */
4.1 --- a/src/share/vm/compiler/disassembler.cpp Fri Nov 02 07:44:11 2012 -0700 4.2 +++ b/src/share/vm/compiler/disassembler.cpp Fri Nov 02 13:30:47 2012 -0700 4.3 @@ -55,16 +55,18 @@ 4.4 bool Disassembler::_tried_to_load_library = false; 4.5 4.6 // This routine is in the shared library: 4.7 +Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; 4.8 Disassembler::decode_func Disassembler::_decode_instructions = NULL; 4.9 4.10 static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH; 4.11 -static const char decode_instructions_name[] = "decode_instructions_virtual"; 4.12 - 4.13 +static const char decode_instructions_virtual_name[] = "decode_instructions_virtual"; 4.14 +static const char decode_instructions_name[] = "decode_instructions"; 4.15 +static bool use_new_version = true; 4.16 #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/ 4.17 #define BYTES_COMMENT ";..." /* funky byte display comment */ 4.18 4.19 bool Disassembler::load_library() { 4.20 - if (_decode_instructions != NULL) { 4.21 + if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) { 4.22 // Already succeeded. 4.23 return true; 4.24 } 4.25 @@ -123,11 +125,19 @@ 4.26 _library = os::dll_load(buf, ebuf, sizeof ebuf); 4.27 } 4.28 if (_library != NULL) { 4.29 + _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual, 4.30 + os::dll_lookup(_library, decode_instructions_virtual_name)); 4.31 + } 4.32 + if (_decode_instructions_virtual == NULL) { 4.33 + // could not spot in new version, try old version 4.34 _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, 4.35 os::dll_lookup(_library, decode_instructions_name)); 4.36 + use_new_version = false; 4.37 + } else { 4.38 + use_new_version = true; 4.39 } 4.40 _tried_to_load_library = true; 4.41 - if (_decode_instructions == NULL) { 4.42 + if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) { 4.43 tty->print_cr("Could not load %s; %s; %s", buf, 4.44 ((_library != NULL) 4.45 ? "entry point is missing" 4.46 @@ -450,17 +460,31 @@ 4.47 // This is mainly for debugging the library itself. 4.48 FILE* out = stdout; 4.49 FILE* xmlout = (_print_raw > 1 ? out : NULL); 4.50 - return (address) 4.51 - (*Disassembler::_decode_instructions)((uintptr_t)start, (uintptr_t)end, 4.52 - start, end - start, 4.53 + return use_new_version ? 4.54 + (address) 4.55 + (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end, 4.56 + start, end - start, 4.57 + NULL, (void*) xmlout, 4.58 + NULL, (void*) out, 4.59 + options(), 0/*nice new line*/) 4.60 + : 4.61 + (address) 4.62 + (*Disassembler::_decode_instructions)(start, end, 4.63 NULL, (void*) xmlout, 4.64 NULL, (void*) out, 4.65 options()); 4.66 } 4.67 4.68 - return (address) 4.69 - (*Disassembler::_decode_instructions)((uintptr_t)start, (uintptr_t)end, 4.70 - start, end - start, 4.71 + return use_new_version ? 4.72 + (address) 4.73 + (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end, 4.74 + start, end - start, 4.75 + &event_to_env, (void*) this, 4.76 + &printf_to_env, (void*) this, 4.77 + options(), 0/*nice new line*/) 4.78 + : 4.79 + (address) 4.80 + (*Disassembler::_decode_instructions)(start, end, 4.81 &event_to_env, (void*) this, 4.82 &printf_to_env, (void*) this, 4.83 options());
5.1 --- a/src/share/vm/compiler/disassembler.hpp Fri Nov 02 07:44:11 2012 -0700 5.2 +++ b/src/share/vm/compiler/disassembler.hpp Fri Nov 02 13:30:47 2012 -0700 5.3 @@ -49,18 +49,27 @@ 5.4 friend class decode_env; 5.5 private: 5.6 // this is the type of the dll entry point: 5.7 - typedef void* (*decode_func)(uintptr_t start_va, uintptr_t end_va, 5.8 + typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va, 5.9 unsigned char* buffer, uintptr_t length, 5.10 void* (*event_callback)(void*, const char*, void*), 5.11 void* event_stream, 5.12 int (*printf_callback)(void*, const char*, ...), 5.13 void* printf_stream, 5.14 + const char* options, 5.15 + int newline); 5.16 + // this is the type of the dll entry point for old version: 5.17 + typedef void* (*decode_func)(void* start_va, void* end_va, 5.18 + void* (*event_callback)(void*, const char*, void*), 5.19 + void* event_stream, 5.20 + int (*printf_callback)(void*, const char*, ...), 5.21 + void* printf_stream, 5.22 const char* options); 5.23 // points to the library. 5.24 static void* _library; 5.25 // bailout 5.26 static bool _tried_to_load_library; 5.27 // points to the decode function. 5.28 + static decode_func_virtual _decode_instructions_virtual; 5.29 static decode_func _decode_instructions; 5.30 // tries to load library and return whether it succedded. 5.31 static bool load_library(); 5.32 @@ -85,7 +94,9 @@ 5.33 5.34 public: 5.35 static bool can_decode() { 5.36 - return (_decode_instructions != NULL) || load_library(); 5.37 + return (_decode_instructions_virtual != NULL) || 5.38 + (_decode_instructions != NULL) || 5.39 + load_library(); 5.40 } 5.41 static void decode(CodeBlob *cb, outputStream* st = NULL); 5.42 static void decode(nmethod* nm, outputStream* st = NULL);