闈㈣瘯蹇呴棶鐨?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绠楁硶

Oracle锛屼綘鎳傜殑

闈㈣瘯瀹橀棶锛氬浣曞疄鐜伴珮瀹归噺澶у苟鍙戞暟鎹簱鏈嶅姟锛熸垜鏄繖鏍峰洖绛旂殑

闈㈣瘯瀹橈細鏁版嵁搴撹繛鎺ユ睜涓轰粈涔堥兘瑕佺敤Threadlocal鍛紵

TypeScript闈㈣瘯棰樻€荤粨