Thu, 02 Apr 2009 18:17:03 -0400
Merge
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_stubCodeGenerator.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Implementation of StubCodeDesc |
duke@435 | 30 | |
duke@435 | 31 | StubCodeDesc* StubCodeDesc::_list = NULL; |
duke@435 | 32 | int StubCodeDesc::_count = 0; |
duke@435 | 33 | |
duke@435 | 34 | |
duke@435 | 35 | StubCodeDesc* StubCodeDesc::desc_for(address pc) { |
duke@435 | 36 | StubCodeDesc* p = _list; |
duke@435 | 37 | while (p != NULL && !p->contains(pc)) p = p->_next; |
duke@435 | 38 | // p == NULL || p->contains(pc) |
duke@435 | 39 | return p; |
duke@435 | 40 | } |
duke@435 | 41 | |
duke@435 | 42 | |
duke@435 | 43 | StubCodeDesc* StubCodeDesc::desc_for_index(int index) { |
duke@435 | 44 | StubCodeDesc* p = _list; |
duke@435 | 45 | while (p != NULL && p->index() != index) p = p->_next; |
duke@435 | 46 | return p; |
duke@435 | 47 | } |
duke@435 | 48 | |
duke@435 | 49 | |
duke@435 | 50 | const char* StubCodeDesc::name_for(address pc) { |
duke@435 | 51 | StubCodeDesc* p = desc_for(pc); |
duke@435 | 52 | return p == NULL ? NULL : p->name(); |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | |
duke@435 | 56 | void StubCodeDesc::print() { |
duke@435 | 57 | tty->print(group()); |
duke@435 | 58 | tty->print("::"); |
duke@435 | 59 | tty->print(name()); |
duke@435 | 60 | tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes()); |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | |
duke@435 | 64 | |
duke@435 | 65 | // Implementation of StubCodeGenerator |
duke@435 | 66 | |
duke@435 | 67 | StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) { |
duke@435 | 68 | _masm = new MacroAssembler(code); |
duke@435 | 69 | _first_stub = _last_stub = NULL; |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | extern "C" { |
duke@435 | 73 | static int compare_cdesc(const void* void_a, const void* void_b) { |
duke@435 | 74 | int ai = (*((StubCodeDesc**) void_a))->index(); |
duke@435 | 75 | int bi = (*((StubCodeDesc**) void_b))->index(); |
duke@435 | 76 | return ai - bi; |
duke@435 | 77 | } |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | StubCodeGenerator::~StubCodeGenerator() { |
duke@435 | 81 | if (PrintStubCode) { |
duke@435 | 82 | CodeBuffer* cbuf = _masm->code(); |
duke@435 | 83 | CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start()); |
duke@435 | 84 | if (blob != NULL) { |
duke@435 | 85 | blob->set_comments(cbuf->comments()); |
duke@435 | 86 | } |
duke@435 | 87 | bool saw_first = false; |
duke@435 | 88 | StubCodeDesc* toprint[1000]; |
duke@435 | 89 | int toprint_len = 0; |
duke@435 | 90 | for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) { |
duke@435 | 91 | toprint[toprint_len++] = cdesc; |
duke@435 | 92 | if (cdesc == _first_stub) { saw_first = true; break; } |
duke@435 | 93 | } |
duke@435 | 94 | assert(saw_first, "must get both first & last"); |
duke@435 | 95 | // Print in reverse order: |
duke@435 | 96 | qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc); |
duke@435 | 97 | for (int i = 0; i < toprint_len; i++) { |
duke@435 | 98 | StubCodeDesc* cdesc = toprint[i]; |
duke@435 | 99 | cdesc->print(); |
duke@435 | 100 | tty->cr(); |
duke@435 | 101 | Disassembler::decode(cdesc->begin(), cdesc->end()); |
duke@435 | 102 | tty->cr(); |
duke@435 | 103 | } |
duke@435 | 104 | } |
duke@435 | 105 | } |
duke@435 | 106 | |
duke@435 | 107 | |
duke@435 | 108 | void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) { |
duke@435 | 109 | // default implementation - do nothing |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | |
duke@435 | 113 | void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) { |
duke@435 | 114 | // default implementation - record the cdesc |
duke@435 | 115 | if (_first_stub == NULL) _first_stub = cdesc; |
duke@435 | 116 | _last_stub = cdesc; |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | |
duke@435 | 120 | // Implementation of CodeMark |
duke@435 | 121 | |
duke@435 | 122 | StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) { |
duke@435 | 123 | _cgen = cgen; |
duke@435 | 124 | _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc()); |
duke@435 | 125 | _cgen->stub_prolog(_cdesc); |
duke@435 | 126 | // define the stub's beginning (= entry point) to be after the prolog: |
duke@435 | 127 | _cdesc->set_begin(_cgen->assembler()->pc()); |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | StubCodeMark::~StubCodeMark() { |
duke@435 | 131 | _cgen->assembler()->flush(); |
duke@435 | 132 | _cdesc->set_end(_cgen->assembler()->pc()); |
duke@435 | 133 | assert(StubCodeDesc::_list == _cdesc, "expected order on list"); |
duke@435 | 134 | _cgen->stub_epilog(_cdesc); |
duke@435 | 135 | VTune::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
duke@435 | 136 | Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
duke@435 | 137 | |
duke@435 | 138 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 139 | JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
duke@435 | 140 | } |
duke@435 | 141 | } |