Skip to content

Commit 2f73c15

Browse files
committed
Make handle data final on RubyFiber.
1 parent 542ec11 commit 2f73c15

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public HandleBlockHolder makeThreadData(RubyContext context) {
7272
}
7373

7474
public HandleBlockHolder getBlockHolder(RubyContext context, RubyLanguage language) {
75-
RubyFiber fiber = language.getCurrentThread().getCurrentFiber();
76-
if (fiber.handleData == null) {
77-
fiber.handleData = makeThreadData(context);
78-
}
79-
return fiber.handleData;
75+
return language.getCurrentThread().getCurrentFiber().handleData;
8076
}
8177

8278
/* We keep a map of long wrappers that have been generated because various C extensions assume that any given fixnum
@@ -174,6 +170,11 @@ public void freeAllBlocksInMap(RubyLanguage language) {
174170
}
175171
}
176172

173+
public void cleanup(RubyContext context, HandleBlockHolder holder) {
174+
context.getMarkingService().queueForMarking(holder.handleBlock);
175+
holder.handleBlock = null;
176+
}
177+
177178
protected static class FreeHandleBlock {
178179
public final long start;
179180
public final FreeHandleBlock next;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public void start(RubyFiber fiber, Thread javaThread) {
299299
public void cleanup(RubyFiber fiber, Thread javaThread) {
300300
final ThreadManager threadManager = context.getThreadManager();
301301

302+
context.getValueWrapperManager().cleanup(context, fiber.handleData);
303+
302304
fiber.alive = false;
303305

304306
threadManager.cleanupValuesForJavaThread(javaThread);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public final class RubyFiber extends RubyDynamicObject implements ObjectGraphNod
4747
public volatile Throwable uncaughtException = null;
4848
String sourceLocation;
4949
public final MarkingService.ExtensionCallStack extensionCallStack;
50-
public ValueWrapperManager.HandleBlockHolder handleData = null;
50+
public final ValueWrapperManager.HandleBlockHolder handleData;
5151

5252
public RubyFiber(
5353
RubyClass rubyClass,
@@ -66,6 +66,7 @@ public RubyFiber(
6666
this.rubyThread = rubyThread;
6767
this.sourceLocation = sourceLocation;
6868
extensionCallStack = new MarkingService.ExtensionCallStack(Nil.INSTANCE);
69+
handleData = new ValueWrapperManager.HandleBlockHolder();
6970
}
7071

7172
public boolean isRootFiber() {

0 commit comments

Comments
 (0)