author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58556 | ff8716224f35 |
permissions | -rw-r--r-- |
29183 | 1 |
/* |
58505
c16f3a24a6fc
8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
coleenp
parents:
54440
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
50104 | 3 |
* Copyright (c) 2014, 2018, Red Hat Inc. All rights reserved. |
29183 | 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 |
// ---------------------------------------------------------------------------- |
|
36 |
||
37 |
#define __ _masm. |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32082
diff
changeset
|
38 |
address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark) { |
29183 | 39 |
// Stub is fixed up when the corresponding call is converted from |
40 |
// calling compiled code to calling interpreted code. |
|
41 |
// mov rmethod, 0 |
|
42 |
// jmp -4 # to self |
|
43 |
||
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32082
diff
changeset
|
44 |
if (mark == NULL) { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32082
diff
changeset
|
45 |
mark = cbuf.insts_mark(); // Get mark within main instrs section. |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32082
diff
changeset
|
46 |
} |
29183 | 47 |
|
48 |
// Note that the code buffer's insts_mark is always relative to insts. |
|
49 |
// That's why we must use the macroassembler to generate a stub. |
|
50 |
MacroAssembler _masm(&cbuf); |
|
51 |
||
32082
2a3323e25de1
8130309: Need to bailout cleanly if creation of stubs fails when codecache is out of space
thartmann
parents:
29183
diff
changeset
|
52 |
address base = __ start_a_stub(to_interp_stub_size()); |
29183 | 53 |
int offset = __ offset(); |
32082
2a3323e25de1
8130309: Need to bailout cleanly if creation of stubs fails when codecache is out of space
thartmann
parents:
29183
diff
changeset
|
54 |
if (base == NULL) { |
2a3323e25de1
8130309: Need to bailout cleanly if creation of stubs fails when codecache is out of space
thartmann
parents:
29183
diff
changeset
|
55 |
return NULL; // CodeBuffer::expand failed |
2a3323e25de1
8130309: Need to bailout cleanly if creation of stubs fails when codecache is out of space
thartmann
parents:
29183
diff
changeset
|
56 |
} |
29183 | 57 |
// static stub relocation stores the instruction address of the call |
58 |
__ relocate(static_stub_Relocation::spec(mark)); |
|
50104 | 59 |
|
60 |
#if INCLUDE_AOT |
|
61 |
// Don't create a Metadata reloc if we're generating immutable PIC. |
|
62 |
if (cbuf.immutable_PIC()) { |
|
63 |
__ movptr(rmethod, 0); |
|
54440
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
64 |
__ movptr(rscratch1, 0); |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
65 |
__ br(rscratch1); |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
66 |
|
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
67 |
} else |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
68 |
#endif |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
69 |
{ |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
70 |
__ emit_static_call_stub(); |
50104 | 71 |
} |
29183 | 72 |
|
73 |
assert((__ offset() - offset) <= (int)to_interp_stub_size(), "stub too big"); |
|
74 |
__ end_a_stub(); |
|
32082
2a3323e25de1
8130309: Need to bailout cleanly if creation of stubs fails when codecache is out of space
thartmann
parents:
29183
diff
changeset
|
75 |
return base; |
29183 | 76 |
} |
77 |
#undef __ |
|
78 |
||
79 |
int CompiledStaticCall::to_interp_stub_size() { |
|
54440
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
80 |
// isb; movk; movz; movz; movk; movz; movz; br |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
81 |
return 8 * NativeInstruction::instruction_size; |
29183 | 82 |
} |
83 |
||
48487 | 84 |
int CompiledStaticCall::to_trampoline_stub_size() { |
85 |
// Somewhat pessimistically, we count 3 instructions here (although |
|
86 |
// there are only two) because we sometimes emit an alignment nop. |
|
87 |
// Trampoline stubs are always word aligned. |
|
88 |
return 3 * NativeInstruction::instruction_size + wordSize; |
|
89 |
} |
|
90 |
||
29183 | 91 |
// Relocation entries for call stub, compiled java to interpreter. |
92 |
int CompiledStaticCall::reloc_to_interp_stub() { |
|
93 |
return 4; // 3 in emit_to_interp_stub + 1 in emit_call |
|
94 |
} |
|
95 |
||
50104 | 96 |
#if INCLUDE_AOT |
97 |
#define __ _masm. |
|
98 |
void CompiledStaticCall::emit_to_aot_stub(CodeBuffer &cbuf, address mark) { |
|
99 |
if (!UseAOT) { |
|
100 |
return; |
|
101 |
} |
|
102 |
// Stub is fixed up when the corresponding call is converted from |
|
103 |
// calling compiled code to calling aot code. |
|
104 |
// mov r, imm64_aot_code_address |
|
105 |
// jmp r |
|
106 |
||
107 |
if (mark == NULL) { |
|
108 |
mark = cbuf.insts_mark(); // Get mark within main instrs section. |
|
109 |
} |
|
110 |
||
111 |
// Note that the code buffer's insts_mark is always relative to insts. |
|
112 |
// That's why we must use the macroassembler to generate a stub. |
|
113 |
MacroAssembler _masm(&cbuf); |
|
114 |
||
115 |
address base = |
|
116 |
__ start_a_stub(to_aot_stub_size()); |
|
117 |
guarantee(base != NULL, "out of space"); |
|
118 |
||
119 |
// Static stub relocation stores the instruction address of the call. |
|
120 |
__ relocate(static_stub_Relocation::spec(mark, true /* is_aot */)); |
|
121 |
// Load destination AOT code address. |
|
122 |
__ movptr(rscratch1, 0); // address is zapped till fixup time. |
|
123 |
// This is recognized as unresolved by relocs/nativeinst/ic code. |
|
124 |
__ br(rscratch1); |
|
125 |
||
126 |
assert(__ pc() - base <= to_aot_stub_size(), "wrong stub size"); |
|
127 |
||
128 |
// Update current stubs pointer and restore insts_end. |
|
129 |
__ end_a_stub(); |
|
130 |
} |
|
131 |
#undef __ |
|
132 |
||
133 |
int CompiledStaticCall::to_aot_stub_size() { |
|
134 |
if (UseAOT) { |
|
135 |
return 5 * 4; // movz; movk; movk; movk; br |
|
136 |
} else { |
|
137 |
return 0; |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
// Relocation entries for call stub, compiled java to aot. |
|
142 |
int CompiledStaticCall::reloc_to_aot_stub() { |
|
143 |
if (UseAOT) { |
|
144 |
return 5 * 4; // movz; movk; movk; movk; br |
|
145 |
} else { |
|
146 |
return 0; |
|
147 |
} |
|
148 |
} |
|
149 |
#endif // INCLUDE_AOT |
|
150 |
||
42650 | 151 |
void CompiledDirectStaticCall::set_to_interpreted(const methodHandle& callee, address entry) { |
152 |
address stub = find_stub(false /* is_aot */); |
|
29183 | 153 |
guarantee(stub != NULL, "stub not found"); |
154 |
||
155 |
if (TraceICs) { |
|
156 |
ResourceMark rm; |
|
42650 | 157 |
tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", |
29183 | 158 |
p2i(instruction_address()), |
159 |
callee->name_and_sig_as_C_string()); |
|
160 |
} |
|
161 |
||
162 |
// Creation also verifies the object. |
|
54440
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
163 |
NativeMovConstReg* method_holder |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
164 |
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size); |
29183 | 165 |
|
58505
c16f3a24a6fc
8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
coleenp
parents:
54440
diff
changeset
|
166 |
#ifdef ASSERT |
c16f3a24a6fc
8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
coleenp
parents:
54440
diff
changeset
|
167 |
NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address()); |
c16f3a24a6fc
8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
coleenp
parents:
54440
diff
changeset
|
168 |
verify_mt_safe(callee, entry, method_holder, jump); |
29183 | 169 |
#endif |
58505
c16f3a24a6fc
8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
coleenp
parents:
54440
diff
changeset
|
170 |
|
29183 | 171 |
// Update stub. |
172 |
method_holder->set_data((intptr_t)callee()); |
|
173 |
NativeGeneralJump::insert_unconditional(method_holder->next_instruction_address(), entry); |
|
174 |
ICache::invalidate_range(stub, to_interp_stub_size()); |
|
175 |
// Update jump to call. |
|
176 |
set_destination_mt_safe(stub); |
|
177 |
} |
|
178 |
||
42650 | 179 |
void CompiledDirectStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { |
29183 | 180 |
// Reset stub. |
181 |
address stub = static_stub->addr(); |
|
182 |
assert(stub != NULL, "stub not found"); |
|
52384
d6dc479bcdd3
8212681: Refactor IC locking to use a fine grained CompiledICLocker
eosterlund
parents:
51996
diff
changeset
|
183 |
assert(CompiledICLocker::is_safe(stub), "mt unsafe call"); |
29183 | 184 |
// Creation also verifies the object. |
54440
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
185 |
NativeMovConstReg* method_holder |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
186 |
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size); |
29183 | 187 |
method_holder->set_data(0); |
58556 | 188 |
if (!static_stub->is_aot()) { |
189 |
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
|
190 |
jump->set_jump_destination((address)-1); |
|
191 |
} |
|
29183 | 192 |
} |
193 |
||
194 |
//----------------------------------------------------------------------------- |
|
195 |
// Non-product mode code |
|
196 |
#ifndef PRODUCT |
|
197 |
||
42650 | 198 |
void CompiledDirectStaticCall::verify() { |
29183 | 199 |
// Verify call. |
42650 | 200 |
_call->verify(); |
51996
84743156e780
8188764: Obsolete AssumeMP and then remove all support for non-MP builds
dholmes
parents:
50104
diff
changeset
|
201 |
_call->verify_alignment(); |
29183 | 202 |
|
203 |
// Verify stub. |
|
42650 | 204 |
address stub = find_stub(false /* is_aot */); |
29183 | 205 |
assert(stub != NULL, "no stub found for static call"); |
206 |
// Creation also verifies the object. |
|
54440
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
207 |
NativeMovConstReg* method_holder |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
208 |
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size); |
23a04fe2aca2
8219993: AArch64: Compiled CI stubs are unsafely modified
aph
parents:
52384
diff
changeset
|
209 |
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
29183 | 210 |
|
211 |
// Verify state. |
|
212 |
assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); |
|
213 |
} |
|
214 |
||
215 |
#endif // !PRODUCT |