src/share/vm/runtime/stubCodeGenerator.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial