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