[OSPL-Dev] JNI classloader issues

386 views
Skip to first unread message

Adam Wagner

unread,
Sep 4, 2009, 3:17:29 PM9/4/09
to deve...@opensplice.org
I'm trying to use OpenSplice within JBoss application server.  I developed a JBoss ESB service that uses OpenSplice.  I can deploy the service and it works fine, but then if I undeploy it and then deploy it again I get the following error when trying to get the domain participant factory.

16:56:46,374 ERROR [STDERR] DDS.DomainParticipantFactory.get_instance() failed: Native Library C:\Projects\fnicots\trunk\ospl-4.1\HDE\x86.win32\lib\dcpssaj.dll already loaded in another classloader

I think I understand what's happening.  The native library is loaded on the first deploy and then never unloaded (due to the way classloaders work), and then on the second deploy the call to System.loadLibrary fails.  This is more of a J2EE/JNI conflict that a problem with OpenSplice.  I was just wondering if anybody has experienced this before and knows of a resolution?

Thanks,
Adam

Holger Hoffstätte

unread,
Sep 7, 2009, 1:09:23 PM9/7/09
to OpenSplice DDS Developer Mailing List

The problem is manyfold and deep.

Contrary to popular "belief" native libraries _can_ and _are_ properly
unloaded by the JVM; this is documented and works. A native library is
associated with the classloader of the class that loaded it; when that
classloader is GC'ed, the library will be natively unloaded. For details
look into the code of java.lang.ClassLoader.finalize() where any loaded
libraries are released.

Note that I said "when the classloader is GC'ed", NOT "when the
classloader is not referenced any more". A container calling System.gc()
may or may not help; on servers it is usually explicitly disabled.
Different collectors (CMS, parallel, G1) have different aggressiveness and
consequently you will see different behaviour in all cases.

So it seems that JBoss does not free your service's classloader properly,
meaning either "in time" or "not at all" (both of which would lead to the
symptom that you observed). This can be caused by anything from bugs in
JBoss, the usual commons-logging cross-classloader logger reference leaks,
to static singletons in the OpenSplice Java library, or even the native
code still referencing Java objects.

It is not possible to tell which one of these factors are at play in your
case without a very detailed inspection of both your code and a live JVM -
though I suspect a combination of multiple causes, covering each other up. :(

regards
Holger

_______________________________________________
OpenSplice DDS Developer Mailing List
Deve...@opensplice.org
Subscribe / Unsubscribe http://www.opensplice.org/mailman/listinfo/developer

Adam Wagner

unread,
Sep 8, 2009, 6:14:18 PM9/8/09
to OpenSplice DDS Developer Mailing List
Holger,

Thanks for your insight.  I'll look into this in more detail and see if I can find a resolution.

- Adam

2009/9/7 Holger Hoffstätte <holger.ho...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages