src/share/vm/runtime/stubCodeGenerator.cpp

Sat, 09 Apr 2011 21:16:12 -0700

author
jrose
date
Sat, 09 Apr 2011 21:16:12 -0700
changeset 2750
6c97c830fb6f
parent 2708
1d1603768966
child 2954
f8c9417e3571
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@2708 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "compiler/disassembler.hpp"
stefank@2314 27 #include "oops/oop.inline.hpp"
stefank@2314 28 #include "prims/forte.hpp"
stefank@2314 29 #include "runtime/stubCodeGenerator.hpp"
stefank@2314 30 #ifdef TARGET_ARCH_x86
stefank@2314 31 # include "assembler_x86.inline.hpp"
stefank@2314 32 #endif
stefank@2314 33 #ifdef TARGET_ARCH_sparc
stefank@2314 34 # include "assembler_sparc.inline.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_ARCH_zero
stefank@2314 37 # include "assembler_zero.inline.hpp"
stefank@2314 38 #endif
bobv@2508 39 #ifdef TARGET_ARCH_arm
bobv@2508 40 # include "assembler_arm.inline.hpp"
bobv@2508 41 #endif
bobv@2508 42 #ifdef TARGET_ARCH_ppc
bobv@2508 43 # include "assembler_ppc.inline.hpp"
bobv@2508 44 #endif
duke@435 45
duke@435 46
duke@435 47 // Implementation of StubCodeDesc
duke@435 48
duke@435 49 StubCodeDesc* StubCodeDesc::_list = NULL;
duke@435 50 int StubCodeDesc::_count = 0;
duke@435 51
duke@435 52
duke@435 53 StubCodeDesc* StubCodeDesc::desc_for(address pc) {
duke@435 54 StubCodeDesc* p = _list;
duke@435 55 while (p != NULL && !p->contains(pc)) p = p->_next;
duke@435 56 // p == NULL || p->contains(pc)
duke@435 57 return p;
duke@435 58 }
duke@435 59
duke@435 60
duke@435 61 StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
duke@435 62 StubCodeDesc* p = _list;
duke@435 63 while (p != NULL && p->index() != index) p = p->_next;
duke@435 64 return p;
duke@435 65 }
duke@435 66
duke@435 67
duke@435 68 const char* StubCodeDesc::name_for(address pc) {
duke@435 69 StubCodeDesc* p = desc_for(pc);
duke@435 70 return p == NULL ? NULL : p->name();
duke@435 71 }
duke@435 72
duke@435 73
bobv@2036 74 void StubCodeDesc::print_on(outputStream* st) const {
bobv@2036 75 st->print(group());
bobv@2036 76 st->print("::");
bobv@2036 77 st->print(name());
bobv@2036 78 st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
duke@435 79 }
duke@435 80
duke@435 81 // Implementation of StubCodeGenerator
duke@435 82
duke@435 83 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) {
duke@435 84 _masm = new MacroAssembler(code);
duke@435 85 _first_stub = _last_stub = NULL;
duke@435 86 }
duke@435 87
duke@435 88 extern "C" {
duke@435 89 static int compare_cdesc(const void* void_a, const void* void_b) {
duke@435 90 int ai = (*((StubCodeDesc**) void_a))->index();
duke@435 91 int bi = (*((StubCodeDesc**) void_b))->index();
duke@435 92 return ai - bi;
duke@435 93 }
duke@435 94 }
duke@435 95
duke@435 96 StubCodeGenerator::~StubCodeGenerator() {
duke@435 97 if (PrintStubCode) {
duke@435 98 CodeBuffer* cbuf = _masm->code();
duke@435 99 CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
duke@435 100 if (blob != NULL) {
duke@435 101 blob->set_comments(cbuf->comments());
duke@435 102 }
duke@435 103 bool saw_first = false;
duke@435 104 StubCodeDesc* toprint[1000];
duke@435 105 int toprint_len = 0;
duke@435 106 for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
duke@435 107 toprint[toprint_len++] = cdesc;
duke@435 108 if (cdesc == _first_stub) { saw_first = true; break; }
duke@435 109 }
duke@435 110 assert(saw_first, "must get both first & last");
duke@435 111 // Print in reverse order:
duke@435 112 qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
duke@435 113 for (int i = 0; i < toprint_len; i++) {
duke@435 114 StubCodeDesc* cdesc = toprint[i];
duke@435 115 cdesc->print();
duke@435 116 tty->cr();
duke@435 117 Disassembler::decode(cdesc->begin(), cdesc->end());
duke@435 118 tty->cr();
duke@435 119 }
duke@435 120 }
duke@435 121 }
duke@435 122
duke@435 123
duke@435 124 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
duke@435 125 // default implementation - do nothing
duke@435 126 }
duke@435 127
duke@435 128
duke@435 129 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
duke@435 130 // default implementation - record the cdesc
duke@435 131 if (_first_stub == NULL) _first_stub = cdesc;
duke@435 132 _last_stub = cdesc;
duke@435 133 }
duke@435 134
duke@435 135
duke@435 136 // Implementation of CodeMark
duke@435 137
duke@435 138 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
duke@435 139 _cgen = cgen;
duke@435 140 _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
duke@435 141 _cgen->stub_prolog(_cdesc);
duke@435 142 // define the stub's beginning (= entry point) to be after the prolog:
duke@435 143 _cdesc->set_begin(_cgen->assembler()->pc());
duke@435 144 }
duke@435 145
duke@435 146 StubCodeMark::~StubCodeMark() {
duke@435 147 _cgen->assembler()->flush();
duke@435 148 _cdesc->set_end(_cgen->assembler()->pc());
duke@435 149 assert(StubCodeDesc::_list == _cdesc, "expected order on list");
duke@435 150 _cgen->stub_epilog(_cdesc);
duke@435 151 Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
duke@435 152
duke@435 153 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 154 JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
duke@435 155 }
duke@435 156 }

mercurial