Thu, 07 Sep 2017 09:12:16 +0800
#5745 [Code Reorganization] code cleanup and code style fix
This is a huge patch, but only code cleanup, code style fix and useless code deletion are included, for example:
tab -> two spaces, deleted spacees at the end of a line, delete useless comments.
This patch also included:
Declaration and definition of class MacroAssembler is moved from assembler_mips.h/cpp to macroAssembler_mips.h/cpp
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2016, Loongson Technology. 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 */
26 #include "precompiled.hpp"
27 #include "asm/macroAssembler.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/interpreterRuntime.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "prims/methodHandles.hpp"
33 #define __ _masm->
35 #ifdef PRODUCT
36 #define BLOCK_COMMENT(str) /* nothing */
37 #define STOP(error) stop(error)
38 #else
39 #define BLOCK_COMMENT(str) __ block_comment(str)
40 #define STOP(error) block_comment(error); __ stop(error)
41 #endif
43 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
45 void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg) {
46 if (VerifyMethodHandles)
47 verify_klass(_masm, klass_reg, SystemDictionary::WK_KLASS_ENUM_NAME(java_lang_Class),
48 "MH argument is a Class");
49 __ ld(klass_reg, Address(klass_reg, java_lang_Class::klass_offset_in_bytes()));
50 }
52 #ifdef ASSERT
53 static int check_nonzero(const char* xname, int x) {
54 assert(x != 0, err_msg("%s should be nonzero", xname));
55 return x;
56 }
57 #define NONZERO(x) check_nonzero(#x, x)
58 #else //ASSERT
59 #define NONZERO(x) (x)
60 #endif //ASSERT
62 #ifdef ASSERT
63 void MethodHandles::verify_klass(MacroAssembler* _masm,
64 Register obj, SystemDictionary::WKID klass_id,
65 const char* error_message) {
66 /*
67 Klass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
68 KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
69 Register temp = S0;
70 Label L_ok, L_bad;
71 BLOCK_COMMENT("verify_klass {");
72 __ verify_oop(obj);
73 __ beq(obj, R0, L_bad);
74 __ nop();
75 __ push(temp); //if (temp2 != noreg) __ push(temp2);
76 #define UNPUSH { __ pop(temp); }
77 __ load_klass(temp, obj);
78 __ li(AT, (long)&klass_addr);
79 __ ld(AT, AT, 0);
80 __ beq(temp, AT, L_ok);
81 __ nop();
82 intptr_t super_check_offset = klass->super_check_offset();
83 __ ld(temp, Address(temp, super_check_offset));
84 __ li(AT, (long)&klass_addr);
85 __ ld(AT, AT, 0);
86 __ beq(AT, temp, L_ok);
87 __ nop();
88 UNPUSH;
89 __ bind(L_bad);
90 __ STOP(error_message);
91 __ BIND(L_ok);
92 UNPUSH;
93 BLOCK_COMMENT("} verify_klass");
94 */
95 }
97 void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
98 Label L;
99 BLOCK_COMMENT("verify_ref_kind {");
100 __ lw(temp, Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes())));
101 __ sra(temp, temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT);
102 __ move(AT, java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK);
103 __ andr(temp, temp, AT);
104 __ move(AT, ref_kind);
105 __ beq(temp, AT, L);
106 __ nop();
107 { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
108 jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
109 if (ref_kind == JVM_REF_invokeVirtual ||
110 ref_kind == JVM_REF_invokeSpecial)
111 // could do this for all ref_kinds, but would explode assembly code size
112 trace_method_handle(_masm, buf);
113 __ STOP(buf);
114 }
115 BLOCK_COMMENT("} verify_ref_kind");
116 __ bind(L);
117 }
119 #endif //ASSERT
121 void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, Register method, Register temp,
122 bool for_compiler_entry) {
123 assert(method == Rmethod, "interpreter calling convention");
125 Label L_no_such_method;
126 __ beq(method, R0, L_no_such_method);
127 __ nop();
129 __ verify_method_ptr(method);
131 if (!for_compiler_entry && JvmtiExport::can_post_interpreter_events()) {
132 Label run_compiled_code;
133 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
134 // compiled code in threads for which the event is enabled. Check here for
135 // interp_only_mode if these events CAN be enabled.
136 #ifdef _LP64
137 Register rthread = TREG;
138 #else
139 Register rthread = temp;
140 __ get_thread(rthread);
141 #endif
142 // interp_only is an int, on little endian it is sufficient to test the byte only
143 // Is a cmpl faster?
144 __ lbu(AT, rthread, in_bytes(JavaThread::interp_only_mode_offset()));
145 __ beq(AT, R0, run_compiled_code);
146 __ nop();
147 __ ld(T9, method, in_bytes(Method::interpreter_entry_offset()));
148 __ jr(T9);
149 __ nop();
150 __ BIND(run_compiled_code);
151 }
153 const ByteSize entry_offset = for_compiler_entry ? Method::from_compiled_offset() :
154 Method::from_interpreted_offset();
155 __ ld(T9, method, in_bytes(entry_offset));
156 __ jr(T9);
157 __ nop();
159 __ bind(L_no_such_method);
160 address wrong_method = StubRoutines::throw_AbstractMethodError_entry();
161 __ jmp(wrong_method, relocInfo::runtime_call_type);
162 __ nop();
163 }
165 void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
166 Register recv, Register method_temp,
167 Register temp2,
168 bool for_compiler_entry) {
169 BLOCK_COMMENT("jump_to_lambda_form {");
170 // This is the initial entry point of a lazy method handle.
171 // After type checking, it picks up the invoker from the LambdaForm.
172 assert_different_registers(recv, method_temp, temp2);
173 assert(recv != noreg, "required register");
174 assert(method_temp == Rmethod, "required register for loading method");
176 //NOT_PRODUCT({ FlagSetting fs(TraceMethodHandles, true); trace_method_handle(_masm, "LZMH"); });
178 // Load the invoker, as MH -> MH.form -> LF.vmentry
179 __ verify_oop(recv);
180 __ load_heap_oop(method_temp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes())));
181 __ verify_oop(method_temp);
182 __ load_heap_oop(method_temp, Address(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes())));
183 __ verify_oop(method_temp);
184 // the following assumes that a Method* is normally compressed in the vmtarget field:
185 __ ld(method_temp, Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes())));
187 if (VerifyMethodHandles && !for_compiler_entry) {
188 // make sure recv is already on stack
189 __ ld(temp2, Address(method_temp, Method::const_offset()));
190 __ load_sized_value(temp2,
191 Address(temp2, ConstMethod::size_of_parameters_offset()),
192 sizeof(u2), false);
193 // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
194 Label L;
195 Address recv_addr = __ argument_address(temp2, -1);
196 __ ld(AT, recv_addr);
197 __ beq(recv, AT, L);
198 __ nop();
200 recv_addr = __ argument_address(temp2, -1);
201 __ ld(V0, recv_addr);
202 __ STOP("receiver not on stack");
203 __ BIND(L);
204 }
206 jump_from_method_handle(_masm, method_temp, temp2, for_compiler_entry);
207 BLOCK_COMMENT("} jump_to_lambda_form");
208 }
211 // Code generation
212 address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm,
213 vmIntrinsics::ID iid) {
214 const bool not_for_compiler_entry = false; // this is the interpreter entry
215 assert(is_signature_polymorphic(iid), "expected invoke iid");
216 if (iid == vmIntrinsics::_invokeGeneric ||
217 iid == vmIntrinsics::_compiledLambdaForm) {
218 // Perhaps surprisingly, the symbolic references visible to Java are not directly used.
219 // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod.
220 // They all allow an appendix argument.
221 __ stop("empty stubs make SG sick");
222 return NULL;
223 }
225 // rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
226 // rbx: Method*
227 // rdx: argument locator (parameter slot count, added to rsp)
228 // rcx: used as temp to hold mh or receiver
229 // rax, rdi: garbage temps, blown away
230 Register rdx_argp = T9; // argument list ptr, live on error paths
231 Register rcx_mh = S7; // MH receiver; dies quickly and is recycled
232 Register rbx_method = Rmethod; // eventual target of this invocation
234 // here's where control starts out:
235 __ align(CodeEntryAlignment);
236 address entry_point = __ pc();
238 if (VerifyMethodHandles) {
239 Label L;
240 BLOCK_COMMENT("verify_intrinsic_id {");
241 __ lbu(AT, rbx_method, Method::intrinsic_id_offset_in_bytes());
242 guarantee(Assembler::is_simm16(iid), "Oops, iid is not simm16! Change the instructions.");
243 __ addiu(AT, AT, -1 * (int) iid);
244 __ beq(AT, R0, L);
245 __ nop();
246 if (iid == vmIntrinsics::_linkToVirtual ||
247 iid == vmIntrinsics::_linkToSpecial) {
248 // could do this for all kinds, but would explode assembly code size
249 trace_method_handle(_masm, "bad Method*::intrinsic_id");
250 }
251 __ STOP("bad Method*::intrinsic_id");
252 __ bind(L);
253 BLOCK_COMMENT("} verify_intrinsic_id");
254 }
256 // First task: Find out how big the argument list is.
257 Address rdx_first_arg_addr;
258 int ref_kind = signature_polymorphic_intrinsic_ref_kind(iid);
259 assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic");
260 if (ref_kind == 0 || MethodHandles::ref_kind_has_receiver(ref_kind)) {
261 __ ld(rdx_argp, Address(rbx_method, Method::const_offset()));
262 __ load_sized_value(rdx_argp,
263 Address(rdx_argp, ConstMethod::size_of_parameters_offset()),
264 sizeof(u2), false);
265 // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
266 rdx_first_arg_addr = __ argument_address(rdx_argp, -1);
267 } else {
268 DEBUG_ONLY(rdx_argp = noreg);
269 }
271 if (!is_signature_polymorphic_static(iid)) {
272 __ ld(rcx_mh, rdx_first_arg_addr);
273 DEBUG_ONLY(rdx_argp = noreg);
274 }
276 // rdx_first_arg_addr is live!
278 trace_method_handle_interpreter_entry(_masm, iid);
280 if (iid == vmIntrinsics::_invokeBasic) {
281 generate_method_handle_dispatch(_masm, iid, rcx_mh, noreg, not_for_compiler_entry);
283 } else {
284 // Adjust argument list by popping the trailing MemberName argument.
285 Register rcx_recv = noreg;
286 if (MethodHandles::ref_kind_has_receiver(ref_kind)) {
287 // Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
288 __ ld(rcx_recv = T2, rdx_first_arg_addr);
289 }
290 DEBUG_ONLY(rdx_argp = noreg);
291 Register rbx_member = rbx_method; // MemberName ptr; incoming method ptr is dead now
292 __ pop(rbx_member); // extract last argument
293 generate_method_handle_dispatch(_masm, iid, rcx_recv, rbx_member, not_for_compiler_entry);
294 }
296 return entry_point;
297 }
299 void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
300 vmIntrinsics::ID iid,
301 Register receiver_reg,
302 Register member_reg,
303 bool for_compiler_entry) {
304 assert(is_signature_polymorphic(iid), "expected invoke iid");
305 Register rbx_method = Rmethod; // eventual target of this invocation
306 // temps used in this code are not used in *either* compiled or interpreted calling sequences
307 Register j_rarg0 = T0;
308 Register j_rarg1 = A0;
309 Register j_rarg2 = A1;
310 Register j_rarg3 = A2;
311 Register j_rarg4 = A3;
312 Register j_rarg5 = A4;
314 Register temp1 = T8;
315 Register temp2 = T9;
316 Register temp3 = V0;
317 if (for_compiler_entry) {
318 assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : j_rarg0), "only valid assignment");
319 assert_different_registers(temp1, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5);
320 assert_different_registers(temp2, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5);
321 assert_different_registers(temp3, j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5);
322 }
323 else {
324 assert_different_registers(temp1, temp2, temp3, saved_last_sp_register()); // don't trash lastSP
325 }
326 assert_different_registers(temp1, temp2, temp3, receiver_reg);
327 assert_different_registers(temp1, temp2, temp3, member_reg);
329 if (iid == vmIntrinsics::_invokeBasic) {
330 // indirect through MH.form.vmentry.vmtarget
331 jump_to_lambda_form(_masm, receiver_reg, rbx_method, temp1, for_compiler_entry);
333 } else {
334 // The method is a member invoker used by direct method handles.
335 if (VerifyMethodHandles) {
336 // make sure the trailing argument really is a MemberName (caller responsibility)
337 verify_klass(_masm, member_reg, SystemDictionary::WK_KLASS_ENUM_NAME(java_lang_invoke_MemberName),
338 "MemberName required for invokeVirtual etc.");
339 }
341 Address member_clazz( member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset_in_bytes()));
342 Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset_in_bytes()));
343 Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes()));
345 Register temp1_recv_klass = temp1;
346 if (iid != vmIntrinsics::_linkToStatic) {
347 __ verify_oop(receiver_reg);
348 if (iid == vmIntrinsics::_linkToSpecial) {
349 // Don't actually load the klass; just null-check the receiver.
350 __ null_check(receiver_reg);
351 } else {
352 // load receiver klass itself
353 __ null_check(receiver_reg, oopDesc::klass_offset_in_bytes());
354 __ load_klass(temp1_recv_klass, receiver_reg);
355 __ verify_klass_ptr(temp1_recv_klass);
356 }
357 BLOCK_COMMENT("check_receiver {");
358 // The receiver for the MemberName must be in receiver_reg.
359 // Check the receiver against the MemberName.clazz
360 if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) {
361 // Did not load it above...
362 __ load_klass(temp1_recv_klass, receiver_reg);
363 __ verify_klass_ptr(temp1_recv_klass);
364 }
365 if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) {
366 Label L_ok;
367 Register temp2_defc = temp2;
368 __ load_heap_oop(temp2_defc, member_clazz);
369 load_klass_from_Class(_masm, temp2_defc);
370 __ verify_klass_ptr(temp2_defc);
371 __ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, L_ok);
372 // If we get here, the type check failed!
373 __ STOP("receiver class disagrees with MemberName.clazz");
374 __ bind(L_ok);
375 }
376 BLOCK_COMMENT("} check_receiver");
377 }
378 if (iid == vmIntrinsics::_linkToSpecial ||
379 iid == vmIntrinsics::_linkToStatic) {
380 DEBUG_ONLY(temp1_recv_klass = noreg); // these guys didn't load the recv_klass
381 }
383 // Live registers at this point:
384 // member_reg - MemberName that was the trailing argument
385 // temp1_recv_klass - klass of stacked receiver, if needed
386 // rsi/r13 - interpreter linkage (if interpreted)
387 // rcx, rdx, rsi, rdi, r8, r8 - compiler arguments (if compiled)
389 Label L_incompatible_class_change_error;
390 switch (iid) {
391 case vmIntrinsics::_linkToSpecial:
392 if (VerifyMethodHandles) {
393 verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp3);
394 }
395 __ ld(rbx_method, member_vmtarget);
396 break;
398 case vmIntrinsics::_linkToStatic:
399 if (VerifyMethodHandles) {
400 verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp3);
401 }
402 __ ld(rbx_method, member_vmtarget);
403 break;
405 case vmIntrinsics::_linkToVirtual:
406 {
407 // same as TemplateTable::invokevirtual,
408 // minus the CP setup and profiling:
410 if (VerifyMethodHandles) {
411 verify_ref_kind(_masm, JVM_REF_invokeVirtual, member_reg, temp3);
412 }
414 // pick out the vtable index from the MemberName, and then we can discard it:
415 Register temp2_index = temp2;
416 __ ld(temp2_index, member_vmindex);
418 if (VerifyMethodHandles) {
419 Label L_index_ok;
420 __ slt(AT, R0, temp2_index);
421 __ bne(AT, R0, L_index_ok);
422 __ nop();
423 __ STOP("no virtual index");
424 __ BIND(L_index_ok);
425 }
427 // Note: The verifier invariants allow us to ignore MemberName.clazz and vmtarget
428 // at this point. And VerifyMethodHandles has already checked clazz, if needed.
430 // get target Method* & entry point
431 __ lookup_virtual_method(temp1_recv_klass, temp2_index, rbx_method);
432 break;
433 }
435 case vmIntrinsics::_linkToInterface:
436 {
437 // same as TemplateTable::invokeinterface
438 // (minus the CP setup and profiling, with different argument motion)
439 if (VerifyMethodHandles) {
440 verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp3);
441 }
443 Register temp3_intf = temp3;
444 __ load_heap_oop(temp3_intf, member_clazz);
445 load_klass_from_Class(_masm, temp3_intf);
446 __ verify_klass_ptr(temp3_intf);
448 Register rbx_index = rbx_method;
449 __ ld(rbx_index, member_vmindex);
450 if (VerifyMethodHandles) {
451 Label L;
452 __ slt(AT, rbx_index, R0);
453 __ beq(AT, R0, L);
454 __ nop();
455 __ STOP("invalid vtable index for MH.invokeInterface");
456 __ bind(L);
457 }
459 // given intf, index, and recv klass, dispatch to the implementation method
460 __ lookup_interface_method(temp1_recv_klass, temp3_intf,
461 // note: next two args must be the same:
462 rbx_index, rbx_method,
463 temp2,
464 L_incompatible_class_change_error);
465 break;
466 }
468 default:
469 fatal(err_msg_res("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
470 break;
471 }
473 // Live at this point:
474 // rbx_method
475 // rsi/r13 (if interpreted)
477 // After figuring out which concrete method to call, jump into it.
478 // Note that this works in the interpreter with no data motion.
479 // But the compiled version will require that rcx_recv be shifted out.
480 __ verify_method_ptr(rbx_method);
481 jump_from_method_handle(_masm, rbx_method, temp1, for_compiler_entry);
483 if (iid == vmIntrinsics::_linkToInterface) {
484 __ bind(L_incompatible_class_change_error);
485 address icce_entry= StubRoutines::throw_IncompatibleClassChangeError_entry();
486 __ jmp(icce_entry, relocInfo::runtime_call_type);
487 __ nop();
488 }
489 }
490 }
492 #ifndef PRODUCT
493 void trace_method_handle_stub(const char* adaptername,
494 oop mh,
495 intptr_t* saved_regs,
496 intptr_t* entry_sp) {
497 // called as a leaf from native code: do not block the JVM!
498 bool has_mh = (strstr(adaptername, "/static") == NULL &&
499 strstr(adaptername, "linkTo") == NULL); // static linkers don't have MH
500 const char* mh_reg_name = has_mh ? "rcx_mh" : "rcx";
501 tty->print_cr("MH %s %s="PTR_FORMAT" sp="PTR_FORMAT,
502 adaptername, mh_reg_name,
503 (void *)mh, entry_sp);
505 if (Verbose) {
506 tty->print_cr("Registers:");
507 const int saved_regs_count = RegisterImpl::number_of_registers;
508 for (int i = 0; i < saved_regs_count; i++) {
509 Register r = as_Register(i);
510 // The registers are stored in reverse order on the stack (by pusha).
511 tty->print("%3s=" PTR_FORMAT, r->name(), saved_regs[((saved_regs_count - 1) - i)]);
512 if ((i + 1) % 4 == 0) {
513 tty->cr();
514 } else {
515 tty->print(", ");
516 }
517 }
518 tty->cr();
520 {
521 // dumping last frame with frame::describe
523 JavaThread* p = JavaThread::active();
525 ResourceMark rm;
526 PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here
527 FrameValues values;
529 // Note: We want to allow trace_method_handle from any call site.
530 // While trace_method_handle creates a frame, it may be entered
531 // without a PC on the stack top (e.g. not just after a call).
532 // Walking that frame could lead to failures due to that invalid PC.
533 // => carefully detect that frame when doing the stack walking
535 // Current C frame
536 frame cur_frame = os::current_frame();
538 // Robust search of trace_calling_frame (independant of inlining).
539 // Assumes saved_regs comes from a pusha in the trace_calling_frame.
540 assert(cur_frame.sp() < saved_regs, "registers not saved on stack ?");
541 frame trace_calling_frame = os::get_sender_for_C_frame(&cur_frame);
542 while (trace_calling_frame.fp() < saved_regs) {
543 trace_calling_frame = os::get_sender_for_C_frame(&trace_calling_frame);
544 }
546 // safely create a frame and call frame::describe
547 intptr_t *dump_sp = trace_calling_frame.sender_sp();
548 intptr_t *dump_fp = trace_calling_frame.link();
550 bool walkable = has_mh; // whether the traced frame shoud be walkable
552 if (walkable) {
553 // The previous definition of walkable may have to be refined
554 // if new call sites cause the next frame constructor to start
555 // failing. Alternatively, frame constructors could be
556 // modified to support the current or future non walkable
557 // frames (but this is more intrusive and is not considered as
558 // part of this RFE, which will instead use a simpler output).
559 frame dump_frame = frame(dump_sp, dump_fp);
560 dump_frame.describe(values, 1);
561 } else {
562 // Stack may not be walkable (invalid PC above FP):
563 // Add descriptions without building a Java frame to avoid issues
564 values.describe(-1, dump_fp, "fp for #1 <not parsed, cannot trust pc>");
565 values.describe(-1, dump_sp, "sp for #1");
566 }
567 values.describe(-1, entry_sp, "raw top of stack");
569 tty->print_cr("Stack layout:");
570 values.print(p);
571 }
572 if (has_mh && mh->is_oop()) {
573 mh->print();
574 if (java_lang_invoke_MethodHandle::is_instance(mh)) {
575 if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
576 java_lang_invoke_MethodHandle::form(mh)->print();
577 }
578 }
579 }
580 }
582 // The stub wraps the arguments in a struct on the stack to avoid
583 // dealing with the different calling conventions for passing 6
584 // arguments.
585 struct MethodHandleStubArguments {
586 const char* adaptername;
587 oopDesc* mh;
588 intptr_t* saved_regs;
589 intptr_t* entry_sp;
590 };
591 void trace_method_handle_stub_wrapper(MethodHandleStubArguments* args) {
592 trace_method_handle_stub(args->adaptername,
593 args->mh,
594 args->saved_regs,
595 args->entry_sp);
596 }
598 void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) {
599 /*
600 if (!TraceMethodHandles) return;
601 BLOCK_COMMENT("trace_method_handle {");
602 __ enter();
603 __ andptr(rsp, -16); // align stack if needed for FPU state
604 __ pusha();
605 __ mov(rbx, rsp); // for retreiving saved_regs
606 // Note: saved_regs must be in the entered frame for the
607 // robust stack walking implemented in trace_method_handle_stub.
609 // save FP result, valid at some call sites (adapter_opt_return_float, ...)
610 __ increment(rsp, -2 * wordSize);
611 if (UseSSE >= 2) {
612 __ movdbl(Address(rsp, 0), xmm0);
613 } else if (UseSSE == 1) {
614 __ movflt(Address(rsp, 0), xmm0);
615 } else {
616 __ fst_d(Address(rsp, 0));
617 }
619 // Incoming state:
620 // rcx: method handle
621 //
622 // To avoid calling convention issues, build a record on the stack
623 // and pass the pointer to that instead.
624 __ push(rbp); // entry_sp (with extra align space)
625 __ push(rbx); // pusha saved_regs
626 __ push(rcx); // mh
627 __ push(rcx); // slot for adaptername
628 __ movptr(Address(rsp, 0), (intptr_t) adaptername);
629 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub_wrapper), rsp);
630 __ increment(rsp, sizeof(MethodHandleStubArguments));
632 if (UseSSE >= 2) {
633 __ movdbl(xmm0, Address(rsp, 0));
634 } else if (UseSSE == 1) {
635 __ movflt(xmm0, Address(rsp, 0));
636 } else {
637 __ fld_d(Address(rsp, 0));
638 }
639 __ increment(rsp, 2 * wordSize);
641 __ popa();
642 __ leave();
643 BLOCK_COMMENT("} trace_method_handle");
644 */
645 }
646 #endif //PRODUCT