Java HotSpot VM

来源:互联网 发布:沪昆高铁质量 知乎 编辑:程序博客网 时间:2024/06/06 16:34

(本文JDK版本

JDK 7 and earlier releases

Oracle官网有相关Reference

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


SUN的JDK版本从1.3.1开始使用HotSpot虚拟机技术。

HotSpot是较新的Java虚拟机技术,用来代替JIT(Just in Time)技术,可以大大提高Java运行的性能。

Java原先是把源代码编译为字节码在虚拟机执行,这样执行速度较慢。而该技术将常用的部分代码编译为本地(原生,native)代码,这样

显著提高了性能。

用于服务器版和标准版的HotSpot有所不同。

其他的Java虚拟机也有类似的技术。

HotSpot JVM 参数可以分为标准参数(standard options)和非标准参数(non-standard options)。

标准参数相对稳定,在JDK未来的版本里不会有太大的改动。
非标准参数则有因升级JDK而改变的可能。

java启动参数共分为三类(其中非标准又分为-X和-XX);
其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容;
其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足,且不保证向后兼容;
其三是非Stable参数(-XX),此类参数各个jvm实现会有所不同,将来可能会随时取消,需要慎重使用;




标准参数:
-client

  使用Java HotSpot 客户端版VM。

-server
  使用Java HotSpot 服务器版VM。如果是64位的JDK,默认只有server版,所以以上两个参数对64位版本JDK无效。


JDK包括2个JVM的实现
   Java HotSpot Client VM(-client),为在客户端环境中减少启动时间而优化;
   Java HotSpot Server VM(-server),为在服务器环境中最大化程序执行速度而设计.

比较:Server VM启动比Client VM慢,运行比Client VM快.

如何将VM设置成 Server VM:
   找到 [jre安装目录]/lib/i386/jvm.cfg 文件
   里面第一行写的是 -client 默认就是client版本,把第二行的-server KNOWN 放到
   第一行,如下面所示
   代码
  -server KNOWN
  -client KNOWN
  -hotspot ALIASED_TO -client
  -classic WARN
  -native ERROR
  -green ERROR

-agentlib: libname [=options]
  加载本地代理函数库, e.g.
  -agentlib:jdwp=help

-agentpath :pathname [=options]
  使用给定的路径加载本地代理库。

-classpath classpath
-cp classpath
  不用说了。

-Dproperty =value
  设置一个系统属性。

-d32
-d64

  要求程序在32位或64位下跑,未来这个参数可能有变。

-enableassertions [:<package name>"..." | :<class name> ]
-ea [:<package name>"..." | :<class name> ]
  开启断言。

-disableassertions [:<package name>"..." | :<class name> ]
-da [:<package name>"..." | :<class name> ]
  关闭断言。

-enablesystemassertions
- esa

  启动所有系统类的断言。


-disablesystemassertions
-dsa

  关闭所有系统类的断言。

-jar
  这个也没什么说的。

-javaagent :jarpath [=options]
  加载Java 程序语言代理

-verbose:class
  输出每个加载的类详细信息。

-verbose:gc
  输出GC的详细信息。

-verbose:jni
  输出本地方法接口的调用信息。

-version
-help
-?

  不用说了。

-X
  显示可用的非标准参数



非标准参数:

-Xint

  以解释模式运行。JVM不会使用HotSpot的新特性,不会将部分常用代码编译为本地代码,所有代码都以字节码的方式解释运行。你可以理解为使用JDK1.3.1以前的JIT方式运行程序。

-Xbatch
  不使用后台编译。

-Xbootclasspath:bootclasspath
  使用bootstrap classloader 加载指定路径的class或jar,这是种完全覆盖默认系统类加载的方案,慎用。

-Xbootclasspath/a:bootclasspath
  将指定的classpath追加到默认的bootclasspath的后面加载

-Xbootclasspath/p:bootclasspath
  将指定的classpath追加到默认的bootclasspath的前面加载

-Xcheck:jni
  在调用JNI函数时做额外的检查。这个参数会降低JVM的执行性能。

-Xfuture
  执行严格的class文件格式检查,不加这个参数,默认使用JDK1.1.* 版本的class格式检查方法。

-Xnoclassgc
  禁用class垃圾收集。

-Xincgc
  开启增量垃圾收集机制。默认为关闭。增量垃圾收集能减少因垃圾收集而引起的程序中断,它会在程序运行期间不定期地以并发的方式运行,在运行期间不会引起中断但是会减少分配给程序的cpu资源。

-Xloggc:file
  GC详情日志。效果如-verbose:gc ,不过这个可以输出到一个文件。除了-verbose:gc包含的信息,还有显示发生的时间。 文件可以是远程的,但是考虑到网络延迟会引起JVM中断,一般建议使用本地文件,

-Xms
  分配的堆空间初始值:
  -Xms6291456
  -Xms6144k
  -Xms6m

-Xmx
  分配的堆空间最大值:
  -Xmx83886080
  -Xmx81920k
  -Xmx80m

-Xmn

设置年轻代大小。整个堆大小=年轻代大小 + 年老代大小 + 持久代大小。持久代一般固定大小为64m,所以增大年轻代后,将会减小年老代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8

-Xmn200m


-Xprof
  在运行程序时给出分析数据。适用于开发环境,不适用于生产环境。

-Xrs
  减少JVM的操作系统信号的使用量。

-Xss

设置每个线程的堆栈大小。JDK5.0以后每个线程堆栈大小为1M,以前每个线程堆栈大小为256K。更具应用的线程所需内存大小进行调整。在相同物理内存下,减小这个值能生成更多的线程。但是操作系统对一个进程内的线程数还是有限制的,不能无限生成,经验值在3000~5000左右。



非标准-XX参数

 

有三种-XX参数的形式:

 

  • Boolean 型的参数 开启如 -XX:+<option> 关闭如 -XX:-<option>.
  • Numeric 型参数 -XX:<option>=<number>. 数字可以包括单位 'm' 或 'M' 代表MB, 'k' or 'K' 代表KB, 'g' or 'G' 代表 GB ,没有单位意味着bytes。
  • String 参数 -XX:<option>=<string>

以下是-XX参数列表,本来想都翻译过来,但是发现一些技术术语如果硬是翻译可能会导致词不达意,因此大部分描述都保持原文。

 

 

参数名和默认值描述-XX:-AllowUserSignalHandlers允许使用用户自定义的信号处理器 (只对应Solaris和Linux)-XX:AltStackSize=16384修改栈容量 (单位 Kb) (对应Solaris, JDK 5.0以后弃用)-XX:-DisableExplicitGC禁止手动调用System.gc()-XX:+FailOverToOldVerifier如果新的类型校验器验证失败使用旧版本的类型校验器 (开始于JDK6.)-XX:+HandlePromotionFailureThe youngest generation collection does not require a guarantee of full promotion of all live objects. (Introduced in 1.4.2 update 11) [5.0 and earlier: false.]-XX:+MaxFDLimit将文件描述符加到最大 (对应Solaris)-XX:PreBlockSpin=10Spin count variable for use with -XX:+UseSpinning. Controls the maximum spin iterations allowed before entering operating system thread synchronization code. (Introduced in 1.4.2.)-XX:-RelaxAccessControlCheck放宽类型校验机的准入控制(JDK6)-XX:+ScavengeBeforeFullGC在full GC之前先做年轻代GC (开始于JDK1.4.1.)-XX:+UseAltSigsUse alternate signals instead of SIGUSR1 and SIGUSR2 for VM internal signals. (Introduced in 1.3.1 update 9, 1.4.1. Relevant to Solaris only.)-XX:+UseBoundThreadsBind user level threads to kernel threads. (Relevant to Solaris only.)-XX:-UseConcMarkSweepGC使用并发的mark-sweep GC收集年老代 (始于JDK1.4.1)-XX:+UseGCOverheadLimit使用一种限制VM做GC操作的时间所占比例过高的策略 (始于JDK6.)-XX:+UseLWPSynchronization使用轻量级进程同步替代线程同步 (始于JDK1.4.0. Solaris相关)-XX:-UseParallelGC使用并发平行GC(始于JDK1.4.1)-XX:-UseParallelOldGC使用并发平行GC做 full GC. (始于JDK5.0 update 6.)-XX:-UseSerialGC使用串行GC (始于JDK5.0.)-XX:-UseSpinningEnable naive spinning on Java monitor before entering operating system thread synchronizaton code. (Relevant to 1.4.2 and 5.0 only.) [1.4.2, multi-processor Windows platforms: true]-XX:+UseTLABUse thread-local object allocation (Introduced in 1.4.0, known as UseTLE prior to that.) [1.4.2 and earlier, x86 or with -client: false]-XX:+UseSplitVerifierUse the new type checker with StackMapTable attributes. (Introduced in 5.0.)[5.0: false]-XX:+UseThreadPrioritiesUse native thread priorities.-XX:+UseVMInterruptibleIOThread interrupt before or with EINTR for I/O operations results in OS_INTRPT. (Introduced in 6. Relevant to Solaris only.)

 

 

 

参数名和默认值描述-XX:+AggressiveOptsTurn on point performance compiler optimizations that are expected to be default in upcoming releases. (Introduced in 5.0 update 6.)-XX:CompileThreshold=10000Number of method invocations/branches before compiling [-client: 1,500]-XX:LargePageSizeInBytes=4mSets the large page size used for the Java heap. (Introduced in 1.4.0 update 1.) [amd64: 2m.]-XX:MaxHeapFreeRatio=70Maximum percentage of heap free after GC to avoid shrinking.-XX:MaxNewSize=sizeMaximum size of new generation (in bytes). Since 1.4, MaxNewSize is computed as a function of NewRatio. [1.3.1 Sparc: 32m; 1.3.1 x86: 2.5m.]-XX:MaxPermSize=64mSize of the Permanent Generation.  [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.]-XX:MinHeapFreeRatio=40Minimum percentage of heap free after GC to avoid expansion.-XX:NewRatio=2Ratio of new/old generation sizes. [Sparc -client: 8; x86 -server: 8; x86 -client: 12.]-client: 4 (1.3) 8 (1.3.1+), x86: 12]-XX:NewSize=2.125mDefault size of new generation (in bytes) [5.0 and newer: 64 bit VMs are scaled 30% larger; x86: 1m; x86, 5.0 and older: 640k]-XX:ReservedCodeCacheSize=32mReserved code cache size (in bytes) - maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 48m; in 1.5.0_06 and earlier, Solaris 64-bit and and64: 1024m.]-XX:SurvivorRatio=8Ratio of eden/survivor space size [Solaris amd64: 6; Sparc in 1.3.1: 25; other Solaris platforms in 5.0 and earlier: 32]-XX:TargetSurvivorRatio=50Desired percentage of survivor space used after scavenge.-XX:ThreadStackSize=512Thread Stack Size (in Kbytes). (0 means use default stack size) [Sparc: 512; Solaris x86: 320 (was 256 prior in 5.0 and earlier); Sparc 64 bit: 1024; Linux amd64: 1024 (was 0 in 5.0 and earlier); all others 0.]-XX:+UseBiasedLockingEnable biased locking. For more details, see this tuning example . (Introduced in 5.0 update 6.) [5.0: false]-XX:+UseFastAccessorMethodsUse optimized versions of Get<Primitive>Field.-XX:-UseISMUse Intimate Shared Memory. [Not accepted for non-Solaris platforms.] For details, seeIntimate Shared Memory .-XX:+UseLargePagesUse large page memory. (Introduced in 5.0 update 5.) For details, see Java Support for Large Memory Pages .-XX:+UseMPSSUse Multiple Page Size Support w/4mb pages for the heap. Do not use with ISM as this replaces the need for ISM. (Introduced in 1.4.0 update 1, Relevant to Solaris 9 and newer.) [1.4.1 and earlier: false]-XX:+StringCacheEnables caching of commonly allocated strings.-XX:AllocatePrefetchLines=1Number of cache lines to load after the last object allocation using prefetch instructions generated in JIT compiled code. Default values are 1 if the last allocated object was an instance and 3 if it was an array.-XX:AllocatePrefetchStyle=1Generated code style for prefetch instructions.
0 - no prefetch instructions are generate*d*,
1 - execute prefetch instructions after each allocation,
2 - use TLAB allocation watermark pointer to gate when prefetch instructions are executed.

 

 

