src/cpu/x86/vm/x86_64.ad
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/cpu/x86/vm

src/cpu/x86/vm/x86_64.ad

Print this page
rev 6132 : 8032410: compiler/uncommontrap/TestStackBangRbp.java times out on Solaris-Sparc V9
Summary: make compiled code bang the stack by the worst case size of the interpreter frame at deoptimization points.
Reviewed-by:


 696 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
 697   // Empty encoding
 698 }
 699 
 700 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
 701   return 0;
 702 }
 703 
 704 #ifndef PRODUCT
 705 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 706   st->print("# MachConstantBaseNode (empty encoding)");
 707 }
 708 #endif
 709 
 710 
 711 //=============================================================================
 712 #ifndef PRODUCT
 713 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 714   Compile* C = ra_->C;
 715 
 716   int framesize = C->frame_slots() << LogBytesPerInt;

 717   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 718   // Remove wordSize for return addr which is already pushed.
 719   framesize -= wordSize;
 720 
 721   if (C->need_stack_bang(framesize)) {
 722     framesize -= wordSize;
 723     st->print("# stack bang");
 724     st->print("\n\t");
 725     st->print("pushq   rbp\t# Save rbp");
 726     if (framesize) {
 727       st->print("\n\t");
 728       st->print("subq    rsp, #%d\t# Create frame",framesize);
 729     }
 730   } else {
 731     st->print("subq    rsp, #%d\t# Create frame",framesize);
 732     st->print("\n\t");
 733     framesize -= wordSize;
 734     st->print("movq    [rsp + #%d], rbp\t# Save rbp",framesize);
 735   }
 736 
 737   if (VerifyStackAtCalls) {
 738     st->print("\n\t");
 739     framesize -= wordSize;
 740     st->print("movq    [rsp + #%d], 0xbadb100d\t# Majik cookie for stack depth check",framesize);
 741 #ifdef ASSERT
 742     st->print("\n\t");
 743     st->print("# stack alignment check");
 744 #endif
 745   }
 746   st->cr();
 747 }
 748 #endif
 749 
 750 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 751   Compile* C = ra_->C;
 752   MacroAssembler _masm(&cbuf);
 753 
 754   int framesize = C->frame_slots() << LogBytesPerInt;

 755 
 756   __ verified_entry(framesize, C->need_stack_bang(framesize), false);
 757 
 758   C->set_frame_complete(cbuf.insts_size());
 759 
 760   if (C->has_mach_constant_base_node()) {
 761     // NOTE: We set the table base offset here because users might be
 762     // emitted before MachConstantBaseNode.
 763     Compile::ConstantTable& constant_table = C->constant_table();
 764     constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
 765   }
 766 }
 767 
 768 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
 769 {
 770   return MachNode::size(ra_); // too many variables; just compute it
 771                               // the hard way
 772 }
 773 
 774 int MachPrologNode::reloc() const
 775 {
 776   return 0; // a large enough number
 777 }
 778 
 779 //=============================================================================
 780 #ifndef PRODUCT
 781 void MachEpilogNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 782 {
 783   Compile* C = ra_->C;
 784   if (C->max_vector_size() > 16) {
 785     st->print("vzeroupper");
 786     st->cr(); st->print("\t");
 787   }
 788 
 789   int framesize = C->frame_slots() << LogBytesPerInt;
 790   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 791   // Remove word for return adr already pushed
 792   // and RBP
 793   framesize -= 2*wordSize;
 794 
 795   if (framesize) {
 796     st->print_cr("addq    rsp, %d\t# Destroy frame", framesize);
 797     st->print("\t");
 798   }
 799 
 800   st->print_cr("popq   rbp");
 801   if (do_polling() && C->is_method_compilation()) {
 802     st->print("\t");
 803     if (Assembler::is_polling_page_far()) {
 804       st->print_cr("movq   rscratch1, #polling_page_address\n\t"
 805                    "testl  rax, [rscratch1]\t"
 806                    "# Safepoint: poll for GC");
 807     } else {
 808       st->print_cr("testl  rax, [rip + #offset_to_poll_page]\t"
 809                    "# Safepoint: poll for GC");
 810     }
 811   }
 812 }
 813 #endif
 814 
 815 void MachEpilogNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
 816 {
 817   Compile* C = ra_->C;
 818   if (C->max_vector_size() > 16) {
 819     // Clear upper bits of YMM registers when current compiled code uses
 820     // wide vectors to avoid AVX <-> SSE transition penalty during call.
 821     MacroAssembler _masm(&cbuf);
 822     __ vzeroupper();
 823   }
 824 
 825   int framesize = C->frame_slots() << LogBytesPerInt;
 826   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 827   // Remove word for return adr already pushed
 828   // and RBP
 829   framesize -= 2*wordSize;
 830 
 831   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
 832 
 833   if (framesize) {
 834     emit_opcode(cbuf, Assembler::REX_W);
 835     if (framesize < 0x80) {
 836       emit_opcode(cbuf, 0x83); // addq rsp, #framesize
 837       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
 838       emit_d8(cbuf, framesize);
 839     } else {
 840       emit_opcode(cbuf, 0x81); // addq rsp, #framesize
 841       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
 842       emit_d32(cbuf, framesize);
 843     }
 844   }
 845 




 696 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
 697   // Empty encoding
 698 }
 699 
 700 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
 701   return 0;
 702 }
 703 
 704 #ifndef PRODUCT
 705 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 706   st->print("# MachConstantBaseNode (empty encoding)");
 707 }
 708 #endif
 709 
 710 
 711 //=============================================================================
 712 #ifndef PRODUCT
 713 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 714   Compile* C = ra_->C;
 715 
 716   int framesize = C->frame_size_in_bytes();
 717   int bangsize = C->bang_size_in_bytes();
 718   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 719   // Remove wordSize for return addr which is already pushed.
 720   framesize -= wordSize;
 721 
 722   if (C->need_stack_bang(bangsize)) {
 723     framesize -= wordSize;
 724     st->print("# stack bang (%d bytes)", bangsize);
 725     st->print("\n\t");
 726     st->print("pushq   rbp\t# Save rbp");
 727     if (framesize) {
 728       st->print("\n\t");
 729       st->print("subq    rsp, #%d\t# Create frame",framesize);
 730     }
 731   } else {
 732     st->print("subq    rsp, #%d\t# Create frame",framesize);
 733     st->print("\n\t");
 734     framesize -= wordSize;
 735     st->print("movq    [rsp + #%d], rbp\t# Save rbp",framesize);
 736   }
 737 
 738   if (VerifyStackAtCalls) {
 739     st->print("\n\t");
 740     framesize -= wordSize;
 741     st->print("movq    [rsp + #%d], 0xbadb100d\t# Majik cookie for stack depth check",framesize);
 742 #ifdef ASSERT
 743     st->print("\n\t");
 744     st->print("# stack alignment check");
 745 #endif
 746   }
 747   st->cr();
 748 }
 749 #endif
 750 
 751 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 752   Compile* C = ra_->C;
 753   MacroAssembler _masm(&cbuf);
 754 
 755   int framesize = C->frame_size_in_bytes();
 756   int bangsize = C->bang_size_in_bytes();
 757 
 758   __ verified_entry(framesize, C->need_stack_bang(bangsize)?bangsize:0, false);
 759 
 760   C->set_frame_complete(cbuf.insts_size());
 761 
 762   if (C->has_mach_constant_base_node()) {
 763     // NOTE: We set the table base offset here because users might be
 764     // emitted before MachConstantBaseNode.
 765     Compile::ConstantTable& constant_table = C->constant_table();
 766     constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
 767   }
 768 }
 769 
 770 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
 771 {
 772   return MachNode::size(ra_); // too many variables; just compute it
 773                               // the hard way
 774 }
 775 
 776 int MachPrologNode::reloc() const
 777 {
 778   return 0; // a large enough number
 779 }
 780 
 781 //=============================================================================
 782 #ifndef PRODUCT
 783 void MachEpilogNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 784 {
 785   Compile* C = ra_->C;
 786   if (C->max_vector_size() > 16) {
 787     st->print("vzeroupper");
 788     st->cr(); st->print("\t");
 789   }
 790 
 791   int framesize = C->frame_size_in_bytes();
 792   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 793   // Remove word for return adr already pushed
 794   // and RBP
 795   framesize -= 2*wordSize;
 796 
 797   if (framesize) {
 798     st->print_cr("addq    rsp, %d\t# Destroy frame", framesize);
 799     st->print("\t");
 800   }
 801 
 802   st->print_cr("popq   rbp");
 803   if (do_polling() && C->is_method_compilation()) {
 804     st->print("\t");
 805     if (Assembler::is_polling_page_far()) {
 806       st->print_cr("movq   rscratch1, #polling_page_address\n\t"
 807                    "testl  rax, [rscratch1]\t"
 808                    "# Safepoint: poll for GC");
 809     } else {
 810       st->print_cr("testl  rax, [rip + #offset_to_poll_page]\t"
 811                    "# Safepoint: poll for GC");
 812     }
 813   }
 814 }
 815 #endif
 816 
 817 void MachEpilogNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
 818 {
 819   Compile* C = ra_->C;
 820   if (C->max_vector_size() > 16) {
 821     // Clear upper bits of YMM registers when current compiled code uses
 822     // wide vectors to avoid AVX <-> SSE transition penalty during call.
 823     MacroAssembler _masm(&cbuf);
 824     __ vzeroupper();
 825   }
 826 
 827   int framesize = C->frame_size_in_bytes();
 828   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 829   // Remove word for return adr already pushed
 830   // and RBP
 831   framesize -= 2*wordSize;
 832 
 833   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
 834 
 835   if (framesize) {
 836     emit_opcode(cbuf, Assembler::REX_W);
 837     if (framesize < 0x80) {
 838       emit_opcode(cbuf, 0x83); // addq rsp, #framesize
 839       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
 840       emit_d8(cbuf, framesize);
 841     } else {
 842       emit_opcode(cbuf, 0x81); // addq rsp, #framesize
 843       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
 844       emit_d32(cbuf, framesize);
 845     }
 846   }
 847 


src/cpu/x86/vm/x86_64.ad
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File