Skip to content

Commit ae3d416

Browse files
committed
Make --experimental-engine-caching implicitly enable --run-twice
1 parent ededecc commit ae3d416

File tree

6 files changed

+37
-23
lines changed

6 files changed

+37
-23
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,13 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
215215

216216
int result = runContext(contextBuilder, config);
217217

218-
final boolean runTwice = config.getUnknownArguments().contains("--run-twice=true");
218+
final boolean runTwice = config.getUnknownArguments().contains("--run-twice") ||
219+
config.getUnknownArguments().contains("--run-twice=true");
219220
if (runTwice) {
220-
result = runContext(contextBuilder, config);
221+
final int secondResult = runContext(contextBuilder, config);
222+
if (secondResult != 0 && result == 0) {
223+
result = secondResult;
224+
}
221225
}
222226

223227
return result;

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,12 @@ private boolean checkAreOptionsCompatible(OptionValues firstOptions, OptionValue
644644
if (singleContext) {
645645
return false;
646646
}
647-
if (!firstOptions.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY) ||
648-
!newOptions.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY)) {
647+
648+
if (options.RUN_TWICE || options.EXPERIMENTAL_ENGINE_CACHING) {
649+
return LanguageOptions.areOptionsCompatible(firstOptions, newOptions);
650+
} else {
649651
return false;
650652
}
651-
return LanguageOptions.areOptionsCompatible(firstOptions, newOptions);
652653
}
653654

654655
/** {@link RubyLanguage#getSourcePath(Source)} should be used instead whenever possible (i.e., when we can access

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public class LanguageOptions {
122122
public final boolean SHARED_OBJECTS_DEBUG;
123123
/** --shared-objects-force=false */
124124
public final boolean SHARED_OBJECTS_FORCE;
125-
/** --experimental-engine-caching=false */
125+
/** --run-twice=false */
126+
public final boolean RUN_TWICE;
127+
/** --experimental-engine-caching=RUN_TWICE */
126128
public final boolean EXPERIMENTAL_ENGINE_CACHING;
127129

128130
public LanguageOptions(Env env, OptionValues options, boolean singleContext) {
@@ -176,7 +178,8 @@ public LanguageOptions(Env env, OptionValues options, boolean singleContext) {
176178
SHARED_OBJECTS_ENABLED = options.get(OptionsCatalog.SHARED_OBJECTS_ENABLED_KEY);
177179
SHARED_OBJECTS_DEBUG = options.get(OptionsCatalog.SHARED_OBJECTS_DEBUG_KEY);
178180
SHARED_OBJECTS_FORCE = options.get(OptionsCatalog.SHARED_OBJECTS_FORCE_KEY);
179-
EXPERIMENTAL_ENGINE_CACHING = options.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY);
181+
RUN_TWICE = options.get(OptionsCatalog.RUN_TWICE_KEY);
182+
EXPERIMENTAL_ENGINE_CACHING = options.hasBeenSet(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY) ? options.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY) : RUN_TWICE;
180183
}
181184

182185
public Object fromDescriptor(OptionDescriptor descriptor) {
@@ -281,6 +284,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
281284
return SHARED_OBJECTS_DEBUG;
282285
case "ruby.shared-objects-force":
283286
return SHARED_OBJECTS_FORCE;
287+
case "ruby.run-twice":
288+
return RUN_TWICE;
284289
case "ruby.experimental-engine-caching":
285290
return EXPERIMENTAL_ENGINE_CACHING;
286291
default:
@@ -339,6 +344,7 @@ public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
339344
one.get(OptionsCatalog.SHARED_OBJECTS_ENABLED_KEY).equals(two.get(OptionsCatalog.SHARED_OBJECTS_ENABLED_KEY)) &&
340345
one.get(OptionsCatalog.SHARED_OBJECTS_DEBUG_KEY).equals(two.get(OptionsCatalog.SHARED_OBJECTS_DEBUG_KEY)) &&
341346
one.get(OptionsCatalog.SHARED_OBJECTS_FORCE_KEY).equals(two.get(OptionsCatalog.SHARED_OBJECTS_FORCE_KEY)) &&
347+
one.get(OptionsCatalog.RUN_TWICE_KEY).equals(two.get(OptionsCatalog.RUN_TWICE_KEY)) &&
342348
one.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY).equals(two.get(OptionsCatalog.EXPERIMENTAL_ENGINE_CACHING_KEY));
343349
}
344350

@@ -696,6 +702,13 @@ public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOp
696702
return false;
697703
}
698704

705+
oldValue = oldOptions.RUN_TWICE;
706+
newValue = newOptions.RUN_TWICE;
707+
if (!newValue.equals(oldValue)) {
708+
logger.fine("not reusing pre-initialized context: --run-twice differs, was: " + oldValue + " and is now: " + newValue);
709+
return false;
710+
}
711+
699712
oldValue = oldOptions.EXPERIMENTAL_ENGINE_CACHING;
700713
newValue = newOptions.EXPERIMENTAL_ENGINE_CACHING;
701714
if (!newValue.equals(oldValue)) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ 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;
198196
/** --compare-regex-engines=false */
199197
public final boolean COMPARE_REGEX_ENGINES;
200198

