@@ -227,9 +227,6 @@ private HandleBlock() {
227
227
public HandleBlock (RubyContext context , RubyLanguage language , ValueWrapperManager manager ) {
228
228
HandleBlockAllocator allocator = language .handleBlockAllocator ;
229
229
long base = allocator .getFreeBlock ();
230
- if (context != null && context .getOptions ().CEXTS_KEEP_HANDLES_ALIVE ) {
231
- keepAlive (this );
232
- }
233
230
this .base = base ;
234
231
this .wrappers = new ValueWrapperWeakReference [BLOCK_SIZE ];
235
232
this .count = 0 ;
@@ -243,11 +240,6 @@ private static Runnable makeCleaner(ValueWrapperManager manager, long base, Hand
243
240
};
244
241
}
245
242
246
- @ TruffleBoundary
247
- private static void keepAlive (HandleBlock block ) {
248
- keepAlive .add (block );
249
- }
250
-
251
243
public long getBase () {
252
244
return base ;
253
245
}
@@ -298,10 +290,15 @@ public static class HandleBlockHolder {
298
290
@ GenerateUncached
299
291
public abstract static class AllocateHandleNode extends RubyBaseNode {
300
292
293
+ private static final Set <ValueWrapper > keepAlive = ConcurrentHashMap .newKeySet ();
294
+
301
295
public abstract long execute (ValueWrapper wrapper );
302
296
303
297
@ Specialization (guards = "!isSharedObject(wrapper)" )
304
298
protected long allocateHandleOnKnownThread (ValueWrapper wrapper ) {
299
+ if (getContext ().getOptions ().CEXTS_KEEP_HANDLES_ALIVE ) {
300
+ keepAlive (wrapper );
301
+ }
305
302
return allocateHandle (
306
303
wrapper ,
307
304
getContext (),
@@ -312,6 +309,9 @@ protected long allocateHandleOnKnownThread(ValueWrapper wrapper) {
312
309
313
310
@ Specialization (guards = "isSharedObject(wrapper)" )
314
311
protected long allocateSharedHandleOnKnownThread (ValueWrapper wrapper ) {
312
+ if (getContext ().getOptions ().CEXTS_KEEP_HANDLES_ALIVE ) {
313
+ keepAlive (wrapper );
314
+ }
315
315
return allocateHandle (
316
316
wrapper ,
317
317
getContext (),
@@ -320,6 +320,11 @@ protected long allocateSharedHandleOnKnownThread(ValueWrapper wrapper) {
320
320
true );
321
321
}
322
322
323
+ @ TruffleBoundary
324
+ protected static void keepAlive (ValueWrapper wrapper ) {
325
+ keepAlive .add (wrapper );
326
+ }
327
+
323
328
protected long allocateHandle (ValueWrapper wrapper , RubyContext context , RubyLanguage language ,
324
329
HandleBlockHolder holder , boolean shared ) {
325
330
HandleBlock block ;
0 commit comments