闈㈣瘯蹇呴棶鐨?JVM 杩愯鏃舵暟鎹尯锛屼綘鎳備簡鍚楋紵
Posted 绋嬪簭鍛樺洤杈?; var articleD
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了闈㈣瘯蹇呴棶鐨?JVM 杩愯鏃舵暟鎹尯锛屼綘鎳備簡鍚楋紵相关的知识,希望对你有一定的参考价值。
鍓嶈█
Java聽铏氭嫙鏈虹殑杩愯鏃舵暟鎹尯缁忓父鍦ㄩ潰璇曚腑琚嬁鏉ユ彁闂?#xff0c;寰堝姒傚康鍦ㄥ競闈笂鏈夊悇绉嶅悇鏍风殑璇存硶,鎼炵殑涓嶅皯鍚屽搴旇鏄嚨閫肩殑銆?/p>
褰撴垜浠櫡鍏ヤ笉鐭ラ亾鍝釜璇存硶鏄纭殑鎯呭喌鏃?#xff0c;鏈€濂界殑鍙傝€冨氨鏄簮鐮佸拰瑙勮寖銆?/p>
鍦ㄩ潰璇曚腑,褰撻潰璇曞畼鍙嶉棶浣?#xff1a;涓轰粈涔堟煇鏌愭槸杩欐牱?鐨勬椂鍊?#xff0c;濡傛灉浣犲洖绛?#xff1a;鍥犱负瑙勮寖鏄繖涔堝啓鐨勩€佸洜涓烘簮鐮佹槸杩欎箞鍐欑殑銆?/p>
杩欎釜鍥炵瓟鏄潪甯告湁璇存湇鍔涚殑銆?/p>
鍥犳,鏈枃鍦ㄦ弿杩颁竴浜涙湁浜夎鐨勯棶棰樹笂,浼樺厛浠ャ€奐ava聽铏氭嫙鏈鸿鑼冦€嬬殑璇存硶涓哄噯銆?/p>
姝f枃
1銆佽繍琛屾椂鏁版嵁鍖?#xff08;Run-Time Data Areas)
Java 铏氭嫙鏈哄畾涔変簡鑻ュ共绉嶅湪绋嬪簭鎵ц鏈熼棿浼氫娇鐢ㄥ埌鐨勮繍琛屾椂鏁版嵁鍖哄煙銆?/p>
鍏朵腑涓€浜涙暟鎹尯鍩熷湪 Java 铏氭嫙鏈哄惎鍔ㄦ椂琚垱寤?#xff0c;闅忕潃铏氭嫙鏈洪€€鍑鸿€岄攢姣併€備篃灏辨槸绾跨▼闂村叡浜殑鍖哄煙:鍫嗐€佹柟娉曞尯銆佽繍琛屾椂甯搁噺姹犮€?/p>
鍙﹀涓€浜涙暟鎹尯鍩熸槸鎸夌嚎绋嬪垝鍒嗙殑,杩欎簺鏁版嵁鍖哄煙鍦ㄧ嚎绋嬪垱寤烘椂鍒涘缓,鍦ㄧ嚎绋嬮€€鍑烘椂閿€姣併€備篃灏辨槸绾跨▼闂撮殧绂荤殑鍖哄煙:绋嬪簭璁℃暟鍣ㄣ€丣ava铏氭嫙鏈烘爤銆佹湰鍦版柟娉曟爤銆?/p>
1)绋嬪簭璁℃暟鍣?#xff08;Program聽Counter Register)
Java聽铏氭嫙鏈哄彲浠ユ敮鎸佸涓嚎绋嬪悓鏃舵墽琛?#xff0c;姣忎釜绾跨▼閮芥湁鑷繁鐨勭▼搴忚鏁板櫒銆傚湪浠讳綍鏃跺埢,姣忎釜绾跨▼閮藉彧浼氭墽琛屼竴涓柟娉曠殑浠g爜,杩欎釜鏂规硶绉颁负璇ョ嚎绋嬬殑褰撳墠鏂规硶(current聽method)銆?/p>
濡傛灉绾跨▼姝e湪鎵ц鐨勬槸聽Java 鏂规硶(涓嶆槸聽native聽鐨?#xff09;,鍒欑▼搴忚鏁板櫒璁板綍鐨勬槸姝e湪鎵ц鐨?Java 铏氭嫙鏈哄瓧鑺傜爜鎸囦护鐨勫湴鍧€銆傚鏋滄鍦ㄦ墽琛岀殑鏄湰鍦?#xff08;native)鏂规硶,閭d箞璁℃暟鍣ㄧ殑鍊兼槸绌虹殑(undefined)銆?/p>
2)Java铏氭嫙鏈烘爤(Java Virtual Machine Stacks)
姣忎釜 Java 铏氭嫙鏈虹嚎绋嬮兘鏈夎嚜宸辩鏈夌殑 Java 铏氭嫙鏈烘爤,瀹冧笌绾跨▼鍚屾椂鍒涘缓,鐢ㄤ簬瀛樺偍鏍堝抚銆?/p>
Java 铏氭嫙鏈烘爤鎻忚堪鐨勬槸 Java 鏂规硶鎵ц鐨勫唴瀛樻ā鍨?#xff1a;姣忎釜鏂规硶鍦ㄦ墽琛岀殑鍚屾椂閮戒細鍒涘缓涓€涓爤甯х敤浜庡瓨鍌ㄥ眬閮ㄥ彉閲忚〃銆佹搷浣滄暟鏍堛€佸姩鎬侀摼鎺ャ€佹柟娉曞嚭鍙g瓑淇℃伅銆?/p>
姣忎竴涓柟娉曚粠璋冪敤鐩磋嚦鎵ц瀹屾垚鐨勮繃绋?#xff0c;灏卞搴旂潃涓€涓爤甯у湪铏氭嫙鏈烘爤涓叆鏍堝埌鍑烘爤鐨勮繃绋嬨€?/p>
3)鏈湴鏂规硶鏍?#xff08;Native Method Stacks)
鏈湴鏂规硶鏍堜笌聽Java 铏氭嫙鏈烘爤鎵€鍙戞尌鐨勪綔鐢ㄦ槸闈炲父鐩镐技鐨?#xff0c;瀹冧滑涔嬮棿鐨勫尯鍒笉杩囨槸聽Java 铏氭嫙鏈烘爤涓鸿櫄鎷熸満鎵ц Java鏂规硶(涔熷氨鏄瓧鑺傜爜)鏈嶅姟,鑰屾湰鍦版柟娉曟爤鍒欎负铏氭嫙鏈轰娇鐢ㄥ埌鐨勬湰鍦?#xff08;Native)鏂规硶鏈嶅姟銆?/p>
4)鍫?#xff08;Heap)
鍫嗘槸琚悇涓嚎绋嬪叡浜殑杩愯鏃跺唴瀛樺尯鍩?#xff0c;涔熸槸渚涙墍鏈夌被瀹炰緥鍜屾暟缁勫璞″垎閰嶅唴瀛樼殑鍖哄煙銆?/p>
鍫嗗湪铏氭嫙鏈哄惎鍔ㄦ椂鍒涘缓,鍫嗗瓨鍌ㄧ殑瀵硅薄涓嶄細琚樉绀洪噴鏀?#xff0c;鑰屾槸鐢卞瀮鍦炬敹闆嗗櫒杩涜缁熶竴绠$悊鍜屽洖鏀躲€?/p>
5)鏂规硶鍖?#xff08;Method Area)
鏂规硶鍖烘槸琚悇涓嚎绋嬪叡浜殑杩愯鏃跺唴瀛樺尯鍩熴€傛柟娉曞尯绫讳技浜庝紶缁熻瑷€鐨勭紪璇戜唬鐮佺殑瀛樺偍鍖恒€傚畠瀛樺偍浜嗘瘡涓€涓被鐨勭粨鏋勪俊鎭?#xff0c;渚嬪:杩愯鏃跺父閲忔睜銆佸瓧娈靛拰鏂规硶鏁版嵁,鏋勯€犲嚱鏁板拰鏅€氭柟娉曠殑瀛楄妭鐮佸唴瀹?#xff0c;杩樺寘鎷竴浜涚敤浜庣被銆佸疄渚嬨€佹帴鍙e垵濮嬪寲鐢ㄥ埌鐨勭壒娈婃柟娉曘€?/p>
6)杩愯鏃跺父閲忔睜(Run-Time Constant Pool)
杩愯鏃跺父閲忔睜鏄燾lass聽鏂囦欢涓瘡涓€涓被鎴栨帴鍙g殑甯搁噺姹犺〃(constant_pool table)鐨勮繍琛屾椂琛ㄧず褰㈠紡銆?/p>
瀹冨寘鍚簡鑻ュ共绉嶅父閲?#xff0c;浠庣紪璇戞椂宸茬煡鐨勬暟鍊煎瓧闈㈤噺鍒板繀椤诲湪杩愯鏃惰В鏋愬悗鎵嶈兘鑾峰緱鐨勬柟娉曞拰瀛楁寮曠敤銆傝繍琛屾椂甯搁噺姹犵殑鍔熻兘绫讳技浜庝紶缁熺紪绋嬭瑷€鐨勭鍙疯〃(symbol聽table),涓嶈繃瀹冨寘鍚殑鏁版嵁鑼冨洿姣旈€氬父鎰忎箟涓婄殑绗﹀彿琛ㄨ鏇翠负骞挎硾銆?/p>
2銆丣ava聽涓湁鍝嚑绉嶅父閲忔睜?
鐜板湪鎴戜滑缁忓父鎻愬埌鐨勫父閲忔睜涓昏鏈変笁绉?#xff1a;class聽鏂囦欢甯搁噺姹犮€佽繍琛屾椂甯搁噺姹犮€佸瓧绗︿覆甯搁噺姹犮€?/p>
3銆乧lass聽鏂囦欢甯搁噺姹?/h2>
class聽鏂囦欢甯搁噺姹?#xff08;class constant pool)灞炰簬聽class聽鏂囦欢鐨勫叾涓竴椤?#xff0c;class聽绫绘枃浠跺寘鍚?#xff1a;榄旀暟銆佺被鐨勭増鏈€佸父閲忔睜銆佽闂爣蹇椼€佸瓧娈佃〃闆嗗悎銆佹柟鍙戣〃绛変俊鎭€?/p>
甯搁噺姹犵敤浜庡瓨鏀剧紪璇戞湡闂寸敓鎴愮殑鍚勭瀛楅潰閲?#xff08;Literal)鍜岀鍙峰紩鐢?#xff08;Symbolic References)銆?/p>
瀛楅潰閲忔瘮杈冩帴杩戜簬Java璇█灞傞潰鐨勫父閲忔蹇?#xff0c;濡傛枃鏈瓧绗︿覆銆佸0鏄庝负 final 鐨勫父閲忓€肩瓑銆?/p>
绗﹀彿寮曠敤鍒欏睘浜庣紪璇戝師鐞嗘柟闈㈢殑姒傚康銆傜鍙峰紩鐢ㄦ槸涓€缁勭鍙锋潵鎻忚堪鎵€寮曠敤鐨勭洰鏍?#xff0c;绗﹀彿鍙互鏄换浣曞舰寮忕殑瀛楅潰閲?#xff0c;鍙浣跨敤鏃惰兘鏃犳涔夊湴瀹氫綅鍒扮洰鏍囧嵆鍙?#xff08;瀹冧笌鐩存帴寮曠敤鍖哄垎,鐩存帴寮曠敤涓€鑸槸鎸囧悜鏂规硶鍖虹殑鏈湴鎸囬拡,鐩稿鍋忕Щ閲忔垨鏄竴涓兘闂存帴瀹氫綅鍒扮洰鏍囩殑鍙ユ焺)銆傜鍙峰紩鐢ㄤ富瑕佸寘鎷笅闈㈠嚑绫诲父閲?#xff1a;
- 琚ā鍧楀鍑烘垨寮€鏀剧殑鍖?#xff08;Package)
- 绫诲拰鎺ュ彛鐨勫叏闄愬畾鍚?#xff08;Fully Qualified Name)
- 瀛楁鐨勫悕绉板拰鎻忚堪绗?#xff08;Descriptor)
甯搁噺姹犱腑姣忎竴椤瑰父閲忛兘鏄竴涓〃,鎴嚦JDK 13,甯搁噺琛ㄤ腑鍒嗗埆鏈?7绉嶄笉鍚岀被鍨嬬殑甯搁噺銆?7绉嶅父閲忕被鍨嬫墍浠h〃鐨勫叿浣撳惈涔夊鍥炬墍绀恒€?/p>
鍏充簬聽class聽鏂囦欢甯搁噺姹犵殑鏇村鍐呭鍙互闃呰鍛ㄥ織鏄庣殑銆婃繁鍏ョ悊瑙ava铏氭嫙鏈恒€?.3.2 绔犺妭銆?/p>
4銆佽繍琛屾椂甯搁噺姹?/h2>
class聽鏂囦欢甯搁噺姹犳槸鍦ㄧ被琚紪璇戞垚聽class聽鏂囦欢鏃剁敓鎴愮殑銆傝€屽綋绫昏鍔犺浇鍒板唴瀛樹腑鍚?#xff0c;JVM 灏变細灏喡燾lass聽鏂囦欢甯搁噺姹犱腑鐨勫唴瀹瑰瓨鏀惧埌杩愯鏃跺父閲忔睜涓€?/p>
Java聽铏氭嫙鏈鸿鑼冧腑瀵硅繍琛屾椂甯搁噺姹犵殑瀹氫箟濡備笅:
A run-time constant pool is a per-class or per-interface run-time representation of the constant_pool table in a class file.
杩愯鏃跺父閲忔睜鏄燾lass聽鏂囦欢涓瘡涓€涓被鎴栨帴鍙g殑甯搁噺姹犺〃(constant_pool table)鐨勮繍琛屾椂琛ㄧず褰㈠紡銆?/p>
鍥犳,鏍规嵁瑙勮寖瀹氫箟,鍙互璇磋繍琛屾椂甯搁噺姹犳槸聽class聽鏂囦欢甯搁噺姹犵殑杩愯鏃惰〃绀?#xff0c;姣忎釜绫诲湪杩愯鏃堕兘鏈夎嚜宸辩殑涓€涓嫭绔嬬殑杩愯鏃跺父閲忔睜銆?/p>
5銆佸瓧绗︿覆甯搁噺姹?/h2>
绠€鍗曟潵璇?#xff0c;HotSpot VM 閲岀殑瀛楃涓插父閲忔睜(StringTable)鏄釜鍝堝笇琛?#xff0c;鍏ㄥ眬鍙湁涓€浠?#xff0c;琚墍鏈夌殑绫诲叡浜€?/p>
StringTable 鍏蜂綋瀛樺偍鐨勬槸聽String聽瀵硅薄鐨勫紩鐢?#xff0c;鑰屼笉鏄燬tring聽瀵硅薄瀹炰緥鑷韩銆係tring聽瀵硅薄瀹炰緥鍦?JDK 6 鍙婁箣鍓嶆槸鍦ㄦ案涔呬唬閲?#xff0c;浠嶫DK 7 寮€濮嬫斁鍦ㄥ爢閲屻€?/p>
鏍规嵁聽Java聽铏氭嫙鏈鸿鑼冪殑瀹氫箟,鍫嗘槸瀛樺偍聽Java聽瀵硅薄鐨勫湴鏂?#xff0c;鍏朵粬鍦版柟鏄笉浼氭湁聽Java聽瀵硅薄瀹炰綋鐨?#xff0c;濡傛灉鏈夌殑璇?#xff0c;鏍规嵁瑙勮寖瀹氫箟,杩欎簺鍦版柟涔熻绠楀爢鐨勪竴閮ㄥ垎銆?/p>
6銆佸瓧绗︿覆甯搁噺姹犳槸鍚﹀睘浜庢柟娉曞尯?
鎴戣涓烘槸涓嶅睘浜庣殑銆?/p>
鍦ㄨ鏈枃涔嬪墠,鎴戠浉淇″緢澶氬悓瀛︿細鏈夊涓嬭鐐?#xff1a;鍥犱负杩愯鏃跺父閲忔睜灞炰簬鏂规硶鍖?#xff0c;鎵€浠ュ緢澶氬悓瀛﹁涓哄瓧绗︿覆甯搁噺姹犱篃搴旇灞炰簬鏂规硶鍖恒€?/p>
浣嗘槸鐩镐俊鐪嬩簡涓婇潰鐨勫唴瀹瑰悗,浼氬紑濮嬫剰璇嗗埌,杩愯鏃跺父閲忔睜鍜屽瓧绗︿覆甯搁噺姹犲叾瀹炴槸涓嶅悓鐨勪袱涓笢瑗?#xff0c;褰撶劧瀹冧滑鍦ㄥ瓧绗︿覆瑙f瀽鏃朵細鏈夊叧鑱斻€?/p>
Java聽铏氭嫙鏈鸿鑼冧腑瀵规柟娉曞尯鐨勫畾涔夊涓?#xff1a;
The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in an operating system process. It stores per-class structures such as the run-time constant pool, field and method data, and the code for methods and constructors, including the special methods (搂2.9) used in class and instance initialization and interface initialization
鍦?Java 铏氭嫙鏈轰腑,鏂规硶鍖烘槸琚悇涓嚎绋嬪叡浜殑杩愯鏃跺唴瀛樺尯鍩熴€傛柟娉曞尯绫讳技浜庝紶缁熻瑷€鐨勭紪璇戜唬鐮佺殑瀛樺偍鍖?#xff0c;鎴栬€呯被浼间簬鎿嶄綔绯荤粺杩涚▼涓殑鏂囨湰娈点€傚畠瀛樺偍浜嗘瘡涓€涓被鐨勭粨鏋勪俊鎭?#xff0c;渚嬪:杩愯鏃跺父閲忔睜銆佸瓧娈靛拰鏂规硶鏁版嵁,鏋勯€犲嚱鏁板拰鏅€氭柟娉曠殑瀛楄妭鐮佸唴瀹?#xff0c;杩樺寘鎷竴浜涚敤浜庣被銆佸疄渚嬨€佹帴鍙e垵濮嬪寲鐢ㄥ埌鐨勭壒娈婃柟娉曘€?/p>
杩欒竟鐨勫叧閿湪浜?鈥滃畠瀛樺偍浜嗘瘡涓€涓被鐨勭粨鏋勪俊鎭€?#xff0c;鑰屽瓧绗︿覆甯搁噺姹犲苟涓嶅睘浜庢煇涓被,瀛楃涓插父閲忔槸鍏ㄥ眬鍏变韩鐨?#xff0c;鍥犳,鏍规嵁瑙勮寖瀹氫箟,鎴戜滑鍙互璇村瓧绗︿覆甯搁噺姹犱笉灞炰簬鏂规硶鍖恒€?/p>
閭e瓧绗︿覆甯搁噺姹?#xff08;StringTable)绌剁珶瀛樺湪鍝噷浜?#xff1f;聽
StringTable 鏈綋鏄瓨鍌ㄥ湪 native聽memory(鏈湴鍐呭瓨)閲?#xff0c;涓嶆槸鍦ㄦ案涔呬唬閲?#xff0c;涓嶆槸鍦ㄦ柟娉曞尯閲?#xff0c;褰撶劧,鏇翠笉鏄湪鍫嗛噷銆?/p>
7銆佽繍琛屾椂甯搁噺姹犲拰瀛楃涓插父閲忔睜鐨勫叧鑱?#xff1f;聽
涓婇潰璇翠簡,杩愯鏃跺父閲忔睜鍜屽瓧绗︿覆甯搁噺姹犲湪瀛楃涓茶В鏋愭椂浼氭湁鍏宠仈,鍏蜂綋濡備笅銆?/p>
绫荤殑杩愯鏃跺父閲忔睜涓湁聽CONSTANT_String_info(瑙侀3琛ㄦ牸)绫诲瀷鐨勫父閲?#xff0c;CONSTANT_String_info聽绫诲瀷鐨勫父閲忕殑瑙f瀽(resolve)杩囩▼濡備笅:
棣栧厛鍒板瓧绗︿覆甯搁噺姹?#xff08;StringTable)涓煡鎵炬槸鍚﹀凡缁忔湁浜嗚瀛楃涓茬殑寮曠敤,濡傛灉鏈?#xff0c;鍒欑洿鎺ヨ繑鍥炲瓧绗︿覆甯搁噺姹犵殑寮曠敤;濡傛灉娌℃湁,鍒欏湪鍫嗕腑鍒涘缓聽String聽瀵硅薄,骞跺湪瀛楃涓插父閲忔睜椹荤暀鍏跺紩鐢?#xff0c;鐒跺悗杩斿洖璇ュ紩鐢ㄣ€?/p>
涔熷氨璇?#xff0c;杩愯鏃跺父閲忔睜閲岀殑 CONSTANT_String_info 绫诲瀷鐨勫父閲?#xff0c;缁忚繃瑙f瀽(resolve)涔嬪悗,鍚屾牱瀛樼殑鏄瓧绗︿覆鐨勫紩鐢?#xff0c;骞朵笖鍜?StringTable聽椹荤暀鐨勫紩鐢ㄧ殑鏄竴鑷寸殑銆?/p>
8銆丼tring#intern聽鏂规硶
鍦?JDK 7聽鍙婁箣鍚庣殑鐗堟湰涓?#xff0c;璇ユ柟娉曠殑浣滅敤濡備笅:濡傛灉瀛楃涓插父閲忔睜涓凡缁忔湁杩欎釜瀛楃涓?#xff0c;鍒欑洿鎺ヨ繑鍥炲父閲忔睜涓殑寮曠敤;濡傛灉娌℃湁,鍒欏皢杩欎釜瀛楃涓茬殑寮曠敤淇濆瓨涓€浠藉埌瀛楃涓插父閲忔睜,鐒跺悗杩斿洖杩欎釜寮曠敤銆?/p>
涓嬮潰鐨勪緥瀛愬彲浠ヨ繘琛岀畝鍗曠殑楠岃瘉:
public static void main(String args[])
// 鍒涘缓2涓璞?#xff0c;str鎸佹湁鐨勬槸new鍒涘缓鐨勫璞″紩鐢? // 1)椹荤暀(intern)鍦ㄥ瓧绗︿覆甯搁噺姹犱腑鐨勫璞? // 2)new鍒涘缓鐨勫璞? String str = new String("joonwhee");
// 瀛楃涓插父閲忔睜涓凡缁忔湁浜?#xff0c;杩斿洖瀛楃涓插父閲忔睜涓殑寮曠敤
String str2 = "joonwhee";
// false,str涓簄ew鍒涘缓鐨勫璞″紩鐢?#xff0c;str2涓哄瓧绗﹀垱甯搁噺姹犱腑鐨勫紩鐢? System.out.println(str == str2);
// str淇敼涓哄瓧绗︿覆甯搁噺姹犵殑寮曠敤,鎵€浠ヤ笅闈负true
str = str.intern();
// true
System.out.println(str == str2);
9銆佹案涔呬唬(PermGen)
姘镐箙浠e湪聽Java 8聽琚Щ闄ゃ€傛牴鎹畼鏂规彁妗堢殑鎻忚堪,绉婚櫎鐨勪富瑕佸姩鏈烘槸:瑕佸皢 JRockit 鍜?Hotspot聽杩涜铻嶅悎,鑰?JRockit聽骞舵病鏈夋案涔呬唬銆?/p>
鑰屾嵁鎴戜滑鎵€浜嗚В鐨?#xff0c;杩樻湁鍙﹀涓€涓噸瑕佸師鍥犳槸姘镐箙浠f湰韬篃瀛樺湪杈冨鐨勯棶棰?#xff0c;缁忓父鍑虹幇OOM,杩樺嚭杩囦笉灏慴ug銆?/p>
鏍规嵁瀹樻柟鎻愭鐨勬弿杩?#xff0c;姘镐箙浠d富瑕佸瓨鍌ㄤ簡涓夌鏁版嵁:聽
1)Class metadata(绫诲厓鏁版嵁),涔熷氨鏄柟娉曞尯涓寘鍚殑鏁版嵁,闄や簡缂栬瘧鐢熸垚鐨勫瓧鑺傜爜琚斁鍦?native聽memory(鏈湴鍐呭瓨)銆?/p>
2)interned Strings,涔熷氨鏄瓧绗︿覆甯搁噺姹犱腑椹荤暀寮曠敤鐨勫瓧绗︿覆瀵硅薄,瀛楃涓插父閲忔睜鍙┗鐣欏紩鐢?#xff0c;鑰屽疄闄呭璞℃槸鍦ㄦ案涔呬唬涓€?/p>
3)class static variables,绫婚潤鎬佸彉閲忋€?/p>
绉婚櫎姘镐箙浠e悗,interned Strings聽鍜屄燾lass static variables聽琚Щ鍔ㄤ簡鍫嗕腑,Class metadata聽琚Щ鍔ㄥ埌浜嗗悗鏉ョ殑鍏冪┖闂淬€?/p>
10銆佹案涔呬唬鍜屾柟娉曞尯鐨勫叧绯?#xff1f;
鏂规硶鍖烘槸 Java聽铏氭嫙鏈鸿鑼冧腑瀹氫箟鐨勪竴绉嶉€昏緫姒傚康,鑰屾案涔呬唬鏄鏂规硶鍖虹殑瀹炵幇銆備絾鏄案涔呬唬骞朵笉绛夊悓浜庢柟娉曞尯,鏂规硶鍖轰篃涓嶇瓑鍚屼簬姘镐箙浠c€?/p>
姘镐箙浠d腑鐨劼爄nterned Strings聽骞朵笉灞炰簬鏂规硶鍖?#xff0c;鎸夎鑼?#xff1a;鍫嗘槸瀛樺偍聽Java聽瀵硅薄鐨勫湴鏂孤?#xff0c;杩欓儴鍒嗗簲璇ュ睘浜庡爢,鍥犳姘镐箙浠e苟涓嶆槸鍙敤浜庡疄鐜版柟娉曞尯銆?/p>
鏂规硶鍖轰腑 JIT 缂栬瘧鐢熸垚鐨勪唬鐮佸苟涓嶆槸瀛樻斁鍦ㄦ案涔呬唬,鑰屾槸鍦爊ative聽memory聽涓?#xff0c;鍥犳鍙互璇存柟娉曞尯涔熷苟涓嶅彧鏄敱姘镐箙浠f潵瀹炵幇銆?/p>
11銆佸厓绌洪棿(metaspace)
鍏冪┖闂村湪聽Java 8聽绉婚櫎姘镐箙浠e悗琚紩鍏?#xff0c;鐢ㄦ潵浠f浛姘镐箙浠?#xff0c;鏈川鍜屾案涔呬唬绫讳技,閮芥槸瀵规柟娉曞尯鐨勫疄鐜般€備笉杩囧厓绌洪棿涓庢案涔呬唬涔嬮棿鏈€澶х殑鍖哄埆鍦ㄤ簬:鍏冪┖闂村苟涓嶅湪铏氭嫙鏈轰腑,鑰屾槸浣跨敤鏈湴鍐呭瓨(native memory)銆?/p>
鍏冪┖闂翠富瑕佺敤浜庡瓨鍌燙lass metadata(绫诲厓鏁版嵁),鏍规嵁鍏跺懡鍚嶅叾瀹炰篃鐪嬪緱鍑烘潵銆?/p>
鍙互閫氳繃聽-XX:MaxMetaspaceSize聽鍙傛暟鏉ラ檺鍒跺厓绌洪棿鐨勫ぇ灏?#xff0c;濡傛灉娌℃湁璁剧疆璇ュ弬鏁?#xff0c;鍒欏厓绌洪棿榛樿闄愬埗涓烘満鍣ㄥ唴瀛樸€?/p>
12銆佷负浠€涔堝紩鍏ュ厓绌洪棿?
鍦?Java 8聽涔嬪墠,Java聽铏氭嫙鏈轰娇鐢ㄦ案涔呬唬鏉ュ瓨鏀剧被鍏冧俊鎭?#xff0c;閫氳繃-XX:PermSize銆?XX:MaxPermSize 鏉ユ帶鍒惰繖鍧楀唴瀛樼殑澶у皬,闅忕潃鍔ㄦ€佺被鍔犺浇鐨勬儏鍐佃秺鏉ヨ秺澶?#xff0c;杩欏潡鍐呭瓨鍙樺緱涓嶅お鍙帶,鍒板簳璁剧疆澶氬ぇ鍚堥€傛槸姣忎釜寮€鍙戣€呰鑰冭檻鐨勯棶棰樸€?/p>
濡傛灉璁剧疆灏忎簡,瀹规槗鍑虹幇鍐呭瓨婧㈠嚭;濡傛灉璁剧疆澶т簡,鍙堟湁鐐规氮璐?#xff0c;灏界涓嶄細瀹炶川鍒嗛厤杩欎箞澶х殑鐗╃悊鍐呭瓨銆?/p>
鑰屽厓绌洪棿鍙互杈冨ソ鐨勮В鍐冲唴瀛樿缃澶х殑闂:褰撴垜浠病鏈夋寚瀹?-XX:MaxMetaspaceSize聽鏃?#xff0c;鍏冪┖闂村彲浠ュ姩鎬佺殑璋冩暣浣跨敤鐨勫唴瀛樺ぇ灏?#xff0c;浠ュ绾充笉鏂鍔犵殑绫汇€?/p>
13銆佸厓绌洪棿鑳藉交搴曡В鍐冲唴瀛樻孩鍑?#xff08;Out Of Memory)闂鍚?#xff1f;
寰堥仐鎲?#xff0c;绛旀鏄笉琛岀殑銆?/p>
鍏冪┖闂存棤娉曞交搴曡В鍐冲唴瀛樻孩鍑虹殑闂,鍙兘璇存槸鏈夋墍缂撹В銆傚綋鍐呭瓨浣跨敤瀹屾瘯鍚?#xff0c;鍏冪┖闂翠竴鏍蜂細鍑虹幇鍐呭瓨婧㈠嚭鐨勬儏鍐?#xff0c;鏈€鍏稿瀷鐨勫満鏅氨鏄嚭鐜颁簡鍐呭瓨娉勬紡鏃躲€?/p>
鏈€鍚?/h1>
鎴戞槸鍥ц緣,涓€涓潥鎸佸垎浜師鍒涙妧鏈共璐х殑绋嬪簭鍛?/strong>,鎴戠殑鐩爣鏄府鍔╁ぇ瀹舵嬁鍒板績浠殑澶у巶 Offer銆?/p>
以上是关于闈㈣瘯蹇呴棶鐨?JVM 杩愯鏃舵暟鎹尯锛屼綘鎳備簡鍚楋紵的主要内容,如果未能解决你的问题,请参考以下文章
闈㈣瘯涓殑缃戠孩铏氭嫙DOM锛屼綘鐭ュ灏戝憿锛熸繁鍏ヨВ璇籨iff绠楁硶
闈㈣瘯瀹橀棶锛氬浣曞疄鐜伴珮瀹归噺澶у苟鍙戞暟鎹簱鏈嶅姟锛熸垜鏄繖鏍峰洖绛旂殑