Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class HeapBreakdownProvider {
private static final String BYTE_ARRAY_PREFIX = "byte[] for ";
private static final Field STRING_VALUE = ReflectionUtil.lookupField(String.class, "value");

protected ImageHeapPartition[] allImageHeapPartitions;
private boolean reportStringBytes = true;
private int graphEncodingByteLength = -1;

Expand Down Expand Up @@ -103,10 +104,16 @@ protected void setTotalHeapSize(long totalHeapSize) {
this.totalHeapSize = totalHeapSize;
}

public ImageHeapPartition[] getAllImageHeapPartitions() {
assert allImageHeapPartitions != null;
return allImageHeapPartitions;
}

protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAreReachable) {
allImageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();

HostedMetaAccess metaAccess = access.getHostedMetaAccess();
ObjectLayout objectLayout = ImageSingletons.lookup(ObjectLayout.class);
HeapBreakdownEntry.imageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();

Map<HostedClass, HeapBreakdownEntry> classToDataMap = new HashMap<>();

Expand All @@ -123,7 +130,7 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
totalObjectSize += objectSize;
HeapBreakdownEntry heapBreakdownEntry = classToDataMap.computeIfAbsent(o.getClazz(), HeapBreakdownEntry::of);
heapBreakdownEntry.add(objectSize);
heapBreakdownEntry.addPartition(o.getPartition());
heapBreakdownEntry.addPartition(o.getPartition(), allImageHeapPartitions);
if (reportStringBytesConstant && o.getObject() instanceof String string) {
byte[] bytes = getInternalByteArray(string);
/* Ensure every byte[] is counted only once. */
Expand Down Expand Up @@ -221,8 +228,6 @@ private static byte[] getInternalByteArray(String string) {
}

public abstract static class HeapBreakdownEntry {
public static ImageHeapPartition[] imageHeapPartitions;

long byteSize;
int count;
int partitions = 0;
Expand All @@ -242,12 +247,12 @@ public static HeapBreakdownEntry of(String prefix, String name, String htmlAncho

public abstract HeapBreakdownLabel getLabel(int maxLength);

public ImageHeapPartition[] getPartitions() {
public ImageHeapPartition[] getPartitions(ImageHeapPartition[] allImageHeapPartitions) {
ImageHeapPartition[] entryPartitions = new ImageHeapPartition[Integer.bitCount(partitions)];
int i = 0;
for (int j = 0; j < imageHeapPartitions.length; j++) {
for (int j = 0; j < allImageHeapPartitions.length; j++) {
if (((partitions >> j) & 1) == 1) {
entryPartitions[i] = imageHeapPartitions[j];
entryPartitions[i] = allImageHeapPartitions[j];
i++;
}
}
Expand Down Expand Up @@ -280,9 +285,9 @@ void remove(long subByteSize, int subCount) {
this.count -= subCount;
}

void addPartition(ImageHeapPartition newPartition) {
void addPartition(ImageHeapPartition newPartition, ImageHeapPartition[] allImageHeapPartitions) {
int newPartitionMask = 1;
for (ImageHeapPartition partition : imageHeapPartitions) {
for (ImageHeapPartition partition : allImageHeapPartitions) {
if (partition.equals(newPartition)) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class WebImageJSHeapBreakdownProvider extends HeapBreakdownProvider {
*/
@Override
protected void calculate(FeatureImpl.BeforeImageWriteAccessImpl access, boolean resourcesAreReachable) {
HeapBreakdownEntry.imageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();
allImageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();

long totalByteSize = 0;
WebImageJSProviders providers = (WebImageJSProviders) ImageSingletons.lookup(WebImageProviders.class);
ConstantIdentityMapping identityMapping = providers.typeControl().getConstantMap().identityMapping;
Expand Down