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

src/share/vm/compiler/disassembler.cpp

Print this page




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 # include "incls/_precompiled.incl"
  26 # include "incls/_disassembler.cpp.incl"
  27 
  28 void*       Disassembler::_library               = NULL;
  29 bool        Disassembler::_tried_to_load_library = false;
  30 
  31 // This routine is in the shared library:
  32 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
  33 
  34 static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH;
  35 static const char decode_instructions_name[] = "decode_instructions";
  36 
  37 #define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
  38 #define BYTES_COMMENT   ";..."  /* funky byte display comment */
  39 
  40 bool Disassembler::load_library() {
  41   if (_decode_instructions != NULL) {
  42     // Already succeeded.
  43     return true;
  44   }
  45   if (_tried_to_load_library) {
  46     // Do not try twice.
  47     // To force retry in debugger: assign _tried_to_load_library=0
  48     return false;
  49   }
  50   // Try to load it.
  51   char ebuf[1024];
  52   char buf[JVM_MAXPATHLEN];
  53   os::jvm_path(buf, sizeof(buf));
  54   int jvm_offset = -1;
  55   {


 148 
 149   void end_insn(address pc) {
 150     address pc0 = cur_insn();
 151     outputStream* st = output();
 152     if (_print_bytes && pc > pc0)
 153       print_insn_bytes(pc0, pc);
 154     if (_nm != NULL)
 155       _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
 156 
 157     // Output pc bucket ticks if we have any
 158     if (total_ticks() != 0) {
 159       address bucket_pc = FlatProfiler::bucket_start_for(pc);
 160       if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) {
 161         int bucket_count = FlatProfiler::bucket_count_for(pc0);
 162         if (bucket_count != 0) {
 163           st->bol();
 164           st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count);
 165         }
 166       }
 167     }


 168   }
 169 
 170   address handle_event(const char* event, address arg);
 171 
 172   outputStream* output() { return _output; }
 173   address cur_insn() { return _cur_insn; }
 174   int total_ticks() { return _total_ticks; }
 175   void set_total_ticks(int n) { _total_ticks = n; }
 176   const char* options() { return _option_buf; }
 177 };
 178 
 179 decode_env::decode_env(CodeBlob* code, outputStream* output) {
 180   memset(this, 0, sizeof(*this));
 181   _output = output ? output : tty;
 182   _code = code;
 183   if (code != NULL && code->is_nmethod())
 184     _nm = (nmethod*) code;
 185 
 186   // by default, output pc but not bytes:
 187   _print_pc       = true;


 371   _start = start; _end = end;
 372 
 373   assert((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment() == 0), "misaligned insn addr");
 374 
 375   const int show_bytes = false; // for disassembler debugging
 376 
 377   //_version = Disassembler::pd_cpu_version();
 378 
 379   if (!Disassembler::can_decode()) {
 380     return NULL;
 381   }
 382 
 383   // decode a series of instructions and return the end of the last instruction
 384 
 385   if (_print_raw) {
 386     // Print whatever the library wants to print, w/o fancy callbacks.
 387     // This is mainly for debugging the library itself.
 388     FILE* out = stdout;
 389     FILE* xmlout = (_print_raw > 1 ? out : NULL);
 390     return (address)
 391       (*Disassembler::_decode_instructions)(start, end,

 392                                             NULL, (void*) xmlout,
 393                                             NULL, (void*) out,
 394                                             options());
 395   }
 396 
 397   return (address)
 398     (*Disassembler::_decode_instructions)(start, end,

 399                                           &event_to_env,  (void*) this,
 400                                           &printf_to_env, (void*) this,
 401                                           options());
 402 }
 403 
 404 
 405 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
 406   if (!load_library())  return;
 407   decode_env env(cb, st);
 408   env.output()->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
 409   env.decode_instructions(cb->instructions_begin(), cb->instructions_end());
 410 }
 411 
 412 
 413 void Disassembler::decode(address start, address end, outputStream* st) {
 414   if (!load_library())  return;
 415   decode_env env(CodeCache::find_blob_unsafe(start), st);
 416   env.decode_instructions(start, end);
 417 }
 418 




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 # include "incls/_precompiled.incl"
  26 # include "incls/_disassembler.cpp.incl"
  27 
  28 void*       Disassembler::_library               = NULL;
  29 bool        Disassembler::_tried_to_load_library = false;
  30 
  31 // This routine is in the shared library:
  32 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
  33 
  34 static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH;
  35 static const char decode_instructions_name[] = "decode_instructions_virtual";
  36 
  37 #define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
  38 #define BYTES_COMMENT   ";..."  /* funky byte display comment */
  39 
  40 bool Disassembler::load_library() {
  41   if (_decode_instructions != NULL) {
  42     // Already succeeded.
  43     return true;
  44   }
  45   if (_tried_to_load_library) {
  46     // Do not try twice.
  47     // To force retry in debugger: assign _tried_to_load_library=0
  48     return false;
  49   }
  50   // Try to load it.
  51   char ebuf[1024];
  52   char buf[JVM_MAXPATHLEN];
  53   os::jvm_path(buf, sizeof(buf));
  54   int jvm_offset = -1;
  55   {


 148 
 149   void end_insn(address pc) {
 150     address pc0 = cur_insn();
 151     outputStream* st = output();
 152     if (_print_bytes && pc > pc0)
 153       print_insn_bytes(pc0, pc);
 154     if (_nm != NULL)
 155       _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
 156 
 157     // Output pc bucket ticks if we have any
 158     if (total_ticks() != 0) {
 159       address bucket_pc = FlatProfiler::bucket_start_for(pc);
 160       if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) {
 161         int bucket_count = FlatProfiler::bucket_count_for(pc0);
 162         if (bucket_count != 0) {
 163           st->bol();
 164           st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count);
 165         }
 166       }
 167     }
 168     // follow each complete insn by a nice newline
 169     st->cr();
 170   }
 171 
 172   address handle_event(const char* event, address arg);
 173 
 174   outputStream* output() { return _output; }
 175   address cur_insn() { return _cur_insn; }
 176   int total_ticks() { return _total_ticks; }
 177   void set_total_ticks(int n) { _total_ticks = n; }
 178   const char* options() { return _option_buf; }
 179 };
 180 
 181 decode_env::decode_env(CodeBlob* code, outputStream* output) {
 182   memset(this, 0, sizeof(*this));
 183   _output = output ? output : tty;
 184   _code = code;
 185   if (code != NULL && code->is_nmethod())
 186     _nm = (nmethod*) code;
 187 
 188   // by default, output pc but not bytes:
 189   _print_pc       = true;


 373   _start = start; _end = end;
 374 
 375   assert((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment() == 0), "misaligned insn addr");
 376 
 377   const int show_bytes = false; // for disassembler debugging
 378 
 379   //_version = Disassembler::pd_cpu_version();
 380 
 381   if (!Disassembler::can_decode()) {
 382     return NULL;
 383   }
 384 
 385   // decode a series of instructions and return the end of the last instruction
 386 
 387   if (_print_raw) {
 388     // Print whatever the library wants to print, w/o fancy callbacks.
 389     // This is mainly for debugging the library itself.
 390     FILE* out = stdout;
 391     FILE* xmlout = (_print_raw > 1 ? out : NULL);
 392     return (address)
 393       (*Disassembler::_decode_instructions)((uintptr_t)start, (uintptr_t)end,
 394                                             start, end - start,
 395                                             NULL, (void*) xmlout,
 396                                             NULL, (void*) out,
 397                                             options());
 398   }
 399 
 400   return (address)
 401     (*Disassembler::_decode_instructions)((uintptr_t)start, (uintptr_t)end,
 402                                           start, end - start,
 403                                           &event_to_env,  (void*) this,
 404                                           &printf_to_env, (void*) this,
 405                                           options());
 406 }
 407 
 408 
 409 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
 410   if (!load_library())  return;
 411   decode_env env(cb, st);
 412   env.output()->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
 413   env.decode_instructions(cb->instructions_begin(), cb->instructions_end());
 414 }
 415 
 416 
 417 void Disassembler::decode(address start, address end, outputStream* st) {
 418   if (!load_library())  return;
 419   decode_env env(CodeCache::find_blob_unsafe(start), st);
 420   env.decode_instructions(start, end);
 421 }
 422 


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