5

If I run java from the command line on my windows box like this:

"C:\Program Files (x86)\Java\jdk1.7.0_51\bin\java.exe" -XshowSettings:all -Xss=1m -Xmx256m

I see this output:

VM settings:
Stack Size: 1.00M
Max. Heap Size: 256.00M
Ergonomics Machine Class: client
Using VM: Java HotSpot(TM) Client VM

The important part for me is "Stack Size: 1.00M", which is what I set it to be via the command line option "-Xss1m". But if I remove this option and let the VM run with the default stack size I get this output:

VM settings:
Max. Heap Size: 256.00M
Ergonomics Machine Class: client
Using VM: Java HotSpot(TM) Client VM

Notice it no longer displays the "Stack Size" anymore. I was hoping I would see the default size if I didn't specify a custom "-Xss" value. Is there any way to determine the default thread stack size?

BenjaminLinus
  • 2,100
  • 23
  • 24
  • try `-XX:+PrintFinalFlags` – Peter Lawrey May 08 '14 at 20:55
  • 1
    @Peter Lawrey the -XX:+PrintFinalFlags is a "Unrecognized VM option" for my java vm. Thanks for the suggestion though. – BenjaminLinus May 08 '14 at 21:02
  • Oops you need another option to use it. http://stackoverflow.com/questions/10486375/print-all-jvm-flags – Peter Lawrey May 08 '14 at 21:03
  • 2
    Ahh, now that shows me a ton of stuff. When I toggle between setting "-Xss1m" on the command line the only value that changes in the output from "-XX:+PrintFlagsFinal" is "ThreadStackSize" which shows 1024 if I set "-Xss1m" and shows "0" if I leave "-Xss1m" out. I am guessing that 0 isn't the true default for thread stack size or I imagine nothing would ever run. – BenjaminLinus May 08 '14 at 21:20

1 Answers1

3

The default stack size of Windows application is specified in .exe file header.
You can find it out using Cygwin objdump tool or with Microsoft Visual Studio dumpbin utility:

C:\Program Files\Java\jdk1.7.0_51\bin> objdump -p java.exe | grep Stack
SizeOfStackReserve      0000000000100000
SizeOfStackCommit       0000000000001000

C:\Program Files\Java\jdk1.7.0_51\bin> dumpbin.exe /headers java.exe | grep stack
      100000 size of stack reserve
        1000 size of stack commit

As we can see, Java 7 x64 default stack size in 0x100000 (1 MB).
For x86 version, the default stack size is 0x50000 (320 KB):

C:\Program Files (x86)\Java\jre7\bin>objdump -p java.exe | grep Stack
SizeOfStackReserve      00050000
SizeOfStackCommit       00001000
apangin
  • 92,924
  • 10
  • 193
  • 247
  • 3
    Just to clarify: HotSpot JVM uses native OS stack as Java stack. If `-Xss` is not given, the default Java thread stack size is equal to OS stack size on Windows. – apangin May 08 '14 at 23:38
  • I was able to use "objdump" the way you suggested and it worked great. Thank you for your clear and concise answer. – BenjaminLinus May 09 '14 at 19:30