jvm總結

        Java程序經過編譯生成class文件,生成的class文件經過JVM(Java Virtual Machine)來運行,JVM在執行Java程序的過程當中會把它所管理的內存劃分爲若干個不一樣的數據區域,Java虛擬機所管理的內存將會包括如下幾個運行時數據區域。html

運行時數據區域java

 

程序計數器(Program Counter Register)node

       學過《計算機組成原理》的人對於這個名詞都不會感到陌生,PC指向當前執行的指令地址。在JVM中,也能夠這麼理解,根據PC值選取將要執行的指令。JVM的多線程是經過線程輪流切換並根據CPU時間分片的方式來實現,任什麼時候刻,一個處理器只會執行一條線程中的指令。每條線程都須要有一個獨立的程序計數器,各條線程之間的計數器互不影響,獨立存儲,這類內存區域爲「線程私有」的內存。Java中有兩種方法:Java方法和本地方法。若是線程正在執行的是一個Java 方法,這個計數器記錄的是正在執行的指令地址;若是正在執行的是Natvie 方法,這個計數器值爲空(Undefined)。算法

本地方法棧(Native Method Stack)windows

       Java本地方法(Native Method)是由其它語言編寫的,編譯成和處理器相關的機器代碼,保存在動態連接庫中,即.dll(windows系統)文件中,格式是各個平臺專有的。雖然說Java方法是與平臺無關的,可是本地方法不是。程序運行中Java方法調用本地方法時,JVM裝載包含這個本地方法的動態庫的,並調用這個方法。經過本地方法,Java程序能夠直接訪問底層操做系統的資源,若是你這樣用,你的程序就變成平臺相關了,由於本地方法的動態庫是與平臺相關的,可是使用本地方法還可能把程序變得和特定的Java平臺實現相關。
        本地方法棧與虛擬機棧(後面介紹)做用相似,Sun HotSpot中直接將本地方法棧和虛擬機棧合二爲一,它和虛擬機棧同樣都會拋出StackOverflowError和OutOfMemoryError異常。數組

方法區(Method Area)服務器

      方法區是各個內存所共享的內存空間, 方法區中主要存放被JVM加載的類信息、常量、靜態變量、即時編譯後的代碼等數據。常把方法區成爲永久代(據說不嚴謹),方法區的大小用戶能夠更改,若是發生溢出會出現java.lang.OutOfMemoryError:PermGen space信息。多線程

運行時常量併發

 

      運行時常量是方法區的一部分。Class文件有一個常量池用來存放編譯器生成的各類字面量和符號引用,這部份內容在類加載後存放到方法區的運行時常量池中。
      運行時常量池相對於Class 文件常量池的另一個重要特徵是具有動態性,Java 語言並不要求常量必定只能在編譯期產生,也就是並不是預置入Class 文件中常量池的內容才能進入方法區運行時常量池,運行期間也可能將新的常量放入池中。oracle

虛擬機棧(VM Stack)

       從圖中能夠看出,JVM的棧中存放的數據主要有:
1.各類基礎數據類型(boolean、byte、char 、short、int、float、long、double );
2.方法的形式參數,方法調用完後從棧空間回收;
3.引用對象的地址,引用完後,棧空間地址當即被回收,堆空間等待GC。
       JVM的棧也屬於線程私有的內存,用戶能夠設置大小,後面會講到。對於異常,這塊區域有兩種狀況:若是線程請求的棧深度大於JVM所容許的深度,將拋出StackOverflowError異常;若是JVM的棧能夠動態擴展,可是在嘗試擴展時沒法申請到足夠的內存則拋出OutOfMemoryError異常。

堆(Heap)

      Java 堆是JVM所管理的內存中最大的一塊而且是全部線程共享的內存區域,在JVM啓動時建立。堆存放的就是存放對象實例和數組,幾乎全部的對象實例都在這裏分配內存。Java堆是垃圾回收器管理的主要區域,後面將詳細介紹。若是在堆中沒有內存完成實例分配,而且堆也沒法再擴展時,將會拋出OutOfMemoryError 異常。

