JVM Parameters

Note

http://blog.csdn.net/yang_net/article/details/5830820 

JVM Paramter

http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html


Oracle JVM

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

Oracle GC Turnning

http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

A really Good tutorial 

http://javarevisited.blogspot.sg/2011/11/hotspot-jvm-options-java-examples.html

On the basis of how we specify JVM option it can be divided into two parts, JVM Options which starts with –X and those which starts with -XX:

1)    JVM Options that begin with -X are non-standard (thy are not guaranteed to be supported on all JVM implementations), and are subject to change without notice in subsequent releases of the JDK.

2)    JVM Options that begin with -XX are not stable and are not recommended for casual use. These options are subject to change without notice also.


If you wish to detect which JVM arguments your currently running Java application is using, you can use the ManagementFactory.getRuntimeMXBean().getInputArguments()

032632_wJPX_1767744.png

1) JVM memory options related to java heap sizeFollowing three JVM options are used to specify initial and max heap size and thread stack size while running Java programs. 

-Xms        set initial Java heap size 
-Xmx        set maximum Java heap size 
-Xss>         set java thread stack size

2) JVM option to print gc details-verbose:gc logs garbage collector runs and how long they're taking. I generally use this as my first tool to investigate if GC is a bottleneck for a given application.-

-XX:+PrintGCDetails includes the data from 
-verbose:gc but also adds information about the size of the new generation and more accurate timings.
-XX:-PrintGCTimeStamps  Print timestamps at garbage collection.

3) JVM parameters to specify Java Garbage collector

-XX:+UseParallelGC      Use parallel garbage collection for scavenges
-XX:-UseConcMarkSweepGC Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)
-XX:-UseSerialGC        Use serial garbage collection. (Introduced in 5.0.)

beware when you use GC Parameters if you are working on time critical application e.g. high frequency trading application. As  GC is time consuming operation and its desired to create a balance.


4) JVM debug options JVM options for remote debugging

-Xdebug -Xnoagent 
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000


to read more about remote debugging check How to Setup Java remote debugging in Eclipse and 10 Java debugging tips in Eclipse 

5) JVM options related to profiling

-Xprof
-Xrunhprof


6) JVM options related to java classpathXbootclasspath specifies classpath entries you want loaded without verification. The JVM verifies all classes it loads to ensure they don't try to dereference an object with an int, pop extra entries off the stack or push too many, and so on. This verification is part of the reason why the JVM is very stable, but it's also rather costly, and responsible for a large part of start up delay. Putting classes on the bootclasspath skips this cost, but should only be used when you know the classes have been verified many times before. In JRuby, this reduced startup time by half or more for a simple script. The 

-Xbootclasspath
 option can be used to either prepend (/p) or append (/a) resources to the bootstrap classpath.



7) JVM options to change  Perm Gen SizeThese JVM optiosn are quite useful to solve java.lang.OutOfMemoryError:Perm Gen Space.

-XX:PermSize and MaxPermSize
-XX:NewRatio=2  Ratio of new/old generation sizes.-
XX:MaxPermSize=64m     Size of the Permanent Generation.


8) JVM parameters to trace classloading and unloading

-XX:+TraceClassLoading 
-XX:+TraceClassUnloading

are two JVM options which we use to print logging information whenever classes loads into JVM or unloads from JVM. These JVM flags are extremely useful if you have any memory leak related to classloader and or suspecting that classes are not unloading or garbage collected.

9) JVM switches related to logging

-XX:+TraceClassLoading 
-XX:+TraceClassUnloading

print information class loads and unloads. Useful for investigating if you have a class leak or if old classes (like JITed Ruby methods in JRuby) are getting collected or not. 

-XX:+PrintCompilation

prints out the name of each Java method Hotspot decides to JIT compile. The list will usually show a bunch of core Java class methods initially, and then turn to methods in your application. 

10) JVM Switches for debugging purpose

-XX:HeapDumpPath=./java_pid.hprof  Path to directory or file name for heap dump.
-XX:-PrintConcurrentLocks       Print java.util.concurrent locks in Ctrl-Break thread dump.
-XX:-PrintCommandLineFlags   Print flags that appeared on the command line.

Test

// Testing Parameter
-verbose:gc
-Xms20M
-Xmx20M
-Xmn10M
-XX:+HeapDumpOnOutOfMemoryError
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:SurvivorRatio=8
-XX:MaxTenuringThreshold=1
-XX:+PrintTenuringDistribution
-XX:+UseSerialGC
-Xloggc:filePath/filename 
//relative path ../gc.log
//abs path: c://gc.log

example

-Xloggc:../gc.log       //logs
-XX:+PrintVMOptions     //
-XX:+UseConcMarkSweepGC //Full GC
-XX:+UseParNewGC        //设置年轻代为并行收集
-XX:+ExplicitGCInvokesConcurrent
-XX:+CMSParallelRemarkEnabled
-XX:NewRatio=3
-XX:SurvivorRatio=8
-XX:PermSize=256m
-XX:CMSInitiatingOccupancyFraction=70   //when to triger GC
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintTenuringDistribution
-XX:+HeapDumpOnOutOfMemoryError 
-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider //turn on epoll


转载于:https://my.oschina.net/u/1767744/blog/298408

[omm@lm2hdp03 bin]$ ./start-cluster.sh Starting cluster. [ERROR] The execution result is empty. [ERROR] Could not get JVM parameters and dynamic configurations properly. [ERROR] Raw output from BashJavaUtils: OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080200000, 1404043264, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 1404043264 bytes for committing reserved memory. # An error report file with more information is saved as: # /opt/gcytest/flink-1.17.1/bin/hs_err_pid30333.log Warning: Permanently added 'lm2hdp01,10.100.40.200' (ECDSA) to the list of known hosts. [INFO] 1 instance(s) of taskexecutor are already running on lm2hdp01. Starting taskexecutor daemon on host lm2hdp01. Warning: Permanently added 'lm2hdp02,10.100.40.202' (ECDSA) to the list of known hosts. [INFO] 1 instance(s) of taskexecutor are already running on lm2hdp02. Starting taskexecutor daemon on host lm2hdp02. Warning: Permanently added 'lm2hdp03,10.100.40.209' (ECDSA) to the list of known hosts. [ERROR] Could not get JVM parameters and dynamic configurations properly. [ERROR] Raw output from BashJavaUtils: OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080200000, 1404043264, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 1404043264 bytes for committing reserved memory. # An error report file with more information is saved as: # /home/omm/hs_err_pid32379.log
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值