Skip to content

Commit 6be8b3d

Browse files
committed
[GR-70788] Add setup method support to polybench benchmarks.
PullRequest: graal/22667
2 parents 8fa3cf0 + bdf6750 commit 6be8b3d

File tree

14 files changed

+7676
-7377
lines changed

14 files changed

+7676
-7377
lines changed

truffle/src/org.graalvm.polybench/src/org/graalvm/polybench/PolyBenchAstBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,12 @@ private void stageRunHarnessBody(Context.Builder contextBuilder, boolean evalSou
229229

230230
builder.append(new Expr.FunctionCall.LogCall(new Expr.Atom.String("::: Bench specific options :::")));
231231
if (evalResult.value instanceof Value value) {
232-
if (evalResult.languageId.equals("wasm")) {
233-
value = value.getMember("exports");
232+
// Execute "setup" function if it exists
233+
try (Stat.Block.Builder thenBranchBuilder = new Stat.Block.Builder(null)) {
234+
thenBranchBuilder.append(new Expr.FunctionCall(new Expr.Reference.Ident("setup"), null));
235+
thenBranch = thenBranchBuilder.build();
234236
}
237+
builder.append(new Stat.If(new Expr.FunctionCall(new Expr.Reference.Ident("checkIfFunctionExists"), new Expr[]{new Expr.Atom.String("setup")}), thenBranch, null));
235238
config.parseBenchSpecificDefaults(value);
236239
builder.append(new Expr.FunctionCall(new Expr.Reference.CompoundReference(new Expr.Reference.Ident("configMetric"), new Expr.Reference.Ident("parseBenchSpecificOptions")), null));
237240
}

truffle/src/org.graalvm.polybench/src/org/graalvm/polybench/PolyBenchLauncher.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ EvalResult evalSource(Context context) {
403403
config.metric.afterLoad(config);
404404
}
405405
if (language.equals("wasm")) {
406-
result = result.newInstance();
406+
result = result.newInstance().getMember("exports");
407407
}
408408
return new EvalResult(language, source.getName(), source.hasBytes(), source.getLength(), result);
409409
}
@@ -495,8 +495,9 @@ private void runHarness(Context.Builder contextBuilder, boolean evalSourceOnly,
495495
log("::: Bench specific options :::");
496496
if (evalResult.value instanceof Value) {
497497
Value value = (Value) evalResult.value;
498-
if (evalResult.languageId.equals("wasm")) {
499-
value = value.getMember("exports");
498+
Value setup = tryLookup(context, evalResult.languageId, value, "setup");
499+
if (setup != null && setup.canExecute()) {
500+
setup.execute();
500501
}
501502
config.parseBenchSpecificDefaults(value);
502503
config.metric.parseBenchSpecificOptions(value);
@@ -573,13 +574,29 @@ private void repeatIterations(Context context, Workload workload, String name, b
573574
}
574575
}
575576

577+
private static Value tryLookup(Context context, String languageId, Value evalSourceValue, String memberName) {
578+
// language-specific lookup
579+
return switch (languageId) {
580+
case "wasm" -> evalSourceValue.getMember(memberName);
581+
default -> {
582+
// first try the memberName directly
583+
if (evalSourceValue.hasMember(memberName)) {
584+
yield evalSourceValue.getMember(memberName);
585+
} else {
586+
// Fallback for other languages: Look for 'memberName' in global scope.
587+
yield context.getBindings(languageId).getMember(memberName);
588+
}
589+
}
590+
};
591+
}
592+
576593
private Workload lookup(Context context, String languageId, Object evalSource, String memberName) {
577594
Value evalSourceValue = (Value) evalSource;
578595
Value result;
579596
// language-specific lookup
580597
switch (languageId) {
581598
case "wasm":
582-
result = evalSourceValue.getMember("exports").getMember(memberName);
599+
result = evalSourceValue.getMember(memberName);
583600
break;
584601
case "java":
585602
// Espresso doesn't provide methods as executable values.

vm/ci/ci_common/common-bench.jsonnet

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,14 @@ local repo_config = import '../../../ci/repo-configuration.libsonnet';
197197
notify_groups +: ['wasm'],
198198
},
199199
self.polybench_vm_daily('linux', 'amd64', 'wasm') + common.deps.wasm + {
200+
local is_enterprise = (repo_config.graalvm_edition == 'ee'),
200201
setup+: [
201202
['mx', '--dy', '/wasm', 'build'],
202203
['mx', '--dy', '/wasm', 'build', '--dependencies', 'WASM_POLYBENCH_BENCHMARKS']
203-
],
204+
] + if is_enterprise then [['mx', '--dy', '/wasm-enterprise', 'build', '--dependencies', 'WASM_ENTERPRISE_POLYBENCH_BENCHMARKS']] else [],
204205
run+: [
205206
self.polybench_wrap(['mx', '--dy', '/wasm', '--java-home', '${POLYBENCH_JVM}', 'polybench', '--suite', 'wasm:benchmark']),
206-
],
207+
] + if is_enterprise then [self.polybench_wrap(['mx', '--dy', '/wasm-enterprise', '--java-home', '${POLYBENCH_JVM}', 'polybench', '--suite', 'wasm-enterprise:benchmark'])] else [],
207208
notify_groups +: ['wasm'],
208209
}
209210
] + [
@@ -276,12 +277,13 @@ local repo_config = import '../../../ci/repo-configuration.libsonnet';
276277
notify_groups +: ['javascript'],
277278
},
278279
self.polybench_vm_daily('linux', 'amd64', 'js') + {
280+
local is_enterprise = (repo_config.graalvm_edition == 'ee'),
279281
setup+: [
280282
['mx', '--dy', '/graal-js', 'build']
281-
],
283+
] + if is_enterprise then [['mx', '--dy', '/graal-js-enterprise', 'build', '--dependencies', 'GRAALJS_ENTERPRISE_POLYBENCH_BENCHMARKS']] else [],
282284
run+: [
283285
self.polybench_wrap(['mx', '--dy', '/graal-js', '--java-home', '${POLYBENCH_JVM}', 'polybench', '--suite', 'js:benchmark']),
284-
],
286+
] + if is_enterprise then [self.polybench_wrap(['mx', '--dy', '/graal-js-enterprise', '--java-home', '${POLYBENCH_JVM}', 'polybench', '--suite', 'js-enterprise:benchmark'])] else [],
285287
notify_groups +: ['javascript'],
286288
}
287289
] + [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.wasm

wasm/benchmarks/interpreter/deltablue.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 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
@@ -1110,6 +1110,9 @@ double OutlierRemovalAverageSummaryUpperThreshold() {
11101110
return 0.5;
11111111
}
11121112

1113+
void setup() {
1114+
}
1115+
11131116
int run()
11141117
{
11151118
int n = 1000;

0 commit comments

Comments
 (0)