How much can the stack grow?
You can use the VM option called ss to configure the maximum stack size. The VM option is usually passed using -X {option}. So you can use java -Xss 1M to set the maximum stack size to 1M.
Each thread has at least one stack. Some Java Virtual Machines (JVMs) put the Java stack (calls to Java methods) and its own stack (calls to the Native method in the virtual machine) on the same stack and unwind the stack using the Managed to Native Frame, known as M2NFrame. Some JVMs save two stacks separately. Xss in most cases sets the size of the Java stack.
For many JVMs, they set different defaults for the stack size on different platforms.
Can we limit this growth?
When a method is called on the stack of this thread, a new stack stack will be created. The stack will contain local variables, parameters, return address, etc. In java, you can never push an object onto the stack, only a reference to the object can be stored on the stack. Since an array is also an object in java, arrays are also not stored on the stack. So, if you reduce the number of local primitive variables, parameters, grouping them into objects, you can reduce the space on the stack. In fact, the fact that we cannot push objects onto the java stack affects performance for a while (misses in the cache).
Does the stack value have a minimum default value or a maximum default value?
As I said, different virtual machines are different from each other and can change versions. See here .
How does garbage collection on the stack work?
Java garbage collections are a hot topic. Garbage collection aims to collect an unreachable object on the heap. So you need a definition of the achievable. Everything on the stack is part of the root links in the GC. Everything that is accessible from each pile of each thread should be considered as living. There are also some other root links, such as Thread objects and some class objects.
This is just a very vague use of the stack on the GC. Most JVMs currently use the GC generation. This article provides a brief description of the Java GC. And recently, I read a very good article about GC on .net. The GC on oracle jvm is pretty similar, so I think this can also help you.