{"id":401,"date":"2013-09-19T14:11:23","date_gmt":"2013-09-19T13:11:23","guid":{"rendered":"http:\/\/hirt.se\/blog\/?p=401"},"modified":"2013-09-19T14:11:23","modified_gmt":"2013-09-19T13:11:23","slug":"native-memory-tracking-in-7u40","status":"publish","type":"post","link":"https:\/\/hirt.se\/blog\/?p=401","title":{"rendered":"Native Memory Tracking in 7u40"},"content":{"rendered":"<p>Since we don\u2019t have any nice NMT (Native Memory Tracking) MBean in HotSpot (yet), and therefore not in the JMC console, I thought I\u2019d show how it can be done using command line arguments and JCMD. Please note that you\u2019ll get a <font style=\"background-color: #ffff00\">5-10% performance hit<\/font> if you enable this.<\/p>\n<h2>Step 1 \u2013 Enabling NMT<\/h2>\n<p>This is done by using the following command line:<\/p>\n<pre>-XX:NativeMemoryTracking=[off|summary|detail]<\/pre>\n<p>Where the different options are: <\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"500\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"125\">off<\/td>\n<td valign=\"top\">NMT is turned off. This is the default.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">summary<\/td>\n<td valign=\"top\">Only collect memory usage aggregated by subsystem. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">detail<\/td>\n<td valign=\"top\">Collect memory usage by individual call sites.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#160;<\/p>\n<p>Again, note that enabling this will cause you a 5-10% overhead.<\/p>\n<p>&#160;<\/p>\n<h2>Step 2 \u2013 Using JCMD to Access the Data<\/h2>\n<p>To use JCMD to dump the data collected thus far, and to optionally compare it to the last baseline, use the following command:<\/p>\n<p><code>jcmd &lt;pid&gt; VM.native_memory [summary | detail | baseline | summary.diff | detail.diff | shutdown] [scale= KB | MB | GB]<\/code> <\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"500\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"125\">summary<\/td>\n<td valign=\"top\">Print a summary aggregated by category.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">detail<\/td>\n<td valign=\"top\">\n<ul>\n<li>Print memory usage aggregated by category <\/li>\n<li>Print virtual memory map <\/li>\n<li>Print memory usage aggregated by call site <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">baseline<\/td>\n<td valign=\"top\">Create a new memory usage snapshot to diff against.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">summary.diff<\/td>\n<td valign=\"top\">Print a new summary report against the last baseline.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">detail.diff<\/td>\n<td valign=\"top\">Print a new detail report against the last baseline.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"125\">shutdown<\/td>\n<td valign=\"top\">Shutdown NMT.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#160;<\/p>\n<p>Here is a table with the different memory categories (this may change):<br \/>\n  <\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"500\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Category <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Java Heap <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">The heap. This is where your objects live.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Class <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Class meta data. <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Code <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">Generated code.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>GC<\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">Data use by the GC, such as card table.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Compiler<\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">Memory used by the compiler when generating code.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Symbol<\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">Symbols.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Memory Tracking <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">Memory used by the NMT itself.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Pooled Free Chunks <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Memory used by chunks in the arena chunk pool.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Shared space for classes <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Memory mapped to class data sharing archive.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Thread <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Memory used by threads, including thread data structure, resource area and handle area, etc. <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Thread stack <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Thread stack. It is marked as committed memory, but it might not be completely committed by the OS.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Internal <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>Memory which does not fit the above categories, such as the memory used by the command line parser, JVMTI, properties, etc. <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"163\">\n<p>Unknown <\/p>\n<\/td>\n<td valign=\"top\" width=\"337\">\n<p>When memory category can not be determined. <\/p>\n<ul>\n<li>Arena: when arena is used as stack or value object <\/li>\n<li>Virtual Memory: when type information has not yet arrived <\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>&#160;<\/h2>\n<h2>Additional Options<\/h2>\n<p>Use the following NMT options to print a report on VM exit:<\/p>\n<pre><p>-XX:+PrintNMTStatistics -XX:+UnlockDiagnosticVMOptions<\/p><\/pre>\n<p>NMT will shut itself down when it detects low resource conditions, such as when running low on native memory. Sometimes that may be the situation when you would really want the data! This is the flag to disable auto shutdown:<\/p>\n<pre>-XX:-AutoShutdownNMT<\/pre>\n<p>Note that detail level information is not supported on ARM.<br \/>\n  <\/p>\n<h2>Final Thoughts<\/h2>\n<p>The information in this blog post mostly comes from a wiki document authored by Zhengyu Gu, who also did the HotSpot implementation. Also, shout out to Fredrik \u00d6hrstr\u00f6m who came up with the NMT idea, and who did the original JRockit implementation of it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since we don\u2019t have any nice NMT (Native Memory Tracking) MBean in HotSpot (yet), and therefore not in the JMC console, I thought I\u2019d show how it can be done using command line arguments and JCMD. Please note that you\u2019ll get a 5-10% performance hit if you enable this. Step 1 \u2013 Enabling NMT This [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-java-mission-control-fair-dj"],"_links":{"self":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=401"}],"version-history":[{"count":1,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/401\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/401\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}