src/cpu/sparc/vm/methodHandles_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7063628_1 Sdiff src/cpu/sparc/vm

src/cpu/sparc/vm/methodHandles_sparc.cpp

Print this page




 270 // Emit code to verify that FP is pointing at a valid ricochet frame.
 271 #ifdef ASSERT
 272 enum {
 273   ARG_LIMIT = 255, SLOP = 45,
 274   // use this parameter for checking for garbage stack movements:
 275   UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP)
 276   // the slop defends against false alarms due to fencepost errors
 277 };
 278 
 279 void MethodHandles::RicochetFrame::verify_clean(MacroAssembler* _masm) {
 280   // The stack should look like this:
 281   //    ... keep1 | dest=42 | keep2 | magic | handler | magic | recursive args | [RF]
 282   // Check various invariants.
 283 
 284   Register O7_temp = O7, O5_temp = O5;
 285 
 286   Label L_ok_1, L_ok_2, L_ok_3, L_ok_4;
 287   BLOCK_COMMENT("verify_clean {");
 288   // Magic numbers must check out:
 289   __ set((int32_t) MAGIC_NUMBER_1, O7_temp);
 290   __ cmp_and_br(O7_temp, L0_magic_number_1, Assembler::equal, false, Assembler::pt, L_ok_1);
 291   __ stop("damaged ricochet frame: MAGIC_NUMBER_1 not found");
 292 
 293   __ BIND(L_ok_1);
 294 
 295   // Arguments pointer must look reasonable:
 296 #ifdef _LP64
 297   Register FP_temp = O5_temp;
 298   __ add(FP, STACK_BIAS, FP_temp);
 299 #else
 300   Register FP_temp = FP;
 301 #endif
 302   __ cmp_and_brx(L4_saved_args_base, FP_temp, Assembler::greaterEqualUnsigned, false, Assembler::pt, L_ok_2);
 303   __ stop("damaged ricochet frame: L4 < FP");
 304 
 305   __ BIND(L_ok_2);
 306   // Disable until we decide on it's fate
 307   // __ sub(L4_saved_args_base, UNREASONABLE_STACK_MOVE * Interpreter::stackElementSize, O7_temp);
 308   // __ cmp(O7_temp, FP_temp);
 309   // __ br(Assembler::lessEqualUnsigned, false, Assembler::pt, L_ok_3);
 310   // __ delayed()->nop();
 311   // __ stop("damaged ricochet frame: (L4 - UNREASONABLE_STACK_MOVE) > FP");
 312 
 313   __ BIND(L_ok_3);
 314   extract_conversion_dest_type(_masm, L5_conversion, O7_temp);
 315   __ cmp_and_br(O7_temp, T_VOID, Assembler::equal, false, Assembler::pt, L_ok_4);
 316   extract_conversion_vminfo(_masm, L5_conversion, O5_temp);
 317   __ ld_ptr(L4_saved_args_base, __ argument_offset(O5_temp, O5_temp), O7_temp);
 318   assert(__ is_simm13(RETURN_VALUE_PLACEHOLDER), "must be simm13");
 319   __ cmp_and_brx(O7_temp, (int32_t) RETURN_VALUE_PLACEHOLDER, Assembler::equal, false, Assembler::pt, L_ok_4);
 320   __ stop("damaged ricochet frame: RETURN_VALUE_PLACEHOLDER not found");
 321   __ BIND(L_ok_4);
 322   BLOCK_COMMENT("} verify_clean");
 323 }
 324 #endif //ASSERT
 325 
 326 void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp_reg, Register temp2_reg) {
 327   if (VerifyMethodHandles)
 328     verify_klass(_masm, klass_reg, SystemDictionaryHandles::Class_klass(), temp_reg, temp2_reg,
 329                  "AMH argument is a Class");
 330   __ load_heap_oop(Address(klass_reg, java_lang_Class::klass_offset_in_bytes()), klass_reg);
 331 }
 332 
 333 void MethodHandles::load_conversion_vminfo(MacroAssembler* _masm, Address conversion_field_addr, Register reg) {
 334   assert(CONV_VMINFO_SHIFT == 0, "preshifted");
 335   assert(CONV_VMINFO_MASK == right_n_bits(BitsPerByte), "else change type of following load");
 336   __ ldub(conversion_field_addr.plus_disp(BytesPerInt - 1), reg);
 337 }
 338 
 339 void MethodHandles::extract_conversion_vminfo(MacroAssembler* _masm, Register conversion_field_reg, Register reg) {
 340   assert(CONV_VMINFO_SHIFT == 0, "preshifted");
 341   __ and3(conversion_field_reg, CONV_VMINFO_MASK, reg);
 342 }
 343 
 344 void MethodHandles::extract_conversion_dest_type(MacroAssembler* _masm, Register conversion_field_reg, Register reg) {
 345   __ srl(conversion_field_reg, CONV_DEST_TYPE_SHIFT, reg);
 346   __ and3(reg, 0x0F, reg);
 347 }
 348 
 349 void MethodHandles::load_stack_move(MacroAssembler* _masm,
 350                                     Address G3_amh_conversion,
 351                                     Register stack_move_reg) {
 352   BLOCK_COMMENT("load_stack_move {");
 353   __ ldsw(G3_amh_conversion, stack_move_reg);
 354   __ sra(stack_move_reg, CONV_STACK_MOVE_SHIFT, stack_move_reg);
 355   if (VerifyMethodHandles) {
 356     Label L_ok, L_bad;
 357     int32_t stack_move_limit = 0x0800;  // extra-large
 358     __ cmp_and_br(stack_move_reg, stack_move_limit, Assembler::greaterEqual, false, Assembler::pn, L_bad);
 359     __ cmp(stack_move_reg, -stack_move_limit);
 360     __ br(Assembler::greater, false, Assembler::pt, L_ok);
 361     __ delayed()->nop();
 362     __ BIND(L_bad);
 363     __ stop("load_stack_move of garbage value");
 364     __ BIND(L_ok);
 365   }
 366   BLOCK_COMMENT("} load_stack_move");
 367 }
 368 
 369 #ifdef ASSERT
 370 void MethodHandles::RicochetFrame::verify() const {
 371   assert(magic_number_1() == MAGIC_NUMBER_1, "");
 372   if (!Universe::heap()->is_gc_active()) {
 373     if (saved_args_layout() != NULL) {
 374       assert(saved_args_layout()->is_method(), "must be valid oop");
 375     }
 376     if (saved_target() != NULL) {
 377       assert(java_lang_invoke_MethodHandle::is_instance(saved_target()), "checking frame value");
 378     }
 379   }
 380   int conv_op = adapter_conversion_op(conversion());
 381   assert(conv_op == java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS ||
 382          conv_op == java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS ||
 383          conv_op == java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF,
 384          "must be a sane conversion");
 385   if (has_return_value_slot()) {
 386     assert(*return_value_slot_addr() == RETURN_VALUE_PLACEHOLDER, "");
 387   }
 388 }
 389 
 390 void MethodHandles::verify_argslot(MacroAssembler* _masm, Register argslot_reg, Register temp_reg, const char* error_message) {
 391   // Verify that argslot lies within (Gargs, FP].
 392   Label L_ok, L_bad;
 393   BLOCK_COMMENT("verify_argslot {");
 394   __ cmp_and_brx(Gargs, argslot_reg, Assembler::greaterUnsigned, false, Assembler::pn, L_bad);
 395   __ add(FP, STACK_BIAS, temp_reg);  // STACK_BIAS is zero on !_LP64
 396   __ cmp_and_brx(argslot_reg, temp_reg, Assembler::lessEqualUnsigned, false, Assembler::pt, L_ok);
 397   __ BIND(L_bad);
 398   __ stop(error_message);
 399   __ BIND(L_ok);
 400   BLOCK_COMMENT("} verify_argslot");
 401 }
 402 
 403 void MethodHandles::verify_argslots(MacroAssembler* _masm,
 404                                     RegisterOrConstant arg_slots,
 405                                     Register arg_slot_base_reg,
 406                                     Register temp_reg,
 407                                     Register temp2_reg,
 408                                     bool negate_argslots,
 409                                     const char* error_message) {
 410   // Verify that [argslot..argslot+size) lies within (Gargs, FP).
 411   Label L_ok, L_bad;
 412   BLOCK_COMMENT("verify_argslots {");
 413   if (negate_argslots) {
 414     if (arg_slots.is_constant()) {
 415       arg_slots = -1 * arg_slots.as_constant();
 416     } else {
 417       __ neg(arg_slots.as_register(), temp_reg);
 418       arg_slots = temp_reg;
 419     }
 420   }
 421   __ add(arg_slot_base_reg, __ argument_offset(arg_slots, temp_reg), temp_reg);
 422   __ add(FP, STACK_BIAS, temp2_reg);  // STACK_BIAS is zero on !_LP64
 423   __ cmp_and_brx(temp_reg, temp2_reg, Assembler::greaterUnsigned, false, Assembler::pn, L_bad);
 424   // Gargs points to the first word so adjust by BytesPerWord
 425   __ add(arg_slot_base_reg, BytesPerWord, temp_reg);
 426   __ cmp_and_brx(Gargs, temp_reg, Assembler::lessEqualUnsigned, false, Assembler::pt, L_ok);
 427   __ BIND(L_bad);
 428   __ stop(error_message);
 429   __ BIND(L_ok);
 430   BLOCK_COMMENT("} verify_argslots");
 431 }
 432 
 433 // Make sure that arg_slots has the same sign as the given direction.
 434 // If (and only if) arg_slots is a assembly-time constant, also allow it to be zero.
 435 void MethodHandles::verify_stack_move(MacroAssembler* _masm,
 436                                       RegisterOrConstant arg_slots, int direction) {
 437   enum { UNREASONABLE_STACK_MOVE = 256 * 4 };  // limit of 255 arguments
 438   bool allow_zero = arg_slots.is_constant();
 439   if (direction == 0) { direction = +1; allow_zero = true; }
 440   assert(stack_move_unit() == -1, "else add extra checks here");
 441   if (arg_slots.is_register()) {
 442     Label L_ok, L_bad;
 443     BLOCK_COMMENT("verify_stack_move {");
 444     // __ btst(-stack_move_unit() - 1, arg_slots.as_register());  // no need
 445     // __ br(Assembler::notZero, false, Assembler::pn, L_bad);
 446     // __ delayed()->nop();


 467     BLOCK_COMMENT("} verify_stack_move");
 468   } else {
 469     intptr_t size = arg_slots.as_constant();
 470     if (direction < 0)  size = -size;
 471     assert(size >= 0, "correct direction of constant move");
 472     assert(size < UNREASONABLE_STACK_MOVE, "reasonable size of constant move");
 473   }
 474 }
 475 
 476 void MethodHandles::verify_klass(MacroAssembler* _masm,
 477                                  Register obj_reg, KlassHandle klass,
 478                                  Register temp_reg, Register temp2_reg,
 479                                  const char* error_message) {
 480   oop* klass_addr = klass.raw_value();
 481   assert(klass_addr >= SystemDictionaryHandles::Object_klass().raw_value() &&
 482          klass_addr <= SystemDictionaryHandles::Long_klass().raw_value(),
 483          "must be one of the SystemDictionaryHandles");
 484   Label L_ok, L_bad;
 485   BLOCK_COMMENT("verify_klass {");
 486   __ verify_oop(obj_reg);
 487   __ br_null(obj_reg, false, Assembler::pn, L_bad);
 488   __ load_klass(obj_reg, temp_reg);
 489   __ set(ExternalAddress(klass_addr), temp2_reg);
 490   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
 491   __ cmp_and_brx(temp_reg, temp2_reg, Assembler::equal, false, Assembler::pt, L_ok);
 492   intptr_t super_check_offset = klass->super_check_offset();
 493   __ ld_ptr(Address(temp_reg, super_check_offset), temp_reg);
 494   __ set(ExternalAddress(klass_addr), temp2_reg);
 495   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
 496   __ cmp_and_brx(temp_reg, temp2_reg, Assembler::equal, false, Assembler::pt, L_ok);
 497   __ BIND(L_bad);
 498   __ stop(error_message);
 499   __ BIND(L_ok);
 500   BLOCK_COMMENT("} verify_klass");
 501 }
 502 #endif // ASSERT
 503 
 504 
 505 void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, Register method, Register target, Register temp) {
 506   assert(method == G5_method, "interpreter calling convention");
 507   __ verify_oop(method);
 508   __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_interpreted_offset()), target);
 509   if (JvmtiExport::can_post_interpreter_events()) {
 510     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 511     // compiled code in threads for which the event is enabled.  Check here for
 512     // interp_only_mode if these events CAN be enabled.
 513     __ verify_thread();
 514     Label skip_compiled_code;
 515 
 516     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());


 631   __ ldsw(vmargslot_addr, result);
 632 }
 633 
 634 static RegisterOrConstant adjust_SP_and_Gargs_down_by_slots(MacroAssembler* _masm,
 635                                                             RegisterOrConstant arg_slots,
 636                                                             Register temp_reg, Register temp2_reg) {
 637   // Keep the stack pointer 2*wordSize aligned.
 638   const int TwoWordAlignmentMask = right_n_bits(LogBytesPerWord + 1);
 639   if (arg_slots.is_constant()) {
 640     const int        offset = arg_slots.as_constant() << LogBytesPerWord;
 641     const int masked_offset = round_to(offset, 2 * BytesPerWord);
 642     const int masked_offset2 = (offset + 1*BytesPerWord) & ~TwoWordAlignmentMask;
 643     assert(masked_offset == masked_offset2, "must agree");
 644     __ sub(Gargs,        offset, Gargs);
 645     __ sub(SP,    masked_offset, SP   );
 646     return offset;
 647   } else {
 648 #ifdef ASSERT
 649     {
 650       Label L_ok;
 651       __ cmp_and_br(arg_slots.as_register(), 0, Assembler::greaterEqual, false, Assembler::pt, L_ok);
 652       __ stop("negative arg_slots");
 653       __ bind(L_ok);
 654     }
 655 #endif
 656     __ sll_ptr(arg_slots.as_register(), LogBytesPerWord, temp_reg);
 657     __ add( temp_reg,  1*BytesPerWord,       temp2_reg);
 658     __ andn(temp2_reg, TwoWordAlignmentMask, temp2_reg);
 659     __ sub(Gargs, temp_reg,  Gargs);
 660     __ sub(SP,    temp2_reg, SP   );
 661     return temp_reg;
 662   }
 663 }
 664 
 665 static RegisterOrConstant adjust_SP_and_Gargs_up_by_slots(MacroAssembler* _masm,
 666                                                           RegisterOrConstant arg_slots,
 667                                                           Register temp_reg, Register temp2_reg) {
 668   // Keep the stack pointer 2*wordSize aligned.
 669   const int TwoWordAlignmentMask = right_n_bits(LogBytesPerWord + 1);
 670   if (arg_slots.is_constant()) {
 671     const int        offset = arg_slots.as_constant() << LogBytesPerWord;


 706   // Make space on the stack for the inserted argument(s).
 707   // Then pull down everything shallower than argslot_reg.
 708   // The stacked return address gets pulled down with everything else.
 709   // That is, copy [sp, argslot) downward by -size words.  In pseudo-code:
 710   //   sp -= size;
 711   //   for (temp = sp + size; temp < argslot; temp++)
 712   //     temp[-size] = temp[0]
 713   //   argslot -= size;
 714 
 715   // offset is temp3_reg in case of arg_slots being a register.
 716   RegisterOrConstant offset = adjust_SP_and_Gargs_up_by_slots(_masm, arg_slots, temp3_reg, temp_reg);
 717   __ sub(Gargs, offset, temp_reg);  // source pointer for copy
 718 
 719   {
 720     Label loop;
 721     __ BIND(loop);
 722     // pull one word down each time through the loop
 723     __ ld_ptr(           Address(temp_reg, 0     ), temp2_reg);
 724     __ st_ptr(temp2_reg, Address(temp_reg, offset)           );
 725     __ add(temp_reg, wordSize, temp_reg);
 726     __ cmp_and_brx(temp_reg, argslot_reg, Assembler::lessUnsigned, false, Assembler::pt, loop);
 727   }
 728 
 729   // Now move the argslot down, to point to the opened-up space.
 730   __ add(argslot_reg, offset, argslot_reg);
 731   BLOCK_COMMENT("} insert_arg_slots");
 732 }
 733 
 734 
 735 // Helper to remove argument slots from the stack.
 736 // arg_slots must be a multiple of stack_move_unit() and > 0
 737 void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
 738                                      RegisterOrConstant arg_slots,
 739                                      Register argslot_reg,
 740                                      Register temp_reg, Register temp2_reg, Register temp3_reg) {
 741   // allow constant zero
 742   if (arg_slots.is_constant() && arg_slots.as_constant() == 0)
 743     return;
 744   assert_different_registers(argslot_reg, temp_reg, temp2_reg, temp3_reg,
 745                              (!arg_slots.is_register() ? Gargs : arg_slots.as_register()));
 746 


 753 
 754   // Pull up everything shallower than argslot.
 755   // Then remove the excess space on the stack.
 756   // The stacked return address gets pulled up with everything else.
 757   // That is, copy [sp, argslot) upward by size words.  In pseudo-code:
 758   //   for (temp = argslot-1; temp >= sp; --temp)
 759   //     temp[size] = temp[0]
 760   //   argslot += size;
 761   //   sp += size;
 762 
 763   RegisterOrConstant offset = __ regcon_sll_ptr(arg_slots, LogBytesPerWord, temp3_reg);
 764   __ sub(argslot_reg, wordSize, temp_reg);  // source pointer for copy
 765 
 766   {
 767     Label L_loop;
 768     __ BIND(L_loop);
 769     // pull one word up each time through the loop
 770     __ ld_ptr(           Address(temp_reg, 0     ), temp2_reg);
 771     __ st_ptr(temp2_reg, Address(temp_reg, offset)           );
 772     __ sub(temp_reg, wordSize, temp_reg);
 773     __ cmp_and_brx(temp_reg, Gargs, Assembler::greaterEqualUnsigned, false, Assembler::pt, L_loop);
 774   }
 775 
 776   // And adjust the argslot address to point at the deletion point.
 777   __ add(argslot_reg, offset, argslot_reg);
 778 
 779   // We don't need the offset at this point anymore, just adjust SP and Gargs.
 780   (void) adjust_SP_and_Gargs_up_by_slots(_masm, arg_slots, temp3_reg, temp_reg);
 781 
 782   BLOCK_COMMENT("} remove_arg_slots");
 783 }
 784 
 785 // Helper to copy argument slots to the top of the stack.
 786 // The sequence starts with argslot_reg and is counted by slot_count
 787 // slot_count must be a multiple of stack_move_unit() and >= 0
 788 // This function blows the temps but does not change argslot_reg.
 789 void MethodHandles::push_arg_slots(MacroAssembler* _masm,
 790                                    Register argslot_reg,
 791                                    RegisterOrConstant slot_count,
 792                                    Register temp_reg, Register temp2_reg) {
 793   // allow constant zero


 802   if (VerifyMethodHandles)
 803     verify_stack_move(_masm, slot_count, 0);
 804 
 805   RegisterOrConstant offset = adjust_SP_and_Gargs_down_by_slots(_masm, slot_count, temp2_reg, temp_reg);
 806 
 807   if (slot_count.is_constant()) {
 808     for (int i = slot_count.as_constant() - 1; i >= 0; i--) {
 809       __ ld_ptr(          Address(argslot_reg, i * wordSize), temp_reg);
 810       __ st_ptr(temp_reg, Address(Gargs,       i * wordSize));
 811     }
 812   } else {
 813     Label L_plural, L_loop, L_break;
 814     // Emit code to dynamically check for the common cases, zero and one slot.
 815     __ cmp(slot_count.as_register(), (int32_t) 1);
 816     __ br(Assembler::greater, false, Assembler::pn, L_plural);
 817     __ delayed()->nop();
 818     __ br(Assembler::less, false, Assembler::pn, L_break);
 819     __ delayed()->nop();
 820     __ ld_ptr(          Address(argslot_reg, 0), temp_reg);
 821     __ st_ptr(temp_reg, Address(Gargs,       0));
 822     __ ba(L_break);
 823     __ BIND(L_plural);
 824 
 825     // Loop for 2 or more:
 826     //   top = &argslot[slot_count]
 827     //   while (top > argslot)  *(--Gargs) = *(--top)
 828     Register top_reg = temp_reg;
 829     __ add(argslot_reg, offset, top_reg);
 830     __ add(Gargs,       offset, Gargs  );  // move back up again so we can go down
 831     __ BIND(L_loop);
 832     __ sub(top_reg, wordSize, top_reg);
 833     __ sub(Gargs,   wordSize, Gargs  );
 834     __ ld_ptr(           Address(top_reg, 0), temp2_reg);
 835     __ st_ptr(temp2_reg, Address(Gargs,   0));
 836     __ cmp_and_brx(top_reg, argslot_reg, Assembler::greaterUnsigned, false, Assembler::pt, L_loop);
 837     __ BIND(L_break);
 838   }
 839   BLOCK_COMMENT("} push_arg_slots");
 840 }
 841 
 842 // in-place movement; no change to Gargs
 843 // blows temp_reg, temp2_reg
 844 void MethodHandles::move_arg_slots_up(MacroAssembler* _masm,
 845                                       Register bottom_reg,  // invariant
 846                                       Address  top_addr,    // can use temp_reg
 847                                       RegisterOrConstant positive_distance_in_slots,  // destroyed if register
 848                                       Register temp_reg, Register temp2_reg) {
 849   assert_different_registers(bottom_reg,
 850                              temp_reg, temp2_reg,
 851                              positive_distance_in_slots.register_or_noreg());
 852   BLOCK_COMMENT("move_arg_slots_up {");
 853   Label L_loop, L_break;
 854   Register top_reg = temp_reg;
 855   if (!top_addr.is_same_address(Address(top_reg, 0))) {
 856     __ add(top_addr, top_reg);
 857   }
 858   // Detect empty (or broken) loop:
 859 #ifdef ASSERT
 860   if (VerifyMethodHandles) {
 861     // Verify that &bottom < &top (non-empty interval)
 862     Label L_ok, L_bad;
 863     if (positive_distance_in_slots.is_register()) {
 864       __ cmp(positive_distance_in_slots.as_register(), (int32_t) 0);
 865       __ br(Assembler::lessEqual, false, Assembler::pn, L_bad);
 866       __ delayed()->nop();
 867     }
 868     __ cmp_and_brx(bottom_reg, top_reg, Assembler::lessUnsigned, false, Assembler::pt, L_ok);
 869     __ BIND(L_bad);
 870     __ stop("valid bounds (copy up)");
 871     __ BIND(L_ok);
 872   }
 873 #endif
 874   __ cmp_and_brx(bottom_reg, top_reg, Assembler::greaterEqualUnsigned, false, Assembler::pn, L_break);
 875   // work top down to bottom, copying contiguous data upwards
 876   // In pseudo-code:
 877   //   while (--top >= bottom) *(top + distance) = *(top + 0);
 878   RegisterOrConstant offset = __ argument_offset(positive_distance_in_slots, positive_distance_in_slots.register_or_noreg());
 879   __ BIND(L_loop);
 880   __ sub(top_reg, wordSize, top_reg);
 881   __ ld_ptr(           Address(top_reg, 0     ), temp2_reg);
 882   __ st_ptr(temp2_reg, Address(top_reg, offset)           );
 883   __ cmp_and_brx(top_reg, bottom_reg, Assembler::greaterUnsigned, false, Assembler::pt, L_loop);
 884   assert(Interpreter::stackElementSize == wordSize, "else change loop");
 885   __ BIND(L_break);
 886   BLOCK_COMMENT("} move_arg_slots_up");
 887 }
 888 
 889 // in-place movement; no change to rsp
 890 // blows temp_reg, temp2_reg
 891 void MethodHandles::move_arg_slots_down(MacroAssembler* _masm,
 892                                         Address  bottom_addr,  // can use temp_reg
 893                                         Register top_reg,      // invariant
 894                                         RegisterOrConstant negative_distance_in_slots,  // destroyed if register
 895                                         Register temp_reg, Register temp2_reg) {
 896   assert_different_registers(top_reg,
 897                              negative_distance_in_slots.register_or_noreg(),
 898                              temp_reg, temp2_reg);
 899   BLOCK_COMMENT("move_arg_slots_down {");
 900   Label L_loop, L_break;
 901   Register bottom_reg = temp_reg;
 902   if (!bottom_addr.is_same_address(Address(bottom_reg, 0))) {
 903     __ add(bottom_addr, bottom_reg);
 904   }
 905   // Detect empty (or broken) loop:
 906 #ifdef ASSERT
 907   assert(!negative_distance_in_slots.is_constant() || negative_distance_in_slots.as_constant() < 0, "");
 908   if (VerifyMethodHandles) {
 909     // Verify that &bottom < &top (non-empty interval)
 910     Label L_ok, L_bad;
 911     if (negative_distance_in_slots.is_register()) {
 912       __ cmp(negative_distance_in_slots.as_register(), (int32_t) 0);
 913       __ br(Assembler::greaterEqual, false, Assembler::pn, L_bad);
 914       __ delayed()->nop();
 915     }
 916     __ cmp_and_brx(bottom_reg, top_reg, Assembler::lessUnsigned, false, Assembler::pt, L_ok);
 917     __ BIND(L_bad);
 918     __ stop("valid bounds (copy down)");
 919     __ BIND(L_ok);
 920   }
 921 #endif
 922   __ cmp_and_brx(bottom_reg, top_reg, Assembler::greaterEqualUnsigned, false, Assembler::pn, L_break);
 923   // work bottom up to top, copying contiguous data downwards
 924   // In pseudo-code:
 925   //   while (bottom < top) *(bottom - distance) = *(bottom + 0), bottom++;
 926   RegisterOrConstant offset = __ argument_offset(negative_distance_in_slots, negative_distance_in_slots.register_or_noreg());
 927   __ BIND(L_loop);
 928   __ ld_ptr(           Address(bottom_reg, 0     ), temp2_reg);
 929   __ st_ptr(temp2_reg, Address(bottom_reg, offset)           );
 930   __ add(bottom_reg, wordSize, bottom_reg);
 931   __ cmp_and_brx(bottom_reg, top_reg, Assembler::lessUnsigned, false, Assembler::pt, L_loop);
 932   assert(Interpreter::stackElementSize == wordSize, "else change loop");
 933   __ BIND(L_break);
 934   BLOCK_COMMENT("} move_arg_slots_down");
 935 }
 936 
 937 // Copy from a field or array element to a stacked argument slot.
 938 // is_element (ignored) says whether caller is loading an array element instead of an instance field.
 939 void MethodHandles::move_typed_arg(MacroAssembler* _masm,
 940                                    BasicType type, bool is_element,
 941                                    Address value_src, Address slot_dest,
 942                                    Register temp_reg) {
 943   assert(!slot_dest.uses(temp_reg), "must be different register");
 944   BLOCK_COMMENT(!is_element ? "move_typed_arg {" : "move_typed_arg { (array element)");
 945   if (type == T_OBJECT || type == T_ARRAY) {
 946     __ load_heap_oop(value_src, temp_reg);
 947     __ verify_oop(temp_reg);
 948     __ st_ptr(temp_reg, slot_dest);
 949   } else if (type != T_VOID) {
 950     int  arg_size      = type2aelembytes(type);
 951     bool arg_is_signed = is_signed_subword_type(type);


1268     __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1269     __ verify_oop(G3_method_handle);
1270     __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1271     // This is OK when all parameter types widen.
1272     // It is also OK when a return type narrows.
1273     break;
1274 
1275   case _adapter_check_cast:
1276     {
1277       // Check a reference argument before jumping to the next layer of MH:
1278       load_vmargslot(_masm, G3_amh_vmargslot, O0_argslot);
1279       Address vmarg = __ argument_address(O0_argslot, O0_argslot);
1280 
1281       // What class are we casting to?
1282       Register O1_klass = O1_scratch;  // Interesting AMH data.
1283       __ load_heap_oop(G3_amh_argument, O1_klass);  // This is a Class object!
1284       load_klass_from_Class(_masm, O1_klass, O2_scratch, O3_scratch);
1285 
1286       Label L_done;
1287       __ ld_ptr(vmarg, O2_scratch);
1288       __ br_null(O2_scratch, false, Assembler::pn, L_done);  // No cast if null.
1289       __ load_klass(O2_scratch, O2_scratch);
1290 
1291       // Live at this point:
1292       // - O0_argslot      :  argslot index in vmarg; may be required in the failing path
1293       // - O1_klass        :  klass required by the target method
1294       // - O2_scratch      :  argument klass to test
1295       // - G3_method_handle:  adapter method handle
1296       __ check_klass_subtype(O2_scratch, O1_klass, O3_scratch, O4_scratch, L_done);
1297 
1298       // If we get here, the type check failed!
1299       __ load_heap_oop(G3_amh_argument,        O2_required);  // required class
1300       __ ld_ptr(       vmarg,                  O1_actual);    // bad object
1301       __ jump_to(AddressLiteral(from_interpreted_entry(_raise_exception)), O3_scratch);
1302       __ delayed()->mov(Bytecodes::_checkcast, O0_code);      // who is complaining?
1303 
1304       __ BIND(L_done);
1305       // Get the new MH:
1306       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1307       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1308     }


1373         ShouldNotReachHere();
1374       }
1375 
1376       // This check is required on _BIG_ENDIAN
1377       Register G5_vminfo = G5_scratch;
1378       __ ldsw(G3_amh_conversion, G5_vminfo);
1379       assert(CONV_VMINFO_SHIFT == 0, "preshifted");
1380 
1381       // Original 32-bit vmdata word must be of this form:
1382       // | MBZ:6 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 |
1383       __ lduw(value, O1_scratch);
1384       if (!value_left_justified)
1385         __ sll(O1_scratch, G5_vminfo, O1_scratch);
1386       Label zero_extend, done;
1387       __ btst(CONV_VMINFO_SIGN_FLAG, G5_vminfo);
1388       __ br(Assembler::zero, false, Assembler::pn, zero_extend);
1389       __ delayed()->nop();
1390 
1391       // this path is taken for int->byte, int->short
1392       __ sra(O1_scratch, G5_vminfo, O1_scratch);
1393       __ ba(done);
1394 
1395       __ bind(zero_extend);
1396       // this is taken for int->char
1397       __ srl(O1_scratch, G5_vminfo, O1_scratch);
1398 
1399       __ bind(done);
1400       __ st(O1_scratch, vmarg);
1401 
1402       // Get the new MH:
1403       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1404       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1405     }
1406     break;
1407 
1408   case _adapter_opt_i2l:        // optimized subcase of adapt_prim_to_prim
1409   case _adapter_opt_unboxl:     // optimized subcase of adapt_ref_to_prim
1410     {
1411       // Perform an in-place int-to-long or ref-to-long conversion.
1412       load_vmargslot(_masm, G3_amh_vmargslot, O0_argslot);
1413 


1796       // In the case of a boxing call, the recursive call is to a 'boxer' method,
1797       // such as Integer.valueOf or Long.valueOf.  In the case of a filter
1798       // or collect call, it will take one or more arguments, transform them,
1799       // and return some result, to store back into argument_base[vminfo].
1800       __ load_heap_oop(G3_amh_argument, G3_method_handle);
1801       if (VerifyMethodHandles)  verify_method_handle(_masm, G3_method_handle, O1_scratch, O2_scratch);
1802 
1803       // Calculate |collect|, the number of arguments we are collecting.
1804       Register O1_collect_count = O1_scratch;
1805       RegisterOrConstant collect_count;
1806       if (collect_count_constant < 0) {
1807         __ load_method_handle_vmslots(O1_collect_count, G3_method_handle, O2_scratch);
1808         collect_count = O1_collect_count;
1809       } else {
1810         collect_count = collect_count_constant;
1811 #ifdef ASSERT
1812         if (VerifyMethodHandles) {
1813           BLOCK_COMMENT("verify collect_count_constant {");
1814           __ load_method_handle_vmslots(O3_scratch, G3_method_handle, O2_scratch);
1815           Label L_count_ok;
1816           __ cmp_and_br(O3_scratch, collect_count_constant, Assembler::equal, false, Assembler::pt, L_count_ok);
1817           __ stop("bad vminfo in AMH.conv");
1818           __ BIND(L_count_ok);
1819           BLOCK_COMMENT("} verify collect_count_constant");
1820         }
1821 #endif //ASSERT
1822       }
1823 
1824       // copy |collect| slots directly to TOS:
1825       push_arg_slots(_masm, O0_coll, collect_count, O2_scratch, O3_scratch);
1826       // Now pushed:  ... keep1 | collect | keep2 | RF... | collect |
1827       // O0_coll still points at the trailing edge of |collect| and leading edge of |keep2|
1828 
1829       // If necessary, adjust the saved arguments to make room for the eventual return value.
1830       // Normal adjustment:  ... keep1 | +dest+ | -collect- | keep2 | RF... | collect |
1831       // If retaining args:  ... keep1 | +dest+ |  collect  | keep2 | RF... | collect |
1832       // In the non-retaining case, this might move keep2 either up or down.
1833       // We don't have to copy the whole | RF... collect | complex,
1834       // but we must adjust RF.saved_args_base.
1835       // Also, from now on, we will forget about the original copy of |collect|.
1836       // If we are retaining it, we will treat it as part of |keep2|.


1843       Register O1_close_count = O1_collect_count;
1844       if (retain_original_args) {
1845         close_count = constant(0);
1846       } else if (collect_count_constant == -1) {
1847         close_count = O1_collect_count;
1848       }
1849 
1850       // How many slots need moving?  This is simply dest_slot (0 => no |keep3|).
1851       RegisterOrConstant keep3_count;
1852       Register O2_keep3_count = O2_scratch;
1853       if (dest_slot_constant < 0) {
1854         extract_conversion_vminfo(_masm, RicochetFrame::L5_conversion, O2_keep3_count);
1855         keep3_count = O2_keep3_count;
1856       } else  {
1857         keep3_count = dest_slot_constant;
1858 #ifdef ASSERT
1859         if (VerifyMethodHandles && dest_slot_constant < 0) {
1860           BLOCK_COMMENT("verify dest_slot_constant {");
1861           extract_conversion_vminfo(_masm, RicochetFrame::L5_conversion, O3_scratch);
1862           Label L_vminfo_ok;
1863           __ cmp_and_br(O3_scratch, dest_slot_constant, Assembler::equal, false, Assembler::pt, L_vminfo_ok);
1864           __ stop("bad vminfo in AMH.conv");
1865           __ BIND(L_vminfo_ok);
1866           BLOCK_COMMENT("} verify dest_slot_constant");
1867         }
1868 #endif //ASSERT
1869       }
1870 
1871       // tasks remaining:
1872       bool move_keep3 = (!keep3_count.is_constant() || keep3_count.as_constant() != 0);
1873       bool stomp_dest = (NOT_DEBUG(dest == T_OBJECT) DEBUG_ONLY(dest_count != 0));
1874       bool fix_arg_base = (!close_count.is_constant() || open_count != close_count.as_constant());
1875 
1876       // Old and new argument locations (based at slot 0).
1877       // Net shift (&new_argv - &old_argv) is (close_count - open_count).
1878       bool zero_open_count = (open_count == 0);  // remember this bit of info
1879       if (move_keep3 && fix_arg_base) {
1880         // It will be easier to have everything in one register:
1881         if (close_count.is_register()) {
1882           // Deduct open_count from close_count register to get a clean +/- value.
1883           __ sub(close_count.as_register(), open_count, close_count.as_register());
1884         } else {
1885           close_count = close_count.as_constant() - open_count;
1886         }
1887         open_count = 0;
1888       }
1889       Register L4_old_argv = RicochetFrame::L4_saved_args_base;
1890       Register O3_new_argv = O3_scratch;
1891       if (fix_arg_base) {
1892         __ add(L4_old_argv, __ argument_offset(close_count, O4_scratch), O3_new_argv,
1893                -(open_count * Interpreter::stackElementSize));
1894       }
1895 
1896       // First decide if any actual data are to be moved.
1897       // We can skip if (a) |keep3| is empty, or (b) the argument list size didn't change.
1898       // (As it happens, all movements involve an argument list size change.)
1899 
1900       // If there are variable parameters, use dynamic checks to skip around the whole mess.
1901       Label L_done;
1902       if (keep3_count.is_register()) {
1903         __ br_zero(keep3_count.as_register(), L_done);
1904       }
1905       if (close_count.is_register()) {
1906         __ cmp_and_br(close_count.as_register(), open_count, Assembler::equal, false, Assembler::pn, L_done);
1907       }
1908 
1909       if (move_keep3 && fix_arg_base) {
1910         bool emit_move_down = false, emit_move_up = false, emit_guard = false;
1911         if (!close_count.is_constant()) {
1912           emit_move_down = emit_guard = !zero_open_count;
1913           emit_move_up   = true;
1914         } else if (open_count != close_count.as_constant()) {
1915           emit_move_down = (open_count > close_count.as_constant());
1916           emit_move_up   = !emit_move_down;
1917         }
1918         Label L_move_up;
1919         if (emit_guard) {
1920           __ cmp(close_count.as_register(), open_count);
1921           __ br(Assembler::greater, false, Assembler::pn, L_move_up);
1922           __ delayed()->nop();
1923         }
1924 
1925         if (emit_move_down) {
1926           // Move arguments down if |+dest+| > |-collect-|
1927           // (This is rare, except when arguments are retained.)
1928           // This opens space for the return value.
1929           if (keep3_count.is_constant()) {
1930             for (int i = 0; i < keep3_count.as_constant(); i++) {
1931               __ ld_ptr(            Address(L4_old_argv, i * Interpreter::stackElementSize), O4_scratch);
1932               __ st_ptr(O4_scratch, Address(O3_new_argv, i * Interpreter::stackElementSize)            );
1933             }
1934           } else {
1935             // Live: O1_close_count, O2_keep3_count, O3_new_argv
1936             Register argv_top = O0_scratch;
1937             __ add(L4_old_argv, __ argument_offset(keep3_count, O4_scratch), argv_top);
1938             move_arg_slots_down(_masm,
1939                                 Address(L4_old_argv, 0),  // beginning of old argv
1940                                 argv_top,                 // end of old argv
1941                                 close_count,              // distance to move down (must be negative)
1942                                 O4_scratch, G5_scratch);
1943           }
1944         }
1945 
1946         if (emit_guard) {
1947           __ ba(L_done);  // assumes emit_move_up is true also
1948           __ BIND(L_move_up);
1949         }
1950 
1951         if (emit_move_up) {
1952           // Move arguments up if |+dest+| < |-collect-|
1953           // (This is usual, except when |keep3| is empty.)
1954           // This closes up the space occupied by the now-deleted collect values.
1955           if (keep3_count.is_constant()) {
1956             for (int i = keep3_count.as_constant() - 1; i >= 0; i--) {
1957               __ ld_ptr(            Address(L4_old_argv, i * Interpreter::stackElementSize), O4_scratch);
1958               __ st_ptr(O4_scratch, Address(O3_new_argv, i * Interpreter::stackElementSize)            );
1959             }
1960           } else {
1961             Address argv_top(L4_old_argv, __ argument_offset(keep3_count, O4_scratch));
1962             // Live: O1_close_count, O2_keep3_count, O3_new_argv
1963             move_arg_slots_up(_masm,
1964                               L4_old_argv,  // beginning of old argv
1965                               argv_top,     // end of old argv
1966                               close_count,  // distance to move up (must be positive)
1967                               O4_scratch, G5_scratch);


2060       if (VerifyMethodHandles)  verify_method_handle(_masm, G3_method_handle, O0_scratch, O1_scratch);
2061       __ restore(I5_savedSP, G0, SP);
2062       __ jump_to_method_handle_entry(G3_method_handle, O0_scratch);
2063       __ illtrap(0);
2064     }
2065     break;
2066 
2067   case _adapter_opt_return_any:
2068     {
2069       Register O7_temp      = O7;
2070       Register O5_dest_type = O5;
2071 
2072       if (VerifyMethodHandles)  RicochetFrame::verify_clean(_masm);
2073       extract_conversion_dest_type(_masm, RicochetFrame::L5_conversion, O5_dest_type);
2074       __ set(ExternalAddress((address) &_adapter_return_handlers[0]), O7_temp);
2075       __ sll_ptr(O5_dest_type, LogBytesPerWord, O5_dest_type);
2076       __ ld_ptr(O7_temp, O5_dest_type, O7_temp);
2077 
2078 #ifdef ASSERT
2079       { Label L_ok;
2080         __ br_notnull(O7_temp, false, Assembler::pt, L_ok);
2081         __ stop("bad method handle return");
2082         __ BIND(L_ok);
2083       }
2084 #endif //ASSERT
2085       __ JMP(O7_temp, 0);
2086       __ delayed()->nop();
2087     }
2088     break;
2089 
2090   case _adapter_opt_spread_0:
2091   case _adapter_opt_spread_1_ref:
2092   case _adapter_opt_spread_2_ref:
2093   case _adapter_opt_spread_3_ref:
2094   case _adapter_opt_spread_4_ref:
2095   case _adapter_opt_spread_5_ref:
2096   case _adapter_opt_spread_ref:
2097   case _adapter_opt_spread_byte:
2098   case _adapter_opt_spread_char:
2099   case _adapter_opt_spread_short:
2100   case _adapter_opt_spread_int:


2118 
2119       // O0_argslot points both to the array and to the first output arg
2120       Address vmarg = Address(O0_argslot, 0);
2121 
2122       // Get the array value.
2123       Register  O1_array       = O1_scratch;
2124       Register  O2_array_klass = O2_scratch;
2125       BasicType elem_type      = ek_adapter_opt_spread_type(ek);
2126       int       elem_slots     = type2size[elem_type];  // 1 or 2
2127       int       array_slots    = 1;  // array is always a T_OBJECT
2128       int       length_offset  = arrayOopDesc::length_offset_in_bytes();
2129       int       elem0_offset   = arrayOopDesc::base_offset_in_bytes(elem_type);
2130       __ ld_ptr(vmarg, O1_array);
2131 
2132       Label L_array_is_empty, L_insert_arg_space, L_copy_args, L_args_done;
2133       if (length_can_be_zero) {
2134         // handle the null pointer case, if zero is allowed
2135         Label L_skip;
2136         if (length_constant < 0) {
2137           load_conversion_vminfo(_masm, G3_amh_conversion, O3_scratch);
2138           __ tst(O3_scratch);
2139           __ br(Assembler::notZero, false, Assembler::pn, L_skip);
2140           __ delayed()->nop(); // to avoid back-to-back cbcond instructions
2141         }
2142         __ br_null(O1_array, false, Assembler::pn, L_array_is_empty);
2143         __ BIND(L_skip);
2144       }
2145       __ null_check(O1_array, oopDesc::klass_offset_in_bytes());
2146       __ load_klass(O1_array, O2_array_klass);
2147 
2148       // Check the array type.
2149       Register O3_klass = O3_scratch;
2150       __ load_heap_oop(G3_amh_argument, O3_klass);  // this is a Class object!
2151       load_klass_from_Class(_masm, O3_klass, O4_scratch, G5_scratch);
2152 
2153       Label L_ok_array_klass, L_bad_array_klass, L_bad_array_length;
2154       __ check_klass_subtype(O2_array_klass, O3_klass, O4_scratch, G5_scratch, L_ok_array_klass);
2155       // If we get here, the type check failed!
2156       __ ba(L_bad_array_klass);
2157       __ BIND(L_ok_array_klass);
2158 
2159       // Check length.
2160       if (length_constant >= 0) {
2161         __ ldsw(Address(O1_array, length_offset), O4_scratch);
2162         __ cmp(O4_scratch, length_constant);
2163       } else {
2164         Register O3_vminfo = O3_scratch;
2165         load_conversion_vminfo(_masm, G3_amh_conversion, O3_vminfo);
2166         __ ldsw(Address(O1_array, length_offset), O4_scratch);
2167         __ cmp(O3_vminfo, O4_scratch);
2168       }
2169       __ br(Assembler::notEqual, false, Assembler::pn, L_bad_array_length);
2170       __ delayed()->nop();
2171 
2172       Register O2_argslot_limit = O2_scratch;
2173 
2174       // Array length checks out.  Now insert any required stack slots.
2175       if (length_constant == -1) {
2176         // Form a pointer to the end of the affected region.
2177         __ add(O0_argslot, Interpreter::stackElementSize, O2_argslot_limit);
2178         // 'stack_move' is negative number of words to insert
2179         // This number already accounts for elem_slots.
2180         Register O3_stack_move = O3_scratch;
2181         load_stack_move(_masm, G3_amh_conversion, O3_stack_move);
2182         __ cmp(O3_stack_move, 0);
2183         assert(stack_move_unit() < 0, "else change this comparison");
2184         __ br(Assembler::less, false, Assembler::pn, L_insert_arg_space);
2185         __ delayed()->nop();
2186         __ br(Assembler::equal, false, Assembler::pn, L_copy_args);
2187         __ delayed()->nop();
2188         // single argument case, with no array movement
2189         __ BIND(L_array_is_empty);
2190         remove_arg_slots(_masm, -stack_move_unit() * array_slots,
2191                          O0_argslot, O1_scratch, O2_scratch, O3_scratch);
2192         __ ba(L_args_done);  // no spreading to do
2193         __ BIND(L_insert_arg_space);
2194         // come here in the usual case, stack_move < 0 (2 or more spread arguments)
2195         // Live: O1_array, O2_argslot_limit, O3_stack_move
2196         insert_arg_slots(_masm, O3_stack_move,
2197                          O0_argslot, O4_scratch, G5_scratch, O1_scratch);
2198         // reload from rdx_argslot_limit since rax_argslot is now decremented
2199         __ ld_ptr(Address(O2_argslot_limit, -Interpreter::stackElementSize), O1_array);
2200       } else if (length_constant >= 1) {
2201         int new_slots = (length_constant * elem_slots) - array_slots;
2202         insert_arg_slots(_masm, new_slots * stack_move_unit(),
2203                          O0_argslot, O2_scratch, O3_scratch, O4_scratch);
2204       } else if (length_constant == 0) {
2205         __ BIND(L_array_is_empty);
2206         remove_arg_slots(_masm, -stack_move_unit() * array_slots,
2207                          O0_argslot, O1_scratch, O2_scratch, O3_scratch);
2208       } else {
2209         ShouldNotReachHere();
2210       }
2211 
2212       // Copy from the array to the new slots.
2213       // Note: Stack change code preserves integrity of O0_argslot pointer.
2214       // So even after slot insertions, O0_argslot still points to first argument.
2215       // Beware:  Arguments that are shallow on the stack are deep in the array,
2216       // and vice versa.  So a downward-growing stack (the usual) has to be copied
2217       // elementwise in reverse order from the source array.
2218       __ BIND(L_copy_args);
2219       if (length_constant == -1) {
2220         // [O0_argslot, O2_argslot_limit) is the area we are inserting into.
2221         // Array element [0] goes at O0_argslot_limit[-wordSize].
2222         Register O1_source = O1_array;
2223         __ add(Address(O1_array, elem0_offset), O1_source);
2224         Register O4_fill_ptr = O4_scratch;
2225         __ mov(O2_argslot_limit, O4_fill_ptr);
2226         Label L_loop;
2227         __ BIND(L_loop);
2228         __ add(O4_fill_ptr, -Interpreter::stackElementSize * elem_slots, O4_fill_ptr);
2229         move_typed_arg(_masm, elem_type, true,
2230                        Address(O1_source, 0), Address(O4_fill_ptr, 0),
2231                        O2_scratch);  // must be an even register for !_LP64 long moves (uses O2/O3)
2232         __ add(O1_source, type2aelembytes(elem_type), O1_source);
2233         __ cmp_and_brx(O4_fill_ptr, O0_argslot, Assembler::greaterUnsigned, false, Assembler::pt, L_loop);
2234       } else if (length_constant == 0) {
2235         // nothing to copy
2236       } else {
2237         int elem_offset = elem0_offset;
2238         int slot_offset = length_constant * Interpreter::stackElementSize;
2239         for (int index = 0; index < length_constant; index++) {
2240           slot_offset -= Interpreter::stackElementSize * elem_slots;  // fill backward
2241           move_typed_arg(_masm, elem_type, true,
2242                          Address(O1_array, elem_offset), Address(O0_argslot, slot_offset),
2243                          O2_scratch);  // must be an even register for !_LP64 long moves (uses O2/O3)
2244           elem_offset += type2aelembytes(elem_type);
2245         }
2246       }
2247       __ BIND(L_args_done);
2248 
2249       // Arguments are spread.  Move to next method handle.
2250       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
2251       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
2252 
2253       __ BIND(L_bad_array_klass);




 270 // Emit code to verify that FP is pointing at a valid ricochet frame.
 271 #ifdef ASSERT
 272 enum {
 273   ARG_LIMIT = 255, SLOP = 45,
 274   // use this parameter for checking for garbage stack movements:
 275   UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP)
 276   // the slop defends against false alarms due to fencepost errors
 277 };
 278 
 279 void MethodHandles::RicochetFrame::verify_clean(MacroAssembler* _masm) {
 280   // The stack should look like this:
 281   //    ... keep1 | dest=42 | keep2 | magic | handler | magic | recursive args | [RF]
 282   // Check various invariants.
 283 
 284   Register O7_temp = O7, O5_temp = O5;
 285 
 286   Label L_ok_1, L_ok_2, L_ok_3, L_ok_4;
 287   BLOCK_COMMENT("verify_clean {");
 288   // Magic numbers must check out:
 289   __ set((int32_t) MAGIC_NUMBER_1, O7_temp);
 290   __ cmp_and_br_short(O7_temp, L0_magic_number_1, Assembler::equal, Assembler::pt, L_ok_1);
 291   __ stop("damaged ricochet frame: MAGIC_NUMBER_1 not found");
 292 
 293   __ BIND(L_ok_1);
 294 
 295   // Arguments pointer must look reasonable:
 296 #ifdef _LP64
 297   Register FP_temp = O5_temp;
 298   __ add(FP, STACK_BIAS, FP_temp);
 299 #else
 300   Register FP_temp = FP;
 301 #endif
 302   __ cmp_and_brx_short(L4_saved_args_base, FP_temp, Assembler::greaterEqualUnsigned, Assembler::pt, L_ok_2);
 303   __ stop("damaged ricochet frame: L4 < FP");
 304 
 305   __ BIND(L_ok_2);
 306   // Disable until we decide on it's fate
 307   // __ sub(L4_saved_args_base, UNREASONABLE_STACK_MOVE * Interpreter::stackElementSize, O7_temp);
 308   // __ cmp(O7_temp, FP_temp);
 309   // __ br(Assembler::lessEqualUnsigned, false, Assembler::pt, L_ok_3);
 310   // __ delayed()->nop();
 311   // __ stop("damaged ricochet frame: (L4 - UNREASONABLE_STACK_MOVE) > FP");
 312 
 313   __ BIND(L_ok_3);
 314   extract_conversion_dest_type(_masm, L5_conversion, O7_temp);
 315   __ cmp_and_br_short(O7_temp, T_VOID, Assembler::equal, Assembler::pt, L_ok_4);
 316   extract_conversion_vminfo(_masm, L5_conversion, O5_temp);
 317   __ ld_ptr(L4_saved_args_base, __ argument_offset(O5_temp, O5_temp), O7_temp);
 318   assert(__ is_simm13(RETURN_VALUE_PLACEHOLDER), "must be simm13");
 319   __ cmp_and_brx_short(O7_temp, (int32_t) RETURN_VALUE_PLACEHOLDER, Assembler::equal, Assembler::pt, L_ok_4);
 320   __ stop("damaged ricochet frame: RETURN_VALUE_PLACEHOLDER not found");
 321   __ BIND(L_ok_4);
 322   BLOCK_COMMENT("} verify_clean");
 323 }
 324 #endif //ASSERT
 325 
 326 void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp_reg, Register temp2_reg) {
 327   if (VerifyMethodHandles)
 328     verify_klass(_masm, klass_reg, SystemDictionaryHandles::Class_klass(), temp_reg, temp2_reg,
 329                  "AMH argument is a Class");
 330   __ load_heap_oop(Address(klass_reg, java_lang_Class::klass_offset_in_bytes()), klass_reg);
 331 }
 332 
 333 void MethodHandles::load_conversion_vminfo(MacroAssembler* _masm, Address conversion_field_addr, Register reg) {
 334   assert(CONV_VMINFO_SHIFT == 0, "preshifted");
 335   assert(CONV_VMINFO_MASK == right_n_bits(BitsPerByte), "else change type of following load");
 336   __ ldub(conversion_field_addr.plus_disp(BytesPerInt - 1), reg);
 337 }
 338 
 339 void MethodHandles::extract_conversion_vminfo(MacroAssembler* _masm, Register conversion_field_reg, Register reg) {
 340   assert(CONV_VMINFO_SHIFT == 0, "preshifted");
 341   __ and3(conversion_field_reg, CONV_VMINFO_MASK, reg);
 342 }
 343 
 344 void MethodHandles::extract_conversion_dest_type(MacroAssembler* _masm, Register conversion_field_reg, Register reg) {
 345   __ srl(conversion_field_reg, CONV_DEST_TYPE_SHIFT, reg);
 346   __ and3(reg, 0x0F, reg);
 347 }
 348 
 349 void MethodHandles::load_stack_move(MacroAssembler* _masm,
 350                                     Address G3_amh_conversion,
 351                                     Register stack_move_reg) {
 352   BLOCK_COMMENT("load_stack_move {");
 353   __ ldsw(G3_amh_conversion, stack_move_reg);
 354   __ sra(stack_move_reg, CONV_STACK_MOVE_SHIFT, stack_move_reg);
 355   if (VerifyMethodHandles) {
 356     Label L_ok, L_bad;
 357     int32_t stack_move_limit = 0x0800;  // extra-large
 358     __ cmp_and_br_short(stack_move_reg, stack_move_limit, Assembler::greaterEqual, Assembler::pn, L_bad);
 359     __ cmp(stack_move_reg, -stack_move_limit);
 360     __ br(Assembler::greater, false, Assembler::pt, L_ok);
 361     __ delayed()->nop();
 362     __ BIND(L_bad);
 363     __ stop("load_stack_move of garbage value");
 364     __ BIND(L_ok);
 365   }
 366   BLOCK_COMMENT("} load_stack_move");
 367 }
 368 
 369 #ifdef ASSERT
 370 void MethodHandles::RicochetFrame::verify() const {
 371   assert(magic_number_1() == MAGIC_NUMBER_1, "");
 372   if (!Universe::heap()->is_gc_active()) {
 373     if (saved_args_layout() != NULL) {
 374       assert(saved_args_layout()->is_method(), "must be valid oop");
 375     }
 376     if (saved_target() != NULL) {
 377       assert(java_lang_invoke_MethodHandle::is_instance(saved_target()), "checking frame value");
 378     }
 379   }
 380   int conv_op = adapter_conversion_op(conversion());
 381   assert(conv_op == java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS ||
 382          conv_op == java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS ||
 383          conv_op == java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF,
 384          "must be a sane conversion");
 385   if (has_return_value_slot()) {
 386     assert(*return_value_slot_addr() == RETURN_VALUE_PLACEHOLDER, "");
 387   }
 388 }
 389 
 390 void MethodHandles::verify_argslot(MacroAssembler* _masm, Register argslot_reg, Register temp_reg, const char* error_message) {
 391   // Verify that argslot lies within (Gargs, FP].
 392   Label L_ok, L_bad;
 393   BLOCK_COMMENT("verify_argslot {");
 394   __ cmp_and_brx_short(Gargs, argslot_reg, Assembler::greaterUnsigned, Assembler::pn, L_bad);
 395   __ add(FP, STACK_BIAS, temp_reg);  // STACK_BIAS is zero on !_LP64
 396   __ cmp_and_brx_short(argslot_reg, temp_reg, Assembler::lessEqualUnsigned, Assembler::pt, L_ok);
 397   __ BIND(L_bad);
 398   __ stop(error_message);
 399   __ BIND(L_ok);
 400   BLOCK_COMMENT("} verify_argslot");
 401 }
 402 
 403 void MethodHandles::verify_argslots(MacroAssembler* _masm,
 404                                     RegisterOrConstant arg_slots,
 405                                     Register arg_slot_base_reg,
 406                                     Register temp_reg,
 407                                     Register temp2_reg,
 408                                     bool negate_argslots,
 409                                     const char* error_message) {
 410   // Verify that [argslot..argslot+size) lies within (Gargs, FP).
 411   Label L_ok, L_bad;
 412   BLOCK_COMMENT("verify_argslots {");
 413   if (negate_argslots) {
 414     if (arg_slots.is_constant()) {
 415       arg_slots = -1 * arg_slots.as_constant();
 416     } else {
 417       __ neg(arg_slots.as_register(), temp_reg);
 418       arg_slots = temp_reg;
 419     }
 420   }
 421   __ add(arg_slot_base_reg, __ argument_offset(arg_slots, temp_reg), temp_reg);
 422   __ add(FP, STACK_BIAS, temp2_reg);  // STACK_BIAS is zero on !_LP64
 423   __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::greaterUnsigned, Assembler::pn, L_bad);
 424   // Gargs points to the first word so adjust by BytesPerWord
 425   __ add(arg_slot_base_reg, BytesPerWord, temp_reg);
 426   __ cmp_and_brx_short(Gargs, temp_reg, Assembler::lessEqualUnsigned, Assembler::pt, L_ok);
 427   __ BIND(L_bad);
 428   __ stop(error_message);
 429   __ BIND(L_ok);
 430   BLOCK_COMMENT("} verify_argslots");
 431 }
 432 
 433 // Make sure that arg_slots has the same sign as the given direction.
 434 // If (and only if) arg_slots is a assembly-time constant, also allow it to be zero.
 435 void MethodHandles::verify_stack_move(MacroAssembler* _masm,
 436                                       RegisterOrConstant arg_slots, int direction) {
 437   enum { UNREASONABLE_STACK_MOVE = 256 * 4 };  // limit of 255 arguments
 438   bool allow_zero = arg_slots.is_constant();
 439   if (direction == 0) { direction = +1; allow_zero = true; }
 440   assert(stack_move_unit() == -1, "else add extra checks here");
 441   if (arg_slots.is_register()) {
 442     Label L_ok, L_bad;
 443     BLOCK_COMMENT("verify_stack_move {");
 444     // __ btst(-stack_move_unit() - 1, arg_slots.as_register());  // no need
 445     // __ br(Assembler::notZero, false, Assembler::pn, L_bad);
 446     // __ delayed()->nop();


 467     BLOCK_COMMENT("} verify_stack_move");
 468   } else {
 469     intptr_t size = arg_slots.as_constant();
 470     if (direction < 0)  size = -size;
 471     assert(size >= 0, "correct direction of constant move");
 472     assert(size < UNREASONABLE_STACK_MOVE, "reasonable size of constant move");
 473   }
 474 }
 475 
 476 void MethodHandles::verify_klass(MacroAssembler* _masm,
 477                                  Register obj_reg, KlassHandle klass,
 478                                  Register temp_reg, Register temp2_reg,
 479                                  const char* error_message) {
 480   oop* klass_addr = klass.raw_value();
 481   assert(klass_addr >= SystemDictionaryHandles::Object_klass().raw_value() &&
 482          klass_addr <= SystemDictionaryHandles::Long_klass().raw_value(),
 483          "must be one of the SystemDictionaryHandles");
 484   Label L_ok, L_bad;
 485   BLOCK_COMMENT("verify_klass {");
 486   __ verify_oop(obj_reg);
 487   __ br_null_short(obj_reg, Assembler::pn, L_bad);
 488   __ load_klass(obj_reg, temp_reg);
 489   __ set(ExternalAddress(klass_addr), temp2_reg);
 490   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
 491   __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
 492   intptr_t super_check_offset = klass->super_check_offset();
 493   __ ld_ptr(Address(temp_reg, super_check_offset), temp_reg);
 494   __ set(ExternalAddress(klass_addr), temp2_reg);
 495   __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
 496   __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
 497   __ BIND(L_bad);
 498   __ stop(error_message);
 499   __ BIND(L_ok);
 500   BLOCK_COMMENT("} verify_klass");
 501 }
 502 #endif // ASSERT
 503 
 504 
 505 void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, Register method, Register target, Register temp) {
 506   assert(method == G5_method, "interpreter calling convention");
 507   __ verify_oop(method);
 508   __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_interpreted_offset()), target);
 509   if (JvmtiExport::can_post_interpreter_events()) {
 510     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 511     // compiled code in threads for which the event is enabled.  Check here for
 512     // interp_only_mode if these events CAN be enabled.
 513     __ verify_thread();
 514     Label skip_compiled_code;
 515 
 516     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());


 631   __ ldsw(vmargslot_addr, result);
 632 }
 633 
 634 static RegisterOrConstant adjust_SP_and_Gargs_down_by_slots(MacroAssembler* _masm,
 635                                                             RegisterOrConstant arg_slots,
 636                                                             Register temp_reg, Register temp2_reg) {
 637   // Keep the stack pointer 2*wordSize aligned.
 638   const int TwoWordAlignmentMask = right_n_bits(LogBytesPerWord + 1);
 639   if (arg_slots.is_constant()) {
 640     const int        offset = arg_slots.as_constant() << LogBytesPerWord;
 641     const int masked_offset = round_to(offset, 2 * BytesPerWord);
 642     const int masked_offset2 = (offset + 1*BytesPerWord) & ~TwoWordAlignmentMask;
 643     assert(masked_offset == masked_offset2, "must agree");
 644     __ sub(Gargs,        offset, Gargs);
 645     __ sub(SP,    masked_offset, SP   );
 646     return offset;
 647   } else {
 648 #ifdef ASSERT
 649     {
 650       Label L_ok;
 651       __ cmp_and_br_short(arg_slots.as_register(), 0, Assembler::greaterEqual, Assembler::pt, L_ok);
 652       __ stop("negative arg_slots");
 653       __ bind(L_ok);
 654     }
 655 #endif
 656     __ sll_ptr(arg_slots.as_register(), LogBytesPerWord, temp_reg);
 657     __ add( temp_reg,  1*BytesPerWord,       temp2_reg);
 658     __ andn(temp2_reg, TwoWordAlignmentMask, temp2_reg);
 659     __ sub(Gargs, temp_reg,  Gargs);
 660     __ sub(SP,    temp2_reg, SP   );
 661     return temp_reg;
 662   }
 663 }
 664 
 665 static RegisterOrConstant adjust_SP_and_Gargs_up_by_slots(MacroAssembler* _masm,
 666                                                           RegisterOrConstant arg_slots,
 667                                                           Register temp_reg, Register temp2_reg) {
 668   // Keep the stack pointer 2*wordSize aligned.
 669   const int TwoWordAlignmentMask = right_n_bits(LogBytesPerWord + 1);
 670   if (arg_slots.is_constant()) {
 671     const int        offset = arg_slots.as_constant() << LogBytesPerWord;


 706   // Make space on the stack for the inserted argument(s).
 707   // Then pull down everything shallower than argslot_reg.
 708   // The stacked return address gets pulled down with everything else.
 709   // That is, copy [sp, argslot) downward by -size words.  In pseudo-code:
 710   //   sp -= size;
 711   //   for (temp = sp + size; temp < argslot; temp++)
 712   //     temp[-size] = temp[0]
 713   //   argslot -= size;
 714 
 715   // offset is temp3_reg in case of arg_slots being a register.
 716   RegisterOrConstant offset = adjust_SP_and_Gargs_up_by_slots(_masm, arg_slots, temp3_reg, temp_reg);
 717   __ sub(Gargs, offset, temp_reg);  // source pointer for copy
 718 
 719   {
 720     Label loop;
 721     __ BIND(loop);
 722     // pull one word down each time through the loop
 723     __ ld_ptr(           Address(temp_reg, 0     ), temp2_reg);
 724     __ st_ptr(temp2_reg, Address(temp_reg, offset)           );
 725     __ add(temp_reg, wordSize, temp_reg);
 726     __ cmp_and_brx_short(temp_reg, argslot_reg, Assembler::lessUnsigned, Assembler::pt, loop);
 727   }
 728 
 729   // Now move the argslot down, to point to the opened-up space.
 730   __ add(argslot_reg, offset, argslot_reg);
 731   BLOCK_COMMENT("} insert_arg_slots");
 732 }
 733 
 734 
 735 // Helper to remove argument slots from the stack.
 736 // arg_slots must be a multiple of stack_move_unit() and > 0
 737 void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
 738                                      RegisterOrConstant arg_slots,
 739                                      Register argslot_reg,
 740                                      Register temp_reg, Register temp2_reg, Register temp3_reg) {
 741   // allow constant zero
 742   if (arg_slots.is_constant() && arg_slots.as_constant() == 0)
 743     return;
 744   assert_different_registers(argslot_reg, temp_reg, temp2_reg, temp3_reg,
 745                              (!arg_slots.is_register() ? Gargs : arg_slots.as_register()));
 746 


 753 
 754   // Pull up everything shallower than argslot.
 755   // Then remove the excess space on the stack.
 756   // The stacked return address gets pulled up with everything else.
 757   // That is, copy [sp, argslot) upward by size words.  In pseudo-code:
 758   //   for (temp = argslot-1; temp >= sp; --temp)
 759   //     temp[size] = temp[0]
 760   //   argslot += size;
 761   //   sp += size;
 762 
 763   RegisterOrConstant offset = __ regcon_sll_ptr(arg_slots, LogBytesPerWord, temp3_reg);
 764   __ sub(argslot_reg, wordSize, temp_reg);  // source pointer for copy
 765 
 766   {
 767     Label L_loop;
 768     __ BIND(L_loop);
 769     // pull one word up each time through the loop
 770     __ ld_ptr(           Address(temp_reg, 0     ), temp2_reg);
 771     __ st_ptr(temp2_reg, Address(temp_reg, offset)           );
 772     __ sub(temp_reg, wordSize, temp_reg);
 773     __ cmp_and_brx_short(temp_reg, Gargs, Assembler::greaterEqualUnsigned, Assembler::pt, L_loop);
 774   }
 775 
 776   // And adjust the argslot address to point at the deletion point.
 777   __ add(argslot_reg, offset, argslot_reg);
 778 
 779   // We don't need the offset at this point anymore, just adjust SP and Gargs.
 780   (void) adjust_SP_and_Gargs_up_by_slots(_masm, arg_slots, temp3_reg, temp_reg);
 781 
 782   BLOCK_COMMENT("} remove_arg_slots");
 783 }
 784 
 785 // Helper to copy argument slots to the top of the stack.
 786 // The sequence starts with argslot_reg and is counted by slot_count
 787 // slot_count must be a multiple of stack_move_unit() and >= 0
 788 // This function blows the temps but does not change argslot_reg.
 789 void MethodHandles::push_arg_slots(MacroAssembler* _masm,
 790                                    Register argslot_reg,
 791                                    RegisterOrConstant slot_count,
 792                                    Register temp_reg, Register temp2_reg) {
 793   // allow constant zero


 802   if (VerifyMethodHandles)
 803     verify_stack_move(_masm, slot_count, 0);
 804 
 805   RegisterOrConstant offset = adjust_SP_and_Gargs_down_by_slots(_masm, slot_count, temp2_reg, temp_reg);
 806 
 807   if (slot_count.is_constant()) {
 808     for (int i = slot_count.as_constant() - 1; i >= 0; i--) {
 809       __ ld_ptr(          Address(argslot_reg, i * wordSize), temp_reg);
 810       __ st_ptr(temp_reg, Address(Gargs,       i * wordSize));
 811     }
 812   } else {
 813     Label L_plural, L_loop, L_break;
 814     // Emit code to dynamically check for the common cases, zero and one slot.
 815     __ cmp(slot_count.as_register(), (int32_t) 1);
 816     __ br(Assembler::greater, false, Assembler::pn, L_plural);
 817     __ delayed()->nop();
 818     __ br(Assembler::less, false, Assembler::pn, L_break);
 819     __ delayed()->nop();
 820     __ ld_ptr(          Address(argslot_reg, 0), temp_reg);
 821     __ st_ptr(temp_reg, Address(Gargs,       0));
 822     __ ba_short(L_break);
 823     __ BIND(L_plural);
 824 
 825     // Loop for 2 or more:
 826     //   top = &argslot[slot_count]
 827     //   while (top > argslot)  *(--Gargs) = *(--top)
 828     Register top_reg = temp_reg;
 829     __ add(argslot_reg, offset, top_reg);
 830     __ add(Gargs,       offset, Gargs  );  // move back up again so we can go down
 831     __ BIND(L_loop);
 832     __ sub(top_reg, wordSize, top_reg);
 833     __ sub(Gargs,   wordSize, Gargs  );
 834     __ ld_ptr(           Address(top_reg, 0), temp2_reg);
 835     __ st_ptr(temp2_reg, Address(Gargs,   0));
 836     __ cmp_and_brx_short(top_reg, argslot_reg, Assembler::greaterUnsigned, Assembler::pt, L_loop);
 837     __ BIND(L_break);
 838   }
 839   BLOCK_COMMENT("} push_arg_slots");
 840 }
 841 
 842 // in-place movement; no change to Gargs
 843 // blows temp_reg, temp2_reg
 844 void MethodHandles::move_arg_slots_up(MacroAssembler* _masm,
 845                                       Register bottom_reg,  // invariant
 846                                       Address  top_addr,    // can use temp_reg
 847                                       RegisterOrConstant positive_distance_in_slots,  // destroyed if register
 848                                       Register temp_reg, Register temp2_reg) {
 849   assert_different_registers(bottom_reg,
 850                              temp_reg, temp2_reg,
 851                              positive_distance_in_slots.register_or_noreg());
 852   BLOCK_COMMENT("move_arg_slots_up {");
 853   Label L_loop, L_break;
 854   Register top_reg = temp_reg;
 855   if (!top_addr.is_same_address(Address(top_reg, 0))) {
 856     __ add(top_addr, top_reg);
 857   }
 858   // Detect empty (or broken) loop:
 859 #ifdef ASSERT
 860   if (VerifyMethodHandles) {
 861     // Verify that &bottom < &top (non-empty interval)
 862     Label L_ok, L_bad;
 863     if (positive_distance_in_slots.is_register()) {
 864       __ cmp(positive_distance_in_slots.as_register(), (int32_t) 0);
 865       __ br(Assembler::lessEqual, false, Assembler::pn, L_bad);
 866       __ delayed()->nop();
 867     }
 868     __ cmp_and_brx_short(bottom_reg, top_reg, Assembler::lessUnsigned, Assembler::pt, L_ok);
 869     __ BIND(L_bad);
 870     __ stop("valid bounds (copy up)");
 871     __ BIND(L_ok);
 872   }
 873 #endif
 874   __ cmp_and_brx_short(bottom_reg, top_reg, Assembler::greaterEqualUnsigned, Assembler::pn, L_break);
 875   // work top down to bottom, copying contiguous data upwards
 876   // In pseudo-code:
 877   //   while (--top >= bottom) *(top + distance) = *(top + 0);
 878   RegisterOrConstant offset = __ argument_offset(positive_distance_in_slots, positive_distance_in_slots.register_or_noreg());
 879   __ BIND(L_loop);
 880   __ sub(top_reg, wordSize, top_reg);
 881   __ ld_ptr(           Address(top_reg, 0     ), temp2_reg);
 882   __ st_ptr(temp2_reg, Address(top_reg, offset)           );
 883   __ cmp_and_brx_short(top_reg, bottom_reg, Assembler::greaterUnsigned, Assembler::pt, L_loop);
 884   assert(Interpreter::stackElementSize == wordSize, "else change loop");
 885   __ BIND(L_break);
 886   BLOCK_COMMENT("} move_arg_slots_up");
 887 }
 888 
 889 // in-place movement; no change to rsp
 890 // blows temp_reg, temp2_reg
 891 void MethodHandles::move_arg_slots_down(MacroAssembler* _masm,
 892                                         Address  bottom_addr,  // can use temp_reg
 893                                         Register top_reg,      // invariant
 894                                         RegisterOrConstant negative_distance_in_slots,  // destroyed if register
 895                                         Register temp_reg, Register temp2_reg) {
 896   assert_different_registers(top_reg,
 897                              negative_distance_in_slots.register_or_noreg(),
 898                              temp_reg, temp2_reg);
 899   BLOCK_COMMENT("move_arg_slots_down {");
 900   Label L_loop, L_break;
 901   Register bottom_reg = temp_reg;
 902   if (!bottom_addr.is_same_address(Address(bottom_reg, 0))) {
 903     __ add(bottom_addr, bottom_reg);
 904   }
 905   // Detect empty (or broken) loop:
 906 #ifdef ASSERT
 907   assert(!negative_distance_in_slots.is_constant() || negative_distance_in_slots.as_constant() < 0, "");
 908   if (VerifyMethodHandles) {
 909     // Verify that &bottom < &top (non-empty interval)
 910     Label L_ok, L_bad;
 911     if (negative_distance_in_slots.is_register()) {
 912       __ cmp(negative_distance_in_slots.as_register(), (int32_t) 0);
 913       __ br(Assembler::greaterEqual, false, Assembler::pn, L_bad);
 914       __ delayed()->nop();
 915     }
 916     __ cmp_and_brx_short(bottom_reg, top_reg, Assembler::lessUnsigned, Assembler::pt, L_ok);
 917     __ BIND(L_bad);
 918     __ stop("valid bounds (copy down)");
 919     __ BIND(L_ok);
 920   }
 921 #endif
 922   __ cmp_and_brx_short(bottom_reg, top_reg, Assembler::greaterEqualUnsigned, Assembler::pn, L_break);
 923   // work bottom up to top, copying contiguous data downwards
 924   // In pseudo-code:
 925   //   while (bottom < top) *(bottom - distance) = *(bottom + 0), bottom++;
 926   RegisterOrConstant offset = __ argument_offset(negative_distance_in_slots, negative_distance_in_slots.register_or_noreg());
 927   __ BIND(L_loop);
 928   __ ld_ptr(           Address(bottom_reg, 0     ), temp2_reg);
 929   __ st_ptr(temp2_reg, Address(bottom_reg, offset)           );
 930   __ add(bottom_reg, wordSize, bottom_reg);
 931   __ cmp_and_brx_short(bottom_reg, top_reg, Assembler::lessUnsigned, Assembler::pt, L_loop);
 932   assert(Interpreter::stackElementSize == wordSize, "else change loop");
 933   __ BIND(L_break);
 934   BLOCK_COMMENT("} move_arg_slots_down");
 935 }
 936 
 937 // Copy from a field or array element to a stacked argument slot.
 938 // is_element (ignored) says whether caller is loading an array element instead of an instance field.
 939 void MethodHandles::move_typed_arg(MacroAssembler* _masm,
 940                                    BasicType type, bool is_element,
 941                                    Address value_src, Address slot_dest,
 942                                    Register temp_reg) {
 943   assert(!slot_dest.uses(temp_reg), "must be different register");
 944   BLOCK_COMMENT(!is_element ? "move_typed_arg {" : "move_typed_arg { (array element)");
 945   if (type == T_OBJECT || type == T_ARRAY) {
 946     __ load_heap_oop(value_src, temp_reg);
 947     __ verify_oop(temp_reg);
 948     __ st_ptr(temp_reg, slot_dest);
 949   } else if (type != T_VOID) {
 950     int  arg_size      = type2aelembytes(type);
 951     bool arg_is_signed = is_signed_subword_type(type);


1268     __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1269     __ verify_oop(G3_method_handle);
1270     __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1271     // This is OK when all parameter types widen.
1272     // It is also OK when a return type narrows.
1273     break;
1274 
1275   case _adapter_check_cast:
1276     {
1277       // Check a reference argument before jumping to the next layer of MH:
1278       load_vmargslot(_masm, G3_amh_vmargslot, O0_argslot);
1279       Address vmarg = __ argument_address(O0_argslot, O0_argslot);
1280 
1281       // What class are we casting to?
1282       Register O1_klass = O1_scratch;  // Interesting AMH data.
1283       __ load_heap_oop(G3_amh_argument, O1_klass);  // This is a Class object!
1284       load_klass_from_Class(_masm, O1_klass, O2_scratch, O3_scratch);
1285 
1286       Label L_done;
1287       __ ld_ptr(vmarg, O2_scratch);
1288       __ br_null_short(O2_scratch, Assembler::pn, L_done);  // No cast if null.
1289       __ load_klass(O2_scratch, O2_scratch);
1290 
1291       // Live at this point:
1292       // - O0_argslot      :  argslot index in vmarg; may be required in the failing path
1293       // - O1_klass        :  klass required by the target method
1294       // - O2_scratch      :  argument klass to test
1295       // - G3_method_handle:  adapter method handle
1296       __ check_klass_subtype(O2_scratch, O1_klass, O3_scratch, O4_scratch, L_done);
1297 
1298       // If we get here, the type check failed!
1299       __ load_heap_oop(G3_amh_argument,        O2_required);  // required class
1300       __ ld_ptr(       vmarg,                  O1_actual);    // bad object
1301       __ jump_to(AddressLiteral(from_interpreted_entry(_raise_exception)), O3_scratch);
1302       __ delayed()->mov(Bytecodes::_checkcast, O0_code);      // who is complaining?
1303 
1304       __ BIND(L_done);
1305       // Get the new MH:
1306       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1307       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1308     }


1373         ShouldNotReachHere();
1374       }
1375 
1376       // This check is required on _BIG_ENDIAN
1377       Register G5_vminfo = G5_scratch;
1378       __ ldsw(G3_amh_conversion, G5_vminfo);
1379       assert(CONV_VMINFO_SHIFT == 0, "preshifted");
1380 
1381       // Original 32-bit vmdata word must be of this form:
1382       // | MBZ:6 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 |
1383       __ lduw(value, O1_scratch);
1384       if (!value_left_justified)
1385         __ sll(O1_scratch, G5_vminfo, O1_scratch);
1386       Label zero_extend, done;
1387       __ btst(CONV_VMINFO_SIGN_FLAG, G5_vminfo);
1388       __ br(Assembler::zero, false, Assembler::pn, zero_extend);
1389       __ delayed()->nop();
1390 
1391       // this path is taken for int->byte, int->short
1392       __ sra(O1_scratch, G5_vminfo, O1_scratch);
1393       __ ba_short(done);
1394 
1395       __ bind(zero_extend);
1396       // this is taken for int->char
1397       __ srl(O1_scratch, G5_vminfo, O1_scratch);
1398 
1399       __ bind(done);
1400       __ st(O1_scratch, vmarg);
1401 
1402       // Get the new MH:
1403       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
1404       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
1405     }
1406     break;
1407 
1408   case _adapter_opt_i2l:        // optimized subcase of adapt_prim_to_prim
1409   case _adapter_opt_unboxl:     // optimized subcase of adapt_ref_to_prim
1410     {
1411       // Perform an in-place int-to-long or ref-to-long conversion.
1412       load_vmargslot(_masm, G3_amh_vmargslot, O0_argslot);
1413 


1796       // In the case of a boxing call, the recursive call is to a 'boxer' method,
1797       // such as Integer.valueOf or Long.valueOf.  In the case of a filter
1798       // or collect call, it will take one or more arguments, transform them,
1799       // and return some result, to store back into argument_base[vminfo].
1800       __ load_heap_oop(G3_amh_argument, G3_method_handle);
1801       if (VerifyMethodHandles)  verify_method_handle(_masm, G3_method_handle, O1_scratch, O2_scratch);
1802 
1803       // Calculate |collect|, the number of arguments we are collecting.
1804       Register O1_collect_count = O1_scratch;
1805       RegisterOrConstant collect_count;
1806       if (collect_count_constant < 0) {
1807         __ load_method_handle_vmslots(O1_collect_count, G3_method_handle, O2_scratch);
1808         collect_count = O1_collect_count;
1809       } else {
1810         collect_count = collect_count_constant;
1811 #ifdef ASSERT
1812         if (VerifyMethodHandles) {
1813           BLOCK_COMMENT("verify collect_count_constant {");
1814           __ load_method_handle_vmslots(O3_scratch, G3_method_handle, O2_scratch);
1815           Label L_count_ok;
1816           __ cmp_and_br_short(O3_scratch, collect_count_constant, Assembler::equal, Assembler::pt, L_count_ok);
1817           __ stop("bad vminfo in AMH.conv");
1818           __ BIND(L_count_ok);
1819           BLOCK_COMMENT("} verify collect_count_constant");
1820         }
1821 #endif //ASSERT
1822       }
1823 
1824       // copy |collect| slots directly to TOS:
1825       push_arg_slots(_masm, O0_coll, collect_count, O2_scratch, O3_scratch);
1826       // Now pushed:  ... keep1 | collect | keep2 | RF... | collect |
1827       // O0_coll still points at the trailing edge of |collect| and leading edge of |keep2|
1828 
1829       // If necessary, adjust the saved arguments to make room for the eventual return value.
1830       // Normal adjustment:  ... keep1 | +dest+ | -collect- | keep2 | RF... | collect |
1831       // If retaining args:  ... keep1 | +dest+ |  collect  | keep2 | RF... | collect |
1832       // In the non-retaining case, this might move keep2 either up or down.
1833       // We don't have to copy the whole | RF... collect | complex,
1834       // but we must adjust RF.saved_args_base.
1835       // Also, from now on, we will forget about the original copy of |collect|.
1836       // If we are retaining it, we will treat it as part of |keep2|.


1843       Register O1_close_count = O1_collect_count;
1844       if (retain_original_args) {
1845         close_count = constant(0);
1846       } else if (collect_count_constant == -1) {
1847         close_count = O1_collect_count;
1848       }
1849 
1850       // How many slots need moving?  This is simply dest_slot (0 => no |keep3|).
1851       RegisterOrConstant keep3_count;
1852       Register O2_keep3_count = O2_scratch;
1853       if (dest_slot_constant < 0) {
1854         extract_conversion_vminfo(_masm, RicochetFrame::L5_conversion, O2_keep3_count);
1855         keep3_count = O2_keep3_count;
1856       } else  {
1857         keep3_count = dest_slot_constant;
1858 #ifdef ASSERT
1859         if (VerifyMethodHandles && dest_slot_constant < 0) {
1860           BLOCK_COMMENT("verify dest_slot_constant {");
1861           extract_conversion_vminfo(_masm, RicochetFrame::L5_conversion, O3_scratch);
1862           Label L_vminfo_ok;
1863           __ cmp_and_br_short(O3_scratch, dest_slot_constant, Assembler::equal, Assembler::pt, L_vminfo_ok);
1864           __ stop("bad vminfo in AMH.conv");
1865           __ BIND(L_vminfo_ok);
1866           BLOCK_COMMENT("} verify dest_slot_constant");
1867         }
1868 #endif //ASSERT
1869       }
1870 
1871       // tasks remaining:
1872       bool move_keep3 = (!keep3_count.is_constant() || keep3_count.as_constant() != 0);
1873       bool stomp_dest = (NOT_DEBUG(dest == T_OBJECT) DEBUG_ONLY(dest_count != 0));
1874       bool fix_arg_base = (!close_count.is_constant() || open_count != close_count.as_constant());
1875 
1876       // Old and new argument locations (based at slot 0).
1877       // Net shift (&new_argv - &old_argv) is (close_count - open_count).
1878       bool zero_open_count = (open_count == 0);  // remember this bit of info
1879       if (move_keep3 && fix_arg_base) {
1880         // It will be easier to have everything in one register:
1881         if (close_count.is_register()) {
1882           // Deduct open_count from close_count register to get a clean +/- value.
1883           __ sub(close_count.as_register(), open_count, close_count.as_register());
1884         } else {
1885           close_count = close_count.as_constant() - open_count;
1886         }
1887         open_count = 0;
1888       }
1889       Register L4_old_argv = RicochetFrame::L4_saved_args_base;
1890       Register O3_new_argv = O3_scratch;
1891       if (fix_arg_base) {
1892         __ add(L4_old_argv, __ argument_offset(close_count, O4_scratch), O3_new_argv,
1893                -(open_count * Interpreter::stackElementSize));
1894       }
1895 
1896       // First decide if any actual data are to be moved.
1897       // We can skip if (a) |keep3| is empty, or (b) the argument list size didn't change.
1898       // (As it happens, all movements involve an argument list size change.)
1899 
1900       // If there are variable parameters, use dynamic checks to skip around the whole mess.
1901       Label L_done;
1902       if (keep3_count.is_register()) {
1903         __ cmp_and_br_short(keep3_count.as_register(), 0, Assembler::equal, Assembler::pn, L_done);
1904       }
1905       if (close_count.is_register()) {
1906         __ cmp_and_br_short(close_count.as_register(), open_count, Assembler::equal, Assembler::pn, L_done);
1907       }
1908 
1909       if (move_keep3 && fix_arg_base) {
1910         bool emit_move_down = false, emit_move_up = false, emit_guard = false;
1911         if (!close_count.is_constant()) {
1912           emit_move_down = emit_guard = !zero_open_count;
1913           emit_move_up   = true;
1914         } else if (open_count != close_count.as_constant()) {
1915           emit_move_down = (open_count > close_count.as_constant());
1916           emit_move_up   = !emit_move_down;
1917         }
1918         Label L_move_up;
1919         if (emit_guard) {
1920           __ cmp(close_count.as_register(), open_count);
1921           __ br(Assembler::greater, false, Assembler::pn, L_move_up);
1922           __ delayed()->nop();
1923         }
1924 
1925         if (emit_move_down) {
1926           // Move arguments down if |+dest+| > |-collect-|
1927           // (This is rare, except when arguments are retained.)
1928           // This opens space for the return value.
1929           if (keep3_count.is_constant()) {
1930             for (int i = 0; i < keep3_count.as_constant(); i++) {
1931               __ ld_ptr(            Address(L4_old_argv, i * Interpreter::stackElementSize), O4_scratch);
1932               __ st_ptr(O4_scratch, Address(O3_new_argv, i * Interpreter::stackElementSize)            );
1933             }
1934           } else {
1935             // Live: O1_close_count, O2_keep3_count, O3_new_argv
1936             Register argv_top = O0_scratch;
1937             __ add(L4_old_argv, __ argument_offset(keep3_count, O4_scratch), argv_top);
1938             move_arg_slots_down(_masm,
1939                                 Address(L4_old_argv, 0),  // beginning of old argv
1940                                 argv_top,                 // end of old argv
1941                                 close_count,              // distance to move down (must be negative)
1942                                 O4_scratch, G5_scratch);
1943           }
1944         }
1945 
1946         if (emit_guard) {
1947           __ ba_short(L_done);  // assumes emit_move_up is true also
1948           __ BIND(L_move_up);
1949         }
1950 
1951         if (emit_move_up) {
1952           // Move arguments up if |+dest+| < |-collect-|
1953           // (This is usual, except when |keep3| is empty.)
1954           // This closes up the space occupied by the now-deleted collect values.
1955           if (keep3_count.is_constant()) {
1956             for (int i = keep3_count.as_constant() - 1; i >= 0; i--) {
1957               __ ld_ptr(            Address(L4_old_argv, i * Interpreter::stackElementSize), O4_scratch);
1958               __ st_ptr(O4_scratch, Address(O3_new_argv, i * Interpreter::stackElementSize)            );
1959             }
1960           } else {
1961             Address argv_top(L4_old_argv, __ argument_offset(keep3_count, O4_scratch));
1962             // Live: O1_close_count, O2_keep3_count, O3_new_argv
1963             move_arg_slots_up(_masm,
1964                               L4_old_argv,  // beginning of old argv
1965                               argv_top,     // end of old argv
1966                               close_count,  // distance to move up (must be positive)
1967                               O4_scratch, G5_scratch);


2060       if (VerifyMethodHandles)  verify_method_handle(_masm, G3_method_handle, O0_scratch, O1_scratch);
2061       __ restore(I5_savedSP, G0, SP);
2062       __ jump_to_method_handle_entry(G3_method_handle, O0_scratch);
2063       __ illtrap(0);
2064     }
2065     break;
2066 
2067   case _adapter_opt_return_any:
2068     {
2069       Register O7_temp      = O7;
2070       Register O5_dest_type = O5;
2071 
2072       if (VerifyMethodHandles)  RicochetFrame::verify_clean(_masm);
2073       extract_conversion_dest_type(_masm, RicochetFrame::L5_conversion, O5_dest_type);
2074       __ set(ExternalAddress((address) &_adapter_return_handlers[0]), O7_temp);
2075       __ sll_ptr(O5_dest_type, LogBytesPerWord, O5_dest_type);
2076       __ ld_ptr(O7_temp, O5_dest_type, O7_temp);
2077 
2078 #ifdef ASSERT
2079       { Label L_ok;
2080         __ br_notnull_short(O7_temp, Assembler::pt, L_ok);
2081         __ stop("bad method handle return");
2082         __ BIND(L_ok);
2083       }
2084 #endif //ASSERT
2085       __ JMP(O7_temp, 0);
2086       __ delayed()->nop();
2087     }
2088     break;
2089 
2090   case _adapter_opt_spread_0:
2091   case _adapter_opt_spread_1_ref:
2092   case _adapter_opt_spread_2_ref:
2093   case _adapter_opt_spread_3_ref:
2094   case _adapter_opt_spread_4_ref:
2095   case _adapter_opt_spread_5_ref:
2096   case _adapter_opt_spread_ref:
2097   case _adapter_opt_spread_byte:
2098   case _adapter_opt_spread_char:
2099   case _adapter_opt_spread_short:
2100   case _adapter_opt_spread_int:


2118 
2119       // O0_argslot points both to the array and to the first output arg
2120       Address vmarg = Address(O0_argslot, 0);
2121 
2122       // Get the array value.
2123       Register  O1_array       = O1_scratch;
2124       Register  O2_array_klass = O2_scratch;
2125       BasicType elem_type      = ek_adapter_opt_spread_type(ek);
2126       int       elem_slots     = type2size[elem_type];  // 1 or 2
2127       int       array_slots    = 1;  // array is always a T_OBJECT
2128       int       length_offset  = arrayOopDesc::length_offset_in_bytes();
2129       int       elem0_offset   = arrayOopDesc::base_offset_in_bytes(elem_type);
2130       __ ld_ptr(vmarg, O1_array);
2131 
2132       Label L_array_is_empty, L_insert_arg_space, L_copy_args, L_args_done;
2133       if (length_can_be_zero) {
2134         // handle the null pointer case, if zero is allowed
2135         Label L_skip;
2136         if (length_constant < 0) {
2137           load_conversion_vminfo(_masm, G3_amh_conversion, O3_scratch);
2138           __ cmp_zero_and_br(Assembler::notZero, O3_scratch, L_skip);

2139           __ delayed()->nop(); // to avoid back-to-back cbcond instructions
2140         }
2141         __ br_null_short(O1_array, Assembler::pn, L_array_is_empty);
2142         __ BIND(L_skip);
2143       }
2144       __ null_check(O1_array, oopDesc::klass_offset_in_bytes());
2145       __ load_klass(O1_array, O2_array_klass);
2146 
2147       // Check the array type.
2148       Register O3_klass = O3_scratch;
2149       __ load_heap_oop(G3_amh_argument, O3_klass);  // this is a Class object!
2150       load_klass_from_Class(_masm, O3_klass, O4_scratch, G5_scratch);
2151 
2152       Label L_ok_array_klass, L_bad_array_klass, L_bad_array_length;
2153       __ check_klass_subtype(O2_array_klass, O3_klass, O4_scratch, G5_scratch, L_ok_array_klass);
2154       // If we get here, the type check failed!
2155       __ ba_short(L_bad_array_klass);
2156       __ BIND(L_ok_array_klass);
2157 
2158       // Check length.
2159       if (length_constant >= 0) {
2160         __ ldsw(Address(O1_array, length_offset), O4_scratch);
2161         __ cmp(O4_scratch, length_constant);
2162       } else {
2163         Register O3_vminfo = O3_scratch;
2164         load_conversion_vminfo(_masm, G3_amh_conversion, O3_vminfo);
2165         __ ldsw(Address(O1_array, length_offset), O4_scratch);
2166         __ cmp(O3_vminfo, O4_scratch);
2167       }
2168       __ br(Assembler::notEqual, false, Assembler::pn, L_bad_array_length);
2169       __ delayed()->nop();
2170 
2171       Register O2_argslot_limit = O2_scratch;
2172 
2173       // Array length checks out.  Now insert any required stack slots.
2174       if (length_constant == -1) {
2175         // Form a pointer to the end of the affected region.
2176         __ add(O0_argslot, Interpreter::stackElementSize, O2_argslot_limit);
2177         // 'stack_move' is negative number of words to insert
2178         // This number already accounts for elem_slots.
2179         Register O3_stack_move = O3_scratch;
2180         load_stack_move(_masm, G3_amh_conversion, O3_stack_move);
2181         __ cmp(O3_stack_move, 0);
2182         assert(stack_move_unit() < 0, "else change this comparison");
2183         __ br(Assembler::less, false, Assembler::pn, L_insert_arg_space);
2184         __ delayed()->nop();
2185         __ br(Assembler::equal, false, Assembler::pn, L_copy_args);
2186         __ delayed()->nop();
2187         // single argument case, with no array movement
2188         __ BIND(L_array_is_empty);
2189         remove_arg_slots(_masm, -stack_move_unit() * array_slots,
2190                          O0_argslot, O1_scratch, O2_scratch, O3_scratch);
2191         __ ba_short(L_args_done);  // no spreading to do
2192         __ BIND(L_insert_arg_space);
2193         // come here in the usual case, stack_move < 0 (2 or more spread arguments)
2194         // Live: O1_array, O2_argslot_limit, O3_stack_move
2195         insert_arg_slots(_masm, O3_stack_move,
2196                          O0_argslot, O4_scratch, G5_scratch, O1_scratch);
2197         // reload from rdx_argslot_limit since rax_argslot is now decremented
2198         __ ld_ptr(Address(O2_argslot_limit, -Interpreter::stackElementSize), O1_array);
2199       } else if (length_constant >= 1) {
2200         int new_slots = (length_constant * elem_slots) - array_slots;
2201         insert_arg_slots(_masm, new_slots * stack_move_unit(),
2202                          O0_argslot, O2_scratch, O3_scratch, O4_scratch);
2203       } else if (length_constant == 0) {
2204         __ BIND(L_array_is_empty);
2205         remove_arg_slots(_masm, -stack_move_unit() * array_slots,
2206                          O0_argslot, O1_scratch, O2_scratch, O3_scratch);
2207       } else {
2208         ShouldNotReachHere();
2209       }
2210 
2211       // Copy from the array to the new slots.
2212       // Note: Stack change code preserves integrity of O0_argslot pointer.
2213       // So even after slot insertions, O0_argslot still points to first argument.
2214       // Beware:  Arguments that are shallow on the stack are deep in the array,
2215       // and vice versa.  So a downward-growing stack (the usual) has to be copied
2216       // elementwise in reverse order from the source array.
2217       __ BIND(L_copy_args);
2218       if (length_constant == -1) {
2219         // [O0_argslot, O2_argslot_limit) is the area we are inserting into.
2220         // Array element [0] goes at O0_argslot_limit[-wordSize].
2221         Register O1_source = O1_array;
2222         __ add(Address(O1_array, elem0_offset), O1_source);
2223         Register O4_fill_ptr = O4_scratch;
2224         __ mov(O2_argslot_limit, O4_fill_ptr);
2225         Label L_loop;
2226         __ BIND(L_loop);
2227         __ add(O4_fill_ptr, -Interpreter::stackElementSize * elem_slots, O4_fill_ptr);
2228         move_typed_arg(_masm, elem_type, true,
2229                        Address(O1_source, 0), Address(O4_fill_ptr, 0),
2230                        O2_scratch);  // must be an even register for !_LP64 long moves (uses O2/O3)
2231         __ add(O1_source, type2aelembytes(elem_type), O1_source);
2232         __ cmp_and_brx_short(O4_fill_ptr, O0_argslot, Assembler::greaterUnsigned, Assembler::pt, L_loop);
2233       } else if (length_constant == 0) {
2234         // nothing to copy
2235       } else {
2236         int elem_offset = elem0_offset;
2237         int slot_offset = length_constant * Interpreter::stackElementSize;
2238         for (int index = 0; index < length_constant; index++) {
2239           slot_offset -= Interpreter::stackElementSize * elem_slots;  // fill backward
2240           move_typed_arg(_masm, elem_type, true,
2241                          Address(O1_array, elem_offset), Address(O0_argslot, slot_offset),
2242                          O2_scratch);  // must be an even register for !_LP64 long moves (uses O2/O3)
2243           elem_offset += type2aelembytes(elem_type);
2244         }
2245       }
2246       __ BIND(L_args_done);
2247 
2248       // Arguments are spread.  Move to next method handle.
2249       __ load_heap_oop(G3_mh_vmtarget, G3_method_handle);
2250       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
2251 
2252       __ BIND(L_bad_array_klass);


src/cpu/sparc/vm/methodHandles_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File