2 years ago
#62832
Marco Servetto
Java 17 stack size and actual memory consumption
Is there any real downside to allow for a VERY large stack on the JVM, like gigabytes?
In particular, with many threads, is this going to give troubles? if the stack space is not actually used, is there going to be more wasted memory in practice on the most used JVMs running on win/linux/mac?
For example, if I allocate 1GB for the stack, and I run 100 threads, but they do not actually fill up the stack space with actual data, would running the program require 100GB of actual physical memory?
This question is strongly connected with this old one (Dynamically expandable JVM stack) that was asked 10 years ago when the Java environment was quite different.
Now near every Java program runs over a 64 bits architecture, and so much in JVM has overall improved.
Expansion: I'm often running very complex recursive programs on large/deep data structures, and having to use free monads or other program transformations to use the heap instead of the stack is complex, slow and possibly pointless. An alternative would be using Java looms fibers, but.. again, may be just allocating a duper stack is easier and faster. I see why this is not done in C/C++, but under a VM this should be reasonable. Is it?
java
jvm
java-17
0 Answers
Your Answer