@@ -65,6 +65,7 @@ public class HeapBreakdownProvider {
6565 private static final String BYTE_ARRAY_PREFIX = "byte[] for " ;
6666 private static final Field STRING_VALUE = ReflectionUtil .lookupField (String .class , "value" );
6767
68+ protected ImageHeapPartition [] allImageHeapPartitions ;
6869 private boolean reportStringBytes = true ;
6970 private int graphEncodingByteLength = -1 ;
7071
@@ -103,10 +104,16 @@ protected void setTotalHeapSize(long totalHeapSize) {
103104 this .totalHeapSize = totalHeapSize ;
104105 }
105106
107+ public ImageHeapPartition [] getAllImageHeapPartitions () {
108+ assert allImageHeapPartitions != null ;
109+ return allImageHeapPartitions ;
110+ }
111+
106112 protected void calculate (BeforeImageWriteAccessImpl access , boolean resourcesAreReachable ) {
113+ allImageHeapPartitions = access .getImage ().getHeap ().getLayouter ().getPartitions ();
114+
107115 HostedMetaAccess metaAccess = access .getHostedMetaAccess ();
108116 ObjectLayout objectLayout = ImageSingletons .lookup (ObjectLayout .class );
109- HeapBreakdownEntry .imageHeapPartitions = access .getImage ().getHeap ().getLayouter ().getPartitions ();
110117
111118 Map <HostedClass , HeapBreakdownEntry > classToDataMap = new HashMap <>();
112119
@@ -123,7 +130,7 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
123130 totalObjectSize += objectSize ;
124131 HeapBreakdownEntry heapBreakdownEntry = classToDataMap .computeIfAbsent (o .getClazz (), HeapBreakdownEntry ::of );
125132 heapBreakdownEntry .add (objectSize );
126- heapBreakdownEntry .addPartition (o .getPartition ());
133+ heapBreakdownEntry .addPartition (o .getPartition (), allImageHeapPartitions );
127134 if (reportStringBytesConstant && o .getObject () instanceof String string ) {
128135 byte [] bytes = getInternalByteArray (string );
129136 /* Ensure every byte[] is counted only once. */
@@ -221,8 +228,6 @@ private static byte[] getInternalByteArray(String string) {
221228 }
222229
223230 public abstract static class HeapBreakdownEntry {
224- public static ImageHeapPartition [] imageHeapPartitions ;
225-
226231 long byteSize ;
227232 int count ;
228233 int partitions = 0 ;
@@ -242,12 +247,12 @@ public static HeapBreakdownEntry of(String prefix, String name, String htmlAncho
242247
243248 public abstract HeapBreakdownLabel getLabel (int maxLength );
244249
245- public ImageHeapPartition [] getPartitions () {
250+ public ImageHeapPartition [] getPartitions (ImageHeapPartition [] allImageHeapPartitions ) {
246251 ImageHeapPartition [] entryPartitions = new ImageHeapPartition [Integer .bitCount (partitions )];
247252 int i = 0 ;
248- for (int j = 0 ; j < imageHeapPartitions .length ; j ++) {
253+ for (int j = 0 ; j < allImageHeapPartitions .length ; j ++) {
249254 if (((partitions >> j ) & 1 ) == 1 ) {
250- entryPartitions [i ] = imageHeapPartitions [j ];
255+ entryPartitions [i ] = allImageHeapPartitions [j ];
251256 i ++;
252257 }
253258 }
@@ -280,9 +285,9 @@ void remove(long subByteSize, int subCount) {
280285 this .count -= subCount ;
281286 }
282287
283- void addPartition (ImageHeapPartition newPartition ) {
288+ void addPartition (ImageHeapPartition newPartition , ImageHeapPartition [] allImageHeapPartitions ) {
284289 int newPartitionMask = 1 ;
285- for (ImageHeapPartition partition : imageHeapPartitions ) {
290+ for (ImageHeapPartition partition : allImageHeapPartitions ) {
286291 if (partition .equals (newPartition )) {
287292 break ;
288293 }
0 commit comments