﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-paulwong-随笔分类-JVM</title><link>http://www.blogjava.net/paulwong/category/55341.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 24 Feb 2020 17:28:03 GMT</lastBuildDate><pubDate>Mon, 24 Feb 2020 17:28:03 GMT</pubDate><ttl>60</ttl><item><title>各种获取JVM DUMP的方法</title><link>http://www.blogjava.net/paulwong/archive/2020/02/24/435157.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 24 Feb 2020 14:03:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/02/24/435157.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435157.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/02/24/435157.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435157.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435157.html</trackback:ping><description><![CDATA[<p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">JVM 的线程堆栈 dump 也称 core dump，内容为文本，主要包含当时 JVM 的线程堆栈，堆 dump 也称 heap dump，内容为二进制格式，主要包含当时 JVM 堆内存中的内容。由于各个操作系统、各个 JVM 实现不同，即使同一 JVM 实现，各个版本也有差异，本文描述的方法都基于 64 位 Linux 操作系统环境，Java 8 Oracle HotSpot JVM 实现。</p><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">堆栈和堆的内容在定位问题的时候，都是非常重要的信息。线程堆栈 dump 可以了解当时 JVM 中所有线程的运行情况，比如线程的状态和当前正在运行的代码行。堆 dump 可以了解当时堆的使用情况，各个类实例的数量及各个实例所占用的空间大小。</p><h1>线程堆栈</h1><h2>使用 jstack</h2><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">jstack 是 JDK 自带的工具，用于 dump 指定进程 ID(PID)的 JVM 的线程堆栈信息。</p><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;打印堆栈信息到标准输出&nbsp;jstack&nbsp;PID&nbsp;&nbsp;<br />#&nbsp;打印堆栈信息到标准输出，会打印关于锁的信息&nbsp;jstack&nbsp;-l&nbsp;PID&nbsp;&nbsp;<br />强制打印堆栈信息到标准输出，如果使用&nbsp;jstack&nbsp;PID&nbsp;没有响应的情况下(此时&nbsp;JVM&nbsp;进程可能挂起)，<br />加&nbsp;-F&nbsp;参数&nbsp;jstack&nbsp;-F&nbsp;PID&nbsp;</div></pre></div><h2>使用 jcmd</h2><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">jcmd 是 JDK 自带的工具，用于向 JVM 进程发送命令，根据命令的不同，可以代替或部分代替 jstack、jmap 等。可以发送命令&nbsp;<code>Thread.print</code>&nbsp;来打印出 JVM 的线程堆栈信息。</p><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;下面的命令同等于&nbsp;jstack&nbsp;PID&nbsp;<br />jcmd&nbsp;PID&nbsp;Thread.print&nbsp;&nbsp;<br /><br />#&nbsp;同等于&nbsp;jstack&nbsp;-l&nbsp;PID&nbsp;<br />jcmd&nbsp;PID&nbsp;Thread.print&nbsp;-l&nbsp;</div></pre></div><h2>使用 kill -3</h2><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">kill 可以向特定的进程发送信号(SIGNAL)，缺省情况是发送终止(TERM) 的信号 ，即 kill PID 与 kill -15 PID 或 kill -TERM PID 是等价的。JVM 进程会监听 QUIT 信号(其值为 3)，当收到这个信号时，会打印出当时的线程堆栈和堆内存使用概要，相比 jstack，此时多了堆内存的使用概要情况。但 jstack 可以指定 -l 参数，打印锁的信息。</p><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->kill&nbsp;-3&nbsp;PID&nbsp;<br />#&nbsp;或&nbsp;kill&nbsp;-QUIT&nbsp;PID&nbsp;</div></pre></div><h1>堆</h1><h2>-XX:+HeapDumpOnOutOfMemoryError</h2><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">添加 JVM 参数 -XX:+HeapDumpOnOutOfMemoryError 后，当发生 OOM(OutOfMemory)时，自动堆 dump。缺省情况下，JVM 会创建一个名称为 java_pidPID.hprof 的堆 dump 文件在 JVM 的工作目录下。但可以使用参数 -XX:HeapDumpPath=PATH 来指定 dump 文件的保存位置。</p><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;JVM&nbsp;发生&nbsp;OOM&nbsp;时，会自动在&nbsp;/var/log/abc&nbsp;目录下产生堆&nbsp;dump&nbsp;文件&nbsp;java_pidPID.hprof&nbsp;<br />java&nbsp;-XX:+HeapDumpOnOutOfMemoryError&nbsp;-XX:HeapDumpPath=/var/log/abc/&nbsp;</div></pre></div><h2>jmap</h2><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">jmap 也是 JDK 自带的工具，主要用于获取堆相关的信息。</p><h3>堆 dump</h3><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;将&nbsp;JVM&nbsp;的堆&nbsp;dump&nbsp;到指定文件，如果堆中对象较多，需要的时间会较长，子参数&nbsp;format&nbsp;只支持&nbsp;b，<br />即二进制格式<br />jmap&nbsp;-dump:format=b,file=FILE_WITH_PATH<br /><br />#&nbsp;如果&nbsp;JVM&nbsp;进程未响应命令，可以加上参数&nbsp;-F&nbsp;尝试<br />jmap&nbsp;-F&nbsp;-dump:format=b,file=FILE_WITH_PATH<br /><br />#&nbsp;可以只&nbsp;dump&nbsp;堆中的存活对象，加上&nbsp;live&nbsp;子参数，但使用&nbsp;-F&nbsp;时不支持&nbsp;live<br />jmap&nbsp;-dump:live,format=b,file=FILE_WITH_PATH</div></pre></div><h3>获取堆概要信息</h3><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;-heap&nbsp;参数用于查看指定&nbsp;JVM&nbsp;进程的堆的信息，包括堆的各个参数的值，堆中新生代、年老代的内存大小、使用率等&nbsp;<br />jmap&nbsp;-heap&nbsp;PID&nbsp;&nbsp;<br /><br />#&nbsp;同样，如果&nbsp;JVM&nbsp;进程未响应命令，可以加上参数&nbsp;-F&nbsp;尝试&nbsp;<br />jmap&nbsp;-F&nbsp;-heap&nbsp;PID&nbsp;</div></pre></div><p style="font-size: medium; font-family: &quot;Times New Roman&quot;;">一个实例输出如下：</p><div style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Attaching&nbsp;to&nbsp;process&nbsp;ID&nbsp;68322,&nbsp;please&nbsp;wait<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />Debugger&nbsp;attached&nbsp;successfully.<br />Server&nbsp;compiler&nbsp;detected.<br />JVM&nbsp;version&nbsp;is&nbsp;25.112-b16<br /><br />using&nbsp;thread-local&nbsp;object&nbsp;allocation.<br />Parallel&nbsp;GC&nbsp;with&nbsp;4&nbsp;thread(s)<br /><br />Heap&nbsp;Configuration:<br />&nbsp;&nbsp;&nbsp;MinHeapFreeRatio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;0<br />&nbsp;&nbsp;&nbsp;MaxHeapFreeRatio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;100<br />&nbsp;&nbsp;&nbsp;MaxHeapSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;268435456&nbsp;(256.0MB)<br />&nbsp;&nbsp;&nbsp;NewSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;8388608&nbsp;(8.0MB)<br />&nbsp;&nbsp;&nbsp;MaxNewSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;89128960&nbsp;(85.0MB)<br />&nbsp;&nbsp;&nbsp;OldSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;16777216&nbsp;(16.0MB)<br />&nbsp;&nbsp;&nbsp;NewRatio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;2<br />&nbsp;&nbsp;&nbsp;SurvivorRatio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;8<br />&nbsp;&nbsp;&nbsp;MetaspaceSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;21807104&nbsp;(20.796875MB)<br />&nbsp;&nbsp;&nbsp;CompressedClassSpaceSize&nbsp;=&nbsp;1073741824&nbsp;(1024.0MB)<br />&nbsp;&nbsp;&nbsp;MaxMetaspaceSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;17592186044415&nbsp;MB<br />&nbsp;&nbsp;&nbsp;G1HeapRegionSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;0&nbsp;(0.0MB)<br /><br />Heap&nbsp;Usage:<br />PS&nbsp;Young&nbsp;Generation<br />Eden&nbsp;Space:<br />&nbsp;&nbsp;&nbsp;capacity&nbsp;=&nbsp;41943040&nbsp;(40.0MB)<br />&nbsp;&nbsp;&nbsp;used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;1701504&nbsp;(1.6226806640625MB)<br />&nbsp;&nbsp;&nbsp;free&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;40241536&nbsp;(38.3773193359375MB)<br />&nbsp;&nbsp;&nbsp;4.05670166015625%&nbsp;used<br />From&nbsp;Space:<br />&nbsp;&nbsp;&nbsp;capacity&nbsp;=&nbsp;4194304&nbsp;(4.0MB)<br />&nbsp;&nbsp;&nbsp;used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;0&nbsp;(0.0MB)<br />&nbsp;&nbsp;&nbsp;free&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;4194304&nbsp;(4.0MB)<br />&nbsp;&nbsp;&nbsp;0.0%&nbsp;used<br />To&nbsp;Space:<br />&nbsp;&nbsp;&nbsp;capacity&nbsp;=&nbsp;5242880&nbsp;(5.0MB)<br />&nbsp;&nbsp;&nbsp;used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;0&nbsp;(0.0MB)<br />&nbsp;&nbsp;&nbsp;free&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;5242880&nbsp;(5.0MB)<br />&nbsp;&nbsp;&nbsp;0.0%&nbsp;used<br />PS&nbsp;Old&nbsp;Generation<br />&nbsp;&nbsp;&nbsp;capacity&nbsp;=&nbsp;30408704&nbsp;(29.0MB)<br />&nbsp;&nbsp;&nbsp;used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;12129856&nbsp;(11.56793212890625MB)<br />&nbsp;&nbsp;&nbsp;free&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;18278848&nbsp;(17.43206787109375MB)<br />&nbsp;&nbsp;&nbsp;39.889421134159484%&nbsp;used<br /><br />16658&nbsp;interned&nbsp;Strings&nbsp;occupying&nbsp;1428472&nbsp;bytes.</div><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;"><br />获取堆中的类实例统计</span></pre></div><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;打印&nbsp;JVM&nbsp;堆中的类实例统计信息，以占用内存的大小排序，同样，如果&nbsp;JVM&nbsp;未响应命令，也可以使用&nbsp;-F&nbsp;参数&nbsp;<br />jmap&nbsp;-histo&nbsp;PID&nbsp;&nbsp;<br /><br />#&nbsp;也可以只统计堆中的存活对象，加上&nbsp;live&nbsp;子参数，但使用&nbsp;-F&nbsp;时不支持&nbsp;live&nbsp;<br />jmap&nbsp;-histo:live&nbsp;PID&nbsp;</div></pre></div><h2>使用 jcmd</h2><div highlighter-rouge"="" style="font-size: medium; font-family: &quot;Times New Roman&quot;;"><pre><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#&nbsp;等同&nbsp;jmap&nbsp;-dump:live,format=b,file=FILE_WITH_PATH<br />jcmd&nbsp;PID&nbsp;GC.heap_dump&nbsp;FILE_WITH_PATH<br /><br />#&nbsp;等同&nbsp;jmap&nbsp;-dump:format=b,file=FILE_WITH_PATH<br />jcmd&nbsp;PID&nbsp;GC.heap_dump&nbsp;-all&nbsp;FILE_WITH_PATH<br /><br />#&nbsp;等同&nbsp;jmap&nbsp;-histo:live&nbsp;PID<br />jcmd&nbsp;PID&nbsp;GC.class_histogram<br /><br />#&nbsp;等同&nbsp;jmap&nbsp;-histo&nbsp;PID<br />jcmd&nbsp;PID&nbsp;GC.class_histogram&nbsp;-all</div></pre></div><img src ="http://www.blogjava.net/paulwong/aggbug/435157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-02-24 22:03 <a href="http://www.blogjava.net/paulwong/archive/2020/02/24/435157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>!!21 MOST IMPORTANT JAVA 8 VM OPTIONS FOR SERVERS</title><link>http://www.blogjava.net/paulwong/archive/2020/02/16/435118.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Sun, 16 Feb 2020 14:30:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/02/16/435118.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435118.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/02/16/435118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435118.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435118.html</trackback:ping><description><![CDATA[<header style="position: relative; z-index: 1; margin: 0px auto; max-width: 474px; background-color: #ffffff; padding: 0px 30px 12px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px;"><h1><br /></h1><div style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; margin: 0px auto 8px; outline: 0px; vertical-align: baseline; clear: both; color: #767676; line-height: 1.33333; text-transform: uppercase; max-width: 474px;"><span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 10px 0px 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="https://www.maknesium.de/21-most-important-java-8-vm-options-for-servers" rel="bookmark" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #767676; text-decoration-line: none;"><time datetime="2016-03-27T19:23:29+01:00">27/03/2016</time></a></span>&nbsp;<span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 10px 0px 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span vcard"="" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a fn=""  n"="" href="https://www.maknesium.de/author/mak" rel="author" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #767676; text-decoration-line: none;">MAURICE KNOPP</a></span></span>&nbsp;<span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 10px 0px 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="https://www.maknesium.de/21-most-important-java-8-vm-options-for-servers#comments" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #767676; text-decoration-line: none;">7 KOMMENTARE</a></span></div></header><div style="border: 0px; font-family: Lato, sans-serif; font-size: 16px; margin: 0px auto; outline: 0px; padding-top: 12px; padding-right: 30px; padding-left: 30px; vertical-align: baseline; overflow-wrap: break-word; max-width: 474px; background-color: #ffffff; color: #2b2b2b;"><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">In this video I explain some 21 JVM parameters which are suited for most server applications. If you have any questions, you can read those links below for more information or just ask in the comments section.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;"></p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="https://youtu.be/qevqQ2XRxpU" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #24890d;"><img src="https://www.maknesium.de/wp-content/uploads/2013/10/java_video.jpg" alt="Java server flags video" width="474" height="316" size-full=""  wp-image-1630"="" srcset="https://www.maknesium.de/wp-content/uploads/2013/10/java_video.jpg 474w, https://www.maknesium.de/wp-content/uploads/2013/10/java_video-300x200.jpg 300w" sizes="(max-width: 474px) 100vw, 474px" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;" /></a></p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">I run several Java enterprise server applications. I often wondered &#8211; what are the best &#8222;default&#8220; JVM settings for a server application to start with in production? I read a lot on the web and tried several things myself and wanted to share what I found out, so far. Links containing more information about JVM optimization can be found here:</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">http://blog.sokolenko.me/2014/11/javavm-options-production.html</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">http://www.petefreitag.com/articles/gctuning/</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">http://stas-blogspot.blogspot.de/2011/07/most-complete-list-of-xx-options-for.html</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">&nbsp;</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">So let&#8217;s start:</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-server</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Use &#8222;-server&#8220;: All 64-bit JVMs use the server VM as default anyway. This setting generally optimizes the JVM for long running server applications instead of startup time. The JVM will collect more data about the Java byte code during program execution and generate the most efficient machine code via JIT.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-Xms=&lt;heap size&gt;[g|m|k] -Xmx=&lt;heap size&gt;[g|m|k]</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The &#8222;-Xmx/-Xms&#8220; settings specify the maximum and minimum values for the JVM heap memory. For servers, both params should have the same value to avoid heap resizing during runtime. I&#8217;ve applications running with 16GB heap sizes without an issue.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Depending on your application, you will have to try out how much memory will be best suited for your use case.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:MaxMetaspaceSize=&lt;metaspace size&gt;[g|m|k]</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Java 8 has no &#8222;Permanent Generation&#8220; (PermGen) anymore but requires additional &#8222;Metaspace&#8220; memory instead. This memory is used, in addition to the heap memory we specified before, for storing class meta data information.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The default size will be unlimited &#8211; I tend to limit MaxMetaspaceSize with a somewhat high value. Just in case something goes wrong with the application, the JVM will not hog all the memory of the server.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">I suggest: Let your application run for a couple of days to get a feeling for how much Metaspace Size it uses normally. Upon next restart of the application set the limit to e.g. double the value.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+CMSClassUnloadingEnabled</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Additionally, you might want to allow the JVM to unload classes which are held in memory but no code is pointing to them any more. If your application generates lots of dynamic classes, this is what you want.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+UseConcMarkSweepGC</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">This option makes the JVM use the ConcurrentMarkSweepGC &#8211; It can do much work in parallel to program execution but in some circumstances a &#8222;full GC&#8220; with a &#8222;STW pause&#8220; might still occur. I&#8217;ve read many articles and came to the conclusion that this GC is still the best one for server workloads.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+CMSParallelRemarkEnabled</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The option CMSParallelRemarkEnabled means the remarking is done in parallel to program execution &#8211; which is what you want if your server has many cores (and most servers do).</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;"> -XX:+UseCMSInitiatingOccupancyOnly  -XX:CMSInitiatingOccupancyFraction=&lt;percent&gt;</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Normally the GC will use heuristics to know when it&#8217;s time to clear memory. GC might kick in too late with default settings (causing full-Gcs).<br />Some sources say it might be a good idea to disable heuristics altogether and just use generation occupancy to start a CMS collection cycle. Setting values around 70% worked fine for all of my applications and use cases.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+ScavengeBeforeFullGC</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The first option tells the GC to first free memory by clearing out the &#8222;young generation&#8220; or fairly new objects before doing a full GC.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+CMSScavengeBeforeRemark</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">CMSScavengeBeforeRemark does attempt a minor collection before the CMS remark phase &#8211; thus keeping the remark pause afterwards short.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+CMSClassUnloadingEnabled</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The option &#8222;-XX:+CMSClassUnloadingEnabled&#8220; here tells the JVM to unload classes, which are not needed any more by the running application. If you deploy war files to an application server like wildfly, tomcat or glassfish without restarting the server after the deployment, this flag is for you.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">The option &#8222;-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses&#8220; is especially important if your application uses RMI (remote method invocation). The usage of RMI will cause the JVM to do a FULL-GC EVERY HOUR! This might be a very bad idea for large heap sizes because the FULL-GC pause might take up to several seconds. It would be better to do a concurrent GC and try to unload unused classes to free up more memory &#8211; which is exactly what the second option does.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:"&lt;path to log&gt;"</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">These options shown here will write out all GC related information to a specified log file. You can see how well your GC configuration works by looking into it.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">I personally prefer to use the &#8222;Visual GC&#8220; plug in for the &#8222;Visual VM&#8220; tool to monitor the general JVM and GC behavior.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=&lt;path to dump&gt;`date`.hprof</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">When your JVM runs out of memory, you will want to know why. Since the OOM error might be hard to reproduce and you want to get your production server up and running again &#8211; you should specify a path for a heap dump. When things have settled down, you can analyze the dump afterwards.</p><pre style="border: 1px solid rgba(0, 0, 0, 0.1); font-family: monospace, serif; font-size: 15px; font-style: inherit; font-weight: inherit; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 12px; vertical-align: baseline; hyphens: none; line-height: 1.6; box-sizing: border-box; max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word;">-Djava.rmi.server.hostname=&lt;external IP&gt; -Dcom.sun.management.jmxremote.port=&lt;port&gt;</pre><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">These options will help you to specify an IP and port for JMX &#8211; you will need those ports open to connect remotely to a JVM running on a server for tools like VisualVM. You can gain deep insights over cpu and memory usage, gc behaviour, class loading, thread count and usage of your application this way.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;"><img wp-image-1584"="" src="http://www.maknesium.de/wp-content/uploads/2016/03/Selection_002-300x200.png" alt="Visual VM" width="500" height="333" srcset="https://www.maknesium.de/wp-content/uploads/2016/03/Selection_002-300x200.png 300w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_002-768x512.png 768w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_002-1024x682.png 1024w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_002.png 1061w" sizes="(max-width: 500px) 100vw, 500px" style="border: 0px; vertical-align: middle; display: block; margin: 7px auto; max-width: 100%; height: auto;" /><br />Lastly, I would like to recommend to you the VisualVM tool which is bundled with the Java 8 JDK. You can use it to gain more insights about your specific application behaviour on the JVM &#8211; like cpu and memory usage, thread utilisation and much more.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;"><img wp-image-1585"="" src="http://www.maknesium.de/wp-content/uploads/2016/03/Selection_003-300x172.png" alt="Visual GC" width="500" height="287" srcset="https://www.maknesium.de/wp-content/uploads/2016/03/Selection_003-300x172.png 300w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_003-768x441.png 768w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_003-1024x588.png 1024w, https://www.maknesium.de/wp-content/uploads/2016/03/Selection_003.png 1066w" sizes="(max-width: 500px) 100vw, 500px" style="border: 0px; vertical-align: middle; display: block; margin: 7px auto; max-width: 100%; height: auto;" />VisualVM can be extended with a plug in called &#8222;Visual GC&#8220;. It will briefly show you VERY detailed information about the usage of the young and old generation object spaces. You can easily spot problems with garbage collection simply by analyzing these graphs during application runtime.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Thank you very much for watching! If you liked the video you might consider giving it a &#8222;thumbs up&#8220;. If you have any questions &#8211; just put them in the comments section. I will reply as quickly as possible.<br /><br />-------------------------------------------------------<br /><br /></p><p style="border: 0px; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">-XX:+UseCompressedOops [If Max Heap allocation is less than 32GB]<br />This can save a significant amount of memory and this option should already be enabled by default on recent java 8 versions. This option allowes object references to be stored as 32-bit values instead of 64-bit on 64-bit JVMs. This leads to before mentioned memory savings.</p><p style="border: 0px; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">-XX:+AggressiveOpts<br />This option will enable performance options which are hoped to become enabled by default in upcoming released of the JVM. This option sets some performance settings but is marked as experimental! So you should only enable it, when you have to possibility to test your application thoroughly before enabling this flag on an production server.</p><p style="border: 0px; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">-XX:+UseStringDeduplication<br />Since Java 8 update 20 you can use this option to reduce the memory usage of your application. The JVM will spot identical strings in memory, remove the duplicated and point all references to the remaining, single instance of the string.</p><p style="border: 0px; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">-XX:+UseG1GC<br />Will tell the JVM to use the most recent G1 garbage collector. You are trading better application response times (due to shorter gc times with G1) against lower throughput (compared against good old ConcMarkSweepGC / CMS). If your application can deliver more value through short gc times, then G1 is definately better suited. Otherwise on Java 8, I&#8217;d recommend sticking with CMS.</p><p style="border: 0px; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;">Concerning your Tomcat 8 question, I&#8217;d suggest you have a look into it with the &#8222;VisualVM&#8220; tool. Look at memory usage, GC times (visual GC plugin), pull and analyse stack traces or thread dumps to find the weak spot. You might also consider attaching a debugger to tomcat to find the bug.</p><p style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline;"><br /><br /><a href="https://www.maknesium.de/21-most-important-java-8-vm-options-for-servers" target="_blank">https://www.maknesium.de/21-most-important-java-8-vm-options-for-servers</a></p></div><img src ="http://www.blogjava.net/paulwong/aggbug/435118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-02-16 22:30 <a href="http://www.blogjava.net/paulwong/archive/2020/02/16/435118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Guide to the Most Important JVM Parameters</title><link>http://www.blogjava.net/paulwong/archive/2019/08/01/434330.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 01 Aug 2019 08:55:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2019/08/01/434330.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/434330.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2019/08/01/434330.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/434330.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/434330.html</trackback:ping><description><![CDATA[<a href="https://www.baeldung.com/jvm-parameters" target="_blank">https://www.baeldung.com/jvm-parameters</a>a<br /><br />Optimising Your Minecraft: Jvm Arguments<br /><a href="https://xealgaming.net/threads/optimising-your-minecraft-jvm-arguments.4758/" target="_blank">https://xealgaming.net/threads/optimising-your-minecraft-jvm-arguments.4758/</a><br /><img src ="http://www.blogjava.net/paulwong/aggbug/434330.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2019-08-01 16:55 <a href="http://www.blogjava.net/paulwong/archive/2019/08/01/434330.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JVM内存配置</title><link>http://www.blogjava.net/paulwong/archive/2019/08/01/434329.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 01 Aug 2019 08:44:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2019/08/01/434329.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/434329.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2019/08/01/434329.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/434329.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/434329.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;">JVM内存主要分为两个部分，分别是PermanentSapce和HeapSpace。</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;">PermantSpace主要负责存放加载的<a href="http://whatis.ctocio.com.cn/searchwhatis/213/5947213.shtml" style="color: #075db3;">Class</a>类级对象如class本身，<a href="http://whatis.ctocio.com.cn/searchwhatis/229/5948729.shtml" style="color: #075db3;">method</a>，field等反射对象，一般不用配置。</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;">JVM的Heap区可以通过-X参数来设定。HeapSpace= {Old + NEW {= Eden , from, to } }</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;">当一个URL被访问时，内存申请过程如下：</p><ol style="padding-left: 40px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"><li style="list-style-type: decimal;">JVM会试图为相关Java对象在Eden中初始化一块内存区域&nbsp;</li><li style="list-style-type: decimal;"><span style="line-height: 19.5px;">当Eden空间足够时，内存申请结束。否则到下一步&nbsp;</span></li><li style="list-style-type: decimal;">JVM试图释放在Eden中所有不活跃的对象（这属于1或更高级的垃圾回收）, 释放后若Eden空间仍然不足以放入新对象，则试图将部分Eden中活跃对象放入Survivor区</li><li style="list-style-type: decimal;"><span style="line-height: 19.5px;">&nbsp;Survivor区被用来作为Eden及OLD的中间交换区域，当OLD区空间足够时，Survivor区的对象会被移到Old区，否则会被保留在Survivor区&nbsp;</span></li><li style="list-style-type: decimal;"><span style="line-height: 19.5px;">当OLD区空间不够时，JVM会在OLD区进行完全的垃圾收集（0级）&nbsp;</span></li><li style="list-style-type: decimal;">完全垃圾收集后，若Survivor及OLD区仍然无法存放从Eden复制过来的部分对象，导致JVM无法在Eden区为新对象创建内存区域，则出现&#8221;out of memory错误&#8221;</li></ol><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"><strong><em><span style="line-height: 19.5px; text-decoration-line: underline;">Xms/Xmx</span></em></strong>：定义NEW+OLD段的总尺寸，ms为JVM启动时NEW+OLD的内存大小；mx为最大可占用的NEW+OLD内存大小。。在用户生产环境上一般将这两个值设为相同，以减少运行期间系统在内存申请上所花的开销；&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"><span style="line-height: 19.5px;"><span style="line-height: 19.5px; text-decoration-line: underline;"><em><strong>NewSize/MaxNewSize</strong></em></span>：定义单独NEW段的尺寸，NewSize为JVM启动时NEW的内存大小；MaxNewSize为最大可占用的NEW的内存大小。在用户生产环境上一般将这两个值设为相同，以减少运行期间系统在内存申请上所花的开销；</span></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"><span style="line-height: 19.5px;"><span style="line-height: 19.5px; text-decoration-line: underline;"><em><strong>Xms/Xmx和NewSize/MaxNewSize</strong></em></span>定义好后，OLD区间也自然定义完毕了，即OLD区初始大小=（Xms-NewSize），OLD区最大可占用大小=（Xmx-MaxNewSize）；&nbsp;</span></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"><span style="line-height: 19.5px;"><span style="line-height: 19.5px; text-decoration-line: underline;"><em><strong>PermSize/MaxPermSize</strong></em></span>：定义Perm段的尺寸，PermSize为JVM启动时Perm的内存大小；MaxPermSize为最大可占用的Perm内存大小。在用户生产环境上一般将这两个值设为相同，以减少运行期间系统在内存申请上所花的开销。</span></p><img src ="http://www.blogjava.net/paulwong/aggbug/434329.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2019-08-01 16:44 <a href="http://www.blogjava.net/paulwong/archive/2019/08/01/434329.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>