Skip to content

Commit 5f48270

Browse files
committed
[GR-28176] Merge Code Breakdown sizes before dumping.
PullRequest: graal/7865
2 parents 1c5f5dc + d9a3f83 commit 5f48270

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dashboard/CodeBreakdownJsonObject.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,21 @@
3636
import java.util.Arrays;
3737
import java.util.List;
3838
import java.util.Map;
39-
import java.util.stream.Collectors;
39+
import java.util.HashMap;
4040
import java.util.stream.Stream;
4141

4242
class CodeBreakdownJsonObject extends JsonObject {
4343

44-
private final Feature.AfterCompilationAccess access;
45-
46-
private static final String INFO_NAME = "name";
47-
private static final List<String> NAMES = Arrays.asList(INFO_NAME, "size");
44+
private boolean built = false;
45+
private Feature.AfterCompilationAccess access;
46+
private final Map<String, Integer> data = new HashMap<>();
4847

4948
CodeBreakdownJsonObject(Feature.AfterCompilationAccess access) {
5049
this.access = access;
5150
}
5251

5352
public Map<String, Integer> getData() {
54-
return ((FeatureImpl.AfterCompilationAccessImpl) access).getCompilationTasks().stream()
55-
.collect(Collectors.toMap(t -> t.method.format("%H.%n(%p) %r"), t -> t.result.getTargetCodeSize()));
53+
return data;
5654
}
5755

5856
@Override
@@ -62,15 +60,35 @@ Stream<String> getNames() {
6260

6361
@Override
6462
JsonValue getValue(String name) {
65-
return JsonArray.get(((FeatureImpl.AfterCompilationAccessImpl) access).getCompilationTasks().stream().map(MethodJsonObject::new));
63+
return JsonArray.get(data.entrySet().stream().map(MethodJsonObject::new));
64+
}
65+
66+
@Override
67+
protected void build() {
68+
if (built) {
69+
return;
70+
}
71+
for (CompileQueue.CompileTask task : ((FeatureImpl.AfterCompilationAccessImpl) access).getCompilationTasks()) {
72+
data.merge(task.method.format("%H.%n(%p) %r"), task.result.getTargetCodeSize(), Integer::sum);
73+
}
74+
access = null;
75+
built = true;
6676
}
6777

6878
private static class MethodJsonObject extends JsonObject {
79+
private static final String INFO_NAME = "name";
80+
private static final List<String> NAMES = Arrays.asList(INFO_NAME, "size");
6981

70-
private final CompileQueue.CompileTask task;
82+
private final String methodName;
83+
private final int methodSize;
84+
85+
MethodJsonObject(Map.Entry<String, Integer> entry) {
86+
this(entry.getKey(), entry.getValue());
87+
}
7188

72-
MethodJsonObject(CompileQueue.CompileTask task) {
73-
this.task = task;
89+
MethodJsonObject(String name, int size) {
90+
this.methodName = name;
91+
this.methodSize = size;
7492
}
7593

7694
@Override
@@ -80,9 +98,9 @@ Stream<String> getNames() {
8098

8199
@Override
82100
JsonValue getValue(String name) {
83-
return name == INFO_NAME
84-
? JsonString.get(task.method.format("%H.%n(%p) %r"))
85-
: JsonNumber.get(task.result.getTargetCodeSize());
101+
return INFO_NAME.equals(name)
102+
? JsonString.get(this.methodName)
103+
: JsonNumber.get(this.methodSize);
86104
}
87105
}
88106
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dashboard/HeapBreakdownJsonObject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
class HeapBreakdownJsonObject extends JsonObject {
4545

46-
private final Feature.AfterHeapLayoutAccess access;
46+
private Feature.AfterHeapLayoutAccess access;
4747
private boolean built = false;
4848
private static final String INFO_NAME = "name";
4949
private static final String INFO_SIZE = "size";
@@ -121,6 +121,7 @@ protected void build() {
121121
stats.size += info.getSize();
122122
stats.count += 1;
123123
}
124+
access = null;
124125
built = true;
125126
}
126127
}

0 commit comments

Comments
 (0)