1

I'm working with a vendor who has provided me a Java application which I'm trying to get up and running on a Linux OS (CentOS 7). The vendor builds, runs and tests the application on Windows.

The application starts up just fine on my Linux system. But from time to time, I'm seeing a stack overflow come up. The vendor swears that this never happens on Windows.

Note that I am in no way a Java expert, so apologize if this is an incoherent rambling, but after a little research, I decided to try increasing the JVM stack size to 8MB from the default size using a -Xss8m parameter. With that, the application starts up just fine, but sure enough I encounter another stack overflow.

The vendor's comment on this never happening on Windows makes me wonder (while also making a lot of assumptions) if Linux is somehow implementing a limit that would now allow the JVM to create a 8MB stack.

However, after running ulimit -s as the user executing the process, I find the default Linux stack limit is 8MB! As an experiment, I've set the stack limit value to unlimited. Waiting to see what happens.

This leaves me with a few things to ponder, which maybe someone on here can help me understand.

  • Is there something else I could possibly be missing in the environment that can cause the Java application to use up all its stack?
    • If not, I'll need to go back to the vendor and get a better understanding of their code, looking for deep recursion where the stack overflow seems to happen most.

Some additional details about my environment:

  • Linux 3.10.0-1160.15.2.el7.x86_64 (CentOS 7)
  • OpenJDK 11
  • Other Java options related to memory utilization being passed while experimenting:
    • Xms1g
    • Xmx1g
    • Xss8m
    • XX:VMThreadStackSize=8192
    • XX:PermSize=128m
    • XX:MetaspaceSize=1g
    • XX:MaxMetaspaceSize=1g
    • XX:CompressedClassSpaceSize=256m
    • XX:ReservedCodeCacheSize=64m
    • XX:+UseG1GC
    • XX:+UseStringDeduplication
    • XX:MaxGCPauseMillis=200
    • XX:+UseCompressedOops
azurepancake
  • 751
  • 1
  • 9
  • 15
  • Related, possibly duplicate: [How to increase the Java stack size?](https://stackoverflow.com/questions/3700459/how-to-increase-the-java-stack-size) – Mark Rotteveel May 07 '21 at 16:00
  • According to [this website,](https://www.baeldung.com/jvm-configure-stack-sizes) the default stack size on Linux is 1MB. 8K (your configured stack size) seems very small. Try increasing the stack size to the default or just leave the option off, see if that helps. – markspace May 07 '21 at 16:00
  • **Usually** a StackOverflowError happens due to unbounded recursion. "Limited" overflows are possible (in recursive handling of deeply nested structures, usually), but they are definitely the exception. **If** this is caused by some unbounded recursion, then no amount of increasing the stack size will help. It's quite possible that *some* difference between Linux and Windows causes such an unbounded recursion if the vendor never tested on Linux. – Joachim Sauer May 07 '21 at 16:01
  • Joachim makes a good point. Linux and Windows are not the same, it's possible that data input ("garbage in, garbage out") or untested code paths are causing an unbounded recursion. Increasing the stack size will provide a quick check. If it still overflows, then it's likely you have a bug and a code path that's not being tested on Linux. – markspace May 07 '21 at 16:04
  • @markspace The question says “8MB”, not 8K. – Basil Bourque May 07 '21 at 16:40
  • if `XX:VMThreadStackSize=8192`, the configuration the OP says they're using, really means 8MB, then I think they've hit a bug / bad input, this isn't something that twiddling around with JVM parameters will fix. – markspace May 07 '21 at 16:55

0 Answers0