You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is Java RMI doesnt work traditional way with AdoptJDK Openj9 JVM? #10503
I am trying to start a simple RMI server with AdoptOpenJDK's OpenJ9 JVM but, the program exits with no error/exception and the RMI server doesn't start. The exact same program works with AdoptOpenJDK's HotSpot JVM and other oracle variants.
OpenJDK uses the RMI reaper thread to keep itself alive (as seen in comments here). When UnicastRemoteObject.exportObject is called, a WeakReference is created and registered to the ReferenceQueue in the reaper. When the exported object is to be destroyed, the reaper checks if there are no more exported objects left to keep track of, then the reaper thread will kill itself, and the VM if there are no other threads keeping it alive.
I believe that in OpenJ9 the exported object gets GC'd too early, which causes the WeakReference to be added to the queue, which in turn causes the reaper to run its cleanup and check if it has anything else to keep track of. In the example snippet given above, there is no other object, so the reaper thread ends and nothing is keeping the VM alive.
However, when I ran the code in a debugger (VS Code's Java debugger in my case), set a breakpoint at the UnicastRemoteObject.exportObject line, stepped over that line, then continued, the exported object's reference was never added to the reaper's queue and thus the reaper thread continued to block waiting for a reference to clean up. I think this is because the debugger prevented the WeakReference from being GC'd.
@dmitripivkine do you have any insight on if it is a GC issue here?
GC is going to process Weak Reference as soon as discovers that referent is not reachable any more (immediately). So if object should not die it should be reachable from the roots. Alternatively using of Soft Reference however might extend referent life for a period of time (32 collections)
Activity
pshipton commentedon Sep 23, 2020
What version of Java are you trying?
tajila commentedon Oct 20, 2020
@mikezhang1234567890 Can you try to reproduce this
mikezhang1234567890 commentedon Oct 20, 2020
Looking into it.
mikezhang1234567890 commentedon Oct 20, 2020
Reproduced the issue, OpenJ9 seems to immediately discard the new server after creating it. Looking further.
mikezhang1234567890 commentedon Nov 19, 2020
OpenJDK uses the RMI reaper thread to keep itself alive (as seen in comments here). When
UnicastRemoteObject.exportObjectis called, a WeakReference is created and registered to the ReferenceQueue in the reaper. When the exported object is to be destroyed, the reaper checks if there are no more exported objects left to keep track of, then the reaper thread will kill itself, and the VM if there are no other threads keeping it alive.I believe that in OpenJ9 the exported object gets GC'd too early, which causes the WeakReference to be added to the queue, which in turn causes the reaper to run its cleanup and check if it has anything else to keep track of. In the example snippet given above, there is no other object, so the reaper thread ends and nothing is keeping the VM alive.
However, when I ran the code in a debugger (VS Code's Java debugger in my case), set a breakpoint at the
UnicastRemoteObject.exportObjectline, stepped over that line, then continued, the exported object's reference was never added to the reaper's queue and thus the reaper thread continued to block waiting for a reference to clean up. I think this is because the debugger prevented the WeakReference from being GC'd.@dmitripivkine do you have any insight on if it is a GC issue here?
dmitripivkine commentedon Nov 19, 2020
GC is going to process Weak Reference as soon as discovers that referent is not reachable any more (immediately). So if object should not die it should be reachable from the roots. Alternatively using of Soft Reference however might extend referent life for a period of time (32 collections)
tajila commentedon Dec 2, 2020
@mikezhang1234567890 is there an update on this?
mikezhang1234567890 commentedon Dec 2, 2020
Still looking into why the remote object gets GC'd early. Don't think this will be done in time for 0.24.