直接內存

       直接內存並非虛擬機運行時數據區的一部分,也不是JVM規範中定義的內存區域,可是這部份內存也被頻繁地使用,並且也可能致使OutOfMemoryError 異常出現。
         爲了提升IO速度,在JDK 1.4 中新加入了NIO(New Input/Output)類,引入了一種基於通道(Channel)與緩衝區(Buffer)的I/O 方式,它可使用Native 函數庫直接分配堆外內存,而後經過一個存儲在Java 堆裏面的DirectByteBuffer 對象做爲這塊內存的引用進行操做。這樣能在一些場景中顯著提升性能,由於避免了在Java 堆和Native 堆中來回複製數據。顯然,本機直接內存的分配不會受到Java 堆大小的限制,可是,既然是內存,則確定仍是會受到本機總內存(包括RAM 及SWAP 區或者分頁文件)的大小及處理器尋址空間的限制。服務器管理員配置虛擬機參數時,通常會根據實際內存設置-Xmx等參數信息,但常常會忽略掉直接內存,使得各個內存區域的總和大於物理內存限制(包括物理上的和操做系統級的限制),從而致使動態擴展時出現OutOfMemoryError異常。

堆的分代以及垃圾回收

        如今的垃圾回收器都採用分代收集算法,堆分代的惟一理由就是優化GC性能,若是沒有分代,那麼全部的對象都在一塊,GC的時候要找到哪些對象沒用,這樣就會對堆的全部區域進行掃描。而不少對象都是朝生夕死的,若是分代的話,把新建立的對象放到某一地方,當GC的時候先把這塊存「朝生夕死」對象的區域進行回收,這樣就會騰出很大的空間出來。
        堆能夠細分爲年輕代與年老代,而且年輕代還分爲了三部分:1個Eden區和2個Survivor區(分別叫From和To),默認比例爲8:1。通常狀況下,新建立的對象都會被分配到Eden區(大對象直接分配到年老代),這些對象通過第一次Minor GC後,若是仍然存活,將會被移到Survivor區。對象在Survivor區中每通過一次Minor GC,年齡就會增長1歲,當它的年齡增長到必定程度時,就會被移動到年老代中。

        IBM公司的專門研究代表,年輕代中98%的對象是朝生夕死的,所以在年輕代的垃圾回收算法使用的是複製算法,複製算法的基本思想就是將內存分爲兩塊,每次只用其中一塊,當這一塊內存用完,就將還活着的對象複製到另一塊上面,而後再把已使用過的內存空間一次清理掉。這樣使得每次都對整個半區進行內存回收,分配時不用考慮碎片的狀況。

複製算法

       在GC開始的時候,存在對象於Eden區和名爲「From」的Survivor區,Survivor區「To」是空的。緊接着進行GC,Eden區中全部存活的對象都會被複制到「To」,而在「From」區中,仍存活的對象會根據他們的年齡值來決定去向。年齡達到必定值(年齡閾值,能夠經過-XX:MaxTenuringThreshold來設置)的對象會被移動到年老代中,沒有達到閾值的對象會被複制到「To」區域。通過此次GC後,Eden區和From區已經被清空。這個時候,「From」和「To」會交換他們的角色,也就是新的「To」就是上次GC前的「From」,新的「From」就是上次GC前的「To」。無論怎樣,都會保證名爲To的Survivor區域是空的。Minor GC會一直重複這樣的過程,直到「To」區被填滿,「To」區被填滿以後,會將全部對象移動到年老代中。Eden區和Survivor區並非按照1:1的比例來劃份內存空間的,當Survivor空間不夠用時,須要依賴老年代的空間來進行分配。

        年輕代採用複製算法,這種算法在對象存活率較高時就要進行較多的複製操做,效率將變低。更關鍵的是,若是不想浪費50%的空間,就須要有額外的空間進行分配,以應對一些極端狀況,因此這種算法對於年老代不適用。對於年老代,採用「標記-清除」或者「標記-整理」算法進行回收。「標記-清除」算法分爲兩個過程:標記的過程其實就是,遍歷全部的GC Roots,而後將全部GC Roots可達的對象標記爲存活的對象;清除的過程將遍歷堆中全部的對象,將沒有標記的對象所有清除掉。下圖表示「標記-清除」算法。

