璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1> Posted 娣卞叆鍘熺悊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1>
相关的知识,希望对你有一定的参考价值。
鐐瑰嚮馃憜钃濊壊鈥?nbsp;娣卞叆鍘熺悊鈥濓紝鍏虫敞骞垛€?/span>璁句负鏄熸爣鈥?/span>
鎶€鏈共璐э紝绗竴鏃堕棿鎺ㄩ€?/span>
鍓嶈█
Garbage First(G1)鏄瀮鍦炬敹闆嗛鍩熺殑鏈€鏂版垚鏋滐紝鍚屾椂涔熸槸HotSpot鍦↗VM涓婂姏鎺ㄧ殑鍨冨溇鏀堕泦鍣紝骞惰祴浜堝彇浠MS鐨勪娇鍛姐€傚鏋滀娇鐢↗ava 8/9锛岄偅涔堟湁寰堝ぇ鍙兘甯屾湜瀵笹1鏀堕泦鍣ㄨ繘琛岃瘎浼般€傛湰鏂囪缁嗛鍏堝JVM鍏朵粬鐨勫瀮鍦炬敹闆嗗櫒杩涜鎬荤粨锛屽苟涓嶨1杩涜浜嗙畝鍗曠殑瀵规瘮锛涚劧鍚庨€氳繃G1鐨勫唴瀛樻ā鍨嬨€丟1鐨勬椿鍔ㄥ懆鏈燂紝瀵笹1鐨勫伐浣滄満鍒惰繘琛屼簡浠嬬粛锛涘悓鏃惰繕鍦ㄤ粙缁嶈繃绋嬩腑锛屾弿杩颁簡鍙兘闇€瑕佸紩璧锋敞鎰忕殑浼樺寲鐐广€傜瑪鑰呭笇鏈涢€氳繃鏈枃锛岃鏈変竴瀹欽VM鍩虹鐨勮鑰呰兘灏藉揩鎺屾彙G1鐨勭煡璇嗙偣銆?/p>
绗竴绔?姒傝堪
G1(Garbage First)鍨冨溇鏀堕泦鍣ㄦ槸褰撲粖鍨冨溇鍥炴敹鎶€鏈渶鍓嶆部鐨勬垚鏋滀箣涓€銆傛棭鍦↗DK7灏卞凡鍔犲叆JVM鐨勬敹闆嗗櫒澶у搴腑锛屾垚涓篐otSpot閲嶇偣鍙戝睍鐨勫瀮鍦惧洖鏀舵妧鏈€傚悓浼樼鐨凜MS鍨冨溇鍥炴敹鍣ㄤ竴鏍凤紝G1涔熸槸鍏虫敞鏈€灏忔椂寤剁殑鍨冨溇鍥炴敹鍣紝涔熷悓鏍烽€傚悎澶у昂瀵稿爢鍐呭瓨鐨勫瀮鍦炬敹闆嗭紝瀹樻柟涔熸帹鑽愪娇鐢℅1鏉ヤ唬鏇块€夋嫨CMS銆侴1鏈€澶х殑鐗圭偣鏄紩鍏ュ垎鍖虹殑鎬濊矾锛屽急鍖栦簡鍒嗕唬鐨勬蹇碉紝鍚堢悊鍒╃敤鍨冨溇鏀堕泦鍚勪釜鍛ㄦ湡鐨勮祫婧愶紝瑙e喅浜嗗叾浠栨敹闆嗗櫒鐢氳嚦CMS鐨勪紬澶氱己闄枫€?/p>
绗簩绔?JVM GC鏀堕泦鍣ㄧ殑鍥為【涓庢瘮杈?/h1>
鍥句腑灞曠ず浜?绉嶄笉鍚屽垎浠g殑鏀堕泦鍣細
Serial銆丳arNew銆丳arallel Scavenge銆丼erial Old銆丳arallel Old銆丆MS銆丟1锛?/p>
鑰屽畠浠墍澶勫尯鍩燂紝鍒欒〃鏄庡叾鏄睘浜庢柊鐢熶唬鏀堕泦鍣ㄨ繕鏄€佸勾浠f敹闆嗗櫒锛?/p>
鏂扮敓浠f敹闆嗗櫒锛歋erial銆丳arNew銆丳arallel Scavenge锛?/p>
鑰佸勾浠f敹闆嗗櫒锛歋erial Old銆丳arallel Old銆丆MS锛?/p>
鏁村爢鏀堕泦鍣細G1锛?/p>
涓や釜鏀堕泦鍣ㄩ棿鏈夎繛绾匡紝琛ㄦ槑瀹冧滑鍙互鎼厤浣跨敤锛?/p>
Serial/Serial Old銆丼erial/CMS銆丳arNew/Serial Old銆丳arNew/CMS銆丳arallel Scavenge/Serial Old銆丳arallel Scavenge/Parallel Old銆丟1锛?/p>
涓茶鏀堕泦鍣?/h2>
涓茶鏀堕泦鍣ㄧ粍鍚?Serial + Serial Old
寮€鍚€夐」锛?code class="mq-43">-XX:+SerialGC
涓茶鏀堕泦鍣ㄦ槸鏈€鍩烘湰銆佸彂灞曟椂闂存渶闀裤€佷箙缁忚€冮獙鐨勫瀮鍦炬敹闆嗗櫒锛屼篃鏄痗lient妯″紡涓嬬殑榛樿鏀堕泦鍣ㄩ厤缃€?/p>
涓茶鏀堕泦鍣ㄩ噰鐢ㄥ崟绾跨▼stop-the-world鐨勬柟寮忚繘琛屾敹闆嗐€傚綋鍐呭瓨涓嶈冻鏃讹紝涓茶GC璁剧疆鍋滈】鏍囪瘑锛屽緟鎵€鏈夌嚎绋嬮兘杩涘叆瀹夊叏鐐?Safepoint)鏃讹紝搴旂敤绾跨▼鏆傚仠锛屼覆琛孏C寮€濮嬪伐浣滐紝閲囩敤鍗曠嚎绋嬫柟寮忓洖鏀剁┖闂村苟鏁寸悊鍐呭瓨銆傚崟绾跨▼涔熸剰鍛崇潃澶嶆潅搴︽洿浣庛€佸崰鐢ㄥ唴瀛樻洿灏戯紝浣嗗悓鏃朵篃鎰忓懗鐫€涓嶈兘鏈夋晥鍒╃敤澶氭牳浼樺娍銆備簨瀹炰笂锛屼覆琛屾敹闆嗗櫒鐗瑰埆閫傚悎鍫嗗唴瀛樹笉楂樸€佸崟鏍哥敋鑷冲弻鏍窩PU鐨勫満鍚堛€?/p>
骞惰鏀堕泦鍣?/h2>
骞惰鏀堕泦鍣ㄧ粍鍚?Parallel Scavenge + Parallel Old
寮€鍚€夐」锛?code class="mq-51">-XX:+UseParallelGC鎴?code class="mq-52">-XX:+UseParallelOldGC(鍙簰鐩告縺娲?
骞惰鏀堕泦鍣ㄦ槸浠ュ叧娉ㄥ悶鍚愰噺涓虹洰鏍囩殑鍨冨溇鏀堕泦鍣紝涔熸槸server妯″紡涓嬬殑榛樿鏀堕泦鍣ㄩ厤缃紝瀵瑰悶鍚愰噺鐨勫叧娉ㄤ富瑕佷綋鐜板湪骞磋交浠arallel Scavenge鏀堕泦鍣ㄤ笂銆?/p>
骞惰鏀堕泦鍣ㄤ笌涓茶鏀堕泦鍣ㄥ伐浣滄ā寮忕浉浼硷紝閮芥槸stop-the-world鏂瑰紡锛屽彧鏄殏鍋滄椂骞惰鍦拌繘琛屽瀮鍦炬敹闆嗐€傚勾杞讳唬閲囩敤澶嶅埗绠楁硶锛岃€佸勾浠i噰鐢ㄦ爣璁?鏁寸悊锛屽湪鍥炴敹鐨勫悓鏃惰繕浼氬鍐呭瓨杩涜鍘嬬缉銆傚叧娉ㄥ悶鍚愰噺涓昏鎸囧勾杞讳唬鐨凱arallel Scavenge鏀堕泦鍣紝閫氳繃涓や釜鐩爣鍙傛暟-XX:MaxGCPauseMills
鍜?code class="mq-56">-XX:GCTimeRatio锛岃皟鏁存柊鐢熶唬绌洪棿澶у皬锛屾潵闄嶄綆GC瑙﹀彂鐨勯鐜囥€傚苟琛屾敹闆嗗櫒閫傚悎瀵瑰悶鍚愰噺瑕佹眰杩滆繙楂樹簬寤惰繜瑕佹眰鐨勫満鏅紝骞朵笖鍦ㄦ弧瓒虫渶宸欢鏃剁殑鎯呭喌涓嬶紝骞惰鏀堕泦鍣ㄥ皢鎻愪緵鏈€浣崇殑鍚炲悙閲忋€?/p>
骞跺彂鏍囪娓呴櫎鏀堕泦鍣?/h2>
骞跺彂鏍囪娓呴櫎鏀堕泦鍣ㄧ粍鍚?ParNew + CMS + Serial Old
寮€鍚€夐」锛?code class="mq-61">-XX:+UseConcMarkSweepGC
骞跺彂鏍囪娓呴櫎(CMS)鏄互鍏虫敞寤惰繜涓虹洰鏍囥€佸崄鍒嗕紭绉€鐨勫瀮鍦惧洖鏀剁畻娉曪紝寮€鍚悗锛屽勾杞讳唬浣跨敤STW寮忕殑骞惰鏀堕泦锛岃€佸勾浠e洖鏀堕噰鐢–MS杩涜鍨冨溇鍥炴敹锛屽寤惰繜鐨勫叧娉ㄤ篃涓昏浣撶幇鍦ㄨ€佸勾浠MS涓娿€?/p>
骞磋交浠arNew涓庡苟琛屾敹闆嗗櫒绫讳技锛岃€岃€佸勾浠MS姣忎釜鏀堕泦鍛ㄦ湡閮借缁忓巻锛?span>鍒濆鏍囪銆佸苟鍙戞爣璁般€侀噸鏂版爣璁般€佸苟鍙戞竻闄?/strong>銆傚叾涓紝鍒濆鏍囪浠TW鐨勬柟寮忔爣璁版墍鏈夌殑鏍瑰璞★紱骞跺彂鏍囪鍒欏悓搴旂敤绾跨▼涓€璧峰苟琛岋紝鏍囪鍑烘牴瀵硅薄鐨勫彲杈捐矾寰勶紱鍦ㄨ繘琛屽瀮鍦惧洖鏀跺墠锛孋MS鍐嶄互涓€涓猄TW杩涜閲嶆柊鏍囪锛屾爣璁伴偅浜涚敱mutator绾跨▼(鎸囧紩璧锋暟鎹彉鍖栫殑绾跨▼锛屽嵆搴旂敤绾跨▼)淇敼鑰屽彲鑳介敊杩囩殑鍙揪瀵硅薄锛涙渶鍚庡緱鍒扮殑涓嶅彲杈惧璞″皢鍦ㄥ苟鍙戞竻闄ら樁娈佃繘琛屽洖鏀躲€?span>鍊煎緱娉ㄦ剰鐨勬槸锛屽垵濮嬫爣璁板拰閲嶆柊鏍囪閮藉凡浼樺寲涓哄绾跨▼鎵ц銆侰MS闈炲父閫傚悎鍫嗗唴瀛樺ぇ銆丆PU鏍告暟澶氱殑鏈嶅姟鍣ㄧ搴旂敤锛屼篃鏄疓1鍑虹幇涔嬪墠澶у瀷搴旂敤鐨勯閫夋敹闆嗗櫒銆?/p>
浣嗘槸CMS骞朵笉瀹岀編锛屽畠鏈変互涓嬬己鐐癸細
鐢变簬骞跺彂杩涜锛孋MS鍦ㄦ敹闆嗕笌搴旂敤绾跨▼浼氬悓鏃朵細澧炲姞瀵瑰爢鍐呭瓨鐨勫崰鐢紝涔熷氨鏄锛孋MS蹇呴』瑕佸湪鑰佸勾浠e爢鍐呭瓨鐢ㄥ敖涔嬪墠瀹屾垚鍨冨溇鍥炴敹锛屽惁鍒機MS鍥炴敹澶辫触鏃讹紝灏嗚Е鍙戞媴淇濇満鍒讹紝涓茶鑰佸勾浠f敹闆嗗櫒灏嗕細浠TW鐨勬柟寮忚繘琛屼竴娆C锛屼粠鑰岄€犳垚杈冨ぇ鍋滈】鏃堕棿锛?/p>
鏍囪娓呴櫎绠楁硶鏃犳硶鏁寸悊绌洪棿纰庣墖锛岃€佸勾浠g┖闂翠細闅忕潃搴旂敤鏃堕暱琚€愭鑰楀敖锛屾渶鍚庡皢涓嶅緱涓嶉€氳繃鎷呬繚鏈哄埗瀵瑰爢鍐呭瓨杩涜鍘嬬缉銆侰MS涔熸彁渚涗簡鍙傛暟-XX:CMSFullGCsBeForeCompaction
(榛樿0锛屽嵆姣忔閮借繘琛屽唴瀛樻暣鐞?鏉ユ寚瀹氬灏戞CMS鏀堕泦涔嬪悗锛岃繘琛屼竴娆″帇缂╃殑Full GC銆?/p>
Garbage First
Garbage First (G1)
寮€鍚€夐」锛?code class="mq-72">-XX:+UseG1GC
涔嬪墠浠嬬粛鐨勫嚑缁勫瀮鍦炬敹闆嗗櫒缁勫悎锛岄兘鏈夊嚑涓叡鍚岀偣锛?/p>
骞磋交浠c€佽€佸勾浠f槸鐙珛涓旇繛缁殑鍐呭瓨鍧楋紱
骞磋交浠f敹闆嗕娇鐢ㄥ崟eden銆佸弻survivor杩涜澶嶅埗绠楁硶锛?/p>
鑰佸勾浠f敹闆嗗繀椤绘壂鎻忔暣涓€佸勾浠e尯鍩燂紱
閮芥槸浠ュ敖鍙兘灏戣€屽潡鍦版墽琛孏C涓鸿璁″師鍒欍€?/p>
G1鍨冨溇鏀堕泦鍣ㄤ篃鏄互鍏虫敞寤惰繜涓虹洰鏍囥€佹湇鍔″櫒绔簲鐢ㄧ殑鍨冨溇鏀堕泦鍣紝琚獺otSpot鍥㈤槦瀵勪簣鍙栦唬CMS鐨勪娇鍛斤紝涔熸槸涓€涓潪甯稿叿鏈夎皟浼樻綔鍔涚殑鍨冨溇鏀堕泦鍣ㄣ€傝櫧鐒禛1涔熸湁绫讳技CMS鐨勬敹闆嗗姩浣滐細鍒濆鏍囪銆佸苟鍙戞爣璁般€侀噸鏂版爣璁般€佹竻闄ゃ€佽浆绉诲洖鏀讹紝骞朵笖涔熶互涓€涓覆琛屾敹闆嗗櫒鍋氭媴淇濇満鍒讹紝浣嗗崟绾湴浠ョ被浼煎墠涓夌鐨勮繃绋嬫弿杩版樉寰楀苟涓嶆槸寰堝Ε褰撱€備簨瀹炰笂锛孏1鏀堕泦涓庝互涓婁笁缁勬敹闆嗗櫒鏈夊緢澶т笉鍚岋細
G1鐨勮璁″師鍒欐槸"棣栧厛鏀堕泦灏藉彲鑳藉鐨勫瀮鍦?Garbage First)"銆傚洜姝わ紝G1骞朵笉浼氱瓑鍐呭瓨鑰楀敖(涓茶銆佸苟琛?鎴栬€呭揩鑰楀敖(CMS)鐨勬椂鍊欏紑濮嬪瀮鍦炬敹闆嗭紝鑰屾槸鍦ㄥ唴閮ㄩ噰鐢ㄤ簡鍚彂寮忕畻娉曪紝鍦ㄨ€佸勾浠f壘鍑哄叿鏈夐珮鏀堕泦鏀剁泭鐨勫垎鍖鸿繘琛屾敹闆嗐€傚悓鏃禛1鍙互鏍规嵁鐢ㄦ埛璁剧疆鐨勬殏鍋滄椂闂寸洰鏍囪嚜鍔ㄨ皟鏁村勾杞讳唬鍜屾€诲爢澶у皬锛屾殏鍋滅洰鏍囪秺鐭勾杞讳唬绌洪棿瓒婂皬銆佹€荤┖闂村氨瓒婂ぇ锛?/p>
G1閲囩敤鍐呭瓨鍒嗗尯(Region)鐨勬€濊矾锛屽皢鍐呭瓨鍒掑垎涓轰竴涓釜鐩哥瓑澶у皬鐨勫唴瀛樺垎鍖猴紝鍥炴敹鏃跺垯浠ュ垎鍖轰负鍗曚綅杩涜鍥炴敹锛屽瓨娲荤殑瀵硅薄澶嶅埗鍒板彟涓€涓┖闂插垎鍖轰腑銆傜敱浜庨兘鏄互鐩哥瓑澶у皬鐨勫垎鍖轰负鍗曚綅杩涜鎿嶄綔锛屽洜姝1澶╃劧灏辨槸涓€绉嶅帇缂╂柟妗?灞€閮ㄥ帇缂?锛?/p>
G1铏界劧涔熸槸鍒嗕唬鏀堕泦鍣紝浣嗘暣涓唴瀛樺垎鍖轰笉瀛樺湪鐗╃悊涓婄殑骞磋交浠d笌鑰佸勾浠g殑鍖哄埆锛屼篃涓嶉渶瑕佸畬鍏ㄧ嫭绔嬬殑survivor(to space)鍫嗗仛澶嶅埗鍑嗗銆侴1鍙湁閫昏緫涓婄殑鍒嗕唬姒傚康锛屾垨鑰呰姣忎釜鍒嗗尯閮藉彲鑳介殢G1鐨勮繍琛屽湪涓嶅悓浠d箣闂村墠鍚庡垏鎹紱
G1鐨勬敹闆嗛兘鏄疭TW鐨勶紝浣嗗勾杞讳唬鍜岃€佸勾浠g殑鏀堕泦鐣岄檺姣旇緝妯$硦锛岄噰鐢ㄤ簡娣峰悎(mixed)鏀堕泦鐨勬柟寮忋€傚嵆姣忔鏀堕泦鏃㈠彲鑳藉彧鏀堕泦骞磋交浠e垎鍖?骞磋交浠f敹闆?锛屼篃鍙兘鍦ㄦ敹闆嗗勾杞讳唬鐨勫悓鏃讹紝鍖呭惈閮ㄥ垎鑰佸勾浠e垎鍖?娣峰悎鏀堕泦)锛岃繖鏍峰嵆浣垮爢鍐呭瓨寰堝ぇ鏃讹紝涔熷彲浠ラ檺鍒舵敹闆嗚寖鍥达紝浠庤€岄檷浣庡仠椤裤€?/p>
绗笁绔?G1鐨勫唴瀛樻ā鍨?/h1>
鍒嗗尯姒傚康
鍒嗗尯
鍒嗗尯 Region
G1閲囩敤浜嗗垎鍖?Region)鐨勬€濊矾锛屽皢鏁翠釜鍫嗙┖闂村垎鎴愯嫢骞蹭釜澶у皬鐩哥瓑鐨勫唴瀛樺尯鍩燂紝姣忔鍒嗛厤瀵硅薄绌洪棿灏嗛€愭鍦颁娇鐢ㄥ唴瀛樸€傚洜姝わ紝鍦ㄥ爢鐨勪娇鐢ㄤ笂锛孏1骞朵笉瑕佹眰瀵硅薄鐨勫瓨鍌ㄤ竴瀹氭槸鐗╃悊涓婅繛缁殑锛屽彧瑕侀€昏緫涓婅繛缁嵆鍙紱姣忎釜鍒嗗尯涔熶笉浼氱‘瀹氬湴涓烘煇涓唬鏈嶅姟锛屽彲浠ユ寜闇€鍦ㄥ勾杞讳唬鍜岃€佸勾浠d箣闂村垏鎹€傚惎鍔ㄦ椂鍙互閫氳繃鍙傛暟-XX:G1HeapRegionSize=n
鍙寚瀹氬垎鍖哄ぇ灏?1MB~32MB锛屼笖蹇呴』鏄?鐨勫箓)锛岄粯璁ゅ皢鏁村爢鍒掑垎涓?048涓垎鍖恒€?/p>
鍗$墖
鍗$墖 Card
鍦ㄦ瘡涓垎鍖哄唴閮ㄥ張琚垎鎴愪簡鑻ュ共涓ぇ灏忎负512 Byte鍗$墖(Card)锛屾爣璇嗗爢鍐呭瓨鏈€灏忓彲鐢ㄧ矑搴︽墍鏈夊垎鍖虹殑鍗$墖灏嗕細璁板綍鍦ㄥ叏灞€鍗$墖琛?Global Card Table)涓紝鍒嗛厤鐨勫璞′細鍗犵敤鐗╃悊涓婅繛缁殑鑻ュ共涓崱鐗囷紝褰撴煡鎵惧鍒嗗尯鍐呭璞$殑寮曠敤鏃朵究鍙€氳繃璁板綍鍗$墖鏉ユ煡鎵捐寮曠敤瀵硅薄(瑙丷Set)銆傛瘡娆″鍐呭瓨鐨勫洖鏀讹紝閮芥槸瀵规寚瀹氬垎鍖虹殑鍗$墖杩涜澶勭悊銆?/p>
鍫?/h3>
鍫?Heap
G1鍚屾牱鍙互閫氳繃-Xms
/-Xmx
鏉ユ寚瀹氬爢绌洪棿澶у皬銆傚綋鍙戠敓骞磋交浠f敹闆嗘垨娣峰悎鏀堕泦鏃讹紝閫氳繃璁$畻GC涓庡簲鐢ㄧ殑鑰楄垂鏃堕棿姣旓紝鑷姩璋冩暣鍫嗙┖闂村ぇ灏忋€傚鏋淕C棰戠巼澶珮锛屽垯閫氳繃澧炲姞鍫嗗昂瀵革紝鏉ュ噺灏慓C棰戠巼锛岀浉搴斿湴GC鍗犵敤鐨勬椂闂翠篃闅忎箣闄嶄綆锛涚洰鏍囧弬鏁?code class="mq-93">-XX:GCTimeRatio鍗充负GC涓庡簲鐢ㄧ殑鑰楄垂鏃堕棿姣旓紝G1榛樿涓?锛岃€孋MS榛樿涓?9锛屽洜涓篊MS鐨勮璁″師鍒欐槸鑰楄垂鍦℅C涓婄殑鏃堕棿灏藉彲鑳界殑灏戙€傚彟澶栵紝褰撶┖闂翠笉瓒筹紝濡傚璞$┖闂村垎閰嶆垨杞Щ澶辫触鏃讹紝G1浼氶鍏堝皾璇曞鍔犲爢绌洪棿锛屽鏋滄墿瀹瑰け璐ワ紝鍒欏彂璧锋媴淇濈殑Full GC銆侳ull GC鍚庯紝鍫嗗昂瀵歌绠楃粨鏋滀篃浼氳皟鏁村爢绌洪棿銆?/p>
鍒嗕唬妯″瀷
鍒嗕唬
鍒嗕唬 Generation
鍒嗕唬鍨冨溇鏀堕泦鍙互灏嗗叧娉ㄧ偣闆嗕腑鍦ㄦ渶杩戣鍒嗛厤鐨勫璞′笂锛岃€屾棤闇€鏁村爢鎵弿锛岄伩鍏嶉暱鍛藉璞$殑鎷疯礉锛屽悓鏃剁嫭绔嬫敹闆嗘湁鍔╀簬闄嶄綆鍝嶅簲鏃堕棿銆傝櫧鐒跺垎鍖轰娇寰楀唴瀛樺垎閰嶄笉鍐嶈姹傜揣鍑戠殑鍐呭瓨绌洪棿锛屼絾G1渚濈劧浣跨敤浜嗗垎浠g殑鎬濇兂銆備笌鍏朵粬鍨冨溇鏀堕泦鍣ㄧ被浼硷紝G1灏嗗唴瀛樺湪閫昏緫涓婂垝鍒嗕负骞磋交浠e拰鑰佸勾浠o紝鍏朵腑骞磋交浠e張鍒掑垎涓篍den绌洪棿鍜孲urvivor绌洪棿銆備絾骞磋交浠g┖闂村苟涓嶆槸鍥哄畾涓嶅彉鐨勶紝褰撶幇鏈夊勾杞讳唬鍒嗗尯鍗犳弧鏃讹紝JVM浼氬垎閰嶆柊鐨勭┖闂插垎鍖哄姞鍏ュ埌骞磋交浠g┖闂淬€?/p>
鏁翠釜骞磋交浠e唴瀛樹細鍦ㄥ垵濮嬬┖闂?code class="mq-101">-XX:G1NewSizePercent(榛樿鏁村爢5%)涓庢渶澶х┖闂?code class="mq-102">-XX:G1MaxNewSizePercent(榛樿60%)涔嬮棿鍔ㄦ€佸彉鍖栵紝涓旂敱鍙傛暟鐩爣鏆傚仠鏃堕棿-XX:MaxGCPauseMillis
(榛樿200ms)銆侀渶瑕佹墿缂╁鐨勫ぇ灏忎互鍙婂垎鍖虹殑宸茶蹇嗛泦鍚?RSet)璁$畻寰楀埌銆傚綋鐒讹紝G1渚濈劧鍙互璁剧疆鍥哄畾鐨勫勾杞讳唬澶у皬(鍙傛暟-XX:NewRatio
銆?code class="mq-105">-Xmn)锛屼絾鍚屾椂鏆傚仠鐩爣灏嗗け鍘绘剰涔夈€?/p>
鏈湴鍒嗛厤缂撳啿
鏈湴鍒嗛厤缂撳啿 Local allocation buffer (Lab)
鍊煎緱娉ㄦ剰鐨勬槸锛岀敱浜庡垎鍖虹殑鎬濇兂锛屾瘡涓嚎绋嬪潎鍙互"璁ら"鏌愪釜鍒嗗尯鐢ㄤ簬绾跨▼鏈湴鐨勫唴瀛樺垎閰嶏紝鑰屼笉闇€瑕侀【鍙婂垎鍖烘槸鍚﹁繛缁€傚洜姝わ紝姣忎釜搴旂敤绾跨▼鍜孏C绾跨▼閮戒細鐙珛鐨勪娇鐢ㄥ垎鍖猴紝杩涜€屽噺灏戝悓姝ユ椂闂达紝鎻愬崌GC鏁堢巼锛岃繖涓垎鍖虹О涓烘湰鍦板垎閰嶇紦鍐插尯(Lab)銆?/p>
鍏朵腑锛屽簲鐢ㄧ嚎绋嬪彲浠ョ嫭鍗犱竴涓湰鍦扮紦鍐插尯(TLAB)鏉ュ垱寤虹殑瀵硅薄锛岃€屽ぇ閮ㄥ垎閮戒細钀藉叆Eden鍖哄煙(宸ㄥ瀷瀵硅薄鎴栧垎閰嶅け璐ラ櫎澶?锛屽洜姝LAB鐨勫垎鍖哄睘浜嶦den绌洪棿锛涜€屾瘡娆″瀮鍦炬敹闆嗘椂锛屾瘡涓狦C绾跨▼鍚屾牱鍙互鐙崰涓€涓湰鍦扮紦鍐插尯(GCLAB)鐢ㄦ潵杞Щ瀵硅薄锛屾瘡娆″洖鏀朵細灏嗗璞″鍒跺埌Suvivor绌洪棿鎴栬€佸勾浠g┖闂达紱瀵逛簬浠嶦den/Survivor绌洪棿鏅嬪崌(Promotion)鍒癝urvivor/鑰佸勾浠g┖闂寸殑瀵硅薄锛屽悓鏍锋湁GC鐙崰鐨勬湰鍦扮紦鍐插尯杩涜鎿嶄綔锛岃閮ㄥ垎绉颁负鏅嬪崌鏈湴缂撳啿鍖?PLAB)銆?/p>
鍒嗗尯妯″瀷
G1瀵瑰唴瀛樼殑浣跨敤浠ュ垎鍖?Region)涓哄崟浣嶏紝鑰屽瀵硅薄鐨勫垎閰嶅垯浠ュ崱鐗?Card)涓哄崟浣嶃€?br>
宸ㄥ瀷瀵硅薄
宸ㄥ瀷瀵硅薄 Humongous Region
涓€涓ぇ灏忚揪鍒扮敋鑷宠秴杩囧垎鍖哄ぇ灏忎竴鍗婄殑瀵硅薄绉颁负宸ㄥ瀷瀵硅薄(Humongous Object)銆傚綋绾跨▼涓哄法鍨嬪垎閰嶇┖闂存椂锛屼笉鑳界畝鍗曞湪TLAB杩涜鍒嗛厤锛屽洜涓哄法鍨嬪璞$殑绉诲姩鎴愭湰寰堥珮锛岃€屼笖鏈夊彲鑳戒竴涓垎鍖轰笉鑳藉绾冲法鍨嬪璞°€傚洜姝わ紝宸ㄥ瀷瀵硅薄浼氱洿鎺ュ湪鑰佸勾浠e垎閰嶏紝鎵€鍗犵敤鐨勮繛缁┖闂寸О涓哄法鍨嬪垎鍖?Humongous Region)銆侴1鍐呴儴鍋氫簡涓€涓紭鍖栵紝涓€鏃﹀彂鐜版病鏈夊紩鐢ㄦ寚鍚戝法鍨嬪璞★紝鍒欏彲鐩存帴鍦ㄥ勾杞讳唬鏀堕泦鍛ㄦ湡涓鍥炴敹銆?/p>
宸ㄥ瀷瀵硅薄浼氱嫭鍗犱竴涓€佹垨澶氫釜杩炵画鍒嗗尯锛屽叾涓涓€涓垎鍖鸿鏍囪涓哄紑濮嬪法鍨?StartsHumongous)锛岀浉閭昏繛缁垎鍖鸿鏍囪涓鸿繛缁法鍨?ContinuesHumongous)銆傜敱浜庢棤娉曚韩鍙桳ab甯︽潵鐨勪紭鍖栵紝骞朵笖纭畾涓€鐗囪繛缁殑鍐呭瓨绌洪棿闇€瑕佹壂鎻忔暣鍫嗭紝鍥犳纭畾宸ㄥ瀷瀵硅薄寮€濮嬩綅缃殑鎴愭湰闈炲父楂橈紝濡傛灉鍙互锛屽簲鐢ㄧ▼搴忓簲閬垮厤鐢熸垚宸ㄥ瀷瀵硅薄銆?/p>
宸茶蹇嗛泦鍚?/h3>
宸茶蹇嗛泦鍚?Remember Set (RSet)
鍦ㄤ覆琛屽拰骞惰鏀堕泦鍣ㄤ腑锛孏C閫氳繃鏁村爢鎵弿锛屾潵纭畾瀵硅薄鏄惁澶勪簬鍙揪璺緞涓€傜劧鑰孏1涓轰簡閬垮厤STW寮忕殑鏁村爢鎵弿锛屽湪姣忎釜鍒嗗尯璁板綍浜嗕竴涓凡璁板繂闆嗗悎(RSet)锛屽唴閮ㄧ被浼间竴涓弽鍚戞寚閽堬紝璁板綍寮曠敤鍒嗗尯鍐呭璞$殑鍗$墖绱㈠紩銆傚綋瑕佸洖鏀惰鍒嗗尯鏃讹紝閫氳繃鎵弿鍒嗗尯鐨凴Set锛屾潵纭畾寮曠敤鏈垎鍖哄唴鐨勫璞℃槸鍚﹀瓨娲伙紝杩涜€岀‘瀹氭湰鍒嗗尯鍐呯殑瀵硅薄瀛樻椿鎯呭喌銆?/p>
浜嬪疄涓婏紝骞堕潪鎵€鏈夌殑寮曠敤閮介渶瑕佽褰曞湪RSet涓紝濡傛灉涓€涓垎鍖虹‘瀹氶渶瑕佹壂鎻忥紝閭d箞鏃犻渶RSet涔熷彲浠ユ棤閬楁紡鐨勫緱鍒板紩鐢ㄥ叧绯汇€傞偅涔堝紩鐢ㄦ簮鑷湰鍒嗗尯鐨勫璞★紝褰撶劧涓嶇敤钀藉叆RSet涓紱鍚屾椂锛孏1 GC姣忔閮戒細瀵瑰勾杞讳唬杩涜鏁翠綋鏀堕泦锛屽洜姝ゅ紩鐢ㄦ簮鑷勾杞讳唬鐨勫璞★紝涔熶笉闇€瑕佸湪RSet涓褰曘€傛渶鍚庡彧鏈夎€佸勾浠g殑鍒嗗尯鍙兘浼氭湁RSet璁板綍锛岃繖浜涘垎鍖虹О涓烘嫢鏈塕Set鍒嗗尯(an RSet鈥檚 owning region)銆?/p>
Per Region Table
Per Region Table (PRT)
RSet鍦ㄥ唴閮ㄤ娇鐢≒er Region Table(PRT)璁板綍鍒嗗尯鐨勫紩鐢ㄦ儏鍐点€傜敱浜嶳Set鐨勮褰曡鍗犵敤鍒嗗尯鐨勭┖闂达紝濡傛灉涓€涓垎鍖洪潪甯?鍙楁杩?锛岄偅涔圧Set鍗犵敤鐨勭┖闂翠細涓婂崌锛屼粠鑰岄檷浣庡垎鍖虹殑鍙敤绌洪棿銆侴1搴斿杩欎釜闂閲囩敤浜嗘敼鍙楻Set鐨勫瘑搴︾殑鏂瑰紡锛屽湪PRT涓皢浼氫互涓夌妯″紡璁板綍寮曠敤锛?/p>
绋€灏戯細鐩存帴璁板綍寮曠敤瀵硅薄鐨勫崱鐗囩储寮?/p>
缁嗙矑搴︼細璁板綍寮曠敤瀵硅薄鐨勫垎鍖虹储寮?/p>
绮楃矑搴︼細鍙褰曞紩鐢ㄦ儏鍐碉紝姣忎釜鍒嗗尯瀵瑰簲涓€涓瘮鐗逛綅
鐢变笂鍙煡锛岀矖绮掑害鐨凱RT鍙槸璁板綍浜嗗紩鐢ㄦ暟閲忥紝闇€瑕侀€氳繃鏁村爢鎵弿鎵嶈兘鎵惧嚭鎵€鏈夊紩鐢紝鍥犳鎵弿閫熷害涔熸槸鏈€鎱㈢殑銆?/p>
鏀堕泦闆嗗悎 (CSet)
鏀堕泦闆嗗悎 CSet
鏀堕泦闆嗗悎(CSet)浠h〃姣忔GC鏆傚仠鏃跺洖鏀剁殑涓€绯诲垪鐩爣鍒嗗尯銆傚湪浠绘剰涓€娆℃敹闆嗘殏鍋滀腑锛孋Set鎵€鏈夊垎鍖洪兘浼氳閲婃斁锛屽唴閮ㄥ瓨娲荤殑瀵硅薄閮戒細琚浆绉诲埌鍒嗛厤鐨勭┖闂插垎鍖轰腑銆傚洜姝ゆ棤璁烘槸骞磋交浠f敹闆嗭紝杩樻槸娣峰悎鏀堕泦锛屽伐浣滅殑鏈哄埗閮芥槸涓€鑷寸殑銆傚勾杞讳唬鏀堕泦CSet鍙绾冲勾杞讳唬鍒嗗尯锛岃€屾贩鍚堟敹闆嗕細閫氳繃鍚彂寮忕畻娉曪紝鍦ㄨ€佸勾浠e€欓€夊洖鏀跺垎鍖轰腑锛岀瓫閫夊嚭鍥炴敹鏀剁泭鏈€楂樼殑鍒嗗尯娣诲姞鍒癈Set涓€?/p>
鍊欓€夎€佸勾浠e垎鍖虹殑CSet鍑嗗叆鏉′欢锛屽彲浠ラ€氳繃娲昏穬搴﹂槇鍊?code class="mq-133">-XX:G1MixedGCLiveThresholdPercent(榛樿85%)杩涜璁剧疆锛屼粠鑰屾嫤鎴偅浜涘洖鏀跺紑閿€宸ㄥぇ鐨勫璞★紱鍚屾椂锛屾瘡娆℃贩鍚堟敹闆嗗彲浠ュ寘鍚€欓€夎€佸勾浠e垎鍖猴紝鍙牴鎹瓹Set瀵瑰爢鐨勬€诲ぇ灏忓崰姣?code class="mq-134">-XX:G1OldCSetRegionThresholdPercent(榛樿10%)璁剧疆鏁伴噺涓婇檺銆?/p>
鐢变笂杩板彲鐭ワ紝G1鐨勬敹闆嗛兘鏄牴鎹瓹Set杩涜鎿嶄綔鐨勶紝骞磋交浠f敹闆嗕笌娣峰悎鏀堕泦娌℃湁鏄庢樉鐨勪笉鍚岋紝鏈€澶х殑鍖哄埆鍦ㄤ簬涓ょ鏀堕泦鐨勮Е鍙戞潯浠躲€?/p>
骞磋交浠f敹闆嗛泦鍚?/h3>
骞磋交浠f敹闆嗛泦鍚?CSet of Young Collection
搴旂敤绾跨▼涓嶆柇娲诲姩鍚庯紝骞磋交浠g┖闂翠細琚€愭笎濉弧銆傚綋JVM鍒嗛厤瀵硅薄鍒癊den鍖哄煙澶辫触(Eden鍖哄凡婊?鏃讹紝渚夸細瑙﹀彂涓€娆TW寮忕殑骞磋交浠f敹闆嗐€傚湪骞磋交浠f敹闆嗕腑锛孍den鍒嗗尯瀛樻椿鐨勫璞″皢琚嫹璐濆埌Survivor鍒嗗尯锛涘師鏈塖urvivor鍒嗗尯瀛樻椿鐨勫璞★紝灏嗘牴鎹换鏈熼槇鍊?tenuring threshold)鍒嗗埆鏅嬪崌鍒癙LAB涓紝鏂扮殑survivor鍒嗗尯鍜岃€佸勾浠e垎鍖恒€傝€屽師鏈夌殑骞磋交浠e垎鍖哄皢琚暣浣撳洖鏀舵帀銆?/p>
鍚屾椂锛屽勾杞讳唬鏀堕泦杩樿礋璐g淮鎶ゅ璞$殑骞撮緞(瀛樻椿娆℃暟)锛岃緟鍔╁垽鏂€佸寲(tenuring)瀵硅薄鏅嬪崌鐨勬椂鍊欐槸鍒癝urvivor鍒嗗尯杩樻槸鍒拌€佸勾浠e垎鍖恒€傚勾杞讳唬鏀堕泦棣栧厛鍏堝皢鏅嬪崌瀵硅薄灏哄鎬诲拰銆佸璞″勾榫勪俊鎭淮鎶ゅ埌骞撮緞琛ㄤ腑锛屽啀鏍规嵁骞撮緞琛ㄣ€丼urvivor灏哄銆丼urvivor濉厖瀹归噺-XX:TargetSurvivorRatio
(榛樿50%)銆佹渶澶т换鏈熼槇鍊?code class="mq-141">-XX:MaxTenuringThreshold(榛樿15)锛岃绠楀嚭涓€涓伆褰撶殑浠绘湡闃堝€硷紝鍑℃槸瓒呰繃浠绘湡闃堝€肩殑瀵硅薄閮戒細琚檵鍗囧埌鑰佸勾浠c€?/p>
娣峰悎鏀堕泦闆嗗悎
娣峰悎鏀堕泦闆嗗悎 CSet of Mixed Collection
骞磋交浠f敹闆嗕笉鏂椿鍔ㄥ悗锛岃€佸勾浠g殑绌洪棿涔熶細琚€愭笎濉厖銆傚綋鑰佸勾浠e崰鐢ㄧ┖闂磋秴杩囨暣鍫嗘瘮IHOP闃堝€?code class="mq-145">-XX:InitiatingHeapOccupancyPercent(榛樿45%)鏃讹紝G1灏变細鍚姩涓€娆℃贩鍚堝瀮鍦炬敹闆嗗懆鏈熴€備负浜嗘弧瓒虫殏鍋滅洰鏍囷紝G1鍙兘涓嶈兘涓€鍙f皵灏嗘墍鏈夌殑鍊欓€夊垎鍖烘敹闆嗘帀锛屽洜姝1鍙兘浼氫骇鐢熻繛缁娆$殑娣峰悎鏀堕泦涓庡簲鐢ㄧ嚎绋嬩氦鏇挎墽琛岋紝姣忔STW鐨勬贩鍚堟敹闆嗕笌骞磋交浠f敹闆嗚繃绋嬬浉绫讳技銆?/p>
涓轰簡纭畾鍖呭惈鍒板勾杞讳唬鏀堕泦闆嗗悎CSet鐨勮€佸勾浠e垎鍖猴紝JVM閫氳繃鍙傛暟娣峰悎鍛ㄦ湡鐨勬渶澶ф€绘鏁?code class="mq-147">-XX:G1MixedGCCountTarget(榛樿8)銆佸爢搴熺墿鐧惧垎姣?code class="mq-148">-XX:G1HeapWastePercent(榛樿5%)銆傞€氳繃鍊欓€夎€佸勾浠e垎鍖烘€绘暟涓庢贩鍚堝懆鏈熸渶澶ф€绘鏁帮紝纭畾姣忔鍖呭惈鍒癈Set鐨勬渶灏忓垎鍖烘暟閲忥紱鏍规嵁鍫嗗簾鐗╃櫨鍒嗘瘮锛屽綋鏀堕泦杈惧埌鍙傛暟鏃讹紝涓嶅啀鍚姩鏂扮殑娣峰悎鏀堕泦銆傝€屾瘡娆℃坊鍔犲埌CSet鐨勫垎鍖猴紝鍒欓€氳繃璁$畻寰楀埌鐨凣C鏁堢巼杩涜瀹夋帓銆?/p>
绗洓绔?G1鐨勬椿鍔ㄥ懆鏈?/h1>
G1鍨冨溇鏀堕泦娲诲姩姹囨€?/h2>
绁嚭涓€寮犳€诲浘
RSet鐨勭淮鎶?/h2>
鐢变簬涓嶈兘鏁村爢鎵弿锛屽張闇€瑕佽绠楀垎鍖虹‘鍒囩殑娲昏穬搴︼紝鍥犳锛孏1闇€瑕佷竴涓閲忓紡鐨勫畬鍏ㄦ爣璁板苟鍙戠畻娉曪紝閫氳繃缁存姢RSet锛屽緱鍒板噯纭殑鍒嗗尯寮曠敤淇℃伅銆傚湪G1涓紝RSet鐨勭淮鎶や富瑕佹潵婧愪袱涓柟闈細鍐欐爡鏍?Write Barrier)鍜屽苟鍙戜紭鍖栫嚎绋?Concurrence Refinement Threads)
鏍呮爮
鏍呮爮 Barrier
鎴戜滑棣栧厛浠嬬粛涓€涓嬫爡鏍?Barrier)鐨勬蹇点€傛爡鏍忔槸鎸囧湪鍘熺敓浠g爜鐗囨涓紝褰撴煇浜涜鍙ヨ鎵ц鏃讹紝鏍呮爮浠g爜涔熶細琚墽琛屻€傝€孏1涓昏鍦ㄨ祴鍊艰鍙ヤ腑锛屼娇鐢ㄥ啓鍓嶆爡鏍?Pre-Write Barrrier)鍜屽啓鍚庢爡鏍?Post-Write Barrrier)銆備簨瀹炰笂锛屽啓鏍呮爮鐨勬寚浠ゅ簭鍒楀紑閿€闈炲父鏄傝吹锛屽簲鐢ㄥ悶鍚愰噺涔熶細鏍规嵁鏍呮爮澶嶆潅搴﹁€岄檷浣庛€?/p>
鍐欏墠鏍呮爮 Pre-Write Barrrier
鍗冲皢鎵ц涓€娈佃祴鍊艰鍙ユ椂锛岀瓑寮忓乏渚у璞″皢淇敼寮曠敤鍒板彟涓€涓璞★紝閭d箞绛夊紡宸︿晶瀵硅薄鍘熷厛寮曠敤鐨勫璞℃墍鍦ㄥ垎鍖哄皢鍥犳涓уけ涓€涓紩鐢紝閭d箞JVM灏遍渶瑕佸湪璧嬪€艰鍙ョ敓鏁堜箣鍓嶏紝璁板綍涓уけ寮曠敤鐨勫璞°€侸VM骞朵笉浼氱珛鍗崇淮鎶Set锛岃€屾槸閫氳繃鎵归噺澶勭悊锛屽湪灏嗘潵RSet鏇存柊(瑙丼ATB)銆?/p>
鍐欏悗鏍呮爮 Post-Write Barrrier
褰撴墽琛屼竴娈佃祴鍊艰鍙ュ悗锛岀瓑寮忓彸渚у璞¤幏鍙栦簡宸︿晶瀵硅薄鐨勫紩鐢紝閭d箞绛夊紡鍙充晶瀵硅薄鎵€鍦ㄥ垎鍖虹殑RSet涔熷簲璇ュ緱鍒版洿鏂般€傚悓鏍蜂负浜嗛檷浣庡紑閿€锛屽啓鍚庢爡鏍忓彂鐢熷悗锛孯Set涔熶笉浼氱珛鍗虫洿鏂帮紝鍚屾牱鍙槸璁板綍姝ゆ鏇存柊鏃ュ織锛屽湪灏嗘潵鎵归噺澶勭悊(瑙丆oncurrence Refinement Threads)銆?/p>
璧峰蹇収绠楁硶
璧峰蹇収绠楁硶 Snapshot at the beginning (SATB)
Taiichi Tuasa璐$尞鐨勫閲忓紡瀹屽叏骞跺彂鏍囪绠楁硶璧峰蹇収绠楁硶(SATB)锛屼富瑕侀拡瀵规爣璁?娓呴櫎鍨冨溇鏀堕泦鍣ㄧ殑骞跺彂鏍囪闃舵锛岄潪甯搁€傚悎G1鐨勫垎鍖哄潡鐨勫爢缁撴瀯锛屽悓鏃惰В鍐充簡CMS鐨勪富瑕佺儲鎭硷細閲嶆柊鏍囪鏆傚仠鏃堕棿闀垮甫鏉ョ殑娼滃湪椋庨櫓銆?/p>
SATB浼氬垱寤轰竴涓璞″浘锛岀浉褰撲簬鍫嗙殑閫昏緫蹇収锛屼粠鑰岀‘淇濆苟鍙戞爣璁伴樁娈垫墍鏈夌殑鍨冨溇瀵硅薄閮借兘閫氳繃蹇収琚壌鍒嚭鏉ャ€傚綋璧嬪€艰鍙ュ彂鐢熸椂锛屽簲鐢ㄥ皢浼氭敼鍙樹簡瀹冪殑瀵硅薄鍥撅紝閭d箞JVM闇€瑕佽褰曡瑕嗙洊鐨勫璞°€傚洜姝ゅ啓鍓嶆爡鏍忎細鍦ㄥ紩鐢ㄥ彉鏇村墠锛屽皢鍊艰褰曞湪SATB鏃ュ織鎴栫紦鍐插尯涓€傛瘡涓嚎绋嬮兘浼氱嫭鍗犱竴涓猄ATB缂撳啿鍖猴紝鍒濆鏈?56鏉¤褰曠┖闂淬€傚綋绌洪棿鐢ㄥ敖鏃讹紝绾跨▼浼氬垎閰嶆柊鐨凷ATB缂撳啿鍖虹户缁娇鐢紝鑰屽師鏈夌殑缂撳啿鍘诲垯鍔犲叆鍏ㄥ眬鍒楄〃涓€傛渶缁堝湪骞跺彂鏍囪闃舵锛屽苟鍙戞爣璁扮嚎绋?Concurrent Marking Threads)鍦ㄦ爣璁扮殑鍚屾椂锛岃繕浼氬畾鏈熸鏌ュ拰澶勭悊鍏ㄥ眬缂撳啿鍖哄垪琛ㄧ殑璁板綍锛岀劧鍚庢牴鎹爣璁颁綅鍥惧垎鐗囩殑鏍囪浣嶏紝鎵弿寮曠敤瀛楁鏉ユ洿鏂癛Set銆傛杩囩▼鍙堢О涓哄苟鍙戞爣璁?SATB鍐欏墠鏍呮爮銆?/p>
骞跺彂浼樺寲绾跨▼
骞跺彂浼樺寲绾跨▼ Concurrence Refinement Threads
G1涓娇鐢ㄥ熀浜嶶rs H枚lzle鐨勫揩閫熷啓鏍呮爮锛屽皢鏍呮爮寮€閿€缂╁噺鍒?涓澶栫殑鎸囦护銆傛爡鏍忓皢浼氭洿鏂颁竴涓猚ard table type鐨勭粨鏋勬潵璺熻釜浠i棿寮曠敤銆?/p>
褰撹祴鍊艰鍙ュ彂鐢熷悗锛屽啓鍚庢爡鏍忎細鍏堥€氳繃G1鐨勮繃婊ゆ妧鏈垽鏂槸鍚︽槸璺ㄥ垎鍖虹殑寮曠敤鏇存柊锛屽苟灏嗚法鍒嗗尯鏇存柊瀵硅薄鐨勫崱鐗囧姞鍏ョ紦鍐插尯搴忓垪锛屽嵆鏇存柊鏃ュ織缂撳啿鍖烘垨鑴忓崱鐗囬槦鍒椼€備笌SATB绫讳技锛屼竴鏃︽棩蹇楃紦鍐插尯鐢ㄥ敖锛屽垯鍒嗛厤涓€涓柊鐨勬棩蹇楃紦鍐插尯锛屽苟灏嗗師鏉ョ殑缂撳啿鍖哄姞鍏ュ叏灞€鍒楄〃涓€?/p>
骞跺彂浼樺寲绾跨▼(Concurrence Refinement Threads)锛屽彧涓撴敞鎵弿鏃ュ織缂撳啿鍖鸿褰曠殑鍗$墖鏉ョ淮鎶ゆ洿鏂癛Set锛岀嚎绋嬫渶澶ф暟鐩彲閫氳繃-XX:G1ConcRefinementThreads
(榛樿绛変簬-XX:ParellelGCThreads
)璁剧疆銆傚苟鍙戜紭鍖栫嚎绋嬫案杩滄槸娲昏穬鐨勶紝涓€鏃﹀彂鐜板叏灞€鍒楄〃鏈夎褰曞瓨鍦紝灏卞紑濮嬪苟鍙戝鐞嗐€傚鏋滆褰曞闀垮緢蹇垨鑰呮潵涓嶅強澶勭悊锛岄偅涔堥€氳繃闃堝€?code class="mq-176">-X:G1ConcRefinementGreenZone/-XX:G1ConcRefinementYellowZone
/-XX:G1ConcRefinementRedZone
锛孏1浼氱敤鍒嗗眰鐨勬柟寮忚皟搴︼紝浣挎洿澶氱殑绾跨▼澶勭悊鍏ㄥ眬鍒楄〃銆傚鏋滃苟鍙戜紭鍖栫嚎绋嬩篃涓嶈兘璺熶笂缂撳啿鍖烘暟閲忥紝鍒橫utator绾跨▼(Java搴旂敤绾跨▼)浼氭寕璧峰簲鐢ㄥ苟琚姞杩涙潵甯姪澶勭悊锛岀洿鍒板叏閮ㄥ鐞嗗畬銆傚洜姝わ紝蹇呴』閬垮厤姝ょ被鍦烘櫙鍑虹幇銆?/p>
骞跺彂鏍囪鍛ㄦ湡
骞跺彂鏍囪鍛ㄦ湡 Concurrent Marking Cycle
骞跺彂鏍囪鍛ㄦ湡鏄疓1涓潪甯搁噸瑕佺殑闃舵锛岃繖涓樁娈靛皢浼氫负娣峰悎鏀堕泦鍛ㄦ湡璇嗗埆鍨冨溇鏈€澶氱殑鑰佸勾浠e垎鍖恒€傛暣涓懆鏈熷畬鎴愭牴鏍囪銆佽瘑鍒墍鏈?鍙兘)瀛樻椿瀵硅薄锛屽苟璁$畻姣忎釜鍒嗗尯鐨勬椿璺冨害锛屼粠鑰岀‘瀹欸C鏁堢巼绛夌骇銆?/p>
褰撹揪鍒癐HOP闃堝€?code class="mq-183">-XX:InitiatingHeapOccupancyPercent(鑰佸勾浠e崰鏁村爢姣旓紝榛樿45%)鏃讹紝渚夸細瑙﹀彂骞跺彂鏍囪鍛ㄦ湡銆傛暣涓苟鍙戞爣璁板懆鏈熷皢鐢卞垵濮嬫爣璁?Initial Mark)銆佹牴鍒嗗尯鎵弿(Root Region Scanning)銆佸苟鍙戞爣璁?Concurrent Marking)銆侀噸鏂版爣璁?Remark)銆佹竻闄?Cleanup)鍑犱釜闃舵缁勬垚銆傚叾涓紝鍒濆鏍囪(闅忓勾杞讳唬鏀堕泦涓€璧锋椿鍔?銆侀噸鏂版爣璁般€佹竻闄ゆ槸STW鐨勶紝鑰屽苟鍙戞爣璁板鏋滄潵涓嶅強鏍囪瀛樻椿瀵硅薄锛屽垯鍙兘鍦ㄥ苟鍙戞爣璁拌繃绋嬩腑锛孏1鍙堣Е鍙戜簡鍑犳骞磋交浠f敹闆嗐€?/p>
骞跺彂鏍囪绾跨▼
骞跺彂鏍囪绾跨▼ Concurrent Marking Threads
瑕佹爣璁板瓨娲荤殑瀵硅薄锛屾瘡涓垎鍖洪兘闇€瑕佸垱寤轰綅鍥?Bitmap)淇℃伅鏉ュ瓨鍌ㄦ爣璁版暟鎹紝鏉ョ‘瀹氭爣璁板懆鏈熷唴琚垎閰嶇殑瀵硅薄銆侴1閲囩敤浜嗕袱涓綅鍥綪revious Bitmap銆丯ext Bitmap锛屾潵瀛樺偍鏍囪鏁版嵁锛孭revious浣嶅浘瀛樺偍涓婃鐨勬爣璁版暟鎹紝Next浣嶅浘鍦ㄦ爣璁板懆鏈熷唴涓嶆柇鍙樺寲鏇存柊锛屽悓鏃禤revious浣嶅浘鐨勬爣璁版暟鎹篃瓒婃潵瓒婅繃鏃讹紝褰撴爣璁板懆鏈熺粨鏉熷悗Next浣嶅浘渚挎浛鎹revious浣嶅浘锛屾垚涓轰笂娆℃爣璁扮殑浣嶅浘銆傚悓鏃讹紝姣忎釜鍒嗗尯閫氳繃椤堕儴寮€濮嬫爣璁?TAMS)锛屾潵璁板綍宸叉爣璁拌繃鐨勫唴瀛樿寖鍥淬€傚悓鏍风殑锛孏1浣跨敤浜嗕袱涓《閮ㄥ紑濮嬫爣璁癙revious TAMS(PTAMS)銆丯ext TAMS(NTAMS)锛岃褰曞凡鏍囪鐨勮寖鍥淬€?br>
鍦ㄥ苟鍙戞爣璁伴樁娈碉紝G1浼氭牴鎹弬鏁?code class="mq-190">-XX:ConcGCThreads(榛樿GC绾跨▼鏁扮殑1/4锛屽嵆-XX:ParallelGCThreads
/4)锛屽垎閰嶅苟鍙戞爣璁扮嚎绋?Concurrent Marking Threads)锛岃繘琛屾爣璁版椿鍔ㄣ€傛瘡涓苟鍙戠嚎绋嬩竴娆″彧鎵弿涓€涓垎鍖猴紝骞堕€氳繃"鎵嬫寚"鎸囬拡鐨勬柟寮忎紭鍖栬幏鍙栧垎鍖恒€傚苟鍙戞爣璁扮嚎绋嬫槸鐖嗗彂寮忕殑锛屽湪缁欏畾鐨勬椂闂存鎷煎懡骞叉椿锛岀劧鍚庝紤鎭竴娈垫椂闂达紝鍐嶆嫾鍛藉共娲汇€?/p>
鍒濆鏍囪
鍒濆鏍囪 Initial Mark
鍒濆鏍囪(Initial Mark)璐熻矗鏍囪鎵€鏈夎兘琚洿鎺ュ彲杈剧殑鏍瑰璞?鍘熺敓鏍堝璞°€佸叏灞€瀵硅薄銆丣NI瀵硅薄)锛屾牴鏄璞″浘鐨勮捣鐐癸紝鍥犳鍒濆鏍囪闇€瑕佸皢Mutator绾跨▼(Java搴旂敤绾跨▼)鏆傚仠鎺夛紝涔熷氨鏄渶瑕佷竴涓猄TW鐨勬椂闂存銆備簨瀹炰笂锛屽綋杈惧埌IHOP闃堝€兼椂锛孏1骞朵笉浼氱珛鍗冲彂璧峰苟鍙戞爣璁板懆鏈燂紝鑰屾槸绛夊緟涓嬩竴娆″勾杞讳唬鏀堕泦锛屽埄鐢ㄥ勾杞讳唬鏀堕泦鐨凷TW鏃堕棿娈碉紝瀹屾垚鍒濆鏍囪锛岃繖绉嶆柟寮忕О涓哄€熼亾(Piggybacking)銆傚湪鍒濆鏍囪鏆傚仠涓紝鍒嗗尯鐨凬TAMS閮借璁剧疆鍒板垎鍖洪《閮═op锛屽垵濮嬫爣璁版槸骞跺彂鎵ц锛岀洿鍒版墍鏈夌殑鍒嗗尯澶勭悊瀹屻€?/p>
鏍瑰垎鍖烘壂鎻?/h3>
鏍瑰垎鍖烘壂鎻?Root Region Scanning
鍦ㄥ垵濮嬫爣璁版殏鍋滅粨鏉熷悗锛屽勾杞讳唬鏀堕泦涔熷畬鎴愮殑瀵硅薄澶嶅埗鍒癝urvivor鐨勫伐浣滐紝搴旂敤绾跨▼寮€濮嬫椿璺冭捣鏉ャ€傛鏃朵负浜嗕繚璇佹爣璁扮畻娉曠殑姝g‘鎬э紝鎵€鏈夋柊澶嶅埗鍒癝urvivor鍒嗗尯鐨勫璞★紝閮介渶瑕佽鎵弿骞舵爣璁版垚鏍癸紝杩欎釜杩囩▼绉颁负鏍瑰垎鍖烘壂鎻?Root Region Scanning)锛屽悓鏃舵壂鎻忕殑Suvivor鍒嗗尯涔熻绉颁负鏍瑰垎鍖?Root Region)銆傛牴鍒嗗尯鎵弿蹇呴』鍦ㄤ笅涓€娆″勾杞讳唬鍨冨溇鏀堕泦鍚姩鍓嶅畬鎴?骞跺彂鏍囪鐨勮繃绋嬩腑锛屽彲鑳戒細琚嫢骞叉骞磋交浠e瀮鍦炬敹闆嗘墦鏂?锛屽洜涓烘瘡娆C浼氫骇鐢熸柊鐨勫瓨娲诲璞¢泦鍚堛€?/p>
骞跺彂鏍囪
骞跺彂鏍囪 Concurrent Marking
鍜屽簲鐢ㄧ嚎绋嬪苟鍙戞墽琛岋紝骞跺彂鏍囪绾跨▼鍦ㄥ苟鍙戞爣璁伴樁娈靛惎鍔紝鐢卞弬鏁?code class="mq-201">-XX:ConcGCThreads(榛樿GC绾跨▼鏁扮殑1/4锛屽嵆-XX:ParallelGCThreads
/4)鎺у埗鍚姩鏁伴噺锛屾瘡涓嚎绋嬫瘡娆″彧鎵弿涓€涓垎鍖猴紝浠庤€屾爣璁板嚭瀛樻椿瀵硅薄鍥俱€傚湪杩欎竴闃舵浼氬鐞哖revious/Next鏍囪浣嶅浘锛屾壂鎻忔爣璁板璞$殑寮曠敤瀛楁銆傚悓鏃讹紝骞跺彂鏍囪绾跨▼杩樹細瀹氭湡妫€鏌ュ拰澶勭悊STAB鍏ㄥ眬缂撳啿鍖哄垪琛ㄧ殑璁板綍锛屾洿鏂板璞″紩鐢ㄤ俊鎭€傚弬鏁?code class="mq-203">-XX:+ClassUnloadingWithConcurrentMark浼氬紑鍚竴涓紭鍖栵紝濡傛灉涓€涓被涓嶅彲杈?涓嶆槸瀵硅薄涓嶅彲杈?锛屽垯鍦ㄩ噸鏂版爣璁伴樁娈碉紝杩欎釜绫诲氨浼氳鐩存帴鍗歌浇銆傛墍鏈夌殑鏍囪浠诲姟蹇呴』鍦ㄥ爢婊″墠灏卞畬鎴愭壂鎻忥紝濡傛灉骞跺彂鏍囪鑰楁椂寰堥暱锛岄偅涔堟湁鍙兘鍦ㄥ苟鍙戞爣璁拌繃绋嬩腑锛屽張缁忓巻浜嗗嚑娆″勾杞讳唬鏀堕泦銆傚鏋滃爢婊″墠娌℃湁瀹屾垚鏍囪浠诲姟锛屽垯浼氳Е鍙戞媴淇濇満鍒讹紝缁忓巻涓€娆¢暱鏃堕棿鐨勪覆琛孎ull GC銆?/p>
瀛樻椿鏁版嵁璁$畻
瀛樻椿鏁版嵁璁$畻 Live Data Accounting
瀛樻椿鏁版嵁璁$畻(Live Data Accounting)鏄爣璁版搷浣滅殑闄勫姞浜х墿锛屽彧瑕佷竴涓璞¤鏍囪锛屽悓鏃朵細琚绠楀瓧鑺傛暟锛屽苟璁″叆鍒嗗尯绌洪棿銆傚彧鏈塏TAMS浠ヤ笅鐨勫璞′細琚爣璁板拰璁$畻锛屽湪鏍囪鍛ㄦ湡鐨勬渶鍚庯紝Next浣嶅浘灏嗚娓呯┖锛岀瓑寰呬笅娆℃爣璁板懆鏈熴€?/p>
閲嶆柊鏍囪
閲嶆柊鏍囪 Remark
閲嶆柊鏍囪(Remark)鏄渶鍚庝竴涓爣璁伴樁娈点€傚湪璇ラ樁娈典腑锛孏1闇€瑕佷竴涓殏鍋滅殑鏃堕棿锛屽幓澶勭悊鍓╀笅鐨凷ATB鏃ュ織缂撳啿鍖哄拰鎵€鏈夋洿鏂帮紝鎵惧嚭鎵€鏈夋湭琚闂殑瀛樻椿瀵硅薄锛屽悓鏃跺畨鍏ㄥ畬鎴愬瓨娲绘暟鎹绠椼€傝繖涓樁娈典篃鏄苟琛屾墽琛岀殑锛岄€氳繃鍙傛暟-XX:ParallelGCThread
鍙缃瓽C鏆傚仠鏃跺彲鐢ㄧ殑GC绾跨▼鏁般€傚悓鏃讹紝寮曠敤澶勭悊涔熸槸閲嶆柊鏍囪闃舵鐨勪竴閮ㄥ垎锛屾墍鏈夐噸搴︿娇鐢ㄥ紩鐢ㄥ璞?寮卞紩鐢ㄣ€佽蒋寮曠敤銆佽櫄寮曠敤銆佹渶缁堝紩鐢?鐨勫簲鐢ㄩ兘浼氬湪寮曠敤澶勭悊涓婁骇鐢熷紑閿€銆?/p>
娓呴櫎
娓呴櫎 Cleanup
绱ф尐鐫€閲嶆柊鏍囪闃舵鐨勬竻闄?Clean)闃舵涔熸槸STW鐨勩€侾revious/Next鏍囪浣嶅浘銆佷互鍙奝TAMS/NTAMS锛岄兘浼氬湪娓呴櫎闃舵浜ゆ崲瑙掕壊銆傛竻闄ら樁娈典富瑕佹墽琛屼互涓嬫搷浣滐細
RSet姊崇悊锛屽惎鍙戝紡绠楁硶浼氭牴鎹椿璺冨害鍜孯Set灏哄瀵瑰垎鍖哄畾涔変笉鍚岀瓑绾э紝鍚屾椂RSet鏁扮悊涔熸湁鍔╀簬鍙戠幇鏃犵敤鐨勫紩鐢ㄣ€傚弬鏁?code class="mq-215">-XX:+PrintAdaptiveSizePolicy鍙互寮€鍚墦鍗板惎鍙戝紡绠楁硶鍐崇瓥缁嗚妭锛?/p>
鏁寸悊鍫嗗垎鍖猴紝涓烘贩鍚堟敹闆嗗懆鏈熻瘑鍒洖鏀舵敹鐩婇珮(鍩轰簬閲婃斁绌洪棿鍜屾殏鍋滅洰鏍?鐨勮€佸勾浠e垎鍖洪泦鍚堬紱
璇嗗埆鎵€鏈夌┖闂插垎鍖猴紝鍗冲彂鐜版棤瀛樻椿瀵硅薄鐨勫垎鍖恒€傝鍒嗗尯鍙湪娓呴櫎闃舵鐩存帴鍥炴敹锛屾棤闇€绛夊緟涓嬫鏀堕泦鍛ㄦ湡銆?/p>
骞磋交浠f敹闆?娣峰悎鏀堕泦鍛ㄦ湡
骞磋交浠f敹闆嗗拰娣峰悎鏀堕泦鍛ㄦ湡锛屾槸G1鍥炴敹绌洪棿鐨勪富瑕佹椿鍔ㄣ€傚綋搴旂敤杩愯寮€濮嬫椂锛屽爢鍐呭瓨鍙敤绌洪棿杩樻瘮杈冨ぇ锛屽彧浼氬湪骞磋交浠f弧鏃讹紝瑙﹀彂骞磋交浠f敹闆嗭紱闅忕潃鑰佸勾浠e唴瀛樺闀匡紝褰撳埌杈綢HOP闃堝€?code class="mq-218">-XX:InitiatingHeapOccupancyPercent(鑰佸勾浠e崰鏁村爢姣旓紝榛樿45%)鏃讹紝G1寮€濮嬬潃鎵嬪噯澶囨敹闆嗚€佸勾浠g┖闂淬€傞鍏堢粡鍘嗗苟鍙戞爣璁板懆鏈燂紝璇嗗埆鍑洪珮鏀剁泭鐨勮€佸勾浠e垎鍖猴紝鍓嶆枃宸茶堪銆備絾闅忓悗G1骞朵笉浼氶┈涓婂紑濮嬩竴娆℃贩鍚堟敹闆嗭紝鑰屾槸璁╁簲鐢ㄧ嚎绋嬪厛杩愯涓€娈垫椂闂达紝绛夊緟瑙﹀彂涓€娆″勾杞讳唬鏀堕泦銆傚湪杩欐STW涓紝G1灏嗕繚鍑嗘暣鐞嗘贩鍚堟敹闆嗗懆鏈熴€傛帴鐫€鍐嶆璁╁簲鐢ㄧ嚎绋嬭繍琛岋紝褰撴帴涓嬫潵鐨勫嚑娆″勾杞讳唬鏀堕泦鏃讹紝灏嗕細鏈夎€佸勾浠e垎鍖哄姞鍏ュ埌CSet涓紝鍗宠Е鍙戞贩鍚堟敹闆嗭紝杩欎簺杩炵画澶氭鐨勬贩鍚堟敹闆嗙О涓烘贩鍚堟敹闆嗗懆鏈?Mixed Collection Cycle)銆?/p>
GC宸ヤ綔绾跨▼鏁?/h3>
GC宸ヤ綔绾跨▼鏁?-XX:ParallelGCThreads
JVM鍙互閫氳繃鍙傛暟-XX:ParallelGCThreads
杩涜鎸囧畾GC宸ヤ綔鐨勭嚎绋嬫暟閲忋€傚弬鏁?code class="mq-223">-XX:ParallelGCThreads榛樿鍊煎苟涓嶆槸鍥哄畾鐨勶紝鑰屾槸鏍规嵁褰撳墠鐨凜PU璧勬簮杩涜璁$畻銆傚鏋滅敤鎴锋病鏈夋寚瀹氾紝涓擟PU灏忎簬绛変簬8锛屽垯榛樿涓嶤PU鏍告暟鐩哥瓑锛涜嫢CPU澶т簬8锛屽垯榛樿JVM浼氱粡杩囪绠楀緱鍒颁竴涓皬浜嶤PU鏍告暟鐨勭嚎绋嬫暟锛涘綋鐒朵篃鍙互浜哄伐鎸囧畾涓嶤PU鏍告暟鐩哥瓑銆?/p>
骞磋交浠f敹闆?/h3>
骞磋交浠f敹闆?Young Collection
姣忔鏀堕泦杩囩▼涓紝鏃㈡湁骞惰鎵ц鐨勬椿鍔紝涔熸湁涓茶鎵ц鐨勬椿鍔紝浣嗛兘鍙互鏄绾跨▼鐨勩€傚湪骞惰鎵ц鐨勪换鍔′腑锛屽鏋滄煇涓换鍔¤繃閲嶏紝浼氬鑷村叾浠栫嚎绋嬪湪绛夊緟鏌愰」浠诲姟鐨勫鐞嗭紝闇€瑕佸杩欎簺鍦版柟杩涜浼樺寲銆?/p>
骞惰娲诲姩
澶栭儴鏍瑰垎鍖烘壂鎻?Ext Root Scanning锛氭娲诲姩瀵瑰爢澶栫殑鏍?JVM绯荤粺鐩綍銆乂M鏁版嵁缁撴瀯銆丣NI绾跨▼鍙ユ焺銆佺‖浠跺瘎瀛樺櫒銆佸叏灞€鍙橀噺銆佺嚎绋嬪鏍堟牴)杩涜鎵弿锛屽彂鐜伴偅浜涙病鏈夊姞鍏ュ埌鏆傚仠鏀堕泦闆嗗悎CSet涓殑瀵硅薄銆傚鏋滅郴缁熺洰褰?鍗曟牴)鎷ユ湁澶ч噺鍔犺浇鐨勭被锛屾渶缁堝彲鑳藉叾浠栧苟琛屾椿鍔ㄧ粨鏉熷悗锛岃娲诲姩渚濈劧娌℃湁缁撴潫鑰屽甫鏉ョ殑绛夊緟鏃堕棿銆?/p>
鏇存柊宸茶蹇嗛泦鍚?Update RS锛氬苟鍙戜紭鍖栫嚎绋嬩細瀵硅剰鍗$墖鐨勫垎鍖鸿繘琛屾壂鎻忔洿鏂版棩蹇楃紦鍐插尯鏉ユ洿鏂癛Set锛屼絾鍙細澶勭悊鍏ㄥ眬缂撳啿鍒楄〃銆備綔涓鸿ˉ鍏咃紝鎵€鏈夎璁板綍浣嗘槸杩樻病鏈夎浼樺寲绾跨▼澶勭悊鐨勫墿浣欑紦鍐插尯锛屼細鍦ㄨ闃舵澶勭悊锛屽彉鎴愬凡澶勭悊缂撳啿鍖?Processed Buffers)銆備负浜嗛檺鍒惰姳鍦ㄦ洿鏂癛Set鐨勬椂闂达紝鍙互璁剧疆鏆傚仠鍗犵敤鐧惧垎姣?code class="mq-230">-XX:G1RSetUpdatingPauseTimePercent(榛樿10%锛屽嵆-XX:MaxGCPauseMills
/10)銆傚€煎緱娉ㄦ剰鐨勬槸锛屽鏋滄洿鏂版棩蹇楃紦鍐插尯鏇存柊鐨勪换鍔′笉闄嶄綆锛屽崟绾湴鍑忓皯RSet鐨勬洿鏂版椂闂达紝浼氬鑷存殏鍋滀腑琚鐞嗙殑缂撳啿鍖哄噺灏戯紝灏嗘棩蹇楃紦鍐插尯鏇存柊宸ヤ綔鎺ㄥ埌骞跺彂浼樺寲绾跨▼涓婏紝浠庤€屽鍔犲Java搴旂敤绾跨▼璧勬簮鐨勪簤澶恒€?/p>
RSet鎵弿 Scan RS锛氬湪鏀堕泦褰撳墠CSet涔嬪墠锛岃€冭檻鍒板垎鍖哄鐨勫紩鐢紝蹇呴』鎵弿CSet鍒嗗尯鐨凴Set銆傚鏋淩Set鍙戠敓绮楀寲锛屽垯浼氬鍔燫Set鐨勬壂鎻忔椂闂淬€傚紑鍚瘖鏂ā寮?code class="mq-233">-XX:UnlockDiagnosticVMOptions鍚庯紝閫氳繃鍙傛暟-XX:+G1SummarizeRSetStats
鍙互纭畾骞跺彂浼樺寲绾跨▼鏄惁鑳藉鍙婃椂澶勭悊鏇存柊鏃ュ織缂撳啿鍖猴紝骞舵彁渚涙洿澶氱殑淇℃伅锛屾潵甯姪涓篟Set绮楀寲鎬绘暟鎻愪緵绐楀彛銆傚弬鏁?code class="mq-235">-XX锛欸1SummarizeRSetStatsPeriod=n鍙缃甊Set鐨勭粺璁″懆鏈燂紝鍗崇粡鍘嗗灏戞GC鍚庤繘琛屼竴娆$粺璁?/p>
浠g爜鏍规壂鎻?Code Root Scanning锛氬浠g爜鏍归泦鍚堣繘琛屾壂鎻忥紝鎵弿JVM缂栬瘧鍚庝唬鐮丯ative Method鐨勫紩鐢ㄤ俊鎭?nmethod鎵弿)锛岃繘琛孯Set鎵弿銆備簨瀹炰笂锛屽彧鏈塁Set鍒嗗尯涓殑RSet鏈夊己浠g爜鏍规椂锛屾墠浼氬仛nmethod鎵弿锛屾煡鎵惧CSet鐨勫紩鐢ㄣ€?/p>
杞Щ鍜屽洖鏀?Object Copy锛氶€氳繃閫夊畾鐨凜Set浠ュ強CSet鍒嗗尯瀹屾暣鐨勫紩鐢ㄩ泦锛屽皢鎵ц鏆傚仠鏃堕棿鐨勪富瑕侀儴鍒嗭細CSet鍒嗗尯瀛樻椿瀵硅薄鐨勮浆绉汇€丆Set鍒嗗尯绌洪棿鐨勫洖鏀躲€傞€氳繃宸ヤ綔绐冨彇鏈哄埗鏉ヨ礋杞藉潎琛″湴閫夊畾澶嶅埗瀵硅薄鐨勭嚎绋嬶紝骞朵笖澶嶅埗鍜屾壂鎻忓璞¤杞Щ鐨勫瓨娲诲璞″皢鎷疯礉鍒版瘡涓狦C绾跨▼鍒嗛厤缂撳啿鍖篏CLAB銆侴1浼氶€氳繃璁$畻锛岄娴嬪垎鍖哄鍒舵墍鑺辫垂鐨勬椂闂达紝浠庤€岃皟鏁村勾杞讳唬鐨勫昂瀵搞€?/p>
缁堟 Termination锛氬畬鎴愪笂杩颁换鍔″悗锛屽鏋滀换鍔¢槦鍒楀凡绌猴紝鍒欏伐浣滅嚎绋嬩細鍙戣捣缁堟瑕佹眰銆傚鏋滆繕鏈夊叾浠栫嚎绋嬬户缁伐浣滐紝绌洪棽鐨勭嚎绋嬩細閫氳繃宸ヤ綔绐冨彇鏈哄埗灏濊瘯甯姪鍏朵粬绾跨▼澶勭悊銆傝€屽崟鐙墽琛屾牴鍒嗗尯鎵弿鐨勭嚎绋嬶紝濡傛灉浠诲姟杩囬噸锛屾渶缁堜細鏅氫簬缁堟銆?/p>
GC澶栭儴鐨勫苟琛屾椿鍔?GC Worker Other锛氳閮ㄥ垎骞堕潪GC鐨勬椿鍔紝鑰屾槸JVM鐨勬椿鍔ㄥ鑷村崰鐢ㄤ簡GC鏆傚仠鏃堕棿(渚嬪JNI缂栬瘧)銆?/p>
涓茶娲诲姩
浠g爜鏍规洿鏂?Code Root Fixup锛氭牴鎹浆绉诲璞℃洿鏂颁唬鐮佹牴銆?/p>
浠g爜鏍规竻鐞?Code Root Purge锛氭竻鐞嗕唬鐮佹牴闆嗗悎琛ㄣ€?/p>
娓呴櫎鍏ㄥ眬鍗$墖鏍囪 Clear CT锛氬湪浠绘剰鏀堕泦鍛ㄦ湡浼氭壂鎻廋Set涓嶳Set璁板綍鐨凱RT锛屾壂鎻忔椂浼氬湪鍏ㄥ眬鍗$墖琛ㄤ腑杩涜鏍囪锛岄槻姝㈤噸澶嶆壂鎻忋€傚湪鏀堕泦鍛ㄦ湡鐨勬渶鍚庡皢浼氭竻闄ゅ叏灞€鍗$墖琛ㄤ腑鐨勫凡鎵弿鏍囧織銆?/p>
閫夋嫨涓嬫鏀堕泦闆嗗悎 Choose CSet锛氳閮ㄥ垎涓昏鐢ㄤ簬骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆嗐€佷互鍙婃贩鍚堟敹闆嗕腑锛屽湪杩欎簺鏀堕泦杩囩▼涓紝鐢变簬鏈夎€佸勾浠e€欓€夊垎鍖虹殑鍔犲叆锛屽線寰€闇€瑕佸涓嬫鏀堕泦鐨勮寖鍥村仛鍑虹晫瀹氾紱浣嗗崟绾殑骞磋交浠f敹闆嗕腑锛屾墍鏈夋敹闆嗙殑鍒嗗尯閮戒細琚敹闆嗭紝涓嶅瓨鍦ㄩ€夋嫨銆?/p>
寮曠敤澶勭悊 Ref Proc锛氫富瑕侀拡瀵硅蒋寮曠敤銆佸急寮曠敤銆佽櫄寮曠敤銆乫inal寮曠敤銆丣NI寮曠敤銆傚綋Ref Proc鍗犵敤鏃堕棿杩囧鏃讹紝鍙€夋嫨浣跨敤鍙傛暟-XX:ParallelRefProcEnabled
婵€娲诲绾跨▼寮曠敤澶勭悊銆侴1甯屾湜搴旂敤鑳藉皬蹇冧娇鐢ㄨ蒋寮曠敤锛屽洜涓鸿蒋寮曠敤浼氫竴鐩村崰鎹唴瀛樼┖闂寸洿鍒扮┖闂磋€楀敖鏃惰Full GC鍥炴敹鎺夛紱鍗充娇鏈彂鐢烣ull GC锛岃蒋寮曠敤瀵瑰唴瀛樼殑鍗犵敤锛屼篃浼氬鑷碐C娆℃暟鐨勫鍔犮€?/p>
寮曠敤鎺掗槦 Ref Enq锛氭椤规椿鍔ㄥ彲鑳戒細瀵艰嚧RSet鐨勬洿鏂帮紝姝ゆ椂浼氶€氳繃璁板綍鏃ュ織锛屽皢鍏宠仈鐨勫崱鐗囨爣璁颁负鑴忓崱鐗囥€?/p>
鍗$墖閲嶆柊鑴忓寲 Redirty Cards锛氶噸鏂拌剰鍖栧崱鐗囥€?/p>
鍥炴敹绌洪棽宸ㄥ瀷鍒嗗尯 Humongous Reclaim锛欸1鍋氫簡涓€涓紭鍖栵細閫氳繃鏌ョ湅鎵€鏈夋牴瀵硅薄浠ュ強骞磋交浠e垎鍖虹殑RSet锛屽鏋滅‘瀹歊Set涓法鍨嬪璞℃病鏈変换浣曞紩鐢紝鍒欒鏄嶨1鍙戠幇浜嗕竴涓笉鍙揪鐨勫法鍨嬪璞★紝璇ュ璞″垎鍖轰細琚洖鏀躲€?/p>
閲婃斁鍒嗗尯 Free CSet锛氬洖鏀禖Set鍒嗗尯鐨勬墍鏈夌┖闂达紝骞跺姞鍏ュ埌绌洪棽鍒嗗尯涓€?/p>
鍏朵粬娲诲姩 Other锛欸C涓彲鑳借繕浼氱粡鍘嗗叾浠栬€楁椂寰堝皬鐨勬椿鍔紝濡備慨澶岼NI鍙ユ焺绛夈€?/p>
骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆?/h3>
骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆?Young Collection Following Concurrent Marking Cycle
褰揋1鍙戣捣骞跺彂鏍囪鍛ㄦ湡涔嬪悗锛屽苟涓嶄細椹笂寮€濮嬫贩鍚堟敹闆嗐€侴1浼氬厛绛夊緟涓嬩竴娆″勾杞讳唬鏀堕泦锛岀劧鍚庡湪璇ユ敹闆嗛樁娈典腑锛岀‘瀹氫笅娆℃贩鍚堟敹闆嗙殑CSet(Choose CSet)銆?/p>
娣峰悎鏀堕泦鍛ㄦ湡
娣峰悎鏀堕泦鍛ㄦ湡 Mixed Collection Cycle
鍗曟鐨勬贩鍚堟敹闆嗕笌骞磋交浠f敹闆嗗苟鏃犱簩鑷淬€傛牴鎹殏鍋滅洰鏍囷紝鑰佸勾浠g殑鍒嗗尯鍙兘涓嶈兘涓€娆℃殏鍋滄敹闆嗕腑琚鐞嗗畬锛孏1浼氬彂璧疯繛缁娆$殑娣峰悎鏀堕泦锛岀О涓烘贩鍚堟敹闆嗗懆鏈?Mixed Collection Cycle)銆侴1浼氳绠楁瘡娆″姞鍏ュ埌CSet涓殑鍒嗗尯鏁伴噺銆佹贩鍚堟敹闆嗚繘琛屾鏁帮紝骞朵笖鍦ㄤ笂娆$殑骞磋交浠f敹闆嗐€佷互鍙婃帴涓嬫潵鐨勬贩鍚堟敹闆嗕腑锛孏1浼氱‘瀹氫笅娆″姞鍏Set鐨勫垎鍖洪泦(Choose CSet)锛屽苟涓旂‘瀹氭槸鍚︾粨鏉熸贩鍚堟敹闆嗗懆鏈熴€?/p>
杞Щ澶辫触鐨勬媴淇濇満鍒?Full GC
杞Щ澶辫触鐨勬媴淇濇満鍒?Full GC
杞Щ澶辫触(Evacuation Failure)鏄寚褰揋1鏃犳硶鍦ㄥ爢绌洪棿涓敵璇锋柊鐨勫垎鍖烘椂锛孏1渚夸細瑙﹀彂鎷呬繚鏈哄埗锛屾墽琛屼竴娆TW寮忕殑銆佸崟绾跨▼鐨凢ull GC銆侳ull GC浼氬鏁村爢鍋氭爣璁版竻闄ゅ拰鍘嬬缉锛屾渶鍚庡皢鍙寘鍚函绮圭殑瀛樻椿瀵硅薄銆傚弬鏁?code class="mq-261">-XX:G1ReservePercent(榛樿10%)鍙互淇濈暀绌洪棿锛屾潵搴斿鏅嬪崌妯″紡涓嬬殑寮傚父鎯呭喌锛屾渶澶у崰鐢ㄦ暣鍫?0%锛屾洿澶т篃鏃犳剰涔夈€?/p>
G1鍦ㄤ互涓嬪満鏅腑浼氳Е鍙慒ull GC锛屽悓鏃朵細鍦ㄦ棩蹇椾腑璁板綍to-space-exhausted浠ュ強Evacuation Failure锛?/p>
浠庡勾杞讳唬鍒嗗尯鎷疯礉瀛樻椿瀵硅薄鏃讹紝鏃犳硶鎵惧埌鍙敤鐨勭┖闂插垎鍖?/p>
浠庤€佸勾浠e垎鍖鸿浆绉诲瓨娲诲璞℃椂锛屾棤娉曟壘鍒板彲鐢ㄧ殑绌洪棽鍒嗗尯
鍒嗛厤宸ㄥ瀷瀵硅薄鏃跺湪鑰佸勾浠f棤娉曟壘鍒拌冻澶熺殑杩炵画鍒嗗尯
鐢变簬G1鐨勫簲鐢ㄥ満鍚堝線寰€鍫嗗唴瀛橀兘姣旇緝澶э紝鎵€浠ull GC鐨勬敹闆嗕唬浠烽潪甯告槀璐碉紝搴旇閬垮厤Full GC鐨勫彂鐢熴€?/p>
绗簲绔?鎬荤粨
G1鏄竴娆鹃潪甯镐紭绉€鐨勫瀮鍦炬敹闆嗗櫒锛屼笉浠呴€傚悎鍫嗗唴瀛樺ぇ鐨勫簲鐢紝鍚屾椂涔熺畝鍖栦簡璋冧紭鐨勫伐浣溿€傞€氳繃涓昏鐨勫弬鏁板垵濮嬪拰鏈€澶у爢绌洪棿銆佷互鍙婃渶澶у蹇嶇殑GC鏆傚仠鐩爣锛屽氨鑳藉緱鍒颁笉閿欑殑鎬ц兘锛涘悓鏃讹紝鎴戜滑涔熺湅鍒癎1瀵瑰唴瀛樼┖闂寸殑娴垂杈冮珮锛屼絾閫氳繃**棣栧厛鏀堕泦灏藉彲鑳藉鐨勫瀮鍦?Garbage First)**鐨勮璁″師鍒欙紝鍙互鍙婃椂鍙戠幇杩囨湡瀵硅薄锛屼粠鑰岃鍐呭瓨鍗犵敤澶勪簬鍚堢悊鐨勬按骞炽€?/p>
鍙傝€冭祫鏂?/p>
[1] Charlie H, Monica B, Poonam P, Bengt R. Java Performance Companion
[2] 鍛ㄥ織鏄? 娣卞叆鐞嗚ВJVM铏氭嫙鏈?/p>
https://www.cnblogs.com/jobbible/p/13476128.html
-娣卞叆鍘熺悊-
鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧
以上是关于璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1>
Posted 娣卞叆鍘熺悊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1>
鐐瑰嚮馃憜钃濊壊鈥?nbsp;娣卞叆鍘熺悊鈥濓紝鍏虫敞骞垛€?/span>璁句负鏄熸爣鈥?/span>
鎶€鏈共璐э紝绗竴鏃堕棿鎺ㄩ€?/span>
鍓嶈█
Garbage First(G1)鏄瀮鍦炬敹闆嗛鍩熺殑鏈€鏂版垚鏋滐紝鍚屾椂涔熸槸HotSpot鍦↗VM涓婂姏鎺ㄧ殑鍨冨溇鏀堕泦鍣紝骞惰祴浜堝彇浠MS鐨勪娇鍛姐€傚鏋滀娇鐢↗ava 8/9锛岄偅涔堟湁寰堝ぇ鍙兘甯屾湜瀵笹1鏀堕泦鍣ㄨ繘琛岃瘎浼般€傛湰鏂囪缁嗛鍏堝JVM鍏朵粬鐨勫瀮鍦炬敹闆嗗櫒杩涜鎬荤粨锛屽苟涓嶨1杩涜浜嗙畝鍗曠殑瀵规瘮锛涚劧鍚庨€氳繃G1鐨勫唴瀛樻ā鍨嬨€丟1鐨勬椿鍔ㄥ懆鏈燂紝瀵笹1鐨勫伐浣滄満鍒惰繘琛屼簡浠嬬粛锛涘悓鏃惰繕鍦ㄤ粙缁嶈繃绋嬩腑锛屾弿杩颁簡鍙兘闇€瑕佸紩璧锋敞鎰忕殑浼樺寲鐐广€傜瑪鑰呭笇鏈涢€氳繃鏈枃锛岃鏈変竴瀹欽VM鍩虹鐨勮鑰呰兘灏藉揩鎺屾彙G1鐨勭煡璇嗙偣銆?/p>
绗竴绔?姒傝堪
G1(Garbage First)鍨冨溇鏀堕泦鍣ㄦ槸褰撲粖鍨冨溇鍥炴敹鎶€鏈渶鍓嶆部鐨勬垚鏋滀箣涓€銆傛棭鍦↗DK7灏卞凡鍔犲叆JVM鐨勬敹闆嗗櫒澶у搴腑锛屾垚涓篐otSpot閲嶇偣鍙戝睍鐨勫瀮鍦惧洖鏀舵妧鏈€傚悓浼樼鐨凜MS鍨冨溇鍥炴敹鍣ㄤ竴鏍凤紝G1涔熸槸鍏虫敞鏈€灏忔椂寤剁殑鍨冨溇鍥炴敹鍣紝涔熷悓鏍烽€傚悎澶у昂瀵稿爢鍐呭瓨鐨勫瀮鍦炬敹闆嗭紝瀹樻柟涔熸帹鑽愪娇鐢℅1鏉ヤ唬鏇块€夋嫨CMS銆侴1鏈€澶х殑鐗圭偣鏄紩鍏ュ垎鍖虹殑鎬濊矾锛屽急鍖栦簡鍒嗕唬鐨勬蹇碉紝鍚堢悊鍒╃敤鍨冨溇鏀堕泦鍚勪釜鍛ㄦ湡鐨勮祫婧愶紝瑙e喅浜嗗叾浠栨敹闆嗗櫒鐢氳嚦CMS鐨勪紬澶氱己闄枫€?/p>
绗簩绔?JVM GC鏀堕泦鍣ㄧ殑鍥為【涓庢瘮杈?/h1>
鍥句腑灞曠ず浜?绉嶄笉鍚屽垎浠g殑鏀堕泦鍣細
Serial銆丳arNew銆丳arallel Scavenge銆丼erial Old銆丳arallel Old銆丆MS銆丟1锛?/p>
鑰屽畠浠墍澶勫尯鍩燂紝鍒欒〃鏄庡叾鏄睘浜庢柊鐢熶唬鏀堕泦鍣ㄨ繕鏄€佸勾浠f敹闆嗗櫒锛?/p>
鏂扮敓浠f敹闆嗗櫒锛歋erial銆丳arNew銆丳arallel Scavenge锛?/p>
鑰佸勾浠f敹闆嗗櫒锛歋erial Old銆丳arallel Old銆丆MS锛?/p>
鏁村爢鏀堕泦鍣細G1锛?/p>
涓や釜鏀堕泦鍣ㄩ棿鏈夎繛绾匡紝琛ㄦ槑瀹冧滑鍙互鎼厤浣跨敤锛?/p>
Serial/Serial Old銆丼erial/CMS銆丳arNew/Serial Old銆丳arNew/CMS銆丳arallel Scavenge/Serial Old銆丳arallel Scavenge/Parallel Old銆丟1锛?/p>
涓茶鏀堕泦鍣?/h2>
涓茶鏀堕泦鍣ㄧ粍鍚?Serial + Serial Old
寮€鍚€夐」锛?code class="mq-43">-XX:+SerialGC
涓茶鏀堕泦鍣ㄦ槸鏈€鍩烘湰銆佸彂灞曟椂闂存渶闀裤€佷箙缁忚€冮獙鐨勫瀮鍦炬敹闆嗗櫒锛屼篃鏄痗lient妯″紡涓嬬殑榛樿鏀堕泦鍣ㄩ厤缃€?/p>
涓茶鏀堕泦鍣ㄩ噰鐢ㄥ崟绾跨▼stop-the-world鐨勬柟寮忚繘琛屾敹闆嗐€傚綋鍐呭瓨涓嶈冻鏃讹紝涓茶GC璁剧疆鍋滈】鏍囪瘑锛屽緟鎵€鏈夌嚎绋嬮兘杩涘叆瀹夊叏鐐?Safepoint)鏃讹紝搴旂敤绾跨▼鏆傚仠锛屼覆琛孏C寮€濮嬪伐浣滐紝閲囩敤鍗曠嚎绋嬫柟寮忓洖鏀剁┖闂村苟鏁寸悊鍐呭瓨銆傚崟绾跨▼涔熸剰鍛崇潃澶嶆潅搴︽洿浣庛€佸崰鐢ㄥ唴瀛樻洿灏戯紝浣嗗悓鏃朵篃鎰忓懗鐫€涓嶈兘鏈夋晥鍒╃敤澶氭牳浼樺娍銆備簨瀹炰笂锛屼覆琛屾敹闆嗗櫒鐗瑰埆閫傚悎鍫嗗唴瀛樹笉楂樸€佸崟鏍哥敋鑷冲弻鏍窩PU鐨勫満鍚堛€?/p>
骞惰鏀堕泦鍣?/h2>
骞惰鏀堕泦鍣ㄧ粍鍚?Parallel Scavenge + Parallel Old
寮€鍚€夐」锛?code class="mq-51">-XX:+UseParallelGC鎴?code class="mq-52">-XX:+UseParallelOldGC(鍙簰鐩告縺娲?
骞惰鏀堕泦鍣ㄦ槸浠ュ叧娉ㄥ悶鍚愰噺涓虹洰鏍囩殑鍨冨溇鏀堕泦鍣紝涔熸槸server妯″紡涓嬬殑榛樿鏀堕泦鍣ㄩ厤缃紝瀵瑰悶鍚愰噺鐨勫叧娉ㄤ富瑕佷綋鐜板湪骞磋交浠arallel Scavenge鏀堕泦鍣ㄤ笂銆?/p>
骞惰鏀堕泦鍣ㄤ笌涓茶鏀堕泦鍣ㄥ伐浣滄ā寮忕浉浼硷紝閮芥槸stop-the-world鏂瑰紡锛屽彧鏄殏鍋滄椂骞惰鍦拌繘琛屽瀮鍦炬敹闆嗐€傚勾杞讳唬閲囩敤澶嶅埗绠楁硶锛岃€佸勾浠i噰鐢ㄦ爣璁?鏁寸悊锛屽湪鍥炴敹鐨勫悓鏃惰繕浼氬鍐呭瓨杩涜鍘嬬缉銆傚叧娉ㄥ悶鍚愰噺涓昏鎸囧勾杞讳唬鐨凱arallel Scavenge鏀堕泦鍣紝閫氳繃涓や釜鐩爣鍙傛暟-XX:MaxGCPauseMills
鍜?code class="mq-56">-XX:GCTimeRatio锛岃皟鏁存柊鐢熶唬绌洪棿澶у皬锛屾潵闄嶄綆GC瑙﹀彂鐨勯鐜囥€傚苟琛屾敹闆嗗櫒閫傚悎瀵瑰悶鍚愰噺瑕佹眰杩滆繙楂樹簬寤惰繜瑕佹眰鐨勫満鏅紝骞朵笖鍦ㄦ弧瓒虫渶宸欢鏃剁殑鎯呭喌涓嬶紝骞惰鏀堕泦鍣ㄥ皢鎻愪緵鏈€浣崇殑鍚炲悙閲忋€?/p>
骞跺彂鏍囪娓呴櫎鏀堕泦鍣?/h2>
骞跺彂鏍囪娓呴櫎鏀堕泦鍣ㄧ粍鍚?ParNew + CMS + Serial Old
寮€鍚€夐」锛?code class="mq-61">-XX:+UseConcMarkSweepGC
骞跺彂鏍囪娓呴櫎(CMS)鏄互鍏虫敞寤惰繜涓虹洰鏍囥€佸崄鍒嗕紭绉€鐨勫瀮鍦惧洖鏀剁畻娉曪紝寮€鍚悗锛屽勾杞讳唬浣跨敤STW寮忕殑骞惰鏀堕泦锛岃€佸勾浠e洖鏀堕噰鐢–MS杩涜鍨冨溇鍥炴敹锛屽寤惰繜鐨勫叧娉ㄤ篃涓昏浣撶幇鍦ㄨ€佸勾浠MS涓娿€?/p>
骞磋交浠arNew涓庡苟琛屾敹闆嗗櫒绫讳技锛岃€岃€佸勾浠MS姣忎釜鏀堕泦鍛ㄦ湡閮借缁忓巻锛?span>鍒濆鏍囪銆佸苟鍙戞爣璁般€侀噸鏂版爣璁般€佸苟鍙戞竻闄?/strong>銆傚叾涓紝鍒濆鏍囪浠TW鐨勬柟寮忔爣璁版墍鏈夌殑鏍瑰璞★紱骞跺彂鏍囪鍒欏悓搴旂敤绾跨▼涓€璧峰苟琛岋紝鏍囪鍑烘牴瀵硅薄鐨勫彲杈捐矾寰勶紱鍦ㄨ繘琛屽瀮鍦惧洖鏀跺墠锛孋MS鍐嶄互涓€涓猄TW杩涜閲嶆柊鏍囪锛屾爣璁伴偅浜涚敱mutator绾跨▼(鎸囧紩璧锋暟鎹彉鍖栫殑绾跨▼锛屽嵆搴旂敤绾跨▼)淇敼鑰屽彲鑳介敊杩囩殑鍙揪瀵硅薄锛涙渶鍚庡緱鍒扮殑涓嶅彲杈惧璞″皢鍦ㄥ苟鍙戞竻闄ら樁娈佃繘琛屽洖鏀躲€?span>鍊煎緱娉ㄦ剰鐨勬槸锛屽垵濮嬫爣璁板拰閲嶆柊鏍囪閮藉凡浼樺寲涓哄绾跨▼鎵ц銆侰MS闈炲父閫傚悎鍫嗗唴瀛樺ぇ銆丆PU鏍告暟澶氱殑鏈嶅姟鍣ㄧ搴旂敤锛屼篃鏄疓1鍑虹幇涔嬪墠澶у瀷搴旂敤鐨勯閫夋敹闆嗗櫒銆?/p>
浣嗘槸CMS骞朵笉瀹岀編锛屽畠鏈変互涓嬬己鐐癸細
鐢变簬骞跺彂杩涜锛孋MS鍦ㄦ敹闆嗕笌搴旂敤绾跨▼浼氬悓鏃朵細澧炲姞瀵瑰爢鍐呭瓨鐨勫崰鐢紝涔熷氨鏄锛孋MS蹇呴』瑕佸湪鑰佸勾浠e爢鍐呭瓨鐢ㄥ敖涔嬪墠瀹屾垚鍨冨溇鍥炴敹锛屽惁鍒機MS鍥炴敹澶辫触鏃讹紝灏嗚Е鍙戞媴淇濇満鍒讹紝涓茶鑰佸勾浠f敹闆嗗櫒灏嗕細浠TW鐨勬柟寮忚繘琛屼竴娆C锛屼粠鑰岄€犳垚杈冨ぇ鍋滈】鏃堕棿锛?/p>
鏍囪娓呴櫎绠楁硶鏃犳硶鏁寸悊绌洪棿纰庣墖锛岃€佸勾浠g┖闂翠細闅忕潃搴旂敤鏃堕暱琚€愭鑰楀敖锛屾渶鍚庡皢涓嶅緱涓嶉€氳繃鎷呬繚鏈哄埗瀵瑰爢鍐呭瓨杩涜鍘嬬缉銆侰MS涔熸彁渚涗簡鍙傛暟
-XX:CMSFullGCsBeForeCompaction
(榛樿0锛屽嵆姣忔閮借繘琛屽唴瀛樻暣鐞?鏉ユ寚瀹氬灏戞CMS鏀堕泦涔嬪悗锛岃繘琛屼竴娆″帇缂╃殑Full GC銆?/p>
Garbage First
Garbage First (G1)
寮€鍚€夐」锛?code class="mq-72">-XX:+UseG1GC
涔嬪墠浠嬬粛鐨勫嚑缁勫瀮鍦炬敹闆嗗櫒缁勫悎锛岄兘鏈夊嚑涓叡鍚岀偣锛?/p>
骞磋交浠c€佽€佸勾浠f槸鐙珛涓旇繛缁殑鍐呭瓨鍧楋紱
骞磋交浠f敹闆嗕娇鐢ㄥ崟eden銆佸弻survivor杩涜澶嶅埗绠楁硶锛?/p>
鑰佸勾浠f敹闆嗗繀椤绘壂鎻忔暣涓€佸勾浠e尯鍩燂紱
閮芥槸浠ュ敖鍙兘灏戣€屽潡鍦版墽琛孏C涓鸿璁″師鍒欍€?/p>
G1鍨冨溇鏀堕泦鍣ㄤ篃鏄互鍏虫敞寤惰繜涓虹洰鏍囥€佹湇鍔″櫒绔簲鐢ㄧ殑鍨冨溇鏀堕泦鍣紝琚獺otSpot鍥㈤槦瀵勪簣鍙栦唬CMS鐨勪娇鍛斤紝涔熸槸涓€涓潪甯稿叿鏈夎皟浼樻綔鍔涚殑鍨冨溇鏀堕泦鍣ㄣ€傝櫧鐒禛1涔熸湁绫讳技CMS鐨勬敹闆嗗姩浣滐細鍒濆鏍囪銆佸苟鍙戞爣璁般€侀噸鏂版爣璁般€佹竻闄ゃ€佽浆绉诲洖鏀讹紝骞朵笖涔熶互涓€涓覆琛屾敹闆嗗櫒鍋氭媴淇濇満鍒讹紝浣嗗崟绾湴浠ョ被浼煎墠涓夌鐨勮繃绋嬫弿杩版樉寰楀苟涓嶆槸寰堝Ε褰撱€備簨瀹炰笂锛孏1鏀堕泦涓庝互涓婁笁缁勬敹闆嗗櫒鏈夊緢澶т笉鍚岋細
G1鐨勮璁″師鍒欐槸"棣栧厛鏀堕泦灏藉彲鑳藉鐨勫瀮鍦?Garbage First)"銆傚洜姝わ紝G1骞朵笉浼氱瓑鍐呭瓨鑰楀敖(涓茶銆佸苟琛?鎴栬€呭揩鑰楀敖(CMS)鐨勬椂鍊欏紑濮嬪瀮鍦炬敹闆嗭紝鑰屾槸鍦ㄥ唴閮ㄩ噰鐢ㄤ簡鍚彂寮忕畻娉曪紝鍦ㄨ€佸勾浠f壘鍑哄叿鏈夐珮鏀堕泦鏀剁泭鐨勫垎鍖鸿繘琛屾敹闆嗐€傚悓鏃禛1鍙互鏍规嵁鐢ㄦ埛璁剧疆鐨勬殏鍋滄椂闂寸洰鏍囪嚜鍔ㄨ皟鏁村勾杞讳唬鍜屾€诲爢澶у皬锛屾殏鍋滅洰鏍囪秺鐭勾杞讳唬绌洪棿瓒婂皬銆佹€荤┖闂村氨瓒婂ぇ锛?/p>
G1閲囩敤鍐呭瓨鍒嗗尯(Region)鐨勬€濊矾锛屽皢鍐呭瓨鍒掑垎涓轰竴涓釜鐩哥瓑澶у皬鐨勫唴瀛樺垎鍖猴紝鍥炴敹鏃跺垯浠ュ垎鍖轰负鍗曚綅杩涜鍥炴敹锛屽瓨娲荤殑瀵硅薄澶嶅埗鍒板彟涓€涓┖闂插垎鍖轰腑銆傜敱浜庨兘鏄互鐩哥瓑澶у皬鐨勫垎鍖轰负鍗曚綅杩涜鎿嶄綔锛屽洜姝1澶╃劧灏辨槸涓€绉嶅帇缂╂柟妗?灞€閮ㄥ帇缂?锛?/p>
G1铏界劧涔熸槸鍒嗕唬鏀堕泦鍣紝浣嗘暣涓唴瀛樺垎鍖轰笉瀛樺湪鐗╃悊涓婄殑骞磋交浠d笌鑰佸勾浠g殑鍖哄埆锛屼篃涓嶉渶瑕佸畬鍏ㄧ嫭绔嬬殑survivor(to space)鍫嗗仛澶嶅埗鍑嗗銆侴1鍙湁閫昏緫涓婄殑鍒嗕唬姒傚康锛屾垨鑰呰姣忎釜鍒嗗尯閮藉彲鑳介殢G1鐨勮繍琛屽湪涓嶅悓浠d箣闂村墠鍚庡垏鎹紱
G1鐨勬敹闆嗛兘鏄疭TW鐨勶紝浣嗗勾杞讳唬鍜岃€佸勾浠g殑鏀堕泦鐣岄檺姣旇緝妯$硦锛岄噰鐢ㄤ簡娣峰悎(mixed)鏀堕泦鐨勬柟寮忋€傚嵆姣忔鏀堕泦鏃㈠彲鑳藉彧鏀堕泦骞磋交浠e垎鍖?骞磋交浠f敹闆?锛屼篃鍙兘鍦ㄦ敹闆嗗勾杞讳唬鐨勫悓鏃讹紝鍖呭惈閮ㄥ垎鑰佸勾浠e垎鍖?娣峰悎鏀堕泦)锛岃繖鏍峰嵆浣垮爢鍐呭瓨寰堝ぇ鏃讹紝涔熷彲浠ラ檺鍒舵敹闆嗚寖鍥达紝浠庤€岄檷浣庡仠椤裤€?/p>
绗笁绔?G1鐨勫唴瀛樻ā鍨?/h1>
鍒嗗尯姒傚康
鍒嗗尯
鍒嗗尯 Region
G1閲囩敤浜嗗垎鍖?Region)鐨勬€濊矾锛屽皢鏁翠釜鍫嗙┖闂村垎鎴愯嫢骞蹭釜澶у皬鐩哥瓑鐨勫唴瀛樺尯鍩燂紝姣忔鍒嗛厤瀵硅薄绌洪棿灏嗛€愭鍦颁娇鐢ㄥ唴瀛樸€傚洜姝わ紝鍦ㄥ爢鐨勪娇鐢ㄤ笂锛孏1骞朵笉瑕佹眰瀵硅薄鐨勫瓨鍌ㄤ竴瀹氭槸鐗╃悊涓婅繛缁殑锛屽彧瑕侀€昏緫涓婅繛缁嵆鍙紱姣忎釜鍒嗗尯涔熶笉浼氱‘瀹氬湴涓烘煇涓唬鏈嶅姟锛屽彲浠ユ寜闇€鍦ㄥ勾杞讳唬鍜岃€佸勾浠d箣闂村垏鎹€傚惎鍔ㄦ椂鍙互閫氳繃鍙傛暟-XX:G1HeapRegionSize=n
鍙寚瀹氬垎鍖哄ぇ灏?1MB~32MB锛屼笖蹇呴』鏄?鐨勫箓)锛岄粯璁ゅ皢鏁村爢鍒掑垎涓?048涓垎鍖恒€?/p>
鍗$墖
鍗$墖 Card
鍦ㄦ瘡涓垎鍖哄唴閮ㄥ張琚垎鎴愪簡鑻ュ共涓ぇ灏忎负512 Byte鍗$墖(Card)锛屾爣璇嗗爢鍐呭瓨鏈€灏忓彲鐢ㄧ矑搴︽墍鏈夊垎鍖虹殑鍗$墖灏嗕細璁板綍鍦ㄥ叏灞€鍗$墖琛?Global Card Table)涓紝鍒嗛厤鐨勫璞′細鍗犵敤鐗╃悊涓婅繛缁殑鑻ュ共涓崱鐗囷紝褰撴煡鎵惧鍒嗗尯鍐呭璞$殑寮曠敤鏃朵究鍙€氳繃璁板綍鍗$墖鏉ユ煡鎵捐寮曠敤瀵硅薄(瑙丷Set)銆傛瘡娆″鍐呭瓨鐨勫洖鏀讹紝閮芥槸瀵规寚瀹氬垎鍖虹殑鍗$墖杩涜澶勭悊銆?/p>
鍫?/h3>
鍫?Heap
G1鍚屾牱鍙互閫氳繃-Xms
/-Xmx
鏉ユ寚瀹氬爢绌洪棿澶у皬銆傚綋鍙戠敓骞磋交浠f敹闆嗘垨娣峰悎鏀堕泦鏃讹紝閫氳繃璁$畻GC涓庡簲鐢ㄧ殑鑰楄垂鏃堕棿姣旓紝鑷姩璋冩暣鍫嗙┖闂村ぇ灏忋€傚鏋淕C棰戠巼澶珮锛屽垯閫氳繃澧炲姞鍫嗗昂瀵革紝鏉ュ噺灏慓C棰戠巼锛岀浉搴斿湴GC鍗犵敤鐨勬椂闂翠篃闅忎箣闄嶄綆锛涚洰鏍囧弬鏁?code class="mq-93">-XX:GCTimeRatio鍗充负GC涓庡簲鐢ㄧ殑鑰楄垂鏃堕棿姣旓紝G1榛樿涓?锛岃€孋MS榛樿涓?9锛屽洜涓篊MS鐨勮璁″師鍒欐槸鑰楄垂鍦℅C涓婄殑鏃堕棿灏藉彲鑳界殑灏戙€傚彟澶栵紝褰撶┖闂翠笉瓒筹紝濡傚璞$┖闂村垎閰嶆垨杞Щ澶辫触鏃讹紝G1浼氶鍏堝皾璇曞鍔犲爢绌洪棿锛屽鏋滄墿瀹瑰け璐ワ紝鍒欏彂璧锋媴淇濈殑Full GC銆侳ull GC鍚庯紝鍫嗗昂瀵歌绠楃粨鏋滀篃浼氳皟鏁村爢绌洪棿銆?/p>
鍒嗕唬妯″瀷
鍒嗕唬
鍒嗕唬 Generation
鍒嗕唬鍨冨溇鏀堕泦鍙互灏嗗叧娉ㄧ偣闆嗕腑鍦ㄦ渶杩戣鍒嗛厤鐨勫璞′笂锛岃€屾棤闇€鏁村爢鎵弿锛岄伩鍏嶉暱鍛藉璞$殑鎷疯礉锛屽悓鏃剁嫭绔嬫敹闆嗘湁鍔╀簬闄嶄綆鍝嶅簲鏃堕棿銆傝櫧鐒跺垎鍖轰娇寰楀唴瀛樺垎閰嶄笉鍐嶈姹傜揣鍑戠殑鍐呭瓨绌洪棿锛屼絾G1渚濈劧浣跨敤浜嗗垎浠g殑鎬濇兂銆備笌鍏朵粬鍨冨溇鏀堕泦鍣ㄧ被浼硷紝G1灏嗗唴瀛樺湪閫昏緫涓婂垝鍒嗕负骞磋交浠e拰鑰佸勾浠o紝鍏朵腑骞磋交浠e張鍒掑垎涓篍den绌洪棿鍜孲urvivor绌洪棿銆備絾骞磋交浠g┖闂村苟涓嶆槸鍥哄畾涓嶅彉鐨勶紝褰撶幇鏈夊勾杞讳唬鍒嗗尯鍗犳弧鏃讹紝JVM浼氬垎閰嶆柊鐨勭┖闂插垎鍖哄姞鍏ュ埌骞磋交浠g┖闂淬€?/p>
鏁翠釜骞磋交浠e唴瀛樹細鍦ㄥ垵濮嬬┖闂?code class="mq-101">-XX:G1NewSizePercent(榛樿鏁村爢5%)涓庢渶澶х┖闂?code class="mq-102">-XX:G1MaxNewSizePercent(榛樿60%)涔嬮棿鍔ㄦ€佸彉鍖栵紝涓旂敱鍙傛暟鐩爣鏆傚仠鏃堕棿-XX:MaxGCPauseMillis
(榛樿200ms)銆侀渶瑕佹墿缂╁鐨勫ぇ灏忎互鍙婂垎鍖虹殑宸茶蹇嗛泦鍚?RSet)璁$畻寰楀埌銆傚綋鐒讹紝G1渚濈劧鍙互璁剧疆鍥哄畾鐨勫勾杞讳唬澶у皬(鍙傛暟-XX:NewRatio
銆?code class="mq-105">-Xmn)锛屼絾鍚屾椂鏆傚仠鐩爣灏嗗け鍘绘剰涔夈€?/p>
鏈湴鍒嗛厤缂撳啿
鏈湴鍒嗛厤缂撳啿 Local allocation buffer (Lab)
鍊煎緱娉ㄦ剰鐨勬槸锛岀敱浜庡垎鍖虹殑鎬濇兂锛屾瘡涓嚎绋嬪潎鍙互"璁ら"鏌愪釜鍒嗗尯鐢ㄤ簬绾跨▼鏈湴鐨勫唴瀛樺垎閰嶏紝鑰屼笉闇€瑕侀【鍙婂垎鍖烘槸鍚﹁繛缁€傚洜姝わ紝姣忎釜搴旂敤绾跨▼鍜孏C绾跨▼閮戒細鐙珛鐨勪娇鐢ㄥ垎鍖猴紝杩涜€屽噺灏戝悓姝ユ椂闂达紝鎻愬崌GC鏁堢巼锛岃繖涓垎鍖虹О涓烘湰鍦板垎閰嶇紦鍐插尯(Lab)銆?/p>
鍏朵腑锛屽簲鐢ㄧ嚎绋嬪彲浠ョ嫭鍗犱竴涓湰鍦扮紦鍐插尯(TLAB)鏉ュ垱寤虹殑瀵硅薄锛岃€屽ぇ閮ㄥ垎閮戒細钀藉叆Eden鍖哄煙(宸ㄥ瀷瀵硅薄鎴栧垎閰嶅け璐ラ櫎澶?锛屽洜姝LAB鐨勫垎鍖哄睘浜嶦den绌洪棿锛涜€屾瘡娆″瀮鍦炬敹闆嗘椂锛屾瘡涓狦C绾跨▼鍚屾牱鍙互鐙崰涓€涓湰鍦扮紦鍐插尯(GCLAB)鐢ㄦ潵杞Щ瀵硅薄锛屾瘡娆″洖鏀朵細灏嗗璞″鍒跺埌Suvivor绌洪棿鎴栬€佸勾浠g┖闂达紱瀵逛簬浠嶦den/Survivor绌洪棿鏅嬪崌(Promotion)鍒癝urvivor/鑰佸勾浠g┖闂寸殑瀵硅薄锛屽悓鏍锋湁GC鐙崰鐨勬湰鍦扮紦鍐插尯杩涜鎿嶄綔锛岃閮ㄥ垎绉颁负鏅嬪崌鏈湴缂撳啿鍖?PLAB)銆?/p>
鍒嗗尯妯″瀷
G1瀵瑰唴瀛樼殑浣跨敤浠ュ垎鍖?Region)涓哄崟浣嶏紝鑰屽瀵硅薄鐨勫垎閰嶅垯浠ュ崱鐗?Card)涓哄崟浣嶃€?br>
宸ㄥ瀷瀵硅薄
宸ㄥ瀷瀵硅薄 Humongous Region
涓€涓ぇ灏忚揪鍒扮敋鑷宠秴杩囧垎鍖哄ぇ灏忎竴鍗婄殑瀵硅薄绉颁负宸ㄥ瀷瀵硅薄(Humongous Object)銆傚綋绾跨▼涓哄法鍨嬪垎閰嶇┖闂存椂锛屼笉鑳界畝鍗曞湪TLAB杩涜鍒嗛厤锛屽洜涓哄法鍨嬪璞$殑绉诲姩鎴愭湰寰堥珮锛岃€屼笖鏈夊彲鑳戒竴涓垎鍖轰笉鑳藉绾冲法鍨嬪璞°€傚洜姝わ紝宸ㄥ瀷瀵硅薄浼氱洿鎺ュ湪鑰佸勾浠e垎閰嶏紝鎵€鍗犵敤鐨勮繛缁┖闂寸О涓哄法鍨嬪垎鍖?Humongous Region)銆侴1鍐呴儴鍋氫簡涓€涓紭鍖栵紝涓€鏃﹀彂鐜版病鏈夊紩鐢ㄦ寚鍚戝法鍨嬪璞★紝鍒欏彲鐩存帴鍦ㄥ勾杞讳唬鏀堕泦鍛ㄦ湡涓鍥炴敹銆?/p>
宸ㄥ瀷瀵硅薄浼氱嫭鍗犱竴涓€佹垨澶氫釜杩炵画鍒嗗尯锛屽叾涓涓€涓垎鍖鸿鏍囪涓哄紑濮嬪法鍨?StartsHumongous)锛岀浉閭昏繛缁垎鍖鸿鏍囪涓鸿繛缁法鍨?ContinuesHumongous)銆傜敱浜庢棤娉曚韩鍙桳ab甯︽潵鐨勪紭鍖栵紝骞朵笖纭畾涓€鐗囪繛缁殑鍐呭瓨绌洪棿闇€瑕佹壂鎻忔暣鍫嗭紝鍥犳纭畾宸ㄥ瀷瀵硅薄寮€濮嬩綅缃殑鎴愭湰闈炲父楂橈紝濡傛灉鍙互锛屽簲鐢ㄧ▼搴忓簲閬垮厤鐢熸垚宸ㄥ瀷瀵硅薄銆?/p>
宸茶蹇嗛泦鍚?/h3>
宸茶蹇嗛泦鍚?Remember Set (RSet)
鍦ㄤ覆琛屽拰骞惰鏀堕泦鍣ㄤ腑锛孏C閫氳繃鏁村爢鎵弿锛屾潵纭畾瀵硅薄鏄惁澶勪簬鍙揪璺緞涓€傜劧鑰孏1涓轰簡閬垮厤STW寮忕殑鏁村爢鎵弿锛屽湪姣忎釜鍒嗗尯璁板綍浜嗕竴涓凡璁板繂闆嗗悎(RSet)锛屽唴閮ㄧ被浼间竴涓弽鍚戞寚閽堬紝璁板綍寮曠敤鍒嗗尯鍐呭璞$殑鍗$墖绱㈠紩銆傚綋瑕佸洖鏀惰鍒嗗尯鏃讹紝閫氳繃鎵弿鍒嗗尯鐨凴Set锛屾潵纭畾寮曠敤鏈垎鍖哄唴鐨勫璞℃槸鍚﹀瓨娲伙紝杩涜€岀‘瀹氭湰鍒嗗尯鍐呯殑瀵硅薄瀛樻椿鎯呭喌銆?/p>
浜嬪疄涓婏紝骞堕潪鎵€鏈夌殑寮曠敤閮介渶瑕佽褰曞湪RSet涓紝濡傛灉涓€涓垎鍖虹‘瀹氶渶瑕佹壂鎻忥紝閭d箞鏃犻渶RSet涔熷彲浠ユ棤閬楁紡鐨勫緱鍒板紩鐢ㄥ叧绯汇€傞偅涔堝紩鐢ㄦ簮鑷湰鍒嗗尯鐨勫璞★紝褰撶劧涓嶇敤钀藉叆RSet涓紱鍚屾椂锛孏1 GC姣忔閮戒細瀵瑰勾杞讳唬杩涜鏁翠綋鏀堕泦锛屽洜姝ゅ紩鐢ㄦ簮鑷勾杞讳唬鐨勫璞★紝涔熶笉闇€瑕佸湪RSet涓褰曘€傛渶鍚庡彧鏈夎€佸勾浠g殑鍒嗗尯鍙兘浼氭湁RSet璁板綍锛岃繖浜涘垎鍖虹О涓烘嫢鏈塕Set鍒嗗尯(an RSet鈥檚 owning region)銆?/p>
Per Region Table
Per Region Table (PRT)
RSet鍦ㄥ唴閮ㄤ娇鐢≒er Region Table(PRT)璁板綍鍒嗗尯鐨勫紩鐢ㄦ儏鍐点€傜敱浜嶳Set鐨勮褰曡鍗犵敤鍒嗗尯鐨勭┖闂达紝濡傛灉涓€涓垎鍖洪潪甯?鍙楁杩?锛岄偅涔圧Set鍗犵敤鐨勭┖闂翠細涓婂崌锛屼粠鑰岄檷浣庡垎鍖虹殑鍙敤绌洪棿銆侴1搴斿杩欎釜闂閲囩敤浜嗘敼鍙楻Set鐨勫瘑搴︾殑鏂瑰紡锛屽湪PRT涓皢浼氫互涓夌妯″紡璁板綍寮曠敤锛?/p>
绋€灏戯細鐩存帴璁板綍寮曠敤瀵硅薄鐨勫崱鐗囩储寮?/p>
缁嗙矑搴︼細璁板綍寮曠敤瀵硅薄鐨勫垎鍖虹储寮?/p>
绮楃矑搴︼細鍙褰曞紩鐢ㄦ儏鍐碉紝姣忎釜鍒嗗尯瀵瑰簲涓€涓瘮鐗逛綅
鐢变笂鍙煡锛岀矖绮掑害鐨凱RT鍙槸璁板綍浜嗗紩鐢ㄦ暟閲忥紝闇€瑕侀€氳繃鏁村爢鎵弿鎵嶈兘鎵惧嚭鎵€鏈夊紩鐢紝鍥犳鎵弿閫熷害涔熸槸鏈€鎱㈢殑銆?/p>
鏀堕泦闆嗗悎 (CSet)
鏀堕泦闆嗗悎 CSet
鏀堕泦闆嗗悎(CSet)浠h〃姣忔GC鏆傚仠鏃跺洖鏀剁殑涓€绯诲垪鐩爣鍒嗗尯銆傚湪浠绘剰涓€娆℃敹闆嗘殏鍋滀腑锛孋Set鎵€鏈夊垎鍖洪兘浼氳閲婃斁锛屽唴閮ㄥ瓨娲荤殑瀵硅薄閮戒細琚浆绉诲埌鍒嗛厤鐨勭┖闂插垎鍖轰腑銆傚洜姝ゆ棤璁烘槸骞磋交浠f敹闆嗭紝杩樻槸娣峰悎鏀堕泦锛屽伐浣滅殑鏈哄埗閮芥槸涓€鑷寸殑銆傚勾杞讳唬鏀堕泦CSet鍙绾冲勾杞讳唬鍒嗗尯锛岃€屾贩鍚堟敹闆嗕細閫氳繃鍚彂寮忕畻娉曪紝鍦ㄨ€佸勾浠e€欓€夊洖鏀跺垎鍖轰腑锛岀瓫閫夊嚭鍥炴敹鏀剁泭鏈€楂樼殑鍒嗗尯娣诲姞鍒癈Set涓€?/p>
鍊欓€夎€佸勾浠e垎鍖虹殑CSet鍑嗗叆鏉′欢锛屽彲浠ラ€氳繃娲昏穬搴﹂槇鍊?code class="mq-133">-XX:G1MixedGCLiveThresholdPercent(榛樿85%)杩涜璁剧疆锛屼粠鑰屾嫤鎴偅浜涘洖鏀跺紑閿€宸ㄥぇ鐨勫璞★紱鍚屾椂锛屾瘡娆℃贩鍚堟敹闆嗗彲浠ュ寘鍚€欓€夎€佸勾浠e垎鍖猴紝鍙牴鎹瓹Set瀵瑰爢鐨勬€诲ぇ灏忓崰姣?code class="mq-134">-XX:G1OldCSetRegionThresholdPercent(榛樿10%)璁剧疆鏁伴噺涓婇檺銆?/p>
鐢变笂杩板彲鐭ワ紝G1鐨勬敹闆嗛兘鏄牴鎹瓹Set杩涜鎿嶄綔鐨勶紝骞磋交浠f敹闆嗕笌娣峰悎鏀堕泦娌℃湁鏄庢樉鐨勪笉鍚岋紝鏈€澶х殑鍖哄埆鍦ㄤ簬涓ょ鏀堕泦鐨勮Е鍙戞潯浠躲€?/p>
骞磋交浠f敹闆嗛泦鍚?/h3>
骞磋交浠f敹闆嗛泦鍚?CSet of Young Collection
搴旂敤绾跨▼涓嶆柇娲诲姩鍚庯紝骞磋交浠g┖闂翠細琚€愭笎濉弧銆傚綋JVM鍒嗛厤瀵硅薄鍒癊den鍖哄煙澶辫触(Eden鍖哄凡婊?鏃讹紝渚夸細瑙﹀彂涓€娆TW寮忕殑骞磋交浠f敹闆嗐€傚湪骞磋交浠f敹闆嗕腑锛孍den鍒嗗尯瀛樻椿鐨勫璞″皢琚嫹璐濆埌Survivor鍒嗗尯锛涘師鏈塖urvivor鍒嗗尯瀛樻椿鐨勫璞★紝灏嗘牴鎹换鏈熼槇鍊?tenuring threshold)鍒嗗埆鏅嬪崌鍒癙LAB涓紝鏂扮殑survivor鍒嗗尯鍜岃€佸勾浠e垎鍖恒€傝€屽師鏈夌殑骞磋交浠e垎鍖哄皢琚暣浣撳洖鏀舵帀銆?/p>
鍚屾椂锛屽勾杞讳唬鏀堕泦杩樿礋璐g淮鎶ゅ璞$殑骞撮緞(瀛樻椿娆℃暟)锛岃緟鍔╁垽鏂€佸寲(tenuring)瀵硅薄鏅嬪崌鐨勬椂鍊欐槸鍒癝urvivor鍒嗗尯杩樻槸鍒拌€佸勾浠e垎鍖恒€傚勾杞讳唬鏀堕泦棣栧厛鍏堝皢鏅嬪崌瀵硅薄灏哄鎬诲拰銆佸璞″勾榫勪俊鎭淮鎶ゅ埌骞撮緞琛ㄤ腑锛屽啀鏍规嵁骞撮緞琛ㄣ€丼urvivor灏哄銆丼urvivor濉厖瀹归噺-XX:TargetSurvivorRatio
(榛樿50%)銆佹渶澶т换鏈熼槇鍊?code class="mq-141">-XX:MaxTenuringThreshold(榛樿15)锛岃绠楀嚭涓€涓伆褰撶殑浠绘湡闃堝€硷紝鍑℃槸瓒呰繃浠绘湡闃堝€肩殑瀵硅薄閮戒細琚檵鍗囧埌鑰佸勾浠c€?/p>
娣峰悎鏀堕泦闆嗗悎
娣峰悎鏀堕泦闆嗗悎 CSet of Mixed Collection
骞磋交浠f敹闆嗕笉鏂椿鍔ㄥ悗锛岃€佸勾浠g殑绌洪棿涔熶細琚€愭笎濉厖銆傚綋鑰佸勾浠e崰鐢ㄧ┖闂磋秴杩囨暣鍫嗘瘮IHOP闃堝€?code class="mq-145">-XX:InitiatingHeapOccupancyPercent(榛樿45%)鏃讹紝G1灏变細鍚姩涓€娆℃贩鍚堝瀮鍦炬敹闆嗗懆鏈熴€備负浜嗘弧瓒虫殏鍋滅洰鏍囷紝G1鍙兘涓嶈兘涓€鍙f皵灏嗘墍鏈夌殑鍊欓€夊垎鍖烘敹闆嗘帀锛屽洜姝1鍙兘浼氫骇鐢熻繛缁娆$殑娣峰悎鏀堕泦涓庡簲鐢ㄧ嚎绋嬩氦鏇挎墽琛岋紝姣忔STW鐨勬贩鍚堟敹闆嗕笌骞磋交浠f敹闆嗚繃绋嬬浉绫讳技銆?/p>
涓轰簡纭畾鍖呭惈鍒板勾杞讳唬鏀堕泦闆嗗悎CSet鐨勮€佸勾浠e垎鍖猴紝JVM閫氳繃鍙傛暟娣峰悎鍛ㄦ湡鐨勬渶澶ф€绘鏁?code class="mq-147">-XX:G1MixedGCCountTarget(榛樿8)銆佸爢搴熺墿鐧惧垎姣?code class="mq-148">-XX:G1HeapWastePercent(榛樿5%)銆傞€氳繃鍊欓€夎€佸勾浠e垎鍖烘€绘暟涓庢贩鍚堝懆鏈熸渶澶ф€绘鏁帮紝纭畾姣忔鍖呭惈鍒癈Set鐨勬渶灏忓垎鍖烘暟閲忥紱鏍规嵁鍫嗗簾鐗╃櫨鍒嗘瘮锛屽綋鏀堕泦杈惧埌鍙傛暟鏃讹紝涓嶅啀鍚姩鏂扮殑娣峰悎鏀堕泦銆傝€屾瘡娆℃坊鍔犲埌CSet鐨勫垎鍖猴紝鍒欓€氳繃璁$畻寰楀埌鐨凣C鏁堢巼杩涜瀹夋帓銆?/p>
绗洓绔?G1鐨勬椿鍔ㄥ懆鏈?/h1>
G1鍨冨溇鏀堕泦娲诲姩姹囨€?/h2>
绁嚭涓€寮犳€诲浘
RSet鐨勭淮鎶?/h2>
鐢变簬涓嶈兘鏁村爢鎵弿锛屽張闇€瑕佽绠楀垎鍖虹‘鍒囩殑娲昏穬搴︼紝鍥犳锛孏1闇€瑕佷竴涓閲忓紡鐨勫畬鍏ㄦ爣璁板苟鍙戠畻娉曪紝閫氳繃缁存姢RSet锛屽緱鍒板噯纭殑鍒嗗尯寮曠敤淇℃伅銆傚湪G1涓紝RSet鐨勭淮鎶や富瑕佹潵婧愪袱涓柟闈細鍐欐爡鏍?Write Barrier)鍜屽苟鍙戜紭鍖栫嚎绋?Concurrence Refinement Threads)
鏍呮爮
鏍呮爮 Barrier
鎴戜滑棣栧厛浠嬬粛涓€涓嬫爡鏍?Barrier)鐨勬蹇点€傛爡鏍忔槸鎸囧湪鍘熺敓浠g爜鐗囨涓紝褰撴煇浜涜鍙ヨ鎵ц鏃讹紝鏍呮爮浠g爜涔熶細琚墽琛屻€傝€孏1涓昏鍦ㄨ祴鍊艰鍙ヤ腑锛屼娇鐢ㄥ啓鍓嶆爡鏍?Pre-Write Barrrier)鍜屽啓鍚庢爡鏍?Post-Write Barrrier)銆備簨瀹炰笂锛屽啓鏍呮爮鐨勬寚浠ゅ簭鍒楀紑閿€闈炲父鏄傝吹锛屽簲鐢ㄥ悶鍚愰噺涔熶細鏍规嵁鏍呮爮澶嶆潅搴﹁€岄檷浣庛€?/p>
鍐欏墠鏍呮爮 Pre-Write Barrrier
鍗冲皢鎵ц涓€娈佃祴鍊艰鍙ユ椂锛岀瓑寮忓乏渚у璞″皢淇敼寮曠敤鍒板彟涓€涓璞★紝閭d箞绛夊紡宸︿晶瀵硅薄鍘熷厛寮曠敤鐨勫璞℃墍鍦ㄥ垎鍖哄皢鍥犳涓уけ涓€涓紩鐢紝閭d箞JVM灏遍渶瑕佸湪璧嬪€艰鍙ョ敓鏁堜箣鍓嶏紝璁板綍涓уけ寮曠敤鐨勫璞°€侸VM骞朵笉浼氱珛鍗崇淮鎶Set锛岃€屾槸閫氳繃鎵归噺澶勭悊锛屽湪灏嗘潵RSet鏇存柊(瑙丼ATB)銆?/p>
鍐欏悗鏍呮爮 Post-Write Barrrier
褰撴墽琛屼竴娈佃祴鍊艰鍙ュ悗锛岀瓑寮忓彸渚у璞¤幏鍙栦簡宸︿晶瀵硅薄鐨勫紩鐢紝閭d箞绛夊紡鍙充晶瀵硅薄鎵€鍦ㄥ垎鍖虹殑RSet涔熷簲璇ュ緱鍒版洿鏂般€傚悓鏍蜂负浜嗛檷浣庡紑閿€锛屽啓鍚庢爡鏍忓彂鐢熷悗锛孯Set涔熶笉浼氱珛鍗虫洿鏂帮紝鍚屾牱鍙槸璁板綍姝ゆ鏇存柊鏃ュ織锛屽湪灏嗘潵鎵归噺澶勭悊(瑙丆oncurrence Refinement Threads)銆?/p>
璧峰蹇収绠楁硶
璧峰蹇収绠楁硶 Snapshot at the beginning (SATB)
Taiichi Tuasa璐$尞鐨勫閲忓紡瀹屽叏骞跺彂鏍囪绠楁硶璧峰蹇収绠楁硶(SATB)锛屼富瑕侀拡瀵规爣璁?娓呴櫎鍨冨溇鏀堕泦鍣ㄧ殑骞跺彂鏍囪闃舵锛岄潪甯搁€傚悎G1鐨勫垎鍖哄潡鐨勫爢缁撴瀯锛屽悓鏃惰В鍐充簡CMS鐨勪富瑕佺儲鎭硷細閲嶆柊鏍囪鏆傚仠鏃堕棿闀垮甫鏉ョ殑娼滃湪椋庨櫓銆?/p>
SATB浼氬垱寤轰竴涓璞″浘锛岀浉褰撲簬鍫嗙殑閫昏緫蹇収锛屼粠鑰岀‘淇濆苟鍙戞爣璁伴樁娈垫墍鏈夌殑鍨冨溇瀵硅薄閮借兘閫氳繃蹇収琚壌鍒嚭鏉ャ€傚綋璧嬪€艰鍙ュ彂鐢熸椂锛屽簲鐢ㄥ皢浼氭敼鍙樹簡瀹冪殑瀵硅薄鍥撅紝閭d箞JVM闇€瑕佽褰曡瑕嗙洊鐨勫璞°€傚洜姝ゅ啓鍓嶆爡鏍忎細鍦ㄥ紩鐢ㄥ彉鏇村墠锛屽皢鍊艰褰曞湪SATB鏃ュ織鎴栫紦鍐插尯涓€傛瘡涓嚎绋嬮兘浼氱嫭鍗犱竴涓猄ATB缂撳啿鍖猴紝鍒濆鏈?56鏉¤褰曠┖闂淬€傚綋绌洪棿鐢ㄥ敖鏃讹紝绾跨▼浼氬垎閰嶆柊鐨凷ATB缂撳啿鍖虹户缁娇鐢紝鑰屽師鏈夌殑缂撳啿鍘诲垯鍔犲叆鍏ㄥ眬鍒楄〃涓€傛渶缁堝湪骞跺彂鏍囪闃舵锛屽苟鍙戞爣璁扮嚎绋?Concurrent Marking Threads)鍦ㄦ爣璁扮殑鍚屾椂锛岃繕浼氬畾鏈熸鏌ュ拰澶勭悊鍏ㄥ眬缂撳啿鍖哄垪琛ㄧ殑璁板綍锛岀劧鍚庢牴鎹爣璁颁綅鍥惧垎鐗囩殑鏍囪浣嶏紝鎵弿寮曠敤瀛楁鏉ユ洿鏂癛Set銆傛杩囩▼鍙堢О涓哄苟鍙戞爣璁?SATB鍐欏墠鏍呮爮銆?/p>
骞跺彂浼樺寲绾跨▼
骞跺彂浼樺寲绾跨▼ Concurrence Refinement Threads
G1涓娇鐢ㄥ熀浜嶶rs H枚lzle鐨勫揩閫熷啓鏍呮爮锛屽皢鏍呮爮寮€閿€缂╁噺鍒?涓澶栫殑鎸囦护銆傛爡鏍忓皢浼氭洿鏂颁竴涓猚ard table type鐨勭粨鏋勬潵璺熻釜浠i棿寮曠敤銆?/p>
褰撹祴鍊艰鍙ュ彂鐢熷悗锛屽啓鍚庢爡鏍忎細鍏堥€氳繃G1鐨勮繃婊ゆ妧鏈垽鏂槸鍚︽槸璺ㄥ垎鍖虹殑寮曠敤鏇存柊锛屽苟灏嗚法鍒嗗尯鏇存柊瀵硅薄鐨勫崱鐗囧姞鍏ョ紦鍐插尯搴忓垪锛屽嵆鏇存柊鏃ュ織缂撳啿鍖烘垨鑴忓崱鐗囬槦鍒椼€備笌SATB绫讳技锛屼竴鏃︽棩蹇楃紦鍐插尯鐢ㄥ敖锛屽垯鍒嗛厤涓€涓柊鐨勬棩蹇楃紦鍐插尯锛屽苟灏嗗師鏉ョ殑缂撳啿鍖哄姞鍏ュ叏灞€鍒楄〃涓€?/p>
骞跺彂浼樺寲绾跨▼(Concurrence Refinement Threads)锛屽彧涓撴敞鎵弿鏃ュ織缂撳啿鍖鸿褰曠殑鍗$墖鏉ョ淮鎶ゆ洿鏂癛Set锛岀嚎绋嬫渶澶ф暟鐩彲閫氳繃-XX:G1ConcRefinementThreads
(榛樿绛変簬-XX:ParellelGCThreads
)璁剧疆銆傚苟鍙戜紭鍖栫嚎绋嬫案杩滄槸娲昏穬鐨勶紝涓€鏃﹀彂鐜板叏灞€鍒楄〃鏈夎褰曞瓨鍦紝灏卞紑濮嬪苟鍙戝鐞嗐€傚鏋滆褰曞闀垮緢蹇垨鑰呮潵涓嶅強澶勭悊锛岄偅涔堥€氳繃闃堝€?code class="mq-176">-X:G1ConcRefinementGreenZone/-XX:G1ConcRefinementYellowZone
/-XX:G1ConcRefinementRedZone
锛孏1浼氱敤鍒嗗眰鐨勬柟寮忚皟搴︼紝浣挎洿澶氱殑绾跨▼澶勭悊鍏ㄥ眬鍒楄〃銆傚鏋滃苟鍙戜紭鍖栫嚎绋嬩篃涓嶈兘璺熶笂缂撳啿鍖烘暟閲忥紝鍒橫utator绾跨▼(Java搴旂敤绾跨▼)浼氭寕璧峰簲鐢ㄥ苟琚姞杩涙潵甯姪澶勭悊锛岀洿鍒板叏閮ㄥ鐞嗗畬銆傚洜姝わ紝蹇呴』閬垮厤姝ょ被鍦烘櫙鍑虹幇銆?/p>
骞跺彂鏍囪鍛ㄦ湡
骞跺彂鏍囪鍛ㄦ湡 Concurrent Marking Cycle
骞跺彂鏍囪鍛ㄦ湡鏄疓1涓潪甯搁噸瑕佺殑闃舵锛岃繖涓樁娈靛皢浼氫负娣峰悎鏀堕泦鍛ㄦ湡璇嗗埆鍨冨溇鏈€澶氱殑鑰佸勾浠e垎鍖恒€傛暣涓懆鏈熷畬鎴愭牴鏍囪銆佽瘑鍒墍鏈?鍙兘)瀛樻椿瀵硅薄锛屽苟璁$畻姣忎釜鍒嗗尯鐨勬椿璺冨害锛屼粠鑰岀‘瀹欸C鏁堢巼绛夌骇銆?/p>
褰撹揪鍒癐HOP闃堝€?code class="mq-183">-XX:InitiatingHeapOccupancyPercent(鑰佸勾浠e崰鏁村爢姣旓紝榛樿45%)鏃讹紝渚夸細瑙﹀彂骞跺彂鏍囪鍛ㄦ湡銆傛暣涓苟鍙戞爣璁板懆鏈熷皢鐢卞垵濮嬫爣璁?Initial Mark)銆佹牴鍒嗗尯鎵弿(Root Region Scanning)銆佸苟鍙戞爣璁?Concurrent Marking)銆侀噸鏂版爣璁?Remark)銆佹竻闄?Cleanup)鍑犱釜闃舵缁勬垚銆傚叾涓紝鍒濆鏍囪(闅忓勾杞讳唬鏀堕泦涓€璧锋椿鍔?銆侀噸鏂版爣璁般€佹竻闄ゆ槸STW鐨勶紝鑰屽苟鍙戞爣璁板鏋滄潵涓嶅強鏍囪瀛樻椿瀵硅薄锛屽垯鍙兘鍦ㄥ苟鍙戞爣璁拌繃绋嬩腑锛孏1鍙堣Е鍙戜簡鍑犳骞磋交浠f敹闆嗐€?/p>
骞跺彂鏍囪绾跨▼
骞跺彂鏍囪绾跨▼ Concurrent Marking Threads
瑕佹爣璁板瓨娲荤殑瀵硅薄锛屾瘡涓垎鍖洪兘闇€瑕佸垱寤轰綅鍥?Bitmap)淇℃伅鏉ュ瓨鍌ㄦ爣璁版暟鎹紝鏉ョ‘瀹氭爣璁板懆鏈熷唴琚垎閰嶇殑瀵硅薄銆侴1閲囩敤浜嗕袱涓綅鍥綪revious Bitmap銆丯ext Bitmap锛屾潵瀛樺偍鏍囪鏁版嵁锛孭revious浣嶅浘瀛樺偍涓婃鐨勬爣璁版暟鎹紝Next浣嶅浘鍦ㄦ爣璁板懆鏈熷唴涓嶆柇鍙樺寲鏇存柊锛屽悓鏃禤revious浣嶅浘鐨勬爣璁版暟鎹篃瓒婃潵瓒婅繃鏃讹紝褰撴爣璁板懆鏈熺粨鏉熷悗Next浣嶅浘渚挎浛鎹revious浣嶅浘锛屾垚涓轰笂娆℃爣璁扮殑浣嶅浘銆傚悓鏃讹紝姣忎釜鍒嗗尯閫氳繃椤堕儴寮€濮嬫爣璁?TAMS)锛屾潵璁板綍宸叉爣璁拌繃鐨勫唴瀛樿寖鍥淬€傚悓鏍风殑锛孏1浣跨敤浜嗕袱涓《閮ㄥ紑濮嬫爣璁癙revious TAMS(PTAMS)銆丯ext TAMS(NTAMS)锛岃褰曞凡鏍囪鐨勮寖鍥淬€?br>
鍦ㄥ苟鍙戞爣璁伴樁娈碉紝G1浼氭牴鎹弬鏁?code class="mq-190">-XX:ConcGCThreads(榛樿GC绾跨▼鏁扮殑1/4锛屽嵆-XX:ParallelGCThreads
/4)锛屽垎閰嶅苟鍙戞爣璁扮嚎绋?Concurrent Marking Threads)锛岃繘琛屾爣璁版椿鍔ㄣ€傛瘡涓苟鍙戠嚎绋嬩竴娆″彧鎵弿涓€涓垎鍖猴紝骞堕€氳繃"鎵嬫寚"鎸囬拡鐨勬柟寮忎紭鍖栬幏鍙栧垎鍖恒€傚苟鍙戞爣璁扮嚎绋嬫槸鐖嗗彂寮忕殑锛屽湪缁欏畾鐨勬椂闂存鎷煎懡骞叉椿锛岀劧鍚庝紤鎭竴娈垫椂闂达紝鍐嶆嫾鍛藉共娲汇€?/p>
鍒濆鏍囪
鍒濆鏍囪 Initial Mark
鍒濆鏍囪(Initial Mark)璐熻矗鏍囪鎵€鏈夎兘琚洿鎺ュ彲杈剧殑鏍瑰璞?鍘熺敓鏍堝璞°€佸叏灞€瀵硅薄銆丣NI瀵硅薄)锛屾牴鏄璞″浘鐨勮捣鐐癸紝鍥犳鍒濆鏍囪闇€瑕佸皢Mutator绾跨▼(Java搴旂敤绾跨▼)鏆傚仠鎺夛紝涔熷氨鏄渶瑕佷竴涓猄TW鐨勬椂闂存銆備簨瀹炰笂锛屽綋杈惧埌IHOP闃堝€兼椂锛孏1骞朵笉浼氱珛鍗冲彂璧峰苟鍙戞爣璁板懆鏈燂紝鑰屾槸绛夊緟涓嬩竴娆″勾杞讳唬鏀堕泦锛屽埄鐢ㄥ勾杞讳唬鏀堕泦鐨凷TW鏃堕棿娈碉紝瀹屾垚鍒濆鏍囪锛岃繖绉嶆柟寮忕О涓哄€熼亾(Piggybacking)銆傚湪鍒濆鏍囪鏆傚仠涓紝鍒嗗尯鐨凬TAMS閮借璁剧疆鍒板垎鍖洪《閮═op锛屽垵濮嬫爣璁版槸骞跺彂鎵ц锛岀洿鍒版墍鏈夌殑鍒嗗尯澶勭悊瀹屻€?/p>
鏍瑰垎鍖烘壂鎻?/h3>
鏍瑰垎鍖烘壂鎻?Root Region Scanning
鍦ㄥ垵濮嬫爣璁版殏鍋滅粨鏉熷悗锛屽勾杞讳唬鏀堕泦涔熷畬鎴愮殑瀵硅薄澶嶅埗鍒癝urvivor鐨勫伐浣滐紝搴旂敤绾跨▼寮€濮嬫椿璺冭捣鏉ャ€傛鏃朵负浜嗕繚璇佹爣璁扮畻娉曠殑姝g‘鎬э紝鎵€鏈夋柊澶嶅埗鍒癝urvivor鍒嗗尯鐨勫璞★紝閮介渶瑕佽鎵弿骞舵爣璁版垚鏍癸紝杩欎釜杩囩▼绉颁负鏍瑰垎鍖烘壂鎻?Root Region Scanning)锛屽悓鏃舵壂鎻忕殑Suvivor鍒嗗尯涔熻绉颁负鏍瑰垎鍖?Root Region)銆傛牴鍒嗗尯鎵弿蹇呴』鍦ㄤ笅涓€娆″勾杞讳唬鍨冨溇鏀堕泦鍚姩鍓嶅畬鎴?骞跺彂鏍囪鐨勮繃绋嬩腑锛屽彲鑳戒細琚嫢骞叉骞磋交浠e瀮鍦炬敹闆嗘墦鏂?锛屽洜涓烘瘡娆C浼氫骇鐢熸柊鐨勫瓨娲诲璞¢泦鍚堛€?/p>
骞跺彂鏍囪
骞跺彂鏍囪 Concurrent Marking
鍜屽簲鐢ㄧ嚎绋嬪苟鍙戞墽琛岋紝骞跺彂鏍囪绾跨▼鍦ㄥ苟鍙戞爣璁伴樁娈靛惎鍔紝鐢卞弬鏁?code class="mq-201">-XX:ConcGCThreads(榛樿GC绾跨▼鏁扮殑1/4锛屽嵆-XX:ParallelGCThreads
/4)鎺у埗鍚姩鏁伴噺锛屾瘡涓嚎绋嬫瘡娆″彧鎵弿涓€涓垎鍖猴紝浠庤€屾爣璁板嚭瀛樻椿瀵硅薄鍥俱€傚湪杩欎竴闃舵浼氬鐞哖revious/Next鏍囪浣嶅浘锛屾壂鎻忔爣璁板璞$殑寮曠敤瀛楁銆傚悓鏃讹紝骞跺彂鏍囪绾跨▼杩樹細瀹氭湡妫€鏌ュ拰澶勭悊STAB鍏ㄥ眬缂撳啿鍖哄垪琛ㄧ殑璁板綍锛屾洿鏂板璞″紩鐢ㄤ俊鎭€傚弬鏁?code class="mq-203">-XX:+ClassUnloadingWithConcurrentMark浼氬紑鍚竴涓紭鍖栵紝濡傛灉涓€涓被涓嶅彲杈?涓嶆槸瀵硅薄涓嶅彲杈?锛屽垯鍦ㄩ噸鏂版爣璁伴樁娈碉紝杩欎釜绫诲氨浼氳鐩存帴鍗歌浇銆傛墍鏈夌殑鏍囪浠诲姟蹇呴』鍦ㄥ爢婊″墠灏卞畬鎴愭壂鎻忥紝濡傛灉骞跺彂鏍囪鑰楁椂寰堥暱锛岄偅涔堟湁鍙兘鍦ㄥ苟鍙戞爣璁拌繃绋嬩腑锛屽張缁忓巻浜嗗嚑娆″勾杞讳唬鏀堕泦銆傚鏋滃爢婊″墠娌℃湁瀹屾垚鏍囪浠诲姟锛屽垯浼氳Е鍙戞媴淇濇満鍒讹紝缁忓巻涓€娆¢暱鏃堕棿鐨勪覆琛孎ull GC銆?/p>
瀛樻椿鏁版嵁璁$畻
瀛樻椿鏁版嵁璁$畻 Live Data Accounting
瀛樻椿鏁版嵁璁$畻(Live Data Accounting)鏄爣璁版搷浣滅殑闄勫姞浜х墿锛屽彧瑕佷竴涓璞¤鏍囪锛屽悓鏃朵細琚绠楀瓧鑺傛暟锛屽苟璁″叆鍒嗗尯绌洪棿銆傚彧鏈塏TAMS浠ヤ笅鐨勫璞′細琚爣璁板拰璁$畻锛屽湪鏍囪鍛ㄦ湡鐨勬渶鍚庯紝Next浣嶅浘灏嗚娓呯┖锛岀瓑寰呬笅娆℃爣璁板懆鏈熴€?/p>
閲嶆柊鏍囪
閲嶆柊鏍囪 Remark
閲嶆柊鏍囪(Remark)鏄渶鍚庝竴涓爣璁伴樁娈点€傚湪璇ラ樁娈典腑锛孏1闇€瑕佷竴涓殏鍋滅殑鏃堕棿锛屽幓澶勭悊鍓╀笅鐨凷ATB鏃ュ織缂撳啿鍖哄拰鎵€鏈夋洿鏂帮紝鎵惧嚭鎵€鏈夋湭琚闂殑瀛樻椿瀵硅薄锛屽悓鏃跺畨鍏ㄥ畬鎴愬瓨娲绘暟鎹绠椼€傝繖涓樁娈典篃鏄苟琛屾墽琛岀殑锛岄€氳繃鍙傛暟-XX:ParallelGCThread
鍙缃瓽C鏆傚仠鏃跺彲鐢ㄧ殑GC绾跨▼鏁般€傚悓鏃讹紝寮曠敤澶勭悊涔熸槸閲嶆柊鏍囪闃舵鐨勪竴閮ㄥ垎锛屾墍鏈夐噸搴︿娇鐢ㄥ紩鐢ㄥ璞?寮卞紩鐢ㄣ€佽蒋寮曠敤銆佽櫄寮曠敤銆佹渶缁堝紩鐢?鐨勫簲鐢ㄩ兘浼氬湪寮曠敤澶勭悊涓婁骇鐢熷紑閿€銆?/p>
娓呴櫎
娓呴櫎 Cleanup
绱ф尐鐫€閲嶆柊鏍囪闃舵鐨勬竻闄?Clean)闃舵涔熸槸STW鐨勩€侾revious/Next鏍囪浣嶅浘銆佷互鍙奝TAMS/NTAMS锛岄兘浼氬湪娓呴櫎闃舵浜ゆ崲瑙掕壊銆傛竻闄ら樁娈典富瑕佹墽琛屼互涓嬫搷浣滐細
RSet姊崇悊锛屽惎鍙戝紡绠楁硶浼氭牴鎹椿璺冨害鍜孯Set灏哄瀵瑰垎鍖哄畾涔変笉鍚岀瓑绾э紝鍚屾椂RSet鏁扮悊涔熸湁鍔╀簬鍙戠幇鏃犵敤鐨勫紩鐢ㄣ€傚弬鏁?code class="mq-215">-XX:+PrintAdaptiveSizePolicy鍙互寮€鍚墦鍗板惎鍙戝紡绠楁硶鍐崇瓥缁嗚妭锛?/p>
鏁寸悊鍫嗗垎鍖猴紝涓烘贩鍚堟敹闆嗗懆鏈熻瘑鍒洖鏀舵敹鐩婇珮(鍩轰簬閲婃斁绌洪棿鍜屾殏鍋滅洰鏍?鐨勮€佸勾浠e垎鍖洪泦鍚堬紱
璇嗗埆鎵€鏈夌┖闂插垎鍖猴紝鍗冲彂鐜版棤瀛樻椿瀵硅薄鐨勫垎鍖恒€傝鍒嗗尯鍙湪娓呴櫎闃舵鐩存帴鍥炴敹锛屾棤闇€绛夊緟涓嬫鏀堕泦鍛ㄦ湡銆?/p>
骞磋交浠f敹闆?娣峰悎鏀堕泦鍛ㄦ湡
骞磋交浠f敹闆嗗拰娣峰悎鏀堕泦鍛ㄦ湡锛屾槸G1鍥炴敹绌洪棿鐨勪富瑕佹椿鍔ㄣ€傚綋搴旂敤杩愯寮€濮嬫椂锛屽爢鍐呭瓨鍙敤绌洪棿杩樻瘮杈冨ぇ锛屽彧浼氬湪骞磋交浠f弧鏃讹紝瑙﹀彂骞磋交浠f敹闆嗭紱闅忕潃鑰佸勾浠e唴瀛樺闀匡紝褰撳埌杈綢HOP闃堝€?code class="mq-218">-XX:InitiatingHeapOccupancyPercent(鑰佸勾浠e崰鏁村爢姣旓紝榛樿45%)鏃讹紝G1寮€濮嬬潃鎵嬪噯澶囨敹闆嗚€佸勾浠g┖闂淬€傞鍏堢粡鍘嗗苟鍙戞爣璁板懆鏈燂紝璇嗗埆鍑洪珮鏀剁泭鐨勮€佸勾浠e垎鍖猴紝鍓嶆枃宸茶堪銆備絾闅忓悗G1骞朵笉浼氶┈涓婂紑濮嬩竴娆℃贩鍚堟敹闆嗭紝鑰屾槸璁╁簲鐢ㄧ嚎绋嬪厛杩愯涓€娈垫椂闂达紝绛夊緟瑙﹀彂涓€娆″勾杞讳唬鏀堕泦銆傚湪杩欐STW涓紝G1灏嗕繚鍑嗘暣鐞嗘贩鍚堟敹闆嗗懆鏈熴€傛帴鐫€鍐嶆璁╁簲鐢ㄧ嚎绋嬭繍琛岋紝褰撴帴涓嬫潵鐨勫嚑娆″勾杞讳唬鏀堕泦鏃讹紝灏嗕細鏈夎€佸勾浠e垎鍖哄姞鍏ュ埌CSet涓紝鍗宠Е鍙戞贩鍚堟敹闆嗭紝杩欎簺杩炵画澶氭鐨勬贩鍚堟敹闆嗙О涓烘贩鍚堟敹闆嗗懆鏈?Mixed Collection Cycle)銆?/p>
GC宸ヤ綔绾跨▼鏁?/h3>
GC宸ヤ綔绾跨▼鏁?-XX:ParallelGCThreads
JVM鍙互閫氳繃鍙傛暟-XX:ParallelGCThreads
杩涜鎸囧畾GC宸ヤ綔鐨勭嚎绋嬫暟閲忋€傚弬鏁?code class="mq-223">-XX:ParallelGCThreads榛樿鍊煎苟涓嶆槸鍥哄畾鐨勶紝鑰屾槸鏍规嵁褰撳墠鐨凜PU璧勬簮杩涜璁$畻銆傚鏋滅敤鎴锋病鏈夋寚瀹氾紝涓擟PU灏忎簬绛変簬8锛屽垯榛樿涓嶤PU鏍告暟鐩哥瓑锛涜嫢CPU澶т簬8锛屽垯榛樿JVM浼氱粡杩囪绠楀緱鍒颁竴涓皬浜嶤PU鏍告暟鐨勭嚎绋嬫暟锛涘綋鐒朵篃鍙互浜哄伐鎸囧畾涓嶤PU鏍告暟鐩哥瓑銆?/p>
骞磋交浠f敹闆?/h3>
骞磋交浠f敹闆?Young Collection
姣忔鏀堕泦杩囩▼涓紝鏃㈡湁骞惰鎵ц鐨勬椿鍔紝涔熸湁涓茶鎵ц鐨勬椿鍔紝浣嗛兘鍙互鏄绾跨▼鐨勩€傚湪骞惰鎵ц鐨勪换鍔′腑锛屽鏋滄煇涓换鍔¤繃閲嶏紝浼氬鑷村叾浠栫嚎绋嬪湪绛夊緟鏌愰」浠诲姟鐨勫鐞嗭紝闇€瑕佸杩欎簺鍦版柟杩涜浼樺寲銆?/p>
骞惰娲诲姩
澶栭儴鏍瑰垎鍖烘壂鎻?Ext Root Scanning锛氭娲诲姩瀵瑰爢澶栫殑鏍?JVM绯荤粺鐩綍銆乂M鏁版嵁缁撴瀯銆丣NI绾跨▼鍙ユ焺銆佺‖浠跺瘎瀛樺櫒銆佸叏灞€鍙橀噺銆佺嚎绋嬪鏍堟牴)杩涜鎵弿锛屽彂鐜伴偅浜涙病鏈夊姞鍏ュ埌鏆傚仠鏀堕泦闆嗗悎CSet涓殑瀵硅薄銆傚鏋滅郴缁熺洰褰?鍗曟牴)鎷ユ湁澶ч噺鍔犺浇鐨勭被锛屾渶缁堝彲鑳藉叾浠栧苟琛屾椿鍔ㄧ粨鏉熷悗锛岃娲诲姩渚濈劧娌℃湁缁撴潫鑰屽甫鏉ョ殑绛夊緟鏃堕棿銆?/p>
鏇存柊宸茶蹇嗛泦鍚?Update RS锛氬苟鍙戜紭鍖栫嚎绋嬩細瀵硅剰鍗$墖鐨勫垎鍖鸿繘琛屾壂鎻忔洿鏂版棩蹇楃紦鍐插尯鏉ユ洿鏂癛Set锛屼絾鍙細澶勭悊鍏ㄥ眬缂撳啿鍒楄〃銆備綔涓鸿ˉ鍏咃紝鎵€鏈夎璁板綍浣嗘槸杩樻病鏈夎浼樺寲绾跨▼澶勭悊鐨勫墿浣欑紦鍐插尯锛屼細鍦ㄨ闃舵澶勭悊锛屽彉鎴愬凡澶勭悊缂撳啿鍖?Processed Buffers)銆備负浜嗛檺鍒惰姳鍦ㄦ洿鏂癛Set鐨勬椂闂达紝鍙互璁剧疆鏆傚仠鍗犵敤鐧惧垎姣?code class="mq-230">-XX:G1RSetUpdatingPauseTimePercent(榛樿10%锛屽嵆 RSet鎵弿 Scan RS锛氬湪鏀堕泦褰撳墠CSet涔嬪墠锛岃€冭檻鍒板垎鍖哄鐨勫紩鐢紝蹇呴』鎵弿CSet鍒嗗尯鐨凴Set銆傚鏋淩Set鍙戠敓绮楀寲锛屽垯浼氬鍔燫Set鐨勬壂鎻忔椂闂淬€傚紑鍚瘖鏂ā寮?code class="mq-233">-XX:UnlockDiagnosticVMOptions鍚庯紝閫氳繃鍙傛暟 浠g爜鏍规壂鎻?Code Root Scanning锛氬浠g爜鏍归泦鍚堣繘琛屾壂鎻忥紝鎵弿JVM缂栬瘧鍚庝唬鐮丯ative Method鐨勫紩鐢ㄤ俊鎭?nmethod鎵弿)锛岃繘琛孯Set鎵弿銆備簨瀹炰笂锛屽彧鏈塁Set鍒嗗尯涓殑RSet鏈夊己浠g爜鏍规椂锛屾墠浼氬仛nmethod鎵弿锛屾煡鎵惧CSet鐨勫紩鐢ㄣ€?/p>
杞Щ鍜屽洖鏀?Object Copy锛氶€氳繃閫夊畾鐨凜Set浠ュ強CSet鍒嗗尯瀹屾暣鐨勫紩鐢ㄩ泦锛屽皢鎵ц鏆傚仠鏃堕棿鐨勪富瑕侀儴鍒嗭細CSet鍒嗗尯瀛樻椿瀵硅薄鐨勮浆绉汇€丆Set鍒嗗尯绌洪棿鐨勫洖鏀躲€傞€氳繃宸ヤ綔绐冨彇鏈哄埗鏉ヨ礋杞藉潎琛″湴閫夊畾澶嶅埗瀵硅薄鐨勭嚎绋嬶紝骞朵笖澶嶅埗鍜屾壂鎻忓璞¤杞Щ鐨勫瓨娲诲璞″皢鎷疯礉鍒版瘡涓狦C绾跨▼鍒嗛厤缂撳啿鍖篏CLAB銆侴1浼氶€氳繃璁$畻锛岄娴嬪垎鍖哄鍒舵墍鑺辫垂鐨勬椂闂达紝浠庤€岃皟鏁村勾杞讳唬鐨勫昂瀵搞€?/p>
缁堟 Termination锛氬畬鎴愪笂杩颁换鍔″悗锛屽鏋滀换鍔¢槦鍒楀凡绌猴紝鍒欏伐浣滅嚎绋嬩細鍙戣捣缁堟瑕佹眰銆傚鏋滆繕鏈夊叾浠栫嚎绋嬬户缁伐浣滐紝绌洪棽鐨勭嚎绋嬩細閫氳繃宸ヤ綔绐冨彇鏈哄埗灏濊瘯甯姪鍏朵粬绾跨▼澶勭悊銆傝€屽崟鐙墽琛屾牴鍒嗗尯鎵弿鐨勭嚎绋嬶紝濡傛灉浠诲姟杩囬噸锛屾渶缁堜細鏅氫簬缁堟銆?/p>
GC澶栭儴鐨勫苟琛屾椿鍔?GC Worker Other锛氳閮ㄥ垎骞堕潪GC鐨勬椿鍔紝鑰屾槸JVM鐨勬椿鍔ㄥ鑷村崰鐢ㄤ簡GC鏆傚仠鏃堕棿(渚嬪JNI缂栬瘧)銆?/p>
涓茶娲诲姩 浠g爜鏍规洿鏂?Code Root Fixup锛氭牴鎹浆绉诲璞℃洿鏂颁唬鐮佹牴銆?/p>
浠g爜鏍规竻鐞?Code Root Purge锛氭竻鐞嗕唬鐮佹牴闆嗗悎琛ㄣ€?/p>
娓呴櫎鍏ㄥ眬鍗$墖鏍囪 Clear CT锛氬湪浠绘剰鏀堕泦鍛ㄦ湡浼氭壂鎻廋Set涓嶳Set璁板綍鐨凱RT锛屾壂鎻忔椂浼氬湪鍏ㄥ眬鍗$墖琛ㄤ腑杩涜鏍囪锛岄槻姝㈤噸澶嶆壂鎻忋€傚湪鏀堕泦鍛ㄦ湡鐨勬渶鍚庡皢浼氭竻闄ゅ叏灞€鍗$墖琛ㄤ腑鐨勫凡鎵弿鏍囧織銆?/p>
閫夋嫨涓嬫鏀堕泦闆嗗悎 Choose CSet锛氳閮ㄥ垎涓昏鐢ㄤ簬骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆嗐€佷互鍙婃贩鍚堟敹闆嗕腑锛屽湪杩欎簺鏀堕泦杩囩▼涓紝鐢变簬鏈夎€佸勾浠e€欓€夊垎鍖虹殑鍔犲叆锛屽線寰€闇€瑕佸涓嬫鏀堕泦鐨勮寖鍥村仛鍑虹晫瀹氾紱浣嗗崟绾殑骞磋交浠f敹闆嗕腑锛屾墍鏈夋敹闆嗙殑鍒嗗尯閮戒細琚敹闆嗭紝涓嶅瓨鍦ㄩ€夋嫨銆?/p>
寮曠敤澶勭悊 Ref Proc锛氫富瑕侀拡瀵硅蒋寮曠敤銆佸急寮曠敤銆佽櫄寮曠敤銆乫inal寮曠敤銆丣NI寮曠敤銆傚綋Ref Proc鍗犵敤鏃堕棿杩囧鏃讹紝鍙€夋嫨浣跨敤鍙傛暟 寮曠敤鎺掗槦 Ref Enq锛氭椤规椿鍔ㄥ彲鑳戒細瀵艰嚧RSet鐨勬洿鏂帮紝姝ゆ椂浼氶€氳繃璁板綍鏃ュ織锛屽皢鍏宠仈鐨勫崱鐗囨爣璁颁负鑴忓崱鐗囥€?/p>
鍗$墖閲嶆柊鑴忓寲 Redirty Cards锛氶噸鏂拌剰鍖栧崱鐗囥€?/p>
鍥炴敹绌洪棽宸ㄥ瀷鍒嗗尯 Humongous Reclaim锛欸1鍋氫簡涓€涓紭鍖栵細閫氳繃鏌ョ湅鎵€鏈夋牴瀵硅薄浠ュ強骞磋交浠e垎鍖虹殑RSet锛屽鏋滅‘瀹歊Set涓法鍨嬪璞℃病鏈変换浣曞紩鐢紝鍒欒鏄嶨1鍙戠幇浜嗕竴涓笉鍙揪鐨勫法鍨嬪璞★紝璇ュ璞″垎鍖轰細琚洖鏀躲€?/p>
閲婃斁鍒嗗尯 Free CSet锛氬洖鏀禖Set鍒嗗尯鐨勬墍鏈夌┖闂达紝骞跺姞鍏ュ埌绌洪棽鍒嗗尯涓€?/p>
鍏朵粬娲诲姩 Other锛欸C涓彲鑳借繕浼氱粡鍘嗗叾浠栬€楁椂寰堝皬鐨勬椿鍔紝濡備慨澶岼NI鍙ユ焺绛夈€?/p>
骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆?Young Collection Following Concurrent Marking Cycle 褰揋1鍙戣捣骞跺彂鏍囪鍛ㄦ湡涔嬪悗锛屽苟涓嶄細椹笂寮€濮嬫贩鍚堟敹闆嗐€侴1浼氬厛绛夊緟涓嬩竴娆″勾杞讳唬鏀堕泦锛岀劧鍚庡湪璇ユ敹闆嗛樁娈典腑锛岀‘瀹氫笅娆℃贩鍚堟敹闆嗙殑CSet(Choose CSet)銆?/p>
娣峰悎鏀堕泦鍛ㄦ湡 Mixed Collection Cycle 鍗曟鐨勬贩鍚堟敹闆嗕笌骞磋交浠f敹闆嗗苟鏃犱簩鑷淬€傛牴鎹殏鍋滅洰鏍囷紝鑰佸勾浠g殑鍒嗗尯鍙兘涓嶈兘涓€娆℃殏鍋滄敹闆嗕腑琚鐞嗗畬锛孏1浼氬彂璧疯繛缁娆$殑娣峰悎鏀堕泦锛岀О涓烘贩鍚堟敹闆嗗懆鏈?Mixed Collection Cycle)銆侴1浼氳绠楁瘡娆″姞鍏ュ埌CSet涓殑鍒嗗尯鏁伴噺銆佹贩鍚堟敹闆嗚繘琛屾鏁帮紝骞朵笖鍦ㄤ笂娆$殑骞磋交浠f敹闆嗐€佷互鍙婃帴涓嬫潵鐨勬贩鍚堟敹闆嗕腑锛孏1浼氱‘瀹氫笅娆″姞鍏Set鐨勫垎鍖洪泦(Choose CSet)锛屽苟涓旂‘瀹氭槸鍚︾粨鏉熸贩鍚堟敹闆嗗懆鏈熴€?/p>
杞Щ澶辫触鐨勬媴淇濇満鍒?Full GC 杞Щ澶辫触(Evacuation Failure)鏄寚褰揋1鏃犳硶鍦ㄥ爢绌洪棿涓敵璇锋柊鐨勫垎鍖烘椂锛孏1渚夸細瑙﹀彂鎷呬繚鏈哄埗锛屾墽琛屼竴娆TW寮忕殑銆佸崟绾跨▼鐨凢ull GC銆侳ull GC浼氬鏁村爢鍋氭爣璁版竻闄ゅ拰鍘嬬缉锛屾渶鍚庡皢鍙寘鍚函绮圭殑瀛樻椿瀵硅薄銆傚弬鏁?code class="mq-261">-XX:G1ReservePercent(榛樿10%)鍙互淇濈暀绌洪棿锛屾潵搴斿鏅嬪崌妯″紡涓嬬殑寮傚父鎯呭喌锛屾渶澶у崰鐢ㄦ暣鍫?0%锛屾洿澶т篃鏃犳剰涔夈€?/p>
G1鍦ㄤ互涓嬪満鏅腑浼氳Е鍙慒ull GC锛屽悓鏃朵細鍦ㄦ棩蹇椾腑璁板綍to-space-exhausted浠ュ強Evacuation Failure锛?/p>
浠庡勾杞讳唬鍒嗗尯鎷疯礉瀛樻椿瀵硅薄鏃讹紝鏃犳硶鎵惧埌鍙敤鐨勭┖闂插垎鍖?/p> 浠庤€佸勾浠e垎鍖鸿浆绉诲瓨娲诲璞℃椂锛屾棤娉曟壘鍒板彲鐢ㄧ殑绌洪棽鍒嗗尯 鍒嗛厤宸ㄥ瀷瀵硅薄鏃跺湪鑰佸勾浠f棤娉曟壘鍒拌冻澶熺殑杩炵画鍒嗗尯 鐢变簬G1鐨勫簲鐢ㄥ満鍚堝線寰€鍫嗗唴瀛橀兘姣旇緝澶э紝鎵€浠ull GC鐨勬敹闆嗕唬浠烽潪甯告槀璐碉紝搴旇閬垮厤Full GC鐨勫彂鐢熴€?/p>
G1鏄竴娆鹃潪甯镐紭绉€鐨勫瀮鍦炬敹闆嗗櫒锛屼笉浠呴€傚悎鍫嗗唴瀛樺ぇ鐨勫簲鐢紝鍚屾椂涔熺畝鍖栦簡璋冧紭鐨勫伐浣溿€傞€氳繃涓昏鐨勫弬鏁板垵濮嬪拰鏈€澶у爢绌洪棿銆佷互鍙婃渶澶у蹇嶇殑GC鏆傚仠鐩爣锛屽氨鑳藉緱鍒颁笉閿欑殑鎬ц兘锛涘悓鏃讹紝鎴戜滑涔熺湅鍒癎1瀵瑰唴瀛樼┖闂寸殑娴垂杈冮珮锛屼絾閫氳繃**棣栧厛鏀堕泦灏藉彲鑳藉鐨勫瀮鍦?Garbage First)**鐨勮璁″師鍒欙紝鍙互鍙婃椂鍙戠幇杩囨湡瀵硅薄锛屼粠鑰岃鍐呭瓨鍗犵敤澶勪簬鍚堢悊鐨勬按骞炽€?/p>
鍙傝€冭祫鏂?/p>
[1] Charlie H, Monica B, Poonam P, Bengt R. Java Performance Companion -娣卞叆鍘熺悊- 鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧 以上是关于璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1> -XX:MaxGCPauseMills
/10)銆傚€煎緱娉ㄦ剰鐨勬槸锛屽鏋滄洿鏂版棩蹇楃紦鍐插尯鏇存柊鐨勪换鍔′笉闄嶄綆锛屽崟绾湴鍑忓皯RSet鐨勬洿鏂版椂闂达紝浼氬鑷存殏鍋滀腑琚鐞嗙殑缂撳啿鍖哄噺灏戯紝灏嗘棩蹇楃紦鍐插尯鏇存柊宸ヤ綔鎺ㄥ埌骞跺彂浼樺寲绾跨▼涓婏紝浠庤€屽鍔犲Java搴旂敤绾跨▼璧勬簮鐨勪簤澶恒€?/p>
-XX:+G1SummarizeRSetStats
鍙互纭畾骞跺彂浼樺寲绾跨▼鏄惁鑳藉鍙婃椂澶勭悊鏇存柊鏃ュ織缂撳啿鍖猴紝骞舵彁渚涙洿澶氱殑淇℃伅锛屾潵甯姪涓篟Set绮楀寲鎬绘暟鎻愪緵绐楀彛銆傚弬鏁?code class="mq-235">-XX锛欸1SummarizeRSetStatsPeriod=n鍙缃甊Set鐨勭粺璁″懆鏈燂紝鍗崇粡鍘嗗灏戞GC鍚庤繘琛屼竴娆$粺璁?/p>
-XX:ParallelRefProcEnabled
婵€娲诲绾跨▼寮曠敤澶勭悊銆侴1甯屾湜搴旂敤鑳藉皬蹇冧娇鐢ㄨ蒋寮曠敤锛屽洜涓鸿蒋寮曠敤浼氫竴鐩村崰鎹唴瀛樼┖闂寸洿鍒扮┖闂磋€楀敖鏃惰Full GC鍥炴敹鎺夛紱鍗充娇鏈彂鐢烣ull GC锛岃蒋寮曠敤瀵瑰唴瀛樼殑鍗犵敤锛屼篃浼氬鑷碐C娆℃暟鐨勫鍔犮€?/p>
骞跺彂鏍囪鍛ㄦ湡鍚庣殑骞磋交浠f敹闆?/h3>
娣峰悎鏀堕泦鍛ㄦ湡
杞Щ澶辫触鐨勬媴淇濇満鍒?Full GC
绗簲绔?鎬荤粨
[2] 鍛ㄥ織鏄? 娣卞叆鐞嗚ВJVM铏氭嫙鏈?/p>
https://www.cnblogs.com/jobbible/p/13476128.html