@@ -284,7 +282,6 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
284282
METRICS_TIME_PARSING_FILE = options.get(OptionsCatalog.METRICS_TIME_PARSING_FILE_KEY);
285283
METRICS_TIME_REQUIRE = options.get(OptionsCatalog.METRICS_TIME_REQUIRE_KEY);
286284
TESTING_RUBYGEMS = options.get(OptionsCatalog.TESTING_RUBYGEMS_KEY);
287-
RUN_TWICE = options.get(OptionsCatalog.RUN_TWICE_KEY);
288285
COMPARE_REGEX_ENGINES = options.get(OptionsCatalog.COMPARE_REGEX_ENGINES_KEY);
289286
}
290287

@@ -460,8 +457,6 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
460457
return METRICS_TIME_REQUIRE;
461458
case "ruby.testing-rubygems":
462459
return TESTING_RUBYGEMS;
463-
case "ruby.run-twice":
464-
return RUN_TWICE;
465460
case "ruby.compare-regex-engines":
466461
return COMPARE_REGEX_ENGINES;
467462
default:

src/options.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ LANGUAGE_OPTIONS:
5151
- ARRAY_DUP_CACHE
5252
- ARRAY_STRATEGY_CACHE
5353
- EXPERIMENTAL_ENGINE_CACHING
54+
- RUN_TWICE
5455

5556
USER:
5657
STABLE:
@@ -246,8 +247,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
246247

247248
# Options for testing
248249
TESTING_RUBYGEMS: [testing-rubygems, boolean, false, 'Indicates rubygems is being tested']
249-
EXPERIMENTAL_ENGINE_CACHING: [experimental-engine-caching, boolean, false, 'Enables experimental support for engine caching for TruffleRuby']
250250
RUN_TWICE: [run-twice, boolean, false, 'Run a workload twice using a shared engine in the same process']
251+
EXPERIMENTAL_ENGINE_CACHING: [experimental-engine-caching, boolean, RUN_TWICE, 'Enables experimental support for engine caching for TruffleRuby']
251252

252253
# Options for the regular expression engines
253254
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ public class OptionsCatalog {
155155
public static final OptionKey<Boolean> SHARED_OBJECTS_DEBUG_KEY = new OptionKey<>(false);
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);
158-
public static final OptionKey<Boolean> EXPERIMENTAL_ENGINE_CACHING_KEY = new OptionKey<>(false);
159158
public static final OptionKey<Boolean> RUN_TWICE_KEY = new OptionKey<>(false);
159+
public static final OptionKey<Boolean> EXPERIMENTAL_ENGINE_CACHING_KEY = new OptionKey<>(RUN_TWICE_KEY.getDefaultValue());
160160
public static final OptionKey<Boolean> COMPARE_REGEX_ENGINES_KEY = new OptionKey<>(false);
161161

162162
public static final OptionDescriptor LOAD_PATHS = OptionDescriptor
@@ -1104,16 +1104,16 @@ public class OptionsCatalog {
11041104
.stability(OptionStability.EXPERIMENTAL)
11051105
.build();
11061106

1107-
public static final OptionDescriptor EXPERIMENTAL_ENGINE_CACHING = OptionDescriptor
1108-
.newBuilder(EXPERIMENTAL_ENGINE_CACHING_KEY, "ruby.experimental-engine-caching")
1109-
.help("Enables experimental support for engine caching for TruffleRuby")
1107+
public static final OptionDescriptor RUN_TWICE = OptionDescriptor
1108+
.newBuilder(RUN_TWICE_KEY, "ruby.run-twice")
1109+
.help("Run a workload twice using a shared engine in the same process")
11101110
.category(OptionCategory.INTERNAL)
11111111
.stability(OptionStability.EXPERIMENTAL)
11121112
.build();
11131113

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")
1114+
public static final OptionDescriptor EXPERIMENTAL_ENGINE_CACHING = OptionDescriptor
1115+
.newBuilder(EXPERIMENTAL_ENGINE_CACHING_KEY, "ruby.experimental-engine-caching")
1116+
.help("Enables experimental support for engine caching for TruffleRuby")
11171117
.category(OptionCategory.INTERNAL)
11181118
.stability(OptionStability.EXPERIMENTAL)
11191119
.build();
@@ -1397,10 +1397,10 @@ public static OptionDescriptor fromName(String name) {
13971397
return SHARED_OBJECTS_FORCE;
13981398
case "ruby.testing-rubygems":
13991399
return TESTING_RUBYGEMS;
1400-
case "ruby.experimental-engine-caching":
1401-
return EXPERIMENTAL_ENGINE_CACHING;
14021400
case "ruby.run-twice":
14031401
return RUN_TWICE;
1402+
case "ruby.experimental-engine-caching":
1403+
return EXPERIMENTAL_ENGINE_CACHING;
14041404
case "ruby.compare-regex-engines":
14051405
return COMPARE_REGEX_ENGINES;
14061406
default:
@@ -1545,8 +1545,8 @@ public static OptionDescriptor[] allDescriptors() {
15451545
SHARED_OBJECTS_DEBUG,
15461546
SHARED_OBJECTS_FORCE,
15471547
TESTING_RUBYGEMS,
1548-
EXPERIMENTAL_ENGINE_CACHING,
15491548
RUN_TWICE,
1549+
EXPERIMENTAL_ENGINE_CACHING,
15501550
COMPARE_REGEX_ENGINES,
15511551
};
15521552
}

0 commit comments

Comments
 (0)