How do I get stack memory stats programatically?


I'm writing a simple memory reporting utility (in this particular situation using an existing tool is not an option). I've got it to print the max, commit and usage for all the memory pools returned by iterating ManagementFactory.getMemoryPoolMXBeans(). That gets me the three heap generations of heap memory (eden, survivor and old), the permgen, and the "code cache".

None of these appear to be the method stack memory. The closest thing seems be the "code cache", but I've read that that's actually where the hotspotter puts compiled classes.

I ask because I'm trying to track down the cause of a crash in a JBoss webapp that's failing to create a new thread. <a href="http://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-solve-javalangoutofmemoryerror-unable-to-create-new-native-thread" rel="nofollow">http://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-solve-javalangoutofmemoryerror-unable-to-create-new-native-thread</a> suggests that this could be due to running out of stack memory, which stands to reason. The question is: how do I <em>get</em> the stack memory, so I can check?


On Linux you can parse /proc/self/maps (or /proc/self/smaps for more details).<br /> Look for the lines ending with [stack:NNN] and calculate the stack size as top - bottom:

7f8a5c0e1000-7f8a5c1df000 rw-p 00000000 00:00 0 [stack:2669] ^ bottom ^ top ^ tid

On Windows this would be harder, but you can estimate the memory used by stacks as<br /><a href="https://docs.oracle.com/javase/7/docs/api/java/lang/management/ThreadMXBean.html#getThreadCount%28%29" rel="nofollow">number_of_threads</a> * <a href="https://stackoverflow.com/questions/23552296/how-to-determine-hotspot-vm-default-thread-stack-size" rel="nofollow">default_stack_size</a>


  • What happens when a tcp server binds and forks before doing an accept ? Which process would handle t
  • G1 GC — extremely long termination time
  • jdk1.6 memory layout
  • How is factorial computed?
  • SCSS Language Injection in Pycharm
  • Configure WAF Application Gateway in front of App Services [closed]
  • Pytest/Allure - How to generate testcase description?
  • Iterate twice through a DataReader
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Where these are stored?
  • HttpClient: disabling chunked encoding
  • Clear fused location provider's location for testing
  • android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException when using support lib
  • Display images in Django
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Using jQuery closest() method with class selector
  • Join two tables and save into third-sql
  • JSON with duplicate key names losing information when parsed
  • Trying to switch camera back to front but getting exception
  • Display Images one by one with next and previous functionality
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Matplotlib draw Spline from multiple points
  • XCode can't find symbols for a specific iOS library/framework project
  • Calling of Constructors in a Java
  • Compare two NSDates in iPhone
  • Transpose CSV data with awk (pivot transformation)
  • Use group_by to filter specific cases while keeping NAs
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • log4net write single file for each call to log.info
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • LevelDB C iterator
  • How can I remove ASP.NET Designer.cs files?
  • Can't mass-assign protected attributes when import data from csv file
  • Programmatically clearing map cache
  • java string with new operator and a literal