Skip to content

Commit 172f40c

Browse files
committed
[GR-44985] Extract breakdown providers from ProgressReporter.
PullRequest: graal/15130
2 parents 3451dac + 6403a69 commit 172f40c

File tree

11 files changed

+395
-174
lines changed

11 files changed

+395
-174
lines changed

docs/reference-manual/native-image/BuildOutput.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ The total size of all `byte[]` objects that are neither used for `java.lang.Stri
200200
Therefore, this can also include `byte[]` objects from application code.
201201
202202
##### <a name="glossary-embedded-resources"></a>Embedded Resources Stored in `byte[]`
203-
The total size of all `byte[]` objects used for storing resources (for example, files accessed via `Class.getResource()`) within the native binary. The number of resources is shown in the [Heap](#glossary-image-heap) section.
203+
The total size of all `byte[]` objects used for storing resources (for example, files accessed via `Class.getResource()`) within the native binary.
204+
The number of resources is shown in the [Heap](#glossary-image-heap) section.
204205
205206
##### <a name="glossary-code-metadata"></a>Code Metadata Stored in `byte[]`
206207
The total size of all `byte[]` objects used for metadata for the [code area](#glossary-code-area).
@@ -215,6 +216,11 @@ The total size of all `byte[]` objects used for graph encodings.
215216
These encodings are a result of [runtime compiled methods](#glossary-runtime-methods).
216217
Therefore, reducing the number of such methods also reduces the size of corresponding graph encodings.
217218
219+
##### <a name="glossary-heap-alignment"></a>Heap Alignment
220+
Additional space reserved to align the heap for the [selected garbage collector](#glossary-gc).
221+
The heap alignment may also contain GC-specific data structures.
222+
Its size can therefore only be influenced by switching to a different garbage collector.
223+
218224
#### <a name="glossary-debug-info"></a>Debug Info
219225
The total size of generated debug information (if enabled).
220226

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package com.oracle.svm.core.code;
2626

27+
import java.util.List;
28+
2729
import org.graalvm.compiler.word.Word;
2830
import org.graalvm.nativeimage.ImageSingletons;
2931
import org.graalvm.nativeimage.Platform;
@@ -131,8 +133,8 @@ public HostedImageCodeInfo getHostedImageCodeInfo() {
131133
return hostedImageCodeInfo;
132134
}
133135

134-
public long getTotalByteArraySize() {
135-
return codeInfoIndex.length + codeInfoEncodings.length + referenceMapEncoding.length + frameInfoEncodings.length;
136+
public List<Integer> getTotalByteArrayLengths() {
137+
return List.of(codeInfoIndex.length, codeInfoEncodings.length, referenceMapEncoding.length, frameInfoEncodings.length);
136138
}
137139

138140
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/ReflectionMetadataDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public interface ReflectionMetadataDecoder {
6363

6464
boolean isNegative(int modifiers);
6565

66-
long getMetadataByteLength();
66+
int getMetadataByteLength();
6767

6868
class ElementDescriptor {
6969
private final Class<?> declaringClass;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public boolean isNegative(int modifiers) {
245245
}
246246

247247
@Override
248-
public long getMetadataByteLength() {
248+
public int getMetadataByteLength() {
249249
return ImageSingletons.lookup(ReflectionMetadataEncoding.class).getEncoding().length;
250250
}
251251

@@ -307,7 +307,7 @@ private static <T extends Throwable> void decodeAndThrowError(int index) throws
307307
* StringIndex name
308308
* }
309309
* </pre>
310-
*
310+
*
311311
* Negative query field encoding.
312312
*
313313
* <pre>
@@ -466,7 +466,7 @@ private static Object decodeField(UnsafeArrayTypeReader buf, Class<?> declaringC
466466
* ClassIndex[] parameterTypes
467467
* }
468468
* </pre>
469-
*
469+
*
470470
* Negative query constructor encoding.
471471
*
472472
* <pre>

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/LegacyRuntimeCompilationFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
import com.oracle.svm.graal.GraalSupport;
8282
import com.oracle.svm.graal.meta.SubstrateMethod;
8383
import com.oracle.svm.hosted.FeatureImpl;
84-
import com.oracle.svm.hosted.ProgressReporter;
84+
import com.oracle.svm.hosted.HeapBreakdownProvider;
8585
import com.oracle.svm.hosted.code.DeoptimizationUtils;
8686
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
8787
import com.oracle.svm.hosted.meta.HostedMethod;
@@ -489,7 +489,7 @@ public void beforeCompilation(BeforeCompilationAccess c) {
489489
}
490490
}
491491

492-
ProgressReporter.singleton().setGraphEncodingByteLength(graphEncoder.getEncoding().length);
492+
HeapBreakdownProvider.singleton().setGraphEncodingByteLength(graphEncoder.getEncoding().length);
493493
GraalSupport.setGraphEncoding(config, graphEncoder.getEncoding(), graphEncoder.getObjects(), graphEncoder.getNodeClasses());
494494

495495
objectReplacer.setMethodsImplementations();

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/ParseOnceRuntimeCompilationFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
import com.oracle.svm.graal.GraalSupport;
110110
import com.oracle.svm.graal.meta.SubstrateMethod;
111111
import com.oracle.svm.hosted.FeatureImpl;
112-
import com.oracle.svm.hosted.ProgressReporter;
112+
import com.oracle.svm.hosted.HeapBreakdownProvider;
113113
import com.oracle.svm.hosted.RuntimeCompilationSupport;
114114
import com.oracle.svm.hosted.SVMHost;
115115
import com.oracle.svm.hosted.analysis.SVMParsingSupport;
@@ -630,7 +630,7 @@ private void encodeRuntimeCompiledMethods() {
630630
}
631631
}
632632

633-
ProgressReporter.singleton().setGraphEncodingByteLength(graphEncoder.getEncoding().length);
633+
HeapBreakdownProvider.singleton().setGraphEncodingByteLength(graphEncoder.getEncoding().length);
634634
GraalSupport.setGraphEncoding(null, graphEncoder.getEncoding(), graphEncoder.getObjects(), graphEncoder.getNodeClasses());
635635

636636
objectReplacer.setMethodsImplementations();
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.hosted;
26+
27+
import java.security.CodeSource;
28+
import java.util.Collection;
29+
import java.util.Collections;
30+
import java.util.HashMap;
31+
import java.util.Map;
32+
33+
import org.graalvm.nativeimage.ImageSingletons;
34+
35+
import com.oracle.svm.hosted.code.CompileQueue.CompileTask;
36+
import com.oracle.svm.hosted.meta.HostedMethod;
37+
38+
class CodeBreakdownProvider {
39+
private final Map<String, Long> codeBreakdown;
40+
41+
CodeBreakdownProvider(Collection<CompileTask> compilationTasks) {
42+
Map<String, Long> nameToSizeMap = new HashMap<>();
43+
for (CompileTask task : compilationTasks) {
44+
String key = null;
45+
Class<?> javaClass = task.method.getDeclaringClass().getJavaClass();
46+
Module module = javaClass.getModule();
47+
if (module.isNamed()) {
48+
key = module.getName();
49+
if ("org.graalvm.nativeimage.builder".equals(key)) {
50+
key = "svm.jar (Native Image)";
51+
}
52+
} else {
53+
key = findJARFile(javaClass);
54+
if (key == null) {
55+
key = findPackageOrClassName(task.method);
56+
}
57+
}
58+
nameToSizeMap.merge(key, (long) task.result.getTargetCodeSize(), Long::sum);
59+
}
60+
codeBreakdown = Collections.unmodifiableMap(nameToSizeMap);
61+
}
62+
63+
public static Map<String, Long> get() {
64+
return ImageSingletons.lookup(CodeBreakdownProvider.class).codeBreakdown;
65+
}
66+
67+
private static String findJARFile(Class<?> javaClass) {
68+
CodeSource codeSource = javaClass.getProtectionDomain().getCodeSource();
69+
if (codeSource != null && codeSource.getLocation() != null) {
70+
String path = codeSource.getLocation().getPath();
71+
if (path.endsWith(".jar")) {
72+
// Use String API to determine basename of path to handle both / and \.
73+
return path.substring(Math.max(path.lastIndexOf('/') + 1, path.lastIndexOf('\\') + 1));
74+
}
75+
}
76+
return null;
77+
}
78+
79+
private static String findPackageOrClassName(HostedMethod method) {
80+
String qualifier = method.format("%H");
81+
int lastDotIndex = qualifier.lastIndexOf('.');
82+
if (lastDotIndex > 0) {
83+
qualifier = qualifier.substring(0, lastDotIndex);
84+
}
85+
return qualifier;
86+
}
87+
}

0 commit comments

Comments
 (0)