「標記-清除」算法

        「標記-整理」算法前期跟「標記-清除」算法同樣,但後續的整理步驟不是直接對可回收對象進行清理,而是讓全部存活的對象都向一端移動,而後直接清理掉端邊界之外的內存。     

「標記-整理」算法

JVM堆棧大小以及一些參數設置

        JVM 中設置堆大小有三方面限制:操做系統位數(32位、64位)限制;可用虛擬內存限制;可用物理內存限制。32位系統下,通常限制在1.5G~2G;64位操做系統無限制。下面舉例說明:
java -Xmx3550m -Xms3550m -Xmn2g -Xss128k
-Xmx3550m:設置JVM最大可用內存爲3550M。
-Xms3550m:設置JVM初始內存爲3550m。此值能夠設置與-Xmx相同,以免每次垃圾回收完成後JVM從新分配內存。
-Xmn2g:設置年輕代大小爲2G。持久代通常固定大小爲64m,因此增大年輕代後,將會減少年老代大小。此值對系統性能影響較大,Sun官方推薦配置爲整個堆的3/8。
-Xss128k:設置每一個線程的棧大小。JDK5.0之後每一個線程堆棧大小爲1M,之前每一個線程堆棧大小爲256K。
java -Xmx3550m -Xms3550m -Xss128k -XX:NewRatio=2 -XX:SurvivorRatio=8 -XX:MaxPermSize=16m -XX:MaxTenuringThreshold=3
-XX:NewRatio=2:設置年老代與年輕代(包括Eden和兩個Survivor區)的比值(除去持久代)。設置爲2,則年輕代與年老代所佔比值爲1:2,年輕代佔整個堆棧的1/3。Xms=Xmx而且設置了Xmn的狀況下,該參數不須要進行設置。
-XX:SurvivorRatio=8:設置年輕代中Eden區與Survivor區的大小比值。設置爲8,則兩個Survivor區與一個Eden區的比值爲2:8,一個Survivor區佔整個年輕代的1/10。
-XX:MaxPermSize=16m:設置持久代最大值爲16m。
-XX:MaxTenuringThreshold=3:設置垃圾最大年齡爲3,即對象在Survivor區存在的年齡爲3(複製一次年齡+1)。若是設置爲0的話,則年輕代對象不通過Survivor區,直接進入年老代。 對於年老代比較多的應用,能夠提升效率。若是將此值設置爲一個較大值,則年輕代對象會在Survivor區進行屢次複製,這樣能夠增長對象再年輕代的存活 時間,增長在年輕代即被回收的機率該參數只有在串行GC時纔有效。

 

附 JVM參數的含義(轉)

