Skip to content

Commit 55970cf

Browse files
committed
Move logic in the RubyFiber constructor and call it directly
1 parent ddce559 commit 55970cf

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616
import org.truffleruby.RubyContext;
1717
import org.truffleruby.RubyLanguage;
1818
import org.truffleruby.core.DummyNode;
19-
import org.truffleruby.core.array.ArrayHelpers;
20-
import org.truffleruby.core.array.RubyArray;
2119
import org.truffleruby.core.basicobject.BasicObjectNodes.ObjectIDNode;
22-
import org.truffleruby.core.basicobject.RubyBasicObject;
2320
import org.truffleruby.core.exception.ExceptionOperations;
2421
import org.truffleruby.core.exception.RubyException;
25-
import org.truffleruby.core.klass.RubyClass;
2622
import org.truffleruby.core.proc.ProcOperations;
2723
import org.truffleruby.core.thread.RubyThread;
2824
import org.truffleruby.core.proc.RubyProc;
@@ -35,11 +31,9 @@
3531
import org.truffleruby.language.control.RaiseException;
3632
import org.truffleruby.language.control.TerminationException;
3733

38-
import com.oracle.truffle.api.CompilerAsserts;
3934
import com.oracle.truffle.api.CompilerDirectives;
4035
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4136
import com.oracle.truffle.api.nodes.Node;
42-
import com.oracle.truffle.api.object.Shape;
4337
import com.oracle.truffle.api.profiles.BranchProfile;
4438
import com.oracle.truffle.api.source.SourceSection;
4539
import org.truffleruby.language.objects.shared.SharedObjects;
@@ -57,27 +51,6 @@ public FiberManager(RubyLanguage language, RubyContext context) {
5751
this.context = context;
5852
}
5953

60-
public static RubyFiber createRootFiber(RubyLanguage language, RubyContext context, RubyThread thread) {
61-
return createFiber(
62-
language,
63-
context,
64-
thread,
65-
context.getCoreLibrary().fiberClass,
66-
language.fiberShape,
67-
"root");
68-
}
69-
70-
public static RubyFiber createFiber(RubyLanguage language, RubyContext context, RubyThread thread,
71-
RubyClass rubyClass, Shape shape, String sourceLocation) {
72-
CompilerAsserts.partialEvaluationConstant(language);
73-
final RubyBasicObject fiberLocals = new RubyBasicObject(
74-
context.getCoreLibrary().objectClass,
75-
language.basicObjectShape);
76-
final RubyArray catchTags = ArrayHelpers.createEmptyArray(context, language);
77-
78-
return new RubyFiber(rubyClass, shape, fiberLocals, catchTags, thread, sourceLocation);
79-
}
80-
8154
public void initialize(RubyFiber fiber, RubyProc block, Node currentNode) {
8255
final SourceSection sourceSection = block.sharedMethodInfo.getSourceSection();
8356
fiber.sourceLocation = RubyLanguage.fileLine(sourceSection);

src/main/java/org/truffleruby/core/fiber/FiberNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ protected RubyFiber allocate(RubyClass rubyClass) {
9494
}
9595

9696
final RubyThread thread = getLanguage().getCurrentThread();
97-
final RubyFiber fiber = FiberManager.createFiber(
98-
getLanguage(),
99-
getContext(),
100-
thread,
97+
final RubyFiber fiber = new RubyFiber(
10198
rubyClass,
10299
getLanguage().fiberShape,
100+
getContext(),
101+
getLanguage(),
102+
thread,
103103
"<uninitialized>");
104104
AllocationTracing.trace(fiber, this);
105105
return fiber;

src/main/java/org/truffleruby/core/fiber/RubyFiber.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import java.util.concurrent.CountDownLatch;
1515
import java.util.concurrent.LinkedBlockingQueue;
1616

17+
import com.oracle.truffle.api.CompilerAsserts;
18+
import org.truffleruby.RubyContext;
19+
import org.truffleruby.RubyLanguage;
20+
import org.truffleruby.core.array.ArrayHelpers;
1721
import org.truffleruby.core.array.RubyArray;
1822
import org.truffleruby.core.basicobject.RubyBasicObject;
1923
import org.truffleruby.core.klass.RubyClass;
@@ -43,14 +47,17 @@ public final class RubyFiber extends RubyDynamicObject implements ObjectGraphNod
4347
public RubyFiber(
4448
RubyClass rubyClass,
4549
Shape shape,
46-
RubyBasicObject fiberLocals,
47-
RubyArray catchTags,
50+
RubyContext context,
51+
RubyLanguage language,
4852
RubyThread rubyThread,
4953
String sourceLocation) {
5054
super(rubyClass, shape);
5155
assert rubyThread != null;
52-
this.fiberLocals = fiberLocals;
53-
this.catchTags = catchTags;
56+
CompilerAsserts.partialEvaluationConstant(language);
57+
this.fiberLocals = new RubyBasicObject(
58+
context.getCoreLibrary().objectClass,
59+
language.basicObjectShape);
60+
this.catchTags = ArrayHelpers.createEmptyArray(context, language);
5461
this.rubyThread = rubyThread;
5562
this.sourceLocation = sourceLocation;
5663
}

src/main/java/org/truffleruby/core/thread/RubyThread.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.truffleruby.RubyLanguage;
2424
import org.truffleruby.core.InterruptMode;
2525
import org.truffleruby.core.exception.RubyException;
26-
import org.truffleruby.core.fiber.FiberManager;
2726
import org.truffleruby.core.fiber.RubyFiber;
2827
import org.truffleruby.core.hash.HashOperations;
2928
import org.truffleruby.core.hash.RubyHash;
@@ -90,7 +89,13 @@ public RubyThread(
9089

9190
// Initialized last as it captures `this`
9291
MemoryFence.storeStore();
93-
this.rootFiber = FiberManager.createRootFiber(language, context, this);
92+
this.rootFiber = new RubyFiber(
93+
context.getCoreLibrary().fiberClass,
94+
language.fiberShape,
95+
context,
96+
language,
97+
this,
98+
"root");
9499
this.currentFiber = rootFiber;
95100
}
96101

0 commit comments

Comments
 (0)