src/share/vm/compiler/disassembler.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 7062856 Sdiff src/share/vm/compiler

src/share/vm/compiler/disassembler.cpp

Print this page




  61 static const char decode_instructions_name[] = "decode_instructions";
  62 
  63 #define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
  64 #define BYTES_COMMENT   ";..."  /* funky byte display comment */
  65 
  66 bool Disassembler::load_library() {
  67   if (_decode_instructions != NULL) {
  68     // Already succeeded.
  69     return true;
  70   }
  71   if (_tried_to_load_library) {
  72     // Do not try twice.
  73     // To force retry in debugger: assign _tried_to_load_library=0
  74     return false;
  75   }
  76   // Try to load it.
  77   char ebuf[1024];
  78   char buf[JVM_MAXPATHLEN];
  79   os::jvm_path(buf, sizeof(buf));
  80   int jvm_offset = -1;

  81   {
  82     // Match "jvm[^/]*" in jvm_path.
  83     const char* base = buf;
  84     const char* p = strrchr(buf, '/');

  85     p = strstr(p ? p : base, "jvm");
  86     if (p != NULL)  jvm_offset = p - base;
  87   }






  88   if (jvm_offset >= 0) {
  89     // Find the disassembler next to libjvm.so.
  90     strcpy(&buf[jvm_offset], hsdis_library_name);
  91     strcat(&buf[jvm_offset], os::dll_file_extension());
  92     _library = os::dll_load(buf, ebuf, sizeof ebuf);





  93   }
  94   if (_library == NULL) {
  95     // Try a free-floating lookup.












  96     strcpy(&buf[0], hsdis_library_name);
  97     strcat(&buf[0], os::dll_file_extension());
  98     _library = os::dll_load(buf, ebuf, sizeof ebuf);
  99   }
 100   if (_library != NULL) {
 101     _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
 102                                           os::dll_lookup(_library, decode_instructions_name));
 103   }
 104   _tried_to_load_library = true;
 105   if (_decode_instructions == NULL) {
 106     tty->print_cr("Could not load %s; %s; %s", buf,
 107                   ((_library != NULL)
 108                    ? "entry point is missing"
 109                    : (WizardMode || PrintMiscellaneous)
 110                    ? (const char*)ebuf
 111                    : "library not loadable"),
 112                   "PrintAssembly is disabled");
 113     return false;
 114   }
 115 


 232     tty->print_cr("PrintAssemblyOptions help:");
 233     tty->print_cr("  hsdis-print-raw       test plugin by requesting raw output");
 234     tty->print_cr("  hsdis-print-raw-xml   test plugin by requesting raw xml");
 235     tty->print_cr("  hsdis-print-pc        turn off PC printing (on by default)");
 236     tty->print_cr("  hsdis-print-bytes     turn on instruction byte output");
 237     tty->print_cr("combined options: %s", options());
 238   }
 239 }
 240 
 241 address decode_env::handle_event(const char* event, address arg) {
 242   if (match(event, "insn")) {
 243     start_insn(arg);
 244   } else if (match(event, "/insn")) {
 245     end_insn(arg);
 246   } else if (match(event, "addr")) {
 247     if (arg != NULL) {
 248       print_address(arg);
 249       return arg;
 250     }
 251   } else if (match(event, "mach")) {





 252    output()->print_cr("[Disassembling for mach='%s']", arg);

 253   } else if (match(event, "format bytes-per-line")) {
 254     _bytes_per_line = (int) (intptr_t) arg;
 255   } else {
 256     // ignore unrecognized markup
 257   }
 258   return NULL;
 259 }
 260 
 261 // called by the disassembler to print out jump targets and data addresses
 262 void decode_env::print_address(address adr) {
 263   outputStream* st = _output;
 264 
 265   if (adr == NULL) {
 266     st->print("NULL");
 267     return;
 268   }
 269 
 270   int small_num = (int)(intptr_t)adr;
 271   if ((intptr_t)adr == (intptr_t)small_num
 272       && -1 <= small_num && small_num <= 9) {




  61 static const char decode_instructions_name[] = "decode_instructions";
  62 
  63 #define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
  64 #define BYTES_COMMENT   ";..."  /* funky byte display comment */
  65 
  66 bool Disassembler::load_library() {
  67   if (_decode_instructions != NULL) {
  68     // Already succeeded.
  69     return true;
  70   }
  71   if (_tried_to_load_library) {
  72     // Do not try twice.
  73     // To force retry in debugger: assign _tried_to_load_library=0
  74     return false;
  75   }
  76   // Try to load it.
  77   char ebuf[1024];
  78   char buf[JVM_MAXPATHLEN];
  79   os::jvm_path(buf, sizeof(buf));
  80   int jvm_offset = -1;
  81   int lib_offset = -1;
  82   {
  83     // Match "jvm[^/]*" in jvm_path.
  84     const char* base = buf;
  85     const char* p = strrchr(buf, '/');
  86     if (p != NULL) lib_offset = p - base + 1;
  87     p = strstr(p ? p : base, "jvm");
  88     if (p != NULL)  jvm_offset = p - base;
  89   }
  90   // Find the disassembler shared library.
  91   // Search for several paths derived from libjvm, in this order:
  92   // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so  (for compatibility)
  93   // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
  94   // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
  95   // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
  96   if (jvm_offset >= 0) {
  97     // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
  98     strcpy(&buf[jvm_offset], hsdis_library_name);
  99     strcat(&buf[jvm_offset], os::dll_file_extension());
 100     _library = os::dll_load(buf, ebuf, sizeof ebuf);
 101     if (_library == NULL) {
 102       // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
 103       strcpy(&buf[lib_offset], hsdis_library_name);
 104       strcat(&buf[lib_offset], os::dll_file_extension());
 105       _library = os::dll_load(buf, ebuf, sizeof ebuf);
 106     }
 107     if (_library == NULL) {
 108       // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
 109       buf[lib_offset - 1] = '\0';
 110       const char* p = strrchr(buf, '/');
 111       if (p != NULL) {
 112         lib_offset = p - buf + 1;
 113         strcpy(&buf[lib_offset], hsdis_library_name);
 114         strcat(&buf[lib_offset], os::dll_file_extension());
 115         _library = os::dll_load(buf, ebuf, sizeof ebuf);
 116       }
 117     }
 118   }
 119   if (_library == NULL) {
 120     // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)                                                                                                  
 121     strcpy(&buf[0], hsdis_library_name);
 122     strcat(&buf[0], os::dll_file_extension());
 123     _library = os::dll_load(buf, ebuf, sizeof ebuf);
 124   }
 125   if (_library != NULL) {
 126     _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
 127                                           os::dll_lookup(_library, decode_instructions_name));
 128   }
 129   _tried_to_load_library = true;
 130   if (_decode_instructions == NULL) {
 131     tty->print_cr("Could not load %s; %s; %s", buf,
 132                   ((_library != NULL)
 133                    ? "entry point is missing"
 134                    : (WizardMode || PrintMiscellaneous)
 135                    ? (const char*)ebuf
 136                    : "library not loadable"),
 137                   "PrintAssembly is disabled");
 138     return false;
 139   }
 140 


 257     tty->print_cr("PrintAssemblyOptions help:");
 258     tty->print_cr("  hsdis-print-raw       test plugin by requesting raw output");
 259     tty->print_cr("  hsdis-print-raw-xml   test plugin by requesting raw xml");
 260     tty->print_cr("  hsdis-print-pc        turn off PC printing (on by default)");
 261     tty->print_cr("  hsdis-print-bytes     turn on instruction byte output");
 262     tty->print_cr("combined options: %s", options());
 263   }
 264 }
 265 
 266 address decode_env::handle_event(const char* event, address arg) {
 267   if (match(event, "insn")) {
 268     start_insn(arg);
 269   } else if (match(event, "/insn")) {
 270     end_insn(arg);
 271   } else if (match(event, "addr")) {
 272     if (arg != NULL) {
 273       print_address(arg);
 274       return arg;
 275     }
 276   } else if (match(event, "mach")) {
 277     static char buffer[32] = { 0, };
 278     if (strcmp(buffer, (const char*)arg) != 0 ||
 279         strlen((const char*)arg) > sizeof(buffer) - 1) {
 280       // Only print this when the mach changes
 281       strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
 282       output()->print_cr("[Disassembling for mach='%s']", arg);
 283     }
 284   } else if (match(event, "format bytes-per-line")) {
 285     _bytes_per_line = (int) (intptr_t) arg;
 286   } else {
 287     // ignore unrecognized markup
 288   }
 289   return NULL;
 290 }
 291 
 292 // called by the disassembler to print out jump targets and data addresses
 293 void decode_env::print_address(address adr) {
 294   outputStream* st = _output;
 295 
 296   if (adr == NULL) {
 297     st->print("NULL");
 298     return;
 299   }
 300 
 301   int small_num = (int)(intptr_t)adr;
 302   if ((intptr_t)adr == (intptr_t)small_num
 303       && -1 <= small_num && small_num <= 9) {


src/share/vm/compiler/disassembler.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File