參數名稱 含義 默認值  
-Xms 初始堆大小 物理內存的1/64(<1GB) 默認(MinHeapFreeRatio參數能夠調整)空餘堆內存小於40%時,JVM就會增大堆直到-Xmx的最大限制.
-Xmx 最大堆大小 物理內存的1/4(<1GB) 默認(MaxHeapFreeRatio參數能夠調整)空餘堆內存大於70%時,JVM會減小堆直到 -Xms的最小限制
-Xmn 年輕代大小(1.4or lator)   注意:此處的大小是(eden+ 2 survivor space).與jmap -heap中顯示的New gen是不一樣的。
整個堆大小=年輕代大小 + 年老代大小 + 持久代大小.
增大年輕代後,將會減少年老代大小.此值對系統性能影響較大,Sun官方推薦配置爲整個堆的3/8
-XX:NewSize 設置年輕代大小(for 1.3/1.4)    
-XX:MaxNewSize 年輕代最大值(for 1.3/1.4)    
-XX:PermSize 設置持久代(perm gen)初始值 物理內存的1/64  
-XX:MaxPermSize 設置持久代最大值 物理內存的1/4  
-Xss 每一個線程的堆棧大小   JDK5.0之後每一個線程堆棧大小爲1M,之前每一個線程堆棧大小爲256K.更具應用的線程所需內存大小進行 調整.在相同物理內存下,減少這個值能生成更多的線程.可是操做系統對一個進程內的線程數仍是有限制的,不能無限生成,經驗值在3000~5000左右
通常小的應用, 若是棧不是很深, 應該是128k夠用的 大的應用建議使用256k。這個選項對性能影響比較大,須要嚴格的測試。(校長)
和threadstacksize選項解釋很相似,官方文檔彷佛沒有解釋,在論壇中有這樣一句話:"」
-Xss is translated in a VM flag named ThreadStackSize」
通常設置這個值就能夠了。
-XX:ThreadStackSize Thread Stack Size   (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:NewRatio 年輕代(包括Eden和兩個Survivor區)與年老代的比值(除去持久代)   -XX:NewRatio=2表示年輕代與年老代所佔比值爲1:2,年輕代佔整個堆棧的1/3
Xms=Xmx而且設置了Xmn的狀況下,該參數不須要進行設置。
-XX:SurvivorRatio Eden區與Survivor區的大小比值   設置爲8,則兩個Survivor區與一個Eden區的比值爲2:8,一個Survivor區佔整個年輕代的1/10
-XX:LargePageSizeInBytes 內存頁的大小不可設置過大, 會影響Perm的大小   =128m
-XX:+UseFastAccessorMethods 原始類型的快速優化    
-XX:+DisableExplicitGC 關閉System.gc()   這個參數須要嚴格的測試
-XX:MaxTenuringThreshold 垃圾最大年齡   若是設置爲0的話,則年輕代對象不通過Survivor區,直接進入年老代. 對於年老代比較多的應用,能夠提升效率.若是將此值設置爲一個較大值,則年輕代對象會在Survivor區進行屢次複製,這樣能夠增長對象再年輕代的存活 時間,增長在年輕代即被回收的機率
該參數只有在串行GC時纔有效.
-XX:+AggressiveOpts 加快編譯    
-XX:+UseBiasedLocking 鎖機制的性能改善    
-Xnoclassgc 禁用垃圾回收    
-XX:SoftRefLRUPolicyMSPerMB 每兆堆空閒空間中SoftReference的存活時間 1s softly reachable objects will remain alive for some amount of time after the last time they were referenced. The default value is one second of lifetime per free megabyte in the heap
-XX:PretenureSizeThreshold 對象超過多大是直接在舊生代分配 0 單位字節 新生代採用Parallel Scavenge GC時無效
另外一種直接在舊生代分配的狀況是大的數組對象,且數組中無外部引用對象.
-XX:TLABWasteTargetPercent TLAB佔eden區的百分比 1%  
-XX:+CollectGen0First FullGC時是否先YGC false  

並行收集器相關參數

-XX:+UseParallelGC Full GC採用parallel MSC
(此項待驗證)
 

選擇垃圾收集器爲並行收集器.此配置僅對年輕代有效.即上述配置下,年輕代使用併發收集,而年老代仍舊使用串行收集.(此項待驗證)

-XX:+UseParNewGC 設置年輕代爲並行收集   可與CMS收集同時使用
JDK5.0以上,JVM會根據系統配置自行設置,因此無需再設置此值
-XX:ParallelGCThreads 並行收集器的線程數   此值最好配置與處理器數目相等 一樣適用於CMS
-XX:+UseParallelOldGC 年老代垃圾收集方式爲並行收集(Parallel Compacting)   這個是JAVA 6出現的參數選項
-XX:MaxGCPauseMillis 每次年輕代垃圾回收的最長時間(最大暫停時間)   若是沒法知足此時間,JVM會自動調全年輕代大小,以知足此值.
-XX:+UseAdaptiveSizePolicy 自動選擇年輕代區大小和相應的Survivor區比例   設置此選項後,並行收集器會自動選擇年輕代區大小和相應的Survivor區比例,以達到目標系統規定的最低相應時間或者收集頻率等,此值建議使用並行收集器時,一直打開.
-XX:GCTimeRatio 設置垃圾回收時間佔程序運行時間的百分比   公式爲1/(1+n)
-XX:+ScavengeBeforeFullGC Full GC前調用YGC true Do young generation GC prior to a full GC. (Introduced in 1.4.1.)

CMS相關參數

-XX:+UseConcMarkSweepGC 使用CMS內存收集   測試中配置這個之後,-XX:NewRatio=4的配置失效了,緣由不明.因此,此時年輕代大小最好用-Xmn設置.???
-XX:+AggressiveHeap     試圖是使用大量的物理內存
長時間大內存使用的優化,能檢查計算資源(內存, 處理器數量)
至少須要256MB內存
大量的CPU/內存, (在1.4.1在4CPU的機器上已經顯示有提高)
-XX:CMSFullGCsBeforeCompaction 多少次後進行內存壓縮   因爲併發收集器不對內存空間進行壓縮,整理,因此運行一段時間之後會產生"碎片",使得運行效率下降.此值設置運行多少次GC之後對內存空間進行壓縮,整理.
-XX:+CMSParallelRemarkEnabled 下降標記停頓    
-XX+UseCMSCompactAtFullCollection 在FULL GC的時候, 對年老代的壓縮   CMS是不會移動內存的, 所以, 這個很是容易產生碎片, 致使內存不夠用, 所以, 內存的壓縮這個時候就會被啓用。 增長這個參數是個好習慣。
可能會影響性能,可是能夠消除碎片
-XX:+UseCMSInitiatingOccupancyOnly 使用手動定義初始化定義開始CMS收集   禁止hostspot自行觸發CMS GC
-XX:CMSInitiatingOccupancyFraction=70 使用cms做爲垃圾回收
使用70%後開始CMS收集
92 爲了保證不出現promotion failed(見下面介紹)錯誤,該值的設置須要知足如下公式CMSInitiatingOccupancyFraction計算公式
-XX:CMSInitiatingPermOccupancyFraction 設置Perm Gen使用到達多少比率時觸發 92  
-XX:+CMSIncrementalMode 設置爲增量模式   用於單CPU狀況
-XX:+CMSClassUnloadingEnabled      

輔助信息

-XX:+PrintGC    

輸出形式:

[GC 118250K->113543K(130112K), 0.0094143 secs]
[Full GC 121376K->10414K(130112K), 0.0650971 secs]

-XX:+PrintGCDetails    

輸出形式:[GC [DefNew: 8614K->781K(9088K), 0.0123035 secs] 118250K->113543K(130112K), 0.0124633 secs]
[GC [DefNew: 8614K->8614K(9088K), 0.0000665 secs][Tenured: 112761K->10414K(121024K), 0.0433488 secs] 121376K->10414K(130112K), 0.0436268 secs]

-XX:+PrintGCTimeStamps      
-XX:+PrintGC:PrintGCTimeStamps     可與-XX:+PrintGC -XX:+PrintGCDetails混合使用
輸出形式:11.851: [GC 98328K->93620K(130112K), 0.0082960 secs]
-XX:+PrintGCApplicationStoppedTime 打印垃圾回收期間程序暫停的時間.可與上面混合使用   輸出形式:Total time for which application threads were stopped: 0.0468229 seconds
-XX:+PrintGCApplicationConcurrentTime 打印每次垃圾回收前,程序未中斷的執行時間.可與上面混合使用   輸出形式:Application time: 0.5291524 seconds
-XX:+PrintHeapAtGC 打印GC先後的詳細堆棧信息    
-Xloggc:filename 把相關日誌信息記錄到文件以便分析.
與上面幾個配合使用
   

-XX:+PrintClassHistogram

garbage collects before printing the histogram.    
-XX:+PrintTLAB 查看TLAB空間的使用狀況    
XX:+PrintTenuringDistribution 查看每次minor GC後新的存活週期的閾值  

Desired survivor size 1048576 bytes, new threshold 7 (max 15)
new threshold 7即標識新的存活週期的閾值爲7。

 


下面的表格是官方文檔(點擊打開oracle官網查看
 

Behavioral Options

 

Option and Default Value Description
-XX:-AllowUserSignalHandlers Do not complain if the application installs signal handlers. (Relevant to Solaris and Linux only.)
-XX:AltStackSize=16384 Alternate signal stack size (in Kbytes). (Relevant to Solaris only, removed from 5.0.)
-XX:-DisableExplicitGC By default calls to System.gc() are enabled (-XX:-DisableExplicitGC). Use -XX:+DisableExplicitGC to disable calls to System.gc(). Note that the JVM still performs garbage collection when necessary.
-XX:+FailOverToOldVerifier Fail over to old verifier when the new type checker fails. (Introduced in 6.)
-XX:+HandlePromotionFailure The 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 Bump the number of file descriptors to max. (Relevant  to Solaris only.)
-XX:PreBlockSpin=10 Spin 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 Relax the access control checks in the verifier. (Introduced in 6.)
-XX:+ScavengeBeforeFullGC Do young generation GC prior to a full GC. (Introduced in 1.4.1.)
-XX:+UseAltSigs Use 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:+UseBoundThreads Bind user level threads to kernel threads. (Relevant to Solaris only.)
-XX:-UseConcMarkSweepGC Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)
-XX:+UseGCOverheadLimit Use a policy that limits the proportion of the VM's time that is spent in GC before an OutOfMemory error is thrown. (Introduced in 6.)
-XX:+UseLWPSynchronization Use LWP-based instead of thread based synchronization. (Introduced in 1.4.0. Relevant to Solaris only.)
-XX:-UseParallelGC Use parallel garbage collection for scavenges. (Introduced in 1.4.1)
-XX:-UseParallelOldGC Use parallel garbage collection for the full collections. Enabling this option automatically sets -XX:+UseParallelGC. (Introduced in 5.0 update 6.)
-XX:-UseSerialGC Use serial garbage collection. (Introduced in 5.0.)
-XX:-UseSpinning Enable 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:+UseTLAB Use 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:+UseSplitVerifier Use the new type checker with StackMapTable attributes. (Introduced in 5.0.)[5.0: false]
-XX:+UseThreadPriorities Use native thread priorities.
-XX:+UseVMInterruptibleIO Thread interrupt before or with EINTR for I/O operations results in OS_INTRPT. (Introduced in 6. Relevant to Solaris only.)

 

Garbage First (G1) Garbage Collection Options

 

Option and Default Value Description
-XX:+UseG1GC Use the Garbage First (G1) Collector
-XX:MaxGCPauseMillis=n Sets a target for the maximum GC pause time. This is a soft goal, and the JVM will make its best effort to achieve it.
-XX:InitiatingHeapOccupancyPercent=n Percentage of the (entire) heap occupancy to start a concurrent GC cycle. It is used by GCs that trigger a concurrent GC cycle based on the occupancy of the entire heap, not just one of the generations (e.g., G1). A value of 0 denotes 'do constant GC cycles'. The default value is 45.
-XX:NewRatio=n Ratio of old/new generation sizes. The default value is 2.
-XX:SurvivorRatio=n Ratio of eden/survivor space size. The default value is 8.
-XX:MaxTenuringThreshold=n Maximum value for tenuring threshold. The default value is 15.
-XX:ParallelGCThreads=n Sets the number of threads used during parallel phases of the garbage collectors. The default value varies with the platform on which the JVM is running.
-XX:ConcGCThreads=n Number of threads concurrent garbage collectors will use. The default value varies with the platform on which the JVM is running.
-XX:G1ReservePercent=n Sets the amount of heap that is reserved as a false ceiling to reduce the possibility of promotion failure. The default value is 10.
-XX:G1HeapRegionSize=n With G1 the Java heap is subdivided into uniformly sized regions. This sets the size of the individual sub-divisions. The default value of this parameter is determined ergonomically based upon heap size. The minimum value is 1Mb and the maximum value is 32Mb.


 

Performance Options

 

Option and Default Value Description
-XX:+AggressiveOpts Turn on point performance compiler optimizations that are expected to be default in upcoming releases. (Introduced in 5.0 update 6.)
-XX:CompileThreshold=10000 Number of method invocations/branches before compiling [-client: 1,500]
-XX:LargePageSizeInBytes=4m Sets the large page size used for the Java heap. (Introduced in 1.4.0 update 1.) [amd64: 2m.]
-XX:MaxHeapFreeRatio=70 Maximum percentage of heap free after GC to avoid shrinking.
-XX:MaxNewSize=size Maximum 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=64m Size 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=40 Minimum percentage of heap free after GC to avoid expansion.
-XX:NewRatio=2 Ratio of old/new generation sizes. [Sparc -client: 8; x86 -server: 8; x86 -client: 12.]-client: 4 (1.3) 8 (1.3.1+), x86: 12]
-XX:NewSize=2m Default 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=32m Reserved code cache size (in bytes) - maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 2048m; in 1.5.0_06 and earlier, Solaris 64-bit and amd64: 1024m.]
-XX:SurvivorRatio=8 Ratio 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=50 Desired percentage of survivor space used after scavenge.
-XX:ThreadStackSize=512 Thread 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:+UseBiasedLocking Enable biased locking. For more details, see thistuning example. (Introduced in 5.0 update 6.) [5.0: false]
-XX:+UseFastAccessorMethods Use optimized versions of Get<Primitive>Field.
-XX:-UseISM Use Intimate Shared Memory. [Not accepted for non-Solaris platforms.] For details, see Intimate Shared Memory.
-XX:+UseLargePages Use large page memory. (Introduced in 5.0 update 5.) For details, see Java Support for Large Memory Pages.
-XX:+UseMPSS Use 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:+UseStringCache Enables caching of commonly allocated strings.
 
