@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(); } }
@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(); } }
public ResolvedJavaType lookupJavaType(Constant constant) { if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) { return null; } Object o = HotSpotObjectConstant.asObject(constant); return HotSpotResolvedObjectType.fromClass(o.getClass()); }
public ResolvedJavaField lookupJavaField(Field reflectionField) { String name = reflectionField.getName(); Class<?> fieldHolder = reflectionField.getDeclaringClass(); Class<?> fieldType = reflectionField.getType(); // java.lang.reflect.Field's modifiers should be enough here since VM internal modifier bits // are not used (yet). final int modifiers = reflectionField.getModifiers(); final long offset = Modifier.isStatic(modifiers) ? UNSAFE.staticFieldOffset(reflectionField) : UNSAFE.objectFieldOffset(reflectionField); HotSpotResolvedObjectType holder = fromObjectClass(fieldHolder); JavaType type = runtime.fromClass(fieldType); if (offset != -1) { HotSpotResolvedObjectType resolved = holder; return resolved.createField(name, type, offset, modifiers); } else { throw new JVMCIError("unresolved field %s", reflectionField); } }
public ResolvedJavaField lookupJavaField(Field reflectionField) { String name = reflectionField.getName(); Class<?> fieldHolder = reflectionField.getDeclaringClass(); Class<?> fieldType = reflectionField.getType(); // java.lang.reflect.Field's modifiers should be enough here since VM internal modifier bits // are not used (yet). final int modifiers = reflectionField.getModifiers(); final long offset = Modifier.isStatic(modifiers) ? unsafe.staticFieldOffset(reflectionField) : unsafe.objectFieldOffset(reflectionField); ResolvedJavaType holder = HotSpotResolvedObjectType.fromClass(fieldHolder); ResolvedJavaType type = HotSpotResolvedObjectType.fromClass(fieldType); if (offset != -1) { HotSpotResolvedObjectType resolved = (HotSpotResolvedObjectType) holder; return resolved.createField(name, type, offset, modifiers); } else { throw GraalInternalError.shouldNotReachHere("unresolved field " + reflectionField); } }
private RawItemProfile<ResolvedJavaType> getRawTypeProfile( HotSpotMethodData data, int position) { int typeProfileWidth = config.typeProfileWidth; ResolvedJavaType[] types = new ResolvedJavaType[typeProfileWidth]; long[] counts = new long[typeProfileWidth]; long totalCount = 0; int entries = 0; outer: for (int i = 0; i < typeProfileWidth; i++) { long receiverKlass = data.readWord(position, getTypeOffset(i)); if (receiverKlass != 0) { ResolvedJavaType klass = HotSpotResolvedObjectType.fromMetaspaceKlass(receiverKlass); long count = data.readUnsignedInt(position, getTypeCountOffset(i)); /* * Because of races in the profile collection machinery it's possible for a * class to appear multiple times so merge them to make the profile look * rational. */ for (int j = 0; j < entries; j++) { if (types[j].equals(klass)) { totalCount += count; counts[j] += count; continue outer; } } types[entries] = klass; totalCount += count; counts[entries] = count; entries++; } } totalCount += getTypesNotRecordedExecutionCount(data, position); return new RawItemProfile<>(entries, types, counts, totalCount); }
public ResolvedJavaType lookupJavaType(Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Class parameter was null"); } return HotSpotResolvedObjectType.fromClass(clazz); }