Skip to content

Is Java RMI doesnt work traditional way with AdoptJDK Openj9 JVM? #10503

Open

Description

@smrutiprayag

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.

Sample code:

Registry registry = LocateRegistry.createRegistry(9002);
   RMIServer myServerInstance = new RMIServer();
   <<MyClassStub>>stub = <<MyClassStub>> UnicastRemoteObject.exportObject(myServerInstance, 9002);
            registry.rebind("RMIServer", stub);

Activity

  1. pshipton commented on Sep 23, 2020

    @pshipton
    Member

    What version of Java are you trying?

  2. tajila commented on Oct 20, 2020

    @tajila
    Contributor

    @mikezhang1234567890 Can you try to reproduce this

  3. mikezhang1234567890 commented on Oct 20, 2020

    @mikezhang1234567890
    Contributor

    Looking into it.

  4. mikezhang1234567890 commented on Oct 20, 2020

    @mikezhang1234567890
    Contributor

    Reproduced the issue, OpenJ9 seems to immediately discard the new server after creating it. Looking further.

  5. mikezhang1234567890 commented on Nov 19, 2020

    @mikezhang1234567890
    Contributor

    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?

  6. dmitripivkine commented on Nov 19, 2020

    @dmitripivkine
    Contributor

    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)

  7. tajila commented on Dec 2, 2020

    @tajila
    Contributor

    @mikezhang1234567890 is there an update on this?

  8. mikezhang1234567890 commented on Dec 2, 2020

    @mikezhang1234567890
    Contributor

    Still looking into why the remote object gets GC'd early. Don't think this will be done in time for 0.24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions