Skip to content

Commit 3b120d9

Browse files
committed
Language options must be identical to reuse the pre-initialized context
1 parent ecca2be commit 3b120d9

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ protected boolean patchContext(RubyContext context, Env newEnv) {
300300

301301
LOGGER.fine("patchContext()");
302302
Metrics.printTime("before-patch-context");
303+
final LanguageOptions oldOptions = Objects.requireNonNull(this.options);
304+
final LanguageOptions newOptions = new LanguageOptions(newEnv, newEnv.getOptions());
305+
if (!LanguageOptions.areOptionsCompatibleOrLog(LOGGER, oldOptions, newOptions)) {
306+
return false;
307+
}
308+
303309
boolean patched = context.patchContext(newEnv);
304310
Metrics.printTime("after-patch-context");
305311
return patched;

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.graalvm.options.OptionDescriptor;
1616
import org.graalvm.options.OptionValues;
1717
import org.truffleruby.shared.options.OptionsCatalog;
18+
import com.oracle.truffle.api.TruffleLogger;
1819

1920
import com.oracle.truffle.api.TruffleLanguage.Env;
2021

@@ -118,5 +119,110 @@ public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
118119
one.get(OptionsCatalog.SHARED_OBJECTS_DEBUG_KEY).equals(two.get(OptionsCatalog.SHARED_OBJECTS_DEBUG_KEY)) &&
119120
one.get(OptionsCatalog.SHARED_OBJECTS_FORCE_KEY).equals(two.get(OptionsCatalog.SHARED_OBJECTS_FORCE_KEY));
120121
}
122+
123+
public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOptions oldOptions, LanguageOptions newOptions) {
124+
Object oldValue;
125+
Object newValue;
126+
127+
oldValue = oldOptions.FROZEN_STRING_LITERALS;
128+
newValue = newOptions.FROZEN_STRING_LITERALS;
129+
if (!newValue.equals(oldValue)) {
130+
logger.fine("not reusing pre-initialized context: --frozen-string-literals differs, was: " + oldValue + " and is now: " + newValue);
131+
return false;
132+
}
133+
134+
oldValue = oldOptions.DEFAULT_LAZY;
135+
newValue = newOptions.DEFAULT_LAZY;
136+
if (!newValue.equals(oldValue)) {
137+
logger.fine("not reusing pre-initialized context: --lazy-default differs, was: " + oldValue + " and is now: " + newValue);
138+
return false;
139+
}
140+
141+
oldValue = oldOptions.LAZY_TRANSLATION_USER;
142+
newValue = newOptions.LAZY_TRANSLATION_USER;
143+
if (!newValue.equals(oldValue)) {
144+
logger.fine("not reusing pre-initialized context: --lazy-translation-user differs, was: " + oldValue + " and is now: " + newValue);
145+
return false;
146+
}
147+
148+
oldValue = oldOptions.BACKTRACES_OMIT_UNUSED;
149+
newValue = newOptions.BACKTRACES_OMIT_UNUSED;
150+
if (!newValue.equals(oldValue)) {
151+
logger.fine("not reusing pre-initialized context: --backtraces-omit-unused differs, was: " + oldValue + " and is now: " + newValue);
152+
return false;
153+
}
154+
155+
oldValue = oldOptions.LAZY_TRANSLATION_LOG;
156+
newValue = newOptions.LAZY_TRANSLATION_LOG;
157+
if (!newValue.equals(oldValue)) {
158+
logger.fine("not reusing pre-initialized context: --lazy-translation-log differs, was: " + oldValue + " and is now: " + newValue);
159+
return false;
160+
}
161+
162+
oldValue = oldOptions.LOG_DYNAMIC_CONSTANT_LOOKUP;
163+
newValue = newOptions.LOG_DYNAMIC_CONSTANT_LOOKUP;
164+
if (!newValue.equals(oldValue)) {
165+
logger.fine("not reusing pre-initialized context: --constant-dynamic-lookup-log differs, was: " + oldValue + " and is now: " + newValue);
166+
return false;
167+
}
168+
169+
oldValue = oldOptions.LAZY_BUILTINS;
170+
newValue = newOptions.LAZY_BUILTINS;
171+
if (!newValue.equals(oldValue)) {
172+
logger.fine("not reusing pre-initialized context: --lazy-builtins differs, was: " + oldValue + " and is now: " + newValue);
173+
return false;
174+
}
175+
176+
oldValue = oldOptions.LAZY_TRANSLATION_CORE;
177+
newValue = newOptions.LAZY_TRANSLATION_CORE;
178+
if (!newValue.equals(oldValue)) {
179+
logger.fine("not reusing pre-initialized context: --lazy-translation-core differs, was: " + oldValue + " and is now: " + newValue);
180+
return false;
181+
}
182+
183+
oldValue = oldOptions.BASICOPS_INLINE;
184+
newValue = newOptions.BASICOPS_INLINE;
185+
if (!newValue.equals(oldValue)) {
186+
logger.fine("not reusing pre-initialized context: --basic-ops-inline differs, was: " + oldValue + " and is now: " + newValue);
187+
return false;
188+
}
189+
190+
oldValue = oldOptions.PROFILE_ARGUMENTS;
191+
newValue = newOptions.PROFILE_ARGUMENTS;
192+
if (!newValue.equals(oldValue)) {
193+
logger.fine("not reusing pre-initialized context: --profile-arguments differs, was: " + oldValue + " and is now: " + newValue);
194+
return false;
195+
}
196+
197+
oldValue = oldOptions.HASH_PACKED_ARRAY_MAX;
198+
newValue = newOptions.HASH_PACKED_ARRAY_MAX;
199+
if (!newValue.equals(oldValue)) {
200+
logger.fine("not reusing pre-initialized context: --hash-packed-array-max differs, was: " + oldValue + " and is now: " + newValue);
201+
return false;
202+
}
203+
204+
oldValue = oldOptions.SHARED_OBJECTS_ENABLED;
205+
newValue = newOptions.SHARED_OBJECTS_ENABLED;
206+
if (!newValue.equals(oldValue)) {
207+
logger.fine("not reusing pre-initialized context: --shared-objects differs, was: " + oldValue + " and is now: " + newValue);
208+
return false;
209+
}
210+
211+
oldValue = oldOptions.SHARED_OBJECTS_DEBUG;
212+
newValue = newOptions.SHARED_OBJECTS_DEBUG;
213+
if (!newValue.equals(oldValue)) {
214+
logger.fine("not reusing pre-initialized context: --shared-objects-debug differs, was: " + oldValue + " and is now: " + newValue);
215+
return false;
216+
}
217+
218+
oldValue = oldOptions.SHARED_OBJECTS_FORCE;
219+
newValue = newOptions.SHARED_OBJECTS_FORCE;
220+
if (!newValue.equals(oldValue)) {
221+
logger.fine("not reusing pre-initialized context: --shared-objects-force differs, was: " + oldValue + " and is now: " + newValue);
222+
return false;
223+
}
224+
225+
return true;
226+
}
121227
}
122228
// @formatter:on

tool/generate-options.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def parse_reference_defaults(default)
130130
<% if class_prefix == '' -%>
131131
import org.truffleruby.shared.options.Verbosity;
132132
import org.truffleruby.shared.options.Profile;
133+
<% else -%>
134+
import com.oracle.truffle.api.TruffleLogger;
133135
<% end -%>
134136
135137
import com.oracle.truffle.api.TruffleLanguage.Env;
@@ -165,6 +167,20 @@ def parse_reference_defaults(default)
165167
public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
166168
return <%= options.map { |o| "one.get(OptionsCatalog.#{o.constant}_KEY).equals(two.get(OptionsCatalog.#{o.constant}_KEY))" }.join(" &&\n ") %>;
167169
}
170+
171+
public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOptions oldOptions, LanguageOptions newOptions) {
172+
Object oldValue;
173+
Object newValue;
174+
<%= options.map { |o| "
175+
oldValue = oldOptions.#{o.constant};
176+
newValue = newOptions.#{o.constant};
177+
if (!newValue.equals(oldValue)) {
178+
logger.fine(\"not reusing pre-initialized context: --#{o.name} differs, was: \" + oldValue + \" and is now: \" + newValue);
179+
return false;
180+
}" }.join("\n") %>
181+
182+
return true;
183+
}
168184
<% end -%>
169185
}
170186
// @formatter:on

0 commit comments

Comments
 (0)