src/cpu/x86/vm/compiledIC_x86.cpp

Wed, 12 Mar 2014 11:24:26 -0700

author
iveresov
date
Wed, 12 Mar 2014 11:24:26 -0700
changeset 6378
8a8ff6b577ed
parent 5000
a6e09d6dd8e5
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8031321: Support Intel bit manipulation instructions
Summary: Add support for BMI1 instructions
Reviewed-by: kvn, roland

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

mercurial