Пример #1
0
 public ResolvedJavaType lookupJavaType(Constant constant) {
   if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
     return null;
   }
   Object o = HotSpotObjectConstant.asObject(constant);
   return HotSpotResolvedObjectType.fromClass(o.getClass());
 }
Пример #2
0
  @Override
  public long getMemorySize(Constant constant) {
    if (constant.getKind() == Kind.Object) {
      HotSpotResolvedObjectType lookupJavaType =
          (HotSpotResolvedObjectType) this.lookupJavaType(constant);

      if (lookupJavaType == null) {
        return 0;
      } else {
        if (lookupJavaType.isArray()) {
          // TODO(tw): Add compressed pointer support.
          int length = Array.getLength(HotSpotObjectConstant.asObject(constant));
          ResolvedJavaType elementType = lookupJavaType.getComponentType();
          Kind elementKind = elementType.getKind();
          final int headerSize = HotSpotGraalRuntime.getArrayBaseOffset(elementKind);
          int sizeOfElement = HotSpotGraalRuntime.runtime().getTarget().getSizeInBytes(elementKind);
          int alignment = HotSpotGraalRuntime.runtime().getTarget().wordSize;
          int log2ElementSize = CodeUtil.log2(sizeOfElement);
          return NewObjectSnippets.computeArrayAllocationSize(
              length, alignment, headerSize, log2ElementSize);
        }
        return lookupJavaType.instanceSize();
      }
    } else {
      return constant.getKind().getByteCount();
    }
  }