Link to home
Start Free TrialLog in
Avatar of oracle1998
oracle1998

asked on

SIGSEGV terminates my JVM

I've a java app and the SIGSEGV (segmentation fault) happens randomly to kill my JVM. I need to debug this. Here's a quick question. What would cause Java to get that kind of signal?

I'm using JRE1.3.1 with a native library to local c programs in solaris 8.

many thanks to those who answer.

kyle
Avatar of aozarov
aozarov

I can think of either
Invalid memory access (segmentation error)
or out of memory.

The program will be aborted if it received SIGSEGV signal or u ll get Invalid memory access Error at worst.

Will not out of memory error. It will come if ur JVM not able to get Memory for it's process


Avatar of oracle1998

ASKER

My thought was that I got an invalid memory access on the program. The question is how do I get this kind of error with Java? Some examples would be nice.


thanks,
kyle



You are using JNI aren't you?
yup, JNI.
SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mayank S
Can we have some of your native code?
> Can we have some of your native code?

The native code is pretty simple, most of the native functions call a function in c and return a result. It's not a good idea to post the code since it's confidential (it's for work). I've a good sense of direction now and I'll try if I can resolveit from here. If not, I can probably modify some of the code and post it here.

cheers,
kyle
Make sure you have handled pointers correctly and that you are not having ny dangling pointers anywhere. A lot of times segmentation faults occur because of that.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not that good with C programming. Is this what you called passing local variable to another function? I was told that as long as it's referenced, it does not get deallocated.

int configport(void)
{
    return(getport("456789", 12345));
}

static int getport( char *var, int defaultval )
{
    if (var == 0 )
        return defaultval ;
    else
        return atoi(var) ;
}

cheers,
kyle
discard my last comment.. hah.. I realize that it's only bad to return a local variable.
> So you I think you should look for your answer in the native code and not the Java part.

I'm just wondering the scope of c program I need to verify. Here's what happens

JVM <---> libJavaToC.so <---> C program

I'm wondering if I only have to verify the code for libJavaToC.so or I need to verify the functions (in c program) called by the libJavaToC.so as well?  Would a segmentation fault generated in C program area cause the JVM to die?

many thanks,
kyle
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks to all who replied. I've come up with a test plan to find the bug. That is, to strip out the JNI section and see if it still kills the JVM.

kyle