I am asking a question about "java stack overflow" in the "stackoverflow" site :)
A particular thread which makes some recursive function calls for a particular input runs fine in Oracle Java 7 (64 bit) for a configured stack size of 228k (-Xss228k).
However, the same thread running the same recursive code for the same input throws a java.lang.StackOverflowError in Oracle Java 8 (64 bit) for the same stack size of 228k. It runs fine in Java 8 if the stack size is increased to 512k (-Xss512k).
Any idea why this could happen? Have any changes been made in Java 8 (Hotspot JVM) compared to Java 7 which could increase the stack memory consumption for recursive function calls? I can provide additional details if required.
(Edit) NOTE: The same recursion depth works "always" in Java 7 but fails "always" in Java 8 for a stack size of 228k.
I wrote a small test for different recursion scenarios (static or instance method, different number of int parameters). Here's the results (number of calls before
StackOverflowError
occurs) on different versions of HotSpot JVM 64bit with-Xss228k
option. Note that numbers differ somewhat between runs (I launched twice with every JVM):It's quite expected that
Instance/0
is the same asStatic/1
and so on as instance call need to passthis
as an additional argument.So indeed there's some degradation of number of recursive calls allowed (except for
Static/0
case) betwee JDK 7 and JDK 8: you lose around 30-40 calls (roughly 5%) of total count. So probably in your application you was very close to the limit. By the way I noticed a sudden jump between-Xss256k
and-Xss260k
(tested on 1.8.0_40):So you may try to increase stack size to
-Xss260k
and it should be enough for your task.By the way 32-bit JVM allows much more calls with the same
-Xss228k
:Thus it's also possible that you've switched from 32-bit Java-7 to 64-bit Java-8. In this case, of course much more stack space is needed as even with compressed OOPs pointers in the stack seem to be 64bit, thus occupying more space.