Skip to content

Commit 1c925c7

Browse files
committed
Give CachedLazyCallTargetSupplier a more specific name, and put the transfer in it
1 parent 5afb83e commit 1c925c7

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.oracle.truffle.api.TruffleSafepoint;
1717
import org.truffleruby.RubyContext;
1818
import org.truffleruby.RubyLanguage;
19-
import org.truffleruby.collections.CachedSupplier;
19+
import org.truffleruby.language.methods.CachedLazyCallTargetSupplier;
2020
import org.truffleruby.core.CoreLibrary;
2121
import org.truffleruby.core.DummyNode;
2222
import org.truffleruby.core.array.ArrayUtils;
@@ -253,7 +253,7 @@ private static void addMethod(
253253
arity);
254254

255255
final RootCallTarget callTarget;
256-
final CachedSupplier<RootCallTarget> callTargetSupplier;
256+
final CachedLazyCallTargetSupplier callTargetSupplier;
257257
final NodeFactory<? extends RubyBaseNode> alwaysInlinedNodeFactory;
258258
if (alwaysInlined) {
259259
callTarget = callTargetFactory.apply(sharedMethodInfo);
@@ -262,10 +262,8 @@ private static void addMethod(
262262
} else {
263263
if (context.getLanguageSlow().options.LAZY_CALLTARGETS) {
264264
callTarget = null;
265-
callTargetSupplier = new CachedSupplier<>(() -> {
266-
CompilerDirectives.transferToInterpreterAndInvalidate();
267-
return callTargetFactory.apply(sharedMethodInfo);
268-
});
265+
callTargetSupplier = new CachedLazyCallTargetSupplier(
266+
() -> callTargetFactory.apply(sharedMethodInfo));
269267
} else {
270268
callTarget = callTargetFactory.apply(sharedMethodInfo);
271269
callTargetSupplier = null;

src/main/java/org/truffleruby/collections/CachedSupplier.java renamed to src/main/java/org/truffleruby/language/methods/CachedLazyCallTargetSupplier.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@
77
* GNU General Public License version 2, or
88
* GNU Lesser General Public License version 2.1.
99
*/
10-
package org.truffleruby.collections;
10+
package org.truffleruby.language.methods;
11+
12+
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.RootCallTarget;
1114

1215
import java.util.function.Supplier;
1316

14-
public class CachedSupplier<T> {
17+
public class CachedLazyCallTargetSupplier {
1518

16-
private volatile T value = null;
17-
private Supplier<T> supplier;
19+
private volatile RootCallTarget value = null;
20+
private Supplier<RootCallTarget> supplier;
1821

19-
public CachedSupplier(Supplier<T> supplier) {
22+
public CachedLazyCallTargetSupplier(Supplier<RootCallTarget> supplier) {
2023
this.supplier = supplier;
2124
}
2225

23-
public T get() {
26+
public RootCallTarget get() {
2427
if (isAvailable()) {
2528
return value;
2629
}
30+
CompilerDirectives.transferToInterpreterAndInvalidate();
2731
synchronized (this) {
2832
if (value == null) {
2933
value = supplier.get();

src/main/java/org/truffleruby/language/methods/InternalMethod.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1515
import com.oracle.truffle.api.dsl.NodeFactory;
1616
import org.truffleruby.RubyContext;
17-
import org.truffleruby.collections.CachedSupplier;
1817
import org.truffleruby.core.klass.RubyClass;
1918
import org.truffleruby.core.module.RubyModule;
2019
import org.truffleruby.core.proc.RubyProc;
@@ -52,7 +51,7 @@ public class InternalMethod implements ObjectGraphNode {
5251
public final NodeFactory<? extends RubyBaseNode> alwaysInlinedNodeFactory;
5352
private final RubyProc proc; // only if method is created from a Proc
5453

55-
private final CachedSupplier<RootCallTarget> callTargetSupplier;
54+
private final CachedLazyCallTargetSupplier callTargetSupplier;
5655
@CompilationFinal private RootCallTarget callTarget;
5756

5857
public static InternalMethod fromProc(
@@ -116,7 +115,7 @@ public InternalMethod(
116115
NodeFactory<? extends RubyBaseNode> alwaysInlined,
117116
RubyProc proc,
118117
RootCallTarget callTarget,
119-
CachedSupplier<RootCallTarget> callTargetSupplier) {
118+
CachedLazyCallTargetSupplier callTargetSupplier) {
120119
this(
121120
sharedMethodInfo,
122121
lexicalScope,
@@ -150,7 +149,7 @@ private InternalMethod(
150149
DeclarationContext activeRefinements,
151150
RubyProc proc,
152151
RootCallTarget callTarget,
153-
CachedSupplier<RootCallTarget> callTargetSupplier) {
152+
CachedLazyCallTargetSupplier callTargetSupplier) {
154153
assert declaringModule != null;
155154
assert lexicalScope != null;
156155
assert !sharedMethodInfo.isBlock() : sharedMethodInfo;

src/main/java/org/truffleruby/language/methods/LiteralMethodDefinitionNode.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
import com.oracle.truffle.api.instrumentation.InstrumentableNode;
1414
import com.oracle.truffle.api.instrumentation.StandardTags;
1515
import com.oracle.truffle.api.instrumentation.Tag;
16-
import org.truffleruby.collections.CachedSupplier;
1716
import org.truffleruby.core.module.RubyModule;
1817
import org.truffleruby.language.RubyContextSourceNode;
1918
import org.truffleruby.language.RubyNode;
2019
import org.truffleruby.language.Visibility;
2120
import org.truffleruby.language.arguments.RubyArguments;
2221

23-
import com.oracle.truffle.api.RootCallTarget;
2422
import com.oracle.truffle.api.frame.VirtualFrame;
2523

2624
import java.util.Set;
@@ -32,7 +30,7 @@ public class LiteralMethodDefinitionNode extends RubyContextSourceNode {
3230
private final String name;
3331
private final SharedMethodInfo sharedMethodInfo;
3432
private final boolean isDefSingleton;
35-
private final CachedSupplier<RootCallTarget> callTargetSupplier;
33+
private final CachedLazyCallTargetSupplier callTargetSupplier;
3634

3735
@Child private RubyNode moduleNode;
3836

@@ -41,7 +39,7 @@ public LiteralMethodDefinitionNode(
4139
String name,
4240
SharedMethodInfo sharedMethodInfo,
4341
boolean isDefSingleton,
44-
CachedSupplier<RootCallTarget> callTargetSupplier) {
42+
CachedLazyCallTargetSupplier callTargetSupplier) {
4543
this.name = name;
4644
this.sharedMethodInfo = sharedMethodInfo;
4745
this.isDefSingleton = isDefSingleton;

src/main/java/org/truffleruby/parser/MethodTranslator.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
import java.util.Arrays;
1313
import java.util.function.Supplier;
1414

15-
import com.oracle.truffle.api.CompilerDirectives;
1615
import org.truffleruby.RubyLanguage;
17-
import org.truffleruby.collections.CachedSupplier;
16+
import org.truffleruby.language.methods.CachedLazyCallTargetSupplier;
1817
import org.truffleruby.core.IsNilNode;
1918
import org.truffleruby.core.cast.SplatCastNode;
2019
import org.truffleruby.core.cast.SplatCastNode.NilBehavior;
@@ -419,17 +418,15 @@ private RubyMethodRootNode translateMethodNode(SourceIndexLength sourceSection,
419418
argsNode.getArity());
420419
}
421420

422-
public CachedSupplier<RootCallTarget> buildMethodNodeCompiler(SourceIndexLength sourceSection,
421+
public CachedLazyCallTargetSupplier buildMethodNodeCompiler(SourceIndexLength sourceSection,
423422
MethodDefParseNode defNode, ParseNode bodyNode) {
424423

425424
if (shouldLazyTranslate) {
426-
return new CachedSupplier<>(() -> {
427-
CompilerDirectives.transferToInterpreterAndInvalidate();
428-
return translateMethodNode(sourceSection, defNode, bodyNode).getCallTarget();
429-
});
425+
return new CachedLazyCallTargetSupplier(
426+
() -> translateMethodNode(sourceSection, defNode, bodyNode).getCallTarget());
430427
} else {
431428
final RubyMethodRootNode root = translateMethodNode(sourceSection, defNode, bodyNode);
432-
return new CachedSupplier<>(() -> root.getCallTarget());
429+
return new CachedLazyCallTargetSupplier(() -> root.getCallTarget());
433430
}
434431
}
435432

0 commit comments

Comments
 (0)