< prev index next >

src/hotspot/share/runtime/stubCodeGenerator.cpp

Print this page
rev 54960 : 8213084: Rework and enhance Print[Opto]Assembly output
Reviewed-by: kvn, thartmann


  43     p = p->_next;
  44   }
  45   return p;
  46 }
  47 
  48 const char* StubCodeDesc::name_for(address pc) {
  49   StubCodeDesc* p = desc_for(pc);
  50   return p == NULL ? NULL : p->name();
  51 }
  52 
  53 
  54 void StubCodeDesc::freeze() {
  55   assert(!_frozen, "repeated freeze operation");
  56   _frozen = true;
  57 }
  58 
  59 void StubCodeDesc::print_on(outputStream* st) const {
  60   st->print("%s", group());
  61   st->print("::");
  62   st->print("%s", name());
  63   st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", p2i(begin()), p2i(end()), size_in_bytes());
  64 }
  65 
  66 void StubCodeDesc::print() const { print_on(tty); }
  67 
  68 // Implementation of StubCodeGenerator
  69 
  70 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) {
  71   _masm = new MacroAssembler(code );
  72   _print_code = PrintStubCode || print_code;
  73 }
  74 
  75 StubCodeGenerator::~StubCodeGenerator() {
  76   if (PRODUCT_ONLY(_print_code) NOT_PRODUCT(true)) {
  77     CodeBuffer* cbuf = _masm->code();
  78     CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
  79     if (blob != NULL) {
  80       blob->set_strings(cbuf->strings());
  81     }
  82   }
  83 }
  84 
  85 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
  86   // default implementation - do nothing
  87 }
  88 
  89 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
  90   if (_print_code) {
  91     CodeStrings cs;
  92     ptrdiff_t offset = 0;
  93 #ifndef PRODUCT
  94     // Find the code strings in the outer CodeBuffer.
  95     CodeBuffer *outer_cbuf = _masm->code_section()->outer();
  96     cs = outer_cbuf->strings();
  97     // The offset from the start of the outer CodeBuffer to the start
  98     // of this stub.
  99     offset = cdesc->begin() - outer_cbuf->insts()->start();
 100 #endif
 101     cdesc->print();


 102     tty->cr();
 103     Disassembler::decode(cdesc->begin(), cdesc->end(), NULL, cs, offset);

 104     tty->cr();
 105   }
 106 }
 107 
 108 
 109 // Implementation of CodeMark
 110 
 111 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
 112   _cgen  = cgen;
 113   _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
 114   _cgen->stub_prolog(_cdesc);
 115   // define the stub's beginning (= entry point) to be after the prolog:
 116   _cdesc->set_begin(_cgen->assembler()->pc());
 117 }
 118 
 119 StubCodeMark::~StubCodeMark() {
 120   _cgen->assembler()->flush();
 121   _cdesc->set_end(_cgen->assembler()->pc());
 122   assert(StubCodeDesc::_list == _cdesc, "expected order on list");
 123   _cgen->stub_epilog(_cdesc);


  43     p = p->_next;
  44   }
  45   return p;
  46 }
  47 
  48 const char* StubCodeDesc::name_for(address pc) {
  49   StubCodeDesc* p = desc_for(pc);
  50   return p == NULL ? NULL : p->name();
  51 }
  52 
  53 
  54 void StubCodeDesc::freeze() {
  55   assert(!_frozen, "repeated freeze operation");
  56   _frozen = true;
  57 }
  58 
  59 void StubCodeDesc::print_on(outputStream* st) const {
  60   st->print("%s", group());
  61   st->print("::");
  62   st->print("%s", name());
  63   st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%d bytes)", p2i(begin()), p2i(end()), size_in_bytes());
  64 }
  65 
  66 void StubCodeDesc::print() const { print_on(tty); }
  67 
  68 // Implementation of StubCodeGenerator
  69 
  70 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) {
  71   _masm = new MacroAssembler(code );
  72   _print_code = PrintStubCode || print_code;
  73 }
  74 
  75 StubCodeGenerator::~StubCodeGenerator() {
  76   if (PRODUCT_ONLY(_print_code) NOT_PRODUCT(true)) {
  77     CodeBuffer* cbuf = _masm->code();
  78     CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
  79     if (blob != NULL) {
  80       blob->set_strings(cbuf->strings());
  81     }
  82   }
  83 }
  84 
  85 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
  86   // default implementation - do nothing
  87 }
  88 
  89 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
  90   if (_print_code) {
  91     CodeStrings cs;
  92     ptrdiff_t offset = 0;
  93 #ifndef PRODUCT
  94     // Find the code strings in the outer CodeBuffer.
  95     CodeBuffer *outer_cbuf = _masm->code_section()->outer();
  96     cs = outer_cbuf->strings();
  97     // The offset from the start of the outer CodeBuffer to the start
  98     // of this stub.
  99     offset = cdesc->begin() - outer_cbuf->insts()->start();
 100 #endif
 101     ttyLocker ttyl;
 102     tty->print_cr("- - - [BEGIN] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
 103     cdesc->print_on(tty);
 104     tty->cr();
 105     Disassembler::decode(cdesc->begin(), cdesc->end(), tty, cs /*, offset */);
 106     tty->print_cr("- - - [END] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
 107     tty->cr();
 108   }
 109 }
 110 
 111 
 112 // Implementation of CodeMark
 113 
 114 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
 115   _cgen  = cgen;
 116   _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
 117   _cgen->stub_prolog(_cdesc);
 118   // define the stub's beginning (= entry point) to be after the prolog:
 119   _cdesc->set_begin(_cgen->assembler()->pc());
 120 }
 121 
 122 StubCodeMark::~StubCodeMark() {
 123   _cgen->assembler()->flush();
 124   _cdesc->set_end(_cgen->assembler()->pc());
 125   assert(StubCodeDesc::_list == _cdesc, "expected order on list");
 126   _cgen->stub_epilog(_cdesc);
< prev index next >