< prev index next >

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Print this page

  22  * questions.
  23  *
  24  */
  25 
  26 #include <sys/types.h>
  27 
  28 #include "precompiled.hpp"
  29 #include "jvm.h"
  30 #include "asm/assembler.hpp"
  31 #include "asm/assembler.inline.hpp"
  32 #include "gc/shared/barrierSet.hpp"
  33 #include "gc/shared/barrierSetAssembler.hpp"
  34 #include "gc/shared/cardTableBarrierSet.hpp"
  35 #include "gc/shared/cardTable.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "gc/shared/tlab_globals.hpp"
  38 #include "interpreter/bytecodeHistogram.hpp"
  39 #include "interpreter/interpreter.hpp"
  40 #include "compiler/compileTask.hpp"
  41 #include "compiler/disassembler.hpp"

  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "nativeInst_aarch64.hpp"
  45 #include "oops/accessDecorators.hpp"

  46 #include "oops/compressedOops.inline.hpp"
  47 #include "oops/klass.inline.hpp"
  48 #include "runtime/icache.hpp"
  49 #include "runtime/interfaceSupport.inline.hpp"
  50 #include "runtime/jniHandles.inline.hpp"
  51 #include "runtime/sharedRuntime.hpp"
  52 #include "runtime/stubRoutines.hpp"
  53 #include "runtime/thread.hpp"
  54 #include "utilities/powerOfTwo.hpp"
  55 #ifdef COMPILER1
  56 #include "c1/c1_LIRAssembler.hpp"
  57 #endif
  58 #ifdef COMPILER2
  59 #include "oops/oop.hpp"
  60 #include "opto/compile.hpp"
  61 #include "opto/node.hpp"
  62 #include "opto/output.hpp"
  63 #endif
  64 
  65 #ifdef PRODUCT

3884   // Cannot assert, unverified entry point counts instructions (see .ad file)
3885   // vtableStubs also counts instructions in pd_code_size_limit.
3886   // Also do not verify_oop as this is called by verify_oop.
3887   if (CompressedOops::shift() != 0) {
3888     assert(LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
3889     if (CompressedOops::base() != NULL) {
3890       add(dst, rheapbase, src, Assembler::LSL, LogMinObjAlignmentInBytes);
3891     } else {
3892       add(dst, zr, src, Assembler::LSL, LogMinObjAlignmentInBytes);
3893     }
3894   } else {
3895     assert (CompressedOops::base() == NULL, "sanity");
3896     if (dst != src) {
3897       mov(dst, src);
3898     }
3899   }
3900 }
3901 
3902 MacroAssembler::KlassDecodeMode MacroAssembler::_klass_decode_mode(KlassDecodeNone);
3903 














