Remove use of finalizers in JNA and improve concurrency for Memory, CallbackReference and NativeLibrary#1402
Conversation
fca09be to
77755e1
Compare
|
The finalizer mechanism is deprecated for removal: https://mail.openjdk.java.net/pipermail/jdk-dev/2021-November/006279.html |
|
FYI, I've got a report of running out of memory that I'm pretty sure is related to excessive use of finalizer in the |
79c98e0 to
7a2387b
Compare
|
@dbwiddis - I reread the changes and the API is still intact. There is a potential behavioral change, but I think it should not be common that people overrode |
dbwiddis
left a comment
There was a problem hiding this comment.
LGTM, but a few comments/suggestions.
| if(ref instanceof CleanerRef) { | ||
| ((CleanerRef) ref).clean(); | ||
| } | ||
| } catch (InterruptedException ex) { |
There was a problem hiding this comment.
Should we set Thread.currentThread.interrupt() here? I recognize that the thread will essentially terminate on an interrupt and it probably doesn't matter in practice, but will keep static analysis tools happier.
There was a problem hiding this comment.
I don't get the intention. InterruptedException is raised if the waiting thread is interrupted (in this case the cleaner thread). Why would an analyser expect that the threads interrupts itself again?
There was a problem hiding this comment.
Analyzers don't like when you catch an interrupted exception and do nothing. The general guidance is to either re-throw the exception or re-set the interrupted flag so that any upstream code recognizes the interruption.
As I said it probably doesn't matter in this case as the thread just terminates. (I'm not sure if it would terminate with a different exit code with that flag or not, or if that matters.)
This article says what I'm saying a lot better than I can: https://programming.guide/java/handling-interrupted-exceptions.html
|
Ok - this needs more work - the unittests became flaky. I first thought, that the cleaner implementation of |
9a64627 to
be1a2d0
Compare
|
This is the problematic part: I still try to understand how we could end there. |
I suspect a race condition in |
|
FYI, long-running program with the Memory portion of this PR resolved the out-of-memory issues seen earlier with too many finalizers. So if we can resolve the test failures this looks like a good improvement. |
edb7975 to
cb5be82
Compare
|
So what happened: I removed the changes to the platform code, added stabilization to some of the regularly failing tests to get noise down or get better diagnostics. Multiple runs got through cleanly or reported errors that are "consistent" with breaks, that can happen in a shared system. I intent to merge this at the end of the week end. |
The following uses of finalizers were replaced by a Cleaner or removed because they are unneeded: - c.s.j.Memory#finalize - c.s.j.CallbackReference#finalize - c.s.j.NativeLibrary#finalize The cleanup handling is moved to the #close method and #dispose is being deprecated. Anyone relying on #dispose being called from the GC has to take action now! If a subclass needs a cleanup after this object goes out of scope, it will need to register a cleaner.
…UnloadFromResourcePath on Intel 32bit
cb5be82 to
cebf3ac
Compare
No description provided.