• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 936
  • Last Modified:

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
0
oracle1998
Asked:
oracle1998
  • 7
  • 4
  • 3
  • +1
3 Solutions
 
aozarovCommented:
I can think of either
Invalid memory access (segmentation error)
or out of memory.
0
 
neonlinesProject managerCommented:

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


0
 
oracle1998Author Commented:
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



0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
aozarovCommented:
You are using JNI aren't you?
0
 
oracle1998Author Commented:
yup, JNI.
0
 
aozarovCommented:
So you I think you should look for your answer in the native code and not the Java part.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Can we have some of your native code?
0
 
oracle1998Author Commented:
> 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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Segmentation fault generally occus when you try to reference a memory location which is now free or deallocated. For example, if you are returning a pointer from a function, and let's say that the pointer pointed to a local variable of the function, then after the function execution finishes, the memory allocated for all its local variables is freed and the address returned is now free, not allocated. So effectively, the pointer in the callling function which held the address returned by this called function, is now pointing to garbage.

Typically, this problem can also arise in C++ when if you are passing objects (which contain pointer data-members) by value to a function - in case the destructor destroys the allocated memory which was pointed to by the pointer - that is why passing by references is preferred in that situation (which is probably why the concept of references was introduced in C++). The destructor would be called when the function finishes execution for the local parameter that it had and it would go ahead and de-allocate the memory pointed to by the actual argument object which was passed to it from the calling function.

Since you have not provided your entire code, it is not possible to point out where it is occuring, but can go through your code and see if this helps you to solve your problem.
0
 
oracle1998Author Commented:
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
0
 
oracle1998Author Commented:
discard my last comment.. hah.. I realize that it's only bad to return a local variable.
0
 
oracle1998Author Commented:
> 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
0
 
aozarovCommented:
>>   Would a segmentation fault generated in C program area cause the JVM to die?
Yes as they are running in the same process.

>> JVM <---> libJavaToC.so <---> C program
what is libJavaToC isn't that your C program library?
Regardless, any native code that is being invoked from Java via JNI should be inspected though that can
be done in order of its likelyhood.
0
 
oracle1998Author Commented:
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
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now