@@ -441,33 +441,7 @@ public static final boolean internalDeallocateDirectBuffer(final ByteBuffer dire
441
441
442
442
XTypes .guaranteeDirectByteBuffer (directBuffer );
443
443
444
- final Object cleaner = getObject (directBuffer , FIELD_OFFSET_DirectByteBuffer_cleaner );
445
- final Object cleanerThunkDeallocatorRunnable = getObject (cleaner , FIELD_OFFSET_Cleaner_thunk );
446
-
447
- if (!(cleanerThunkDeallocatorRunnable instanceof Runnable ))
448
- {
449
- // better to not deallocate and hope the DBB will get cleaned up by the GC instead of an exception
450
- return false ;
451
- }
452
-
453
- // at least secure this call externally against race conditions if the geniuses can't do it internally
454
- synchronized (cleanerThunkDeallocatorRunnable )
455
- {
456
- ((Runnable )cleanerThunkDeallocatorRunnable ).run ();
457
-
458
- /*
459
- * Must be set explicitly since the deallocator only sets his copy of the address to 0.
460
- * It might seem dangerous to zero out the address of a still reachable and potentially used
461
- * direct byte buffer, but this logic here is only executed if the DirectByteBuffer is explicitly
462
- * deallocated. If it is still used after that, it is simple a programming error, not different
463
- * from writing to a wrong memory address.
464
- * So zeroing out the address is the correct thing to do and keep the state consistent
465
- * and on the other hand prevent access to allegedly still allocated memory while in fact, it has
466
- * already been deallocated. It is much better to encounter a zero address in such a case than to
467
- * chaotically read or even write from/to memory that might already have been allocated for something else.
468
- */
469
- set_long (directBuffer , FIELD_OFFSET_Buffer_address , 0 );
470
- }
444
+ VM .invokeCleaner (directBuffer );
471
445
472
446
return true ;
473
447
}
0 commit comments