54 #endif |
54 #endif |
55 #ifdef SHARK |
55 #ifdef SHARK |
56 #include "shark/sharkEntry.hpp" |
56 #include "shark/sharkEntry.hpp" |
57 #endif |
57 #endif |
58 |
58 |
59 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
|
60 |
|
61 void* Disassembler::_library = NULL; |
59 void* Disassembler::_library = NULL; |
62 bool Disassembler::_tried_to_load_library = false; |
60 bool Disassembler::_tried_to_load_library = false; |
63 |
61 |
64 // This routine is in the shared library: |
62 // This routine is in the shared library: |
65 Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; |
63 Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; |
328 } |
326 } |
329 |
327 |
330 if (Universe::is_fully_initialized()) { |
328 if (Universe::is_fully_initialized()) { |
331 if (StubRoutines::contains(adr)) { |
329 if (StubRoutines::contains(adr)) { |
332 StubCodeDesc* desc = StubCodeDesc::desc_for(adr); |
330 StubCodeDesc* desc = StubCodeDesc::desc_for(adr); |
333 if (desc == NULL) |
331 if (desc == NULL) { |
334 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset); |
332 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset); |
|
333 } |
335 if (desc != NULL) { |
334 if (desc != NULL) { |
336 st->print("Stub::%s", desc->name()); |
335 st->print("Stub::%s", desc->name()); |
337 if (desc->begin() != adr) |
336 if (desc->begin() != adr) { |
338 st->print("%+d 0x%p",adr - desc->begin(), adr); |
337 st->print(INTX_FORMAT_W(+) " " PTR_FORMAT, adr - desc->begin(), p2i(adr)); |
339 else if (WizardMode) st->print(" " PTR_FORMAT, adr); |
338 } else if (WizardMode) { |
|
339 st->print(" " PTR_FORMAT, p2i(adr)); |
|
340 } |
340 return; |
341 return; |
341 } |
342 } |
342 st->print("Stub::<unknown> " PTR_FORMAT, adr); |
343 st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr)); |
343 return; |
344 return; |
344 } |
345 } |
345 |
346 |
346 BarrierSet* bs = Universe::heap()->barrier_set(); |
347 BarrierSet* bs = Universe::heap()->barrier_set(); |
347 if (bs->is_a(BarrierSet::CardTableModRef) && |
348 if (bs->is_a(BarrierSet::CardTableModRef) && |
348 adr == (address)(barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base)) { |
349 adr == (address)(barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base)) { |
349 st->print("word_map_base"); |
350 st->print("word_map_base"); |
350 if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr); |
351 if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr)); |
351 return; |
352 return; |
352 } |
353 } |
353 } |
354 } |
354 |
355 |
355 // Fall through to a simple (hexadecimal) numeral. |
356 // Fall through to a simple (hexadecimal) numeral. |
356 st->print(PTR_FORMAT, adr); |
357 st->print(PTR_FORMAT, p2i(adr)); |
357 } |
358 } |
358 |
359 |
359 void decode_env::print_insn_labels() { |
360 void decode_env::print_insn_labels() { |
360 address p = cur_insn(); |
361 address p = cur_insn(); |
361 outputStream* st = output(); |
362 outputStream* st = output(); |
363 if (cb != NULL) { |
364 if (cb != NULL) { |
364 cb->print_block_comment(st, p); |
365 cb->print_block_comment(st, p); |
365 } |
366 } |
366 _strings.print_block_comment(st, (intptr_t)(p - _start)); |
367 _strings.print_block_comment(st, (intptr_t)(p - _start)); |
367 if (_print_pc) { |
368 if (_print_pc) { |
368 st->print(" " PTR_FORMAT ": ", p); |
369 st->print(" " PTR_FORMAT ": ", p2i(p)); |
369 } |
370 } |
370 } |
371 } |
371 |
372 |
372 void decode_env::print_insn_bytes(address pc, address pc_limit) { |
373 void decode_env::print_insn_bytes(address pc, address pc_limit) { |
373 outputStream* st = output(); |
374 outputStream* st = output(); |
384 st->move_to(COMMENT_COLUMN); |
385 st->move_to(COMMENT_COLUMN); |
385 address pc0 = pc; |
386 address pc0 = pc; |
386 address pc1 = pc + perline; |
387 address pc1 = pc + perline; |
387 if (pc1 > pc_limit) pc1 = pc_limit; |
388 if (pc1 > pc_limit) pc1 = pc_limit; |
388 for (; pc < pc1; pc += incr) { |
389 for (; pc < pc1; pc += incr) { |
389 if (pc == pc0) |
390 if (pc == pc0) { |
390 st->print(BYTES_COMMENT); |
391 st->print(BYTES_COMMENT); |
391 else if ((uint)(pc - pc0) % sizeof(int) == 0) |
392 } else if ((uint)(pc - pc0) % sizeof(int) == 0) { |
392 st->print(" "); // put out a space on word boundaries |
393 st->print(" "); // put out a space on word boundaries |
393 if (incr == sizeof(int)) |
394 } |
394 st->print("%08lx", *(int*)pc); |
395 if (incr == sizeof(int)) { |
395 else st->print("%02x", (*pc)&0xFF); |
396 st->print("%08x", *(int*)pc); |
|
397 } else { |
|
398 st->print("%02x", (*pc)&0xFF); |
|
399 } |
396 } |
400 } |
397 st->cr(); |
401 st->cr(); |
398 } |
402 } |
399 } |
403 } |
400 |
404 |
486 |
490 |
487 |
491 |
488 void Disassembler::decode(CodeBlob* cb, outputStream* st) { |
492 void Disassembler::decode(CodeBlob* cb, outputStream* st) { |
489 if (!load_library()) return; |
493 if (!load_library()) return; |
490 decode_env env(cb, st); |
494 decode_env env(cb, st); |
491 env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb); |
495 env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, p2i(cb)); |
492 env.decode_instructions(cb->code_begin(), cb->code_end()); |
496 env.decode_instructions(cb->code_begin(), cb->code_end()); |
493 } |
497 } |
494 |
498 |
495 void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) { |
499 void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) { |
496 if (!load_library()) return; |
500 if (!load_library()) return; |
499 } |
503 } |
500 |
504 |
501 void Disassembler::decode(nmethod* nm, outputStream* st) { |
505 void Disassembler::decode(nmethod* nm, outputStream* st) { |
502 if (!load_library()) return; |
506 if (!load_library()) return; |
503 decode_env env(nm, st); |
507 decode_env env(nm, st); |
504 env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm); |
508 env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", p2i(nm)); |
505 env.output()->print_cr("Code:"); |
509 env.output()->print_cr("Code:"); |
506 |
510 |
507 #ifdef SHARK |
511 #ifdef SHARK |
508 SharkEntry* entry = (SharkEntry *) nm->code_begin(); |
512 SharkEntry* entry = (SharkEntry *) nm->code_begin(); |
509 unsigned char* p = entry->code_start(); |
513 unsigned char* p = entry->code_start(); |
531 if (nm->consts_size() > 0) { |
535 if (nm->consts_size() > 0) { |
532 nm->print_nmethod_labels(env.output(), nm->consts_begin()); |
536 nm->print_nmethod_labels(env.output(), nm->consts_begin()); |
533 int offset = 0; |
537 int offset = 0; |
534 for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) { |
538 for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) { |
535 if ((offset % 8) == 0) { |
539 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)); |
540 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p2i(p), offset, *((int32_t*) p), *((int64_t*) p)); |
537 } else { |
541 } else { |
538 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p, offset, *((int32_t*) p)); |
542 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p2i(p), offset, *((int32_t*) p)); |
539 } |
543 } |
540 } |
544 } |
541 } |
545 } |
542 |
546 |
543 env.decode_instructions(p, end); |
547 env.decode_instructions(p, end); |