src/cpu/sparc/vm/methodHandles_sparc.cpp

Mon, 27 Aug 2012 15:17:17 -0700

author
twisti
date
Mon, 27 Aug 2012 15:17:17 -0700
changeset 4020
a5dd6e3ef9f3
parent 3969
1d7922586cf6
child 4037
da91efe96a93
permissions
-rw-r--r--

6677625: Move platform specific flags from globals.hpp to globals_<arch>.hpp
Reviewed-by: kvn, dholmes, coleenp
Contributed-by: Tao Mao <tao.mao@oracle.com>

     1 /*
     2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
     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  */
    25 #include "precompiled.hpp"
    26 #include "interpreter/interpreter.hpp"
    27 #include "memory/allocation.inline.hpp"
    28 #include "prims/methodHandles.hpp"
    30 #define __ _masm->
    32 #ifdef PRODUCT
    33 #define BLOCK_COMMENT(str) /* nothing */
    34 #define STOP(error) stop(error)
    35 #else
    36 #define BLOCK_COMMENT(str) __ block_comment(str)
    37 #define STOP(error) block_comment(error); __ stop(error)
    38 #endif
    40 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
    42 // Workaround for C++ overloading nastiness on '0' for RegisterOrConstant.
    43 static RegisterOrConstant constant(int value) {
    44   return RegisterOrConstant(value);
    45 }
    47 void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp_reg, Register temp2_reg) {
    48   if (VerifyMethodHandles)
    49     verify_klass(_masm, klass_reg, SystemDictionaryHandles::Class_klass(), temp_reg, temp2_reg,
    50                  "MH argument is a Class");
    51   __ load_heap_oop(Address(klass_reg, java_lang_Class::klass_offset_in_bytes()), klass_reg);
    52 }
    54 #ifdef ASSERT
    55 static int check_nonzero(const char* xname, int x) {
    56   assert(x != 0, err_msg("%s should be nonzero", xname));
    57   return x;
    58 }
    59 #define NONZERO(x) check_nonzero(#x, x)
    60 #else //ASSERT
    61 #define NONZERO(x) (x)
    62 #endif //ASSERT
    64 #ifdef ASSERT
    65 void MethodHandles::verify_klass(MacroAssembler* _masm,
    66                                  Register obj_reg, KlassHandle klass,
    67                                  Register temp_reg, Register temp2_reg,
    68                                  const char* error_message) {
    69   oop* klass_addr = klass.raw_value();
    70   assert(klass_addr >= SystemDictionaryHandles::Object_klass().raw_value() &&
    71          klass_addr <= SystemDictionaryHandles::Long_klass().raw_value(),
    72          "must be one of the SystemDictionaryHandles");
    73   bool did_save = false;
    74   if (temp_reg == noreg || temp2_reg == noreg) {
    75     temp_reg = L1;
    76     temp2_reg = L2;
    77     __ save_frame_and_mov(0, obj_reg, L0);
    78     obj_reg = L0;
    79     did_save = true;
    80   }
    81   Label L_ok, L_bad;
    82   BLOCK_COMMENT("verify_klass {");
    83   __ verify_oop(obj_reg);
    84   __ br_null_short(obj_reg, Assembler::pn, L_bad);
    85   __ load_klass(obj_reg, temp_reg);
    86   __ set(ExternalAddress(klass_addr), temp2_reg);
    87   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
    88   __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
    89   intptr_t super_check_offset = klass->super_check_offset();
    90   __ ld_ptr(Address(temp_reg, super_check_offset), temp_reg);
    91   __ set(ExternalAddress(klass_addr), temp2_reg);
    92   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
    93   __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
    94   __ BIND(L_bad);
    95   if (did_save)  __ restore();
    96   __ STOP(error_message);
    97   __ BIND(L_ok);
    98   if (did_save)  __ restore();
    99   BLOCK_COMMENT("} verify_klass");
   100 }
   102 void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
   103   Label L;
   104   BLOCK_COMMENT("verify_ref_kind {");
   105   __ lduw(Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes())), temp);
   106   __ srl( temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT, temp);
   107   __ and3(temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK,  temp);
   108   __ cmp_and_br_short(temp, ref_kind, Assembler::equal, Assembler::pt, L);
   109   { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
   110     jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
   111     if (ref_kind == JVM_REF_invokeVirtual ||
   112         ref_kind == JVM_REF_invokeSpecial)
   113       // could do this for all ref_kinds, but would explode assembly code size
   114       trace_method_handle(_masm, buf);
   115     __ STOP(buf);
   116   }
   117   BLOCK_COMMENT("} verify_ref_kind");
   118   __ bind(L);
   119 }
   121 #endif // ASSERT
   123 void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, Register method, Register target, Register temp,
   124                                             bool for_compiler_entry) {
   125   assert(method == G5_method, "interpreter calling convention");
   126   __ verify_oop(method);
   128   if (!for_compiler_entry && JvmtiExport::can_post_interpreter_events()) {
   129     Label run_compiled_code;
   130     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   131     // compiled code in threads for which the event is enabled.  Check here for
   132     // interp_only_mode if these events CAN be enabled.
   133     __ verify_thread();
   134     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());
   135     __ ld(interp_only, temp);
   136     __ cmp_and_br_short(temp, 0, Assembler::zero, Assembler::pt, run_compiled_code);
   137     __ ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), target);
   138     __ jmp(target, 0);
   139     __ delayed()->nop();
   140     __ BIND(run_compiled_code);
   141     // Note: we could fill some delay slots here, but
   142     // it doesn't matter, since this is interpreter code.
   143   }
   145   const ByteSize entry_offset = for_compiler_entry ? methodOopDesc::from_compiled_offset() :
   146                                                      methodOopDesc::from_interpreted_offset();
   147   __ ld_ptr(G5_method, in_bytes(entry_offset), target);
   148   __ jmp(target, 0);
   149   __ delayed()->nop();
   150 }
   152 void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
   153                                         Register recv, Register method_temp,
   154                                         Register temp2, Register temp3,
   155                                         bool for_compiler_entry) {
   156   BLOCK_COMMENT("jump_to_lambda_form {");
   157   // This is the initial entry point of a lazy method handle.
   158   // After type checking, it picks up the invoker from the LambdaForm.
   159   assert_different_registers(recv, method_temp, temp2, temp3);
   160   assert(method_temp == G5_method, "required register for loading method");
   162   //NOT_PRODUCT({ FlagSetting fs(TraceMethodHandles, true); trace_method_handle(_masm, "LZMH"); });
   164   // Load the invoker, as MH -> MH.form -> LF.vmentry
   165   __ verify_oop(recv);
   166   __ load_heap_oop(Address(recv,        NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes())),       method_temp);
   167   __ verify_oop(method_temp);
   168   __ load_heap_oop(Address(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes())), method_temp);
   169   __ verify_oop(method_temp);
   170   // the following assumes that a methodOop is normally compressed in the vmtarget field:
   171   __ load_heap_oop(Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes())),     method_temp);
   172   __ verify_oop(method_temp);
   174   if (VerifyMethodHandles && !for_compiler_entry) {
   175     // make sure recv is already on stack
   176     __ load_sized_value(Address(method_temp, methodOopDesc::size_of_parameters_offset()),
   177                         temp2,
   178                         sizeof(u2), /*is_signed*/ false);
   179     // assert(sizeof(u2) == sizeof(methodOopDesc::_size_of_parameters), "");
   180     Label L;
   181     __ ld_ptr(__ argument_address(temp2, temp2, -1), temp2);
   182     __ cmp_and_br_short(temp2, recv, Assembler::equal, Assembler::pt, L);
   183     __ STOP("receiver not on stack");
   184     __ BIND(L);
   185   }
   187   jump_from_method_handle(_masm, method_temp, temp2, temp3, for_compiler_entry);
   188   BLOCK_COMMENT("} jump_to_lambda_form");
   189 }
   192 // Code generation
   193 address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm,
   194                                                                 vmIntrinsics::ID iid) {
   195   const bool not_for_compiler_entry = false;  // this is the interpreter entry
   196   assert(is_signature_polymorphic(iid), "expected invoke iid");
   197   if (iid == vmIntrinsics::_invokeGeneric ||
   198       iid == vmIntrinsics::_compiledLambdaForm) {
   199     // Perhaps surprisingly, the symbolic references visible to Java are not directly used.
   200     // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod.
   201     // They all allow an appendix argument.
   202     __ should_not_reach_here();           // empty stubs make SG sick
   203     return NULL;
   204   }
   206   // I5_savedSP/O5_savedSP: sender SP (must preserve; see prepare_to_jump_from_interpreted)
   207   // G5_method:  methodOop
   208   // G4 (Gargs): incoming argument list (must preserve)
   209   // O0: used as temp to hold mh or receiver
   210   // O1, O4: garbage temps, blown away
   211   Register O1_scratch    = O1;
   212   Register O4_param_size = O4;   // size of parameters
   214   address code_start = __ pc();
   216   // here's where control starts out:
   217   __ align(CodeEntryAlignment);
   218   address entry_point = __ pc();
   220   if (VerifyMethodHandles) {
   221     Label L;
   222     BLOCK_COMMENT("verify_intrinsic_id {");
   223     __ ldub(Address(G5_method, methodOopDesc::intrinsic_id_offset_in_bytes()), O1_scratch);
   224     __ cmp_and_br_short(O1_scratch, (int) iid, Assembler::equal, Assembler::pt, 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 methodOop::intrinsic_id");
   229     }
   230     __ STOP("bad methodOop::intrinsic_id");
   231     __ bind(L);
   232     BLOCK_COMMENT("} verify_intrinsic_id");
   233   }
   235   // First task:  Find out how big the argument list is.
   236   Address O4_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     __ load_sized_value(Address(G5_method, methodOopDesc::size_of_parameters_offset()),
   241                         O4_param_size,
   242                         sizeof(u2), /*is_signed*/ false);
   243     // assert(sizeof(u2) == sizeof(methodOopDesc::_size_of_parameters), "");
   244     O4_first_arg_addr = __ argument_address(O4_param_size, O4_param_size, -1);
   245   } else {
   246     DEBUG_ONLY(O4_param_size = noreg);
   247   }
   249   Register O0_mh = noreg;
   250   if (!is_signature_polymorphic_static(iid)) {
   251     __ ld_ptr(O4_first_arg_addr, O0_mh = O0);
   252     DEBUG_ONLY(O4_param_size = noreg);
   253   }
   255   // O4_first_arg_addr is live!
   257   if (TraceMethodHandles) {
   258     const char* name = vmIntrinsics::name_at(iid);
   259     if (*name == '_')  name += 1;
   260     const size_t len = strlen(name) + 50;
   261     char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
   262     const char* suffix = "";
   263     if (vmIntrinsics::method_for(iid) == NULL ||
   264         !vmIntrinsics::method_for(iid)->access_flags().is_public()) {
   265       if (is_signature_polymorphic_static(iid))
   266         suffix = "/static";
   267       else
   268         suffix = "/private";
   269     }
   270     jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
   271     if (O0_mh != noreg)
   272       __ mov(O0_mh, G3_method_handle);  // make stub happy
   273     trace_method_handle(_masm, qname);
   274   }
   276   if (iid == vmIntrinsics::_invokeBasic) {
   277     generate_method_handle_dispatch(_masm, iid, O0_mh, noreg, not_for_compiler_entry);
   279   } else {
   280     // Adjust argument list by popping the trailing MemberName argument.
   281     Register O0_recv = noreg;
   282     if (MethodHandles::ref_kind_has_receiver(ref_kind)) {
   283       // Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
   284       __ ld_ptr(O4_first_arg_addr, O0_recv = O0);
   285       DEBUG_ONLY(O4_param_size = noreg);
   286     }
   287     Register G5_member = G5_method;  // MemberName ptr; incoming method ptr is dead now
   288     __ ld_ptr(__ argument_address(constant(0)), G5_member);
   289     __ add(Gargs, Interpreter::stackElementSize, Gargs);
   290     generate_method_handle_dispatch(_masm, iid, O0_recv, G5_member, not_for_compiler_entry);
   291   }
   293   if (PrintMethodHandleStubs) {
   294     address code_end = __ pc();
   295     tty->print_cr("--------");
   296     tty->print_cr("method handle interpreter entry for %s", vmIntrinsics::name_at(iid));
   297     Disassembler::decode(code_start, code_end);
   298     tty->cr();
   299   }
   301   return entry_point;
   302 }
   304 void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
   305                                                     vmIntrinsics::ID iid,
   306                                                     Register receiver_reg,
   307                                                     Register member_reg,
   308                                                     bool for_compiler_entry) {
   309   assert(is_signature_polymorphic(iid), "expected invoke iid");
   310   // temps used in this code are not used in *either* compiled or interpreted calling sequences
   311   Register temp1 = (for_compiler_entry ? G1_scratch : O1);
   312   Register temp2 = (for_compiler_entry ? G4_scratch : O4);
   313   Register temp3 = G3_scratch;
   314   Register temp4 = (for_compiler_entry ? noreg      : O2);
   315   if (for_compiler_entry) {
   316     assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : O0), "only valid assignment");
   317     assert_different_registers(temp1,      O0, O1, O2, O3, O4, O5);
   318     assert_different_registers(temp2,      O0, O1, O2, O3, O4, O5);
   319     assert_different_registers(temp3,      O0, O1, O2, O3, O4, O5);
   320     assert_different_registers(temp4,      O0, O1, O2, O3, O4, O5);
   321   }
   322   if (receiver_reg != noreg)  assert_different_registers(temp1, temp2, temp3, temp4, receiver_reg);
   323   if (member_reg   != noreg)  assert_different_registers(temp1, temp2, temp3, temp4, member_reg);
   324   if (!for_compiler_entry)    assert_different_registers(temp1, temp2, temp3, temp4, O5_savedSP);  // don't trash lastSP
   326   if (iid == vmIntrinsics::_invokeBasic) {
   327     // indirect through MH.form.vmentry.vmtarget
   328     jump_to_lambda_form(_masm, receiver_reg, G5_method, temp2, temp3, for_compiler_entry);
   330   } else {
   331     // The method is a member invoker used by direct method handles.
   332     if (VerifyMethodHandles) {
   333       // make sure the trailing argument really is a MemberName (caller responsibility)
   334       verify_klass(_masm, member_reg, SystemDictionaryHandles::MemberName_klass(),
   335                    temp1, temp2,
   336                    "MemberName required for invokeVirtual etc.");
   337     }
   339     Address member_clazz(    member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset_in_bytes()));
   340     Address member_vmindex(  member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset_in_bytes()));
   341     Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes()));
   343     Register temp1_recv_klass = temp1;
   344     if (iid != vmIntrinsics::_linkToStatic) {
   345       __ verify_oop(receiver_reg);
   346       if (iid == vmIntrinsics::_linkToSpecial) {
   347         // Don't actually load the klass; just null-check the receiver.
   348         __ null_check(receiver_reg);
   349       } else {
   350         // load receiver klass itself
   351         __ null_check(receiver_reg, oopDesc::klass_offset_in_bytes());
   352         __ load_klass(receiver_reg, temp1_recv_klass);
   353         __ verify_oop(temp1_recv_klass);
   354       }
   355       BLOCK_COMMENT("check_receiver {");
   356       // The receiver for the MemberName must be in receiver_reg.
   357       // Check the receiver against the MemberName.clazz
   358       if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) {
   359         // Did not load it above...
   360         __ load_klass(receiver_reg, temp1_recv_klass);
   361         __ verify_oop(temp1_recv_klass);
   362       }
   363       if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) {
   364         Label L_ok;
   365         Register temp2_defc = temp2;
   366         __ load_heap_oop(member_clazz, temp2_defc);
   367         load_klass_from_Class(_masm, temp2_defc, temp3, temp4);
   368         __ verify_oop(temp2_defc);
   369         __ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, temp4, L_ok);
   370         // If we get here, the type check failed!
   371         __ STOP("receiver class disagrees with MemberName.clazz");
   372         __ bind(L_ok);
   373       }
   374       BLOCK_COMMENT("} check_receiver");
   375     }
   376     if (iid == vmIntrinsics::_linkToSpecial ||
   377         iid == vmIntrinsics::_linkToStatic) {
   378       DEBUG_ONLY(temp1_recv_klass = noreg);  // these guys didn't load the recv_klass
   379     }
   381     // Live registers at this point:
   382     //  member_reg - MemberName that was the trailing argument
   383     //  temp1_recv_klass - klass of stacked receiver, if needed
   384     //  O5_savedSP - interpreter linkage (if interpreted)
   385     //  O0..O7,G1,G4 - compiler arguments (if compiled)
   387     bool method_is_live = false;
   388     switch (iid) {
   389     case vmIntrinsics::_linkToSpecial:
   390       if (VerifyMethodHandles) {
   391         verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp3);
   392       }
   393       __ load_heap_oop(member_vmtarget, G5_method);
   394       method_is_live = true;
   395       break;
   397     case vmIntrinsics::_linkToStatic:
   398       if (VerifyMethodHandles) {
   399         verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp3);
   400       }
   401       __ load_heap_oop(member_vmtarget, G5_method);
   402       method_is_live = true;
   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_ptr(member_vmindex, temp2_index);
   418       if (VerifyMethodHandles) {
   419         Label L_index_ok;
   420         __ cmp_and_br_short(temp2_index, (int) 0, Assembler::greaterEqual, Assembler::pn, L_index_ok);
   421         __ STOP("no virtual index");
   422         __ BIND(L_index_ok);
   423       }
   425       // Note:  The verifier invariants allow us to ignore MemberName.clazz and vmtarget
   426       // at this point.  And VerifyMethodHandles has already checked clazz, if needed.
   428       // get target methodOop & entry point
   429       __ lookup_virtual_method(temp1_recv_klass, temp2_index, G5_method);
   430       method_is_live = true;
   431       break;
   432     }
   434     case vmIntrinsics::_linkToInterface:
   435     {
   436       // same as TemplateTable::invokeinterface
   437       // (minus the CP setup and profiling, with different argument motion)
   438       if (VerifyMethodHandles) {
   439         verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp3);
   440       }
   442       Register temp3_intf = temp3;
   443       __ load_heap_oop(member_clazz, temp3_intf);
   444       load_klass_from_Class(_masm, temp3_intf, temp2, temp4);
   445       __ verify_oop(temp3_intf);
   447       Register G5_index = G5_method;
   448       __ ld_ptr(member_vmindex, G5_index);
   449       if (VerifyMethodHandles) {
   450         Label L;
   451         __ cmp_and_br_short(G5_index, 0, Assembler::greaterEqual, Assembler::pt, L);
   452         __ STOP("invalid vtable index for MH.invokeInterface");
   453         __ bind(L);
   454       }
   456       // given intf, index, and recv klass, dispatch to the implementation method
   457       Label L_no_such_interface;
   458       Register no_sethi_temp = noreg;
   459       __ lookup_interface_method(temp1_recv_klass, temp3_intf,
   460                                  // note: next two args must be the same:
   461                                  G5_index, G5_method,
   462                                  temp2, no_sethi_temp,
   463                                  L_no_such_interface);
   465       __ verify_oop(G5_method);
   466       jump_from_method_handle(_masm, G5_method, temp2, temp3, for_compiler_entry);
   468       __ bind(L_no_such_interface);
   469       AddressLiteral icce(StubRoutines::throw_IncompatibleClassChangeError_entry());
   470       __ jump_to(icce, temp3);
   471       __ delayed()->nop();
   472       break;
   473     }
   475     default:
   476       fatal(err_msg("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
   477       break;
   478     }
   480     if (method_is_live) {
   481       // live at this point:  G5_method, O5_savedSP (if interpreted)
   483       // After figuring out which concrete method to call, jump into it.
   484       // Note that this works in the interpreter with no data motion.
   485       // But the compiled version will require that rcx_recv be shifted out.
   486       __ verify_oop(G5_method);
   487       jump_from_method_handle(_masm, G5_method, temp1, temp3, for_compiler_entry);
   488     }
   489   }
   490 }
   492 #ifndef PRODUCT
   493 void trace_method_handle_stub(const char* adaptername,
   494                               oopDesc* mh,
   495                               intptr_t* saved_sp,
   496                               intptr_t* args,
   497                               intptr_t* tracing_fp) {
   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 ? "G3_mh" : "G3";
   501   tty->print_cr("MH %s %s="INTPTR_FORMAT " saved_sp=" INTPTR_FORMAT " args=" INTPTR_FORMAT,
   502                 adaptername, mh_reg_name,
   503                 (intptr_t) mh, saved_sp, args);
   505   if (Verbose) {
   506     // dumping last frame with frame::describe
   508     JavaThread* p = JavaThread::active();
   510     ResourceMark rm;
   511     PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here
   512     FrameValues values;
   514     // Note: We want to allow trace_method_handle from any call site.
   515     // While trace_method_handle creates a frame, it may be entered
   516     // without a valid return PC in O7 (e.g. not just after a call).
   517     // Walking that frame could lead to failures due to that invalid PC.
   518     // => carefully detect that frame when doing the stack walking
   520     // walk up to the right frame using the "tracing_fp" argument
   521     intptr_t* cur_sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
   522     frame cur_frame(cur_sp, frame::unpatchable, NULL);
   524     while (cur_frame.fp() != (intptr_t *)(STACK_BIAS+(uintptr_t)tracing_fp)) {
   525       cur_frame = os::get_sender_for_C_frame(&cur_frame);
   526     }
   528     // safely create a frame and call frame::describe
   529     intptr_t *dump_sp = cur_frame.sender_sp();
   530     intptr_t *dump_fp = cur_frame.link();
   532     bool walkable = has_mh; // whether the traced frame shoud be walkable
   534     // the sender for cur_frame is the caller of trace_method_handle
   535     if (walkable) {
   536       // The previous definition of walkable may have to be refined
   537       // if new call sites cause the next frame constructor to start
   538       // failing. Alternatively, frame constructors could be
   539       // modified to support the current or future non walkable
   540       // frames (but this is more intrusive and is not considered as
   541       // part of this RFE, which will instead use a simpler output).
   542       frame dump_frame = frame(dump_sp,
   543                                cur_frame.sp(), // younger_sp
   544                                false); // no adaptation
   545       dump_frame.describe(values, 1);
   546     } else {
   547       // Robust dump for frames which cannot be constructed from sp/younger_sp
   548       // Add descriptions without building a Java frame to avoid issues
   549       values.describe(-1, dump_fp, "fp for #1 <not parsed, cannot trust pc>");
   550       values.describe(-1, dump_sp, "sp");
   551     }
   553     bool has_args = has_mh; // whether Gargs is meaningful
   555     // mark args, if seems valid (may not be valid for some adapters)
   556     if (has_args) {
   557       if ((args >= dump_sp) && (args < dump_fp)) {
   558         values.describe(-1, args, "*G4_args");
   559       }
   560     }
   562     // mark saved_sp, if seems valid (may not be valid for some adapters)
   563     intptr_t *unbiased_sp = (intptr_t *)(STACK_BIAS+(uintptr_t)saved_sp);
   564     const int ARG_LIMIT = 255, SLOP = 45, UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP);
   565     if ((unbiased_sp >= dump_sp - UNREASONABLE_STACK_MOVE) && (unbiased_sp < dump_fp)) {
   566       values.describe(-1, unbiased_sp, "*saved_sp+STACK_BIAS");
   567     }
   569     // Note: the unextended_sp may not be correct
   570     tty->print_cr("  stack layout:");
   571     values.print(p);
   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 void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) {
   583   if (!TraceMethodHandles)  return;
   584   BLOCK_COMMENT("trace_method_handle {");
   585   // save: Gargs, O5_savedSP
   586   __ save_frame(16); // need space for saving required FPU state
   588   __ set((intptr_t) adaptername, O0);
   589   __ mov(G3_method_handle, O1);
   590   __ mov(I5_savedSP, O2);
   591   __ mov(Gargs, O3);
   592   __ mov(I6, O4); // frame identifier for safe stack walking
   594   // Save scratched registers that might be needed. Robustness is more
   595   // important than optimizing the saves for this debug only code.
   597   // save FP result, valid at some call sites (adapter_opt_return_float, ...)
   598   Address d_save(FP, -sizeof(jdouble) + STACK_BIAS);
   599   __ stf(FloatRegisterImpl::D, Ftos_d, d_save);
   600   // Safely save all globals but G2 (handled by call_VM_leaf) and G7
   601   // (OS reserved).
   602   __ mov(G3_method_handle, L3);
   603   __ mov(Gargs, L4);
   604   __ mov(G5_method_type, L5);
   605   __ mov(G6, L6);
   606   __ mov(G1, L1);
   608   __ call_VM_leaf(L2 /* for G2 */, CAST_FROM_FN_PTR(address, trace_method_handle_stub));
   610   __ mov(L3, G3_method_handle);
   611   __ mov(L4, Gargs);
   612   __ mov(L5, G5_method_type);
   613   __ mov(L6, G6);
   614   __ mov(L1, G1);
   615   __ ldf(FloatRegisterImpl::D, d_save, Ftos_d);
   617   __ restore();
   618   BLOCK_COMMENT("} trace_method_handle");
   619 }
   620 #endif // PRODUCT

mercurial