JNI oddity in OpenJDK

Joe Osborne joe.osborne at swiftkey.net
Thu Jun 14 01:21:10 PDT 2012


Hi all,

I've been recommended by a couple of members far wiser than I to bring this
issue to this mailing list.

We've recently switched from using Sun's JDK to OpenJDK6, and found
something a little troubling when using JNI.

In our native code, we do various forms of memory analysis for debugging,
and somewhat unsurprisingly, this includes overriding the global 'operator
new' set of methods.
However, running with the OpenJDK6 JRE, our methods are never hit. Does the
JVM deliberately redirect these when linking, or is something else going on?

I've reproduced this in a trivial program, which elicits the same behaviour
- it's fine under Sun, but not OpenJDK..

This is demonstrable on Ubuntu 12, but we're seeing it on other linux
platforms too.
My testing has been with Sun's JDK 1.6.0.30, and OpenJDK6 (1.6.0.24 -
IcedTea6 1.11.1) (but I've confirmed the same thing happens on OpenJDK7).

I've attached the toy example (source and compiled) which demonstrates this
happening. A simple Java program which loads a native library and invokes a
method. This method tries to create a new object, using a custom global
'operator new'. In this case, the operator is totally daft, just printing a
message before aborting the program, to make it clear. Output is shown
below from the respective JVMs:

joe at okami:~/work/JNItest$ /usr/lib/jvm/java-6-sun-1.6.0.30/jre/bin/java
-Djava.library.path="/home/joe/work/JNItest" JNITest
Calling new
Calling custom operator new, should now abort
Aborted (core dumped)

joe at okami:~/work/JNItest$ /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java
-Djava.library.path="/home/joe/work/JNItest" JNITest
Calling new
Should have aborted but didn't
joe at okami:~/work/JNItest$

I'm hoping someone can tell me what I'm missing here!

Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20120614/016e4d42/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JNITest.zip
Type: application/zip
Size: 4646 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20120614/016e4d42/JNITest.zip 


More information about the distro-pkg-dev mailing list