Skip to content

Commit d0bdb29

Browse files
committed
[GR-15990] Move translator options to language.
PullRequest: truffleruby/2006
2 parents 8c5babc + 86d2663 commit d0bdb29

File tree

121 files changed

+753
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+753
-496
lines changed

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.concurrent.locks.ReentrantLock;
2121
import java.util.logging.Level;
2222

23+
import com.oracle.truffle.api.CompilerAsserts;
2324
import com.oracle.truffle.api.CompilerDirectives;
2425
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
2526
import com.oracle.truffle.api.nodes.Node;
@@ -71,6 +72,7 @@
7172
import org.truffleruby.language.loader.FeatureLoader;
7273
import org.truffleruby.language.methods.InternalMethod;
7374
import org.truffleruby.language.objects.shared.SharedObjects;
75+
import org.truffleruby.options.LanguageOptions;
7476
import org.truffleruby.options.Options;
7577
import org.truffleruby.parser.TranslatorDriver;
7678
import org.truffleruby.platform.NativeConfiguration;
@@ -167,7 +169,7 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
167169
this.env = env;
168170
this.hasOtherPublicLanguages = computeHasOtherPublicLanguages(env);
169171

170-
options = createOptions(env);
172+
options = createOptions(env, language.options);
171173

172174
referenceProcessor = new ReferenceProcessor(this);
173175
finalizationService = new FinalizationService(this, referenceProcessor);
@@ -273,7 +275,7 @@ protected boolean patch(Env newEnv) {
273275
this.hasOtherPublicLanguages = computeHasOtherPublicLanguages(newEnv);
274276

275277
final Options oldOptions = this.options;
276-
final Options newOptions = createOptions(newEnv);
278+
final Options newOptions = createOptions(newEnv, language.options);
277279
final String newHome = findRubyHome(newOptions);
278280
if (!compatibleOptions(oldOptions, newOptions, this.hadHome, newHome != null)) {
279281
return false;
@@ -366,10 +368,9 @@ private boolean compatibleOptions(Options oldOptions, Options newOptions, boolea
366368
return true;
367369
}
368370

369-
private Options createOptions(TruffleLanguage.Env env) {
371+
private Options createOptions(TruffleLanguage.Env env, LanguageOptions languageOptions) {
370372
Metrics.printTime("before-options");
371-
final Options options = new Options(env, env.getOptions());
372-
373+
final Options options = new Options(env, env.getOptions(), languageOptions);
373374
if (options.OPTIONS_LOG && RubyLanguage.LOGGER.isLoggable(Level.CONFIG)) {
374375
for (OptionDescriptor descriptor : OptionsCatalog.allDescriptors()) {
375376
assert descriptor.getName().startsWith(TruffleRuby.LANGUAGE_ID);
@@ -511,7 +512,9 @@ public Hashing getHashing() {
511512
return hashing;
512513
}
513514

514-
public RubyLanguage getLanguage() {
515+
public RubyLanguage getLanguageSlow() {
516+
CompilerAsserts.neverPartOfCompilation(
517+
"@CachedLanguage or a final field in the node should be used so the RubyLanguage instance is constant in PE code");
515518
return language;
516519
}
517520

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.truffleruby.core.exception.RubySystemCallError;
3030
import org.truffleruby.core.fiber.RubyFiber;
3131
import org.truffleruby.core.hash.RubyHash;
32+
import org.graalvm.options.OptionValues;
3233
import org.truffleruby.core.kernel.TraceManager;
3334
import org.truffleruby.core.klass.RubyClass;
3435
import org.truffleruby.core.method.RubyMethod;
@@ -71,6 +72,7 @@
7172
import org.truffleruby.language.RubyInlineParsingRequestNode;
7273
import org.truffleruby.language.RubyParsingRequestNode;
7374
import org.truffleruby.language.objects.RubyObjectType;
75+
import org.truffleruby.options.LanguageOptions;
7476
import org.truffleruby.platform.Platform;
7577
import org.truffleruby.shared.Metrics;
7678
import org.truffleruby.shared.TruffleRuby;
@@ -142,6 +144,7 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
142144
public final CoreSymbols coreSymbols;
143145
public final RopeCache ropeCache;
144146
public final SymbolTable symbolTable;
147+
@CompilationFinal public LanguageOptions options;
145148

146149
@CompilationFinal private AllocationReporter allocationReporter;
147150

@@ -234,8 +237,13 @@ public RubyContext createContext(Env env) {
234237
// We need to initialize the Metrics class of the language classloader
235238
Metrics.initializeOption();
236239

237-
if (allocationReporter == null) {
238-
allocationReporter = env.lookup(AllocationReporter.class);
240+
synchronized (this) {
241+
if (allocationReporter == null) {
242+
allocationReporter = env.lookup(AllocationReporter.class);
243+
}
244+
if (this.options == null) {
245+
this.options = new LanguageOptions(env, env.getOptions());
246+
}
239247
}
240248

241249
LOGGER.fine("createContext()");
@@ -420,4 +428,9 @@ private static Shape createShape(Class<? extends RubyDynamicObject> layoutClass)
420428
.build();
421429
}
422430

431+
@Override
432+
protected boolean areOptionsCompatible(OptionValues firstOptions, OptionValues newOptions) {
433+
return LanguageOptions.areOptionsCompatible(firstOptions, newOptions);
434+
}
435+
423436
}

src/main/java/org/truffleruby/aot/ParserCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ private static RubySource loadSource(String feature) {
5757
}
5858

5959
private static RootParseNode parse(RubySource source) {
60-
final TranslatorDriver driver = new TranslatorDriver(null);
6160
final StaticScope staticScope = new StaticScope(StaticScope.Type.LOCAL, null);
6261
final ParserConfiguration parserConfiguration = new ParserConfiguration(null, false, true, false);
6362

64-
return driver.parseToJRubyAST(source, staticScope, parserConfiguration);
63+
return TranslatorDriver.parseToJRubyAST(null, source, staticScope, parserConfiguration);
6564
}
6665

6766
}

src/main/java/org/truffleruby/builtins/CoreMethodNodeManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public CoreMethodNodeManager(
6363
SingletonClassNode singletonClassNode,
6464
PrimitiveManager primitiveManager) {
6565
this.context = context;
66-
this.language = context.getLanguage();
66+
this.language = context.getLanguageSlow();
6767
this.singletonClassNode = singletonClassNode;
6868
this.primitiveManager = primitiveManager;
6969
}
@@ -167,7 +167,7 @@ public void addLazyCoreMethod(String nodeFactoryName, String moduleName, boolean
167167
final RubyModule module = getModule(moduleName, isClass);
168168
final Arity arity = createArity(required, optional, rest, keywordAsOptional);
169169

170-
Function<SharedMethodInfo, RubyNode> methodNodeFactory = sharedMethodInfo -> new LazyRubyNode(context, () -> {
170+
Function<SharedMethodInfo, RubyNode> methodNodeFactory = sharedMethodInfo -> new LazyRubyNode(language, () -> {
171171
final NodeFactory<? extends RubyNode> nodeFactory = loadNodeFactory(nodeFactoryName);
172172
final CoreMethod methodAnnotation = nodeFactory.getNodeClass().getAnnotation(CoreMethod.class);
173173
return createCoreMethodNode(nodeFactory, methodAnnotation, sharedMethodInfo);
@@ -266,7 +266,7 @@ public RubyNode createCoreMethodNode(NodeFactory<? extends RubyNode> nodeFactory
266266
final boolean needsSelf = needsSelf(method);
267267

268268
if (needsSelf) {
269-
RubyNode readSelfNode = Translator.profileArgument(context, new ReadSelfNode());
269+
RubyNode readSelfNode = Translator.profileArgument(language, new ReadSelfNode());
270270
argumentsNodes[i++] = transformArgument(method, readSelfNode, 0);
271271
}
272272

@@ -276,7 +276,7 @@ public RubyNode createCoreMethodNode(NodeFactory<? extends RubyNode> nodeFactory
276276

277277
for (int n = 0; n < nArgs; n++) {
278278
RubyNode readArgumentNode = Translator
279-
.profileArgument(context, new ReadPreArgumentNode(n, MissingArgumentBehavior.NOT_PROVIDED));
279+
.profileArgument(language, new ReadPreArgumentNode(n, MissingArgumentBehavior.NOT_PROVIDED));
280280
argumentsNodes[i++] = transformArgument(method, readArgumentNode, n + 1);
281281
}
282282

src/main/java/org/truffleruby/builtins/EnumeratorSizeNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.oracle.truffle.api.frame.VirtualFrame;
2121
import com.oracle.truffle.api.profiles.ConditionProfile;
2222

23-
2423
public class EnumeratorSizeNode extends RubyContextSourceNode {
2524

2625
@Child private RubyNode method;

src/main/java/org/truffleruby/builtins/ReturnEnumeratorIfNoBlockNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.oracle.truffle.api.frame.VirtualFrame;
2323
import com.oracle.truffle.api.profiles.ConditionProfile;
2424

25-
2625
public class ReturnEnumeratorIfNoBlockNode extends RubyContextSourceNode {
2726

2827
private final String methodName;

src/main/java/org/truffleruby/builtins/YieldingCoreMethodNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.truffleruby.core.proc.RubyProc;
1313
import org.truffleruby.language.yield.YieldNode;
1414

15-
1615
public abstract class YieldingCoreMethodNode extends CoreMethodArrayArgumentsNode {
1716

1817
@Child private YieldNode dispatchNode = YieldNode.create();

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.math.BigInteger;
1313
import java.util.concurrent.locks.ReentrantLock;
1414

15+
import com.oracle.truffle.api.dsl.CachedLanguage;
1516
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1617
import org.jcodings.Encoding;
1718
import org.jcodings.IntHolder;
@@ -1029,14 +1030,15 @@ public abstract static class StringToPointerNode extends CoreMethodArrayArgument
10291030
@Specialization
10301031
protected RubyPointer toNative(RubyString string,
10311032
@Cached StringToNativeNode stringToNativeNode,
1032-
@Cached AllocateHelperNode allocateNode) {
1033+
@Cached AllocateHelperNode allocateNode,
1034+
@CachedLanguage RubyLanguage language) {
10331035
final NativeRope nativeRope = stringToNativeNode.executeToNative(string);
10341036

10351037
final RubyPointer instance = new RubyPointer(
10361038
coreLibrary().truffleFFIPointerClass,
10371039
RubyLanguage.truffleFFIPointerShape,
10381040
nativeRope.getNativePointer());
1039-
allocateNode.trace(instance, this);
1041+
allocateNode.trace(instance, this, language);
10401042
return instance;
10411043
}
10421044

@@ -1246,7 +1248,8 @@ public abstract static class RbTrMbcCaseFoldNode extends CoreMethodArrayArgument
12461248
protected Object rbTrEncMbcCaseFold(RubyEncoding enc, int flags, RubyString string, Object write_p, Object p,
12471249
@CachedLibrary("write_p") InteropLibrary receivers,
12481250
@Cached AllocateHelperNode allocateNode,
1249-
@Cached TranslateInteropExceptionNode translateInteropExceptionNode) {
1251+
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
1252+
@CachedLanguage RubyLanguage language) {
12501253
final byte[] bytes = string.rope.getBytes();
12511254
final byte[] to = new byte[bytes.length];
12521255
final IntHolder intHolder = new IntHolder();
@@ -1259,6 +1262,7 @@ protected Object rbTrEncMbcCaseFold(RubyEncoding enc, int flags, RubyString stri
12591262
System.arraycopy(to, 0, result, 0, resultLength);
12601263
}
12611264
return StringOperations.createString(
1265+
language,
12621266
getContext(),
12631267
allocateNode,
12641268
this,
@@ -1276,7 +1280,8 @@ public abstract static class RbTrMbcPutNode extends CoreMethodArrayArgumentsNode
12761280

12771281
@Specialization
12781282
protected Object rbTrEncMbcPut(RubyEncoding enc, int code,
1279-
@Cached AllocateHelperNode allocateNode) {
1283+
@Cached AllocateHelperNode allocateNode,
1284+
@CachedLanguage RubyLanguage language) {
12801285
final Encoding encoding = enc.encoding;
12811286
final byte buf[] = new byte[org.jcodings.Config.ENC_CODE_TO_MBC_MAXLEN];
12821287
final int resultLength = encoding.codeToMbc(code, buf, 0);
@@ -1285,6 +1290,7 @@ protected Object rbTrEncMbcPut(RubyEncoding enc, int code,
12851290
System.arraycopy(buf, 0, result, 0, resultLength);
12861291
}
12871292
return StringOperations.createString(
1293+
language,
12881294
getContext(),
12891295
allocateNode,
12901296
this,

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public CoreLibrary(RubyContext context) {
322322
this.sourceSection = initCoreSourceSection(context);
323323
this.node = new CoreLibraryNode();
324324

325-
final RubyLanguage language = context.getLanguage();
325+
final RubyLanguage language = context.getLanguageSlow();
326326

327327
// Nothing in this constructor can use RubyContext.getCoreLibrary() as we are building it!
328328
// Therefore, only initialize the core classes and modules here.

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.PrintStream;
4141
import java.util.Map.Entry;
4242

43+
import com.oracle.truffle.api.dsl.CachedLanguage;
4344
import org.jcodings.specific.ASCIIEncoding;
4445
import org.jcodings.specific.UTF8Encoding;
4546
import org.truffleruby.RubyContext;
@@ -165,7 +166,8 @@ public static abstract class VMMethodLookupNode extends PrimitiveArrayArgumentsN
165166
@Specialization
166167
protected Object vmMethodLookup(VirtualFrame frame, Object receiver, Object name,
167168
@Cached NameToJavaStringNode nameToJavaStringNode,
168-
@Cached LookupMethodOnSelfNode lookupMethodNode) {
169+
@Cached LookupMethodOnSelfNode lookupMethodNode,
170+
@CachedLanguage RubyLanguage language) {
169171
// TODO BJF Sep 14, 2016 Handle private
170172
final String normalizedName = nameToJavaStringNode.execute(name);
171173
InternalMethod method = lookupMethodNode.lookupIgnoringVisibility(frame, receiver, normalizedName);
@@ -177,7 +179,7 @@ protected Object vmMethodLookup(VirtualFrame frame, Object receiver, Object name
177179
RubyLanguage.methodShape,
178180
receiver,
179181
method);
180-
allocateNode.trace(instance, this);
182+
allocateNode.trace(instance, this, language);
181183
return instance;
182184
}
183185

0 commit comments

Comments
 (0)