package com.oracle.svm.hosted.meta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.oracle.graal.pointsto.meta.AnalysisType;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaField;
public class HostedInstanceClass extends HostedClass {
protected HostedField[] instanceFields;
protected int instanceSize;
protected boolean monitorFieldNeeded = false;
protected int monitorFieldOffset = 0;
public HostedInstanceClass(HostedUniverse universe, AnalysisType wrapped, JavaKind kind, JavaKind storageKind, HostedClass superClass, HostedInterface[] interfaces, boolean isCloneable) {
super(universe, wrapped, kind, storageKind, superClass, interfaces, isCloneable);
}
@Override
public boolean isInstanceClass() {
assert wrapped.isInstanceClass();
return true;
}
@Override
public boolean isArray() {
assert !wrapped.isArray();
return false;
}
@Override
public final HostedType getComponentType() {
return null;
}
@Override
public HostedType getBaseType() {
return this;
}
@Override
public int getArrayDimension() {
return 0;
}
@Override
public HostedField[] getInstanceFields(boolean includeSuperclasses) {
assert instanceFields != null;
if (includeSuperclasses && getSuperclass() != null) {
List<HostedField> fields = new ArrayList<>();
fields.addAll(Arrays.asList(getSuperclass().getInstanceFields(true)));
fields.addAll(Arrays.asList(instanceFields));
return fields.toArray(new HostedField[fields.size()]);
}
return instanceFields;
}
@Override
public ResolvedJavaField findInstanceFieldWithOffset(long offset, JavaKind expectedKind) {
assert offset >= 0;
for (HostedField field : instanceFields) {
if (field.getLocation() == offset && (expectedKind == null || field.getStorageKind() == expectedKind)) {
return field;
}
}
if (getSuperclass() != null) {
return getSuperclass().findInstanceFieldWithOffset(offset, expectedKind);
}
return null;
}
public int getInstanceSize() {
return instanceSize;
}
public boolean needMonitorField() {
return monitorFieldNeeded;
}
public void setNeedMonitorField() {
monitorFieldNeeded = true;
}
public int getMonitorFieldOffset() {
return monitorFieldOffset;
}
public void setMonitorFieldOffset(int monitorFieldOffset) {
assert this.monitorFieldOffset == 0 : "setting monitor field offset twice";
this.monitorFieldOffset = monitorFieldOffset;
}
}