author | coleenp |
Wed, 06 Jun 2018 10:45:40 -0400 | |
changeset 50429 | 83aec1d357d4 |
parent 49849 | 2aa32bb6f3dc |
child 51620 | 4871c2d2e97e |
permissions | -rw-r--r-- |
42664 | 1 |
/* |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47765
diff
changeset
|
2 |
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
42664 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
// This file mirror as much as possible methodHandles_x86.cpp to ease |
|
26 |
// cross platform development for JSR292. |
|
27 |
// Last synchronization: changeset f8c9417e3571 |
|
28 |
||
29 |
#include "precompiled.hpp" |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
30 |
#include "jvm.h" |
42664 | 31 |
#include "classfile/javaClasses.inline.hpp" |
32 |
#include "interpreter/interpreter.hpp" |
|
33 |
#include "interpreter/interpreterRuntime.hpp" |
|
34 |
#include "memory/allocation.inline.hpp" |
|
35 |
#include "memory/resourceArea.hpp" |
|
36 |
#include "prims/methodHandles.hpp" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47765
diff
changeset
|
37 |
#include "runtime/frame.inline.hpp" |
49849 | 38 |
#include "utilities/preserveException.hpp" |
42664 | 39 |
|
40 |
#define __ _masm-> |
|
41 |
||
42 |
#ifdef PRODUCT |
|
43 |
#define BLOCK_COMMENT(str) /* nothing */ |
|
44 |
#else |
|
45 |
#define BLOCK_COMMENT(str) __ block_comment(str) |
|
46 |
#endif |
|
47 |
||
48 |
#define BIND(label) bind(label); BLOCK_COMMENT(#label ":") |
|
49 |
||
50 |
void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp1, Register temp2) { |
|
51 |
if (VerifyMethodHandles) { |
|
52 |
verify_klass(_masm, klass_reg, temp1, temp2, SystemDictionary::WK_KLASS_ENUM_NAME(java_lang_Class), |
|
53 |
"MH argument is a Class"); |
|
54 |
} |
|
55 |
__ ldr(klass_reg, Address(klass_reg, java_lang_Class::klass_offset_in_bytes())); |
|
56 |
} |
|
57 |
||
58 |
#ifdef ASSERT |
|
59 |
static int check_nonzero(const char* xname, int x) { |
|
60 |
assert(x != 0, "%s should be nonzero", xname); |
|
61 |
return x; |
|
62 |
} |
|
63 |
#define NONZERO(x) check_nonzero(#x, x) |
|
64 |
#else //ASSERT |
|
65 |
#define NONZERO(x) (x) |
|
66 |
#endif //ASSERT |
|
67 |
||
68 |
#ifdef ASSERT |
|
69 |
void MethodHandles::verify_klass(MacroAssembler* _masm, |
|
70 |
Register obj, Register temp1, Register temp2, SystemDictionary::WKID klass_id, |
|
71 |
const char* error_message) { |
|
72 |
InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42664
diff
changeset
|
73 |
Klass* klass = SystemDictionary::well_known_klass(klass_id); |
42664 | 74 |
Label L_ok, L_bad; |
75 |
BLOCK_COMMENT("verify_klass {"); |
|
76 |
__ verify_oop(obj); |
|
77 |
__ cbz(obj, L_bad); |
|
78 |
__ load_klass(temp1, obj); |
|
79 |
__ lea(temp2, ExternalAddress((address) klass_addr)); |
|
80 |
__ ldr(temp2, temp2); // the cmpptr on x86 dereferences the AddressLiteral (not lea) |
|
81 |
__ cmp(temp1, temp2); |
|
82 |
__ b(L_ok, eq); |
|
83 |
intptr_t super_check_offset = klass->super_check_offset(); |
|
84 |
__ ldr(temp1, Address(temp1, super_check_offset)); |
|
85 |
__ cmp(temp1, temp2); |
|
86 |
__ b(L_ok, eq); |
|
87 |
||
88 |
__ bind(L_bad); |
|
89 |
__ stop(error_message); |
|
90 |
__ BIND(L_ok); |
|
91 |
BLOCK_COMMENT("} verify_klass"); |
|
92 |
} |
|
93 |
||
94 |
void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) { |
|
95 |
Label L; |
|
96 |
BLOCK_COMMENT("verify_ref_kind {"); |
|
97 |
__ ldr_u32(temp, Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes()))); |
|
98 |
__ logical_shift_right(temp, temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT); |
|
99 |
__ andr(temp, temp, (unsigned)java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK); |
|
100 |
__ cmp(temp, ref_kind); |
|
101 |
__ b(L, eq); |
|
102 |
{ char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal); |
|
103 |
jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind); |
|
104 |
if (ref_kind == JVM_REF_invokeVirtual || |
|
105 |
ref_kind == JVM_REF_invokeSpecial) |
|
106 |
// could do this for all ref_kinds, but would explode assembly code size |
|
107 |
trace_method_handle(_masm, buf); |
|
108 |
__ stop(buf); |
|
109 |
} |
|
110 |
BLOCK_COMMENT("} verify_ref_kind"); |
|
111 |
__ bind(L); |
|
112 |
} |
|
113 |
||
114 |
#endif //ASSERT |
|
115 |
||
116 |
void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, bool for_compiler_entry) { |
|
117 |
Label L_no_such_method; |
|
118 |
__ cbz(Rmethod, L_no_such_method); |
|
119 |
||
120 |
// Note: JVMTI overhead seems small enough compared to invocation |
|
121 |
// cost and is not worth the complexity or code size overhead of |
|
122 |
// supporting several variants of each adapter. |
|
123 |
if (!for_compiler_entry && (JvmtiExport::can_post_interpreter_events())) { |
|
124 |
// JVMTI events, such as single-stepping, are implemented partly by avoiding running |
|
125 |
// compiled code in threads for which the event is enabled. Check here for |
|
126 |
// interp_only_mode if these events CAN be enabled. |
|
127 |
__ ldr_s32(Rtemp, Address(Rthread, JavaThread::interp_only_mode_offset())); |
|
128 |
#ifdef AARCH64 |
|
129 |
Label L; |
|
130 |
__ cbz(Rtemp, L); |
|
131 |
__ indirect_jump(Address(Rmethod, Method::interpreter_entry_offset()), Rtemp); |
|
132 |
__ bind(L); |
|
133 |
#else |
|
134 |
__ cmp(Rtemp, 0); |
|
135 |
__ ldr(PC, Address(Rmethod, Method::interpreter_entry_offset()), ne); |
|
136 |
#endif // AARCH64 |
|
137 |
} |
|
138 |
const ByteSize entry_offset = for_compiler_entry ? Method::from_compiled_offset() : |
|
139 |
Method::from_interpreted_offset(); |
|
140 |
||
141 |
__ indirect_jump(Address(Rmethod, entry_offset), Rtemp); |
|
142 |
||
143 |
__ bind(L_no_such_method); |
|
144 |
// throw exception |
|
145 |
__ jump(StubRoutines::throw_AbstractMethodError_entry(), relocInfo::runtime_call_type, Rtemp); |
|
146 |
} |
|
147 |
||
148 |
void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm, |
|
149 |
Register recv, Register tmp, |
|
150 |
bool for_compiler_entry) { |
|
151 |
BLOCK_COMMENT("jump_to_lambda_form {"); |
|
152 |
// This is the initial entry point of a lazy method handle. |
|
153 |
// After type checking, it picks up the invoker from the LambdaForm. |
|
154 |
assert_different_registers(recv, tmp, Rmethod); |
|
155 |
||
156 |
// Load the invoker, as MH -> MH.form -> LF.vmentry |
|
157 |
__ load_heap_oop(tmp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes()))); |
|
158 |
__ verify_oop(tmp); |
|
159 |
||
160 |
__ load_heap_oop(tmp, Address(tmp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes()))); |
|
161 |
__ verify_oop(tmp); |
|
162 |
||
46505
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
163 |
__ load_heap_oop(Rmethod, Address(tmp, NONZERO(java_lang_invoke_MemberName::method_offset_in_bytes()))); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
164 |
__ verify_oop(Rmethod); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
165 |
__ ldr(Rmethod, Address(Rmethod, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset_in_bytes()))); |
42664 | 166 |
|
167 |
if (VerifyMethodHandles && !for_compiler_entry) { |
|
168 |
// make sure recv is already on stack |
|
169 |
__ ldr(tmp, Address(Rmethod, Method::const_offset())); |
|
170 |
__ load_sized_value(tmp, |
|
171 |
Address(tmp, ConstMethod::size_of_parameters_offset()), |
|
172 |
sizeof(u2), /*is_signed*/ false); |
|
173 |
// assert(sizeof(u2) == sizeof(Method::_size_of_parameters), ""); |
|
174 |
Label L; |
|
175 |
__ ldr(tmp, __ receiver_argument_address(Rparams, tmp, tmp)); |
|
176 |
__ cmp(tmp, recv); |
|
177 |
__ b(L, eq); |
|
178 |
__ stop("receiver not on stack"); |
|
179 |
__ bind(L); |
|
180 |
} |
|
181 |
||
182 |
jump_from_method_handle(_masm, for_compiler_entry); |
|
183 |
BLOCK_COMMENT("} jump_to_lambda_form"); |
|
184 |
} |
|
185 |
||
186 |
||
187 |
// Code generation |
|
188 |
address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm, |
|
189 |
vmIntrinsics::ID iid) { |
|
190 |
const bool not_for_compiler_entry = false; // this is the interpreter entry |
|
191 |
assert(is_signature_polymorphic(iid), "expected invoke iid"); |
|
192 |
if (iid == vmIntrinsics::_invokeGeneric || |
|
193 |
iid == vmIntrinsics::_compiledLambdaForm) { |
|
194 |
// Perhaps surprisingly, the user-visible names, and linkToCallSite, are not directly used. |
|
195 |
// They are linked to Java-generated adapters via MethodHandleNatives.linkMethod. |
|
196 |
// They all require an extra argument. |
|
197 |
__ should_not_reach_here(); // empty stubs make SG sick |
|
198 |
return NULL; |
|
199 |
} |
|
200 |
||
201 |
// Rmethod: Method* |
|
202 |
// Rparams (SP on 32-bit ARM): pointer to parameters |
|
203 |
// Rsender_sp (R4/R19): sender SP (must preserve; see prepare_to_jump_from_interpreted) |
|
204 |
// R5_mh: receiver method handle (must load from sp[MethodTypeForm.vmslots]) |
|
205 |
// R1, R2, Rtemp: garbage temp, blown away |
|
206 |
||
207 |
// Use same name as x86 to ease future merges |
|
208 |
Register rdx_temp = R2_tmp; |
|
209 |
Register rdx_param_size = rdx_temp; // size of parameters |
|
210 |
Register rax_temp = R1_tmp; |
|
211 |
Register rcx_mh = R5_mh; // MH receiver; dies quickly and is recycled |
|
212 |
Register rbx_method = Rmethod; // eventual target of this invocation |
|
213 |
Register rdi_temp = Rtemp; |
|
214 |
||
215 |
// here's where control starts out: |
|
216 |
__ align(CodeEntryAlignment); |
|
217 |
address entry_point = __ pc(); |
|
218 |
||
219 |
if (VerifyMethodHandles) { |
|
220 |
Label L; |
|
221 |
BLOCK_COMMENT("verify_intrinsic_id {"); |
|
222 |
__ ldrh(rdi_temp, Address(rbx_method, Method::intrinsic_id_offset_in_bytes())); |
|
223 |
__ sub_slow(rdi_temp, rdi_temp, (int) iid); |
|
224 |
__ cbz(rdi_temp, L); |
|
225 |
if (iid == vmIntrinsics::_linkToVirtual || |
|
226 |
iid == vmIntrinsics::_linkToSpecial) { |
|
227 |
// could do this for all kinds, but would explode assembly code size |
|
228 |
trace_method_handle(_masm, "bad Method*::intrinsic_id"); |
|
229 |
} |
|
230 |
__ stop("bad Method*::intrinsic_id"); |
|
231 |
__ bind(L); |
|
232 |
BLOCK_COMMENT("} verify_intrinsic_id"); |
|
233 |
} |
|
234 |
||
235 |
// First task: Find out how big the argument list is. |
|
236 |
Address rdx_first_arg_addr; |
|
237 |
int ref_kind = signature_polymorphic_intrinsic_ref_kind(iid); |
|
238 |
assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic"); |
|
239 |
if (ref_kind == 0 || MethodHandles::ref_kind_has_receiver(ref_kind)) { |
|
240 |
__ ldr(rdx_param_size, Address(rbx_method, Method::const_offset())); |
|
241 |
__ load_sized_value(rdx_param_size, |
|
242 |
Address(rdx_param_size, ConstMethod::size_of_parameters_offset()), |
|
243 |
sizeof(u2), /*is_signed*/ false); |
|
244 |
// assert(sizeof(u2) == sizeof(Method::_size_of_parameters), ""); |
|
245 |
rdx_first_arg_addr = __ receiver_argument_address(Rparams, rdx_param_size, rdi_temp); |
|
246 |
} else { |
|
247 |
DEBUG_ONLY(rdx_param_size = noreg); |
|
248 |
} |
|
249 |
||
250 |
if (!is_signature_polymorphic_static(iid)) { |
|
251 |
__ ldr(rcx_mh, rdx_first_arg_addr); |
|
252 |
DEBUG_ONLY(rdx_param_size = noreg); |
|
253 |
} |
|
254 |
||
255 |
// rdx_first_arg_addr is live! |
|
256 |
||
257 |
trace_method_handle_interpreter_entry(_masm, iid); |
|
258 |
||
259 |
if (iid == vmIntrinsics::_invokeBasic) { |
|
260 |
generate_method_handle_dispatch(_masm, iid, rcx_mh, noreg, not_for_compiler_entry); |
|
261 |
||
262 |
} else { |
|
263 |
// Adjust argument list by popping the trailing MemberName argument. |
|
264 |
Register rcx_recv = noreg; |
|
265 |
if (MethodHandles::ref_kind_has_receiver(ref_kind)) { |
|
266 |
// Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack. |
|
267 |
__ ldr(rcx_recv = rcx_mh, rdx_first_arg_addr); |
|
268 |
DEBUG_ONLY(rdx_param_size = noreg); |
|
269 |
} |
|
270 |
Register rbx_member = rbx_method; // MemberName ptr; incoming method ptr is dead now |
|
271 |
#ifdef AARCH64 |
|
272 |
__ ldr(rbx_member, Address(Rparams, Interpreter::stackElementSize, post_indexed)); |
|
273 |
#else |
|
274 |
__ pop(rbx_member); |
|
275 |
#endif |
|
276 |
generate_method_handle_dispatch(_masm, iid, rcx_recv, rbx_member, not_for_compiler_entry); |
|
277 |
} |
|
278 |
return entry_point; |
|
279 |
} |
|
280 |
||
281 |
void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm, |
|
282 |
vmIntrinsics::ID iid, |
|
283 |
Register receiver_reg, |
|
284 |
Register member_reg, |
|
285 |
bool for_compiler_entry) { |
|
286 |
assert(is_signature_polymorphic(iid), "expected invoke iid"); |
|
287 |
// Use same name as x86 to ease future merges |
|
288 |
Register rbx_method = Rmethod; // eventual target of this invocation |
|
289 |
// temps used in this code are not used in *either* compiled or interpreted calling sequences |
|
290 |
Register temp1 = (for_compiler_entry ? saved_last_sp_register() : R1_tmp); |
|
291 |
Register temp2 = AARCH64_ONLY(R9) NOT_AARCH64(R8); |
|
292 |
Register temp3 = Rtemp; // R12/R16 |
|
293 |
Register temp4 = AARCH64_ONLY(Rtemp2) NOT_AARCH64(R5); |
|
294 |
if (for_compiler_entry) { |
|
295 |
assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : j_rarg0), "only valid assignment"); |
|
296 |
#ifdef AARCH64 |
|
297 |
assert_different_registers(temp1, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5, j_rarg6, j_rarg7); |
|
298 |
assert_different_registers(temp2, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5, j_rarg6, j_rarg7); |
|
299 |
assert_different_registers(temp3, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5, j_rarg6, j_rarg7); |
|
300 |
assert_different_registers(temp4, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5, j_rarg6, j_rarg7); |
|
301 |
#else |
|
302 |
assert_different_registers(temp1, j_rarg0, j_rarg1, j_rarg2, j_rarg3); |
|
303 |
assert_different_registers(temp2, j_rarg0, j_rarg1, j_rarg2, j_rarg3); |
|
304 |
assert_different_registers(temp3, j_rarg0, j_rarg1, j_rarg2, j_rarg3); |
|
305 |
assert_different_registers(temp4, j_rarg0, j_rarg1, j_rarg2, j_rarg3); |
|
306 |
#endif // AARCH64 |
|
307 |
} |
|
308 |
assert_different_registers(temp1, temp2, temp3, receiver_reg); |
|
309 |
assert_different_registers(temp1, temp2, temp3, temp4, member_reg); |
|
310 |
if (!for_compiler_entry) |
|
311 |
assert_different_registers(temp1, temp2, temp3, temp4, saved_last_sp_register()); // don't trash lastSP |
|
312 |
||
313 |
if (iid == vmIntrinsics::_invokeBasic) { |
|
314 |
// indirect through MH.form.exactInvoker.vmtarget |
|
315 |
jump_to_lambda_form(_masm, receiver_reg, temp3, for_compiler_entry); |
|
316 |
||
317 |
} else { |
|
318 |
// The method is a member invoker used by direct method handles. |
|
319 |
if (VerifyMethodHandles) { |
|
320 |
// make sure the trailing argument really is a MemberName (caller responsibility) |
|
321 |
verify_klass(_masm, member_reg, temp2, temp3, SystemDictionary::WK_KLASS_ENUM_NAME(java_lang_invoke_MemberName), |
|
322 |
"MemberName required for invokeVirtual etc."); |
|
323 |
} |
|
324 |
||
325 |
Address member_clazz( member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset_in_bytes())); |
|
326 |
Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset_in_bytes())); |
|
46505
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
327 |
Address member_vmtarget(member_reg, NONZERO(java_lang_invoke_MemberName::method_offset_in_bytes())); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
328 |
Address vmtarget_method(Rmethod, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset_in_bytes())); |
42664 | 329 |
|
330 |
Register temp1_recv_klass = temp1; |
|
331 |
if (iid != vmIntrinsics::_linkToStatic) { |
|
332 |
if (iid == vmIntrinsics::_linkToSpecial) { |
|
333 |
// Don't actually load the klass; just null-check the receiver. |
|
334 |
__ null_check(receiver_reg, temp3); |
|
335 |
} else { |
|
336 |
// load receiver klass itself |
|
337 |
__ null_check(receiver_reg, temp3, oopDesc::klass_offset_in_bytes()); |
|
338 |
__ load_klass(temp1_recv_klass, receiver_reg); |
|
339 |
__ verify_klass_ptr(temp1_recv_klass); |
|
340 |
} |
|
341 |
BLOCK_COMMENT("check_receiver {"); |
|
342 |
// The receiver for the MemberName must be in receiver_reg. |
|
343 |
// Check the receiver against the MemberName.clazz |
|
344 |
if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) { |
|
345 |
// Did not load it above... |
|
346 |
__ load_klass(temp1_recv_klass, receiver_reg); |
|
347 |
__ verify_klass_ptr(temp1_recv_klass); |
|
348 |
} |
|
349 |
// Check the receiver against the MemberName.clazz |
|
350 |
if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) { |
|
351 |
Label L_ok; |
|
352 |
Register temp2_defc = temp2; |
|
353 |
__ load_heap_oop(temp2_defc, member_clazz); |
|
354 |
load_klass_from_Class(_masm, temp2_defc, temp3, temp4); |
|
355 |
__ verify_klass_ptr(temp2_defc); |
|
356 |
#ifdef AARCH64 |
|
357 |
// TODO-AARCH64 |
|
358 |
__ b(L_ok); |
|
359 |
#else |
|
360 |
__ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, temp4, noreg, L_ok); |
|
361 |
#endif |
|
362 |
// If we get here, the type check failed! |
|
363 |
__ stop("receiver class disagrees with MemberName.clazz"); |
|
364 |
__ bind(L_ok); |
|
365 |
} |
|
366 |
BLOCK_COMMENT("} check_receiver"); |
|
367 |
} |
|
368 |
if (iid == vmIntrinsics::_linkToSpecial || |
|
369 |
iid == vmIntrinsics::_linkToStatic) { |
|
370 |
DEBUG_ONLY(temp1_recv_klass = noreg); // these guys didn't load the recv_klass |
|
371 |
} |
|
372 |
||
373 |
// Live registers at this point: |
|
374 |
// member_reg - MemberName that was the extra argument |
|
375 |
// temp1_recv_klass - klass of stacked receiver, if needed |
|
376 |
||
377 |
Label L_incompatible_class_change_error; |
|
378 |
switch (iid) { |
|
379 |
case vmIntrinsics::_linkToSpecial: |
|
380 |
if (VerifyMethodHandles) { |
|
381 |
verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp3); |
|
382 |
} |
|
46505
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
383 |
__ load_heap_oop(Rmethod, member_vmtarget); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
384 |
__ ldr(Rmethod, vmtarget_method); |
42664 | 385 |
break; |
386 |
||
387 |
case vmIntrinsics::_linkToStatic: |
|
388 |
if (VerifyMethodHandles) { |
|
389 |
verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp3); |
|
390 |
} |
|
46505
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
391 |
__ load_heap_oop(Rmethod, member_vmtarget); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
392 |
__ ldr(Rmethod, vmtarget_method); |
fd4bc78630b1
8174749: Use hash table/oops for MemberName table
coleenp
parents:
46329
diff
changeset
|
393 |
break; |
42664 | 394 |
break; |
395 |
||
396 |
case vmIntrinsics::_linkToVirtual: |
|
397 |
{ |
|
398 |
// same as TemplateTable::invokevirtual, |
|
399 |
// minus the CP setup and profiling: |
|
400 |
||
401 |
if (VerifyMethodHandles) { |
|
402 |
verify_ref_kind(_masm, JVM_REF_invokeVirtual, member_reg, temp3); |
|
403 |
} |
|
404 |
||
405 |
// pick out the vtable index from the MemberName, and then we can discard it: |
|
406 |
Register temp2_index = temp2; |
|
407 |
__ ldr(temp2_index, member_vmindex); |
|
408 |
||
409 |
if (VerifyMethodHandles) { |
|
410 |
Label L_index_ok; |
|
411 |
__ cmp(temp2_index, 0); |
|
412 |
__ b(L_index_ok, ge); |
|
413 |
__ stop("no virtual index"); |
|
414 |
__ bind(L_index_ok); |
|
415 |
} |
|
416 |
||
417 |
// Note: The verifier invariants allow us to ignore MemberName.clazz and vmtarget |
|
418 |
// at this point. And VerifyMethodHandles has already checked clazz, if needed. |
|
419 |
||
420 |
// get target Method* & entry point |
|
421 |
__ lookup_virtual_method(temp1_recv_klass, temp2_index, Rmethod); |
|
422 |
break; |
|
423 |
} |
|
424 |
||
425 |
case vmIntrinsics::_linkToInterface: |
|
426 |
{ |
|
427 |
// same as TemplateTable::invokeinterface |
|
428 |
// (minus the CP setup and profiling, with different argument motion) |
|
429 |
if (VerifyMethodHandles) { |
|
430 |
verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp3); |
|
431 |
} |
|
432 |
||
433 |
Register temp3_intf = temp3; |
|
434 |
__ load_heap_oop(temp3_intf, member_clazz); |
|
435 |
load_klass_from_Class(_masm, temp3_intf, temp2, temp4); |
|
436 |
__ verify_klass_ptr(temp3_intf); |
|
437 |
||
438 |
Register rbx_index = rbx_method; |
|
439 |
__ ldr(rbx_index, member_vmindex); |
|
440 |
if (VerifyMethodHandles) { |
|
441 |
Label L; |
|
442 |
__ cmp(rbx_index, 0); |
|
443 |
__ b(L, ge); |
|
444 |
__ stop("invalid vtable index for MH.invokeInterface"); |
|
445 |
__ bind(L); |
|
446 |
} |
|
447 |
||
448 |
// given intf, index, and recv klass, dispatch to the implementation method |
|
449 |
Label L_no_such_interface; |
|
450 |
__ lookup_interface_method(temp1_recv_klass, temp3_intf, |
|
451 |
// note: next two args must be the same: |
|
452 |
rbx_index, rbx_method, |
|
453 |
temp2, temp4, |
|
454 |
L_incompatible_class_change_error); |
|
455 |
break; |
|
456 |
} |
|
457 |
||
458 |
default: |
|
459 |
fatal("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)); |
|
460 |
break; |
|
461 |
} |
|
462 |
||
463 |
// Live at this point: |
|
464 |
// Rmethod (target method) |
|
465 |
// Rsender_sp, Rparams (if interpreted) |
|
466 |
// register arguments (if compiled) |
|
467 |
||
468 |
// After figuring out which concrete method to call, jump into it. |
|
469 |
__ verify_method_ptr(Rmethod); |
|
470 |
jump_from_method_handle(_masm, for_compiler_entry); |
|
471 |
||
472 |
if (iid == vmIntrinsics::_linkToInterface) { |
|
473 |
__ bind(L_incompatible_class_change_error); |
|
474 |
__ jump(StubRoutines::throw_IncompatibleClassChangeError_entry(), relocInfo::runtime_call_type, Rtemp); |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
478 |
||
479 |
||
480 |
#ifndef PRODUCT |
|
481 |
enum { |
|
482 |
ARG_LIMIT = 255, SLOP = 4, |
|
483 |
// use this parameter for checking for garbage stack movements: |
|
484 |
UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP) |
|
485 |
// the slop defends against false alarms due to fencepost errors |
|
486 |
}; |
|
487 |
||
488 |
#ifdef AARCH64 |
|
489 |
const int trace_mh_nregs = 32; // R0-R30, PC |
|
490 |
#else |
|
491 |
const int trace_mh_nregs = 15; |
|
492 |
const Register trace_mh_regs[trace_mh_nregs] = |
|
493 |
{R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, PC}; |
|
494 |
#endif // AARCH64 |
|
495 |
||
496 |
void trace_method_handle_stub(const char* adaptername, |
|
497 |
intptr_t* saved_regs, |
|
498 |
intptr_t* saved_bp, |
|
499 |
oop mh) { |
|
500 |
// called as a leaf from native code: do not block the JVM! |
|
501 |
bool has_mh = (strstr(adaptername, "/static") == NULL && |
|
502 |
strstr(adaptername, "linkTo") == NULL); // static linkers don't have MH |
|
503 |
intptr_t* entry_sp = (intptr_t*) &saved_regs[trace_mh_nregs]; // just after the saved regs |
|
504 |
intptr_t* saved_sp = (intptr_t*) saved_regs[Rsender_sp->encoding()]; // save of Rsender_sp |
|
505 |
intptr_t* last_sp = (intptr_t*) saved_bp[AARCH64_ONLY(frame::interpreter_frame_stack_top_offset) NOT_AARCH64(frame::interpreter_frame_last_sp_offset)]; |
|
506 |
intptr_t* base_sp = last_sp; |
|
507 |
||
508 |
intptr_t mh_reg = (intptr_t)saved_regs[R5_mh->encoding()]; |
|
509 |
const char* mh_reg_name = "R5_mh"; |
|
510 |
if (!has_mh) mh_reg_name = "R5"; |
|
511 |
tty->print_cr("MH %s %s=" PTR_FORMAT " sp=(" PTR_FORMAT "+" INTX_FORMAT ") stack_size=" INTX_FORMAT " bp=" PTR_FORMAT, |
|
512 |
adaptername, mh_reg_name, mh_reg, |
|
513 |
(intptr_t)entry_sp, (intptr_t)saved_sp - (intptr_t)entry_sp, (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp); |
|
514 |
||
515 |
if (last_sp != saved_sp && last_sp != NULL) |
|
516 |
tty->print_cr("*** last_sp=" INTPTR_FORMAT, p2i(last_sp)); |
|
517 |
if (Verbose) { |
|
518 |
tty->print(" reg dump: "); |
|
519 |
int i; |
|
520 |
for (i = 0; i < trace_mh_nregs; i++) { |
|
521 |
if (i > 0 && i % AARCH64_ONLY(2) NOT_AARCH64(4) == 0) |
|
522 |
tty->print("\n + dump: "); |
|
523 |
#ifdef AARCH64 |
|
524 |
const char* reg_name = (i == trace_mh_nregs-1) ? "pc" : as_Register(i)->name(); |
|
525 |
#else |
|
526 |
const char* reg_name = trace_mh_regs[i]->name(); |
|
527 |
#endif |
|
528 |
tty->print(" %s: " INTPTR_FORMAT, reg_name, p2i((void *)saved_regs[i])); |
|
529 |
} |
|
530 |
tty->cr(); |
|
531 |
} |
|
532 |
||
533 |
if (Verbose) { |
|
534 |
// dump last frame (from JavaThread::print_frame_layout) |
|
535 |
||
536 |
// Note: code is robust but the dumped informationm may not be |
|
537 |
// 100% correct, particularly with respect to the dumped |
|
538 |
// "unextended_sp". Getting it right for all trace_method_handle |
|
539 |
// call paths is not worth the complexity/risk. The correct slot |
|
540 |
// will be identified by *Rsender_sp anyway in the dump. |
|
541 |
JavaThread* p = JavaThread::active(); |
|
542 |
||
543 |
ResourceMark rm; |
|
544 |
PRESERVE_EXCEPTION_MARK; |
|
545 |
FrameValues values; |
|
546 |
||
547 |
intptr_t* dump_fp = (intptr_t *) saved_bp; |
|
548 |
address dump_pc = (address) saved_regs[trace_mh_nregs-2]; // LR (with LR,PC last in saved_regs) |
|
549 |
frame dump_frame((intptr_t *)entry_sp, dump_fp, dump_pc); |
|
550 |
||
551 |
dump_frame.describe(values, 1); |
|
552 |
// mark Rsender_sp if seems valid |
|
553 |
if (has_mh) { |
|
554 |
if ((saved_sp >= entry_sp - UNREASONABLE_STACK_MOVE) && (saved_sp < dump_fp)) { |
|
555 |
values.describe(-1, saved_sp, "*Rsender_sp"); |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
// Note: the unextended_sp may not be correct |
|
560 |
tty->print_cr(" stack layout:"); |
|
561 |
values.print(p); |
|
562 |
} |
|
563 |
if (Verbose) { |
|
46968
9119841280f4
8160399: is_oop_or_null involves undefined behavior
coleenp
parents:
46560
diff
changeset
|
564 |
if (has_mh && oopDesc::is_oop(mh)) { |
42664 | 565 |
mh->print(); |
566 |
if (java_lang_invoke_MethodHandle::is_instance(mh)) { |
|
567 |
if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0) |
|
568 |
java_lang_invoke_MethodHandle::form(mh)->print(); |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) { |
|
575 |
if (!TraceMethodHandles) return; |
|
576 |
BLOCK_COMMENT("trace_method_handle {"); |
|
577 |
// register saving |
|
578 |
// must correspond to trace_mh_nregs and trace_mh_regs defined above |
|
579 |
int push_size = __ save_all_registers(); |
|
580 |
assert(trace_mh_nregs*wordSize == push_size,"saved register count mismatch"); |
|
581 |
||
582 |
__ mov_slow(R0, adaptername); |
|
583 |
__ mov(R1, SP); // entry_sp (after pushes) |
|
584 |
__ mov(R2, FP); |
|
585 |
if (R5_mh != R3) { |
|
586 |
assert_different_registers(R0, R1, R2, R5_mh); |
|
587 |
__ mov(R3, R5_mh); |
|
588 |
} |
|
589 |
||
590 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), R0, R1, R2, R3); |
|
591 |
||
592 |
__ restore_all_registers(); |
|
593 |
BLOCK_COMMENT("} trace_method_handle"); |
|
594 |
} |
|
595 |
#endif //PRODUCT |