java - Stack size verification and StackOverflowError -


in java, each thread have stack memory allocated defined -xss parameter , there default value.

now, overridden default stack size running below code java -xss1k test.

last output:

18479 18480exception in thread "main" java.lang.stackoverflowerror 

questions:

  • why values till 18479 printed? expecting far less values because mentioned stack size of 1kb , storing int on each stack frame.
  • with 1kb or 1024 bytes of stack size, 256 (1024/4) int values storable. no? because each recursive call 1 stack frame added , int stored on it. so, 256 stack frames size of 4 bytes each added there should have been stackoverflowerror.
  • my understanding global scoped counter not contribute in way stack consumption because live in old gen space. confirm?


 public class test {     private static int counter = 0;     public static void main(string[] args) {         getmestackoverflowexception();     }      private static void getmestackoverflowexception(){         int x = 123;         system.out.println(test.counter++);         getmestackoverflowexception();     } } 

with 1kb or 1024 bytes of stack size, 256 (1024/4) int values storable. no?

no. return address stored on stack, should overflow in fewer 256 recursive calls.

my understanding global scoped x not contribute in way stack consumption because live in old gen space. confirm?

confirmed.

for windows:

note on versions of windows, os may round thread stack sizes using coarse granularity. if requested size less default size 1k or more, stack size rounded default; otherwise, stack size rounded multiple of 1 mb

source.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -