Skip to content

Commit 007d87f

Browse files
committed
make sure StrengthenGraphsCounters are properly handled by the benchmarking infrastructure
1 parent e298802 commit 007d87f

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,11 @@ def _get_image_build_stats_rules(self, template: dict, keys: Sequence[str]) -> S
13481348
return [mx_benchmark.JsonFixedFileRule(f, template, keys) for f in stats_files]
13491349

13501350
def image_build_statistics_rules(self, benchmarks):
1351-
objects_list = ["total_array_store",
1351+
"""
1352+
This method generates rules to collect metrics produced by ImageBuildStatistics.
1353+
"""
1354+
# Corresponds to BytecodeExceptionKinds.
1355+
exception_kinds = ["total_array_store",
13521356
"total_assertion_error_nullary",
13531357
"total_assertion_error_object",
13541358
"total_class_cast",
@@ -1360,10 +1364,27 @@ def image_build_statistics_rules(self, benchmarks):
13601364
"total_null_pointer",
13611365
"total_out_of_bounds"]
13621366
metric_objects = ["total_devirtualized_invokes"]
1363-
for obj in objects_list:
1367+
for obj in exception_kinds:
13641368
metric_objects.append(obj + "_after_parse_canonicalization")
13651369
metric_objects.append(obj + "_before_high_tier")
13661370
metric_objects.append(obj + "_after_high_tier")
1371+
1372+
# Example for the bench server: 'invoke-static-after-strengthen-graphs'
1373+
strengthen_graphs_counters = [
1374+
"method",
1375+
"block",
1376+
"is_null",
1377+
"instance_of",
1378+
"prim_cmp",
1379+
"invoke_static",
1380+
"invoke_direct",
1381+
"invoke_indirect",
1382+
"load_field",
1383+
"constant",
1384+
]
1385+
for counter in strengthen_graphs_counters:
1386+
metric_objects.append("total_" + counter + "_before_strengthen_graphs")
1387+
metric_objects.append("total_" + counter + "_after_strengthen_graphs")
13671388
rules = []
13681389
for i in range(0, len(metric_objects)):
13691390
rules += self._get_image_build_stats_rules({

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ private static void reportNeverNullInstanceFields(BigBang bb) {
181181
}
182182
}
183183
ImageBuildStatistics imageBuildStats = ImageBuildStatistics.counters();
184-
imageBuildStats.insert("instancefield_neverNull").addAndGet(neverNull);
185-
imageBuildStats.insert("instancefield_canBeNull").addAndGet(canBeNull);
184+
imageBuildStats.createCounter("instancefield_neverNull").addAndGet(neverNull);
185+
imageBuildStats.createCounter("instancefield_canBeNull").addAndGet(canBeNull);
186186
}
187187

188188
@SuppressWarnings("try")
@@ -392,7 +392,7 @@ enum Counter {
392392

393393
ImageBuildStatistics imageBuildStats = ImageBuildStatistics.counters();
394394
for (Counter counter : Counter.values()) {
395-
values[counter.ordinal()] = imageBuildStats.insert(location + "_" + counter.name());
395+
values[counter.ordinal()] = imageBuildStats.createCounter(counter.name(), location);
396396
}
397397
}
398398

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/ImageBuildStatistics.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,19 +31,26 @@
3131
import java.util.concurrent.atomic.AtomicLong;
3232
import java.util.function.Consumer;
3333

34+
import org.graalvm.nativeimage.ImageSingletons;
35+
3436
import jdk.graal.compiler.debug.GraalError;
3537
import jdk.graal.compiler.nodes.extended.BytecodeExceptionNode;
3638
import jdk.graal.compiler.options.Option;
3739
import jdk.graal.compiler.options.OptionKey;
38-
import org.graalvm.nativeimage.ImageSingletons;
3940

41+
/**
42+
* This class collects detailed counters that are then saved into the image build statistics file.
43+
*/
4044
public class ImageBuildStatistics {
4145

4246
public static class Options {
4347
@Option(help = "Collect information during image build about devirtualized invokes and bytecode exceptions.")//
4448
public static final OptionKey<Boolean> CollectImageBuildStatistics = new OptionKey<>(false);
4549
}
4650

51+
/**
52+
* Phases in the compilation pipeline where the counters may be collected.
53+
*/
4754
public enum CheckCountLocation {
4855
BEFORE_STRENGTHEN_GRAPHS,
4956
AFTER_STRENGTHEN_GRAPHS,
@@ -54,7 +61,12 @@ public enum CheckCountLocation {
5461

5562
final TreeMap<String, AtomicLong> counters;
5663

57-
public AtomicLong insert(String key) {
64+
/**
65+
* Create a new counter based on the given unique {@code key}. Each counter is represented as an
66+
* {@link AtomicLong} so that it can be updated from multiple compilations happening in
67+
* parallel.
68+
*/
69+
public AtomicLong createCounter(String key) {
5870
AtomicLong result = new AtomicLong();
5971
var existing = counters.put(key, result);
6072
if (existing != null) {
@@ -63,6 +75,13 @@ public AtomicLong insert(String key) {
6375
return result;
6476
}
6577

78+
/**
79+
* @see #createCounter(String)
80+
*/
81+
public AtomicLong createCounter(String key, CheckCountLocation location) {
82+
return createCounter(getName(key, location));
83+
}
84+
6685
public void incDevirtualizedInvokeCounter() {
6786
counters.get(devirtualizedInvokes()).incrementAndGet();
6887
}

0 commit comments

Comments
 (0)