< prev index next >

src/hotspot/cpu/s390/macroAssembler_s390.cpp

Print this page

3510       // will provoke OS null exception if reg is null.
3511   }
3512 }
3513 
3514 //-------------------------------------
3515 //  Compressed Klass Pointers
3516 //-------------------------------------
3517 
3518 // Klass oop manipulations if compressed.
3519 void MacroAssembler::encode_klass_not_null(Register dst, Register src) {
3520   Register current = (src != noreg) ? src : dst; // Klass is in dst if no src provided. (dst == src) also possible.
3521   address  base    = CompressedKlassPointers::base();
3522   int      shift   = CompressedKlassPointers::shift();
3523   bool     need_zero_extend = base != 0;
3524   assert(UseCompressedClassPointers, "only for compressed klass ptrs");
3525 
3526   BLOCK_COMMENT("cKlass encoder {");
3527 
3528 #ifdef ASSERT
3529   Label ok;
3530   z_tmll(current, KlassAlignmentInBytes-1); // Check alignment.
3531   z_brc(Assembler::bcondAllZero, ok);
3532   // The plain disassembler does not recognize illtrap. It instead displays
3533   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3534   // the proper beginning of the next instruction.
3535   z_illtrap(0xee);
3536   z_illtrap(0xee);
3537   bind(ok);
3538 #endif
3539 
3540   // Scale down the incoming klass pointer first.
3541   // We then can be sure we calculate an offset that fits into 32 bit.
3542   // More generally speaking: all subsequent calculations are purely 32-bit.
3543   if (shift != 0) {
3544     assert (LogKlassAlignmentInBytes == shift, "decode alg wrong");
3545     z_srlg(dst, current, shift);
3546     current = dst;
3547   }
3548 
3549   if (base != nullptr) {
3550     // Use scaled-down base address parts to match scaled-down klass pointer.
3551     unsigned int base_h = ((unsigned long)base)>>(32+shift);
3552     unsigned int base_l = (unsigned int)(((unsigned long)base)>>shift);
3553 
3554     // General considerations:
3555     //  - when calculating (current_h - base_h), all digits must cancel (become 0).
3556     //    Otherwise, we would end up with a compressed klass pointer which doesn't
3557     //    fit into 32-bit.
3558     //  - Only bit#33 of the difference could potentially be non-zero. For that
3559     //    to happen, (current_l < base_l) must hold. In this case, the subtraction
3560     //    will create a borrow out of bit#32, nicely killing bit#33.
3561     //  - With the above, we only need to consider current_l and base_l to
3562     //    calculate the result.
3563     //  - Both values are treated as unsigned. The unsigned subtraction is
3564     //    replaced by adding (unsigned) the 2's complement of the subtrahend.

3654   BLOCK_COMMENT("cKlass decoder (const size) {");
3655 
3656   if (shift != 0) { // Shift required?
3657     z_sllg(dst, dst, shift);
3658   }
3659   if (base != nullptr) {
3660     unsigned int base_h = ((unsigned long)base)>>32;
3661     unsigned int base_l = (unsigned int)((unsigned long)base);
3662     if ((base_h != 0) && (base_l == 0) && VM_Version::has_HighWordInstr()) {
3663       z_aih(dst, base_h);     // Base has no set bits in lower half.
3664     } else if ((base_h == 0) && (base_l != 0)) {
3665       z_algfi(dst, base_l);   // Base has no set bits in upper half.
3666     } else {
3667       load_const(Z_R0, base); // Base has set bits everywhere.
3668       z_algr(dst, Z_R0);
3669     }
3670   }
3671 
3672 #ifdef ASSERT
3673   Label ok;
3674   z_tmll(dst, KlassAlignmentInBytes-1); // Check alignment.
3675   z_brc(Assembler::bcondAllZero, ok);
3676   // The plain disassembler does not recognize illtrap. It instead displays
3677   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3678   // the proper beginning of the next instruction.
3679   z_illtrap(0xd1);
3680   z_illtrap(0xd1);
3681   bind(ok);
3682 #endif
3683   assert(offset() == beg_off + instr_size_for_decode_klass_not_null(), "Code gen mismatch.");
3684 
3685   BLOCK_COMMENT("} cKlass decoder (const size)");
3686 }
3687 
3688 // This variant of decode_klass_not_null() is for cases where
3689 //  1) the size of the generated instructions may vary
3690 //  2) the result is (potentially) stored in a register different from the source.
3691 void MacroAssembler::decode_klass_not_null(Register dst, Register src) {
3692   address base  = CompressedKlassPointers::base();
3693   int     shift = CompressedKlassPointers::shift();
3694   assert(UseCompressedClassPointers, "only for compressed klass ptrs");

3701     z_sllg(dst, src, shift);
3702   } else {
3703     lgr_if_needed(dst, src);
3704   }
3705 
3706   if (base != nullptr) {
3707     unsigned int base_h = ((unsigned long)base)>>32;
3708     unsigned int base_l = (unsigned int)((unsigned long)base);
3709     if ((base_h != 0) && (base_l == 0) && VM_Version::has_HighWordInstr()) {
3710       z_aih(dst, base_h);     // Base has not set bits in lower half.
3711     } else if ((base_h == 0) && (base_l != 0)) {
3712       z_algfi(dst, base_l);   // Base has no set bits in upper half.
3713     } else {
3714       load_const_optimized(Z_R0, base); // Base has set bits everywhere.
3715       z_algr(dst, Z_R0);
3716     }
3717   }
3718 
3719 #ifdef ASSERT
3720   Label ok;
3721   z_tmll(dst, KlassAlignmentInBytes-1); // Check alignment.
3722   z_brc(Assembler::bcondAllZero, ok);
3723   // The plain disassembler does not recognize illtrap. It instead displays
3724   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3725   // the proper beginning of the next instruction.
3726   z_illtrap(0xd2);
3727   z_illtrap(0xd2);
3728   bind(ok);
3729 #endif
3730   BLOCK_COMMENT("} cKlass decoder");
3731 }
3732 
3733 void MacroAssembler::load_klass(Register klass, Address mem) {
3734   if (UseCompressedClassPointers) {
3735     z_llgf(klass, mem);
3736     // Attention: no null check here!
3737     decode_klass_not_null(klass);
3738   } else {
3739     z_lg(klass, mem);
3740   }
3741 }

