Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit a610dbd

Browse files
fh-mszdenek-jonas
authored andcommitted
Fix DBB cleaner invocation (#694)
(cherry picked from commit 36ec2af)
1 parent 3c2e345 commit a610dbd

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

base/src/main/java/one/microstream/memory/sun/JdkInternals.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -441,33 +441,7 @@ public static final boolean internalDeallocateDirectBuffer(final ByteBuffer dire
441441

442442
XTypes.guaranteeDirectByteBuffer(directBuffer);
443443

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);
471445

472446
return true;
473447
}

0 commit comments

Comments
 (0)