Skip to content

Commit 4598218

Browse files
committed
Small cleanup of Pointer.
1 parent bc1eee1 commit 4598218

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/truffleruby/extra/ffi/Pointer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public static Pointer callocAutoRelease(long size, RubyLanguage langauge) {
6565
private Cleanable cleanable = null;
6666
private AutoReleaseState autoReleaseState = null;
6767

68+
/** This is needed because we need a mutable object to hold the pointer address so that it can be freed or marked as
69+
* not to be freed if auto-release is disabled. THis can't be the address field on the pointer itself as that would
70+
* prevent the pointer from being collected, and we can't retrieve this from the cleaner as it is effectively
71+
* opaque. */
6872
private static class AutoReleaseState implements Runnable {
6973

7074
long address;
@@ -352,8 +356,9 @@ public synchronized void enableAutorelease(RubyLanguage language) {
352356

353357
@TruffleBoundary
354358
private void enableAutoreleaseUnsynchronized(RubyLanguage language) {
355-
// We must be careful here that the finalizer does not capture the Pointer itself that we'd
356-
// like to finalize.
359+
// We must be careful here that the cleaner does not capture
360+
// the Pointer itself, and that we a form of mutable state
361+
// that will allow use to disable autorelease later.
357362
autoReleaseState = new AutoReleaseState(address);
358363
cleanable = language.cleaner.register(this, autoReleaseState);
359364

0 commit comments

Comments
 (0)