Print this page
rev 1025 : imported patch indy.compiler.patch

Split Close
Expand all
Collapse all
          --- old/src/cpu/x86/vm/x86_64.ad
          +++ new/src/cpu/x86/vm/x86_64.ad
↓ open down ↓ 543 lines elided ↑ open up ↑
 544  544  
 545  545  //----------SOURCE BLOCK-------------------------------------------------------
 546  546  // This is a block of C++ code which provides values, functions, and
 547  547  // definitions necessary in the rest of the architecture description
 548  548  source %{
 549  549  #define   RELOC_IMM64    Assembler::imm_operand
 550  550  #define   RELOC_DISP32   Assembler::disp32_operand
 551  551  
 552  552  #define __ _masm.
 553  553  
      554 +static int preserve_SP_size() {
      555 +  return LP64_ONLY(1 +) 2;  // [rex,] op, rm(reg/reg)
      556 +}
      557 +
 554  558  // !!!!! Special hack to get all types of calls to specify the byte offset
 555  559  //       from the start of the call to the point where the return address
 556  560  //       will point.
 557  561  int MachCallStaticJavaNode::ret_addr_offset()
 558  562  {
 559      -  return 5; // 5 bytes from start of call to where return address points
      563 +  int offset = 5; // 5 bytes from start of call to where return address points
      564 +  if (_method_handle_invoke)
      565 +    offset += preserve_SP_size();
      566 +  return offset;
 560  567  }
 561  568  
 562  569  int MachCallDynamicJavaNode::ret_addr_offset()
 563  570  {
 564  571    return 15; // 15 bytes from start of call to where return address points
 565  572  }
 566  573  
 567  574  // In os_cpu .ad file
 568  575  // int MachCallRuntimeNode::ret_addr_offset()
 569  576  
↓ open down ↓ 12 lines elided ↑ open up ↑
 582  589  // The address of the call instruction needs to be 4-byte aligned to
 583  590  // ensure that it does not span a cache line so that it can be patched.
 584  591  int CallStaticJavaDirectNode::compute_padding(int current_offset) const
 585  592  {
 586  593    current_offset += 1; // skip call opcode byte
 587  594    return round_to(current_offset, alignment_required()) - current_offset;
 588  595  }
 589  596  
 590  597  // The address of the call instruction needs to be 4-byte aligned to
 591  598  // ensure that it does not span a cache line so that it can be patched.
      599 +int CallStaticJavaHandleNode::compute_padding(int current_offset) const
      600 +{
      601 +  current_offset += preserve_SP_size();   // skip mov rbp, rsp
      602 +  current_offset += 1; // skip call opcode byte
      603 +  return round_to(current_offset, alignment_required()) - current_offset;
      604 +}
      605 +
      606 +// The address of the call instruction needs to be 4-byte aligned to
      607 +// ensure that it does not span a cache line so that it can be patched.
 592  608  int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
 593  609  {
 594  610    current_offset += 11; // skip movq instruction + call opcode byte
 595  611    return round_to(current_offset, alignment_required()) - current_offset;
 596  612  }
 597  613  
 598  614  #ifndef PRODUCT
 599  615  void MachBreakpointNode::format(PhaseRegAlloc*, outputStream* st) const
 600  616  {
 601  617    st->print("INT3");
↓ open down ↓ 1504 lines elided ↑ open up ↑
2106 2122  // Register for DIVL projection of divmodL
2107 2123  RegMask Matcher::divL_proj_mask() {
2108 2124    return LONG_RAX_REG_mask;
2109 2125  }
2110 2126  
2111 2127  // Register for MODL projection of divmodL
2112 2128  RegMask Matcher::modL_proj_mask() {
2113 2129    return LONG_RDX_REG_mask;
2114 2130  }
2115 2131  
     2132 +const RegMask Matcher::method_handle_invoke_SP_save_mask() {
     2133 +  return PTR_RBP_REG_mask;
     2134 +}
     2135 +
2116 2136  static Address build_address(int b, int i, int s, int d) {
2117 2137    Register index = as_Register(i);
2118 2138    Address::ScaleFactor scale = (Address::ScaleFactor)s;
2119 2139    if (index == rsp) {
2120 2140      index = noreg;
2121 2141      scale = Address::no_scale;
2122 2142    }
2123 2143    Address addr(as_Register(b), index, scale, d);
2124 2144    return addr;
2125 2145  }
↓ open down ↓ 475 lines elided ↑ open up ↑
2601 2621      // This is the instruction starting address for relocation info.
2602 2622      cbuf.set_inst_mark();
2603 2623      $$$emit8$primary;
2604 2624      // CALL directly to the runtime
2605 2625      emit_d32_reloc(cbuf,
2606 2626                     (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
2607 2627                     runtime_call_Relocation::spec(),
2608 2628                     RELOC_DISP32);
2609 2629    %}
2610 2630  
     2631 +  enc_class preserve_SP %{
     2632 +    debug_only(int off0 = cbuf.code_size());
     2633 +    MacroAssembler _masm(&cbuf);
     2634 +    // RBP is preserved across all calls, even compiled calls.
     2635 +    // Use it to preserve RSP in places where the callee might change the SP.
     2636 +    __ movptr(rbp, rsp);
     2637 +    debug_only(int off1 = cbuf.code_size());
     2638 +    assert(off1 - off0 == preserve_SP_size(), "correct size prediction");
     2639 +  %}
     2640 +
     2641 +  enc_class restore_SP %{
     2642 +    MacroAssembler _masm(&cbuf);
     2643 +    __ movptr(rsp, rbp);
     2644 +  %}
     2645 +
2611 2646    enc_class Java_Static_Call(method meth)
2612 2647    %{
2613 2648      // JAVA STATIC CALL
2614 2649      // CALL to fixup routine.  Fixup routine uses ScopeDesc info to
2615 2650      // determine who we intended to call.
2616 2651      cbuf.set_inst_mark();
2617 2652      $$$emit8$primary;
2618 2653  
2619 2654      if (!_method) {
2620 2655        emit_d32_reloc(cbuf,
↓ open down ↓ 9898 lines elided ↑ open up ↑
12519 12554    ins_cost(125);
12520 12555    ins_encode(enc_safepoint_poll);
12521 12556    ins_pipe(ialu_reg_mem);
12522 12557  %}
12523 12558  
12524 12559  // ============================================================================
12525 12560  // Procedure Call/Return Instructions
12526 12561  // Call Java Static Instruction
12527 12562  // Note: If this code changes, the corresponding ret_addr_offset() and
12528 12563  //       compute_padding() functions will have to be adjusted.
12529      -instruct CallStaticJavaDirect(method meth)
12530      -%{
     12564 +instruct CallStaticJavaDirect(method meth) %{
12531 12565    match(CallStaticJava);
     12566 +  predicate(!((CallStaticJavaNode*) n)->is_method_handle_invoke());
12532 12567    effect(USE meth);
12533 12568  
12534 12569    ins_cost(300);
12535 12570    format %{ "call,static " %}
12536 12571    opcode(0xE8); /* E8 cd */
12537 12572    ins_encode(Java_Static_Call(meth), call_epilog);
12538 12573    ins_pipe(pipe_slow);
12539 12574    ins_pc_relative(1);
12540 12575    ins_alignment(4);
12541 12576  %}
12542 12577  
     12578 +// Call Java Static Instruction (method handle version)
     12579 +// Note: If this code changes, the corresponding ret_addr_offset() and
     12580 +//       compute_padding() functions will have to be adjusted.
     12581 +instruct CallStaticJavaHandle(method meth, rbp_RegP rbp) %{
     12582 +  match(CallStaticJava);
     12583 +  predicate(((CallStaticJavaNode*) n)->is_method_handle_invoke());
     12584 +  effect(USE meth);
     12585 +  // RBP is saved by all callees (for interpreter stack correction).
     12586 +  // We use it here for a similar purpose, in {preserve,restore}_SP.
     12587 +
     12588 +  ins_cost(300);
     12589 +  format %{ "call,static/MethodHandle " %}
     12590 +  opcode(0xE8); /* E8 cd */
     12591 +  ins_encode(preserve_SP,
     12592 +             Java_Static_Call(meth),
     12593 +             restore_SP,
     12594 +             call_epilog);
     12595 +  ins_pipe(pipe_slow);
     12596 +  ins_pc_relative(1);
     12597 +  ins_alignment(4);
     12598 +%}
     12599 +
12543 12600  // Call Java Dynamic Instruction
12544 12601  // Note: If this code changes, the corresponding ret_addr_offset() and
12545 12602  //       compute_padding() functions will have to be adjusted.
12546 12603  instruct CallDynamicJavaDirect(method meth)
12547 12604  %{
12548 12605    match(CallDynamicJava);
12549 12606    effect(USE meth);
12550 12607  
12551 12608    ins_cost(300);
12552 12609    format %{ "movq    rax, #Universe::non_oop_word()\n\t"
↓ open down ↓ 261 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX