39 #endif
40 #ifdef TARGET_ARCH_sparc
41 # include "depChecker_sparc.hpp"
42 #endif
43 #ifdef TARGET_ARCH_zero
44 # include "depChecker_zero.hpp"
45 #endif
46 #ifdef TARGET_ARCH_arm
47 # include "depChecker_arm.hpp"
48 #endif
49 #ifdef TARGET_ARCH_ppc
50 # include "depChecker_ppc.hpp"
51 #endif
52 #ifdef TARGET_ARCH_aarch64
53 # include "depChecker_aarch64.hpp"
54 #endif
55 #ifdef SHARK
56 #include "shark/sharkEntry.hpp"
57 #endif
58
59 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
60
61 void* Disassembler::_library = NULL;
62 bool Disassembler::_tried_to_load_library = false;
63
64 // This routine is in the shared library:
65 Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
66 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
67
68 static const char hsdis_library_name[] = "hsdis-" HOTSPOT_LIB_ARCH;
69 static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
70 static const char decode_instructions_name[] = "decode_instructions";
71 static bool use_new_version = true;
72 #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/
73 #define BYTES_COMMENT ";..." /* funky byte display comment */
74
75 bool Disassembler::load_library() {
76 if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
77 // Already succeeded.
78 return true;
79 }
80 if (_tried_to_load_library) {
313
314 // called by the disassembler to print out jump targets and data addresses
315 void decode_env::print_address(address adr) {
316 outputStream* st = _output;
317
318 if (adr == NULL) {
319 st->print("NULL");
320 return;
321 }
322
323 int small_num = (int)(intptr_t)adr;
324 if ((intptr_t)adr == (intptr_t)small_num
325 && -1 <= small_num && small_num <= 9) {
326 st->print("%d", small_num);
327 return;
328 }
329
330 if (Universe::is_fully_initialized()) {
331 if (StubRoutines::contains(adr)) {
332 StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
333 if (desc == NULL)
334 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
335 if (desc != NULL) {
336 st->print("Stub::%s", desc->name());
337 if (desc->begin() != adr)
338 st->print("%+d 0x%p",adr - desc->begin(), adr);
339 else if (WizardMode) st->print(" " PTR_FORMAT, adr);
340 return;
341 }
342 st->print("Stub::<unknown> " PTR_FORMAT, adr);
343 return;
344 }
345
346 BarrierSet* bs = Universe::heap()->barrier_set();
347 if (bs->is_a(BarrierSet::CardTableModRef) &&
348 adr == (address)(barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base)) {
349 st->print("word_map_base");
350 if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
351 return;
352 }
353 }
354
355 // Fall through to a simple (hexadecimal) numeral.
356 st->print(PTR_FORMAT, adr);
357 }
358
359 void decode_env::print_insn_labels() {
360 address p = cur_insn();
361 outputStream* st = output();
362 CodeBlob* cb = _code;
363 if (cb != NULL) {
364 cb->print_block_comment(st, p);
365 }
366 _strings.print_block_comment(st, (intptr_t)(p - _start));
367 if (_print_pc) {
368 st->print(" " PTR_FORMAT ": ", p);
369 }
370 }
371
372 void decode_env::print_insn_bytes(address pc, address pc_limit) {
373 outputStream* st = output();
374 size_t incr = 1;
375 size_t perline = _bytes_per_line;
376 if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
377 && !((uintptr_t)pc % sizeof(int))
378 && !((uintptr_t)pc_limit % sizeof(int))) {
379 incr = sizeof(int);
380 if (perline % incr) perline += incr - (perline % incr);
381 }
382 while (pc < pc_limit) {
383 // tab to the desired column:
384 st->move_to(COMMENT_COLUMN);
385 address pc0 = pc;
386 address pc1 = pc + perline;
387 if (pc1 > pc_limit) pc1 = pc_limit;
388 for (; pc < pc1; pc += incr) {
389 if (pc == pc0)
390 st->print(BYTES_COMMENT);
391 else if ((uint)(pc - pc0) % sizeof(int) == 0)
392 st->print(" "); // put out a space on word boundaries
393 if (incr == sizeof(int))
394 st->print("%08lx", *(int*)pc);
395 else st->print("%02x", (*pc)&0xFF);
396 }
397 st->cr();
398 }
399 }
400
401
402 static void* event_to_env(void* env_pv, const char* event, void* arg) {
403 decode_env* env = (decode_env*) env_pv;
404 return env->handle_event(event, (address) arg);
405 }
406
407 ATTRIBUTE_PRINTF(2, 3)
408 static int printf_to_env(void* env_pv, const char* format, ...) {
409 decode_env* env = (decode_env*) env_pv;
410 outputStream* st = env->output();
411 size_t flen = strlen(format);
412 const char* raw = NULL;
413 if (flen == 0) return 0;
414 if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
415 if (flen < 2 ||
471
472 return use_new_version ?
473 (address)
474 (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
475 start, end - start,
476 &event_to_env, (void*) this,
477 &printf_to_env, (void*) this,
478 options(), 0/*nice new line*/)
479 :
480 (address)
481 (*Disassembler::_decode_instructions)(start, end,
482 &event_to_env, (void*) this,
483 &printf_to_env, (void*) this,
484 options());
485 }
486
487
488 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
489 if (!load_library()) return;
490 decode_env env(cb, st);
491 env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb);
492 env.decode_instructions(cb->code_begin(), cb->code_end());
493 }
494
495 void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) {
496 if (!load_library()) return;
497 decode_env env(CodeCache::find_blob_unsafe(start), st, c);
498 env.decode_instructions(start, end);
499 }
500
501 void Disassembler::decode(nmethod* nm, outputStream* st) {
502 if (!load_library()) return;
503 decode_env env(nm, st);
504 env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm);
505 env.output()->print_cr("Code:");
506
507 #ifdef SHARK
508 SharkEntry* entry = (SharkEntry *) nm->code_begin();
509 unsigned char* p = entry->code_start();
510 unsigned char* end = entry->code_limit();
511 #else
512 unsigned char* p = nm->code_begin();
513 unsigned char* end = nm->code_end();
514 #endif // SHARK
515
516 // If there has been profiling, print the buckets.
517 if (FlatProfiler::bucket_start_for(p) != NULL) {
518 unsigned char* p1 = p;
519 int total_bucket_count = 0;
520 while (p1 < end) {
521 unsigned char* p0 = p1;
522 p1 += pd_instruction_alignment();
523 address bucket_pc = FlatProfiler::bucket_start_for(p1);
524 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
525 total_bucket_count += FlatProfiler::bucket_count_for(p0);
526 }
527 env.set_total_ticks(total_bucket_count);
528 }
529
530 // Print constant table.
531 if (nm->consts_size() > 0) {
532 nm->print_nmethod_labels(env.output(), nm->consts_begin());
533 int offset = 0;
534 for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
535 if ((offset % 8) == 0) {
536 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p, offset, *((int32_t*) p), *((int64_t*) p));
537 } else {
538 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p, offset, *((int32_t*) p));
539 }
540 }
541 }
542
543 env.decode_instructions(p, end);
544 }
|
39 #endif
40 #ifdef TARGET_ARCH_sparc
41 # include "depChecker_sparc.hpp"
42 #endif
43 #ifdef TARGET_ARCH_zero
44 # include "depChecker_zero.hpp"
45 #endif
46 #ifdef TARGET_ARCH_arm
47 # include "depChecker_arm.hpp"
48 #endif
49 #ifdef TARGET_ARCH_ppc
50 # include "depChecker_ppc.hpp"
51 #endif
52 #ifdef TARGET_ARCH_aarch64
53 # include "depChecker_aarch64.hpp"
54 #endif
55 #ifdef SHARK
56 #include "shark/sharkEntry.hpp"
57 #endif
58
59 void* Disassembler::_library = NULL;
60 bool Disassembler::_tried_to_load_library = false;
61
62 // This routine is in the shared library:
63 Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
64 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
65
66 static const char hsdis_library_name[] = "hsdis-" HOTSPOT_LIB_ARCH;
67 static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
68 static const char decode_instructions_name[] = "decode_instructions";
69 static bool use_new_version = true;
70 #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/
71 #define BYTES_COMMENT ";..." /* funky byte display comment */
72
73 bool Disassembler::load_library() {
74 if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
75 // Already succeeded.
76 return true;
77 }
78 if (_tried_to_load_library) {
311
312 // called by the disassembler to print out jump targets and data addresses
313 void decode_env::print_address(address adr) {
314 outputStream* st = _output;
315
316 if (adr == NULL) {
317 st->print("NULL");
318 return;
319 }
320
321 int small_num = (int)(intptr_t)adr;
322 if ((intptr_t)adr == (intptr_t)small_num
323 && -1 <= small_num && small_num <= 9) {
324 st->print("%d", small_num);
325 return;
326 }
327
328 if (Universe::is_fully_initialized()) {
329 if (StubRoutines::contains(adr)) {
330 StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
331 if (desc == NULL) {
332 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
333 }
334 if (desc != NULL) {
335 st->print("Stub::%s", desc->name());
336 if (desc->begin() != adr) {
337 st->print("%+d " PTR_FORMAT, (int)(adr - desc->begin()), p2i(adr));
338 } else if (WizardMode) {
339 st->print(" " PTR_FORMAT, p2i(adr));
340 }
341 return;
342 }
343 st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
344 return;
345 }
346
347 BarrierSet* bs = Universe::heap()->barrier_set();
348 if (bs->is_a(BarrierSet::CardTableModRef) &&
349 adr == (address)(barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base)) {
350 st->print("word_map_base");
351 if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
352 return;
353 }
354 }
355
356 // Fall through to a simple (hexadecimal) numeral.
357 st->print(PTR_FORMAT, p2i(adr));
358 }
359
360 void decode_env::print_insn_labels() {
361 address p = cur_insn();
362 outputStream* st = output();
363 CodeBlob* cb = _code;
364 if (cb != NULL) {
365 cb->print_block_comment(st, p);
366 }
367 _strings.print_block_comment(st, (intptr_t)(p - _start));
368 if (_print_pc) {
369 st->print(" " PTR_FORMAT ": ", p2i(p));
370 }
371 }
372
373 void decode_env::print_insn_bytes(address pc, address pc_limit) {
374 outputStream* st = output();
375 size_t incr = 1;
376 size_t perline = _bytes_per_line;
377 if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
378 && !((uintptr_t)pc % sizeof(int))
379 && !((uintptr_t)pc_limit % sizeof(int))) {
380 incr = sizeof(int);
381 if (perline % incr) perline += incr - (perline % incr);
382 }
383 while (pc < pc_limit) {
384 // tab to the desired column:
385 st->move_to(COMMENT_COLUMN);
386 address pc0 = pc;
387 address pc1 = pc + perline;
388 if (pc1 > pc_limit) pc1 = pc_limit;
389 for (; pc < pc1; pc += incr) {
390 if (pc == pc0) {
391 st->print(BYTES_COMMENT);
392 } else if ((uint)(pc - pc0) % sizeof(int) == 0) {
393 st->print(" "); // put out a space on word boundaries
394 }
395 if (incr == sizeof(int)) {
396 st->print("%08x", *(int*)pc);
397 } else {
398 st->print("%02x", (*pc)&0xFF);
399 }
400 }
401 st->cr();
402 }
403 }
404
405
406 static void* event_to_env(void* env_pv, const char* event, void* arg) {
407 decode_env* env = (decode_env*) env_pv;
408 return env->handle_event(event, (address) arg);
409 }
410
411 ATTRIBUTE_PRINTF(2, 3)
412 static int printf_to_env(void* env_pv, const char* format, ...) {
413 decode_env* env = (decode_env*) env_pv;
414 outputStream* st = env->output();
415 size_t flen = strlen(format);
416 const char* raw = NULL;
417 if (flen == 0) return 0;
418 if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
419 if (flen < 2 ||
475
476 return use_new_version ?
477 (address)
478 (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
479 start, end - start,
480 &event_to_env, (void*) this,
481 &printf_to_env, (void*) this,
482 options(), 0/*nice new line*/)
483 :
484 (address)
485 (*Disassembler::_decode_instructions)(start, end,
486 &event_to_env, (void*) this,
487 &printf_to_env, (void*) this,
488 options());
489 }
490
491
492 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
493 if (!load_library()) return;
494 decode_env env(cb, st);
495 env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, p2i(cb));
496 env.decode_instructions(cb->code_begin(), cb->code_end());
497 }
498
499 void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) {
500 if (!load_library()) return;
501 decode_env env(CodeCache::find_blob_unsafe(start), st, c);
502 env.decode_instructions(start, end);
503 }
504
505 void Disassembler::decode(nmethod* nm, outputStream* st) {
506 if (!load_library()) return;
507 decode_env env(nm, st);
508 env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", p2i(nm));
509 env.output()->print_cr("Code:");
510
511 #ifdef SHARK
512 SharkEntry* entry = (SharkEntry *) nm->code_begin();
513 unsigned char* p = entry->code_start();
514 unsigned char* end = entry->code_limit();
515 #else
516 unsigned char* p = nm->code_begin();
517 unsigned char* end = nm->code_end();
518 #endif // SHARK
519
520 // If there has been profiling, print the buckets.
521 if (FlatProfiler::bucket_start_for(p) != NULL) {
522 unsigned char* p1 = p;
523 int total_bucket_count = 0;
524 while (p1 < end) {
525 unsigned char* p0 = p1;
526 p1 += pd_instruction_alignment();
527 address bucket_pc = FlatProfiler::bucket_start_for(p1);
528 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
529 total_bucket_count += FlatProfiler::bucket_count_for(p0);
530 }
531 env.set_total_ticks(total_bucket_count);
532 }
533
534 // Print constant table.
535 if (nm->consts_size() > 0) {
536 nm->print_nmethod_labels(env.output(), nm->consts_begin());
537 int offset = 0;
538 for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
539 if ((offset % 8) == 0) {
540 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p2i(p), offset, *((int32_t*) p), *((int64_t*) p));
541 } else {
542 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p2i(p), offset, *((int32_t*) p));
543 }
544 }
545 }
546
547 env.decode_instructions(p, end);
548 }
|