-XX:AllocatePrefetchLines=1 Number 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=1 Generated 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:+UseCompressedStrings Use a byte[] for Strings which can be represented as pure ASCII. (Introduced in Java 6 Update 21 Performance Release) 
 
-XX:+OptimizeStringConcat Optimize String concatenation operations where possible. (Introduced in Java 6 Update 20) 
 

 

 

Debugging Options

Option and Default Value Description
-XX:-CITime Prints time spent in JIT Compiler. (Introduced in 1.4.0.)
-XX:ErrorFile=./hs_err_pid<pid>.log If an error occurs, save the error data to this file. (Introduced in 6.)
-XX:-ExtendedDTraceProbes Enable performance-impacting dtrace probes. (Introduced in 6. Relevant to Solaris only.)
-XX:HeapDumpPath=./java_pid<pid>.hprof Path to directory or filename for heap dump.Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)
-XX:-HeapDumpOnOutOfMemoryError Dump 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:-PrintClassHistogram Print a histogram of class instances on Ctrl-Break.Manageable. (Introduced in 1.4.2.) The jmap -histocommand provides equivalent functionality.
-XX:-PrintConcurrentLocks Print java.util.concurrent locks in Ctrl-Break thread dump. Manageable. (Introduced in 6.) The jstack -lcommand provides equivalent functionality.
-XX:-PrintCommandLineFlags Print flags that appeared on the command line. (Introduced in 5.0.)
-XX:-PrintCompilation Print message when a method is compiled.
-XX:-PrintGC Print messages at garbage collection. Manageable.
-XX:-PrintGCDetails Print more details at garbage collection. Manageable. (Introduced in 1.4.0.)
-XX:-PrintGCTimeStamps Print timestamps at garbage collection. Manageable(Introduced in 1.4.0.)
-XX:-PrintTenuringDistribution Print tenuring age information.
-XX:-PrintAdaptiveSizePolicy Enables printing of information about adaptive generation sizing.
-XX:-TraceClassLoading Trace loading of classes.
-XX:-TraceClassLoadingPreorder Trace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)
-XX:-TraceClassResolution Trace constant pool resolutions. (Introduced in 1.4.2.)
-XX:-TraceClassUnloading Trace unloading of classes.
-XX:-TraceLoaderConstraints Trace recording of loader constraints. (Introduced in 6.)
-XX:+PerfDataSaveToFile Saves jvmstat binary data on exit.
-XX:ParallelGCThreads=n Sets the number of garbage collection threads in the young and old parallel garbage collectors. The default value varies with the platform on which the JVM is running.
-XX:+UseCompressedOops Enables the use of compressed pointers (object references represented as 32 bit offsets instead of 64-bit pointers) for optimized 64-bit performance with Java heap sizes less than 32gb.
-XX:+AlwaysPreTouch Pre-touch the Java heap during JVM initialization. Every page of the heap is thus demand-zeroed during initialization rather than incrementally during application execution.
-XX:AllocatePrefetchDistance=n Sets the prefetch distance for object allocation. Memory about to be written with the value of new objects is prefetched into cache at this distance (in bytes) beyond the address of the last allocated object. Each Java thread has its own allocation point. The default value varies with the platform on which the JVM is running.
-XX:InlineSmallCode=n Inline a previously compiled method only if its generated native code size is less than this. The default value varies with the platform on which the JVM is running.
-XX:MaxInlineSize=35 Maximum bytecode size of a method to be inlined.
-XX:FreqInlineSize=n Maximum bytecode size of a frequently executed method to be inlined. The default value varies with the platform on which the JVM is running.
-XX:LoopUnrollLimit=n Unroll loop bodies with server compiler intermediate representation node count less than this value. The limit used by the server compiler is a function of this value, not the actual value. The default value varies with the platform on which the JVM is running.
-XX:InitialTenuringThreshold=7 Sets the initial tenuring threshold for use in adaptive GC sizing in the parallel young collector. The tenuring threshold is the number of times an object survives a young collection before being promoted to the old, or tenured, generation.
-XX:MaxTenuringThreshold=n Sets the maximum tenuring threshold for use in adaptive GC sizing. The current largest value is 15. The default value is 15 for the parallel collector and is 4 for CMS.
-Xloggc:<filename> Log GC verbose output to specified file. The verbose output is controlled by the normal verbose GC flags.
-XX:-UseGCLogFileRotation Enabled GC log rotation, requires -Xloggc.
-XX:NumberOfGClogFiles=1 Set the number of files to use when rotating logs, must be >= 1. The rotated log files will use the following naming scheme, <filename>.0, <filename>.1, ..., <filename>.n-1.
-XX:GCLogFileSize=8K The size of the log file at which point the log will be rotated, must be >= 8K.

這些內容都是根據我平時閱讀和查資料整理的,但願能幫到你們。小弟不才,有錯誤的地方還請你們指出,多多包涵!

相關文章
相關標籤/搜索