src/cpu/mips/vm/compiledIC_mips.cpp

Tue, 31 May 2016 00:22:06 -0400

author
aoqi
date
Tue, 31 May 2016 00:22:06 -0400
changeset 16
3cedde979d75
parent 1
2d8a650513c2
child 368
11ec15adb6c4
permissions
-rw-r--r--

[Code Reorganization] load_two_bytes_from_at_bcp -> get_2_byte_integer_at_bcp
remove useless MacroAssembler::store_two_byts_to_at_bcp
change MacroAssembler::load_two_bytes_from_at_bcp to InterpreterMacroAssembler::get_2_byte_integer_at_bcp
change MacroAssembler::get_4_byte_integer_at_bcp to InterpreterMacroAssembler::get_4_byte_integer_at_bcp

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.
aoqi@1 105 __ li48(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;
aoqi@1 112 __ li48(AT, (long)call_pc);
aoqi@1 113 __ jr(AT);
aoqi@1 114 __ nop();
aoqi@1 115 __ align(16);
aoqi@1 116 __ end_a_stub();
aoqi@1 117 // Update current stubs pointer and restore code_end.
aoqi@1 118 }
aoqi@1 119 #undef __
aoqi@1 120
aoqi@1 121 int CompiledStaticCall::to_interp_stub_size() {
aoqi@1 122 int size = 4 * 4 + NativeCall::instruction_size; // sizeof(li48) + NativeCall::instruction_size
aoqi@1 123 return round_to(size, 16);
aoqi@1 124 }
aoqi@1 125
aoqi@1 126 // Relocation entries for call stub, compiled java to interpreter.
aoqi@1 127 int CompiledStaticCall::reloc_to_interp_stub() {
aoqi@1 128 return 16;
aoqi@1 129 }
aoqi@1 130
aoqi@1 131 void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {
aoqi@1 132 address stub = find_stub();
aoqi@1 133 guarantee(stub != NULL, "stub not found");
aoqi@1 134
aoqi@1 135 if (TraceICs) {
aoqi@1 136 ResourceMark rm;
aoqi@1 137 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
aoqi@1 138 instruction_address(),
aoqi@1 139 callee->name_and_sig_as_C_string());
aoqi@1 140 }
aoqi@1 141
aoqi@1 142 // Creation also verifies the object.
aoqi@1 143 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
aoqi@1 144 #ifndef MIPS64
aoqi@1 145 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
aoqi@1 146 #else
aoqi@1 147 NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
aoqi@1 148 #endif
aoqi@1 149
aoqi@1 150 assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
aoqi@1 151 "a) MT-unsafe modification of inline cache");
aoqi@1 152 assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
aoqi@1 153 "b) MT-unsafe modification of inline cache");
aoqi@1 154
aoqi@1 155 // Update stub.
aoqi@1 156 method_holder->set_data((intptr_t)callee());
aoqi@1 157 jump->set_jump_destination(entry);
aoqi@1 158
aoqi@1 159 // Update jump to call.
aoqi@1 160 set_destination_mt_safe(stub);
aoqi@1 161 }
aoqi@1 162
aoqi@1 163 void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
aoqi@1 164 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
aoqi@1 165 // Reset stub.
aoqi@1 166 address stub = static_stub->addr();
aoqi@1 167 assert(stub != NULL, "stub not found");
aoqi@1 168 // Creation also verifies the object.
aoqi@1 169 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
aoqi@1 170 #ifndef MIPS64
aoqi@1 171 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
aoqi@1 172 #else
aoqi@1 173 NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
aoqi@1 174 #endif
aoqi@1 175 method_holder->set_data(0);
aoqi@1 176 jump->set_jump_destination((address)-1);
aoqi@1 177 }
aoqi@1 178
aoqi@1 179 //-----------------------------------------------------------------------------
aoqi@1 180 // Non-product mode code
aoqi@1 181 #ifndef PRODUCT
aoqi@1 182
aoqi@1 183 void CompiledStaticCall::verify() {
aoqi@1 184 // Verify call.
aoqi@1 185 NativeCall::verify();
aoqi@1 186 if (os::is_MP()) {
aoqi@1 187 verify_alignment();
aoqi@1 188 }
aoqi@1 189
aoqi@1 190 // Verify stub.
aoqi@1 191 address stub = find_stub();
aoqi@1 192 assert(stub != NULL, "no stub found for static call");
aoqi@1 193 // Creation also verifies the object.
aoqi@1 194 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
aoqi@1 195 #ifndef MIPS64
aoqi@1 196 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
aoqi@1 197 #else
aoqi@1 198 NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
aoqi@1 199 #endif
aoqi@1 200
aoqi@1 201
aoqi@1 202 // Verify state.
aoqi@1 203 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
aoqi@1 204 }
aoqi@1 205
aoqi@1 206 #endif // !PRODUCT

mercurial