The only things that are stored on the stack are primitive types and references. Objects are always created on the heap, so the types of data that will be stored on the stack
- Local variables of type byte, char, int, long, float, double, the longest of which is double, which is 8 bytes.
- References to objects: 4 bytes on 32 bits vm, 8 bytes on 64 bits vms (possibly shorter, 48-bit links are used to save space).
Note that arrays are types of objects, so they are stored on the heap, also if you have a primitive that is a field in the class, then the primitive is part of the object and therefore will be stored on the heap.
So it's pretty hard to break out of the stack space for a thread if you don't have runway recursion. I would suggest that this is why Java developers do not give you a way to find out the size of the stack.
Another reason for not specifying the stack size is that it will be implementation information with which you cannot do anything, you cannot change the size of the stack of threads after creating the thread, and you can't do pointer arithmetic to determine the stack size?
source share