Skip to content

Commit 31436f1

Browse files
committed
[GR-31875] Move HelloWorld benchmark to own suite.
PullRequest: graal/9068
2 parents 3f947bd + d8455d9 commit 31436f1

File tree

6 files changed

+119
-18
lines changed

6 files changed

+119
-18
lines changed

java-benchmarks/java/org.graalvm.bench.misc/src/bench/misc/HelloWorld.java renamed to java-benchmarks/java/org.graalvm.bench.console/src/bench/console/HelloWorld.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package bench.misc;
25+
package bench.console;
2626

27-
import org.openjdk.jmh.annotations.Benchmark;
28-
import org.openjdk.jmh.annotations.Scope;
29-
import org.openjdk.jmh.annotations.State;
30-
31-
@State(Scope.Benchmark)
3227
public class HelloWorld {
33-
@Benchmark
34-
public static void helloWorld() {
28+
public static void main(String[] args) {
29+
System.out.println("Hello, World!");
3530
}
3631
}

java-benchmarks/java/org.graalvm.bench.misc/src/bench/misc/Scalafmt.java renamed to java-benchmarks/java/org.graalvm.bench.console/src/bench/console/Scalafmt.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package bench.misc;
25+
package bench.console;
2626

27-
import org.openjdk.jmh.annotations.*;
28-
29-
@State(Scope.Benchmark)
3027
public class Scalafmt {
3128

3229
private static final String file =
@@ -130,8 +127,7 @@ public class Scalafmt {
130127
" }\n" +
131128
"}\n";
132129

133-
@Benchmark
134-
public static String bench() {
135-
return org.scalafmt.Scalafmt.format(file, org.scalafmt.Scalafmt.format$default$2(), org.scalafmt.Scalafmt.format$default$3()).get();
130+
public static void main(String[] args) {
131+
org.scalafmt.Scalafmt.format(file, org.scalafmt.Scalafmt.format$default$2(), org.scalafmt.Scalafmt.format$default$3()).get();
136132
}
137133
}

java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,3 +2033,73 @@ def run(self, benchmarks, bmSuiteArgs):
20332033

20342034

20352035
mx_benchmark.add_bm_suite(AWFYBenchmarkSuite())
2036+
2037+
2038+
_consoleConfig = {
2039+
"helloworld": {
2040+
"mainClass": "bench.console.HelloWorld",
2041+
"args": []
2042+
},
2043+
"scalafmt": {
2044+
"mainClass": "bench.console.Scalafmt",
2045+
"args": []
2046+
}
2047+
}
2048+
2049+
class ConsoleBenchmarkSuite(mx_benchmark.JavaBenchmarkSuite):
2050+
"""Hello World benchmark suite implementation.
2051+
"""
2052+
def name(self):
2053+
return "console"
2054+
2055+
def group(self):
2056+
return "Graal"
2057+
2058+
def subgroup(self):
2059+
return "graal-compiler"
2060+
2061+
def benchSuiteName(self, bmSuiteArgs=None):
2062+
return self.name()
2063+
2064+
def helloWorldPath(self):
2065+
helloWorld = mx.distribution("GRAAL_BENCH_CONSOLE")
2066+
if helloWorld:
2067+
return helloWorld.path
2068+
return None
2069+
2070+
def classpathAndMainClass(self, benchmark):
2071+
main_class = _consoleConfig.get(benchmark)["mainClass"]
2072+
return ["-cp", self.helloWorldPath(), main_class]
2073+
2074+
def appArgs(self, benchmark):
2075+
return _consoleConfig.get(benchmark)["args"]
2076+
2077+
def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
2078+
if benchmarks is None:
2079+
mx.abort("Suite can only run a single benchmark per VM instance.")
2080+
elif len(benchmarks) != 1:
2081+
mx.abort("Must specify exactly one benchmark to run.")
2082+
elif benchmarks[0] not in self.benchmarkList(bmSuiteArgs):
2083+
mx.abort("The specified benchmark doesn't exist. Possible values are: " + ", ".join(self.benchmarkList(bmSuiteArgs)))
2084+
vmArgs = self.runArgs(bmSuiteArgs)
2085+
runArgs = self.runArgs(bmSuiteArgs)
2086+
appArgs = self.appArgs(benchmarks[0])
2087+
return (vmArgs + self.classpathAndMainClass(benchmarks[0]) + runArgs + appArgs)
2088+
2089+
def benchmarkList(self, bmSuiteArgs):
2090+
return sorted(_consoleConfig.keys())
2091+
2092+
def successPatterns(self):
2093+
return []
2094+
2095+
def failurePatterns(self):
2096+
return [
2097+
re.compile(
2098+
r"^\[\[\[Graal compilation failure\]\]\]", # pylint: disable=line-too-long
2099+
re.MULTILINE)
2100+
]
2101+
2102+
def rules(self, output, benchmarks, bmSuiteArgs):
2103+
return []
2104+
2105+
mx_benchmark.add_bm_suite(ConsoleBenchmarkSuite())

java-benchmarks/mx.java-benchmarks/suite.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@
327327
"sourceDirs" : ["src"],
328328
"dependencies" : [
329329
"mx:JMH_1_21",
330-
"SCALAFMT"
331330
],
332331
"javaCompliance" : "8+",
333332
"checkPackagePrefix" : "false",
@@ -349,6 +348,17 @@
349348
"workingSets" : "Graal,Bench",
350349
"testProject" : True,
351350
},
351+
"org.graalvm.bench.console" : {
352+
"subDir" : "java",
353+
"sourceDirs" : ["src"],
354+
"dependencies" : [
355+
"SCALAFMT"
356+
],
357+
"javaCompliance" : "8+",
358+
"checkPackagePrefix" : "false",
359+
"workingSets" : "Graal,Bench",
360+
"testProject" : True,
361+
},
352362
},
353363

354364
"imports" : {
@@ -372,6 +382,12 @@
372382
"dependencies" : ["org.graalvm.bench.shootouts"],
373383
"testDistribution" : True,
374384
"maven": False,
385+
},
386+
"GRAAL_BENCH_CONSOLE" : {
387+
"subDir" : "java",
388+
"dependencies" : ["org.graalvm.bench.console"],
389+
"testDistribution" : True,
390+
"maven": False,
375391
}
376392
}
377393
}

