4040import com .oracle .svm .core .code .RuntimeMetadataEncoding ;
4141import com .oracle .svm .core .config .ObjectLayout ;
4242import com .oracle .svm .core .configure .ConditionalRuntimeValue ;
43+ import com .oracle .svm .core .image .ImageHeapPartition ;
4344import com .oracle .svm .core .imagelayer .ImageLayerBuildingSupport ;
4445import com .oracle .svm .core .jdk .Resources ;
4546import 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 {
0 commit comments