鍨冨溇鍥炴敹鍣細浣犳槸浠€涔堝瀮鍦撅紵
Posted 瓒h皥缂栫▼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍨冨溇鍥炴敹鍣細浣犳槸浠€涔堝瀮鍦撅紵相关的知识,希望对你有一定的参考价值。
猬嗭笍 鍥剧墖鏉ユ簮浜庣綉缁?/span>
涔嬪墠涓婂鐨勬椂鍊欐湁杩欎釜涓€涓锛岃鍦ㄩ鍫傞噷鍚冮キ锛屽悆瀹屾妸椁愮洏绔蛋娓呯悊鐨勶紝鏄?C++ 绋嬪簭鍛橈紝鍚冨畬鐩存帴灏辫蛋鐨勶紝鏄?Java 绋嬪簭鍛樸€傪煠?/span>
纭疄锛屽湪 Java 鐨勪笘鐣岄噷锛屼技涔庢垜浠笉鐢ㄥ鍨冨溇鍥炴敹閭d箞鐨勪笓娉紝寰堝鍒濆鑰呬笉鎳?GC锛屼篃渚濈劧鑳藉啓鍑轰竴涓兘鐢ㄧ敋鑷宠繕涓嶉敊鐨勭▼搴忔垨绯荤粺銆備絾鍏跺疄杩欏苟涓嶄唬琛?Java 鐨?GC 灏变笉閲嶈銆傜浉鍙嶏紝瀹冩槸閭d箞鐨勯噸瑕佸拰澶嶆潅锛屼互鑷充簬鍑轰簡闂锛岄偅浜涘垵瀛﹁€呴櫎浜嗘墦寮€ GC 鏃ュ織锛岀湅鐫€涓€鍫?101鐨勫ぉ鏂囷紝鍟ヤ篃鍋氫笉浜嗐€傪煒?/span>
浠婂ぉ鎴戜滑灏变粠澶村埌灏惧畬鏁村湴鑱婁竴鑱?Java 鐨勫瀮鍦惧洖鏀躲€?br>
浠€涔堟槸鍨冨溇鍥炴敹
鍨冨溇鍥炴敹锛圙arbage Collection锛孏C锛夛紝椤惧悕鎬濅箟灏辨槸閲婃斁鍨冨溇鍗犵敤鐨勭┖闂达紝闃叉鍐呭瓨娉勯湶銆?/span>鏈夋晥鐨勪娇鐢ㄥ彲浠ヤ娇鐢ㄧ殑鍐呭瓨锛屽鍐呭瓨鍫嗕腑宸茬粡姝讳骸鐨勬垨鑰呴暱鏃堕棿娌℃湁浣跨敤鐨勫璞¤繘琛屾竻闄ゅ拰鍥炴敹銆?/span>
Java 璇█鍑烘潵涔嬪墠锛屽ぇ瀹堕兘鍦ㄦ嫾鍛界殑鍐?C 鎴栬€?C++ 鐨勭▼搴忥紝鑰屾鏃跺瓨鍦ㄤ竴涓緢澶х殑鐭涚浘锛孋++ 绛夎瑷€鍒涘缓瀵硅薄瑕佷笉鏂殑鍘诲紑杈熺┖闂达紝涓嶇敤鐨勬椂鍊欏張闇€瑕佷笉鏂殑鍘婚噴鏀炬帶浠讹紝鏃㈣鍐欐瀯閫犲嚱鏁帮紝鍙堣鍐欐瀽鏋勫嚱鏁帮紝寰堝鏃跺€欓兘鍦ㄩ噸澶嶇殑 allocated锛岀劧鍚庝笉鍋滅殑鏋愭瀯銆?/span>浜庢槸锛屾湁浜哄氨鎻愬嚭锛岃兘涓嶈兘鍐欎竴娈电▼搴忓疄鐜拌繖鍧楀姛鑳斤紝姣忔鍒涘缓锛岄噴鏀炬帶浠剁殑鏃跺€欏鐢ㄨ繖娈典唬鐮侊紝鑰屾棤闇€閲嶅鐨勪功鍐欏憿锛?/span>
1960骞达紝鍩轰簬 MIT 鐨?Lisp 棣栧厛鎻愬嚭浜嗗瀮鍦惧洖鏀剁殑姒傚康锛岃€岃繖鏃?Java 杩樻病鏈夊嚭涓栧憿锛?/span>鎵€浠ュ疄闄呬笂 GC 骞朵笉鏄疛ava鐨勪笓鍒╋紝GC 鐨勫巻鍙茶繙杩滃ぇ浜?Java 鐨勫巻鍙诧紒
鎬庝箞瀹氫箟鍨冨溇
鏃㈢劧鎴戜滑瑕佸仛鍨冨溇鍥炴敹锛岄鍏堟垜浠緱鎼炴竻妤氬瀮鍦剧殑瀹氫箟鏄粈涔堬紝鍝簺鍐呭瓨鏄渶瑕佸洖鏀剁殑銆?/span>
寮曠敤璁℃暟绠楁硶
寮曠敤璁℃暟绠楁硶锛圧eachability Counting锛夋槸閫氳繃鍦ㄥ璞″ご涓垎閰嶄竴涓┖闂存潵淇濆瓨璇ュ璞¤寮曠敤鐨勬鏁帮紙Reference Count锛夈€?/span>濡傛灉璇ュ璞¤鍏跺畠瀵硅薄寮曠敤锛屽垯瀹冪殑寮曠敤璁℃暟鍔?锛屽鏋滃垹闄ゅ璇ュ璞$殑寮曠敤锛岄偅涔堝畠鐨勫紩鐢ㄨ鏁板氨鍑?锛屽綋璇ュ璞$殑寮曠敤璁℃暟涓?鏃讹紝閭d箞璇ュ璞″氨浼氳鍥炴敹銆?/span>
String m = new String("jack");
鍏堝垱寤轰竴涓瓧绗︿覆锛岃繖鏃跺€?jack"鏈変竴涓紩鐢紝灏辨槸 m銆?/span>
鐒跺悗灏?m 璁剧疆涓?null锛岃繖鏃跺€?jack"鐨勫紩鐢ㄦ鏁板氨绛変簬0浜嗭紝鍦ㄥ紩鐢ㄨ鏁扮畻娉曚腑锛屾剰鍛崇潃杩欏潡鍐呭灏遍渶瑕佽鍥炴敹浜嗐€?/span>
m = null;
寮曠敤璁℃暟绠楁硶鏄皢鍨冨溇鍥炴敹鍒嗘憡鍒版暣涓簲鐢ㄧ▼搴忕殑杩愯褰撲腑浜嗭紝鑰屼笉鏄湪杩涜鍨冨溇鏀堕泦鏃讹紝瑕佹寕璧锋暣涓簲鐢ㄧ殑杩愯锛岀洿鍒板鍫嗕腑鎵€鏈夊璞$殑澶勭悊閮界粨鏉熴€?/span>鍥犳锛岄噰鐢ㄥ紩鐢ㄨ鏁扮殑鍨冨溇鏀堕泦涓嶅睘浜庝弗鏍兼剰涔変笂鐨?Stop-The-World"鐨勫瀮鍦炬敹闆嗘満鍒躲€?/span>
鐪嬩技寰堢編濂斤紝浣嗘垜浠煡閬揓VM鐨勫瀮鍦惧洖鏀跺氨鏄?Stop-The-World"鐨勶紝閭f槸浠€涔堝師鍥犲鑷存垜浠渶缁堟斁寮冧簡寮曠敤璁℃暟绠楁硶鍛紵鐪嬩笅闈㈢殑渚嬪瓙銆?/span>
public class ReferenceCountingGC {
public Object instance;
public ReferenceCountingGC(String name){}
}
public static void testGC(){
ReferenceCountingGC a = new ReferenceCountingGC("objA");
ReferenceCountingGC b = new ReferenceCountingGC("objB");
a.instance = b;
b.instance = a;
a = null;
b = null;
}
1. 瀹氫箟2涓璞?/span>
2. 鐩镐簰寮曠敤
3. 缃┖鍚勮嚜鐨勫0鏄庡紩鐢?/span>
鎴戜滑鍙互鐪嬪埌锛?/span>鏈€鍚庤繖2涓璞″凡缁忎笉鍙兘鍐嶈璁块棶浜嗭紝浣嗙敱浜庝粬浠浉浜掑紩鐢ㄧ潃瀵规柟锛屽鑷村畠浠殑寮曠敤璁℃暟姘歌繙閮戒笉浼氫负0锛岄€氳繃寮曠敤璁℃暟绠楁硶锛屼篃灏辨案杩滄棤娉曢€氱煡GC鏀堕泦鍣ㄥ洖鏀跺畠浠€?/span>
鍙揪鎬у垎鏋愮畻娉?/span>
鍙揪鎬у垎鏋愮畻娉曪紙Reachability Analysis锛夌殑鍩烘湰鎬濊矾鏄紝閫氳繃涓€浜涜绉颁负寮曠敤閾撅紙GC Roots锛?/strong>鐨勫璞′綔涓鸿捣鐐癸紝浠庤繖浜涜妭鐐瑰紑濮嬪悜涓嬫悳绱紝鎼滅储璧拌繃鐨勮矾寰勮绉颁负锛圧eference Chain)锛?/span>褰撲竴涓璞″埌 GC Roots 娌℃湁浠讳綍寮曠敤閾剧浉杩炴椂锛堝嵆浠?GC Roots 鑺傜偣鍒拌鑺傜偣涓嶅彲杈撅級锛屽垯璇佹槑璇ュ璞℃槸涓嶅彲鐢ㄧ殑銆?/span>
閫氳繃鍙揪鎬х畻娉曪紝鎴愬姛瑙e喅浜嗗紩鐢ㄨ鏁版墍鏃犳硶瑙e喅鐨勯棶棰?鈥滃惊鐜緷璧栤€濓紝鍙浣犳棤娉曚笌 GC Root 寤虹珛鐩存帴鎴栭棿鎺ョ殑杩炴帴锛岀郴缁熷氨浼氬垽瀹氫綘涓哄彲鍥炴敹瀵硅薄銆傞偅杩欐牱灏卞紩鐢冲嚭浜嗗彟涓€涓棶棰橈紝鍝簺灞炰簬 GC Root锛?/span>
Java 鍐呭瓨鍖哄煙
鍦?Java 璇█涓紝鍙綔涓?GC Root 鐨勫璞″寘鎷互涓?绉嶏細
铏氭嫙鏈烘爤锛堟爤甯т腑鐨勬湰鍦板彉閲忚〃锛変腑寮曠敤鐨勫璞?/span>
鏂规硶鍖轰腑绫婚潤鎬佸睘鎬у紩鐢ㄧ殑瀵硅薄
鏂规硶鍖轰腑甯搁噺寮曠敤鐨勫璞?/span>
鏈湴鏂规硶鏍堜腑 JNI锛堝嵆涓€鑸鐨?Native 鏂规硶锛夊紩鐢ㄧ殑瀵硅薄
铏氭嫙鏈烘爤锛堟爤甯т腑鐨勬湰鍦板彉閲忚〃锛変腑寮曠敤鐨勫璞?/span>
姝ゆ椂鐨?s锛堜笅闈唬鐮佷腑鐨剆锛夛紝鍗充负 GC Root锛屽綋s缃┖鏃讹紝localParameter 瀵硅薄涔熸柇鎺変簡涓?GC Root 鐨勫紩鐢ㄩ摼锛屽皢琚洖鏀躲€?/span>
public class StackLocalParameter {
public StackLocalParameter(String name){}
}
public static void testGC(){
StackLocalParameter s = new StackLocalParameter("localParameter");
s = null;
}
鏂规硶鍖轰腑绫婚潤鎬佸睘鎬у紩鐢ㄧ殑瀵硅薄
s 涓?GC Root锛宻 缃负 null锛岀粡杩?GC 鍚庯紝s 鎵€鎸囧悜鐨?properties 瀵硅薄鐢变簬鏃犳硶涓?GC Root 寤虹珛鍏崇郴琚洖鏀躲€?/span>
鑰?m 浣滀负绫荤殑闈欐€佸睘鎬?/span>锛?/span>涔熷睘浜?GC Root锛宲arameter 瀵硅薄渚濈劧涓?GC root 寤虹珛鐫€杩炴帴锛屾墍浠ユ鏃?parameter 瀵硅薄骞朵笉浼氳鍥炴敹銆?/span>
public class MethodAreaStaicProperties {
public static MethodAreaStaicProperties m;
public MethodAreaStaicProperties(String name){}
}
public static void testGC(){
MethodAreaStaicProperties s = new MethodAreaStaicProperties("properties");
s.m = new MethodAreaStaicProperties("parameter");
s = null;
}
鏂规硶鍖轰腑甯搁噺寮曠敤鐨勫璞?/span>
m 鍗充负鏂规硶鍖轰腑鐨勫父閲忓紩鐢?/span>锛屼篃涓?GC Root锛宻 缃负 null 鍚庯紝final 瀵硅薄涔熶笉浼氬洜娌℃湁涓?GC Root 寤虹珛鑱旂郴鑰岃鍥炴敹銆?/span>
public class MethodAreaStaicProperties {
public static final MethodAreaStaicProperties m = MethodAreaStaicProperties("final");
public MethodAreaStaicProperties(String name){}
}
public static void testGC(){
MethodAreaStaicProperties s = new MethodAreaStaicProperties("staticProperties");
s = null;
}
鏈湴鏂规硶鏍堜腑寮曠敤鐨勫璞?/span>
浠讳綍 Native 鎺ュ彛閮戒細浣跨敤鏌愮鏈湴鏂规硶鏍堬紝瀹炵幇鐨勬湰鍦版柟娉曟帴鍙f槸浣跨敤 C 杩炴帴妯″瀷鐨勮瘽锛岄偅涔堝畠鐨勬湰鍦版柟娉曟爤灏辨槸 C 鏍堛€?/span>褰撶嚎绋嬭皟鐢?Java 鏂规硶鏃讹紝铏氭嫙鏈轰細鍒涘缓涓€涓柊鐨勬爤甯у苟鍘嬪叆 Java 鏍堛€?/span>鐒惰€屽綋瀹冭皟鐢ㄧ殑鏄湰鍦版柟娉曟椂锛岃櫄鎷熸満浼氫繚鎸?Java 鏍堜笉鍙橈紝涓嶅啀鍦ㄧ嚎绋嬬殑 Java 鏍堜腑鍘嬪叆鏂扮殑甯э紝铏氭嫙鏈哄彧鏄畝鍗曞湴鍔ㄦ€佽繛鎺ュ苟鐩存帴璋冪敤鎸囧畾鐨勬湰鍦版柟娉曘€?/span>
鎬庝箞鍥炴敹鍨冨溇
鍦ㄧ‘瀹氫簡鍝簺鍨冨溇鍙互琚洖鏀跺悗锛屽瀮鍦炬敹闆嗗櫒瑕佸仛鐨勪簨鎯呭氨鏄紑濮嬭繘琛屽瀮鍦惧洖鏀讹紝浣嗘槸杩欓噷闈㈡秹鍙婂埌涓€涓棶棰樻槸锛?/span>濡備綍楂樻晥鍦拌繘琛屽瀮鍦惧洖鏀讹紵
鐢变簬Java铏氭嫙鏈鸿鑼冨苟娌℃湁瀵瑰浣曞疄鐜板瀮鍦炬敹闆嗗櫒鍋氬嚭鏄庣‘鐨勮瀹氾紝鍥犳鍚勪釜鍘傚晢鐨勮櫄鎷熸満鍙互閲囩敤涓嶅悓鐨勬柟寮忔潵瀹炵幇鍨冨溇鏀堕泦鍣紝杩欓噷鎴戜滑璁ㄨ鍑犵甯歌鐨勫瀮鍦炬敹闆嗙畻娉曠殑鏍稿績鎬濇兂銆?/span>
鏍囪 --- 娓呴櫎绠楁硶
鏍囪娓呴櫎绠楁硶锛圡ark-Sweep锛夋槸鏈€鍩虹鐨勪竴绉嶅瀮鍦惧洖鏀剁畻娉曪紝瀹冨垎涓?閮ㄥ垎锛屽厛鎶婂唴瀛樺尯鍩熶腑鐨勮繖浜涘璞¤繘琛屾爣璁帮紝鍝簺灞炰簬鍙洖鏀舵爣璁板嚭鏉ワ紝鐒跺悗鎶婅繖浜涘瀮鍦炬嫀鍑烘潵娓呯悊鎺?/span>銆傚氨鍍忎笂鍥句竴鏍凤紝娓呯悊鎺夌殑鍨冨溇灏卞彉鎴愭湭浣跨敤鐨勫唴瀛樺尯鍩燂紝绛夊緟琚啀娆′娇鐢ㄣ€?/h1>
娑涘0渚濇棫娉細鏍囪鍨冨溇瀵硅薄鏄剧劧閲囩敤鐨勫氨鏄笂鏂囦腑璇寸殑鍙揪鎬у垎鏋愩€?/p>
杩欓€昏緫鍐嶆竻鏅颁笉杩囦簡锛屽苟涓斾篃寰堝ソ鎿嶄綔锛屼絾瀹冨瓨鍦ㄤ竴涓緢澶х殑闂锛岄偅灏辨槸鍐呭瓨纰庣墖銆?/h1>
涓婂浘涓瓑鏂瑰潡鐨勫亣璁炬槸 2M锛屽皬涓€浜涚殑鏄?1M锛屽ぇ涓€浜涚殑鏄?4M銆傜瓑鎴戜滑鍥炴敹瀹岋紝鍐呭瓨灏变細鍒囨垚浜嗗緢澶氭銆傛垜浠煡閬?span class="mq-233">寮€杈熷唴瀛樼┖闂存椂锛岄渶瑕佺殑鏄繛缁殑鍐呭瓨鍖哄煙
锛岃繖鏃跺€欐垜浠渶瑕佷竴涓?2M鐨勫唴瀛樺尯鍩燂紝鍏朵腑鏈?涓?1M 鏄病娉曠敤鐨勩€傝繖鏍峰氨瀵艰嚧锛屽叾瀹炴垜浠湰韬繕鏈夎繖涔堝鐨勫唴瀛樼殑锛屼絾鍗寸敤涓嶄簡銆?/h1>
澶嶅埗绠楁硶
涓婂浘涓瓑鏂瑰潡鐨勫亣璁炬槸 2M锛屽皬涓€浜涚殑鏄?1M锛屽ぇ涓€浜涚殑鏄?4M銆傜瓑鎴戜滑鍥炴敹瀹岋紝鍐呭瓨灏变細鍒囨垚浜嗗緢澶氭銆傛垜浠煡閬?span class="mq-233">寮€杈熷唴瀛樼┖闂存椂锛岄渶瑕佺殑鏄繛缁殑鍐呭瓨鍖哄煙
澶嶅埗绠楁硶锛圕opying锛夋槸鍦ㄦ爣璁版竻闄ょ畻娉曚笂婕斿寲鑰屾潵锛岃В鍐虫爣璁版竻闄ょ畻娉曠殑鍐呭瓨纰庣墖闂銆傚畠灏嗗彲鐢ㄥ唴瀛樻寜瀹归噺鍒掑垎涓哄ぇ灏忕浉绛夌殑涓ゅ潡锛屾瘡娆″彧浣跨敤鍏朵腑鐨勪竴鍧椼€傚綋杩欎竴鍧楃殑鍐呭瓨鐢ㄥ畬浜嗭紝灏?/span>灏嗚繕瀛樻椿鐫€鐨勫璞″鍒跺埌鍙﹀涓€鍧椾笂闈?/span>锛?/span>鐒跺悗鍐嶆妸宸蹭娇鐢ㄨ繃鐨勫唴瀛樼┖闂翠竴娆℃竻鐞嗘帀銆備繚璇佷簡鍐呭瓨鐨勮繛缁彲鐢紝鍐呭瓨鍒嗛厤鏃朵篃灏变笉鐢ㄨ€冭檻鍐呭瓨纰庣墖绛夊鏉傛儏鍐碉紝閫昏緫娓呮櫚锛岃繍琛岄珮鏁堛€?/span>
涓婇潰鐨勫浘寰堟竻妤氾紝涔熷緢鏄庢樉鐨勬毚闇蹭簡鍙︿竴涓棶棰橈紝鍚堢潃鎴戣繖140骞崇殑澶т笁鎴匡紝鍙兘褰?0骞崇背鐨勫皬涓ゆ埧鏉ヤ娇锛?/span>浠d环瀹炲湪澶珮銆?/span>
鏍囪鏁寸悊绠楁硶
鏍囪鏁寸悊绠楁硶锛圡ark-Compact锛夋爣璁拌繃绋嬩粛鐒朵笌鏍囪 --- 娓呴櫎绠楁硶涓€鏍凤紝浣嗗悗缁楠や笉鏄洿鎺ュ鍙洖鏀跺璞¤繘琛屾竻鐞嗭紝鑰屾槸璁╂墍鏈夊瓨娲荤殑瀵硅薄閮藉悜涓€绔Щ鍔?/span>锛?/span>鍐嶆竻鐞嗘帀绔竟鐣屼互澶栫殑鍐呭瓨鍖哄煙銆?/span>
鍒嗕唬鏀堕泦绠楁硶鍒嗕唬鏀堕泦绠楁硶锛圙enerational Collection锛変弗鏍兼潵璇村苟涓嶆槸涓€绉嶆€濇兂鎴栫悊璁猴紝鑰屾槸铻嶅悎涓婅堪3绉嶅熀纭€鐨勭畻娉曟€濇兂锛岃€屼骇鐢熺殑閽堝涓嶅悓鎯呭喌鎵€閲囩敤涓嶅悓绠楁硶鐨勪竴濂楃粍鍚堟嫵銆?/span>
瀵硅薄瀛樻椿鍛ㄦ湡鐨勪笉鍚屽皢鍐呭瓨鍒掑垎涓哄嚑鍧椼€?/span>涓€鑸槸鎶?Java 鍫嗗垎涓烘柊鐢熶唬鍜岃€佸勾浠o紝杩欐牱灏卞彲浠ユ牴鎹悇涓勾浠g殑鐗圭偣閲囩敤鏈€閫傚綋鐨勬敹闆嗙畻娉曘€?/span>
鍦ㄦ柊鐢熶唬涓紝姣忔鍨冨溇鏀堕泦鏃堕兘鍙戠幇鏈夊ぇ鎵瑰璞℃鍘伙紝鍙湁灏戦噺瀛樻椿锛岄偅灏遍€夌敤澶嶅埗绠楁硶锛?/span>鍙渶瑕佷粯鍑哄皯閲忓瓨娲诲璞$殑澶嶅埗鎴愭湰灏卞彲浠ュ畬鎴愭敹闆?/span>銆?/span>
鑰岃€佸勾浠d腑鍥犱负瀵硅薄瀛樻椿鐜囬珮銆佹病鏈夐澶栫┖闂村瀹冭繘琛屽垎閰嶆媴淇濓紝灏卞繀椤讳娇鐢ㄦ爣璁?娓呯悊鎴栬€呮爣璁?--- 鏁寸悊绠楁硶鏉ヨ繘琛屽洖鏀躲€俿o锛屽彟涓€涓棶棰樻潵浜嗭紝閭?/span>鍐呭瓨鍖哄煙鍒板簳琚垎涓哄摢鍑犲潡锛屾瘡涓€鍧楀張鏈変粈涔堢壒鍒€傚悎浠€涔堢畻娉曞憿锛?/span>
鍐呭瓨妯″瀷涓庡洖鏀剁瓥鐣?/span>
Java 鍫嗭紙Java Heap锛夋槸JVM鎵€绠$悊鐨勫唴瀛樹腑鏈€澶х殑涓€鍧楋紝鍫嗗張鏄瀮鍦炬敹闆嗗櫒绠$悊鐨勪富瑕佸尯鍩燂紝杩欓噷鎴戜滑涓昏鍒嗘瀽涓€涓?Java 鍫嗙殑缁撴瀯銆?/span>
Java 鍫嗕富瑕佸垎涓?涓尯鍩?骞磋交浠?/strong>涓?span>鑰佸勾浠?/strong>锛屽叾涓勾杞讳唬鍙堝垎 Eden 鍖?/strong>鍜?Survivor 鍖?/strong>锛屽叾涓?Survivor 鍖哄張鍒?From 鍜?span> To 2涓尯銆?/span>
鍙兘杩欐椂鍊欏ぇ瀹朵細鏈夌枒闂紝涓轰粈涔堥渶瑕?nbsp;Survivor 鍖猴紝涓轰粈涔?span class="mq-312">Survivor 杩樿鍒?涓尯銆?/span>涓嶇潃鎬ワ紝鎴戜滑浠庡ご鍒板熬锛岀湅鐪嬪璞″埌搴曟槸鎬庝箞鏉ョ殑锛岃€屽畠鍙堟槸鎬庝箞娌$殑銆?/span>
Eden 鍖?/span>
IBM 鍏徃鐨勪笓涓氱爺绌惰〃鏄庯紝鏈夊皢杩?8%鐨勫璞℃槸鏈濈敓澶曟锛屾墍浠ラ拡瀵硅繖涓€鐜扮姸锛屽ぇ澶氭暟鎯呭喌涓嬶紝瀵硅薄浼氬湪鏂扮敓浠?Eden 鍖轰腑杩涜鍒嗛厤锛屽綋 Eden 鍖烘病鏈夎冻澶熺┖闂磋繘琛屽垎閰嶆椂锛岃櫄鎷熸満浼氬彂璧蜂竴娆?Minor GC锛孧inor GC 鐩告瘮 Major GC 鏇撮绻侊紝鍥炴敹閫熷害涔熸洿蹇€?/span>
閫氳繃 Minor GC 涔嬪悗锛孍den 浼氳娓呯┖锛孍den 鍖轰腑缁濆ぇ閮ㄥ垎瀵硅薄浼氳鍥炴敹锛岃€岄偅浜涙棤闇€鍥炴敹鐨勫瓨娲诲璞★紝灏嗕細杩涘埌 Survivor 鐨?From 鍖猴紙鑻?From 鍖轰笉澶燂紝鍒欑洿鎺ヨ繘鍏?Old 鍖猴級銆?/span>
Survivor 鍖?/span>
Survivor 鍖虹浉褰撲簬鏄?Eden 鍖哄拰 Old 鍖虹殑涓€涓紦鍐?/span>锛岀被浼间簬鎴戜滑浜ら€氱伅涓殑榛勭伅銆係urvivor 鍙堝垎涓?涓尯锛屼竴涓槸 From 鍖猴紝涓€涓槸 To 鍖恒€傛瘡娆℃墽琛?Minor GC锛屼細灏?Eden 鍖哄拰 From 瀛樻椿鐨勫璞℃斁鍒?Survivor 鐨?To 鍖猴紙濡傛灉 To 鍖轰笉澶燂紝鍒欑洿鎺ヨ繘鍏?Old 鍖猴級銆?/span>
涓哄暐闇€瑕侊紵
涓嶅氨鏄柊鐢熶唬鍒拌€佸勾浠d箞锛岀洿鎺?Eden 鍒?Old 涓嶅ソ浜嗗悧锛屼负鍟ヨ杩欎箞澶嶆潅銆傛兂鎯冲鏋滄病鏈?Survivor 鍖猴紝Eden 鍖烘瘡杩涜涓€娆?Minor GC锛屽瓨娲荤殑瀵硅薄灏变細琚€佸埌鑰佸勾浠o紝鑰佸勾浠e緢蹇氨浼氳濉弧銆?/span>
鑰屾湁寰堝瀵硅薄铏界劧涓€娆?Minor GC 娌℃湁娑堢伃锛屼絾鍏跺疄涔熷苟涓嶄細韫﹁范澶氫箙锛屾垨璁哥浜屾锛岀涓夋灏遍渶瑕佽娓呴櫎銆?/span>杩欐椂鍊欑Щ鍏ヨ€佸勾鍖猴紝寰堟槑鏄句笉鏄竴涓槑鏅虹殑鍐冲畾銆?/span>
鎵€浠ワ紝Survivor 鐨勫瓨鍦ㄦ剰涔夊氨鏄噺灏戣閫佸埌鑰佸勾浠g殑瀵硅薄锛岃繘鑰屽噺灏?Major GC 鐨勫彂鐢熴€係urvivor 鐨勯绛涢€変繚璇侊紝鍙湁缁忓巻16娆?Minor GC 杩樿兘鍦ㄦ柊鐢熶唬涓瓨娲荤殑瀵硅薄锛屾墠浼氳閫佸埌鑰佸勾浠c€?/span>
涓哄暐闇€瑕佷咯锛?/span>
璁剧疆涓や釜 Survivor 鍖烘渶澶х殑濂藉灏辨槸瑙e喅鍐呭瓨纰庣墖鍖栥€?/span>
鎴戜滑鍏堝亣璁句竴涓嬶紝Survivor 濡傛灉鍙湁涓€涓尯鍩熶細鎬庢牱銆侻inor GC 鎵ц鍚庯紝Eden 鍖鸿娓呯┖浜嗭紝瀛樻椿鐨勫璞℃斁鍒颁簡 Survivor 鍖猴紝鑰?/span>涔嬪墠 Survivor 鍖轰腑鐨勫璞?/span>锛?/span>鍙兘涔?/span>鏈変竴浜?/span>鏄渶瑕佽娓呴櫎鐨?/span>銆?/span>
闂鏉ヤ簡锛岃繖鏃跺€欐垜浠€庝箞娓呴櫎瀹冧滑锛熷湪杩欑鍦烘櫙涓嬶紝鎴戜滑鍙兘鏍囪娓呴櫎锛岃€屾垜浠煡閬撴爣璁版竻闄ゆ渶澶х殑闂灏辨槸鍐呭瓨纰庣墖锛屽湪鏂扮敓浠h繖绉?/span>缁忓父浼氭秷浜$殑鍖哄煙锛?/span>閲囩敤鏍囪娓呴櫎蹇呯劧浼氳鍐呭瓨浜х敓涓ラ噸鐨勭鐗囧寲銆?/span>
鍥犱负 Survivor 鏈?涓尯鍩燂紝鎵€浠ユ瘡娆?Minor GC锛屼細灏嗕箣鍓?Eden 鍖哄拰 From 鍖轰腑鐨勫瓨娲诲璞″鍒跺埌 To 鍖哄煙銆?/span>绗簩娆?Minor GC 鏃讹紝From 涓?To 鑱岃矗鍏戞崲锛岃繖鏃跺€欎細灏?Eden 鍖哄拰 To 鍖轰腑鐨勫瓨娲诲璞″啀澶嶅埗鍒?From 鍖哄煙锛屼互姝ゅ弽澶嶃€?/span>
杩欑鏈哄埗鏈€澶х殑濂藉灏辨槸锛屾暣涓繃绋嬩腑锛?/span>姘歌繙鏈変竴涓?nbsp;Survivor space 鏄┖鐨勶紝鍙︿竴涓潪绌虹殑 Survivor space 鏄棤纰庣墖鐨?/span>銆傞偅涔堬紝Survivor 涓轰粈涔堜笉鍒嗘洿澶氬潡鍛紵姣旀柟璇村垎鎴愪笁涓€佸洓涓€佷簲涓?鏄剧劧锛屽鏋?Survivor 鍖哄啀缁嗗垎涓嬪幓锛屾瘡涓€鍧楃殑绌洪棿灏变細姣旇緝灏忥紝瀹规槗瀵艰嚧 Survivor 鍖烘弧锛屼袱鍧?Survivor 鍖哄彲鑳芥槸缁忚繃鏉冭 涔嬪悗鐨勬渶浣虫柟妗堛€?/span>
Old 鍖?/span>
鑰佸勾浠e崰鎹潃2/3鐨勫爢鍐呭瓨绌洪棿锛屽彧鏈夊湪 Major GC 鐨勬椂鍊欐墠浼氳繘琛屾竻鐞嗭紝姣忔 GC 閮戒細瑙﹀彂鈥淪top-The-World鈥濄€傚唴瀛樿秺澶э紝STW 鐨勬椂闂翠篃瓒婇暱锛屾墍浠ュ唴瀛樹篃涓嶄粎浠呮槸瓒婂ぇ灏辫秺濂姐€傜敱浜庡鍒剁畻娉曞湪瀵硅薄瀛樻椿鐜囪緝楂樼殑鑰佸勾浠d細杩涜寰堝娆$殑澶嶅埗鎿嶄綔锛屾晥鐜囧緢浣?/span>锛屾墍浠ヨ€佸勾浠h繖閲岄噰鐢ㄧ殑鏄爣璁?--- 鏁寸悊绠楁硶銆?/span>
闄や簡涓婅堪鎵€璇达紝鍦ㄥ唴瀛樻媴淇濇満鍒朵笅锛屾棤娉曞畨缃殑瀵硅薄浼氱洿鎺ヨ繘鍒拌€佸勾浠o紝浠ヤ笅鍑犵鎯呭喌涔熶細杩涘叆鑰佸勾浠c€?/span>
澶у璞?/span>
澶у璞℃寚闇€瑕佸ぇ閲忚繛缁唴瀛樼┖闂寸殑瀵硅薄锛岃繖閮ㄥ垎瀵硅薄涓嶇鏄笉鏄€滄湞鐢熷姝烩€濓紝閮戒細鐩存帴杩涘埌鑰佸勾浠?/span>銆傝繖鏍峰仛涓昏鏄负浜嗛伩鍏嶅湪 Eden 鍖哄強2涓?Survivor 鍖轰箣闂村彂鐢熷ぇ閲忕殑鍐呭瓨澶嶅埗銆傚綋浣犵殑绯荤粺鏈夐潪甯稿鈥滄湞鐢熷姝烩€濈殑澶у璞℃椂锛屽緱娉ㄦ剰浜嗐€?/span>
闀挎湡瀛樻椿瀵硅薄
铏氭嫙鏈虹粰姣忎釜瀵硅薄瀹氫箟浜嗕竴涓璞″勾榫勶紙Age锛夎鏁板櫒銆?/span>姝e父鎯呭喌涓嬪璞′細涓嶆柇鐨勫湪 Survivor 鐨?From 鍖轰笌 To 鍖轰箣闂寸Щ鍔紝瀵硅薄鍦?Survivor 鍖轰腑姣忕粡鍘嗕竴娆?Minor GC锛屽勾榫勫氨澧炲姞1宀併€?/span>褰撳勾榫勫鍔犲埌15宀佹椂锛岃繖鏃跺€欏氨浼氳杞Щ鍒拌€佸勾浠c€?/span>褰撶劧锛岃繖閲岀殑15锛孞VM 涔熸敮鎸佽繘琛岀壒娈婅缃€?/span>
鍔ㄦ€佸璞″勾榫?/span>
铏氭嫙鏈哄苟涓嶉噸瑙嗚姹傚璞″勾榫勫繀椤诲埌15宀侊紝鎵嶄細鏀惧叆鑰佸勾鍖猴紝濡傛灉 Survivor 绌洪棿涓浉鍚屽勾榫勬墍鏈夊璞″ぇ灏忕殑鎬诲悎澶т簬 Survivor 绌洪棿鐨勪竴鍗婏紝骞撮緞澶т簬绛変簬璇ュ勾榫勭殑瀵硅薄灏卞彲浠ョ洿鎺ヨ繘鍘昏€佸勾鍖猴紝鏃犻渶绛変綘鈥滄垚骞粹€濄€?/span>
杩欏叾瀹炴湁鐐圭被浼间簬璐熻浇鍧囪 锛岃疆璇㈡槸璐熻浇鍧囪 鐨勪竴绉嶏紝淇濊瘉姣忓彴鏈哄櫒閮藉垎寰楀悓鏍风殑璇锋眰銆?/span>鐪嬩技寰堝潎琛★紝浣嗘瘡鍙版満鐨勭‖浠朵笉閫氾紝鍋ュ悍鐘跺喌涓嶅悓锛屾垜浠繕鍙互鍩轰簬姣忓彴鏈烘帴鍙楃殑璇锋眰鏁帮紝鎴栨瘡鍙版満鐨勫搷搴旀椂闂寸瓑锛屾潵璋冩暣鎴戜滑鐨勮礋杞藉潎琛$畻娉曘€?/span>
鏈枃閮ㄥ垎鍐呭鍙傝€冭嚜涔︾睄锛氥€婃繁鍏ョ悊瑙ava铏氭嫙鏈恒€嬨€?/span>
漏姣忓懆涓€鎺?/span>
绗竴鏃堕棿鑾峰緱涓嬫湡鍒嗕韩
鍏虫敞鎴戯紝璁╀綘杞绘澗瀛︾紪绋?/span>
以上是关于鍨冨溇鍥炴敹鍣細浣犳槸浠€涔堝瀮鍦撅紵的主要内容,如果未能解决你的问题,请参考以下文章