This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Stack Memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Stack Memory" Watch "Stack Memory" New topic
Author

Stack Memory

Mohtashim Shaikh
Ranch Hand

Joined: Jul 18, 2010
Posts: 43
I need to know what is the stack size i.e. -Xss my java program is running with.
Is there a way to find that out from inside the java program code and outside of it.

Regards,
Mohtashim
KayCee Clark
Greenhorn

Joined: Jun 22, 2011
Posts: 13

I have not had experience looking at this but here is what I found.

I tried JConsole ( in your bin directory ). That gives you a lot of information about various pools, but no specific mention of stack.

I found something that indicates setting the stack size higher may be a problem because each thread gets that amount of space and you can actually run out of memory faster.

I found this HotSpot parameter documentation that mentions some default sizes.

-XX:ThreadStackSize=512 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.]

on this page
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

There is another parameter for Solaris only on that page as well.

Have fun !

KayCee Clark
Greenhorn

Joined: Jun 22, 2011
Posts: 13

A little bit more, but I don't (yet?) see any direct way to just look at stack size programatically.

A good page on tuning, including memory, from Oracle.

http://java.sun.com/performance/reference/whitepapers/

tuning.html


I found this page where the author provides his code

and his reasoning behind the test and calculations.

http://www.odi.ch/weblog/posting.php?posting=411


Also, some code here, but again, nothing specific for

stack.

http://viralpatel.net/blogs/2009/05/getting-jvm-heap-s

ize-used-memory-total-memory-using-java-runtime.html
Mohtashim Shaikh
Ranch Hand

Joined: Jul 18, 2010
Posts: 43
Hi,

Thank you for your reply. However, what i am looking for is to read whatever the current set -Xss (stack sie) is for a particular JVM i.e PID be it default or set eplicitly from inside a unix shell script or a java program inorder to setup a monitoring alert script.

A third-party tool may also come handy only if we can use its API inorder to read the stack size inside the unix shell script or a java program.

Kindly help !!!

Regards,
Mohtashim
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Moving discussion as too difficult for "beginning".
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

There is no (easy) way of getting the stack size for threads in a Java process.

There is for example no system property that you could get with System.getProperty(...), and even the JVM TI (an API for debugging and profiling tools to get information from and control a running JVM) doesn't seem to have any way to get the stack size.

Why do you need this?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Mohtashim Shaikh
Ranch Hand

Joined: Jul 18, 2010
Posts: 43
The pmap command for solaris tells us the current stack usage for a JVM. What is th use of the current stack size that it displays when there should be no way to find the upper limit of stack which that JVM is allowed to run with.

This deprives us for writing a script that alerts as the stack size reaches more than 90% of allocated stack size. Thats why i need it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stack Memory
 
Similar Threads
Doubt in stack
Static
Simple Java Program throwing cannot create process =193 error
how to clear the stack
What is stored on Stack and Heap