JNI problem on Solaris 9

T

Tian

I have a native library and a java app that uses JNI to access the
native library, my java app works fine on Solaris 8 and earlier SUN
solaris releases, however on Solaris 9 it failed (native app also
works fine). The reason is one function call in native code , say A(),
calls B() , to create a client socket, and B() return a wraper struct
pointer of that socket, but in A(), this pointer is always NULL.

If anyone has the similar problem before and knows the solution,
please help me out here.

thanks in Advance.

(e-mail address removed)
 
R

Roedy Green

The reason is one function call in native code , say A(),
calls B() , to create a client socket, and B() return a wraper struct
pointer of that socket, but in A(), this pointer is always NULL.

What you have to do is sort out if this is a JNI problem or a C++
problem. Try to extract the troublesome logic into a standalone
program and debug it the traditional way.
 
R

rkm

If I understand you right, A() is a function implemented in
the native library. But where is B(), on the Java side or
is it in the native library too? If not on the Java side,
then I agree with Roedy, build a standalone non-Java app and
debug it from there.

Rick
 
T

Tian

rkm said:
If I understand you right, A() is a function implemented in
the native library. But where is B(), on the Java side or
is it in the native library too? If not on the Java side,
then I agree with Roedy, build a standalone non-Java app and
debug it from there.

Rick

Sorry I didn't make it clear, both A() and B() are in native code, and
there are dozens of functions called between jni and A().

to be more specific, what I wrote is a RPC client program , there are
other threads doing other things at the same time. The failure is
around socket connect ( at or soon after that). B() is the function
that creates the socket and connect it to the server.

I 've already tested by writing c++ program and it works fine without
any troubles(for more than half a year). the trouble only exists when
I use JNI.

thanks

Geng
 
G

Gordon Beaton

Sorry I didn't make it clear, both A() and B() are in native code,
and there are dozens of functions called between jni and A().

to be more specific, what I wrote is a RPC client program , there
are other threads doing other things at the same time. The failure
is around socket connect ( at or soon after that). B() is the
function that creates the socket and connect it to the server.

I 've already tested by writing c++ program and it works fine
without any troubles(for more than half a year). the trouble only
exists when I use JNI.

If B has returned a value but A sees NULL, that would indicate that
you have trashed the stack somewhere in your code. Check all use of
malloc, free, pointers, arrays, data sizes etc. You have likely
overwritten the bounds of something. Use a memory debugging tool like
Purify to find the cause.

/gordon
 
S

Sean Burke

Gordon Beaton said:
If B has returned a value but A sees NULL, that would indicate that
you have trashed the stack somewhere in your code. Check all use of
malloc, free, pointers, arrays, data sizes etc. You have likely
overwritten the bounds of something. Use a memory debugging tool like
Purify to find the cause.

Possibly you are getting stack overflows in the JNI code.
Your C++ threads will (by default) have stack regions of 1MB,
but java threads provide only 128K for C stack. You could try
allocating larger C stacks using the java -ss option.

-SEan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top