关于Sun HotSpot JVM的相关要点 jvmsunjavaGCHotSpot
程序员文章站
2022-03-23 09:52:17
...
关于Sun HotSpot JVM的相关要点:
1、JVM的模式:
(1).-server==>优化模式,启动时慢,但运行时快,比client性能高,一般的web应用都建议JVM用此模式。
(2).-client ==>GUI时用此模式好,启动应用时比-server模式快。
(3).-Xint ==>解释器模式
JVM默认的模式,可以通过java -version查看。
2、JVM Memory Structure:
(1).Method Area
(2).Java Heap
(3).Java Stack => Java Virtual Machine Stack
(4).Program Counter
(5).Native Method Stack
(6).Runtime Constant Pool
注意:32bit or 64bit=>address space=kernel space + user space(native space +jvm memory)
3、Dump 文件:
(1).Java Dump==>Thread Dump
(2).Heap Dump
(3).System Dump
4、JVM down:
(1).JVM:java.lang.OutOfMemoryError==>java_pid<number>.hprof==>for example:java_pid2262.hprof <==需要配置:-XX:+HeapDumpOnOutOfMemoryError
(2).JVM:crash==>hs_err_pid<number>.log==>for example:hs_err_pid7821.log
5、重要的JVM参数:
(1).-Djava.compiler=NONE
(2).-XX:CompileCommand=exclude,com/apusic/net/Muxer.acceptConnection
(3).-Djava.awt.headless=true =>如果是GUI程序,则需要配置该参数为false,即需要外显设备,如果是WEB 程序,不需要在服务器端显示,不需要外显设备,则配置为true。
(4).调试JVM GC:-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:gc.log
(5).配置xml解析器:
(5.1)=>xml解析器用sun的
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
=>sun jdk的rt.jar中包含此两个类
(5.2)=>也可以指定为第三方的xml解析器:
-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
=>需要jar包:xercesImpl-2.6.2.jar
6、GC日志释义:
>>Serial GC
17.868: [Full GC (System) 17.868: [Tenured: 0K->17790K(262144K), 0.3105753 secs] 77919K->17790K(498112K), [Perm : 28414K->28414K(65536K)], 0.3106954 secs] [Times: user=0.30 sys=0.01, real=0.31 secs]
释义:
(1).[Tenured: 0K->17790K(262144K), 0.3105753 secs]==>老代大小为:262144K,major GC(Full GC)前使用了0K,GC后使用了17790K,耗时:0.3105753 secs
(2).77919K->17790K(498112K)==>heap的总大小为:498112K=512*1024K-26176K,即-Xms512M -Xmx512M中指定的heap的大小(512M)减去一个survior的大小,因为总是有一个survior为空。
(3).[Perm : 28414K->28414K(65536K)]==>perm代大小为:65536K,GC前使用了:28414K,GC后使用了28414K。注意:只有CMS策略时才可卸载Perm中的类。
(4).Serial GC=>默认使用该策略
(5).各个代的布局:
Heap
def new generation total 235968K, used 27052K [0x13900000, 0x23900000, 0x23900000)
eden space 209792K, 12% used [0x13900000, 0x1536b138, 0x205e0000)
from space 26176K, 0% used [0x21f70000, 0x21f70000, 0x23900000)
to space 26176K, 0% used [0x205e0000, 0x205e0000, 0x21f70000)
tenured generation total 262144K, used 25969K [0x23900000, 0x33900000, 0x33900000)
the space 262144K, 9% used [0x23900000, 0x2525c440, 0x2525c600, 0x33900000)
compacting perm gen total 65536K, used 40068K [0x33900000, 0x37900000, 0x37900000)
the space 65536K, 61% used [0x33900000, 0x36021018, 0x36021200, 0x37900000)
ro space 10240K, 54% used [0x37900000, 0x37e78290, 0x37e78400, 0x38300000)
rw space 12288K, 55% used [0x38300000, 0x3899d1c0, 0x3899d200, 0x38f00000)
>>Parallel GC
16.275: [Full GC (System) [PSYoungGen: 18245K->0K(229376K)] [PSOldGen: 0K->18024K(262144K)] 18245K->18024K(491520K) [PSPermGen: 33034K->33034K(65536K)], 0.2545408 secs] [Times: user=0.23 sys=0.02, real=0.25 secs]
(1).Parallel GC=>-XX:+UseParallelGC -XX:ParallelGCThreads=8 -XX:+ParallelRefProcEnabled
(2).各个代的布局:
Heap
PSYoungGen total 229376K, used 22887K [0x17990000, 0x27990000, 0x27990000)
eden space 196608K, 11% used [0x17990000,0x18fe9ff8,0x23990000)
from space 32768K, 0% used [0x25990000,0x25990000,0x27990000)
to space 32768K, 0% used [0x23990000,0x23990000,0x25990000)
PSOldGen total 262144K, used 18217K [0x07990000, 0x17990000, 0x17990000)
object space 262144K, 6% used [0x07990000,0x08b5a5e0,0x17990000)
PSPermGen total 65536K, used 37289K [0x03990000, 0x07990000, 0x07990000)
object space 65536K, 56% used [0x03990000,0x05dfa548,0x07990000)
>>ConcMarkSweepGC
110.174: [Full GC (System) 110.175: [CMS: 34625K->30884K(262144K), 0.5798030 secs] 63310K->30884K(498112K), [CMS Perm : 46506K->45974K(65536K)], 0.5800074 secs] [Times: user=0.53 sys=0.00, real=0.58 secs]
(1).CMS GC=>-XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection
(2).各个代的布局
Heap
par new generation total 235968K, used 22476K [0x03920000, 0x13920000, 0x13920000)
eden space 209792K, 10% used [0x03920000, 0x04f131e8, 0x10600000)
from space 26176K, 0% used [0x10600000, 0x10600000, 0x11f90000)
to space 26176K, 0% used [0x11f90000, 0x11f90000, 0x13920000)
concurrent mark-sweep generation total 262144K, used 26411K [0x13920000, 0x23920000, 0x23920000)
concurrent-mark-sweep perm gen total 65536K, used 46039K [0x23920000, 0x27920000, 0x27920000)
1、JVM的模式:
(1).-server==>优化模式,启动时慢,但运行时快,比client性能高,一般的web应用都建议JVM用此模式。
(2).-client ==>GUI时用此模式好,启动应用时比-server模式快。
(3).-Xint ==>解释器模式
JVM默认的模式,可以通过java -version查看。
2、JVM Memory Structure:
(1).Method Area
(2).Java Heap
(3).Java Stack => Java Virtual Machine Stack
(4).Program Counter
(5).Native Method Stack
(6).Runtime Constant Pool
注意:32bit or 64bit=>address space=kernel space + user space(native space +jvm memory)
3、Dump 文件:
(1).Java Dump==>Thread Dump
(2).Heap Dump
(3).System Dump
4、JVM down:
(1).JVM:java.lang.OutOfMemoryError==>java_pid<number>.hprof==>for example:java_pid2262.hprof <==需要配置:-XX:+HeapDumpOnOutOfMemoryError
(2).JVM:crash==>hs_err_pid<number>.log==>for example:hs_err_pid7821.log
5、重要的JVM参数:
(1).-Djava.compiler=NONE
(2).-XX:CompileCommand=exclude,com/apusic/net/Muxer.acceptConnection
(3).-Djava.awt.headless=true =>如果是GUI程序,则需要配置该参数为false,即需要外显设备,如果是WEB 程序,不需要在服务器端显示,不需要外显设备,则配置为true。
(4).调试JVM GC:-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:gc.log
(5).配置xml解析器:
(5.1)=>xml解析器用sun的
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
=>sun jdk的rt.jar中包含此两个类
(5.2)=>也可以指定为第三方的xml解析器:
-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
=>需要jar包:xercesImpl-2.6.2.jar
6、GC日志释义:
>>Serial GC
17.868: [Full GC (System) 17.868: [Tenured: 0K->17790K(262144K), 0.3105753 secs] 77919K->17790K(498112K), [Perm : 28414K->28414K(65536K)], 0.3106954 secs] [Times: user=0.30 sys=0.01, real=0.31 secs]
释义:
(1).[Tenured: 0K->17790K(262144K), 0.3105753 secs]==>老代大小为:262144K,major GC(Full GC)前使用了0K,GC后使用了17790K,耗时:0.3105753 secs
(2).77919K->17790K(498112K)==>heap的总大小为:498112K=512*1024K-26176K,即-Xms512M -Xmx512M中指定的heap的大小(512M)减去一个survior的大小,因为总是有一个survior为空。
(3).[Perm : 28414K->28414K(65536K)]==>perm代大小为:65536K,GC前使用了:28414K,GC后使用了28414K。注意:只有CMS策略时才可卸载Perm中的类。
(4).Serial GC=>默认使用该策略
(5).各个代的布局:
Heap
def new generation total 235968K, used 27052K [0x13900000, 0x23900000, 0x23900000)
eden space 209792K, 12% used [0x13900000, 0x1536b138, 0x205e0000)
from space 26176K, 0% used [0x21f70000, 0x21f70000, 0x23900000)
to space 26176K, 0% used [0x205e0000, 0x205e0000, 0x21f70000)
tenured generation total 262144K, used 25969K [0x23900000, 0x33900000, 0x33900000)
the space 262144K, 9% used [0x23900000, 0x2525c440, 0x2525c600, 0x33900000)
compacting perm gen total 65536K, used 40068K [0x33900000, 0x37900000, 0x37900000)
the space 65536K, 61% used [0x33900000, 0x36021018, 0x36021200, 0x37900000)
ro space 10240K, 54% used [0x37900000, 0x37e78290, 0x37e78400, 0x38300000)
rw space 12288K, 55% used [0x38300000, 0x3899d1c0, 0x3899d200, 0x38f00000)
>>Parallel GC
16.275: [Full GC (System) [PSYoungGen: 18245K->0K(229376K)] [PSOldGen: 0K->18024K(262144K)] 18245K->18024K(491520K) [PSPermGen: 33034K->33034K(65536K)], 0.2545408 secs] [Times: user=0.23 sys=0.02, real=0.25 secs]
(1).Parallel GC=>-XX:+UseParallelGC -XX:ParallelGCThreads=8 -XX:+ParallelRefProcEnabled
(2).各个代的布局:
Heap
PSYoungGen total 229376K, used 22887K [0x17990000, 0x27990000, 0x27990000)
eden space 196608K, 11% used [0x17990000,0x18fe9ff8,0x23990000)
from space 32768K, 0% used [0x25990000,0x25990000,0x27990000)
to space 32768K, 0% used [0x23990000,0x23990000,0x25990000)
PSOldGen total 262144K, used 18217K [0x07990000, 0x17990000, 0x17990000)
object space 262144K, 6% used [0x07990000,0x08b5a5e0,0x17990000)
PSPermGen total 65536K, used 37289K [0x03990000, 0x07990000, 0x07990000)
object space 65536K, 56% used [0x03990000,0x05dfa548,0x07990000)
>>ConcMarkSweepGC
110.174: [Full GC (System) 110.175: [CMS: 34625K->30884K(262144K), 0.5798030 secs] 63310K->30884K(498112K), [CMS Perm : 46506K->45974K(65536K)], 0.5800074 secs] [Times: user=0.53 sys=0.00, real=0.58 secs]
(1).CMS GC=>-XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection
(2).各个代的布局
Heap
par new generation total 235968K, used 22476K [0x03920000, 0x13920000, 0x13920000)
eden space 209792K, 10% used [0x03920000, 0x04f131e8, 0x10600000)
from space 26176K, 0% used [0x10600000, 0x10600000, 0x11f90000)
to space 26176K, 0% used [0x11f90000, 0x11f90000, 0x13920000)
concurrent mark-sweep generation total 262144K, used 26411K [0x13920000, 0x23920000, 0x23920000)
concurrent-mark-sweep perm gen total 65536K, used 46039K [0x23920000, 0x27920000, 0x27920000)
上一篇: 将自然数分解为连续自然数之积