The idea would be to help determine the optimum stack size for a given Java application.
One thing that could be done with this information create a range-table of stack sizes which the threads could modify as they exit and which could be dumped periodically and at application exit.
EDIT: This is in the context of running on customer machines with real workloads which I can't get profiler access to.
EDIT2: In response to one answer, at (IIRC) 256Kb per thread, I have wondered for a while now how close that is to the reality of what's needed (I also wonder if this question might be not very relevant because perhaps stack space is allocated on demand). We have an application server which is based on message passing and highly threaded and runs on everything from an ARM handheld to octo-core Linux, to midrange and mainframes - it would be good to have a feeling for where (and if) we can trade stack space for heap on systems with many message handlers.
There are some similar questions which are of interest, but they are native/os-specific:
If we don't specify a size for the stacks, the JVM will create one with a default size. Usually, this default size depends on the operating system and computer architecture. For instance, these are some of the default sizes as of Java 14: Linux/x86 (64-bit): 1 MB.
You may need to increase the stack size if your program gets stack-overflow messages at runtime. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations).
Sets the maximum stack size for Java™ threads. The default is 320 KB for 31-bit or 32-bit JVMs and 1024 KB for 64-bit JVMs. The maximum value varies according to platform and specific machine configuration.
Within Java, the Java threads are represented by thread objects. Each thread also has a stack, used for storing runtime data. The thread stack has a specific size. If a thread tries to store more items on the stack than the stack size allows, the thread will throw a stack overflow error.
Stack memory will be hard to obtain.
Best you can do, and quite easily, is JVM memory usage via MemoryMXBean
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With