Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacNeXT

macrumors 6502
Original poster
Jun 21, 2004
258
0
Hi

I'm writing a piece of software in which it would be convenient to catch a stack overflow error. I know a stack overflow can be considered to be a very bad thing, especially in Java, but it's a natural phenomenon in this case. If you want to know why, let me know, but I'll stick to the subject in case no one cares.

The problem is that I sometimes get a stack overflow, which is the expected behavior, but in many other cases I get:

"Executable “java” has exited due to signal 10 (SIGBUS)."

This means that the operating system shut down the JVM because it did something illegal. Obviously, this is not acceptable, you can't catch this within Java. Is this a bug in Apple's JVM port? What does "signal 10 (SIGBUS)" mean?

Has anyone seen this before? Unfortunately, I haven't got access to a Windows or Linux system right now, so I can't find out how their JVM ports react in this case.

Any insight is appreciated.
 

broken_keyboard

macrumors 65816
Apr 19, 2004
1,144
0
Secret Moon base
It seems like the JVM itself is crashing. If that's the case you can't catch the error in Java since how can your Java program exist without the JVM? (in a runtime sense)

You can increase the stack of the JVM process itself like so:
ulimit -s 16384

Or you can increase the stack of the Java program with the -Xss command line option to java I think. I had to use this once when I had a recursive function that went a bit too deep...
 

MacNeXT

macrumors 6502
Original poster
Jun 21, 2004
258
0
broken_keyboard said:
It seems like the JVM itself is crashing. If that's the case you can't catch the error in Java since how can your Java program exist without the JVM? (in a runtime sense)

You can increase the stack of the JVM process itself like so:
ulimit -s 16384

Or you can increase the stack of the Java program with the -Xss command line option to java I think. I had to use this once when I had a recursive function that went a bit too deep...

Yes, as I mentioned too, the OS exits the JVM, and ofcourse there is nothing in Java to catch when the Java Virtual Machine doesn't exist anymore. I will look into your suggestions on how to increase the stack, thanks, but I don't consider that to be a solution to the problem. The problem is: Why the hell does the JVM crash in such a horrendous way? Looks like a bug to me.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
MacNeXT said:
Yes, as I mentioned too, the OS exits the JVM, and ofcourse there is nothing in Java to catch when the Java Virtual Machine doesn't exist anymore. I will look into your suggestions on how to increase the stack, thanks, but I don't consider that to be a solution to the problem. The problem is: Why the hell does the JVM crash in such a horrendous way? Looks like a bug to me.

Depends on your code. Anyone can write code to crash a JVM with stack overflows. Have you tried profiling and debugging using Eclipse or something similar? Are you using any recursion or have an absurd amount of method nesting? Are you using JNI to call other non-java libraries?

Another way to increase the JVM stack (can't say I have used broken's method) is to use the -Xss flag on your java command.

For example: -Xss10m or -Xss512k
 

MacNeXT

macrumors 6502
Original poster
Jun 21, 2004
258
0
kingjr3 said:
Depends on your code. Anyone can write code to crash a JVM with stack overflows. Have you tried profiling and debugging using Eclipse or something similar? Are you using any recursion or have an absurd amount of method nesting? Are you using JNI to call other non-java libraries?

Another way to increase the JVM stack (can't say I have used broken's method) is to use the -Xss flag on your java command.

For example: -Xss10m or -Xss512k

It's not direct recursion. It's more like A calls B calls C calls A calls B ... (oversimplified). It's also a mixture of static methods and instance methods. But what do you mean with "crash a JVM with stack overflows"? I can't find evidence that a stack overflow is something that cannot be caught in some cases, it should be possible to handle this. It should not crash the JVM. Unlike for example an Out of Memory error, which cannot be caught.

It still looks like a bug to me.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
MacNeXT said:
But what do you mean with "crash a JVM with stack overflows"?

Sounds more like a code issue to me. You are so quick to blame the JVM. Have you tried Profiling your application?

See http://www.geocities.com/herong_yang/jvm/stack.html

ALthough JVMs have improved since 2002, I would venture to guess these simple programs are still effective at crashing a JVM.

Aside - Worth a shot, but wrap your code with a try/catch and instead of catching Exception, catch Throwable.
 

FritzTheWonderM

macrumors member
Dec 12, 2003
93
0
Planet 10
kingjr3 said:
Aside - Worth a shot, but wrap your code with a try/catch and instead of catching Exception, catch Throwable.

Good point. Also, try running the same code on different JVMs if possible. If it doesn't explode on the Windows or Linux 1.4.2_xx JVM or maybe a 1.3 JVM it's probably Apple's problem.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.