Wed, 29 Mar 2017 09:41:51 +0800
#4662 TieredCompilation is turned off.
TieredCompilation is not supported yet.
aoqi@1 | 1 | /* |
aoqi@1 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@1 | 3 | * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. |
aoqi@1 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@1 | 5 | * |
aoqi@1 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@1 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@1 | 8 | * published by the Free Software Foundation. |
aoqi@1 | 9 | * |
aoqi@1 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@1 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@1 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@1 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@1 | 14 | * accompanied this code). |
aoqi@1 | 15 | * |
aoqi@1 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@1 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@1 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@1 | 19 | * |
aoqi@1 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@1 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@1 | 22 | * questions. |
aoqi@1 | 23 | * |
aoqi@1 | 24 | */ |
aoqi@1 | 25 | |
aoqi@1 | 26 | #include "precompiled.hpp" |
aoqi@1 | 27 | #include "asm/macroAssembler.inline.hpp" |
aoqi@1 | 28 | #include "code/compiledIC.hpp" |
aoqi@1 | 29 | #include "code/icBuffer.hpp" |
aoqi@1 | 30 | #include "code/nmethod.hpp" |
aoqi@1 | 31 | #include "memory/resourceArea.hpp" |
aoqi@1 | 32 | #include "runtime/mutexLocker.hpp" |
aoqi@1 | 33 | #include "runtime/safepoint.hpp" |
aoqi@1 | 34 | |
aoqi@1 | 35 | // Release the CompiledICHolder* associated with this call site is there is one. |
aoqi@1 | 36 | void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { |
aoqi@1 | 37 | // This call site might have become stale so inspect it carefully. |
aoqi@1 | 38 | NativeCall* call = nativeCall_at(call_site->addr()); |
aoqi@1 | 39 | if (is_icholder_entry(call->destination())) { |
aoqi@1 | 40 | NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); |
aoqi@1 | 41 | InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); |
aoqi@1 | 42 | } |
aoqi@1 | 43 | } |
aoqi@1 | 44 | |
aoqi@1 | 45 | bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { |
aoqi@1 | 46 | // This call site might have become stale so inspect it carefully. |
aoqi@1 | 47 | NativeCall* call = nativeCall_at(call_site->addr()); |
aoqi@1 | 48 | return is_icholder_entry(call->destination()); |
aoqi@1 | 49 | } |
aoqi@1 | 50 | |
aoqi@1 | 51 | //----------------------------------------------------------------------------- |
aoqi@1 | 52 | // High-level access to an inline cache. Guaranteed to be MT-safe. |
aoqi@1 | 53 | |
aoqi@1 | 54 | CompiledIC::CompiledIC(nmethod* nm, NativeCall* call) |
aoqi@1 | 55 | : _ic_call(call) |
aoqi@1 | 56 | { |
aoqi@1 | 57 | address ic_call = call->instruction_address(); |
aoqi@1 | 58 | |
aoqi@1 | 59 | assert(ic_call != NULL, "ic_call address must be set"); |
aoqi@1 | 60 | assert(nm != NULL, "must pass nmethod"); |
aoqi@1 | 61 | assert(nm->contains(ic_call), "must be in nmethod"); |
aoqi@1 | 62 | |
aoqi@1 | 63 | // Search for the ic_call at the given address. |
aoqi@1 | 64 | RelocIterator iter(nm, ic_call, ic_call+1); |
aoqi@1 | 65 | bool ret = iter.next(); |
aoqi@1 | 66 | assert(ret == true, "relocInfo must exist at this address"); |
aoqi@1 | 67 | assert(iter.addr() == ic_call, "must find ic_call"); |
aoqi@1 | 68 | if (iter.type() == relocInfo::virtual_call_type) { |
aoqi@1 | 69 | virtual_call_Relocation* r = iter.virtual_call_reloc(); |
aoqi@1 | 70 | _is_optimized = false; |
aoqi@1 | 71 | _value = nativeMovConstReg_at(r->cached_value()); |
aoqi@1 | 72 | } else { |
aoqi@1 | 73 | assert(iter.type() == relocInfo::opt_virtual_call_type, "must be a virtual call"); |
aoqi@1 | 74 | _is_optimized = true; |
aoqi@1 | 75 | _value = NULL; |
aoqi@1 | 76 | } |
aoqi@1 | 77 | } |
aoqi@1 | 78 | |
aoqi@1 | 79 | // ---------------------------------------------------------------------------- |
aoqi@1 | 80 | |
aoqi@1 | 81 | #define __ _masm. |
aoqi@1 | 82 | void CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) { |
aoqi@1 | 83 | |
aoqi@1 | 84 | address mark = cbuf.insts_mark(); // get mark within main instrs section |
aoqi@1 | 85 | |
aoqi@1 | 86 | // Note that the code buffer's insts_mark is always relative to insts. |
aoqi@1 | 87 | // That's why we must use the macroassembler to generate a stub. |
aoqi@1 | 88 | MacroAssembler _masm(&cbuf); |
aoqi@1 | 89 | |
aoqi@1 | 90 | address base = |
aoqi@1 | 91 | __ start_a_stub(Compile::MAX_stubs_size); |
aoqi@1 | 92 | if (base == NULL) return; // CodeBuffer::expand failed |
aoqi@1 | 93 | // static stub relocation stores the instruction address of the call |
aoqi@1 | 94 | |
aoqi@1 | 95 | __ relocate(static_stub_Relocation::spec(mark), 0); |
aoqi@1 | 96 | |
aoqi@1 | 97 | /* 2012/10/29 Jin: Rmethod contains methodOop, it should be relocated for GC */ |
aoqi@1 | 98 | /* |
aoqi@1 | 99 | int oop_index = __ oop_recorder()->allocate_index(NULL); |
aoqi@1 | 100 | RelocationHolder rspec = oop_Relocation::spec(oop_index); |
aoqi@1 | 101 | __ relocate(rspec); |
aoqi@1 | 102 | */ |
aoqi@1 | 103 | |
aoqi@1 | 104 | // static stub relocation also tags the methodOop in the code-stream. |
fujie@368 | 105 | __ patchable_set48(S3, (long)0); |
aoqi@1 | 106 | // This is recognized as unresolved by relocs/nativeInst/ic code |
aoqi@1 | 107 | |
aoqi@1 | 108 | __ relocate(relocInfo::runtime_call_type); |
aoqi@1 | 109 | |
aoqi@1 | 110 | cbuf.set_insts_mark(); |
aoqi@1 | 111 | address call_pc = (address)-1; |
fujie@386 | 112 | __ patchable_jump(call_pc); |
aoqi@1 | 113 | __ align(16); |
aoqi@1 | 114 | __ end_a_stub(); |
aoqi@1 | 115 | // Update current stubs pointer and restore code_end. |
aoqi@1 | 116 | } |
aoqi@1 | 117 | #undef __ |
aoqi@1 | 118 | |
aoqi@1 | 119 | int CompiledStaticCall::to_interp_stub_size() { |
aoqi@1 | 120 | int size = 4 * 4 + NativeCall::instruction_size; // sizeof(li48) + NativeCall::instruction_size |
aoqi@1 | 121 | return round_to(size, 16); |
aoqi@1 | 122 | } |
aoqi@1 | 123 | |
aoqi@1 | 124 | // Relocation entries for call stub, compiled java to interpreter. |
aoqi@1 | 125 | int CompiledStaticCall::reloc_to_interp_stub() { |
aoqi@1 | 126 | return 16; |
aoqi@1 | 127 | } |
aoqi@1 | 128 | |
aoqi@1 | 129 | void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) { |
aoqi@1 | 130 | address stub = find_stub(); |
aoqi@1 | 131 | guarantee(stub != NULL, "stub not found"); |
aoqi@1 | 132 | |
aoqi@1 | 133 | if (TraceICs) { |
aoqi@1 | 134 | ResourceMark rm; |
aoqi@1 | 135 | tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", |
aoqi@1 | 136 | instruction_address(), |
aoqi@1 | 137 | callee->name_and_sig_as_C_string()); |
aoqi@1 | 138 | } |
aoqi@1 | 139 | |
aoqi@1 | 140 | // Creation also verifies the object. |
aoqi@1 | 141 | NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); |
aoqi@1 | 142 | #ifndef MIPS64 |
aoqi@1 | 143 | NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 144 | #else |
aoqi@1 | 145 | NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 146 | #endif |
aoqi@1 | 147 | |
aoqi@1 | 148 | assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(), |
aoqi@1 | 149 | "a) MT-unsafe modification of inline cache"); |
aoqi@1 | 150 | assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry, |
aoqi@1 | 151 | "b) MT-unsafe modification of inline cache"); |
aoqi@1 | 152 | |
aoqi@1 | 153 | // Update stub. |
aoqi@1 | 154 | method_holder->set_data((intptr_t)callee()); |
aoqi@1 | 155 | jump->set_jump_destination(entry); |
aoqi@1 | 156 | |
aoqi@1 | 157 | // Update jump to call. |
aoqi@1 | 158 | set_destination_mt_safe(stub); |
aoqi@1 | 159 | } |
aoqi@1 | 160 | |
aoqi@1 | 161 | void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { |
aoqi@1 | 162 | assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
aoqi@1 | 163 | // Reset stub. |
aoqi@1 | 164 | address stub = static_stub->addr(); |
aoqi@1 | 165 | assert(stub != NULL, "stub not found"); |
aoqi@1 | 166 | // Creation also verifies the object. |
aoqi@1 | 167 | NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); |
aoqi@1 | 168 | #ifndef MIPS64 |
aoqi@1 | 169 | NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 170 | #else |
aoqi@1 | 171 | NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 172 | #endif |
aoqi@1 | 173 | method_holder->set_data(0); |
aoqi@1 | 174 | jump->set_jump_destination((address)-1); |
aoqi@1 | 175 | } |
aoqi@1 | 176 | |
aoqi@1 | 177 | //----------------------------------------------------------------------------- |
aoqi@1 | 178 | // Non-product mode code |
aoqi@1 | 179 | #ifndef PRODUCT |
aoqi@1 | 180 | |
aoqi@1 | 181 | void CompiledStaticCall::verify() { |
aoqi@1 | 182 | // Verify call. |
aoqi@1 | 183 | NativeCall::verify(); |
aoqi@1 | 184 | if (os::is_MP()) { |
aoqi@1 | 185 | verify_alignment(); |
aoqi@1 | 186 | } |
aoqi@1 | 187 | |
aoqi@1 | 188 | // Verify stub. |
aoqi@1 | 189 | address stub = find_stub(); |
aoqi@1 | 190 | assert(stub != NULL, "no stub found for static call"); |
aoqi@1 | 191 | // Creation also verifies the object. |
aoqi@1 | 192 | NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); |
aoqi@1 | 193 | #ifndef MIPS64 |
aoqi@1 | 194 | NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 195 | #else |
aoqi@1 | 196 | NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address()); |
aoqi@1 | 197 | #endif |
aoqi@1 | 198 | |
aoqi@1 | 199 | |
aoqi@1 | 200 | // Verify state. |
aoqi@1 | 201 | assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); |
aoqi@1 | 202 | } |
aoqi@1 | 203 | |
aoqi@1 | 204 | #endif // !PRODUCT |