Skip to content

Commit 517f945

Browse files
committed
Avoid having a reference from ValueWrapperManager to RubyContext.
1 parent e331311 commit 517f945

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
210210
coreLibrary = new CoreLibrary(this, language);
211211
nativeConfiguration = NativeConfiguration.loadNativeConfiguration(this);
212212
coreLibrary.initialize();
213-
valueWrapperManager = new ValueWrapperManager(this);
213+
valueWrapperManager = new ValueWrapperManager();
214214
Metrics.printTime("after-create-core-library");
215215

216216
rootLexicalScope = new LexicalScope(null, coreLibrary.objectClass);

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ public class ValueWrapperManager {
6060

6161
private volatile HandleBlockWeakReference[] blockMap = new HandleBlockWeakReference[0];
6262

63-
private final RubyContext context;
64-
65-
public ValueWrapperManager(RubyContext context) {
66-
this.context = context;
67-
}
68-
69-
public HandleBlockHolder makeThreadData() {
63+
public HandleBlockHolder makeThreadData(RubyContext context) {
7064
HandleBlockHolder holder = new HandleBlockHolder();
7165
context.getFinalizationService().addFinalizer(
7266
context,
@@ -77,10 +71,10 @@ public HandleBlockHolder makeThreadData() {
7771
return holder;
7872
}
7973

80-
public HandleBlockHolder getBlockHolder(RubyLanguage language) {
74+
public HandleBlockHolder getBlockHolder(RubyContext context, RubyLanguage language) {
8175
RubyFiber fiber = language.getCurrentThread().getCurrentFiber();
8276
if (fiber.handleData == null) {
83-
fiber.handleData = makeThreadData();
77+
fiber.handleData = makeThreadData(context);
8478
}
8579
return fiber.handleData;
8680
}
@@ -96,7 +90,7 @@ public ValueWrapper doubleWrapper(double value) {
9690
}
9791

9892
@TruffleBoundary
99-
public synchronized void addToBlockMap(HandleBlock block, RubyLanguage language) {
93+
public synchronized void addToBlockMap(HandleBlock block, RubyContext context, RubyLanguage language) {
10094
int blockIndex = block.getIndex();
10195
long blockBase = block.getBase();
10296
HandleBlockAllocator allocator = language.handleBlockAllocator;
@@ -111,7 +105,7 @@ public synchronized void addToBlockMap(HandleBlock block, RubyLanguage language)
111105
}
112106

113107
@TruffleBoundary
114-
public void addToSharedBlockMap(HandleBlock block, RubyLanguage language) {
108+
public void addToSharedBlockMap(HandleBlock block, RubyContext context, RubyLanguage language) {
115109
synchronized (language) {
116110
int blockIndex = block.getIndex();
117111
long blockBase = block.getBase();
@@ -309,7 +303,7 @@ protected long allocateHandleOnKnownThread(ValueWrapper wrapper) {
309303
wrapper,
310304
getContext(),
311305
getLanguage(),
312-
getContext().getValueWrapperManager().getBlockHolder(getLanguage()),
306+
getContext().getValueWrapperManager().getBlockHolder(getContext(), getLanguage()),
313307
false);
314308
}
315309

@@ -319,7 +313,7 @@ protected long allocateSharedHandleOnKnownThread(ValueWrapper wrapper) {
319313
wrapper,
320314
getContext(),
321315
getLanguage(),
322-
getContext().getValueWrapperManager().getBlockHolder(getLanguage()),
316+
getContext().getValueWrapperManager().getBlockHolder(getContext(), getLanguage()),
323317
true);
324318
}
325319

@@ -342,10 +336,10 @@ protected static long allocateHandle(ValueWrapper wrapper, RubyContext context,
342336
}
343337
if (shared) {
344338
block = (holder.sharedHandleBlock = new HandleBlock(context, language.handleBlockAllocator));
345-
context.getValueWrapperManager().addToSharedBlockMap(block, language);
339+
context.getValueWrapperManager().addToSharedBlockMap(block, context, language);
346340
} else {
347341
block = (holder.handleBlock = new HandleBlock(context, language.handleBlockAllocator));
348-
context.getValueWrapperManager().addToBlockMap(block, language);
342+
context.getValueWrapperManager().addToBlockMap(block, context, language);
349343
}
350344

351345
}

0 commit comments

Comments
 (0)