3770     } else {
3771       z_mvhi(Address(d, oopDesc::klass_gap_offset_in_bytes()), 0);
3772     }
3773   }
3774 }
3775 
3776 // Compare klass ptr in memory against klass ptr in register.
3777 //
3778 // Rop1            - klass in register, always uncompressed.
3779 // disp            - Offset of klass in memory, compressed/uncompressed, depending on runtime flag.
3780 // Rbase           - Base address of cKlass in memory.
3781 // maybenull       - True if Rop1 possibly is a null.
3782 void MacroAssembler::compare_klass_ptr(Register Rop1, int64_t disp, Register Rbase, bool maybenull) {
3783 
3784   BLOCK_COMMENT("compare klass ptr {");
3785 
3786   if (UseCompressedClassPointers) {
3787     const int shift = CompressedKlassPointers::shift();
3788     address   base  = CompressedKlassPointers::base();
3789 
3790     assert((shift == 0) || (shift == LogKlassAlignmentInBytes), "cKlass encoder detected bad shift");




3791     assert_different_registers(Rop1, Z_R0);
3792     assert_different_registers(Rop1, Rbase, Z_R1);
3793 
3794     // First encode register oop and then compare with cOop in memory.
3795     // This sequence saves an unnecessary cOop load and decode.
3796     if (base == nullptr) {
3797       if (shift == 0) {
3798         z_cl(Rop1, disp, Rbase);     // Unscaled
3799       } else {
3800         z_srlg(Z_R0, Rop1, shift);   // ZeroBased
3801         z_cl(Z_R0, disp, Rbase);
3802       }
3803     } else {                         // HeapBased
3804 #ifdef ASSERT
3805       bool     used_R0 = true;
3806       bool     used_R1 = true;
3807 #endif
3808       Register current = Rop1;
3809       Label    done;
3810 

3510       // will provoke OS null exception if reg is null.
3511   }
3512 }
3513 
3514 //-------------------------------------
3515 //  Compressed Klass Pointers
3516 //-------------------------------------
3517 
3518 // Klass oop manipulations if compressed.
3519 void MacroAssembler::encode_klass_not_null(Register dst, Register src) {
3520   Register current = (src != noreg) ? src : dst; // Klass is in dst if no src provided. (dst == src) also possible.
3521   address  base    = CompressedKlassPointers::base();
3522   int      shift   = CompressedKlassPointers::shift();
3523   bool     need_zero_extend = base != 0;
3524   assert(UseCompressedClassPointers, "only for compressed klass ptrs");
3525 
3526   BLOCK_COMMENT("cKlass encoder {");
3527 
3528 #ifdef ASSERT
3529   Label ok;
3530   z_tmll(current, CompressedKlassPointers::klass_alignment_in_bytes() - 1); // Check alignment.
3531   z_brc(Assembler::bcondAllZero, ok);
3532   // The plain disassembler does not recognize illtrap. It instead displays
3533   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3534   // the proper beginning of the next instruction.
3535   z_illtrap(0xee);
3536   z_illtrap(0xee);
3537   bind(ok);
3538 #endif
3539 
3540   // Scale down the incoming klass pointer first.
3541   // We then can be sure we calculate an offset that fits into 32 bit.
3542   // More generally speaking: all subsequent calculations are purely 32-bit.
3543   if (shift != 0) {

3544     z_srlg(dst, current, shift);
3545     current = dst;
3546   }
3547 
3548   if (base != nullptr) {
3549     // Use scaled-down base address parts to match scaled-down klass pointer.
3550     unsigned int base_h = ((unsigned long)base)>>(32+shift);
3551     unsigned int base_l = (unsigned int)(((unsigned long)base)>>shift);
3552 
3553     // General considerations:
3554     //  - when calculating (current_h - base_h), all digits must cancel (become 0).
3555     //    Otherwise, we would end up with a compressed klass pointer which doesn't
3556     //    fit into 32-bit.
3557     //  - Only bit#33 of the difference could potentially be non-zero. For that
3558     //    to happen, (current_l < base_l) must hold. In this case, the subtraction
3559     //    will create a borrow out of bit#32, nicely killing bit#33.
3560     //  - With the above, we only need to consider current_l and base_l to
3561     //    calculate the result.
3562     //  - Both values are treated as unsigned. The unsigned subtraction is
3563     //    replaced by adding (unsigned) the 2's complement of the subtrahend.

3653   BLOCK_COMMENT("cKlass decoder (const size) {");
3654 
3655   if (shift != 0) { // Shift required?
3656     z_sllg(dst, dst, shift);
3657   }
3658   if (base != nullptr) {
3659     unsigned int base_h = ((unsigned long)base)>>32;
3660     unsigned int base_l = (unsigned int)((unsigned long)base);
3661     if ((base_h != 0) && (base_l == 0) && VM_Version::has_HighWordInstr()) {
3662       z_aih(dst, base_h);     // Base has no set bits in lower half.
3663     } else if ((base_h == 0) && (base_l != 0)) {
3664       z_algfi(dst, base_l);   // Base has no set bits in upper half.
3665     } else {
3666       load_const(Z_R0, base); // Base has set bits everywhere.
3667       z_algr(dst, Z_R0);
3668     }
3669   }
3670 
3671 #ifdef ASSERT
3672   Label ok;
3673   z_tmll(dst, CompressedKlassPointers::klass_alignment_in_bytes() - 1); // Check alignment.
3674   z_brc(Assembler::bcondAllZero, ok);
3675   // The plain disassembler does not recognize illtrap. It instead displays
3676   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3677   // the proper beginning of the next instruction.
3678   z_illtrap(0xd1);
3679   z_illtrap(0xd1);
3680   bind(ok);
3681 #endif
3682   assert(offset() == beg_off + instr_size_for_decode_klass_not_null(), "Code gen mismatch.");
3683 
3684   BLOCK_COMMENT("} cKlass decoder (const size)");
3685 }
3686 
3687 // This variant of decode_klass_not_null() is for cases where
3688 //  1) the size of the generated instructions may vary
3689 //  2) the result is (potentially) stored in a register different from the source.
3690 void MacroAssembler::decode_klass_not_null(Register dst, Register src) {
3691   address base  = CompressedKlassPointers::base();
3692   int     shift = CompressedKlassPointers::shift();
3693   assert(UseCompressedClassPointers, "only for compressed klass ptrs");

3700     z_sllg(dst, src, shift);
3701   } else {
3702     lgr_if_needed(dst, src);
3703   }
3704 
3705   if (base != nullptr) {
3706     unsigned int base_h = ((unsigned long)base)>>32;
3707     unsigned int base_l = (unsigned int)((unsigned long)base);
3708     if ((base_h != 0) && (base_l == 0) && VM_Version::has_HighWordInstr()) {
3709       z_aih(dst, base_h);     // Base has not set bits in lower half.
3710     } else if ((base_h == 0) && (base_l != 0)) {
3711       z_algfi(dst, base_l);   // Base has no set bits in upper half.
3712     } else {
3713       load_const_optimized(Z_R0, base); // Base has set bits everywhere.
3714       z_algr(dst, Z_R0);
3715     }
3716   }
3717 
3718 #ifdef ASSERT
3719   Label ok;
3720   z_tmll(dst, CompressedKlassPointers::klass_alignment_in_bytes() - 1); // Check alignment.
3721   z_brc(Assembler::bcondAllZero, ok);
3722   // The plain disassembler does not recognize illtrap. It instead displays
3723   // a 32-bit value. Issuing two illtraps assures the disassembler finds
3724   // the proper beginning of the next instruction.
3725   z_illtrap(0xd2);
3726   z_illtrap(0xd2);
3727   bind(ok);
3728 #endif
3729   BLOCK_COMMENT("} cKlass decoder");
3730 }
3731 
3732 void MacroAssembler::load_klass(Register klass, Address mem) {
3733   if (UseCompressedClassPointers) {
3734     z_llgf(klass, mem);
3735     // Attention: no null check here!
3736     decode_klass_not_null(klass);
3737   } else {
3738     z_lg(klass, mem);
3739   }
3740 }

3769     } else {
3770       z_mvhi(Address(d, oopDesc::klass_gap_offset_in_bytes()), 0);
3771     }
3772   }
3773 }
3774 
3775 // Compare klass ptr in memory against klass ptr in register.
3776 //
3777 // Rop1            - klass in register, always uncompressed.
3778 // disp            - Offset of klass in memory, compressed/uncompressed, depending on runtime flag.
3779 // Rbase           - Base address of cKlass in memory.
3780 // maybenull       - True if Rop1 possibly is a null.
3781 void MacroAssembler::compare_klass_ptr(Register Rop1, int64_t disp, Register Rbase, bool maybenull) {
3782 
3783   BLOCK_COMMENT("compare klass ptr {");
3784 
3785   if (UseCompressedClassPointers) {
3786     const int shift = CompressedKlassPointers::shift();
3787     address   base  = CompressedKlassPointers::base();
3788 
3789     if (CompressedKlassPointers::tiny_classpointer_mode()) {
3790       assert(shift >= 3, "cKlass encoder detected bad shift");
3791     } else {
3792       assert((shift == 0) || (shift == 3), "cKlass encoder detected bad shift");
3793     }
3794     assert_different_registers(Rop1, Z_R0);
3795     assert_different_registers(Rop1, Rbase, Z_R1);
3796 
3797     // First encode register oop and then compare with cOop in memory.
3798     // This sequence saves an unnecessary cOop load and decode.
3799     if (base == nullptr) {
3800       if (shift == 0) {
3801         z_cl(Rop1, disp, Rbase);     // Unscaled
3802       } else {
3803         z_srlg(Z_R0, Rop1, shift);   // ZeroBased
3804         z_cl(Z_R0, disp, Rbase);
3805       }
3806     } else {                         // HeapBased
3807 #ifdef ASSERT
3808       bool     used_R0 = true;
3809       bool     used_R1 = true;
3810 #endif
3811       Register current = Rop1;
3812       Label    done;
3813 
< prev index next >