Where can I find default -Xss (stack size) value for Oracle JVM?
Asked Answered
S

6

80

Has anyone ever found a single JVM document listing default -Xss values for various versions of the Oracle JVM, and for different OS's?

I've been able to find this table in the jrockit docs, but that's not helpful for those using the "normal" Oracle JVM.

I do appreciate that the -Xss value will vary per OS (and JVM version), so maybe there's no one document that lists all recent combinations. But if any readers here know of any individual documents that list at least just the default -Xss value for each JVM version (or at least 1.6 and 1.5), or even if only for some OS's, that would be a great start. I'm especially interested in the default for Windows.

I'll add that the reason this is valuable is that often we see people recommend (wrongly, I think) that someone can solve a problem by changing the -Xss value. But if you don't know your default, then there's no way to know if you're raising or lowering the value by whatever change someone recommends. They don't generally indicate the version/OS they're on, so it's a crapshoot whether their suggestion will "help" you.

Even better than some documentation, if anyone knows a way to query the JVM to get the current value, whether from the command line or via an API call, that would be even more valuable. Thanks.

Update: I have added an answer of my own that summarizes the various suggestions and points to a current resource (in early 2021) indicating the answer, including what I learned about the -Xss value in Windows.

Sedentary answered 16/5, 2011 at 16:46 Comment(2)
Have you read this oracle.com/technetwork/java/hotspotfaq-138619.html#threads_oomPocosin
Thanks, Sean, but you do realize that applies only to 1.4. Note I had asked for any references for 1.5 or 1.6. Those are proving harder to find. Sorry, I should have indicated that I was aware of that 1.4 technote, just like I referenced the jrockit 1.5 note.Sedentary
S
16

What a long, strange trip it's been getting to an answer to this question, first posted in 2011--and getting all kinds of answers in the years since. Some proposed using the -XX:+PrintFlagsFinal JVM argument, which may be best for most, but it did not help for Windows (always reports 0). And some folks shared various resources (for various JVMs and versions), some of which did try to help answer this question but often did not, or did not clarify for those who may be running an Oracle JVM on Windows.

Here's at least a bit more clarity: with Java 11 being (in 2021) the current latest LTS (long-term support release) version of the Oracle JVM, I've found a document for that current version which DOES list the specific defaults for XSS (aka ThreadStackSize), and for different OS's. It's at https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE. Here's what it reports (in case that link breaks in the future):

  • Linux/x64 (64-bit): 1024 KB
  • macOS (64-bit): 1024 KB
  • Oracle Solaris/x64 (64-bit): 1024 KB
  • Windows: The default value depends on virtual memory

Sadly, Windows folks are still left to wonder: what could that mean, "depends on virtual memory"? I suppose it means the virtual memory of Windows itself of course, but even then how do we translate that into what we should expect the actual stack size for a jvm thread to be?

And back to my original question: I'd wanted to know what the default was, because so often someone might suggest the solution to some problem is to change that -XSS jvm arg (to some value they would propose). But how can we know if we are making it larger or smaller than the default? Depending on the problem being solved, that can be vital to know!

After 10 years, I guess it's a mythical quest that may not be concluded. But who knows, maybe someone seeing this now or in the future may ride to the rescue with new info. Or perhaps Java 17 (the expected next LTS version) may change things. (To be clear, there is no version of that page I shared, for Java 13 or above, as I write.)

If nothing else, I leave this for posterity, to at least help someone else facing this question to know that they're not crazy in finding it so hard to get a straight answer (especially about the default XSS value for Windows, and whether changing it would be raising or lowering the size relative to the default).

Sedentary answered 5/3, 2021 at 18:16 Comment(2)
Someone pointed me to another SO thread where someone asserts (from analysis of the JDK source code for JAva 8) that they found the default is 1m (1024k) in 64-bit Windows. For more, see: #45140613. I'll report if I ever do more testing to confirm or deny that assertion (despite the code), or I'd love to hear if anyone else may. But it's a better answer than Oracle's "it depends", above. :-)Sedentary
Note that the documentation you quote seems to have been moved to the tool guide for the java tool, under the -Xss description (at least for Java 21--an LTS release). For x64 macOS/Linux the default is still 1024 KB. There's now additional documentation for AArch64 macOS/Linux with the default at 2048 KB. There's no listing for Solaris specifically. And, unfortunately, for Windows it still says "The default value depends on virtual memory".Nearsighted
M
103

try:

