@@ -114,7 +114,7 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
114114 }
115115 long objectSize = o .getSize ();
116116 totalObjectSize += objectSize ;
117- classToDataMap .computeIfAbsent (o .getClazz (), c -> new HeapBreakdownEntry ( c ) ).add (objectSize );
117+ classToDataMap .computeIfAbsent (o .getClazz (), HeapBreakdownEntry :: of ).add (objectSize );
118118 if (reportStringBytesConstant && o .getObject () instanceof String string ) {
119119 byte [] bytes = getInternalByteArray (string );
120120 /* Ensure every byte[] is counted only once. */
@@ -140,24 +140,24 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
140140 long heapAlignmentSize = getTotalHeapSize () - totalObjectSize ;
141141 assert heapAlignmentSize >= 0 : "Incorrect heap alignment detected: " + heapAlignmentSize ;
142142 if (heapAlignmentSize > 0 ) {
143- HeapBreakdownEntry heapAlignmentEntry = new HeapBreakdownEntry ("" , "heap alignment" , "#glossary-heap-alignment" );
143+ HeapBreakdownEntry heapAlignmentEntry = HeapBreakdownEntry . of ("" , "heap alignment" , "#glossary-heap-alignment" );
144144 heapAlignmentEntry .add (heapAlignmentSize );
145145 entries .add (heapAlignmentEntry );
146146 }
147147
148148 /* Extract byte[] for Strings. */
149149 if (stringByteArrayTotalSize > 0 ) {
150- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX + "java.lang.String " ), stringByteArrayTotalSize , stringByteArrayTotalCount );
150+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX + "string data " ), stringByteArrayTotalSize , stringByteArrayTotalCount );
151151 }
152152 /* Extract byte[] for code info. */
153153 List <Integer > codeInfoByteArrayLengths = CodeInfoTable .getCurrentLayerImageCodeCache ().getTotalByteArrayLengths ();
154154 long codeInfoSize = codeInfoByteArrayLengths .stream ().map (l -> objectLayout .getArraySize (JavaKind .Byte , l , true )).reduce (0L , Long ::sum );
155- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX , "code metadata" , "#glossary-code-metadata" ), codeInfoSize , codeInfoByteArrayLengths .size ());
155+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX , "code metadata" , "#glossary-code-metadata" ), codeInfoSize , codeInfoByteArrayLengths .size ());
156156 /* Extract byte[] for metadata. */
157157 int metadataByteLength = ImageSingletons .lookup (RuntimeMetadataDecoder .class ).getMetadataByteLength ();
158158 if (metadataByteLength > 0 ) {
159159 long metadataSize = objectLayout .getArraySize (JavaKind .Byte , metadataByteLength , true );
160- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX , "reflection metadata" , "#glossary-reflection-metadata" ), metadataSize , 1 );
160+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX , "reflection metadata" , "#glossary-reflection-metadata" ), metadataSize , 1 );
161161 }
162162 ProgressReporter reporter = ProgressReporter .singleton ();
163163 long resourcesByteArraySize = 0 ;
@@ -177,19 +177,19 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
177177 }
178178 }
179179 if (resourcesByteArraySize > 0 ) {
180- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX , "embedded resources" , "#glossary-embedded-resources" ), resourcesByteArraySize , resourcesByteArrayCount );
180+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX , "embedded resources" , "#glossary-embedded-resources" ), resourcesByteArraySize , resourcesByteArrayCount );
181181 }
182182 }
183183 reporter .recordJsonMetric (ImageDetailKey .RESOURCE_SIZE_BYTES , resourcesByteArraySize );
184184 /* Extract byte[] for graph encodings. */
185185 if (graphEncodingByteLength >= 0 ) {
186186 long graphEncodingSize = objectLayout .getArraySize (JavaKind .Byte , graphEncodingByteLength , true );
187187 reporter .recordJsonMetric (ImageDetailKey .GRAPH_ENCODING_SIZE , graphEncodingSize );
188- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX , "graph encodings" , "#glossary-graph-encodings" ), graphEncodingSize , 1 );
188+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX , "graph encodings" , "#glossary-graph-encodings" ), graphEncodingSize , 1 );
189189 }
190190 /* Add remaining byte[]. */
191191 assert byteArrayEntry .byteSize >= 0 && byteArrayEntry .count >= 0 ;
192- addEntry (entries , byteArrayEntry , new HeapBreakdownEntry (BYTE_ARRAY_PREFIX , "general heap data" , "#glossary-general-heap-data" ), byteArrayEntry .byteSize , byteArrayEntry .count );
192+ addEntry (entries , byteArrayEntry , HeapBreakdownEntry . of (BYTE_ARRAY_PREFIX , "general heap data" , "#glossary-general-heap-data" ), byteArrayEntry .byteSize , byteArrayEntry .count );
193193 assert byteArrayEntry .byteSize == 0 && byteArrayEntry .count == 0 ;
194194 setBreakdownEntries (entries );
195195 }
@@ -209,26 +209,23 @@ private static byte[] getInternalByteArray(String string) {
209209 }
210210 }
211211
212- public static class HeapBreakdownEntry {
213- final HeapBreakdownLabel label ;
212+ public abstract static class HeapBreakdownEntry {
214213 long byteSize ;
215214 int count ;
216215
217- public HeapBreakdownEntry (HostedClass hostedClass ) {
218- this (hostedClass .toJavaName ( true ));
216+ public static HeapBreakdownEntry of (HostedClass hostedClass ) {
217+ return new HeapBreakdownEntryForClass (hostedClass .getJavaClass ( ));
219218 }
220219
221- public HeapBreakdownEntry (String name ) {
222- label = new SimpleHeapObjectKindName (name );
220+ public static HeapBreakdownEntry of (String name ) {
221+ return new HeapBreakdownEntryFixed ( new SimpleHeapObjectKindName (name ) );
223222 }
224223
225- HeapBreakdownEntry (String prefix , String name , String htmlAnchor ) {
226- label = new LinkyHeapObjectKindName (prefix , name , htmlAnchor );
224+ public static HeapBreakdownEntry of (String prefix , String name , String htmlAnchor ) {
225+ return new HeapBreakdownEntryFixed ( new LinkyHeapObjectKindName (prefix , name , htmlAnchor ) );
227226 }
228227
229- public HeapBreakdownLabel getLabel () {
230- return label ;
231- }
228+ public abstract HeapBreakdownLabel getLabel (int maxLength );
232229
233230 public long getByteSize () {
234231 return byteSize ;
@@ -253,6 +250,41 @@ void remove(long subByteSize, int subCount) {
253250 }
254251 }
255252
253+ static class HeapBreakdownEntryFixed extends HeapBreakdownEntry {
254+
255+ private final HeapBreakdownLabel label ;
256+
257+ HeapBreakdownEntryFixed (HeapBreakdownLabel label ) {
258+ this .label = label ;
259+ }
260+
261+ @ Override
262+ public HeapBreakdownLabel getLabel (int unused ) {
263+ return label ;
264+ }
265+ }
266+
267+ static class HeapBreakdownEntryForClass extends HeapBreakdownEntry {
268+
269+ private final Class <?> clazz ;
270+
271+ HeapBreakdownEntryForClass (Class <?> clazz ) {
272+ this .clazz = clazz ;
273+ }
274+
275+ @ Override
276+ public HeapBreakdownLabel getLabel (int maxLength ) {
277+ if (maxLength >= 0 ) {
278+ String moduleNamePrefix = ProgressReporterUtils .moduleNamePrefix (clazz .getModule ());
279+ int maxLengthClassName = maxLength - moduleNamePrefix .length ();
280+ String truncatedClassName = ProgressReporterUtils .truncateFQN (clazz .getTypeName (), maxLengthClassName );
281+ return new SimpleHeapObjectKindName (moduleNamePrefix + truncatedClassName );
282+ } else {
283+ return new SimpleHeapObjectKindName (clazz .getTypeName ());
284+ }
285+ }
286+ }
287+
256288 public interface HeapBreakdownLabel {
257289 String renderToString (LinkStrategy linkStrategy );
258290 }
0 commit comments