1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/stubCodeGenerator.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 + * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_stubCodeGenerator.cpp.incl" 1.30 + 1.31 + 1.32 +// Implementation of StubCodeDesc 1.33 + 1.34 +StubCodeDesc* StubCodeDesc::_list = NULL; 1.35 +int StubCodeDesc::_count = 0; 1.36 + 1.37 + 1.38 +StubCodeDesc* StubCodeDesc::desc_for(address pc) { 1.39 + StubCodeDesc* p = _list; 1.40 + while (p != NULL && !p->contains(pc)) p = p->_next; 1.41 + // p == NULL || p->contains(pc) 1.42 + return p; 1.43 +} 1.44 + 1.45 + 1.46 +StubCodeDesc* StubCodeDesc::desc_for_index(int index) { 1.47 + StubCodeDesc* p = _list; 1.48 + while (p != NULL && p->index() != index) p = p->_next; 1.49 + return p; 1.50 +} 1.51 + 1.52 + 1.53 +const char* StubCodeDesc::name_for(address pc) { 1.54 + StubCodeDesc* p = desc_for(pc); 1.55 + return p == NULL ? NULL : p->name(); 1.56 +} 1.57 + 1.58 + 1.59 +void StubCodeDesc::print() { 1.60 + tty->print(group()); 1.61 + tty->print("::"); 1.62 + tty->print(name()); 1.63 + tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes()); 1.64 +} 1.65 + 1.66 + 1.67 + 1.68 +// Implementation of StubCodeGenerator 1.69 + 1.70 +StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) { 1.71 + _masm = new MacroAssembler(code); 1.72 + _first_stub = _last_stub = NULL; 1.73 +} 1.74 + 1.75 +#ifndef PRODUCT 1.76 +extern "C" { 1.77 + static int compare_cdesc(const void* void_a, const void* void_b) { 1.78 + int ai = (*((StubCodeDesc**) void_a))->index(); 1.79 + int bi = (*((StubCodeDesc**) void_b))->index(); 1.80 + return ai - bi; 1.81 + } 1.82 +} 1.83 +#endif 1.84 + 1.85 +StubCodeGenerator::~StubCodeGenerator() { 1.86 +#ifndef PRODUCT 1.87 + if (PrintStubCode) { 1.88 + CodeBuffer* cbuf = _masm->code(); 1.89 + CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start()); 1.90 + if (blob != NULL) { 1.91 + blob->set_comments(cbuf->comments()); 1.92 + } 1.93 + bool saw_first = false; 1.94 + StubCodeDesc* toprint[1000]; 1.95 + int toprint_len = 0; 1.96 + for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) { 1.97 + toprint[toprint_len++] = cdesc; 1.98 + if (cdesc == _first_stub) { saw_first = true; break; } 1.99 + } 1.100 + assert(saw_first, "must get both first & last"); 1.101 + // Print in reverse order: 1.102 + qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc); 1.103 + for (int i = 0; i < toprint_len; i++) { 1.104 + StubCodeDesc* cdesc = toprint[i]; 1.105 + cdesc->print(); 1.106 + tty->cr(); 1.107 + Disassembler::decode(cdesc->begin(), cdesc->end()); 1.108 + tty->cr(); 1.109 + } 1.110 + } 1.111 +#endif //PRODUCT 1.112 +} 1.113 + 1.114 + 1.115 +void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) { 1.116 + // default implementation - do nothing 1.117 +} 1.118 + 1.119 + 1.120 +void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) { 1.121 + // default implementation - record the cdesc 1.122 + if (_first_stub == NULL) _first_stub = cdesc; 1.123 + _last_stub = cdesc; 1.124 +} 1.125 + 1.126 + 1.127 +// Implementation of CodeMark 1.128 + 1.129 +StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) { 1.130 + _cgen = cgen; 1.131 + _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc()); 1.132 + _cgen->stub_prolog(_cdesc); 1.133 + // define the stub's beginning (= entry point) to be after the prolog: 1.134 + _cdesc->set_begin(_cgen->assembler()->pc()); 1.135 +} 1.136 + 1.137 +StubCodeMark::~StubCodeMark() { 1.138 + _cgen->assembler()->flush(); 1.139 + _cdesc->set_end(_cgen->assembler()->pc()); 1.140 + assert(StubCodeDesc::_list == _cdesc, "expected order on list"); 1.141 + _cgen->stub_epilog(_cdesc); 1.142 + VTune::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); 1.143 + Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); 1.144 + 1.145 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.146 + JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end()); 1.147 + } 1.148 +}