Skip to content

Commit 55bb550

Browse files
committed
[GR-50468] Record partition information for each object type in the heap breakdown
PullRequest: graal/21712
2 parents 1a8256c + 463790d commit 55bb550

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapPartition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public String getName() {
169169
return name;
170170
}
171171

172-
boolean isWritable() {
172+
@Override
173+
public boolean isWritable() {
173174
return writable;
174175
}
175176

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/image/ImageHeapPartition.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public interface ImageHeapPartition {
3232
/** Returns the name of the partition. */
3333
String getName();
3434

35+
/** Returns true if the partition is writable. */
36+
boolean isWritable();
37+
3538
/** Returns the offset at which this partition is allocated. */
3639
long getStartOffset();
3740

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.oracle.svm.core.code.RuntimeMetadataEncoding;
4141
import com.oracle.svm.core.config.ObjectLayout;
4242
import com.oracle.svm.core.configure.ConditionalRuntimeValue;
43+
import com.oracle.svm.core.image.ImageHeapPartition;
4344
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
4445
import com.oracle.svm.core.jdk.Resources;
4546
import com.oracle.svm.core.jdk.resources.ResourceStorageEntryBase;
@@ -105,6 +106,7 @@ protected void setTotalHeapSize(long totalHeapSize) {
105106
protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAreReachable) {
106107
HostedMetaAccess metaAccess = access.getHostedMetaAccess();
107108
ObjectLayout objectLayout = ImageSingletons.lookup(ObjectLayout.class);
109+
HeapBreakdownEntry.imageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();
108110

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

@@ -119,7 +121,9 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
119121
}
120122
long objectSize = o.getSize();
121123
totalObjectSize += objectSize;
122-
classToDataMap.computeIfAbsent(o.getClazz(), HeapBreakdownEntry::of).add(objectSize);
124+
HeapBreakdownEntry heapBreakdownEntry = classToDataMap.computeIfAbsent(o.getClazz(), HeapBreakdownEntry::of);
125+
heapBreakdownEntry.add(objectSize);
126+
heapBreakdownEntry.addPartition(o.getPartition());
123127
if (reportStringBytesConstant && o.getObject() instanceof String string) {
124128
byte[] bytes = getInternalByteArray(string);
125129
/* Ensure every byte[] is counted only once. */
@@ -201,6 +205,8 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
201205

202206
private static void addEntry(List<HeapBreakdownEntry> entries, HeapBreakdownEntry byteArrayEntry, HeapBreakdownEntry newData, long byteSize, int count) {
203207
newData.add(byteSize, count);
208+
// Assign byte[] entry's partitions to the new more specific byte[] entry.
209+
newData.copyPartitions(byteArrayEntry);
204210
entries.add(newData);
205211
byteArrayEntry.remove(byteSize, count);
206212
assert byteArrayEntry.byteSize >= 0 && byteArrayEntry.count >= 0;
@@ -215,14 +221,18 @@ private static byte[] getInternalByteArray(String string) {
215221
}
216222

217223
public abstract static class HeapBreakdownEntry {
224+
public static ImageHeapPartition[] imageHeapPartitions;
225+
218226
long byteSize;
219227
int count;
228+
int partitions = 0;
220229

221230
public static HeapBreakdownEntry of(HostedClass hostedClass) {
222231
return new HeapBreakdownEntryForClass(hostedClass.getJavaClass());
223232
}
224233

225234
public static HeapBreakdownEntry of(String name) {
235+
226236
return new HeapBreakdownEntryFixed(new SimpleHeapObjectKindName(name));
227237
}
228238

@@ -232,6 +242,22 @@ public static HeapBreakdownEntry of(String prefix, String name, String htmlAncho
232242

233243
public abstract HeapBreakdownLabel getLabel(int maxLength);
234244

245+
public ImageHeapPartition[] getPartitions() {
246+
ImageHeapPartition[] entryPartitions = new ImageHeapPartition[Integer.bitCount(partitions)];
247+
int i = 0;
248+
for (int j = 0; j < imageHeapPartitions.length; j++) {
249+
if (((partitions >> j) & 1) == 1) {
250+
entryPartitions[i] = imageHeapPartitions[j];
251+
i++;
252+
}
253+
}
254+
return entryPartitions;
255+
}
256+
257+
public HeapBreakdownLabel getLabel() {
258+
return getLabel(-1);
259+
}
260+
235261
public long getByteSize() {
236262
return byteSize;
237263
}
@@ -253,6 +279,21 @@ void remove(long subByteSize, int subCount) {
253279
this.byteSize -= subByteSize;
254280
this.count -= subCount;
255281
}
282+
283+
void addPartition(ImageHeapPartition newPartition) {
284+
int newPartitionMask = 1;
285+
for (ImageHeapPartition partition : imageHeapPartitions) {
286+
if (partition.equals(newPartition)) {
287+
break;
288+
}
289+
newPartitionMask <<= 1;
290+
}
291+
this.partitions |= newPartitionMask;
292+
}
293+
294+
public void copyPartitions(HeapBreakdownEntry sourceEntry) {
295+
this.partitions = sourceEntry.partitions;
296+
}
256297
}
257298

258299
static class HeapBreakdownEntryFixed extends HeapBreakdownEntry {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeap.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ public String getName() {
12001200
throw VMError.shouldNotReachHereAtRuntime(); // ExcludeFromJacocoGeneratedReport
12011201
}
12021202

1203+
@Override
1204+
public boolean isWritable() {
1205+
return false;
1206+
}
1207+
12031208
@Override
12041209
public long getSize() {
12051210
throw VMError.shouldNotReachHereAtRuntime(); // ExcludeFromJacocoGeneratedReport

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/WebImageJSHeapBreakdownProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class WebImageJSHeapBreakdownProvider extends HeapBreakdownProvider {
5353
*/
5454
@Override
5555
protected void calculate(FeatureImpl.BeforeImageWriteAccessImpl access, boolean resourcesAreReachable) {
56+
HeapBreakdownEntry.imageHeapPartitions = access.getImage().getHeap().getLayouter().getPartitions();
5657
long totalByteSize = 0;
5758
WebImageJSProviders providers = (WebImageJSProviders) ImageSingletons.lookup(WebImageProviders.class);
5859
ConstantIdentityMapping identityMapping = providers.typeControl().getConstantMap().identityMapping;

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/image/WasmGCPartition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public String getName() {
7171
return name;
7272
}
7373

74+
@Override
75+
public boolean isWritable() {
76+
return true;
77+
}
78+
7479
public boolean isPseudo() {
7580
return isPseudo;
7681
}

0 commit comments

Comments
 (0)