@Override
  public long getMemorySize(JavaConstant constant) {
    if (constant.getJavaKind() == JavaKind.Object) {
      HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant);

      if (lookupJavaType == null) {
        return 0;
      } else {
        if (lookupJavaType.isArray()) {
          // TODO(tw): Add compressed pointer support.
          int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object());
          ResolvedJavaType elementType = lookupJavaType.getComponentType();
          JavaKind elementKind = elementType.getJavaKind();
          final int headerSize = getArrayBaseOffset(elementKind);
          TargetDescription target = runtime.getHostJVMCIBackend().getTarget();
          int sizeOfElement = getArrayIndexScale(elementKind);
          int alignment = target.wordSize;
          int log2ElementSize = CodeUtil.log2(sizeOfElement);
          return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
        }
        return lookupJavaType.instanceSize();
      }
    } else {
      return constant.getJavaKind().getByteCount();
    }
  }
 @Override
 public JavaConstant encodeDeoptActionAndReason(
     DeoptimizationAction action, DeoptimizationReason reason, int debugId) {
   HotSpotVMConfig config = runtime.getConfig();
   int actionValue = convertDeoptAction(action);
   int reasonValue = convertDeoptReason(reason);
   int debugValue = debugId & intMaskRight(config.deoptimizationDebugIdBits);
   JavaConstant c =
       JavaConstant.forInt(
           ~((debugValue << config.deoptimizationDebugIdShift)
               | (reasonValue << config.deoptimizationReasonShift)
               | (actionValue << config.deoptimizationActionShift)));
   assert c.asInt() < 0;
   return c;
 }
 @Override
 public Value emitUncompress(
     Value pointer, HotSpotVMConfig.CompressEncoding encoding, boolean nonNull) {
   LIRKind inputKind = pointer.getLIRKind();
   assert inputKind.getPlatformKind() == AArch64Kind.DWORD;
   if (inputKind.isReference(0)) {
     // oop
     Variable result = newVariable(LIRKind.reference(AArch64Kind.QWORD));
     append(
         new AArch64HotSpotMove.UncompressPointer(
             result,
             asAllocatable(pointer),
             getProviders().getRegisters().getHeapBaseRegister().asValue(),
             encoding,
             nonNull));
     return result;
   } else {
     // metaspace pointer
     Variable result = newVariable(LIRKind.value(AArch64Kind.QWORD));
     AllocatableValue base = Value.ILLEGAL;
     if (encoding.base != 0) {
       base =
           emitLoadConstant(LIRKind.value(AArch64Kind.QWORD), JavaConstant.forLong(encoding.base));
     }
     append(
         new AArch64HotSpotMove.UncompressPointer(
             result, asAllocatable(pointer), base, encoding, nonNull));
     return result;
   }
 }
 public DeoptimizationAction decodeDeoptAction(JavaConstant constant) {
   HotSpotVMConfig config = runtime.getConfig();
   int actionValue =
       ((~constant.asInt()) >> config.deoptimizationActionShift)
           & intMaskRight(config.deoptimizationActionBits);
   DeoptimizationAction action = convertDeoptAction(actionValue);
   return action;
 }
 public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) {
   if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
     return null;
   }
   return ((HotSpotObjectConstant) constant).getType();
 }
 public int decodeDebugId(JavaConstant constant) {
   HotSpotVMConfig config = runtime.getConfig();
   return ((~constant.asInt()) >> config.deoptimizationDebugIdShift)
       & intMaskRight(config.deoptimizationDebugIdBits);
 }