1637
1638 int MachCallDynamicJavaNode::ret_addr_offset()
1639 {
1640 return 16; // movz, movk, movk, bl
1641 }
1642
1643 int MachCallRuntimeNode::ret_addr_offset() {
1644 // for generated stubs the call will be
1645 // bl(addr)
1646 // or with far branches
1647 // bl(trampoline_stub)
1648 // for real runtime callouts it will be six instructions
1649 // see aarch64_enc_java_to_runtime
1650 // adr(rscratch2, retaddr)
1651 // lea(rscratch1, RuntimeAddress(addr)
1652 // stp(zr, rscratch2, Address(__ pre(sp, -2 * wordSize)))
1653 // blr(rscratch1)
1654 CodeBlob *cb = CodeCache::find_blob(_entry_point);
1655 if (cb) {
1656 return 1 * NativeInstruction::instruction_size;
1657 } else {
1658 return 6 * NativeInstruction::instruction_size;
1659 }
1660 }
1661
1662 //=============================================================================
1663
1664 #ifndef PRODUCT
1665 void MachBreakpointNode::format(PhaseRegAlloc *ra_, outputStream *st) const {
1666 st->print("BREAKPOINT");
1667 }
1668 #endif
1669
1670 void MachBreakpointNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1671 __ brk(0);
1672 }
1673
1674 uint MachBreakpointNode::size(PhaseRegAlloc *ra_) const {
1675 return MachNode::size(ra_);
1676 }
1745 if (C->stub_function() == nullptr && BarrierSet::barrier_set()->barrier_set_nmethod() != nullptr) {
1746 st->print("\n\t");
1747 st->print("ldr rscratch1, [guard]\n\t");
1748 st->print("dmb ishld\n\t");
1749 st->print("ldr rscratch2, [rthread, #thread_disarmed_guard_value_offset]\n\t");
1750 st->print("cmp rscratch1, rscratch2\n\t");
1751 st->print("b.eq skip");
1752 st->print("\n\t");
1753 st->print("blr #nmethod_entry_barrier_stub\n\t");
1754 st->print("b skip\n\t");
1755 st->print("guard: int\n\t");
1756 st->print("\n\t");
1757 st->print("skip:\n\t");
1758 }
1759 }
1760 #endif
1761
1762 void MachPrologNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1763 Compile* C = ra_->C;
1764
1765 // n.b. frame size includes space for return pc and rfp
1766 const int framesize = C->output()->frame_size_in_bytes();
1767
1768 // insert a nop at the start of the prolog so we can patch in a
1769 // branch if we need to invalidate the method later
1770 __ nop();
1771
1772 if (C->clinit_barrier_on_entry()) {
1773 assert(!C->method()->holder()->is_not_initialized(), "initialization should have been started");
1774
1775 Label L_skip_barrier;
1776
1777 __ mov_metadata(rscratch2, C->method()->holder()->constant_encoding());
1778 __ clinit_barrier(rscratch2, rscratch1, &L_skip_barrier);
1779 __ far_jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub()));
1780 __ bind(L_skip_barrier);
1781 }
1782
1783 if (C->max_vector_size() > 0) {
1784 __ reinitialize_ptrue();
1785 }
1786
1787 int bangsize = C->output()->bang_size_in_bytes();
1788 if (C->output()->need_stack_bang(bangsize))
1789 __ generate_stack_overflow_check(bangsize);
1790
1791 __ build_frame(framesize);
1792
1793 if (C->stub_function() == nullptr) {
1794 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
1795 if (BarrierSet::barrier_set()->barrier_set_nmethod() != nullptr) {
1796 // Dummy labels for just measuring the code size
1797 Label dummy_slow_path;
1798 Label dummy_continuation;
1799 Label dummy_guard;
1800 Label* slow_path = &dummy_slow_path;
1801 Label* continuation = &dummy_continuation;
1802 Label* guard = &dummy_guard;
1803 if (!Compile::current()->output()->in_scratch_emit_size()) {
1804 // Use real labels from actual stub when not emitting code for the purpose of measuring its size
1805 C2EntryBarrierStub* stub = new (Compile::current()->comp_arena()) C2EntryBarrierStub();
1806 Compile::current()->output()->add_stub(stub);
1807 slow_path = &stub->entry();
1808 continuation = &stub->continuation();
1809 guard = &stub->guard();
1810 }
1811 // In the C2 code, we move the non-hot part of nmethod entry barriers out-of-line to a stub.
1812 bs->nmethod_entry_barrier(masm, slow_path, continuation, guard);
1813 }
1814 }
1815
1816 if (VerifyStackAtCalls) {
1817 Unimplemented();
1818 }
1819
1820 C->output()->set_frame_complete(__ offset());
1821
1822 if (C->has_mach_constant_base_node()) {
1823 // NOTE: We set the table base offset here because users might be
1824 // emitted before MachConstantBaseNode.
1825 ConstantTable& constant_table = C->output()->constant_table();
1826 constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
1827 }
1828 }
1829
1830 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
1831 {
1832 return MachNode::size(ra_); // too many variables; just compute it
1833 // the hard way
1834 }
1835
1836 int MachPrologNode::reloc() const
1837 {
1838 return 0;
1839 }
1840
1841 //=============================================================================
1842
1843 #ifndef PRODUCT
1844 void MachEpilogNode::format(PhaseRegAlloc *ra_, outputStream *st) const {
1845 Compile* C = ra_->C;
1846 int framesize = C->output()->frame_slots() << LogBytesPerInt;
1847
1848 st->print("# pop frame %d\n\t",framesize);
1849
1850 if (framesize == 0) {
1851 st->print("ldp lr, rfp, [sp],#%d\n\t", (2 * wordSize));
1852 } else if (framesize < ((1 << 9) + 2 * wordSize)) {
1853 st->print("ldp lr, rfp, [sp,#%d]\n\t", framesize - 2 * wordSize);
1854 st->print("add sp, sp, #%d\n\t", framesize);
1855 } else {
1858 st->print("ldp lr, rfp, [sp],#%d\n\t", (2 * wordSize));
1859 }
1860 if (VM_Version::use_rop_protection()) {
1861 st->print("autiaz\n\t");
1862 st->print("ldr zr, [lr]\n\t");
1863 }
1864
1865 if (do_polling() && C->is_method_compilation()) {
1866 st->print("# test polling word\n\t");
1867 st->print("ldr rscratch1, [rthread],#%d\n\t", in_bytes(JavaThread::polling_word_offset()));
1868 st->print("cmp sp, rscratch1\n\t");
1869 st->print("bhi #slow_path");
1870 }
1871 }
1872 #endif
1873
1874 void MachEpilogNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1875 Compile* C = ra_->C;
1876 int framesize = C->output()->frame_slots() << LogBytesPerInt;
1877
1878 __ remove_frame(framesize);
1879
1880 if (StackReservedPages > 0 && C->has_reserved_stack_access()) {
1881 __ reserved_stack_check();
1882 }
1883
1884 if (do_polling() && C->is_method_compilation()) {
1885 Label dummy_label;
1886 Label* code_stub = &dummy_label;
1887 if (!C->output()->in_scratch_emit_size()) {
1888 C2SafepointPollStub* stub = new (C->comp_arena()) C2SafepointPollStub(__ offset());
1889 C->output()->add_stub(stub);
1890 code_stub = &stub->entry();
1891 }
1892 __ relocate(relocInfo::poll_return_type);
1893 __ safepoint_poll(*code_stub, true /* at_return */, false /* acquire */, true /* in_nmethod */);
1894 }
1895 }
1896
1897 uint MachEpilogNode::size(PhaseRegAlloc *ra_) const {
1898 // Variable size. Determine dynamically.
1899 return MachNode::size(ra_);
1900 }
1901
1902 int MachEpilogNode::reloc() const {
1903 // Return number of relocatable values contained in this instruction.
1904 return 1; // 1 for polling page.
1905 }
1906
1907 const Pipeline * MachEpilogNode::pipeline() const {
1908 return MachNode::pipeline_class();
1909 }
1910
1911 //=============================================================================
1912
1913 static enum RC rc_class(OptoReg::Name reg) {
1914
1915 if (reg == OptoReg::Bad) {
1916 return rc_bad;
1917 }
1918
1919 // we have 32 int registers * 2 halves
1920 int slots_of_int_registers = Register::number_of_registers * Register::max_slots_per_register;
1921
2177 void BoxLockNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
2178 int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
2179 int reg = ra_->get_encode(this);
2180
2181 // This add will handle any 24-bit signed offset. 24 bits allows an
2182 // 8 megabyte stack frame.
2183 __ add(as_Register(reg), sp, offset);
2184 }
2185
2186 uint BoxLockNode::size(PhaseRegAlloc *ra_) const {
2187 // BoxLockNode is not a MachNode, so we can't just call MachNode::size(ra_).
2188 int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
2189
2190 if (Assembler::operand_valid_for_add_sub_immediate(offset)) {
2191 return NativeInstruction::instruction_size;
2192 } else {
2193 return 2 * NativeInstruction::instruction_size;
2194 }
2195 }
2196
2197 //=============================================================================
2198
2199 #ifndef PRODUCT
2200 void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
2201 {
2202 st->print_cr("# MachUEPNode");
2203 if (UseCompressedClassPointers) {
2204 st->print_cr("\tldrw rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
2205 st->print_cr("\tldrw r10, [rscratch2 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
2206 st->print_cr("\tcmpw rscratch1, r10");
2207 } else {
2208 st->print_cr("\tldr rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
2209 st->print_cr("\tldr r10, [rscratch2 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
2210 st->print_cr("\tcmp rscratch1, r10");
2211 }
2212 st->print_cr("\tbne, SharedRuntime::_ic_miss_stub");
2213 }
2214 #endif
2215
2216 void MachUEPNode::emit(C2_MacroAssembler* masm, PhaseRegAlloc* ra_) const
2217 {
2218 __ ic_check(InteriorEntryAlignment);
2219 }
2220
2221 uint MachUEPNode::size(PhaseRegAlloc* ra_) const
2222 {
2223 return MachNode::size(ra_);
2224 }
2225
2226 // REQUIRED EMIT CODE
2227
2228 //=============================================================================
2229
2230 // Emit exception handler code.
2231 int HandlerImpl::emit_exception_handler(C2_MacroAssembler* masm)
2232 {
2233 // mov rscratch1 #exception_blob_entry_point
2234 // br rscratch1
2235 // Note that the code buffer's insts_mark is always relative to insts.
2236 // That's why we must use the macroassembler to generate a handler.
2237 address base = __ start_a_stub(size_exception_handler());
2238 if (base == nullptr) {
2239 ciEnv::current()->record_failure("CodeCache is full");
2240 return 0; // CodeBuffer::expand failed
2241 }
2242 int offset = __ offset();
2243 __ far_jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
2244 assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
2245 __ end_a_stub();
3661 %}
3662
3663 enc_class aarch64_enc_java_dynamic_call(method meth) %{
3664 int method_index = resolved_method_index(masm);
3665 address call = __ ic_call((address)$meth$$method, method_index);
3666 if (call == nullptr) {
3667 ciEnv::current()->record_failure("CodeCache is full");
3668 return;
3669 }
3670 __ post_call_nop();
3671 if (Compile::current()->max_vector_size() > 0) {
3672 __ reinitialize_ptrue();
3673 }
3674 %}
3675
3676 enc_class aarch64_enc_call_epilog() %{
3677 if (VerifyStackAtCalls) {
3678 // Check that stack depth is unchanged: find majik cookie on stack
3679 __ call_Unimplemented();
3680 }
3681 %}
3682
3683 enc_class aarch64_enc_java_to_runtime(method meth) %{
3684 // some calls to generated routines (arraycopy code) are scheduled
3685 // by C2 as runtime calls. if so we can call them using a br (they
3686 // will be in a reachable segment) otherwise we have to use a blr
3687 // which loads the absolute address into a register.
3688 address entry = (address)$meth$$method;
3689 CodeBlob *cb = CodeCache::find_blob(entry);
3690 if (cb) {
3691 address call = __ trampoline_call(Address(entry, relocInfo::runtime_call_type));
3692 if (call == nullptr) {
3693 ciEnv::current()->record_failure("CodeCache is full");
3694 return;
3695 }
3696 __ post_call_nop();
3697 } else {
3698 Label retaddr;
3699 __ adr(rscratch2, retaddr);
3700 __ lea(rscratch1, RuntimeAddress(entry));
6738 instruct loadConL(iRegLNoSp dst, immL src)
6739 %{
6740 match(Set dst src);
6741
6742 ins_cost(INSN_COST);
6743 format %{ "mov $dst, $src\t# long" %}
6744
6745 ins_encode( aarch64_enc_mov_imm(dst, src) );
6746
6747 ins_pipe(ialu_imm);
6748 %}
6749
6750 // Load Pointer Constant
6751
6752 instruct loadConP(iRegPNoSp dst, immP con)
6753 %{
6754 match(Set dst con);
6755
6756 ins_cost(INSN_COST * 4);
6757 format %{
6758 "mov $dst, $con\t# ptr\n\t"
6759 %}
6760
6761 ins_encode(aarch64_enc_mov_p(dst, con));
6762
6763 ins_pipe(ialu_imm);
6764 %}
6765
6766 // Load Null Pointer Constant
6767
6768 instruct loadConP0(iRegPNoSp dst, immP0 con)
6769 %{
6770 match(Set dst con);
6771
6772 ins_cost(INSN_COST);
6773 format %{ "mov $dst, $con\t# nullptr ptr" %}
6774
6775 ins_encode(aarch64_enc_mov_p0(dst, con));
6776
6777 ins_pipe(ialu_imm);
6778 %}
7934 %}
7935
7936 // ============================================================================
7937 // Cast/Convert Instructions
7938
7939 instruct castX2P(iRegPNoSp dst, iRegL src) %{
7940 match(Set dst (CastX2P src));
7941
7942 ins_cost(INSN_COST);
7943 format %{ "mov $dst, $src\t# long -> ptr" %}
7944
7945 ins_encode %{
7946 if ($dst$$reg != $src$$reg) {
7947 __ mov(as_Register($dst$$reg), as_Register($src$$reg));
7948 }
7949 %}
7950
7951 ins_pipe(ialu_reg);
7952 %}
7953
7954 instruct castP2X(iRegLNoSp dst, iRegP src) %{
7955 match(Set dst (CastP2X src));
7956
7957 ins_cost(INSN_COST);
7958 format %{ "mov $dst, $src\t# ptr -> long" %}
7959
7960 ins_encode %{
7961 if ($dst$$reg != $src$$reg) {
7962 __ mov(as_Register($dst$$reg), as_Register($src$$reg));
7963 }
7964 %}
7965
7966 ins_pipe(ialu_reg);
7967 %}
7968
7969 // Convert oop into int for vectors alignment masking
7970 instruct convP2I(iRegINoSp dst, iRegP src) %{
7971 match(Set dst (ConvL2I (CastP2X src)));
7972
7973 ins_cost(INSN_COST);
14759
14760 match(Set dst (MoveL2D src));
14761
14762 effect(DEF dst, USE src);
14763
14764 ins_cost(INSN_COST);
14765
14766 format %{ "fmovd $dst, $src\t# MoveL2D_reg_reg" %}
14767
14768 ins_encode %{
14769 __ fmovd(as_FloatRegister($dst$$reg), $src$$Register);
14770 %}
14771
14772 ins_pipe(fp_l2d);
14773
14774 %}
14775
14776 // ============================================================================
14777 // clearing of an array
14778
14779 instruct clearArray_reg_reg(iRegL_R11 cnt, iRegP_R10 base, Universe dummy, rFlagsReg cr)
14780 %{
14781 match(Set dummy (ClearArray cnt base));
14782 effect(USE_KILL cnt, USE_KILL base, KILL cr);
14783
14784 ins_cost(4 * INSN_COST);
14785 format %{ "ClearArray $cnt, $base" %}
14786
14787 ins_encode %{
14788 address tpc = __ zero_words($base$$Register, $cnt$$Register);
14789 if (tpc == nullptr) {
14790 ciEnv::current()->record_failure("CodeCache is full");
14791 return;
14792 }
14793 %}
14794
14795 ins_pipe(pipe_class_memory);
14796 %}
14797
14798 instruct clearArray_imm_reg(immL cnt, iRegP_R10 base, iRegL_R11 temp, Universe dummy, rFlagsReg cr)
14799 %{
14800 predicate((uint64_t)n->in(2)->get_long()
14801 < (uint64_t)(BlockZeroingLowLimit >> LogBytesPerWord));
14802 match(Set dummy (ClearArray cnt base));
14803 effect(TEMP temp, USE_KILL base, KILL cr);
14804
14805 ins_cost(4 * INSN_COST);
14806 format %{ "ClearArray $cnt, $base" %}
14807
14808 ins_encode %{
14809 address tpc = __ zero_words($base$$Register, (uint64_t)$cnt$$constant);
14810 if (tpc == nullptr) {
14811 ciEnv::current()->record_failure("CodeCache is full");
14812 return;
14813 }
14814 %}
14815
14816 ins_pipe(pipe_class_memory);
14817 %}
14818
14819 // ============================================================================
14820 // Overflow Math Instructions
14821
16132 %}
16133
16134 // Call Runtime Instruction without safepoint and with vector arguments
16135 instruct CallLeafDirectVector(method meth)
16136 %{
16137 match(CallLeafVector);
16138
16139 effect(USE meth);
16140
16141 ins_cost(CALL_COST);
16142
16143 format %{ "CALL, runtime leaf vector $meth" %}
16144
16145 ins_encode(aarch64_enc_java_to_runtime(meth));
16146
16147 ins_pipe(pipe_class_call);
16148 %}
16149
16150 // Call Runtime Instruction
16151
16152 instruct CallLeafNoFPDirect(method meth)
16153 %{
16154 match(CallLeafNoFP);
16155
16156 effect(USE meth);
16157
16158 ins_cost(CALL_COST);
16159
16160 format %{ "CALL, runtime leaf nofp $meth" %}
16161
16162 ins_encode( aarch64_enc_java_to_runtime(meth) );
16163
16164 ins_pipe(pipe_class_call);
16165 %}
16166
16167 // Tail Call; Jump from runtime stub to Java code.
16168 // Also known as an 'interprocedural jump'.
16169 // Target of jump will eventually return to caller.
16170 // TailJump below removes the return address.
16171 // Don't use rfp for 'jump_target' because a MachEpilogNode has already been
16172 // emitted just above the TailCall which has reset rfp to the caller state.
16173 instruct TailCalljmpInd(iRegPNoSpNoRfp jump_target, inline_cache_RegP method_ptr)
|
1637
1638 int MachCallDynamicJavaNode::ret_addr_offset()
1639 {
1640 return 16; // movz, movk, movk, bl
1641 }
1642
1643 int MachCallRuntimeNode::ret_addr_offset() {
1644 // for generated stubs the call will be
1645 // bl(addr)
1646 // or with far branches
1647 // bl(trampoline_stub)
1648 // for real runtime callouts it will be six instructions
1649 // see aarch64_enc_java_to_runtime
1650 // adr(rscratch2, retaddr)
1651 // lea(rscratch1, RuntimeAddress(addr)
1652 // stp(zr, rscratch2, Address(__ pre(sp, -2 * wordSize)))
1653 // blr(rscratch1)
1654 CodeBlob *cb = CodeCache::find_blob(_entry_point);
1655 if (cb) {
1656 return 1 * NativeInstruction::instruction_size;
1657 } else if (_entry_point == nullptr) {
1658 // See CallLeafNoFPIndirect
1659 return 1 * NativeInstruction::instruction_size;
1660 } else {
1661 return 6 * NativeInstruction::instruction_size;
1662 }
1663 }
1664
1665 //=============================================================================
1666
1667 #ifndef PRODUCT
1668 void MachBreakpointNode::format(PhaseRegAlloc *ra_, outputStream *st) const {
1669 st->print("BREAKPOINT");
1670 }
1671 #endif
1672
1673 void MachBreakpointNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1674 __ brk(0);
1675 }
1676
1677 uint MachBreakpointNode::size(PhaseRegAlloc *ra_) const {
1678 return MachNode::size(ra_);
1679 }
1748 if (C->stub_function() == nullptr && BarrierSet::barrier_set()->barrier_set_nmethod() != nullptr) {
1749 st->print("\n\t");
1750 st->print("ldr rscratch1, [guard]\n\t");
1751 st->print("dmb ishld\n\t");
1752 st->print("ldr rscratch2, [rthread, #thread_disarmed_guard_value_offset]\n\t");
1753 st->print("cmp rscratch1, rscratch2\n\t");
1754 st->print("b.eq skip");
1755 st->print("\n\t");
1756 st->print("blr #nmethod_entry_barrier_stub\n\t");
1757 st->print("b skip\n\t");
1758 st->print("guard: int\n\t");
1759 st->print("\n\t");
1760 st->print("skip:\n\t");
1761 }
1762 }
1763 #endif
1764
1765 void MachPrologNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1766 Compile* C = ra_->C;
1767
1768 // insert a nop at the start of the prolog so we can patch in a
1769 // branch if we need to invalidate the method later
1770 __ nop();
1771
1772 __ verified_entry(C, 0);
1773
1774 if (C->stub_function() == nullptr) {
1775 __ entry_barrier();
1776 }
1777
1778 if (!Compile::current()->output()->in_scratch_emit_size()) {
1779 __ bind(*_verified_entry);
1780 }
1781
1782 if (VerifyStackAtCalls) {
1783 Unimplemented();
1784 }
1785
1786 C->output()->set_frame_complete(__ offset());
1787
1788 if (C->has_mach_constant_base_node()) {
1789 // NOTE: We set the table base offset here because users might be
1790 // emitted before MachConstantBaseNode.
1791 ConstantTable& constant_table = C->output()->constant_table();
1792 constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
1793 }
1794 }
1795
1796 int MachPrologNode::reloc() const
1797 {
1798 return 0;
1799 }
1800
1801 //=============================================================================
1802
1803 #ifndef PRODUCT
1804 void MachEpilogNode::format(PhaseRegAlloc *ra_, outputStream *st) const {
1805 Compile* C = ra_->C;
1806 int framesize = C->output()->frame_slots() << LogBytesPerInt;
1807
1808 st->print("# pop frame %d\n\t",framesize);
1809
1810 if (framesize == 0) {
1811 st->print("ldp lr, rfp, [sp],#%d\n\t", (2 * wordSize));
1812 } else if (framesize < ((1 << 9) + 2 * wordSize)) {
1813 st->print("ldp lr, rfp, [sp,#%d]\n\t", framesize - 2 * wordSize);
1814 st->print("add sp, sp, #%d\n\t", framesize);
1815 } else {
1818 st->print("ldp lr, rfp, [sp],#%d\n\t", (2 * wordSize));
1819 }
1820 if (VM_Version::use_rop_protection()) {
1821 st->print("autiaz\n\t");
1822 st->print("ldr zr, [lr]\n\t");
1823 }
1824
1825 if (do_polling() && C->is_method_compilation()) {
1826 st->print("# test polling word\n\t");
1827 st->print("ldr rscratch1, [rthread],#%d\n\t", in_bytes(JavaThread::polling_word_offset()));
1828 st->print("cmp sp, rscratch1\n\t");
1829 st->print("bhi #slow_path");
1830 }
1831 }
1832 #endif
1833
1834 void MachEpilogNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
1835 Compile* C = ra_->C;
1836 int framesize = C->output()->frame_slots() << LogBytesPerInt;
1837
1838 __ remove_frame(framesize, C->needs_stack_repair());
1839
1840 if (StackReservedPages > 0 && C->has_reserved_stack_access()) {
1841 __ reserved_stack_check();
1842 }
1843
1844 if (do_polling() && C->is_method_compilation()) {
1845 Label dummy_label;
1846 Label* code_stub = &dummy_label;
1847 if (!C->output()->in_scratch_emit_size()) {
1848 C2SafepointPollStub* stub = new (C->comp_arena()) C2SafepointPollStub(__ offset());
1849 C->output()->add_stub(stub);
1850 code_stub = &stub->entry();
1851 }
1852 __ relocate(relocInfo::poll_return_type);
1853 __ safepoint_poll(*code_stub, true /* at_return */, false /* acquire */, true /* in_nmethod */);
1854 }
1855 }
1856
1857 int MachEpilogNode::reloc() const {
1858 // Return number of relocatable values contained in this instruction.
1859 return 1; // 1 for polling page.
1860 }
1861
1862 const Pipeline * MachEpilogNode::pipeline() const {
1863 return MachNode::pipeline_class();
1864 }
1865
1866 //=============================================================================
1867
1868 static enum RC rc_class(OptoReg::Name reg) {
1869
1870 if (reg == OptoReg::Bad) {
1871 return rc_bad;
1872 }
1873
1874 // we have 32 int registers * 2 halves
1875 int slots_of_int_registers = Register::number_of_registers * Register::max_slots_per_register;
1876
2132 void BoxLockNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
2133 int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
2134 int reg = ra_->get_encode(this);
2135
2136 // This add will handle any 24-bit signed offset. 24 bits allows an
2137 // 8 megabyte stack frame.
2138 __ add(as_Register(reg), sp, offset);
2139 }
2140
2141 uint BoxLockNode::size(PhaseRegAlloc *ra_) const {
2142 // BoxLockNode is not a MachNode, so we can't just call MachNode::size(ra_).
2143 int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
2144
2145 if (Assembler::operand_valid_for_add_sub_immediate(offset)) {
2146 return NativeInstruction::instruction_size;
2147 } else {
2148 return 2 * NativeInstruction::instruction_size;
2149 }
2150 }
2151
2152 ///=============================================================================
2153 #ifndef PRODUCT
2154 void MachVEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
2155 {
2156 st->print_cr("# MachVEPNode");
2157 if (!_verified) {
2158 st->print_cr("\t load_class");
2159 } else {
2160 st->print_cr("\t unpack_inline_arg");
2161 }
2162 }
2163 #endif
2164
2165 void MachVEPNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc* ra_) const
2166 {
2167 if (!_verified) {
2168 __ ic_check(1);
2169 } else {
2170 // insert a nop at the start of the prolog so we can patch in a
2171 // branch if we need to invalidate the method later
2172 __ nop();
2173
2174 // TODO 8284443 Avoid creation of temporary frame
2175 if (ra_->C->stub_function() == nullptr) {
2176 __ verified_entry(ra_->C, 0);
2177 __ entry_barrier();
2178 int framesize = ra_->C->output()->frame_slots() << LogBytesPerInt;
2179 __ remove_frame(framesize, false);
2180 }
2181 // Unpack inline type args passed as oop and then jump to
2182 // the verified entry point (skipping the unverified entry).
2183 int sp_inc = __ unpack_inline_args(ra_->C, _receiver_only);
2184 // Emit code for verified entry and save increment for stack repair on return
2185 __ verified_entry(ra_->C, sp_inc);
2186 if (Compile::current()->output()->in_scratch_emit_size()) {
2187 Label dummy_verified_entry;
2188 __ b(dummy_verified_entry);
2189 } else {
2190 __ b(*_verified_entry);
2191 }
2192 }
2193 }
2194
2195 //=============================================================================
2196 #ifndef PRODUCT
2197 void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
2198 {
2199 st->print_cr("# MachUEPNode");
2200 if (UseCompressedClassPointers) {
2201 st->print_cr("\tldrw rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
2202 st->print_cr("\tldrw r10, [rscratch2 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
2203 st->print_cr("\tcmpw rscratch1, r10");
2204 } else {
2205 st->print_cr("\tldr rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
2206 st->print_cr("\tldr r10, [rscratch2 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
2207 st->print_cr("\tcmp rscratch1, r10");
2208 }
2209 st->print_cr("\tbne, SharedRuntime::_ic_miss_stub");
2210 }
2211 #endif
2212
2213 void MachUEPNode::emit(C2_MacroAssembler* masm, PhaseRegAlloc* ra_) const
2214 {
2215 __ ic_check(InteriorEntryAlignment);
2216 }
2217
2218 // REQUIRED EMIT CODE
2219
2220 //=============================================================================
2221
2222 // Emit exception handler code.
2223 int HandlerImpl::emit_exception_handler(C2_MacroAssembler* masm)
2224 {
2225 // mov rscratch1 #exception_blob_entry_point
2226 // br rscratch1
2227 // Note that the code buffer's insts_mark is always relative to insts.
2228 // That's why we must use the macroassembler to generate a handler.
2229 address base = __ start_a_stub(size_exception_handler());
2230 if (base == nullptr) {
2231 ciEnv::current()->record_failure("CodeCache is full");
2232 return 0; // CodeBuffer::expand failed
2233 }
2234 int offset = __ offset();
2235 __ far_jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
2236 assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
2237 __ end_a_stub();
3653 %}
3654
3655 enc_class aarch64_enc_java_dynamic_call(method meth) %{
3656 int method_index = resolved_method_index(masm);
3657 address call = __ ic_call((address)$meth$$method, method_index);
3658 if (call == nullptr) {
3659 ciEnv::current()->record_failure("CodeCache is full");
3660 return;
3661 }
3662 __ post_call_nop();
3663 if (Compile::current()->max_vector_size() > 0) {
3664 __ reinitialize_ptrue();
3665 }
3666 %}
3667
3668 enc_class aarch64_enc_call_epilog() %{
3669 if (VerifyStackAtCalls) {
3670 // Check that stack depth is unchanged: find majik cookie on stack
3671 __ call_Unimplemented();
3672 }
3673 if (tf()->returns_inline_type_as_fields() && !_method->is_method_handle_intrinsic()) {
3674 // The last return value is not set by the callee but used to pass IsInit information to compiled code.
3675 // Search for the corresponding projection, get the register and emit code that initialized it.
3676 uint con = (tf()->range_cc()->cnt() - 1);
3677 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
3678 ProjNode* proj = fast_out(i)->as_Proj();
3679 if (proj->_con == con) {
3680 // Set IsInit if r0 is non-null (a non-null value is returned buffered or scalarized)
3681 OptoReg::Name optoReg = ra_->get_reg_first(proj);
3682 VMReg reg = OptoReg::as_VMReg(optoReg, ra_->_framesize, OptoReg::reg2stack(ra_->_matcher._new_SP));
3683 Register toReg = reg->is_reg() ? reg->as_Register() : rscratch1;
3684 __ cmp(r0, zr);
3685 __ cset(toReg, Assembler::NE);
3686 if (reg->is_stack()) {
3687 int st_off = reg->reg2stack() * VMRegImpl::stack_slot_size;
3688 __ str(toReg, Address(sp, st_off));
3689 }
3690 break;
3691 }
3692 }
3693 if (return_value_is_used()) {
3694 // An inline type is returned as fields in multiple registers.
3695 // R0 either contains an oop if the inline type is buffered or a pointer
3696 // to the corresponding InlineKlass with the lowest bit set to 1. Zero r0
3697 // if the lowest bit is set to allow C2 to use the oop after null checking.
3698 // r0 &= (r0 & 1) - 1
3699 __ andr(rscratch1, r0, 0x1);
3700 __ sub(rscratch1, rscratch1, 0x1);
3701 __ andr(r0, r0, rscratch1);
3702 }
3703 }
3704 %}
3705
3706 enc_class aarch64_enc_java_to_runtime(method meth) %{
3707 // some calls to generated routines (arraycopy code) are scheduled
3708 // by C2 as runtime calls. if so we can call them using a br (they
3709 // will be in a reachable segment) otherwise we have to use a blr
3710 // which loads the absolute address into a register.
3711 address entry = (address)$meth$$method;
3712 CodeBlob *cb = CodeCache::find_blob(entry);
3713 if (cb) {
3714 address call = __ trampoline_call(Address(entry, relocInfo::runtime_call_type));
3715 if (call == nullptr) {
3716 ciEnv::current()->record_failure("CodeCache is full");
3717 return;
3718 }
3719 __ post_call_nop();
3720 } else {
3721 Label retaddr;
3722 __ adr(rscratch2, retaddr);
3723 __ lea(rscratch1, RuntimeAddress(entry));
6761 instruct loadConL(iRegLNoSp dst, immL src)
6762 %{
6763 match(Set dst src);
6764
6765 ins_cost(INSN_COST);
6766 format %{ "mov $dst, $src\t# long" %}
6767
6768 ins_encode( aarch64_enc_mov_imm(dst, src) );
6769
6770 ins_pipe(ialu_imm);
6771 %}
6772
6773 // Load Pointer Constant
6774
6775 instruct loadConP(iRegPNoSp dst, immP con)
6776 %{
6777 match(Set dst con);
6778
6779 ins_cost(INSN_COST * 4);
6780 format %{
6781 "mov $dst, $con\t# ptr"
6782 %}
6783
6784 ins_encode(aarch64_enc_mov_p(dst, con));
6785
6786 ins_pipe(ialu_imm);
6787 %}
6788
6789 // Load Null Pointer Constant
6790
6791 instruct loadConP0(iRegPNoSp dst, immP0 con)
6792 %{
6793 match(Set dst con);
6794
6795 ins_cost(INSN_COST);
6796 format %{ "mov $dst, $con\t# nullptr ptr" %}
6797
6798 ins_encode(aarch64_enc_mov_p0(dst, con));
6799
6800 ins_pipe(ialu_imm);
6801 %}
7957 %}
7958
7959 // ============================================================================
7960 // Cast/Convert Instructions
7961
7962 instruct castX2P(iRegPNoSp dst, iRegL src) %{
7963 match(Set dst (CastX2P src));
7964
7965 ins_cost(INSN_COST);
7966 format %{ "mov $dst, $src\t# long -> ptr" %}
7967
7968 ins_encode %{
7969 if ($dst$$reg != $src$$reg) {
7970 __ mov(as_Register($dst$$reg), as_Register($src$$reg));
7971 }
7972 %}
7973
7974 ins_pipe(ialu_reg);
7975 %}
7976
7977 instruct castN2X(iRegLNoSp dst, iRegN src) %{
7978 match(Set dst (CastP2X src));
7979
7980 ins_cost(INSN_COST);
7981 format %{ "mov $dst, $src\t# ptr -> long" %}
7982
7983 ins_encode %{
7984 if ($dst$$reg != $src$$reg) {
7985 __ mov(as_Register($dst$$reg), as_Register($src$$reg));
7986 }
7987 %}
7988
7989 ins_pipe(ialu_reg);
7990 %}
7991
7992 instruct castP2X(iRegLNoSp dst, iRegP src) %{
7993 match(Set dst (CastP2X src));
7994
7995 ins_cost(INSN_COST);
7996 format %{ "mov $dst, $src\t# ptr -> long" %}
7997
7998 ins_encode %{
7999 if ($dst$$reg != $src$$reg) {
8000 __ mov(as_Register($dst$$reg), as_Register($src$$reg));
8001 }
8002 %}
8003
8004 ins_pipe(ialu_reg);
8005 %}
8006
8007 // Convert oop into int for vectors alignment masking
8008 instruct convP2I(iRegINoSp dst, iRegP src) %{
8009 match(Set dst (ConvL2I (CastP2X src)));
8010
8011 ins_cost(INSN_COST);
14797
14798 match(Set dst (MoveL2D src));
14799
14800 effect(DEF dst, USE src);
14801
14802 ins_cost(INSN_COST);
14803
14804 format %{ "fmovd $dst, $src\t# MoveL2D_reg_reg" %}
14805
14806 ins_encode %{
14807 __ fmovd(as_FloatRegister($dst$$reg), $src$$Register);
14808 %}
14809
14810 ins_pipe(fp_l2d);
14811
14812 %}
14813
14814 // ============================================================================
14815 // clearing of an array
14816
14817 instruct clearArray_reg_reg_immL0(iRegL_R11 cnt, iRegP_R10 base, immL0 zero, Universe dummy, rFlagsReg cr)
14818 %{
14819 match(Set dummy (ClearArray (Binary cnt base) zero));
14820 effect(USE_KILL cnt, USE_KILL base, KILL cr);
14821
14822 ins_cost(4 * INSN_COST);
14823 format %{ "ClearArray $cnt, $base" %}
14824
14825 ins_encode %{
14826 address tpc = __ zero_words($base$$Register, $cnt$$Register);
14827 if (tpc == nullptr) {
14828 ciEnv::current()->record_failure("CodeCache is full");
14829 return;
14830 }
14831 %}
14832
14833 ins_pipe(pipe_class_memory);
14834 %}
14835
14836 instruct clearArray_reg_reg(iRegL_R11 cnt, iRegP_R10 base, iRegL val, Universe dummy, rFlagsReg cr)
14837 %{
14838 predicate(((ClearArrayNode*)n)->word_copy_only());
14839 match(Set dummy (ClearArray (Binary cnt base) val));
14840 effect(USE_KILL cnt, USE_KILL base, KILL cr);
14841
14842 ins_cost(4 * INSN_COST);
14843 format %{ "ClearArray $cnt, $base, $val" %}
14844
14845 ins_encode %{
14846 __ fill_words($base$$Register, $cnt$$Register, $val$$Register);
14847 %}
14848
14849 ins_pipe(pipe_class_memory);
14850 %}
14851
14852 instruct clearArray_imm_reg(immL cnt, iRegP_R10 base, iRegL_R11 temp, Universe dummy, rFlagsReg cr)
14853 %{
14854 predicate((uint64_t)n->in(2)->get_long()
14855 < (uint64_t)(BlockZeroingLowLimit >> LogBytesPerWord)
14856 && !((ClearArrayNode*)n)->word_copy_only());
14857 match(Set dummy (ClearArray cnt base));
14858 effect(TEMP temp, USE_KILL base, KILL cr);
14859
14860 ins_cost(4 * INSN_COST);
14861 format %{ "ClearArray $cnt, $base" %}
14862
14863 ins_encode %{
14864 address tpc = __ zero_words($base$$Register, (uint64_t)$cnt$$constant);
14865 if (tpc == nullptr) {
14866 ciEnv::current()->record_failure("CodeCache is full");
14867 return;
14868 }
14869 %}
14870
14871 ins_pipe(pipe_class_memory);
14872 %}
14873
14874 // ============================================================================
14875 // Overflow Math Instructions
14876
16187 %}
16188
16189 // Call Runtime Instruction without safepoint and with vector arguments
16190 instruct CallLeafDirectVector(method meth)
16191 %{
16192 match(CallLeafVector);
16193
16194 effect(USE meth);
16195
16196 ins_cost(CALL_COST);
16197
16198 format %{ "CALL, runtime leaf vector $meth" %}
16199
16200 ins_encode(aarch64_enc_java_to_runtime(meth));
16201
16202 ins_pipe(pipe_class_call);
16203 %}
16204
16205 // Call Runtime Instruction
16206
16207 // entry point is null, target holds the address to call
16208 instruct CallLeafNoFPIndirect(iRegP target)
16209 %{
16210 predicate(n->as_Call()->entry_point() == nullptr);
16211
16212 match(CallLeafNoFP target);
16213
16214 ins_cost(CALL_COST);
16215
16216 format %{ "CALL, runtime leaf nofp indirect $target" %}
16217
16218 ins_encode %{
16219 __ blr($target$$Register);
16220 %}
16221
16222 ins_pipe(pipe_class_call);
16223 %}
16224
16225 instruct CallLeafNoFPDirect(method meth)
16226 %{
16227 predicate(n->as_Call()->entry_point() != nullptr);
16228
16229 match(CallLeafNoFP);
16230
16231 effect(USE meth);
16232
16233 ins_cost(CALL_COST);
16234
16235 format %{ "CALL, runtime leaf nofp $meth" %}
16236
16237 ins_encode( aarch64_enc_java_to_runtime(meth) );
16238
16239 ins_pipe(pipe_class_call);
16240 %}
16241
16242 // Tail Call; Jump from runtime stub to Java code.
16243 // Also known as an 'interprocedural jump'.
16244 // Target of jump will eventually return to caller.
16245 // TailJump below removes the return address.
16246 // Don't use rfp for 'jump_target' because a MachEpilogNode has already been
16247 // emitted just above the TailCall which has reset rfp to the caller state.
16248 instruct TailCalljmpInd(iRegPNoSpNoRfp jump_target, inline_cache_RegP method_ptr)
|