java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
Mcroberts answered 5/12, 2014 at 20:59 Comment(5)
that seemed promising (and for Windows user, you'd use find "ThreadStackSize" instead), but it simply reports 0 as the value for ThreadStackSize. I don't expect that means that the size is 0. And while some may say that this would indicate it's using "the default", then that simply leads us back to my very question: what the heck is the default XSS value in a given JVM? I can't believe this still can't be answered in 3.5 years. Still open to any takers, and thanks everyone else for trying so far.Sedentary
Thanks! This is what I got for 64bit linux: java -XX:+PrintFlagsFinal -version | grep ThreadStackSize intx CompilerThreadStackSize = 0 {pd product} intx ThreadStackSize = 1024 {pd product} intx VMThreadStackSize = 1024 {pd product} java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07)Harriettharrietta
@Rohit, size is stored in kbytes : bugs.openjdk.java.net/browse/JDK-8145458Ledezma
Almost five years late to the party... Using java -XX:+PrintFlagsFinal -version shows that ThreadStackSize should be 1024k, but in reality it seems to be 64Mb, as shown by /proc/<pid>/maps. And yes, changing -Xss to for example, 4Mb (java -Xss4m) and comparing /proc/<pid>/maps confirms that "something", which I assume to be thread stack allocations, decreased from 64Mb to 4Mb. I used this small tool to show the memory segment sizes, gist.github.com/cosimo/e90a9f6daa1fbdc62a89843cf27f005a Lastly, to show the JVM flags of a running process, use jcmd <pid> VM.flags instead.Salami
Cosimo, are you referring to on Windows, when no XSS is specified? I find that that jcmd reports 0, at least for its reported VMThreadStackSize, ThreadStackSize, and CompilerThreadStackSize, assuming that the XSS would directly relate to any of those. This is similar to how I reported previously that printflagsfinal also reports 0 in this case. So sadly, no, these are not a way to know what the "current" XSS is on Windows, if it's not set.Sedentary
M
25

This information now appears in the Oracle Hotspot FAQ http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#threads_oom

You may be running into a problem with the default stack size for threads. In Java SE 6, the default on Sparc is 512k in the 32-bit VM, and 1024k in the 64-bit VM. On x86 Solaris/Linux it is 320k in the 32-bit VM and 1024k in the 64-bit VM.

On Windows, the default thread stack size is read from the binary (java.exe). As of Java SE 6, this value is 320k in the 32-bit VM and 1024k in the 64-bit VM.

You can reduce your stack size by running with the -Xss option. For example:

java -server -Xss64k

Note that on some versions of Windows, the OS may round up thread stack sizes using very coarse granularity. If the requested size is less than the default size by 1K or more, the stack size is rounded up to the default; otherwise, the stack size is rounded up to a multiple of 1 MB.

64k is the least amount of stack space allowed per thread.

Milagro answered 11/12, 2013 at 9:38 Comment(2)
Thanks, Ben. That's the most direct potential answer yet, but there is a slight issue: that technote seems to refer to Java older versions ("1.4" and "SE 5.0" and "SE 6"). It may well be that the info is no longer accurate for Java 7 or 8. Folks interested in the particulars should take note of that. But for now it would seem to confirm that in Windows, the only real way to know is indeed to look at the source. Goodness. (That was at least nice of them to say what it was for 32/64bit Windows at least as of Java 6!)Sedentary
Still looking for any way to get the jvm to report the current stack size. Can't believe that's so hard to obtain, especially given all the above about even just finding the default. Some may propose jmx, but I've searched the Java API docs, to no avail. And some may propose using something like 'java -XX:+PrintFlagsFinal | find "Stack"', but that only reports what, if any, value was specified on the XX args when the JVM was started. It does NOT report the value of something left to be its default.Sedentary
S
16

What a long, strange trip it's been getting to an answer to this question, first posted in 2011--and getting all kinds of answers in the years since. Some proposed using the -XX:+PrintFlagsFinal JVM argument, which may be best for most, but it did not help for Windows (always reports 0). And some folks shared various resources (for various JVMs and versions), some of which did try to help answer this question but often did not, or did not clarify for those who may be running an Oracle JVM on Windows.

Here's at least a bit more clarity: with Java 11 being (in 2021) the current latest LTS (long-term support release) version of the Oracle JVM, I've found a document for that current version which DOES list the specific defaults for XSS (aka ThreadStackSize), and for different OS's. It's at https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE. Here's what it reports (in case that link breaks in the future):

  • Linux/x64 (64-bit): 1024 KB
  • macOS (64-bit): 1024 KB
  • Oracle Solaris/x64 (64-bit): 1024 KB
  • Windows: The default value depends on virtual memory

Sadly, Windows folks are still left to wonder: what could that mean, "depends on virtual memory"? I suppose it means the virtual memory of Windows itself of course, but even then how do we translate that into what we should expect the actual stack size for a jvm thread to be?

And back to my original question: I'd wanted to know what the default was, because so often someone might suggest the solution to some problem is to change that -XSS jvm arg (to some value they would propose). But how can we know if we are making it larger or smaller than the default? Depending on the problem being solved, that can be vital to know!

