Skip to content

Commit 6a1c8ec

Browse files
committed
[GR-70983] Make sure StrengthenGraphsCounters are collected by the benchmarking infrastructure
PullRequest: graal/22451
2 parents 5d9fd3e + 007d87f commit 6a1c8ec

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
@@ -1469,7 +1469,11 @@ def _get_image_build_stats_rules(self, template: dict, keys: Sequence[str]) -> S
14691469
return [mx_benchmark.JsonFixedFileRule(f, template, keys) for f in stats_files]
14701470

14711471
def image_build_statistics_rules(self, benchmarks):
1472-
objects_list = ["total_array_store",
1472+
"""
1473+
This method generates rules to collect metrics produced by ImageBuildStatistics.
1474+
"""
1475+
# Corresponds to BytecodeExceptionKinds.
1476+
exception_kinds = ["total_array_store",
14731477
"total_assertion_error_nullary",
14741478
"total_assertion_error_object",
14751479
"total_class_cast",
@@ -1481,10 +1485,27 @@ def image_build_statistics_rules(self, benchmarks):
14811485
"total_null_pointer",
14821486
"total_out_of_bounds"]
14831487
metric_objects = ["total_devirtualized_invokes"]
1484-
for obj in objects_list:
1488+
for obj in exception_kinds:
14851489
metric_objects.append(obj + "_after_parse_canonicalization")
14861490
metric_objects.append(obj + "_before_high_tier")
14871491
metric_objects.append(obj + "_after_high_tier")
1492+
1493+
# Example for the bench server: 'invoke-static-after-strengthen-graphs'
1494+
strengthen_graphs_counters = [
1495+
"method",
1496+
"block",
1497+
"is_null",
1498+
"instance_of",
1499+
"prim_cmp",
1500+
"invoke_static",
1501+
"invoke_direct",
1502+
"invoke_indirect",
1503+
"load_field",
1504+
"constant",
1505+
]
1506+
for counter in strengthen_graphs_counters:
1507+
metric_objects.append("total_" + counter + "_before_strengthen_graphs")
1508+
metric_objects.append("total_" + counter + "_after_strengthen_graphs")
14881509
rules = []
14891510
for i in range(0, len(metric_objects)):
14901511
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)