参数名和默认值描述-XX:-CITimePrints time spent in JIT Compiler. (Introduced in 1.4.0.)-XX:ErrorFile=./hs_err_pid<pid>.logIf an error occurs, save the error data to this file. (Introduced in 6.)-XX:-ExtendedDTraceProbesEnable performance-impacting dtrace probes. (Introduced in 6. Relevant to Solaris only.)-XX:HeapDumpPath=./java_pid<pid>.hprofPath to directory or filename for heap dump. Manageable . (Introduced in 1.4.2 update 12, 5.0 update 7.)-XX:-HeapDumpOnOutOfMemoryErrorDump heap to file when java.lang.OutOfMemoryError is thrown. Manageable . (Introduced in 1.4.2 update 12, 5.0 update 7.)-XX:OnError="<cmd args>;<cmd args>"Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.)-XX:OnOutOfMemoryError="<cmd args>;
<cmd args>"Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6)-XX:-PrintClassHistogramPrint a histogram of class instances on Ctrl-Break. Manageable . (Introduced in 1.4.2.) Thejmap -histo command provides equivalent functionality.-XX:-PrintConcurrentLocksPrint java.util.concurrent locks in Ctrl-Break thread dump. Manageable . (Introduced in 6.) Thejstack -l command provides equivalent functionality.-XX:-PrintCommandLineFlagsPrint flags that appeared on the command line. (Introduced in 5.0.)-XX:-PrintCompilationPrint message when a method is compiled.-XX:-PrintGCPrint messages at garbage collection. Manageable .-XX:-PrintGCDetailsPrint more details at garbage collection. Manageable . (Introduced in 1.4.0.)-XX:-PrintGCTimeStampsPrint timestamps at garbage collection. Manageable (Introduced in 1.4.0.)-XX:-PrintTenuringDistributionPrint tenuring age information.-XX:-TraceClassLoadingTrace loading of classes.-XX:-TraceClassLoadingPreorderTrace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)-XX:-TraceClassResolutionTrace constant pool resolutions. (Introduced in 1.4.2.)-XX:-TraceClassUnloadingTrace unloading of classes.-XX:-TraceLoaderConstraintsTrace recording of loader constraints. (Introduced in 6.)-XX:+PerfSaveDataToFileSaves jvmstat binary data on exit.

 

 

0 0
原创粉丝点击