Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caclulate overall alignment when computing member layout #573

Merged
merged 1 commit into from Jun 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugins/layout/src/main/java/org/qbicc/plugin/layout/Layout.java
Expand Up @@ -413,10 +413,13 @@ public LayoutInfo getInstanceLayoutInfo(DefinedTypeDefinition type) {
}
LoadedTypeDefinition superClass = validated.getSuperClass();
LayoutInfo superLayout;
int minAlignment;
if (superClass != null) {
superLayout = getInstanceLayoutInfo(superClass);
minAlignment = superLayout.getCompoundType().getAlign();
} else {
superLayout = null;
minAlignment = ctxt.getTypeSystem().getPointerAlignment(); // All objects have at least pointer alignment.
}
BitSet allocated = new BitSet();
if (superLayout != null) {
Expand All @@ -430,13 +433,17 @@ public LayoutInfo getInstanceLayoutInfo(DefinedTypeDefinition type) {
if (field.isStatic()) {
continue;
}
fieldToMember.put(field, computeMember(allocated, field));
CompoundType.Member member = computeMember(allocated, field);
if (member.getAlign() > minAlignment) {
minAlignment = member.getAlign();
}
fieldToMember.put(field, member);
}
int size = allocated.length();
CompoundType.Member[] membersArray = fieldToMember.values().toArray(CompoundType.Member[]::new);
Arrays.sort(membersArray);
List<CompoundType.Member> membersList = List.of(membersArray);
CompoundType compoundType = ctxt.getTypeSystem().getCompoundType(CompoundType.Tag.NONE, type.getInternalName().replace('/', '.'), size, 1, () -> membersList);
CompoundType compoundType = ctxt.getTypeSystem().getCompoundType(CompoundType.Tag.NONE, type.getInternalName().replace('/', '.'), size, minAlignment, () -> membersList);
layoutInfo = new LayoutInfo(allocated, compoundType, fieldToMember);
LayoutInfo appearing = instanceLayouts.putIfAbsent(validated, layoutInfo);
return appearing != null ? appearing : layoutInfo;
Expand Down