After 10 years, I guess it's a mythical quest that may not be concluded. But who knows, maybe someone seeing this now or in the future may ride to the rescue with new info. Or perhaps Java 17 (the expected next LTS version) may change things. (To be clear, there is no version of that page I shared, for Java 13 or above, as I write.)

If nothing else, I leave this for posterity, to at least help someone else facing this question to know that they're not crazy in finding it so hard to get a straight answer (especially about the default XSS value for Windows, and whether changing it would be raising or lowering the size relative to the default).

Sedentary answered 5/3, 2021 at 18:16 Comment(2)
Someone pointed me to another SO thread where someone asserts (from analysis of the JDK source code for JAva 8) that they found the default is 1m (1024k) in 64-bit Windows. For more, see: #45140613. I'll report if I ever do more testing to confirm or deny that assertion (despite the code), or I'd love to hear if anyone else may. But it's a better answer than Oracle's "it depends", above. :-)Sedentary
Note that the documentation you quote seems to have been moved to the tool guide for the java tool, under the -Xss description (at least for Java 21--an LTS release). For x64 macOS/Linux the default is still 1024 KB. There's now additional documentation for AArch64 macOS/Linux with the default at 2048 KB. There's no listing for Solaris specifically. And, unfortunately, for Windows it still says "The default value depends on virtual memory".Nearsighted
N
6

You can find it at Oracle site under "-XX:ThreadStackSize" option which means the same as -Xss.

Nonstriated answered 18/6, 2013 at 11:29 Comment(5)
thanks for that. I do find others asserting and demonstrating that xss and threadstacksize seem to be the same thing, just different names from different era's in the evolution of the jvm.Sedentary
But as for that page's reference to defaults, it's rather obtuse in this case. Yes, it lists -XX:ThreadStackSize=512 in the left column, whose header says the column shows "option and default value", but then the right column says "Thread Stack Size (in Kbytes). (0 means use default stack size) [Sparc: 512; Solaris x86: 320 (was 256 prior in 5.0 and earlier); Sparc 64 bit: 1024; Linux amd64: 1024 (was 0 in 5.0 and earlier); all others 0.]" I'm interested in Windows primarily, and but don't know what "all others 0" means, when the first sentence says "0 means use default stack size". :-(Sedentary
According to the left column and its title 512 is the default. So 512 is for Windows.Nonstriated
Keypress, no, that was not so. the 512 is indeed listed in the left col of that page as the "default", but nothing about that page said it was showing defaults for Windows. So that box for threadstacksize was indeed showing things OTHER than Windows. And indeed Windows would be in its classification of "all others", showing "0", which as discussed elsewhere here means "whatever is the OS default", which again tells us nothing.Sedentary
FWIW, that page (that keypress shared) does indeed have a link at the top for a document about Java 8 for Windows (docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html), and THAT page at least said this about xss: " The default value depends on virtual memory." Again, that's not helpful, but it was at least an attempt. It does fly counter to other discussions here (other answers and comments) where some noted that the Java source would indicate the default size. I'll offer a new answer that points to a Java 11 resource that goes a bit farther (just a bit).Sedentary
L
3

For hotspot it depends on your architecture and what not.

The default stack size can be found in the source code in the header files that relate to a given platform e.g.

google code search (edit: this service has been deactivated since this answer was made, sadly) UPDATE: here's a new link from Nebelmann: Openjdk source: globals_windows_x86.hpp

Not sure if this helps but its a start

Locomotive answered 25/5, 2011 at 19:30 Comment(2)
For OpenJDK 7, here's the file: hg.openjdk.java.net/jdk7/jdk7/hotspot/file/473cce303f13/src/…Manysided
Interesting, Greg and Inger. I guess some may want to explore their java source to find it, but since many deploy the JDK or JRE without source, that won't help them (unless they get it again, or find resources like you shared, and hope they find the source there for their specific environment.) And yep, Greg, I had acknowledged from the outset that this would indeed be environment-specific. Still, thanks to both of you for things to consider.Sedentary
L
2

There are default settings available from IBM Java 6 user guide (source):

Xss <size> for Java Threads 32 bits:

AIX®: 256KB
IBM®I: 256KB
Linux: 256KB
Windows: 256KB
z/OS®: 256KB
Loricate answered 29/8, 2012 at 14:7 Comment(1)
Thanks, chepseskaf, but again I was asking (in the title and the body) about the Oracle/Sun JVM. Your resource is in fact from the IBM JVM, which is not the same. So while the information is interesting, we can't conclude that it applies as well to the Oracle/Sun JVM.Sedentary

© 2022 - 2024 — McMap. All rights reserved.