@@ -114,7 +114,7 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
114
114
}
115
115
long objectSize = o .getSize ();
116
116
totalObjectSize += objectSize ;
117
- classToDataMap .computeIfAbsent (o .getClazz (), c -> new HeapBreakdownEntry ( c ) ).add (objectSize );
117
+ classToDataMap .computeIfAbsent (o .getClazz (), HeapBreakdownEntry :: of ).add (objectSize );
118
118
if (reportStringBytesConstant && o .getObject () instanceof String string ) {
119
119
byte [] bytes = getInternalByteArray (string );
120
120
/* Ensure every byte[] is counted only once. */
@@ -140,24 +140,24 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
140
140
long heapAlignmentSize = getTotalHeapSize () - totalObjectSize ;
141
141
assert heapAlignmentSize >= 0 : "Incorrect heap alignment detected: " + heapAlignmentSize ;
142
142
if (heapAlignmentSize > 0 ) {
143
- HeapBreakdownEntry heapAlignmentEntry = new HeapBreakdownEntry ("" , "heap alignment" , "#glossary-heap-alignment" );
143
+ HeapBreakdownEntry heapAlignmentEntry = HeapBreakdownEntry . of ("" , "heap alignment" , "#glossary-heap-alignment" );
144
144
heapAlignmentEntry .add (heapAlignmentSize );
145
145
entries .add (heapAlignmentEntry );
146
146
}
147
147
148
148
/* Extract byte[] for Strings. */
149
149
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 );
151
151
}
152
152
/* Extract byte[] for code info. */
153
153
List <Integer > codeInfoByteArrayLengths = CodeInfoTable .getCurrentLayerImageCodeCache ().getTotalByteArrayLengths ();
154
154
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 ());
156
156
/* Extract byte[] for metadata. */
157
157
int metadataByteLength = ImageSingletons .lookup (RuntimeMetadataDecoder .class ).getMetadataByteLength ();
158
158
if (metadataByteLength > 0 ) {
159
159
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 );
161
161
}
162
162
ProgressReporter reporter = ProgressReporter .singleton ();
163
163
long resourcesByteArraySize = 0 ;
@@ -177,19 +177,19 @@ protected void calculate(BeforeImageWriteAccessImpl access, boolean resourcesAre
177
177
}
178
178
}
179
179
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 );
181
181
}
182
182
}
183
183
reporter .recordJsonMetric (ImageDetailKey .RESOURCE_SIZE_BYTES , resourcesByteArraySize );
184
184
/* Extract byte[] for graph encodings. */
185
185
if (graphEncodingByteLength >= 0 ) {
186
186
long graphEncodingSize = objectLayout .getArraySize (JavaKind .Byte , graphEncodingByteLength , true );
187
187
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 );
189
189
}
190
190
/* Add remaining byte[]. */
191
191
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 );
193
193
assert byteArrayEntry .byteSize == 0 && byteArrayEntry .count == 0 ;
194
194
setBreakdownEntries (entries );
195
195
}
@@ -209,26 +209,23 @@ private static byte[] getInternalByteArray(String string) {
209
209
}
210
210
}
211
211
212
- public static class HeapBreakdownEntry {
213
- final HeapBreakdownLabel label ;
212
+ public abstract static class HeapBreakdownEntry {
214
213
long byteSize ;
215
214
int count ;
216
215
217
- public HeapBreakdownEntry (HostedClass hostedClass ) {
218
- this (hostedClass .toJavaName ( true ));
216
+ public static HeapBreakdownEntry of (HostedClass hostedClass ) {
217
+ return new HeapBreakdownEntryForClass (hostedClass .getJavaClass ( ));
219
218
}
220
219
221
- public HeapBreakdownEntry (String name ) {
222
- label = new SimpleHeapObjectKindName (name );
220
+ public static HeapBreakdownEntry of (String name ) {
221
+ return new HeapBreakdownEntryFixed ( new SimpleHeapObjectKindName (name ) );
223
222
}
224
223
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 ) );
227
226
}
228
227
229
- public HeapBreakdownLabel getLabel () {
230
- return label ;
231
- }
228
+ public abstract HeapBreakdownLabel getLabel (int maxLength );
232
229
233
230
public long getByteSize () {
234
231
return byteSize ;
@@ -253,6 +250,41 @@ void remove(long subByteSize, int subCount) {
253
250
}
254
251
}
255
252
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
+
256
288
public interface HeapBreakdownLabel {
257
289
String renderToString (LinkStrategy linkStrategy );
258
290
}
0 commit comments