substratevm/mx.substratevm/mx_substratevm_benchmark.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,23 @@ def substitution_path():
635635

636636

637637
mx_benchmark.add_bm_suite(ScalaDaCapoNativeImageBenchmarkSuite())
638+
639+
640+
class ConsoleNativeImageBenchmarkSuite(mx_java_benchmarks.ConsoleBenchmarkSuite, mx_sdk_benchmark.NativeImageBenchmarkMixin): #pylint: disable=too-many-ancestors
641+
"""
642+
Console applications suite for Native Image
643+
"""
644+
645+
def name(self):
646+
return 'console-native-image'
647+
648+
def benchSuiteName(self, bmSuiteArgs=None):
649+
return 'console'
650+
651+
def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
652+
args = super(ConsoleNativeImageBenchmarkSuite, self).createCommandLineArgs(benchmarks, bmSuiteArgs)
653+
self.benchmark_name = benchmarks[0]
654+
return args
655+
656+
657+
mx_benchmark.add_bm_suite(ConsoleNativeImageBenchmarkSuite())

vm/mx.vm/mx_vm_benchmark.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ def run_stage_agent(self, config, stages):
525525
with stages.set_command([java_command] + hotspot_args) as s:
526526
s.execute_command()
527527
if self.hotspot_pgo and s.exit_code == 0:
528-
mx.copyfile(profile_path, config.latest_profile_path)
528+
# Hotspot instrumentation does not produce profiling information for the helloworld benchmark
529+
if os.path.exists(profile_path):
530+
mx.copyfile(profile_path, config.latest_profile_path)
531+
else:
532+
mx.warn("No profile information emitted during agent run.")
529533

530534
def run_stage_instrument_image(self, config, stages, out, i, instrumentation_image_name, image_path, image_path_latest, instrumented_iterations):
531535
executable_name_args = ['-H:Name=' + instrumentation_image_name]
@@ -561,7 +565,7 @@ def run_stage_image(self, config, stages):
561565
pgo_args = ['--pgo=' + config.latest_profile_path, '-H:+VerifyPGOProfiles', '-H:VerificationDumpFile=' + pgo_verification_output_path]
562566
pgo_args += ['-H:' + ('+' if self.pgo_context_sensitive else '-') + 'EnablePGOContextSensitivity']
563567
pgo_args += ['-H:+AOTInliner'] if self.pgo_aot_inline else ['-H:-AOTInliner']
564-
final_image_command = config.base_image_build_args + executable_name_args + (pgo_args if self.pgo_instrumented_iterations > 0 or self.hotspot_pgo else [])
568+
final_image_command = config.base_image_build_args + executable_name_args + (pgo_args if self.pgo_instrumented_iterations > 0 or (self.hotspot_pgo and os.path.exists(config.latest_profile_path)) else [])
565569
with stages.set_command(final_image_command) as s:
566570
s.execute_command()
567571

0 commit comments

Comments
 (0)