Skip to content

Commit f21fb1e

Browse files
committed
[GR-15990] AST sharing fixes and download the JDK with mx fetch-jdk
PullRequest: truffleruby/2157
2 parents 9304b9e + adea47f commit f21fb1e

28 files changed

+199
-145
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
import java.util.Objects;
1818
import java.util.Map;
1919
import java.util.WeakHashMap;
20+
import java.util.concurrent.ConcurrentHashMap;
2021
import java.util.concurrent.locks.ReentrantLock;
2122
import java.util.logging.Level;
2223

2324
import com.oracle.truffle.api.CompilerAsserts;
2425
import com.oracle.truffle.api.CompilerDirectives;
26+
import com.oracle.truffle.api.RootCallTarget;
2527
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
2628
import com.oracle.truffle.api.nodes.Node;
29+
import org.graalvm.collections.Pair;
2730
import org.graalvm.options.OptionDescriptor;
2831
import org.joni.Regex;
2932
import org.truffleruby.cext.ValueWrapperManager;
@@ -43,6 +46,7 @@
4346
import org.truffleruby.core.kernel.AtExitManager;
4447
import org.truffleruby.core.kernel.TraceManager;
4548
import org.truffleruby.core.module.ModuleOperations;
49+
import org.truffleruby.core.module.RubyModule;
4650
import org.truffleruby.core.objectspace.ObjectSpaceManager;
4751
import org.truffleruby.core.proc.ProcOperations;
4852
import org.truffleruby.core.proc.RubyProc;
@@ -51,6 +55,7 @@
5155
import org.truffleruby.core.rope.Rope;
5256
import org.truffleruby.core.string.FrozenStringLiterals;
5357
import org.truffleruby.core.string.RubyString;
58+
import org.truffleruby.core.symbol.RubySymbol;
5459
import org.truffleruby.core.thread.ThreadManager;
5560
import org.truffleruby.core.time.GetTimeZoneNode;
5661
import org.truffleruby.debug.MetricsProfiler;
@@ -100,7 +105,7 @@ public class RubyContext {
100105
@CompilationFinal private TruffleFile rubyHomeTruffleFile;
101106
@CompilationFinal private boolean hadHome;
102107

103-
private final SafepointManager safepointManager = new SafepointManager(this);
108+
private final SafepointManager safepointManager;
104109
private final InteropManager interopManager = new InteropManager(this);
105110
private final CodeLoader codeLoader = new CodeLoader(this);
106111
private final FeatureLoader featureLoader;
@@ -121,6 +126,8 @@ public class RubyContext {
121126
private final NativeConfiguration nativeConfiguration;
122127
private final ValueWrapperManager valueWrapperManager;
123128
private final Map<Source, Integer> sourceLineOffsets = Collections.synchronizedMap(new WeakHashMap<>());
129+
/** (Symbol, refinements) -> Proc for Symbol#to_proc */
130+
public final Map<Pair<RubySymbol, Map<RubyModule, RubyModule[]>>, RootCallTarget> cachedSymbolToProcTargetsWithRefinements = new ConcurrentHashMap<>();
124131

125132
@CompilationFinal private SecureRandom random;
126133
private final Hashing hashing;
@@ -165,6 +172,7 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
165172

166173
options = createOptions(env, language.options);
167174

175+
safepointManager = new SafepointManager(this, language);
168176
frozenStringLiterals = new FrozenStringLiterals(this, language);
169177
coreExceptions = new CoreExceptions(this, language);
170178
encodingManager = new EncodingManager(this, language);

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.Objects;
1414
import java.util.concurrent.atomic.AtomicLong;
15+
import java.util.concurrent.locks.ReentrantLock;
1516

1617
import com.oracle.truffle.api.CompilerDirectives;
1718
import com.oracle.truffle.api.instrumentation.AllocationReporter;
@@ -115,7 +116,7 @@
115116
StandardTags.ReadVariableTag.class,
116117
StandardTags.WriteVariableTag.class,
117118
})
118-
public class RubyLanguage extends TruffleLanguage<RubyContext> {
119+
public final class RubyLanguage extends TruffleLanguage<RubyContext> {
119120

120121
public static final String PLATFORM = String.format(
121122
"%s-%s%s",
@@ -138,6 +139,11 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
138139
.createAssumption("single RubyContext per RubyLanguage instance");
139140
public final CyclicAssumption traceFuncUnusedAssumption = new CyclicAssumption("set_trace_func is not used");
140141

142+
private final ReentrantLock safepointLock = new ReentrantLock();
143+
@CompilationFinal private Assumption safepointAssumption = Truffle
144+
.getRuntime()
145+
.createAssumption("SafepointManager");
146+
141147
public final CoreMethodAssumptions coreMethodAssumptions;
142148
public final CoreStrings coreStrings;
143149
public final CoreSymbols coreSymbols;
@@ -222,6 +228,20 @@ public void invalidateTracingAssumption() {
222228
tracingAssumption = tracingCyclicAssumption.getAssumption();
223229
}
224230

231+
public Assumption getSafepointAssumption() {
232+
return safepointAssumption;
233+
}
234+
235+
public void invalidateSafepointAssumption(String reason) {
236+
safepointLock.lock();
237+
safepointAssumption.invalidate(reason);
238+
}
239+
240+
public void resetSafepointAssumption() {
241+
safepointAssumption = Truffle.getRuntime().createAssumption("SafepointManager");
242+
safepointLock.unlock();
243+
}
244+
225245
@Override
226246
protected void initializeMultipleContexts() {
227247
// TODO Make Symbol.all_symbols per context, by having a SymbolTable per context and creating new symbols with

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void addCoreMethod(RubyModule module, MethodDetails methodDetails) {
145145

146146
final Function<SharedMethodInfo, RootCallTarget> callTargetFactory = sharedMethodInfo -> {
147147
final RubyNode methodNode = createCoreMethodNode(nodeFactory, annotation, sharedMethodInfo);
148-
return createCallTarget(context, sharedMethodInfo, methodNode, split);
148+
return createCallTarget(language, sharedMethodInfo, methodNode, split);
149149
};
150150

151151
addMethods(module, isModuleFunc, onSingleton, names, arity, visibility, callTargetFactory);
@@ -173,7 +173,7 @@ public void addLazyCoreMethod(
173173
final NodeFactory<? extends RubyNode> nodeFactory = loadNodeFactory(nodeFactoryName);
174174
final CoreMethod annotation = nodeFactory.getNodeClass().getAnnotation(CoreMethod.class);
175175
final RubyNode methodNode = createCoreMethodNode(nodeFactory, annotation, sharedMethodInfo);
176-
return createCallTarget(context, sharedMethodInfo, methodNode, finalSplit);
176+
return createCallTarget(language, sharedMethodInfo, methodNode, finalSplit);
177177
};
178178

179179
addMethods(module, isModuleFunc, onSingleton, names, arity, visibility, callTargetFactory);
@@ -235,10 +235,10 @@ private static Arity createArity(int required, int optional, boolean rest, Strin
235235
: new Arity(required, optional, rest, 0, new String[]{ keywordAsOptional }, true, false);
236236
}
237237

238-
private static RootCallTarget createCallTarget(RubyContext context, SharedMethodInfo sharedMethodInfo,
238+
private static RootCallTarget createCallTarget(RubyLanguage language, SharedMethodInfo sharedMethodInfo,
239239
RubyNode methodNode, Split split) {
240240
final RubyRootNode rootNode = new RubyRootNode(
241-
context,
241+
language,
242242
sharedMethodInfo.getSourceSection(),
243243
null,
244244
sharedMethodInfo,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.truffleruby.language.RubyGuards;
7272
import org.truffleruby.language.RubyNode;
7373
import org.truffleruby.language.RubyRootNode;
74+
import org.truffleruby.language.SafepointManager;
7475
import org.truffleruby.language.Visibility;
7576
import org.truffleruby.language.arguments.RubyArguments;
7677
import org.truffleruby.language.backtrace.Backtrace;
@@ -1484,7 +1485,7 @@ public abstract static class CheckThreadInterrupt extends CoreMethodArrayArgumen
14841485

14851486
@Specialization
14861487
protected Object checkInts() {
1487-
getContext().getSafepointManager().poll(this);
1488+
SafepointManager.poll(getLanguage(), this);
14881489
return nil;
14891490
}
14901491
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.truffleruby.builtins.Primitive;
2323
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
2424
import org.truffleruby.collections.WeakValueCache;
25+
import org.truffleruby.language.SafepointManager;
2526

2627
@CoreModule("GC")
2728
public abstract class GCNodes {
@@ -68,7 +69,7 @@ protected Object force() {
6869

6970
do {
7071
System.gc();
71-
getContext().getSafepointManager().poll(this);
72+
SafepointManager.poll(getLanguage(), this);
7273
} while (cache.get(key) != null);
7374

7475
return nil;

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,8 +2178,8 @@ protected RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, NotProvid
21782178
"!isSmall(array)",
21792179
"stores.isPrimitive(array.store)" },
21802180
assumptions = {
2181-
"getContext().getLanguageSlow().coreMethodAssumptions.integerCmpAssumption",
2182-
"getContext().getLanguageSlow().coreMethodAssumptions.floatCmpAssumption" },
2181+
"getLanguage().coreMethodAssumptions.integerCmpAssumption",
2182+
"getLanguage().coreMethodAssumptions.floatCmpAssumption" },
21832183
limit = "storageStrategyLimit()")
21842184
protected Object sortPrimitiveArrayNoBlock(RubyArray array, NotProvided block,
21852185
@CachedLibrary("array.store") ArrayStoreLibrary stores,

src/main/java/org/truffleruby/core/cast/ToProcNode.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12+
import com.oracle.truffle.api.RootCallTarget;
1213
import org.truffleruby.core.module.RubyModule;
1314
import org.truffleruby.core.proc.RubyProc;
1415
import org.truffleruby.core.symbol.RubySymbol;
@@ -46,7 +47,7 @@ protected RubyProc doRubyProc(RubyProc proc) {
4647
// No need to guard the refinements here since refinements are always the same in a given source location
4748
@Specialization(
4849
guards = "symbol == cachedSymbol",
49-
assumptions = "getContext().getLanguageSlow().coreMethodAssumptions.symbolToProcAssumption",
50+
assumptions = "getLanguage().coreMethodAssumptions.symbolToProcAssumption",
5051
limit = "1")
5152
protected Object doRubySymbolASTInlined(VirtualFrame frame, RubySymbol symbol,
5253
@Cached("symbol") RubySymbol cachedSymbol,
@@ -84,7 +85,9 @@ protected RubyProc doObject(VirtualFrame frame, Object object,
8485
}
8586

8687
protected RubyProc getProcForSymbol(Map<RubyModule, RubyModule[]> refinements, RubySymbol symbol) {
87-
return SymbolNodes.ToProcNode.getOrCreateProc(getContext(), getLanguage(), refinements, symbol);
88+
final RootCallTarget callTarget = SymbolNodes.ToProcNode
89+
.getOrCreateCallTarget(getContext(), getLanguage(), symbol, refinements);
90+
return SymbolNodes.ToProcNode.createProc(getContext(), getLanguage(), refinements, callTarget);
8891
}
8992

9093
protected static Map<RubyModule, RubyModule[]> getRefinements(VirtualFrame frame) {

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ private InternalMethod createMissingMethod(Object self, Object name, String norm
13131313

13141314
final RubyNode newBody = new CallMethodMissingWithStaticName(name);
13151315
final RubyRootNode newRootNode = new RubyRootNode(
1316-
getContext(),
1316+
getLanguage(),
13171317
info.getSourceSection(),
13181318
new FrameDescriptor(nil),
13191319
info,

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected RootCallTarget methodCallTarget(InternalMethod method) {
304304

305305
final SetReceiverNode setReceiverNode = new SetReceiverNode(method.getCallTarget());
306306
final RootNode newRootNode = new RubyRootNode(
307-
getContext(),
307+
getLanguage(),
308308
sourceSection,
309309
oldRootNode.getFrameDescriptor(),
310310
method.getSharedMethodInfo(),

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ private void createAccessor(RubyModule module, String name, MaterializedFrame ca
436436
final RubyNode body = Translator
437437
.createCheckArityNode(language, arity, accessInstanceVariable);
438438
final RubyRootNode rootNode = new RubyRootNode(
439-
getContext(),
439+
language,
440440
sourceSection,
441441
null,
442442
sharedMethodInfo,
@@ -1214,7 +1214,7 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
12141214
final RubyNode body = NodeUtil.cloneNode(rootNode.getBody());
12151215
final RubyNode newBody = new CallMethodWithProcBody(proc.declarationFrame, body);
12161216
final RubyRootNode newRootNode = new RubyRootNode(
1217-
getContext(),
1217+
getLanguage(),
12181218
info.getSourceSection(),
12191219
rootNode.getFrameDescriptor(),
12201220
info,

0 commit comments

Comments
 (0)