Fri, 31 Oct 2014 12:16:20 +0100
8062169: Multiple OSR compilations issued for same bci
Summary: Fixed 'SimpleThresholdPolicy::event' to always perform OSR if an OSR nmethod is available.
Reviewed-by: kvn, iveresov
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, 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" |
twisti@4318 | 26 | #include "asm/macroAssembler.hpp" |
twisti@4318 | 27 | #include "asm/macroAssembler.inline.hpp" |
twisti@4318 | 28 | #include "code/codeCache.hpp" |
stefank@2314 | 29 | #include "compiler/disassembler.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "prims/forte.hpp" |
stefank@2314 | 32 | #include "runtime/stubCodeGenerator.hpp" |
duke@435 | 33 | |
duke@435 | 34 | |
duke@435 | 35 | // Implementation of StubCodeDesc |
duke@435 | 36 | |
duke@435 | 37 | StubCodeDesc* StubCodeDesc::_list = NULL; |
duke@435 | 38 | int StubCodeDesc::_count = 0; |
duke@435 | 39 | |
duke@435 | 40 | |
duke@435 | 41 | StubCodeDesc* StubCodeDesc::desc_for(address pc) { |
duke@435 | 42 | StubCodeDesc* p = _list; |
duke@435 | 43 | while (p != NULL && !p->contains(pc)) p = p->_next; |
duke@435 | 44 | // p == NULL || p->contains(pc) |
duke@435 | 45 | return p; |
duke@435 | 46 | } |
duke@435 | 47 | |
duke@435 | 48 | |
duke@435 | 49 | StubCodeDesc* StubCodeDesc::desc_for_index(int index) { |
duke@435 | 50 | StubCodeDesc* p = _list; |
duke@435 | 51 | while (p != NULL && p->index() != index) p = p->_next; |
duke@435 | 52 | return p; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | |
duke@435 | 56 | const char* StubCodeDesc::name_for(address pc) { |
duke@435 | 57 | StubCodeDesc* p = desc_for(pc); |
duke@435 | 58 | return p == NULL ? NULL : p->name(); |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | |
bobv@2036 | 62 | void StubCodeDesc::print_on(outputStream* st) const { |
drchase@6680 | 63 | st->print("%s", group()); |
bobv@2036 | 64 | st->print("::"); |
drchase@6680 | 65 | st->print("%s", name()); |
drchase@6680 | 66 | st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", p2i(begin()), p2i(end()), size_in_bytes()); |
duke@435 | 67 | } |
duke@435 | 68 | |
duke@435 | 69 | // Implementation of StubCodeGenerator |
duke@435 | 70 | |
never@2954 | 71 | StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) { |
duke@435 | 72 | _masm = new MacroAssembler(code); |
duke@435 | 73 | _first_stub = _last_stub = NULL; |
never@2954 | 74 | _print_code = print_code; |
duke@435 | 75 | } |
duke@435 | 76 | |
duke@435 | 77 | extern "C" { |
duke@435 | 78 | static int compare_cdesc(const void* void_a, const void* void_b) { |
duke@435 | 79 | int ai = (*((StubCodeDesc**) void_a))->index(); |
duke@435 | 80 | int bi = (*((StubCodeDesc**) void_b))->index(); |
duke@435 | 81 | return ai - bi; |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | StubCodeGenerator::~StubCodeGenerator() { |
never@2954 | 86 | if (PrintStubCode || _print_code) { |
duke@435 | 87 | CodeBuffer* cbuf = _masm->code(); |
duke@435 | 88 | CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start()); |
duke@435 | 89 | if (blob != NULL) { |
roland@4767 | 90 | blob->set_strings(cbuf->strings()); |
duke@435 | 91 | } |
duke@435 | 92 | bool saw_first = false; |
duke@435 | 93 | StubCodeDesc* toprint[1000]; |
duke@435 | 94 | int toprint_len = 0; |
duke@435 | 95 | for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) { |
duke@435 | 96 | toprint[toprint_len++] = cdesc; |
duke@435 | 97 | if (cdesc == _first_stub) { saw_first = true; break; } |
duke@435 | 98 | } |
duke@435 | 99 | assert(saw_first, "must get both first & last"); |
duke@435 | 100 | // Print in reverse order: |
duke@435 | 101 | qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc); |
duke@435 | 102 | for (int i = 0; i < toprint_len; i++) { |
duke@435 | 103 | StubCodeDesc* cdesc = toprint[i]; |
duke@435 | 104 | cdesc->print(); |
duke@435 | 105 | tty->cr(); |
duke@435 | 106 | Disassembler::decode(cdesc->begin(), cdesc->end()); |
duke@435 | 107 | tty->cr(); |
duke@435 | 108 | } |
duke@435 | 109 | } |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | |
duke@435 | 113 | void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) { |
duke@435 | 114 | // default implementation - do nothing |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | |
duke@435 | 118 | void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) { |
duke@435 | 119 | // default implementation - record the cdesc |
duke@435 | 120 | if (_first_stub == NULL) _first_stub = cdesc; |
duke@435 | 121 | _last_stub = cdesc; |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | |
duke@435 | 125 | // Implementation of CodeMark |
duke@435 | 126 | |
duke@435 | 127 | StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) { |
duke@435 | 128 | _cgen = cgen; |
duke@435 | 129 | _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc()); |
duke@435 | 130 | _cgen->stub_prolog(_cdesc); |
duke@435 | 131 | // define the stub's beginning (= entry point) to be after the prolog: |
duke@435 | 132 | _cdesc->set_begin(_cgen->assembler()->pc()); |
duke@435 | 133 | } |
duke@435 | 134 | |
duke@435 | 135 | StubCodeMark::~StubCodeMark() { |
duke@435 | 136 | _cgen->assembler()->flush(); |
duke@435 | 137 | _cdesc->set_end(_cgen->assembler()->pc()); |
duke@435 | 138 | assert(StubCodeDesc::_list == _cdesc, "expected order on list"); |
duke@435 | 139 | _cgen->stub_epilog(_cdesc); |
duke@435 | 140 | Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
duke@435 | 141 | |
duke@435 | 142 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 143 | JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
duke@435 | 144 | } |
duke@435 | 145 | } |