At Thu, 18 Oct 2012 15:48:22 +0000,
Benjamin Wang (gendwang) wrote:
Hi,
When I changed code as following:
public class Connect {
// Load the native part
static {
Libvirt.INSTANCE.virInitialize();
try {
ErrorHandler.processError(Libvirt.INSTANCE);
} catch (Exception e) {
e.printStackTrace();
}
+ Libvirt.INSTANCE.virSetErrorFunc(null, new ErrorCallback());
}
The server will generate the following core dump:
Program terminated with signal 6, Aborted.
#0 0x0000003f9b030265 in raise () from /lib64/libc.so.6
(gdb) where
#0 0x0000003f9b030265 in raise () from /lib64/libc.so.6
#1 0x0000003f9b031d10 in abort () from /lib64/libc.so.6
#2 0x0000003f9b06a84b in __libc_message () from /lib64/libc.so.6
#3 0x0000003f9b07230f in _int_free () from /lib64/libc.so.6
#4 0x0000003f9b07276b in free () from /lib64/libc.so.6
#5 0x00002aaaacf46868 in ?? ()
#6 0x0000000000000000 in ?? ()
The problem was caused that when JNA call setErrorFunc, it will
create ErrorCallback object. But when GC is executed, the object is
GCed.
This should not lead to the crash above.
But even I change code as following. When GC is excuted, the
callback object will be moved. Then C can't find this object.
No, this cannot happen. The VM keeps track of its objects, the C code
never gets a direct pointer to an object but only a handle and JNA is
registering a trampoline function in native code which doesn't move.
Both of scenarios will cause core dump. It seems that JNA mustn't
provide ErrorCallback Class,
Because nobody can use this.
Please correct me.
Which version of JNA are you using?
Which OS and which machine type?
Are you running this on a virtual machine? If yes, which one?
Which JVM are you using?
There's a unit test which exercises the Connect.setErrorCallback
method (which in turn calls virSetErrorFunc). This test works for me
for any version of JNA from 3.3.0 to 4.0.0 using OpenJDK 1.6.0 64bit
on Linux. Did you try to run the unit tests?
Could you show us the Java crash dump?
Claudio
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern