src/cpu/x86/vm/compiledIC_x86.cpp

Fri, 16 Aug 2019 16:50:17 +0200

author
eosterlund
date
Fri, 16 Aug 2019 16:50:17 +0200
changeset 9834
bb1da64b0492
parent 8427
c3d0bd36ab28
child 8604
04d83ba48607
permissions
-rw-r--r--

8229345: Memory leak due to vtable stubs not being shared on SPARC
Reviewed-by: mdoerr, dholmes, kvn

dlong@5000 1 /*
drchase@6680 2 * Copyright (c) 1997, 2014, 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
dlong@5000 52 #define __ _masm.
vkempik@8427 53 address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) {
dlong@5000 54 // Stub is fixed up when the corresponding call is converted from
dlong@5000 55 // calling compiled code to calling interpreted code.
dlong@5000 56 // movq rbx, 0
dlong@5000 57 // jmp -5 # to self
dlong@5000 58
dlong@5000 59 address mark = cbuf.insts_mark(); // Get mark within main instrs section.
dlong@5000 60
dlong@5000 61 // Note that the code buffer's insts_mark is always relative to insts.
dlong@5000 62 // That's why we must use the macroassembler to generate a stub.
dlong@5000 63 MacroAssembler _masm(&cbuf);
dlong@5000 64
vkempik@8427 65 address base = __ start_a_stub(to_interp_stub_size());
vkempik@8427 66 if (base == NULL) {
vkempik@8427 67 return NULL; // CodeBuffer::expand failed.
vkempik@8427 68 }
dlong@5000 69 // Static stub relocation stores the instruction address of the call.
dlong@5000 70 __ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand);
dlong@5000 71 // Static stub relocation also tags the Method* in the code-stream.
dlong@5000 72 __ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time.
dlong@5000 73 // This is recognized as unresolved by relocs/nativeinst/ic code.
dlong@5000 74 __ jump(RuntimeAddress(__ pc()));
dlong@5000 75
dlong@5000 76 // Update current stubs pointer and restore insts_end.
dlong@5000 77 __ end_a_stub();
vkempik@8427 78 return base;
dlong@5000 79 }
dlong@5000 80 #undef __
dlong@5000 81
dlong@5000 82 int CompiledStaticCall::to_interp_stub_size() {
dlong@5000 83 return NOT_LP64(10) // movl; jmp
dlong@5000 84 LP64_ONLY(15); // movq (1+1+8); jmp (1+4)
dlong@5000 85 }
dlong@5000 86
dlong@5000 87 // Relocation entries for call stub, compiled java to interpreter.
dlong@5000 88 int CompiledStaticCall::reloc_to_interp_stub() {
dlong@5000 89 return 4; // 3 in emit_to_interp_stub + 1 in emit_call
dlong@5000 90 }
dlong@5000 91
dlong@5000 92 void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {
dlong@5000 93 address stub = find_stub();
dlong@5000 94 guarantee(stub != NULL, "stub not found");
dlong@5000 95
dlong@5000 96 if (TraceICs) {
dlong@5000 97 ResourceMark rm;
dlong@5000 98 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
drchase@6680 99 p2i(instruction_address()),
dlong@5000 100 callee->name_and_sig_as_C_string());
dlong@5000 101 }
dlong@5000 102
dlong@5000 103 // Creation also verifies the object.
dlong@5000 104 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
dlong@5000 105 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
dlong@5000 106
dlong@5000 107 assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
dlong@5000 108 "a) MT-unsafe modification of inline cache");
dlong@5000 109 assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
dlong@5000 110 "b) MT-unsafe modification of inline cache");
dlong@5000 111
dlong@5000 112 // Update stub.
dlong@5000 113 method_holder->set_data((intptr_t)callee());
dlong@5000 114 jump->set_jump_destination(entry);
dlong@5000 115
dlong@5000 116 // Update jump to call.
dlong@5000 117 set_destination_mt_safe(stub);
dlong@5000 118 }
dlong@5000 119
dlong@5000 120 void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
dlong@5000 121 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
dlong@5000 122 // Reset stub.
dlong@5000 123 address stub = static_stub->addr();
dlong@5000 124 assert(stub != NULL, "stub not found");
dlong@5000 125 // Creation also verifies the object.
dlong@5000 126 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
dlong@5000 127 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
dlong@5000 128 method_holder->set_data(0);
dlong@5000 129 jump->set_jump_destination((address)-1);
dlong@5000 130 }
dlong@5000 131
dlong@5000 132 //-----------------------------------------------------------------------------
dlong@5000 133 // Non-product mode code
dlong@5000 134 #ifndef PRODUCT
dlong@5000 135
dlong@5000 136 void CompiledStaticCall::verify() {
dlong@5000 137 // Verify call.
dlong@5000 138 NativeCall::verify();
dlong@5000 139 if (os::is_MP()) {
dlong@5000 140 verify_alignment();
dlong@5000 141 }
dlong@5000 142
dlong@5000 143 // Verify stub.
dlong@5000 144 address stub = find_stub();
dlong@5000 145 assert(stub != NULL, "no stub found for static call");
dlong@5000 146 // Creation also verifies the object.
dlong@5000 147 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
dlong@5000 148 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
dlong@5000 149
dlong@5000 150 // Verify state.
dlong@5000 151 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
dlong@5000 152 }
dlong@5000 153
dlong@5000 154 #endif // !PRODUCT

mercurial