3904 MacroAssembler::KlassDecodeMode MacroAssembler::klass_decode_mode() {
3905   assert(UseCompressedClassPointers, "not using compressed class pointers");
3906   assert(Metaspace::initialized(), "metaspace not initialized yet");


3907 
3908   if (_klass_decode_mode != KlassDecodeNone) {
3909     return _klass_decode_mode;



3910   }







3911 
3912   assert(LogKlassAlignmentInBytes == CompressedKlassPointers::shift()
3913          || 0 == CompressedKlassPointers::shift(), "decode alg wrong");
3914 
3915   if (CompressedKlassPointers::base() == NULL) {
3916     return (_klass_decode_mode = KlassDecodeZero);
3917   }
3918 
3919   if (operand_valid_for_logical_immediate(
3920         /*is32*/false, (uint64_t)CompressedKlassPointers::base())) {
3921     const uint64_t range_mask =
3922       (1ULL << log2i(CompressedKlassPointers::range())) - 1;
3923     if (((uint64_t)CompressedKlassPointers::base() & range_mask) == 0) {
3924       return (_klass_decode_mode = KlassDecodeXor);
3925     }
3926   }
3927 
3928   const uint64_t shifted_base =
3929     (uint64_t)CompressedKlassPointers::base() >> CompressedKlassPointers::shift();
3930   guarantee((shifted_base & 0xffff0000ffffffff) == 0,
3931             "compressed class base bad alignment");
3932 
3933   return (_klass_decode_mode = KlassDecodeMovk);
3934 }
3935 
3936 void MacroAssembler::encode_klass_not_null(Register dst, Register src) {


3937   switch (klass_decode_mode()) {
3938   case KlassDecodeZero:
3939     if (CompressedKlassPointers::shift() != 0) {
3940       lsr(dst, src, LogKlassAlignmentInBytes);
3941     } else {
3942       if (dst != src) mov(dst, src);
3943     }
3944     break;
3945 
3946   case KlassDecodeXor:
3947     if (CompressedKlassPointers::shift() != 0) {
3948       eor(dst, src, (uint64_t)CompressedKlassPointers::base());
3949       lsr(dst, dst, LogKlassAlignmentInBytes);
3950     } else {
3951       eor(dst, src, (uint64_t)CompressedKlassPointers::base());
3952     }
3953     break;
3954 
3955   case KlassDecodeMovk:
3956     if (CompressedKlassPointers::shift() != 0) {
3957       ubfx(dst, src, LogKlassAlignmentInBytes, 32);
3958     } else {
3959       movw(dst, src);
3960     }
3961     break;
3962 
3963   case KlassDecodeNone:
3964     ShouldNotReachHere();
3965     break;
3966   }
3967 }
3968 
3969 void MacroAssembler::encode_klass_not_null(Register r) {
3970   encode_klass_not_null(r, r);
3971 }
3972 
3973 void  MacroAssembler::decode_klass_not_null(Register dst, Register src) {
3974   assert (UseCompressedClassPointers, "should only be used for compressed headers");
3975 


3976   switch (klass_decode_mode()) {
3977   case KlassDecodeZero:
3978     if (CompressedKlassPointers::shift() != 0) {
3979       lsl(dst, src, LogKlassAlignmentInBytes);
3980     } else {
3981       if (dst != src) mov(dst, src);
3982     }
3983     break;
3984 
3985   case KlassDecodeXor:
3986     if (CompressedKlassPointers::shift() != 0) {
3987       lsl(dst, src, LogKlassAlignmentInBytes);
3988       eor(dst, dst, (uint64_t)CompressedKlassPointers::base());
3989     } else {
3990       eor(dst, src, (uint64_t)CompressedKlassPointers::base());
3991     }
3992     break;
3993 
3994   case KlassDecodeMovk: {
3995     const uint64_t shifted_base =
3996       (uint64_t)CompressedKlassPointers::base() >> CompressedKlassPointers::shift();
3997 



3998     if (dst != src) movw(dst, src);
3999     movk(dst, shifted_base >> 32, 32);
4000 
4001     if (CompressedKlassPointers::shift() != 0) {
4002       lsl(dst, dst, LogKlassAlignmentInBytes);
4003     }
4004 
4005     break;
4006   }
4007 
4008   case KlassDecodeNone:
4009     ShouldNotReachHere();
4010     break;
4011   }
4012 }
4013 
4014 void  MacroAssembler::decode_klass_not_null(Register r) {
4015   decode_klass_not_null(r, r);
4016 }
4017 
4018 void  MacroAssembler::set_narrow_oop(Register dst, jobject obj) {
4019 #ifdef ASSERT
4020   {
4021     ThreadInVMfromUnknown tiv;
4022     assert (UseCompressedOops, "should only be used for compressed oops");
4023     assert (Universe::heap() != NULL, "java heap should be initialized");
4024     assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");

  22  * questions.
  23  *
  24  */
  25 
  26 #include <sys/types.h>
  27 
  28 #include "precompiled.hpp"
  29 #include "jvm.h"
  30 #include "asm/assembler.hpp"
  31 #include "asm/assembler.inline.hpp"
  32 #include "gc/shared/barrierSet.hpp"
  33 #include "gc/shared/barrierSetAssembler.hpp"
  34 #include "gc/shared/cardTableBarrierSet.hpp"
  35 #include "gc/shared/cardTable.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "gc/shared/tlab_globals.hpp"
  38 #include "interpreter/bytecodeHistogram.hpp"
  39 #include "interpreter/interpreter.hpp"
  40 #include "compiler/compileTask.hpp"
  41 #include "compiler/disassembler.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "nativeInst_aarch64.hpp"
  46 #include "oops/accessDecorators.hpp"
  47 #include "oops/compressedKlass.inline.hpp"
  48 #include "oops/compressedOops.inline.hpp"
  49 #include "oops/klass.inline.hpp"
  50 #include "runtime/icache.hpp"
  51 #include "runtime/interfaceSupport.inline.hpp"
  52 #include "runtime/jniHandles.inline.hpp"
  53 #include "runtime/sharedRuntime.hpp"
  54 #include "runtime/stubRoutines.hpp"
  55 #include "runtime/thread.hpp"
  56 #include "utilities/powerOfTwo.hpp"
  57 #ifdef COMPILER1
  58 #include "c1/c1_LIRAssembler.hpp"
  59 #endif
  60 #ifdef COMPILER2
  61 #include "oops/oop.hpp"
  62 #include "opto/compile.hpp"
  63 #include "opto/node.hpp"
  64 #include "opto/output.hpp"
  65 #endif
  66 
  67 #ifdef PRODUCT

3886   // Cannot assert, unverified entry point counts instructions (see .ad file)
3887   // vtableStubs also counts instructions in pd_code_size_limit.
3888   // Also do not verify_oop as this is called by verify_oop.
3889   if (CompressedOops::shift() != 0) {
3890     assert(LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
3891     if (CompressedOops::base() != NULL) {
3892       add(dst, rheapbase, src, Assembler::LSL, LogMinObjAlignmentInBytes);
3893     } else {
3894       add(dst, zr, src, Assembler::LSL, LogMinObjAlignmentInBytes);
3895     }
3896   } else {
3897     assert (CompressedOops::base() == NULL, "sanity");
3898     if (dst != src) {
3899       mov(dst, src);
3900     }
3901   }
3902 }
3903 
3904 MacroAssembler::KlassDecodeMode MacroAssembler::_klass_decode_mode(KlassDecodeNone);
3905 
3906 // Returns a static string
3907 const char* MacroAssembler::describe_klass_decode_mode(MacroAssembler::KlassDecodeMode mode) {
3908   switch (mode) {
3909   case KlassDecodeNone: return "none";
3910   case KlassDecodeZero: return "zero";
3911   case KlassDecodeXor:  return "xor";
3912   case KlassDecodeMovk: return "movk";
3913   default:
3914     ShouldNotReachHere();
3915   }
3916   return NULL;
3917 }
3918 
3919 // Return the current narrow Klass pointer decode mode.
3920 MacroAssembler::KlassDecodeMode MacroAssembler::klass_decode_mode() {
3921   if (_klass_decode_mode == KlassDecodeNone) {
3922     // First time initialization
3923     assert(UseCompressedClassPointers, "not using compressed class pointers");
3924     assert(Metaspace::initialized(), "metaspace not initialized yet");
3925 
3926     _klass_decode_mode = klass_decode_mode_for_base(CompressedKlassPointers::base());
3927     guarantee(_klass_decode_mode != KlassDecodeNone,
3928               PTR_FORMAT " is not a valid encoding base on aarch64",
3929               p2i(CompressedKlassPointers::base()));
3930     log_info(metaspace)("klass decode mode initialized: %s", describe_klass_decode_mode(_klass_decode_mode));
3931   }
3932   return _klass_decode_mode;
3933 }
3934 
3935 // Given an arbitrary base address, return the KlassDecodeMode that would be used. Return KlassDecodeNone
3936 // if base address is not valid for encoding.
3937 MacroAssembler::KlassDecodeMode MacroAssembler::klass_decode_mode_for_base(address base) {
3938   assert(CompressedKlassPointers::shift() != 0, "not lilliput?");
3939 
3940   const uint64_t base_u64 = (uint64_t) base;

3941 
3942   if (base_u64 == 0) {
3943     return KlassDecodeZero;
3944   }
3945 
3946   if (operand_valid_for_logical_immediate(false, base_u64) &&
3947       ((base_u64 & (KlassEncodingMetaspaceMax - 1)) == 0)) {
3948     return KlassDecodeXor;




3949   }
3950 
3951   const uint64_t shifted_base = base_u64 >> CompressedKlassPointers::shift();
3952   if ((shifted_base & 0xffff0000ffffffff) == 0) {
3953     return KlassDecodeMovk;
3954   }
3955 
3956   return KlassDecodeNone;
3957 }
3958 
3959 void MacroAssembler::encode_klass_not_null(Register dst, Register src) {
3960   assert (UseCompressedClassPointers, "should only be used for compressed headers");
3961   assert(CompressedKlassPointers::shift() != 0, "not lilliput?");
3962   switch (klass_decode_mode()) {
3963   case KlassDecodeZero:
3964     lsr(dst, src, LogKlassAlignmentInBytes);




3965     break;
3966 
3967   case KlassDecodeXor:
3968     eor(dst, src, (uint64_t)CompressedKlassPointers::base());
3969     lsr(dst, dst, LogKlassAlignmentInBytes);




3970     break;
3971 
3972   case KlassDecodeMovk:
3973     ubfx(dst, src, LogKlassAlignmentInBytes, MaxNarrowKlassPointerBits);




3974     break;
3975 
3976   case KlassDecodeNone:
3977     ShouldNotReachHere();
3978     break;
3979   }
3980 }
3981 
3982 void MacroAssembler::encode_klass_not_null(Register r) {
3983   encode_klass_not_null(r, r);
3984 }
3985 
3986 void  MacroAssembler::decode_klass_not_null(Register dst, Register src) {
3987   assert (UseCompressedClassPointers, "should only be used for compressed headers");
3988 
3989   assert(CompressedKlassPointers::shift() != 0, "not lilliput?");
3990 
3991   switch (klass_decode_mode()) {
3992   case KlassDecodeZero:
3993     if (dst != src) mov(dst, src);




3994     break;
3995 
3996   case KlassDecodeXor:
3997     lsl(dst, src, LogKlassAlignmentInBytes);
3998     eor(dst, dst, (uint64_t)CompressedKlassPointers::base());




3999     break;
4000 
4001   case KlassDecodeMovk: {
4002     const uint64_t shifted_base =
4003       (uint64_t)CompressedKlassPointers::base() >> CompressedKlassPointers::shift();
4004 
4005     // Invalid base should have been gracefully handled via klass_decode_mode() in VM initialization.
4006     assert((shifted_base & 0xffff0000ffffffff) == 0, "incompatible base");
4007 
4008     if (dst != src) movw(dst, src);
4009     movk(dst, shifted_base >> 32, 32);
4010     lsl(dst, dst, LogKlassAlignmentInBytes);




4011     break;
4012   }
4013 
4014   case KlassDecodeNone:
4015     ShouldNotReachHere();
4016     break;
4017   }
4018 }
4019 
4020 void  MacroAssembler::decode_klass_not_null(Register r) {
4021   decode_klass_not_null(r, r);
4022 }
4023 
4024 void  MacroAssembler::set_narrow_oop(Register dst, jobject obj) {
4025 #ifdef ASSERT
4026   {
4027     ThreadInVMfromUnknown tiv;
4028     assert (UseCompressedOops, "should only be used for compressed oops");
4029     assert (Universe::heap() != NULL, "java heap should be initialized");
4030     assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");
< prev index next >