views:

64

answers:

1

Hello, everyone!

Everywhere I keep reading about increasing the JVM stack size (i.e. to allow deeper recursions).

But I'm asking myself, would decreasing of the stack size speed up method invocation?

Probably my understanding is wrong, but I assume, that the allocation speed of each stack (not only for recursive method calls) depends on it's size.

Could someone point me to benchmarks, or at least to background information on this topic?

Thank you!

+1  A: 

Each platform's virtual machine implementation of Java will be different, but in general, this is not going to be a factor that has a significant impact. Allocating memory is an extremely common operation and is likely to be highly optimized.

For example, it would be easy to have an implementation which uses a list of (pointer, size) tuples to indicate stack space. Now you only have to say the size of the stack you would like and the pointer that points to the beginning of the reserved space, no matter how much space you want.

John Feminella
So, if it's not a big performance matter, why is the maximal stack size such limited (by default), that sometimes method invocation "fail" even after few thousands recursions?
java.is.for.desktop
There are a number of possibilities for why that might happen. For instance, every thread in the JVM gets its own stack. Your stack size limits the number of threads that you can have; if it's too big, you'll run out of memory, and you won't be able to allocate a new thread.
John Feminella
@java.is.for.desktop: maximal stack size must be limited so that your machine doesn't run out of memory quickly. Speed is not the issue. Overall memory consumption is the reason for the limit.
S.Lott