*/
public class CurrentLayouter implements Layouter {
@Override
public ClassLayout layout(ClassData data) {
CurrentDataModel model = new CurrentDataModel();
if (data.isArray()) {
// special case of arrays
try {
int base = VMSupport.U.arrayBaseOffset(Class.forName(data.arrayClass()));
int scale = VMSupport.U.arrayIndexScale(Class.forName(data.arrayClass()));
int instanceSize = VMSupport.align(base + (data.arrayLength()) * scale, 8);
SortedSet<FieldLayout> result = new TreeSet<FieldLayout>();
result.add(new FieldLayout(FieldData.create(data.arrayClass(), "length", "int"), model.headerSize(), model.sizeOf("int")));
result.add(new FieldLayout(FieldData.create(data.arrayClass(), "<elements>", data.arrayComponentType()), base, scale * data.arrayLength()));
return new ClassLayout(data, result, model.headerSize(), instanceSize, false);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Should not reach here.", e);
}
}
Collection<FieldData> fields = data.fields();
SortedSet<FieldLayout> result = new TreeSet<FieldLayout>();
for (FieldData f : fields) {
result.add(new FieldLayout(f, f.vmOffset(), model.sizeOf(f.typeClass())));
}
int instanceSize;
if (result.isEmpty()) {
instanceSize = VMSupport.align(model.headerSize());
} else {
FieldLayout f = result.last();
instanceSize = VMSupport.align(f.offset() + f.size());
}
return new ClassLayout(data, result, model.headerSize(), instanceSize, true);
}