Skip to content

Commit ededecc

Browse files
committed
Add option to run a workload twice with a shared engine
1 parent 0cc14fd commit ededecc

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,30 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
201201
return 0;
202202
}
203203

204-
try (Context context = createContext(contextBuilder, config)) {
204+
if (config.isGemOrBundle() && getImplementationNameFromEngine().contains("Graal")) {
205+
// Apply options to run gem/bundle more efficiently
206+
contextBuilder.option("engine.Mode", "latency");
207+
if (Boolean.getBoolean("truffleruby.launcher.log")) {
208+
System.err.println("[ruby] CONFIG: detected gem or bundle command, using --engine.Mode=latency");
209+
}
210+
}
211+
212+
contextBuilder.options(config.getOptions());
213+
214+
contextBuilder.arguments(TruffleRuby.LANGUAGE_ID, config.getArguments());
215+
216+
int result = runContext(contextBuilder, config);
217+
218+
final boolean runTwice = config.getUnknownArguments().contains("--run-twice=true");
219+
if (runTwice) {
220+
result = runContext(contextBuilder, config);
221+
}
222+
223+
return result;
224+
}
225+
226+
private int runContext(Context.Builder builder, CommandLineOptions config) {
227+
try (Context context = builder.build()) {
205228
Metrics.printTime("before-run");
206229

207230
if (config.executionAction == ExecutionAction.PATH) {
@@ -244,22 +267,6 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
244267
}
245268
}
246269

247-
private Context createContext(Context.Builder builder, CommandLineOptions config) {
248-
if (config.isGemOrBundle() && getImplementationNameFromEngine().contains("Graal")) {
249-
// Apply options to run gem/bundle more efficiently
250-
builder.option("engine.Mode", "latency");
251-
if (Boolean.getBoolean("truffleruby.launcher.log")) {
252-
System.err.println("[ruby] CONFIG: detected gem or bundle command, using --engine.Mode=latency");
253-
}
254-
}
255-
256-
builder.options(config.getOptions());
257-
258-
builder.arguments(TruffleRuby.LANGUAGE_ID, config.getArguments());
259-
260-
return builder.build();
261-
}
262-
263270
private static List<String> getArgsFromEnvVariable(String name) {
264271
String value = System.getenv(name);
265272
if (value != null) {

src/main/java/org/truffleruby/options/Options.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public class Options {
193193
public final boolean METRICS_TIME_REQUIRE;
194194
/** --testing-rubygems=false */
195195
public final boolean TESTING_RUBYGEMS;
196+
/** --run-twice=false */
197+
public final boolean RUN_TWICE;
196198
/** --compare-regex-engines=false */
197199
public final boolean COMPARE_REGEX_ENGINES;
198200

@@ -282,6 +284,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
282284
METRICS_TIME_PARSING_FILE = options.get(OptionsCatalog.METRICS_TIME_PARSING_FILE_KEY);
283285
METRICS_TIME_REQUIRE = options.get(OptionsCatalog.METRICS_TIME_REQUIRE_KEY);
284286
TESTING_RUBYGEMS = options.get(OptionsCatalog.TESTING_RUBYGEMS_KEY);
287+
RUN_TWICE = options.get(OptionsCatalog.RUN_TWICE_KEY);
285288
COMPARE_REGEX_ENGINES = options.get(OptionsCatalog.COMPARE_REGEX_ENGINES_KEY);
286289
}
287290

@@ -457,6 +460,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
457460
return METRICS_TIME_REQUIRE;
458461
case "ruby.testing-rubygems":
459462
return TESTING_RUBYGEMS;
463+
case "ruby.run-twice":
464+
return RUN_TWICE;
460465
case "ruby.compare-regex-engines":
461466
return COMPARE_REGEX_ENGINES;
462467
default:

src/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
247247
# Options for testing
248248
TESTING_RUBYGEMS: [testing-rubygems, boolean, false, 'Indicates rubygems is being tested']
249249
EXPERIMENTAL_ENGINE_CACHING: [experimental-engine-caching, boolean, false, 'Enables experimental support for engine caching for TruffleRuby']
250+
RUN_TWICE: [run-twice, boolean, false, 'Run a workload twice using a shared engine in the same process']
250251

251252
# Options for the regular expression engines
252253
COMPARE_REGEX_ENGINES: [compare-regex-engines, boolean, false, 'Uses both Joni and the TRegex engine and compares their results']

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public class OptionsCatalog {
156156
public static final OptionKey<Boolean> SHARED_OBJECTS_FORCE_KEY = new OptionKey<>(false);
157157
public static final OptionKey<Boolean> TESTING_RUBYGEMS_KEY = new OptionKey<>(false);
158158
public static final OptionKey<Boolean> EXPERIMENTAL_ENGINE_CACHING_KEY = new OptionKey<>(false);
159+
public static final OptionKey<Boolean> RUN_TWICE_KEY = new OptionKey<>(false);
159160
public static final OptionKey<Boolean> COMPARE_REGEX_ENGINES_KEY = new OptionKey<>(false);
160161

161162
public static final OptionDescriptor LOAD_PATHS = OptionDescriptor
@@ -1110,6 +1111,13 @@ public class OptionsCatalog {
11101111
.stability(OptionStability.EXPERIMENTAL)
11111112
.build();
11121113

1114+
public static final OptionDescriptor RUN_TWICE = OptionDescriptor
1115+
.newBuilder(RUN_TWICE_KEY, "ruby.run-twice")
1116+
.help("Run a workload twice using a shared engine in the same process")
1117+
.category(OptionCategory.INTERNAL)
1118+
.stability(OptionStability.EXPERIMENTAL)
1119+
.build();
1120+
11131121
public static final OptionDescriptor COMPARE_REGEX_ENGINES = OptionDescriptor
11141122
.newBuilder(COMPARE_REGEX_ENGINES_KEY, "ruby.compare-regex-engines")
11151123
.help("Uses both Joni and the TRegex engine and compares their results")
@@ -1391,6 +1399,8 @@ public static OptionDescriptor fromName(String name) {
13911399
return TESTING_RUBYGEMS;
13921400
case "ruby.experimental-engine-caching":
13931401
return EXPERIMENTAL_ENGINE_CACHING;
1402+
case "ruby.run-twice":
1403+
return RUN_TWICE;
13941404
case "ruby.compare-regex-engines":
13951405
return COMPARE_REGEX_ENGINES;
13961406
default:
@@ -1536,6 +1546,7 @@ public static OptionDescriptor[] allDescriptors() {
15361546
SHARED_OBJECTS_FORCE,
15371547
TESTING_RUBYGEMS,
15381548
EXPERIMENTAL_ENGINE_CACHING,
1549+
RUN_TWICE,
15391550
COMPARE_REGEX_ENGINES,
15401551
};
15411552
}

0 commit comments

Comments
 (0)