{"id":857,"date":"2018-07-20T08:58:03","date_gmt":"2018-07-20T00:58:03","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=857"},"modified":"2018-07-20T08:58:03","modified_gmt":"2018-07-20T00:58:03","slug":"%e3%80%90jvm%e3%80%91jvm%e7%b3%bb%e5%88%97%e4%b9%8b%e5%9e%83%e5%9c%be%e5%9b%9e%e6%94%b6%ef%bc%88%e4%ba%8c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=857","title":{"rendered":"\u3010JVM\u3011JVM\u7cfb\u5217\u4e4b\u5783\u573e\u56de\u6536\uff08\u4e8c\uff09"},"content":{"rendered":"<p><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u5783\u573e\u56de\u6536<\/strong><\/p>\n<p>\u5982\u679c\u4e0d\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5185\u5b58\u8fdf\u65e9\u90fd\u4f1a\u88ab\u6d88\u8017\u7a7a\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u4e0d\u65ad\u7684\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u800c\u4e0d\u8fdb\u884c\u56de\u6536\u3002\u9664\u975e\u5185\u5b58\u65e0\u9650\u5927\uff0c\u6211\u4eec\u53ef\u4ee5\u4efb\u6027\u7684\u5206\u914d\u800c\u4e0d\u56de\u6536\uff0c\u4f46\u662f\u4e8b\u5b9e\u5e76\u975e\u5982\u6b64\u3002\u6240\u4ee5\uff0c\u5783\u573e\u56de\u6536\u662f\u5fc5\u987b\u7684\u3002<\/p>\n<p><strong>\u4e8c\u3001\u54ea\u4e9b\u5185\u5b58\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536<\/strong><\/p>\n<p>\u5bf9\u4e8e\u865a\u62df\u673a\u4e2d\u7ebf\u7a0b\u79c1\u6709\u7684\u533a\u57df\uff0c\u5982\u7a0b\u5e8f\u8ba1\u6570\u5668\u3001\u865a\u62df\u673a\u6808\u3001\u672c\u5730\u65b9\u6cd5\u6808\u90fd\u4e0d\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u81ea\u52a8\u8fdb\u884c\u7684\uff0c\u968f\u7740\u7ebf\u7a0b\u7684\u6d88\u4ea1\u800c\u6d88\u4ea1\uff0c\u4e0d\u9700\u8981\u6211\u4eec\u53bb\u56de\u6536\uff0c\u6bd4\u5982\u6808\u7684\u6808\u5e27\u7ed3\u6784\uff0c\u5f53\u8fdb\u5165\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u6808\u5e27\uff0c\u6808\u5e27\u5927\u5c0f\u4e5f\u53ef\u4ee5\u501f\u52a9\u7c7b\u4fe1\u606f\u786e\u5b9a\uff0c\u7136\u540e\u6808\u5e27\u5165\u6808\uff0c\u6267\u884c\u65b9\u6cd5\u4f53\uff0c\u9000\u51fa\u65b9\u6cd5\u65f6\uff0c\u6808\u5e27\u51fa\u6808\uff0c\u4e8e\u662f\u5176\u6240\u5360\u636e\u7684\u5185\u5b58\u7a7a\u95f4\u4e5f\u5c31\u88ab\u81ea\u52a8\u56de\u6536\u4e86\u3002\u800c\u5bf9\u4e8e\u865a\u62df\u673a\u4e2d\u7ebf\u7a0b\u5171\u4eab\u7684\u533a\u57df\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5982\u5806\u548c\u65b9\u6cd5\u533a\uff0c\u7ebf\u7a0b\u90fd\u4f1a\u5728\u8fd9\u4e24\u4e2a\u533a\u57df\u4ea7\u751f\u81ea\u8eab\u7684\u6570\u636e\uff0c\u5360\u636e\u4e00\u5b9a\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u5e76\u4e14\u8fd9\u4e9b\u6570\u636e\u53c8\u53ef\u80fd\u4f1a\u5b58\u5728\u76f8\u4e92\u5173\u8054\u7684\u5173\u7cfb\uff0c\u6240\u4ee5\uff0c\u8fd9\u90e8\u5206\u7684\u533a\u57df\u4e0d\u50cf\u7ebf\u7a0b\u79c1\u6709\u7684\u533a\u57df\u90a3\u6837\u53ef\u4ee5\u7b80\u5355\u81ea\u52a8\u7684\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u6b64\u90e8\u5206\u533a\u57df\u7684\u5783\u573e\u56de\u6536\u975e\u5e38\u590d\u6742\uff0c\u800c\u5783\u573e\u56de\u6536\u4e5f\u4e3b\u8981\u662f\u9488\u5bf9\u8fd9\u90e8\u5206\u533a\u57df\u3002<\/p>\n<p><strong>\u4e09\u3001\u5783\u573e\u6536\u96c6\u7b97\u6cd5<\/strong><\/p>\n<p>\u4efb\u4f55\u5783\u573e\u6536\u96c6\u7b97\u6cd5\u90fd\u5fc5\u987b\u505a\u4e24\u4ef6\u4e8b\u60c5\u3002\u9996\u5148\uff0c\u5b83\u5fc5\u987b\u68c0\u6d4b\u51fa\u5783\u573e\u5bf9\u8c61\u3002\u5176\u6b21\uff0c\u5b83\u5fc5\u987b\u56de\u6536\u5783\u573e\u5bf9\u8c61\u6240\u4f7f\u7528\u7684\u5806\u7a7a\u95f4\u5e76\u8fd8\u7ed9\u7a0b\u5e8f\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5982\u4f55\u68c0\u6d4b\u51fa\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u5783\u573e\u5bf9\u8c61\u5462\uff1f\u4e00\u822c\u6709\u4e24\u79cd\u7b97\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u30021. \u5f15\u7528\u8ba1\u6570\u7b97\u6cd5 2. \u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5\u3002<\/p>\n<p>1.\u5f15\u7528\u8ba1\u6570\u7b97\u6cd5<\/p>\n<p>\u5806\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u6709\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u88ab\u521b\u5efa\uff0c\u5e76\u628a\u6307\u5411\u8be5\u5bf9\u8c61\u7684\u5f15\u7528\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u65f6\uff0c\u5f15\u7528\u8ba1\u6570\u7f6e\u4e3a1\uff0c\u5f53\u518d\u628a\u8fd9\u4e2a\u5f15\u7528\u8d4b\u503c\u7ed9\u5176\u4ed6\u53d8\u91cf\u65f6\uff0c\u5f15\u7528\u8ba1\u6570\u52a01\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u8d85\u8fc7\u4e86\u751f\u547d\u5468\u671f\u6216\u8005\u88ab\u8bbe\u7f6e\u4e3a\u65b0\u503c\u65f6\uff0c\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u51cf1\uff0c\u4efb\u4f55\u5f15\u7528\u8ba1\u6570\u4e3a0\u7684\u5bf9\u8c61\u90fd\u53ef\u4ee5\u88ab\u5f53\u6210\u5783\u573e\u56de\u6536\u3002\u5f53\u4e00\u4e2a\u5bf9\u8c61\u88ab\u56de\u6536\u65f6\uff0c\u5b83\u6240\u5f15\u7528\u7684\u4efb\u4f55\u5bf9\u8c61\u8ba1\u6570\u51cf1\uff0c\u8fd9\u6837\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5176\u4ed6\u5bf9\u8c61\u4e5f\u88ab\u5f53\u5783\u573e\u56de\u6536\u3002<\/p>\n<p>\u95ee\u9898\uff1a\u5f88\u96be\u68c0\u6d4b\u51fa\u5bf9\u8c61\u4e4b\u95f4\u7684\u989d\u76f8\u4e92\u5f15\u7528\uff08\u5f15\u7528\u5faa\u73af\u95ee\u9898\uff09<\/p>\n<p>\u5982\u4e0b\u4ee3\u7801\u6bb5\u53ef\u4ee5\u4ece\u53cd\u9762\u9a8c\u8bc1\u865a\u62df\u673a\u7684\u5783\u573e\u56de\u6536\u4e0d\u662f\u91c7\u7528\u7684\u5f15\u7528\u8ba1\u6570\u3002<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_8a930d4d-5f96-4c49-99dd-8953db71b022\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_8a930d4d-5f96-4c49-99dd-8953db71b022\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>package com.leesf.chapter3;\n\npublic class ReferenceCountingGC {\n    public Object instance = null;\n    private static final int _1MB = 1024 * 1024;\n    \/**\n     * \u8fd9\u4e2a\u6210\u5458\u5c5e\u6027\u7684\u552f\u4e00\u610f\u4e49\u5c31\u662f\u5360\u70b9\u5185\u5b58,\u4ee5\u4fbf\u80fd\u5728GC\u65e5\u5fd7\u4e2d\u770b\u6e05\u695a\u662f\u5426\u88ab\u56de\u6536\u8fc7\n     *\/\n    private byte[] bigSize = new byte[2 * _1MB];\n\n    public static void testGC() {\n        \/\/ \u5b9a\u4e49\u4e24\u4e2a\u5bf9\u8c61\n        ReferenceCountingGC objA = new ReferenceCountingGC();\n        ReferenceCountingGC objB = new ReferenceCountingGC();\n\n        \/\/ \u7ed9\u5bf9\u8c61\u7684\u6210\u5458\u8d4b\u503c\uff0c\u5373\u5b58\u5728\u76f8\u4e92\u5f15\u7528\u60c5\u51b5\n        objA.instance = objB;\n        objB.instance = objA;\n\n        \/\/ \u5c06\u5f15\u7528\u8bbe\u4e3a\u7a7a\uff0c\u5373\u6ca1\u6709\u5230\u5806\u5bf9\u8c61\u7684\u5f15\u7528\u4e86\n        objA = null;\n        objB = null;\n\n        \/\/ \u8fdb\u884c\u5783\u573e\u56de\u6536\n        System.gc();\n    }\n\n    public static void main(String[] args) {\n        testGC();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u4ee3\u7801\u7684\u8fd0\u884c\u53c2\u6570\u8bbe\u7f6e\u4e3a\uff1a -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226111115693-1490327308.png\" alt=\"\" \/><\/p>\n<p>\u5728\u4ee3\u7801objA = null \u548c objB = null \u4e4b\u524d\uff0c\u5185\u5b58\u7ed3\u6784\u793a\u610f\u56fe\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226141732208-651423017.png\" alt=\"\" \/><\/p>\n<p>\u6ce8\u610f\uff1a\u5c40\u90e8\u53d8\u91cf\u533a\u7684\u7b2c\u4e00\u9879\u5e76\u6ca1\u6709this\u5f15\u7528\uff0c\u56e0\u4e3atestGC\u65b9\u6cd5\u662f\u7c7b\u65b9\u6cd5\u3002<\/p>\n<p>\u5728\u4ee3\u7801objA = null \u548c objB = null \u4e4b\u540e\uff0c\u5185\u5b58\u7ed3\u6784\u793a\u610f\u56fe\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226141900193-1069001067.png\" alt=\"\" \/><\/p>\n<p>objA\u548cobjB\u5230\u5806\u5bf9\u8c61\u7684\u5f15\u7528\u5df2\u7ecf\u6ca1\u6709\u4e86\uff0c\u4f46\u662fReferenceCountingGC\u5bf9\u8c61\u5185\u90e8\u8fd8\u5b58\u5728\u7740\u5faa\u73af\u5f15\u7528\uff0c\u6211\u4eec\u5728\u56fe\u4e2d\u4e5f\u53ef\u4ee5\u770b\u5230\u3002\u5373\u4fbf\u5982\u6b64\uff0cJVM\u8fd8\u662f\u628a\u8fd9\u4e24\u4e2a\u5bf9\u8c61\u5f53\u6210\u5783\u573e\u8fdb\u884c\u4e86\u56de\u6536\u3002\u5177\u4f53\u7684GC\u65e5\u5fd7\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226112435365-347275628.png\" alt=\"\" \/><\/p>\n<p>\u7531GC\u65e5\u5fd7\u53ef\u77e5\u53d1\u751f\u4e86\u4e24\u6b21GC\uff0c\u753111390K -&gt; 514K\uff0c\u5373\u5bf9\u4e24\u4e2a\u5bf9\u8c61\u90fd\u8fdb\u884c\u4e86\u56de\u6536\uff0c\u4e5f\u4ece\u4fa7\u9762\u8bf4\u660eJVM\u7684\u5783\u573e\u6536\u96c6\u5668\u4e0d\u662f\u91c7\u7528\u7684\u5f15\u7528\u8ba1\u6570\u7684\u7b97\u6cd5\u6765\u8fdb\u884c\u5783\u573e\u56de\u6536\u7684\u3002<\/p>\n<p>2.\u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5<\/p>\n<p>\u6b64\u7b97\u6cd5\u7684\u57fa\u672c\u601d\u60f3\u5c31\u662f\u9009\u53d6\u4e00\u7cfb\u5217GCRoots\u5bf9\u8c61\u4f5c\u4e3a\u8d77\u70b9\uff0c\u5f00\u59cb\u5411\u4e0b\u904d\u5386\u641c\u7d22\u5176\u4ed6\u76f8\u5173\u7684\u5bf9\u8c61\uff0c\u641c\u7d22\u6240\u8d70\u8fc7\u7684\u8def\u5f84\u6210\u4e3a\u5f15\u7528\u94fe\uff0c\u904d\u5386\u5b8c\u6210\u540e\uff0c\u5982\u679c\u4e00\u4e2a\u5bf9\u8c61\u5230GCRoots\u5bf9\u8c61\u6ca1\u6709\u4efb\u4f55\u5f15\u7528\u94fe\uff0c\u5219\u8bc1\u660e\u6b64\u5bf9\u8c61\u662f\u4e0d\u53ef\u7528\u7684\uff0c\u53ef\u4ee5\u88ab\u5f53\u505a\u5783\u573e\u8fdb\u884c\u56de\u6536\u3002<\/p>\n<p>\u90a3\u4e48\u95ee\u9898\u53c8\u6765\u4e86\uff0c\u5982\u4f55\u9009\u53d6GCRoots\u5bf9\u8c61\u5462\uff1f\u5728Java\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f5c\u4e3aGCRoots\u7684\u5bf9\u8c61\u5305\u62ec\u4e0b\u9762\u51e0\u79cd\uff1a<\/p>\n<p>1. \u865a\u62df\u673a\u6808\uff08\u6808\u5e27\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u533a\uff0c\u4e5f\u53eb\u505a\u5c40\u90e8\u53d8\u91cf\u8868\uff09\u4e2d\u5f15\u7528\u7684\u5bf9\u8c61\u3002<\/p>\n<p>2. \u65b9\u6cd5\u533a\u4e2d\u7684\u7c7b\u9759\u6001\u5c5e\u6027\u5f15\u7528\u7684\u5bf9\u8c61\u3002<\/p>\n<p>3. \u65b9\u6cd5\u533a\u4e2d\u5e38\u91cf\u5f15\u7528\u7684\u5bf9\u8c61\u3002<\/p>\n<p>4. \u672c\u5730\u65b9\u6cd5\u6808\u4e2dJNI(Native\u65b9\u6cd5)\u5f15\u7528\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u4e0b\u9762\u7ed9\u51fa\u4e00\u4e2aGCRoots\u7684\u4f8b\u5b50\uff0c\u5982\u4e0b\u56fe\uff0c\u4e3aGCRoots\u7684\u5f15\u7528\u94fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226114056646-1844591019.png\" alt=\"\" \/><\/p>\n<p>\u7531\u56fe\u53ef\u77e5\uff0cobj8\u3001obj9\u3001obj10\u90fd\u6ca1\u6709\u5230GCRoots\u5bf9\u8c61\u7684\u5f15\u7528\u94fe\uff0c\u5373\u4fbfobj9\u548cobj10\u4e4b\u95f4\u6709\u5f15\u7528\u94fe\uff0c\u4ed6\u4eec\u8fd8\u662f\u4f1a\u88ab\u5f53\u6210\u5783\u573e\u5904\u7406\uff0c\u53ef\u4ee5\u8fdb\u884c\u56de\u6536\u3002<\/p>\n<p><strong>\u56db\u3001\u5bf9\u8c61\u7684\u5185\u5b58\u5e03\u5c40<\/strong><\/p>\n<p><strong>\u3000\u3000<\/strong>Java\u4e2d\u6211\u4eec\u63d0\u5230\u6700\u591a\u7684\u5e94\u8be5\u5c31\u662f\u5bf9\u8c61\uff0c\u4f46\u662f\u6211\u4eec\u771f\u7684\u4e86\u89e3\u5bf9\u8c61\u5417\uff0c\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u5e03\u5c40\u5982\u4f55\uff1f\u5bf9\u8c61\u7684\u5185\u5b58\u5e03\u5c40\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226144827990-1417305720.png\" alt=\"\" \/><\/p>\n<p>\u51e0\u70b9\u8bf4\u660e\uff1a1.Mark Word\u90e8\u5206\u6570\u636e\u7684\u957f\u5ea6\u572832\u4f4d\u548c64\u4f4d\u865a\u62df\u673a\uff08\u672a\u5f00\u542f\u538b\u7f29\u6307\u9488\uff09\u4e2d\u5206\u522b\u4e3a32bit\u548c64bit\u3002\u7136\u540e\u5bf9\u8c61\u9700\u8981\u5b58\u50a8\u7684\u8fd0\u884c\u65f6\u6570\u636e\u5176\u5b9e\u5df2\u7ecf\u8d85\u8fc7\u4e8632\u4f4d\u300164\u4f4dBitmap\u7ed3\u6784\u6240\u80fd\u8bb0\u5f55\u7684\u9650\u5ea6\uff0c\u4f46\u662f\u5bf9\u8c61\u5934\u4fe1\u606f\u662f\u4e0e\u5bf9\u8c61\u81ea\u8eab\u5b9a\u4e49\u7684\u6570\u636e\u65e0\u5173\u7684\u5916\u5b58\u50a8\u6210\u672c\uff0cMark Word\u4e00\u822c\u88ab\u8bbe\u8ba1\u4e3a\u975e\u56fa\u5b9a\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4ee5\u4fbf\u5b58\u50a8\u66f4\u591a\u7684\u6570\u636e\u4fe1\u606f\u548c\u590d\u7528\u81ea\u5df1\u7684\u5b58\u50a8\u7a7a\u95f4\u30022.\u7c7b\u578b\u6307\u9488\uff0c\u5373\u6307\u5411\u5b83\u7684\u7c7b\u5143\u6570\u636e\u7684\u6307\u9488\uff0c\u7528\u4e8e\u5224\u65ad\u5bf9\u8c61\u5c5e\u4e8e\u54ea\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u30023.\u5b9e\u4f8b\u6570\u636e\u5b58\u50a8\u7684\u662f\u771f\u6b63\u6709\u6548\u6570\u636e\uff0c\u5982\u5404\u79cd\u5b57\u6bb5\u5185\u5bb9\uff0c\u5404\u5b57\u6bb5\u7684\u5206\u914d\u7b56\u7565\u4e3alongs\/doubles\u3001ints\u3001shorts\/chars\u3001bytes\/boolean\u3001oops(ordinary object pointers)\uff0c\u76f8\u540c\u5bbd\u5ea6\u7684\u5b57\u6bb5\u603b\u662f\u88ab\u5206\u914d\u5230\u4e00\u8d77\uff0c\u4fbf\u4e8e\u4e4b\u540e\u53d6\u6570\u636e\u3002\u7236\u7c7b\u5b9a\u4e49\u7684\u53d8\u91cf\u4f1a\u51fa\u73b0\u5728\u5b50\u7c7b\u524d\u9762\u30023.\u5bf9\u9f50\u586b\u5145\u90e8\u5206\u4ec5\u4ec5\u8d77\u5230\u5360\u4f4d\u7b26\u7684\u4f5c\u7528\uff0c\u5e76\u975e\u5fc5\u987b\u3002<\/p>\n<p>\u8bf4\u5b8c\u5bf9\u8c61\u7684\u5185\u5b58\u5e03\u5c40\uff0c\u73b0\u5728\u6765\u8bf4\u8bf4\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u5f53\u6211\u4eec\u5728\u5806\u4e0a\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\u540e\uff0c\u5982\u4f55\u5bf9\u8be5\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u5462\uff1f\u597d\u6bd4\u4e00\u4e2a\u7535\u89c6\u673a\uff0c\u6211\u5982\u4f55\u64cd\u4f5c\u7535\u89c6\u673a\u6765\u6536\u770b\u4e0d\u540c\u7684\u7535\u89c6\u8282\u76ee\uff0c\u663e\u7136\u6211\u4eec\u9700\u8981\u4f7f\u7528\u5230\u9065\u63a7\uff0c\u800c\u865a\u62df\u673a\u4e2d\u5c31\u662f\u4f7f\u7528\u5230\u5f15\u7528\uff0c\u5373\u865a\u62df\u673a\u6808\u4e2d\u7684reference\u7c7b\u578b\u6570\u636e\u6765\u64cd\u4f5c\u5806\u4e0a\u7684\u5bf9\u8c61\u3002\u73b0\u5728\u4e3b\u6d41\u7684\u8bbf\u95ee\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a<\/p>\n<p>1. \u4f7f\u7528\u53e5\u67c4\u8bbf\u95ee\u5bf9\u8c61\u3002\u5373reference\u4e2d\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u53e5\u67c4\u7684\u5730\u5740\uff0c\u800c\u53e5\u67c4\u4e2d\u5305\u542b\u4e86\u5bf9\u8c61\u793a\u4f8b\u6570\u636e\u4e0e\u7c7b\u578b\u6570\u636e\u7684\u5177\u4f53\u5730\u5740\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8e\u4e8c\u7ea7\u6307\u9488\u3002<\/p>\n<p>2. \u76f4\u63a5\u6307\u9488\u8bbf\u95ee\u5bf9\u8c61\u3002\u5373reference\u4e2d\u5b58\u50a8\u7684\u5c31\u662f\u5bf9\u8c61\u5730\u5740\uff0c\u76f8\u5f53\u4e8e\u4e00\u7ea7\u6307\u9488\u3002<\/p>\n<p>\u4e24\u79cd\u65b9\u5f0f\u6709\u5404\u81ea\u7684\u4f18\u7f3a\u70b9\u3002\u5f53\u5783\u573e\u56de\u6536\u79fb\u52a8\u5bf9\u8c61\u65f6\uff0c\u5bf9\u4e8e\u65b9\u5f0f\u4e00\u800c\u8a00\uff0creference\u4e2d\u5b58\u50a8\u7684\u5730\u5740\u662f\u7a33\u5b9a\u7684\u5730\u5740\uff0c\u4e0d\u9700\u8981\u4fee\u6539\uff0c\u4ec5\u9700\u8981\u4fee\u6539\u5bf9\u8c61\u53e5\u67c4\u7684\u5730\u5740\uff1b\u800c\u5bf9\u4e8e\u65b9\u5f0f\u4e8c\uff0c\u5219\u9700\u8981\u4fee\u6539reference\u4e2d\u5b58\u50a8\u7684\u5730\u5740\u3002\u4ece\u8bbf\u95ee\u6548\u7387\u4e0a\u770b\uff0c\u65b9\u5f0f\u4e8c\u4f18\u4e8e\u65b9\u5f0f\u4e00\uff0c\u56e0\u4e3a\u65b9\u5f0f\u4e8c\u53ea\u8fdb\u884c\u4e86\u4e00\u6b21\u6307\u9488\u5b9a\u4f4d\uff0c\u8282\u7701\u4e86\u65f6\u95f4\u5f00\u9500\uff0c\u800c\u8fd9\u4e5f\u662fHotSpot\u91c7\u7528\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002\u4e0b\u56fe\u662f\u53e5\u67c4\u8bbf\u95ee\u4e0e\u6307\u9488\u8bbf\u95ee\u7684\u793a\u610f\u56fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226155344349-887482013.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201605\/616953-20160518141733169-1486000631.png\" alt=\"\" \/><\/p>\n<p><strong>\u4e94\u3001\u5bf9\u8c61\u7684\u5f15\u7528<\/strong><\/p>\n<p><strong>\u3000\u3000<\/strong>\u524d\u9762\u6240\u8c08\u5230\u7684\u68c0\u6d4b\u5783\u573e\u5bf9\u8c61\u7684\u4e24\u79cd\u7b97\u6cd5\u90fd\u662f\u57fa\u4e8e\u5bf9\u8c61\u5f15\u7528\u3002\u5728Java\u8bed\u8a00\u4e2d\uff0c\u5c06\u5f15\u7528\u5206\u4e3a\u5f3a\u5f15\u7528\u3001\u8f6f\u5f15\u7528\u3001\u5f31\u5f15\u7528\u3001\u865a\u5f15\u7528\u56db\u79cd\u7c7b\u578b\u3002\u5f15\u7528\u5f3a\u5ea6\u4f9d\u6b21\u51cf\u5f31\u3002\u5177\u4f53\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226160743208-1648960890.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u5bf9\u4e8e\u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5\u800c\u8a00\uff0c\u672a\u5230\u8fbe\u7684\u5bf9\u8c61\u5e76\u975e\u662f\u201c\u975e\u6b7b\u4e0d\u53ef\u201d\u7684\uff0c\u82e5\u8981\u5ba3\u5224\u4e00\u4e2a\u5bf9\u8c61\u6b7b\u4ea1\uff0c\u81f3\u5c11\u9700\u8981\u7ecf\u5386\u4e24\u6b21\u6807\u8bb0\u9636\u6bb5\u30021. \u5982\u679c\u5bf9\u8c61\u5728\u8fdb\u884c\u53ef\u8fbe\u6027\u5206\u6790\u540e\u53d1\u73b0\u6ca1\u6709\u4e0eGCRoots\u76f8\u8fde\u7684\u5f15\u7528\u94fe\uff0c\u5219\u8be5\u5bf9\u8c61\u88ab\u7b2c\u4e00\u6b21\u6807\u8bb0\u5e76\u8fdb\u884c\u4e00\u6b21\u7b5b\u9009\uff0c\u7b5b\u9009\u6761\u4ef6\u4e3a\u662f\u5426\u6709\u5fc5\u8981\u6267\u884c\u8be5\u5bf9\u8c61\u7684finalize\u65b9\u6cd5\uff0c\u82e5\u5bf9\u8c61\u6ca1\u6709\u8986\u76d6finalize\u65b9\u6cd5\u6216\u8005\u8be5finalize\u65b9\u6cd5\u662f\u5426\u5df2\u7ecf\u88ab\u865a\u62df\u673a\u6267\u884c\u8fc7\u4e86\uff0c\u5219\u5747\u89c6\u4f5c\u4e0d\u5fc5\u8981\u6267\u884c\u8be5\u5bf9\u8c61\u7684finalize\u65b9\u6cd5\uff0c\u5373\u8be5\u5bf9\u8c61\u5c06\u4f1a\u88ab\u56de\u6536\u3002\u53cd\u4e4b\uff0c\u82e5\u5bf9\u8c61\u8986\u76d6\u4e86finalize\u65b9\u6cd5\u5e76\u4e14\u8be5finalize\u65b9\u6cd5\u5e76\u6ca1\u6709\u88ab\u6267\u884c\u8fc7\uff0c\u90a3\u4e48\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u4f1a\u88ab\u653e\u7f6e\u5728\u4e00\u4e2a\u53ebF-Queue\u7684\u961f\u5217\u4e2d\uff0c\u4e4b\u540e\u4f1a\u7531\u865a\u62df\u673a\u81ea\u52a8\u5efa\u7acb\u7684\u3001\u4f18\u5148\u7ea7\u4f4e\u7684Finalizer\u7ebf\u7a0b\u53bb\u6267\u884c\uff0c\u800c\u865a\u62df\u673a\u4e0d\u5fc5\u8981\u7b49\u5f85\u8be5\u7ebf\u7a0b\u6267\u884c\u7ed3\u675f\uff0c\u5373\u865a\u62df\u673a\u53ea\u8d1f\u8d23\u5efa\u7acb\u7ebf\u7a0b\uff0c\u5176\u4ed6\u7684\u4e8b\u60c5\u4ea4\u7ed9\u6b64\u7ebf\u7a0b\u53bb\u5904\u7406\u30022.\u5bf9F-Queue\u4e2d\u5bf9\u8c61\u8fdb\u884c\u7b2c\u4e8c\u6b21\u6807\u8bb0\uff0c\u5982\u679c\u5bf9\u8c61\u5728finalize\u65b9\u6cd5\u4e2d\u62ef\u6551\u4e86\u81ea\u5df1\uff0c\u5373\u5173\u8054\u4e0a\u4e86GCRoots\u5f15\u7528\u94fe\uff0c\u5982\u628athis\u5173\u952e\u5b57\u8d4b\u503c\u7ed9\u5176\u4ed6\u53d8\u91cf\uff0c\u90a3\u4e48\u5728\u7b2c\u4e8c\u6b21\u6807\u8bb0\u7684\u65f6\u5019\u8be5\u5bf9\u8c61\u5c06\u4ece\u201c\u5373\u5c06\u56de\u6536\u201d\u7684\u96c6\u5408\u4e2d\u79fb\u9664\uff0c\u5982\u679c\u5bf9\u8c61\u8fd8\u662f\u6ca1\u6709\u62ef\u6551\u81ea\u5df1\uff0c\u90a3\u5c31\u4f1a\u88ab\u56de\u6536\u3002\u5982\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u4e00\u4e2a\u5bf9\u8c61\u5982\u4f55\u5728finalize\u65b9\u6cd5\u4e2d\u62ef\u6551\u4e86\u81ea\u5df1\uff0c\u7136\u800c\uff0c\u5b83\u53ea\u80fd\u62ef\u6551\u81ea\u5df1\u4e00\u6b21\uff0c\u7b2c\u4e8c\u6b21\u5c31\u88ab\u56de\u6536\u4e86\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_25f738fe-d9c6-495e-8dea-dea34a6034d6\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_25f738fe-d9c6-495e-8dea-dea34a6034d6\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>\/*\n * \u6b64\u4ee3\u7801\u6f14\u793a\u4e86\u4e24\u70b9\uff1a\n * 1.\u5bf9\u8c61\u53ef\u4ee5\u518d\u88abGC\u65f6\u81ea\u6211\u62ef\u6551\n * 2.\u8fd9\u79cd\u81ea\u6551\u7684\u673a\u4f1a\u53ea\u6709\u4e00\u6b21\uff0c\u56e0\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u7684finalize()\u65b9\u6cd5\u6700\u591a\u53ea\u4f1a\u88ab\u7cfb\u7edf\u81ea\u52a8\u8c03\u7528\u4e00\u6b21\n * *\/\n\npublic class FinalizeEscapeGC {\n    public String name;\n    public static FinalizeEscapeGC SAVE_HOOK = null;\n\n    public FinalizeEscapeGC(String name) {\n        this.name = name;\n    }\n\n    public void isAlive() {\n        System.out.println(\"yes, i am still alive :)\");\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        super.finalize();\n        System.out.println(\"finalize method executed!\");\n        System.out.println(this);\n        FinalizeEscapeGC.SAVE_HOOK = this;\n    }\n\n    @Override\n    public String toString() {\n        return name;\n    }\n\n    public static void main(String[] args) throws InterruptedException {\n        SAVE_HOOK = new FinalizeEscapeGC(\"leesf\");\n        System.out.println(SAVE_HOOK);\n        \/\/ \u5bf9\u8c61\u7b2c\u4e00\u6b21\u62ef\u6551\u81ea\u5df1\n        SAVE_HOOK = null;\n        System.out.println(SAVE_HOOK);\n        System.gc();\n        \/\/ \u56e0\u4e3afinalize\u65b9\u6cd5\u4f18\u5148\u7ea7\u5f88\u4f4e\uff0c\u6240\u4ee5\u6682\u505c0.5\u79d2\u4ee5\u7b49\u5f85\u5b83\n        Thread.sleep(500);\n        if (SAVE_HOOK != null) {\n            SAVE_HOOK.isAlive();\n        } else {\n            System.out.println(\"no, i am dead : (\");\n        }\n\n        \/\/ \u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u4e0e\u4e0a\u9762\u7684\u5b8c\u5168\u76f8\u540c,\u4f46\u662f\u8fd9\u4e00\u6b21\u81ea\u6551\u5374\u5931\u8d25\u4e86\n        \/\/ \u4e00\u4e2a\u5bf9\u8c61\u7684finalize\u65b9\u6cd5\u53ea\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\n        SAVE_HOOK = null;\n        System.gc();\n        \/\/ \u56e0\u4e3afinalize\u65b9\u6cd5\u4f18\u5148\u7ea7\u5f88\u4f4e\uff0c\u6240\u4ee5\u6682\u505c0.5\u79d2\u4ee5\u7b49\u5f85\u5b83\n        Thread.sleep(500);\n        if (SAVE_HOOK != null) {\n            SAVE_HOOK.isAlive();\n        } else {\n            System.out.println(\"no, i am dead : (\");\n        }\n    }\n\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p>leesf<br \/>\nnull<br \/>\nfinalize method executed!<br \/>\nleesf<br \/>\nyes, i am still alive \ud83d\ude42<br \/>\nno, i am dead : (<\/p>\n<p>\u7531\u7ed3\u679c\u53ef\u77e5\uff0c\u8be5\u5bf9\u8c61\u62ef\u6551\u4e86\u81ea\u5df1\u4e00\u6b21\uff0c\u7b2c\u4e8c\u6b21\u6ca1\u6709\u62ef\u6551\u6210\u529f\uff0c\u56e0\u4e3a\u5bf9\u8c61\u7684finalize\u65b9\u6cd5\u6700\u591a\u88ab\u865a\u62df\u673a\u8c03\u7528\u4e00\u6b21\u3002\u6b64\u5916\uff0c\u4ece\u7ed3\u679c\u6211\u4eec\u53ef\u4ee5\u5f97\u77e5\uff0c\u4e00\u4e2a\u5806\u5bf9\u8c61\u7684this\uff08\u653e\u5728\u5c40\u90e8\u53d8\u91cf\u8868\u4e2d\u7684\u7b2c\u4e00\u9879\uff09\u5f15\u7528\u4f1a\u6c38\u8fdc\u5b58\u5728\uff0c\u5728\u65b9\u6cd5\u4f53\u5185\u53ef\u4ee5\u5c06this\u5f15\u7528\u8d4b\u503c\u7ed9\u5176\u4ed6\u53d8\u91cf\uff0c\u8fd9\u6837\u5806\u4e2d\u5bf9\u8c61\u5c31\u53ef\u4ee5\u88ab\u5176\u4ed6\u53d8\u91cf\u6240\u5f15\u7528\uff0c\u5373\u4e0d\u4f1a\u88ab\u56de\u6536\u3002<\/p>\n<p><strong>\u516d\u3001\u65b9\u6cd5\u533a\u7684\u5783\u573e\u56de\u6536<\/strong><\/p>\n<p><strong>\u3000\u3000<\/strong>\u65b9\u6cd5\u533a\u7684\u5783\u573e\u56de\u6536\u4e3b\u8981\u56de\u6536\u4e24\u90e8\u5206\u5185\u5bb9\uff1a1. \u5e9f\u5f03\u5e38\u91cf\u30022. \u65e0\u7528\u7684\u7c7b\u3002\u65e2\u7136\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5c31\u9700\u8981\u5224\u65ad\u54ea\u4e9b\u662f\u5e9f\u5f03\u5e38\u91cf\uff0c\u54ea\u4e9b\u662f\u65e0\u7528\u7684\u7c7b\u3002<\/p>\n<p>\u5982\u4f55\u5224\u65ad\u5e9f\u5f03\u5e38\u91cf\u5462\uff1f\u4ee5\u5b57\u9762\u91cf\u56de\u6536\u4e3a\u4f8b\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u201cabc\u201d\u5df2\u7ecf\u8fdb\u5165\u5e38\u91cf\u6c60\uff0c\u4f46\u662f\u5f53\u524d\u7cfb\u7edf\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2aString\u5bf9\u8c61\u5f15\u7528\u4e86\u53eb\u505a\u201cabc\u201d\u7684\u5b57\u9762\u91cf\uff0c\u90a3\u4e48\uff0c\u5982\u679c\u53d1\u751f\u5783\u573e\u56de\u6536\u5e76\u4e14\u6709\u5fc5\u8981\u65f6\uff0c\u201cabc\u201d\u5c31\u4f1a\u88ab\u7cfb\u7edf\u79fb\u51fa\u5e38\u91cf\u6c60\u3002\u5e38\u91cf\u6c60\u4e2d\u7684\u5176\u4ed6\u7c7b\uff08\u63a5\u53e3\uff09\u3001\u65b9\u6cd5\u3001\u5b57\u6bb5\u7684\u7b26\u53f7\u5f15\u7528\u4e5f\u4e0e\u6b64\u7c7b\u4f3c\u3002<strong><br \/>\n<\/strong><\/p>\n<p>\u5982\u4f55\u5224\u65ad\u65e0\u7528\u7684\u7c7b\u5462\uff1f\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u4e09\u4e2a\u6761\u4ef6<\/p>\n<p>1. \u8be5\u7c7b\u7684\u6240\u6709\u5b9e\u4f8b\u90fd\u5df2\u7ecf\u88ab\u56de\u6536\uff0c\u5373Java\u5806\u4e2d\u4e0d\u5b58\u5728\u8be5\u7c7b\u7684\u4efb\u4f55\u5b9e\u4f8b\u3002<\/p>\n<p>2. \u52a0\u8f7d\u8be5\u7c7b\u7684ClassLoader\u5df2\u7ecf\u88ab\u56de\u6536\u3002<\/p>\n<p>3. \u8be5\u7c7b\u5bf9\u5e94\u7684java.lang.Class\u5bf9\u8c61\u6ca1\u6709\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u5f15\u7528\uff0c\u65e0\u6cd5\u5728\u4efb\u4f55\u5730\u65b9\u901a\u8fc7\u53cd\u5c04\u8bbf\u95ee\u8be5\u7c7b\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u6ee1\u8db3\u4ee5\u4e0a\u4e09\u4e2a\u6761\u4ef6\u7684\u7c7b\u53ef\u4ee5\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u4f46\u662f\u5e76\u4e0d\u662f\u65e0\u7528\u5c31\u88ab\u56de\u6536\uff0c\u865a\u62df\u673a\u63d0\u4f9b\u4e86\u4e00\u4e9b\u53c2\u6570\u4f9b\u6211\u4eec\u914d\u7f6e\u3002<\/p>\n<p><strong>\u4e03\u3001\u5783\u573e\u6536\u96c6\u7b97\u6cd5<\/strong><\/p>\n<p>\u5783\u573e\u6536\u96c6\u7684\u4e3b\u8981\u7b97\u6cd5\u6709\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p>1. \u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5<\/p>\n<p>2. \u590d\u5236\u7b97\u6cd5<\/p>\n<p>3. \u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5<\/p>\n<p>4. \u5206\u4ee3\u6536\u96c6\u7b97\u6cd5<\/p>\n<p>7.1 \u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5<\/p>\n<p>\u9996\u5148\u6807\u8bb0\u51fa\u6240\u6709\u9700\u8981\u56de\u6536\u7684\u5bf9\u8c61\uff0c\u4f7f\u7528\u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5\u5224\u65ad\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u53ef\u56de\u6536\uff0c\u5728\u6807\u8bb0\u5b8c\u6210\u540e\u7edf\u4e00\u56de\u6536\u6240\u6709\u88ab\u6807\u8bb0\u7684\u5bf9\u8c61\u3002\u4e0b\u56fe\u662f\u7b97\u6cd5\u5177\u4f53\u7684\u4e00\u6b21\u6267\u884c\u8fc7\u7a0b\u540e\u7684\u7ed3\u679c\u5bf9\u6bd4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226171404552-396188379.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1.\u6548\u7387\u95ee\u9898\uff0c\u6807\u8bb0\u548c\u6e05\u9664\u4e24\u4e2a\u9636\u6bb5\u7684\u6548\u7387\u90fd\u4e0d\u9ad8\u30022.\u7a7a\u95f4\u95ee\u9898\uff0c\u6807\u8bb0\u6e05\u9664\u540e\u4f1a\u4ea7\u751f\u5927\u91cf\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u788e\u7247\uff0c\u4ee5\u540e\u9700\u8981\u7ed9\u5927\u5bf9\u8c61\u5206\u914d\u5185\u5b58\u65f6\uff0c\u4f1a\u63d0\u524d\u89e6\u53d1\u4e00\u6b21\u5783\u573e\u56de\u6536\u52a8\u4f5c\u3002<\/p>\n<p>7.2 \u590d\u5236\u7b97\u6cd5<\/p>\n<p>\u5c06\u5185\u5b58\u5206\u4e3a\u4e24\u7b49\u5757\uff0c\u6bcf\u6b21\u4f7f\u7528\u5176\u4e2d\u4e00\u5757\u3002\u5f53\u8fd9\u4e00\u5757\u5185\u5b58\u7528\u5b8c\u540e\uff0c\u5c31\u5c06\u8fd8\u5b58\u6d3b\u7684\u5bf9\u8c61\u590d\u5236\u5230\u53e6\u5916\u4e00\u4e2a\u5757\u4e0a\u9762\uff0c\u7136\u540e\u518d\u628a\u5df2\u7ecf\u4f7f\u7528\u8fc7\u7684\u5185\u5b58\u7a7a\u95f4\u4e00\u6b21\u6e05\u7406\u6389\u3002\u56fe\u662f\u7b97\u6cd5\u5177\u4f53\u7684\u4e00\u6b21\u6267\u884c\u8fc7\u7a0b\u540e\u7684\u7ed3\u679c\u5bf9\u6bd4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226171921130-1980588092.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1.\u65e0\u5185\u5b58\u788e\u7247\u95ee\u9898\u30022.\u53ef\u7528\u5185\u5b58\u7f29\u5c0f\u4e3a\u539f\u6765\u7684\u4e00\u534a\u3002 3.\u5f53\u5b58\u6d3b\u7684\u5bf9\u8c61\u6570\u91cf\u5f88\u591a\u65f6\uff0c\u590d\u5236\u7684\u6548\u7387\u5f88\u6162\u3002<\/p>\n<p>7.3 \u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5<\/p>\n<p>\u6807\u8bb0\u8fc7\u7a0b\u8fd8\u662f\u548c\u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5\u4e00\u6837\uff0c\u4e4b\u540e\u8ba9\u6240\u6709\u5b58\u6d3b\u7684\u5bf9\u8c61\u90fd\u5411\u4e00\u7aef\u79fb\u52a8\uff0c\u7136\u540e\u76f4\u63a5\u6e05\u7406\u6389\u8fb9\u754c\u4ee5\u5916\u7684\u5185\u5b58\uff0c\u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5\u793a\u610f\u56fe\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226173024208-705798586.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1.\u65e0\u9700\u8003\u8651\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002<\/p>\n<p>7.4 \u5206\u4ee3\u6536\u96c6\u7b97\u6cd5<\/p>\n<p>\u628a\u5806\u5206\u4e3a\u65b0\u751f\u4ee3\u548c\u8001\u5e74\u4ee3\uff0c\u7136\u540e\u6839\u636e\u5404\u5e74\u4ee3\u7684\u7279\u70b9\u9009\u62e9\u6700\u5408\u9002\u7684\u56de\u6536\u7b97\u6cd5\u3002\u5728\u65b0\u751f\u4ee3\u57fa\u672c\u4e0a\u90fd\u662f\u671d\u751f\u66ae\u6b7b\u7684\uff0c\u751f\u5b58\u65f6\u95f4\u5f88\u77ed\u6682\uff0c\u56e0\u6b64\u53ef\u4ee5\u91c7\u62e5\u6807\u8bb0 &#8211; \u590d\u5236\u7b97\u6cd5\uff0c\u53ea\u9700\u8981\u590d\u5236\u5c11\u91cf\u7684\u5bf9\u8c61\u5c31\u53ef\u4ee5\u5b8c\u6210\u6536\u96c6\u3002\u800c\u8001\u5e74\u4ee3\u4e2d\u7684\u5bf9\u8c61\u5b58\u6d3b\u7387\u9ad8\uff0c\u4e5f\u6ca1\u6709\u989d\u5916\u7684\u7a7a\u95f4\u8fdb\u884c\u5206\u914d\u62c5\u4fdd\uff0c\u56e0\u6b64\u5fc5\u987b\u4f7f\u7528\u6807\u8bb0 &#8211; \u6574\u7406\u6216\u8005\u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5\u8fdb\u884c\u56de\u6536\u3002<\/p>\n<p><strong>\u516b\u3001HotSpot\u7684\u7b97\u6cd5\u5b9e\u73b0<\/strong><\/p>\n<p>\u5bf9\u4e8e\u53ef\u8fbe\u6027\u5206\u6790\u800c\u8a00\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u9996\u5148\u9700\u8981\u9009\u53d6GCRoots\u7ed3\u70b9\uff0c\u800cGCRoots\u7ed3\u70b9\u4e3b\u8981\u5728\u5168\u5c40\u6027\u7684\u5f15\u7528\uff08\u5982\u5e38\u91cf\u6216\u7c7b\u9759\u6001\u5c5e\u6027\uff09\u4e0e\u6267\u884c\u4e0a\u4e0b\u6587\uff08\u5982\u6808\u5e27\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u8868\uff09\u4e2d\u3002\u65b9\u6cd5\u533a\u53ef\u4ee5\u5f88\u5927\uff0c\u8fd9\u5bf9\u4e8e\u5bfb\u627eGCRoots\u7ed3\u70b9\u6765\u8bf4\u4f1a\u975e\u5e38\u8017\u65f6\u3002\u5f53\u9009\u53d6\u4e86GCRoots\u7ed3\u70b9\u4e4b\u540e\uff0c\u8fdb\u884c\u53ef\u8fbe\u6027\u5206\u6790\u65f6\u5fc5\u987b\u8981\u4fdd\u8bc1\u4e00\u81f4\u6027\uff0c\u5373\u5728\u8fdb\u884c\u5206\u6790\u7684\u8fc7\u7a0b\u4e2d\u6574\u4e2a\u6267\u884c\u7cfb\u7edf\u770b\u8d77\u6765\u5c31\u597d\u50cf\u88ab\u51bb\u7ed3\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u4e0a\uff0c\u4e0d\u53ef\u4ee5\u5728\u5206\u6790\u7684\u65f6\u5019\uff0c\u5bf9\u8c61\u7684\u5173\u7cfb\u8fd8\u5728\u52a8\u6001\u53d8\u5316\uff0c\u8fd9\u6837\u7684\u8bdd\u5206\u6790\u7684\u51c6\u786e\u6027\u5c31\u5f97\u4e0d\u5230\u4fdd\u8bc1\uff0c\u6240\u4ee5\u53ef\u8fbe\u6027\u5206\u6790\u662f\u65f6\u95f4\u975e\u5e38\u654f\u611f\u7684\u3002<\/p>\n<p>\u4e3a\u4e86\u4fdd\u8bc1\u5206\u6790\u7ed3\u679c\u7684\u51c6\u786e\u6027\uff0c\u5c31\u4f1a\u5bfc\u81f4GC\u8fdb\u884c\u65f6\u5fc5\u987b\u505c\u987f\u6240\u6709Java\u6267\u884c\u7ebf\u7a0b\uff08Stop the world\uff09\uff0c\u4e3a\u4e86\u5c3d\u53ef\u80fd\u7684\u51cf\u5c11Stop the world\u7684\u65f6\u95f4\uff0cJava\u865a\u62df\u673a\u4f7f\u7528\u4e86\u4e00\u7ec4\u79f0\u4e3aOopMap\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u7528\u4e8e\u5b58\u653e\u5bf9\u8c61\u5f15\u7528\u7684\u5730\u5740\uff0c\u8fd9\u6837\uff0c\u8fdb\u884c\u53ef\u8fbe\u6027\u5206\u6790\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95eeOopMap\u5c31\u53ef\u4ee5\u83b7\u5f97\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4ece\u800c\u52a0\u5feb\u5206\u6790\u8fc7\u7a0b\uff0c\u51cf\u5c11Stop the world\u65f6\u95f4\u3002<\/p>\n<p>OopMap\u6570\u636e\u7ed3\u6784\u6709\u5229\u4e8e\u8fdb\u884cGC\uff0c\u662f\u4e0d\u662f\u865a\u62df\u673a\u65e0\u8bba\u4f55\u65f6\u60f3\u8981\u8fdb\u884cGC\u90fd\u53ef\u4ee5\u8fdb\u884cGC\uff0c\u5373\u65e0\u8bba\u865a\u62df\u673a\u5728\u6267\u884c\u4ec0\u4e48\u6307\u4ee4\u90fd\u53ef\u4ee5\u8fdb\u884cGC\uff1f\u7b54\u6848\u662f\u5426\u5b9a\u7684\uff0c\u56e0\u4e3a\u8981\u60f3\u8ba9\u865a\u62df\u673a\u65e0\u8bba\u5728\u6267\u884c\u4ec0\u4e48\u6307\u4ee4\u7684\u65f6\u5019\u90fd\u53ef\u4ee5\u8fdb\u884cGC\u7684\u8bdd\uff0c\u9700\u8981\u4e3a\u6bcf\u6761\u6307\u4ee4\u90fd\u751f\u6210OopMap\uff0c\u663e\u7136\uff0c\u8fd9\u6837\u592a\u6d6a\u8d39\u7a7a\u95f4\u4e86\u3002\u4e3a\u4e86\u8282\u7ea6\u5b9d\u8d35\u7684\u7a7a\u95f4\uff0c\u865a\u62df\u673a\u53ea\u5728\u201d\u7279\u5b9a\u7684\u4f4d\u7f6e\u201c\u5b58\u653e\u4e86OopMap\u6570\u636e\u7ed3\u6784\uff0c\u8fd9\u4e2a\u7279\u5b9a\u7684\u4f4d\u7f6e\u6211\u4eec\u79f0\u4e4b\u4e3a\u5b89\u5168\u70b9\u3002\u7a0b\u5e8f\u6267\u884c\u65f6\u5e76\u975e\u5728\u6240\u6709\u5730\u65b9\u90fd\u80fd\u591f\u505c\u987f\u4e0b\u6765\u5f00\u59cbGC\uff08\u53ef\u8fbe\u6027\u5206\u6790\uff09\uff0c\u53ea\u6709\u5230\u8fbe\u5b89\u5168\u70b9\u7684\u65f6\u5019\u624d\u80fd\u6682\u505c\u3002\u5b89\u5168\u70b9\u53ef\u4ee5\u7531\u65b9\u6cd5\u8c03\u7528\u3001\u5faa\u73af\u8df3\u8f6c\u3001\u5f02\u5e38\u8df3\u8f6c\u7b49\u6307\u4ee4\u4ea7\u751f\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u6307\u4ee4\u4f1a\u8ba9\u7a0b\u5e8f\u957f\u65f6\u95f4\u6267\u884c\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e86\u5b89\u5168\u70b9\u7684\u6982\u5ff5\uff0c\u5373\u8fdb\u884cGC\u5fc5\u987b\u8981\u5230\u8fbe\u5b89\u5168\u70b9\uff0c\u90a3\u4e48\u5728\u53d1\u751fGC\u65f6\u5982\u4f55\u8ba9\u6240\u6709\u7ebf\u7a0b\u5230\u8fbe\u5b89\u5168\u70b9\u518d\u6682\u505c\u5462\uff1f\u6709\u4e24\u79cd\u65b9\u6cd51. \u62a2\u5148\u5f0f\u4e2d\u65ad\uff0c\u5728\u53d1\u751fGC\u65f6\uff0c\u9996\u5148\u628a\u6240\u6709\u7ebf\u7a0b\u5168\u90e8\u4e2d\u65ad\uff0c\u5982\u679c\u53d1\u73b0\u7ebf\u7a0b\u4e2d\u65ad\u7684\u5730\u65b9\u4e0d\u5728\u5b89\u5168\u70b9\u4e0a\uff0c\u5c31\u6062\u590d\u7ebf\u7a0b\uff0c\u8ba9\u5b83\u8dd1\u5230\u5b89\u5168\u70b9\u4e0a\u30022. \u4e3b\u52a8\u5f0f\u4e2d\u65ad\uff0c\u5728\u53d1\u751fGC\u65f6\uff0c\u4e0d\u4e2d\u65ad\u7ebf\u7a0b\uff0c\u800c\u662f\u8bbe\u7f6e\u4e00\u4e2a\u6807\u5fd7\uff0c\u6240\u6709\u7ebf\u7a0b\u6267\u884c\u65f6\u4e3b\u52a8\u8f6e\u8be2\u8fd9\u4e2a\u6807\u5fd7\uff0c\u53d1\u751f\u6807\u5fd7\u4f4d\u771f\u5c31\u81ea\u5df1\u4e2d\u65ad\u6302\u8d77\uff0c\u8f6e\u8be2\u6807\u5fd7\u7684\u5730\u65b9\u548c\u5b89\u5168\u70b9\u662f\u91cd\u5408\u7684\uff0c\u4e5f\u6709\u53ef\u80fd\u662f\u521b\u5efa\u5bf9\u8c61\u9700\u8981\u5206\u914d\u5185\u5b58\u7684\u5730\u65b9\u3002<\/p>\n<p>\u73b0\u5728\u95ee\u9898\u53c8\u6765\u4e86\uff0c\u5f53\u7a0b\u5e8f\u4e0d\u6267\u884c\u7684\u65f6\u5019\uff0c\u5982\u4f55\u8ba9\u6240\u6709\u7ebf\u7a0b\u8fbe\u5230\u5b89\u5168\u70b9\u5462\uff1f\u5178\u578b\u7684\u5c31\u662f\u7ebf\u7a0b\u5904\u4e8eSleep\u72b6\u6001\u6216\u8005Blocked\u72b6\u6001\uff0c\u8fd9\u65f6\u5019\u7ebf\u7a0b\u662f\u65e0\u6cd5\u8dd1\u5230\u5b89\u5168\u70b9\u518d\u4e2d\u65ad\u81ea\u5df1\u7684\uff0c\u865a\u62df\u673a\u4e5f\u80af\u5b9a\u4e0d\u53ef\u80fd\u7b49\u5f85\u8be5\u7ebf\u7a0b\u88ab\u5524\u9192\u5e76\u91cd\u65b0\u5206\u914dCPU\u65f6\u95f4\u540e\uff0c\u8dd1\u5230\u5b89\u5168\u70b9\u518d\u6682\u505c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5f15\u5165\u5b89\u5168\u533a\u57df\u7684\u6982\u5ff5\u3002\u5b89\u5168\u533a\u57df\u662f\u5bf9\u5b89\u5168\u70b9\u7684\u6269\u5c55\uff0c\u53ef\u4ee5\u770b\u6210\u7531\u5f88\u591a\u5b89\u5168\u70b9\u7ec4\u6210\uff0c\u5b89\u5168\u533a\u57df\u662f\u6307\u4e00\u6bb5\u4ee3\u7801\u7247\u6bb5\u4e4b\u4e2d\uff0c\u5f15\u7528\u5173\u7cfb\u4e0d\u4f1a\u53d1\u751f\u53d8\u5316\u3002\u5728\u8fd9\u4e2a\u533a\u57df\u7684\u4efb\u4f55\u5730\u65b9\u5f00\u59cbGC\u90fd\u662f\u5b89\u5168\u7684\u3002\u5f53\u7ebf\u7a0b\u6267\u884c\u5230\u5b89\u5168\u533a\u57df\u7684\u4ee3\u7801\u65f6\uff0c\u9996\u5148\u6807\u793a\u81ea\u5df1\u5df2\u7ecf\u8fdb\u5165\u4e86\u5b89\u5168\u533a\u57df\uff0c\u90a3\u4e48\uff0c\u5728\u8fd9\u6bb5\u65f6\u95f4\u91ccJVM\u53d1\u8d77GC\u65f6\uff0c\u5c31\u4e0d\u7528\u7ba1\u6807\u793a\u81ea\u5df1\u4e3a\u5b89\u5168\u533a\u57df\u72b6\u6001\u7684\u7ebf\u7a0b\u4e86\u3002\u5728\u7ebf\u7a0b\u5965\u79bb\u5f00\u5b89\u5168\u533a\u57df\u65f6\uff0c\u5b83\u8981\u68c0\u67e5\u7cfb\u7edf\u662f\u5426\u5df2\u7ecf\u5b8c\u6210\u4e86\u6839\u8282\u70b9\u679a\u4e3e\uff08\u6216\u8005\u6574\u4e2aGC\u8fc7\u7a0b\uff09\uff0c\u82e5\u5b8c\u6210\uff0c\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\uff1b\u5426\u5219\uff0c\u5b83\u5fc5\u987b\u7b49\u5f85\u76f4\u5230\u6536\u5230\u53ef\u4ee5\u5b89\u5168\u79bb\u5f00\u5b89\u5168\u533a\u57df\u7684\u4fe1\u53f7\u3002<\/p>\n<p><strong>\u4e5d\u3001\u5783\u573e\u6536\u96c6\u5668<\/strong><\/p>\n<p><strong>\u3000\u3000<\/strong>\u5783\u573e\u6536\u96c6\u5668\u662f\u5185\u5b58\u56de\u6536\u7684\u5177\u4f53\u5b9e\u73b0\uff0cHotSpot\u865a\u62df\u673a\u5305\u542b\u7684\u6240\u6709\u6536\u96c6\u5668\u5982\u4e0b\uff1a<\/p>\n<p><strong><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226204214771-1350914780.png\" alt=\"\" \/>\u3000\u3000<\/strong><\/p>\n<p><strong>\u3000\u3000<\/strong>\u8bf4\u660e\uff1a\u56fe\u4e2d\u5b58\u5728\u8fde\u7ebf\u8868\u793a\u53ef\u4ee5\u642d\u914d\u4f7f\u7528\uff0c\u603b\u5171\u67097\u79cd\u4e0d\u540c\u5206\u4ee3\u7684\u6536\u96c6\u5668\u3002<\/p>\n<p>9.1 Serial\u6536\u96c6\u5668<\/p>\n<p>Serial\u6536\u96c6\u5668\u4e3a\u5355\u7ebf\u7a0b\u6536\u96c6\u5668\uff0c\u5728\u8fdb\u884c\u5783\u573e\u6536\u96c6\u65f6\uff0c\u5fc5\u987b\u8981\u6682\u505c\u5176\u4ed6\u6240\u6709\u7684\u5de5\u4f5c\u7ebf\u7a0b\uff0c\u76f4\u5230\u5b83\u6536\u96c6\u7ed3\u675f\u3002\u8fd0\u884c\u8fc7\u7a0b\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226210049380-85236798.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1. \u9700\u8981STW\uff08Stop The World\uff09\uff0c\u505c\u987f\u65f6\u95f4\u957f\u30022. \u7b80\u5355\u9ad8\u6548\uff0c\u5bf9\u4e8e\u5355\u4e2aCPU\u73af\u5883\u800c\u8a00\uff0cSerial\u6536\u96c6\u5668\u7531\u4e8e\u6ca1\u6709\u7ebf\u7a0b\u4ea4\u4e92\u5f00\u9500\uff0c\u53ef\u4ee5\u83b7\u53d6\u6700\u9ad8\u7684\u5355\u7ebf\u7a0b\u6536\u96c6\u6548\u7387\u3002<\/p>\n<p>9.2 ParNew\u6536\u96c6\u5668<\/p>\n<p>ParNew\u662fSerial\u7684\u591a\u7ebf\u7a0b\u7248\u672c\uff0c\u9664\u4e86\u4f7f\u7528\u591a\u7ebf\u7a0b\u8fdb\u884c\u5783\u573e\u6536\u96c6\u5916\uff0c\u5176\u4ed6\u884c\u4e3a\u4e0eSerial\u5b8c\u5168\u4e00\u6837\uff0c\u8fd0\u884c\u8fc7\u7a0b\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226210203818-445421977.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1.Server\u6a21\u5f0f\u4e0b\u865a\u62df\u673a\u7684\u9996\u9009\u65b0\u751f\u6536\u96c6\u5668\uff0c\u4e0eCMS\u8fdb\u884c\u642d\u914d\u4f7f\u7528\u3002<\/p>\n<p>9.3 Parallel Scavenge\u6536\u96c6\u5668<\/p>\n<p>Parallel Scavenge\u6536\u96c6\u5668\u7684\u76ee\u6807\u662f\u8fbe\u5230\u4e00\u4e2a\u53ef\u63a7\u5236\u7684\u541e\u5410\u91cf\uff0c\u541e\u5410\u91cf = \u8fd0\u884c\u7528\u6237\u4ee3\u7801\u65f6\u95f4 \/ (\u8fd0\u884c\u7528\u6237\u4ee3\u7801\u65f6\u95f4 + \u5783\u573e\u6536\u96c6\u65f6\u95f4)\uff0c\u9ad8\u541e\u5410\u91cf\u53ef\u4ee5\u9ad8\u6548\u7387\u5730\u5229\u7528CPU\u65f6\u95f4\uff0c\u5c3d\u5feb\u5b8c\u6210\u7a0b\u5e8f\u7684\u8fd0\u7b97\u4efb\u52a1\uff0c\u4e3b\u8981\u9002\u5408\u5728\u540e\u53f0\u8fd0\u7b97\u800c\u4e0d\u9700\u8981\u592a\u591a\u4ea4\u4e92\u7684\u4efb\u52a1\uff0c\u5e76\u4e14\u865a\u62df\u673a\u4f1a\u6839\u636e\u5f53\u524d\u7cfb\u7edf\u7684\u8fd0\u884c\u60c5\u51b5\u6536\u96c6\u6027\u80fd\u76d1\u63a7\u4fe1\u606f\uff0c\u52a8\u6001\u8c03\u6574\u8fd9\u4e9b\u53c2\u6570\u4ee5\u63d0\u4f9b\u6700\u5408\u9002\u7684\u505c\u987f\u65f6\u95f4\u6216\u8005\u6700\u5927\u7684\u541e\u5410\u91cf\uff0c\u8fd9\u79cd\u8c03\u8282\u65b9\u5f0f\u79f0\u4e3aGC\u81ea\u9002\u5e94\u8c03\u8282\u7b56\u7565\u3002<\/p>\n<p>9.4 Serial Old\u6536\u96c6\u5668<\/p>\n<p>\u8001\u5e74\u4ee3\u7684\u5355\u7ebf\u7a0b\u6536\u96c6\u5668\uff0c\u4f7f\u7528\u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5\uff0c\u8fd0\u884c\u8fc7\u7a0b\u5728\u4e4b\u524d\u7684Serial\u6536\u96c6\u5668\u5df2\u7ecf\u7ed9\u51fa\u3002\u4e0d\u518d\u7d2f\u8d58\u3002<\/p>\n<p>9.5 Parallel Old\u6536\u96c6\u5668<\/p>\n<p>\u8001\u5e74\u4ee3\u7684\u591a\u7ebf\u7a0b\u6536\u96c6\u5668\uff0c\u4f7f\u7528\u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5\uff0c\u541e\u5410\u91cf\u4f18\u5148\uff0c\u9002\u5408\u4e8eParallel Scavenge\u642d\u914d\u4f7f\u7528\uff0c\u8fd0\u884c\u8fc7\u7a0b\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226211758833-385213915.png\" alt=\"\" \/><\/p>\n<p>9.6 CMS\u6536\u96c6\u5668<\/p>\n<p>CMS\uff08Conrrurent Mark Sweep\uff09\u6536\u96c6\u5668\u662f\u4ee5\u83b7\u53d6\u6700\u77ed\u56de\u6536\u505c\u987f\u65f6\u95f4\u4e3a\u76ee\u6807\u7684\u6536\u96c6\u5668\u3002\u4f7f\u7528\u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5\uff0c\u6536\u96c6\u8fc7\u7a0b\u5206\u4e3a\u5982\u4e0b\u56db\u6b65\uff1a<\/p>\n<p>1. \u521d\u59cb\u6807\u8bb0\uff0c\u6807\u8bb0GCRoots\u80fd\u76f4\u63a5\u5173\u8054\u5230\u7684\u5bf9\u8c61\uff0c\u65f6\u95f4\u5f88\u77ed\u3002<\/p>\n<p>2. \u5e76\u53d1\u6807\u8bb0\uff0c\u8fdb\u884cGCRoots Tracing\uff08\u53ef\u8fbe\u6027\u5206\u6790\uff09\u8fc7\u7a0b\uff0c\u65f6\u95f4\u5f88\u957f\u3002<\/p>\n<p>3. \u91cd\u65b0\u6807\u8bb0\uff0c\u4fee\u6b63\u5e76\u53d1\u6807\u8bb0\u671f\u95f4\u56e0\u7528\u6237\u7a0b\u5e8f\u7ee7\u7eed\u8fd0\u4f5c\u800c\u5bfc\u81f4\u6807\u8bb0\u4ea7\u751f\u53d8\u52a8\u7684\u90a3\u4e00\u90e8\u5206\u5bf9\u8c61\u7684\u6807\u8bb0\u8bb0\u5f55\uff0c\u65f6\u95f4\u8f83\u957f\u3002<\/p>\n<p>4. \u5e76\u53d1\u6e05\u9664\uff0c\u56de\u6536\u5185\u5b58\u7a7a\u95f4\uff0c\u65f6\u95f4\u5f88\u957f\u3002<\/p>\n<p>\u5176\u4e2d\uff0c\u5e76\u53d1\u6807\u8bb0\u4e0e\u5e76\u53d1\u6e05\u9664\u4e24\u4e2a\u9636\u6bb5\u8017\u65f6\u6700\u957f\uff0c\u4f46\u662f\u53ef\u4ee5\u4e0e\u7528\u6237\u7ebf\u7a0b\u5e76\u53d1\u6267\u884c\u3002\u8fd0\u884c\u8fc7\u7a0b\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160226213333458-1151839422.png\" alt=\"\" \/><\/p>\n<p>\u8bf4\u660e\uff1a1. \u5bf9CPU\u8d44\u6e90\u975e\u5e38\u654f\u611f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u53d8\u6162\uff0c\u541e\u5410\u7387\u4e0b\u964d\u30022. \u65e0\u6cd5\u5904\u7406\u6d6e\u52a8\u5783\u573e\uff0c\u56e0\u4e3a\u5728\u5e76\u53d1\u6e05\u7406\u9636\u6bb5\u7528\u6237\u7ebf\u7a0b\u8fd8\u5728\u8fd0\u884c\uff0c\u81ea\u7136\u5c31\u4f1a\u4ea7\u751f\u65b0\u7684\u5783\u573e\uff0c\u800c\u5728\u6b64\u6b21\u6536\u96c6\u4e2d\u65e0\u6cd5\u6536\u96c6\u4ed6\u4eec\uff0c\u53ea\u80fd\u7559\u5230\u4e0b\u6b21\u6536\u96c6\uff0c\u8fd9\u90e8\u5206\u5783\u573e\u4e3a\u6d6e\u52a8\u5783\u573e\uff0c\u540c\u65f6\uff0c\u7531\u4e8e\u7528\u6237\u7ebf\u7a0b\u5e76\u53d1\u6267\u884c\uff0c\u6240\u4ee5\u9700\u8981\u9884\u7559\u4e00\u90e8\u5206\u8001\u5e74\u4ee3\u7a7a\u95f4\u63d0\u4f9b\u5e76\u53d1\u6536\u96c6\u65f6\u7a0b\u5e8f\u8fd0\u884c\u4f7f\u7528\u30023. \u7531\u4e8e\u91c7\u7528\u7684\u6807\u8bb0 &#8211; \u6e05\u9664\u7b97\u6cd5\uff0c\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u5185\u5b58\u788e\u7247\uff0c\u4e0d\u5229\u4e8e\u5927\u5bf9\u8c61\u7684\u5206\u914d\uff0c\u53ef\u80fd\u4f1a\u63d0\u524d\u89e6\u53d1\u4e00\u6b21Full GC\u3002\u865a\u62df\u673a\u63d0\u4f9b\u4e86-XX:+UseCMSCompactAtFullCollection\u53c2\u6570\u6765\u8fdb\u884c\u788e\u7247\u7684\u5408\u5e76\u6574\u7406\u8fc7\u7a0b\uff0c\u8fd9\u6837\u4f1a\u4f7f\u5f97\u505c\u987f\u65f6\u95f4\u53d8\u957f\uff0c\u865a\u62df\u673a\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53c2\u6570\u914d\u7f6e\uff0c-XX:+CMSFullGCsBeforeCompaction\uff0c\u7528\u4e8e\u8bbe\u7f6e\u6267\u884c\u591a\u5c11\u6b21\u4e0d\u538b\u7f29\u7684Full GC\u540e\uff0c\u63a5\u7740\u6765\u4e00\u6b21\u5e26\u538b\u7f29\u7684GC\u3002<\/p>\n<p>9.7 G1\u6536\u96c6\u5668<\/p>\n<p>\u53ef\u4ee5\u5728\u65b0\u751f\u4ee3\u548c\u8001\u5e74\u4ee3\u4e2d\u53ea\u4f7f\u7528G1\u6536\u96c6\u5668\u3002\u5177\u6709\u5982\u4e0b\u7279\u70b9\u3002<\/p>\n<p>1. \u5e76\u884c\u548c\u5e76\u53d1\u3002\u4f7f\u7528\u591a\u4e2aCPU\u6765\u7f29\u77edStop The World\u505c\u987f\u65f6\u95f4\uff0c\u4e0e\u7528\u6237\u7ebf\u7a0b\u5e76\u53d1\u6267\u884c\u3002<\/p>\n<p>2. \u5206\u4ee3\u6536\u96c6\u3002\u72ec\u7acb\u7ba1\u7406\u6574\u4e2a\u5806\uff0c\u4f46\u662f\u80fd\u591f\u91c7\u7528\u4e0d\u540c\u7684\u65b9\u5f0f\u53bb\u5904\u7406\u65b0\u521b\u5efa\u5bf9\u8c61\u548c\u5df2\u7ecf\u5b58\u6d3b\u4e86\u4e00\u6bb5\u65f6\u95f4\u3001\u71ac\u8fc7\u591a\u6b21GC\u7684\u65e7\u5bf9\u8c61\uff0c\u4ee5\u83b7\u53d6\u66f4\u597d\u7684\u6536\u96c6\u6548\u679c\u3002<\/p>\n<p>3. \u7a7a\u95f4\u6574\u5408\u3002\u57fa\u4e8e\u6807\u8bb0 &#8211; \u6574\u7406\u7b97\u6cd5\uff0c\u65e0\u5185\u5b58\u788e\u7247\u4ea7\u751f\u3002<\/p>\n<p>4. \u53ef\u9884\u6d4b\u7684\u505c\u987f\u3002\u80fd\u7b80\u5386\u53ef\u9884\u6d4b\u7684\u505c\u987f\u65f6\u95f4\u6a21\u578b\uff0c\u80fd\u8ba9\u4f7f\u7528\u8005\u660e\u786e\u6307\u5b9a\u5728\u4e00\u4e2a\u957f\u5ea6\u4e3aM\u6beb\u79d2\u7684\u65f6\u95f4\u7247\u6bb5\u5185\uff0c\u6d88\u8017\u5728\u5783\u573e\u6536\u96c6\u4e0a\u7684\u65f6\u95f4\u4e0d\u5f97\u8d85\u8fc7N\u6beb\u79d2\u3002<\/p>\n<p>\u4f7f\u7528G1\u6536\u96c6\u5668\u65f6\uff0cJava\u5806\u4f1a\u88ab\u5212\u5206\u4e3a\u591a\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u72ec\u7acb\u533a\u57df\uff08Region\uff09,\u867d\u7136\u8fd8\u4fdd\u7559\u65b0\u751f\u4ee3\u548c\u8001\u5e74\u4ee3\u7684\u6982\u5ff5\uff0c\u4f46\u4e24\u8005\u5df2\u7ecf\u4e0d\u662f\u7269\u7406\u9694\u79bb\u4e86\uff0c\u90fd\u662f\u4e00\u90e8\u5206Region\uff08\u4e0d\u9700\u8981\u8fde\u7eed\uff09\u7684\u96c6\u5408\u3002G1\u6536\u96c6\u5668\u4e2d\uff0cRegion\u4e4b\u95f4\u7684\u5bf9\u8c61\u5f15\u7528\u4ee5\u53ca\u5176\u4ed6\u6536\u96c6\u5668\u7684\u65b0\u751f\u4ee3\u548c\u8001\u5e74\u4ee3\u4e4b\u95f4\u7684\u5bf9\u8c61\u5f15\u7528\uff0c\u865a\u62df\u673a\u90fd\u4f7f\u7528Remembered Set\u6765\u907f\u514d\u5168\u5806\u626b\u63cf\u7684\u3002\u6bcf\u4e2aRegion\u5bf9\u5e94\u4e00\u4e2aRemembered Set,\u865a\u62df\u673a\u53d1\u73b0\u7a0b\u5e8f\u5728\u5bf9Reference\u7c7b\u578b\u7684\u6570\u636e\u8fdb\u884c\u5199\u64cd\u4f5c\u65f6\uff0c\u4f1a\u4ea7\u751f\u4e00\u4e2aWrite Barrier\u6682\u65f6\u4e2d\u65ad\u5199\u64cd\u4f5c\uff0c\u68c0\u67e5Reference\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u5426\u5904\u4e8e\u4e0d\u540c\u7684Region\u4e4b\u4e2d\uff08\u5728\u5206\u4ee3\u7684\u4f8b\u5b50\u4e2d\u5c31\u662f\u68c0\u67e5\u8001\u5e74\u4ee3\u7684\u5bf9\u8c61\u662f\u5426\u5f15\u7528\u4e86\u65b0\u751f\u4ee3\u7684\u5bf9\u8c61\uff09\uff0c\u5982\u679c\u662f\uff0c\u5219\u901a\u8fc7CardTable\u628a\u76f8\u5173\u5f15\u7528\u4fe1\u606f\u8bb0\u5f55\u5230\u88ab\u5f15\u7528\u5bf9\u8c61\u6240\u5c5e\u7684Region\u7684Remembered Set\u4e4b\u4e2d\uff0c\u5f53\u8fdb\u884c\u5185\u5b58\u56de\u6536\u65f6\uff0c\u5728GC\u6839\u8282\u70b9\u7684\u679a\u4e3e\u8303\u56f4\u4e2d\u52a0\u5165Remembered Set\u5373\u53ef\u4fdd\u8bc1\u4e0d\u5bf9\u5168\u5806\u626b\u63cf\u4e5f\u4e0d\u4f1a\u9057\u6f0f\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e0a\u8ff0\u8fc7\u7a0b\u6211\u4eec\u53ef\u4ee5\u770b\u5982\u4e0b\u4ee3\u7801\u52a0\u6df1\u7406\u89e3<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_46888e4b-618c-4edb-b3a1-5c074f30f85a\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_46888e4b-618c-4edb-b3a1-5c074f30f85a\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class G1 {\n    private Object obj;\n\n    public init() {\n        obj = new Object();\n    }\n\n    public static void main(String[] args) {\n        G1 g1 = new G1();\n        g1.init();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8bf4\u660e\uff1a\u7a0b\u5e8f\u4e2d\u6267\u884cinit\u51fd\u6570\u7684\u65f6\u5019\uff0c\u4f1a\u4ea7\u751f\u4e00\u4e2aWrite Barrier\u6682\u505c\u4e2d\u65ad\u5199\u64cd\u4f5c\uff0c\u6b64\u65f6\uff0c\u5047\u5b9a\u7a0b\u5e8f\u4e2dG1\u5bf9\u8c61\u4e0eObject\u5bf9\u8c61\u88ab\u5206\u914d\u5728\u4e0d\u540c\u7684Region\u5f53\u4e2d\uff0c\u5219\u4f1a\u628aobj\u7684\u5f15\u7528\u4fe1\u606f\u8bb0\u5f55\u5728Object\u6240\u5c5e\u7684Remembered Set\u5f53\u4e2d\u3002\u5177\u4f53\u7684\u5185\u5b58\u5206\u5e03\u56fe\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160227091448943-105458197.png\" alt=\"\" \/><\/p>\n<p>\u5982\u679c\u4e0d\u8ba1\u7b97\u7ef4\u62a4Remembered Set\u7684\u64cd\u4f5c\uff0cG1\u6536\u96c6\u5668\u7684\u8fd0\u4f5c\u53ef\u4ee5\u5206\u4e3a\u5982\u4e0b\u51e0\u6b65<\/p>\n<p>1. \u521d\u59cb\u5e76\u53d1\uff0c\u6807\u8bb0GCRoots\u80fd\u76f4\u63a5\u5173\u8054\u5230\u7684\u5bf9\u8c61\uff1b\u4fee\u6539TAMS\uff08Next Top At Mark Start\uff09,\u4f7f\u5f97\u4e0b\u4e00\u9636\u6bb5\u7a0b\u5e8f\u5e76\u53d1\u65f6\uff0c\u80fd\u591f\u5728\u53ef\u7528\u7684Region\u4e2d\u521b\u5efa\u65b0\u5bf9\u8c61\uff0c\u9700\u505c\u987f\u7ebf\u7a0b\uff0c\u8017\u65f6\u5f88\u77ed\u3002<\/p>\n<p>2. \u5e76\u53d1\u6807\u8bb0\uff0c\u4eceGCRoots\u5f00\u59cb\u8fdb\u884c\u53ef\u8fbe\u6027\u5206\u6790\uff0c\u4e0e\u7528\u6237\u7a0b\u5e8f\u5e76\u53d1\u6267\u884c\uff0c\u8017\u65f6\u5f88\u957f\u3002<\/p>\n<p>3. \u6700\u7ec8\u6807\u8bb0\uff0c\u4fee\u6b63\u5e76\u53d1\u6807\u8bb0\u671f\u95f4\u56e0\u7528\u6237\u7a0b\u5e8f\u7ee7\u7eed\u8fd0\u4f5c\u800c\u5bfc\u81f4\u6807\u8bb0\u4ea7\u751f\u53d8\u52a8\u7684\u90a3\u4e00\u90e8\u5206\u6807\u8bb0\u8bb0\u5f55\uff0c\u53d8\u52a8\u7684\u8bb0\u5f55\u5c06\u88ab\u8bb0\u5f55\u5728Remembered Set Logs\u4e2d\uff0c\u6b64\u9636\u6bb5\u4f1a\u628a\u5176\u6574\u5408\u5230Remembered Set\u4e2d\uff0c\u9700\u8981\u505c\u987f\u7ebf\u7a0b\uff0c\u4e0e\u7528\u6237\u7a0b\u5e8f\u5e76\u884c\u6267\u884c\uff0c\u8017\u65f6\u8f83\u77ed\u3002<\/p>\n<p>4. \u7b5b\u9009\u56de\u6536\uff0c\u5bf9\u5404\u4e2aRegion\u7684\u56de\u6536\u4ef7\u503c\u548c\u6210\u672c\u8fdb\u884c\u6392\u5e8f\uff0c\u6839\u636e\u7528\u6237\u671f\u671b\u7684GC\u65f6\u95f4\u8fdb\u884c\u56de\u6536\uff0c\u4e0e\u7528\u6237\u7a0b\u5e8f\u5e76\u53d1\u6267\u884c\uff0c\u65f6\u95f4\u7528\u6237\u53ef\u63a7\u3002<\/p>\n<p>G1\u6536\u96c6\u5668\u5177\u4f53\u7684\u8fd0\u884c\u793a\u610f\u56fe\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160227092812161-944002896.png\" alt=\"\" \/><\/p>\n<p>\u5404\u4e2a\u5783\u573e\u56de\u6536\u5668\u7684\u4ecb\u7ecd\u5c31\u5230\u8fd9\u91cc\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u53bb\u9605\u8bfb\u6e90\u7801\u3002<\/p>\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u76f8\u4fe1\u6709\u4e9b\u8bfb\u8005\u5bf9\u4e4b\u524d\u7684GC\u65e5\u5fd7\u53ef\u80fd\u4f1a\u6709\u4e9b\u7591\u60d1\uff0c\u4e0b\u9762\u6211\u4eec\u6765\u7406\u89e3\u4e00\u4e0bGC\u65e5\u5fd7<\/p>\n<p>[GC (System.gc()) [PSYoungGen: 6270K-&gt;584K(9216K)] 11390K-&gt;5712K(19456K), 0.0011969 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]<br \/>\n[Full GC (System.gc()) [PSYoungGen: 584K-&gt;0K(9216K)] [ParOldGen: 5128K-&gt;514K(10240K)] 5712K-&gt;514K(19456K), [Metaspace: 2560K-&gt;2560K(1056768K)], 0.0059342 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]<br \/>\nHeap<br \/>\nPSYoungGen\u00a0\u00a0\u00a0\u00a0\u00a0 total 9216K, used 82K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\neden space 8192K, 1% used [0x00000000ff600000,0x00000000ff614920,0x00000000ffe00000)<br \/>\nfrom space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)<br \/>\nto\u00a0\u00a0 space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)<br \/>\nParOldGen\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 total 10240K, used 514K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\nobject space 10240K, 5% used [0x00000000fec00000,0x00000000fec80928,0x00000000ff600000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2567K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<\/p>\n<p>\u8fd9\u662f\u4e4b\u524d\u51fa\u73b0\u8fc7\u7684GC\u65e5\u5fd7\uff0c\u53ef\u4ee5\u77e5\u9053\u7b14\u8005\u865a\u62df\u673a\u7684\u5783\u573e\u6536\u96c6\u5668\u7684\u7ec4\u5408\u4e3aParallel Scavenge(\u65b0\u751f\u4ee3) + Parallel Old(\u8001\u5e74\u4ee3)\uff0c\u662f\u6839\u636ePSYoungGen\u548cParOldGen\u5f97\u77e5\uff0c\u4e0d\u540c\u7684\u5783\u573e\u56de\u6536\u5668\u7684\u4e0d\u540c\u7ec4\u6210\u7684\u65b0\u751f\u4ee3\u548c\u8001\u5e74\u4ee3\u7684\u540d\u5b57\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u865a\u62df\u673a\u4e5f\u63d0\u4f9b\u4e86\u53c2\u6570\u4f9b\u6211\u4eec\u9009\u62e9\u4e0d\u540c\u7684\u5783\u573e\u6536\u96c6\u5668\u3002<\/p>\n<p>1. [GC (System.gc())]\u4e0e[Full GC (System.gc())]\uff0c\u8bf4\u660e\u5783\u573e\u6536\u96c6\u7684\u505c\u987f\u7c7b\u578b\uff0c\u4e0d\u662f\u533a\u5206\u65b0\u751f\u4ee3GC\u548c\u8001\u5e74\u4ee3GC\u7684\uff0c\u5982\u679c\u6709Full\uff0c\u5219\u8868\u793a\u6b64\u6b21GC\u53d1\u751f\u4e86Stop The World\u3002<\/p>\n<p>2. PSYoungGen: 6270K-&gt;584K(9216K)\uff0c\u8868\u793a\uff0c\u65b0\u751f\u4ee3\uff1a\u8be5\u5185\u5b58\u533a\u57dfGC\u524d\u5df2\u4f7f\u7528\u5bb9\u91cf -&gt; \u8be5\u5185\u5b58\u533a\u57dfGC\u540e\u5df2\u4f7f\u7528\u5bb9\u91cf\uff08\u8be5\u5185\u5b58\u533a\u57df\u603b\u5bb9\u91cf\uff09<\/p>\n<p>3. 11390K-&gt;5712K(19456K)\uff0c\u8868\u793a\uff0cGC\u524dJava\u5806\u5df2\u4f7f\u7528\u7684\u5bb9\u91cf -&gt; GC\u540eJava\u5806\u5df2\u4f7f\u7528\u7684\u5bb9\u91cf\uff08Java\u5806\u603b\u5bb9\u91cf\uff09<\/p>\n<p>4. 0.0011969 secs\uff0c\u8868\u793aGC\u6240\u5360\u7528\u7684\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\u3002<\/p>\n<p>5. [Times: user=0.00 sys=0.00, real=0.00 secs]\uff0c\u8868\u793aGC\u7684\u66f4\u5177\u4f53\u7684\u65f6\u95f4\uff0cuser\u4ee3\u8868\u7528\u6237\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\uff0csys\u4ee3\u8868\u5185\u6838\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\uff0creal\u4ee3\u8868\u64cd\u4f5c\u4ece\u5f00\u59cb\u5230\u7ed3\u675f\u6240\u7ecf\u8fc7\u7684\u5899\u949f\u65f6\u95f4\u3002CPU\u65f6\u95f4\u4e0e\u5899\u949f\u65f6\u95f4\u7684\u533a\u522b\u662f\uff0c\u5899\u949f\u65f6\u95f4\u5305\u62ec\u5404\u79cd\u975e\u8fd0\u7b97\u7684\u7b49\u5f85\u8017\u65f6\uff0c\u5982\u7b49\u5f85\u78c1\u76d8IO\uff0c\u7b49\u5f85\u7ebf\u7a0b\u963b\u585e\uff0cCPU\u65f6\u95f4\u5219\u4e0d\u5305\u542b\u8fd9\u4e9b\u8017\u65f6\u3002\u5f53\u7cfb\u7edf\u6709\u591aCPU\u6216\u8005\u591a\u6838\u65f6\uff0c\u591a\u7ebf\u7a0b\u64cd\u4f5c\u4f1a\u53e0\u52a0\u8fd9\u4e9bCPU\u65f6\u95f4\uff0c\u6240\u4ee5\u8bfb\u8005\u770b\u5230user\u6216\u8005sys\u65f6\u95f4\u8d85\u8fc7real\u65f6\u95f4\u4e5f\u662f\u5f88\u6b63\u5e38\u7684\u3002<\/p>\n<p><strong>\u5341\u3001\u5185\u5b58\u5206\u914d\u4e0e\u56de\u6536\u7b56\u7565<\/strong><\/p>\n<p>\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u8be6\u7ec6\u8ba8\u8bba\u4e86\u5185\u5b58\u56de\u6536\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u7a0b\u5e8f\u4e2d\u751f\u6210\u7684\u5bf9\u8c61\u662f\u5982\u4f55\u8fdb\u884c\u5206\u914d\u7684\u5462\uff1f\u5bf9\u8c61\u7684\u5185\u5b58\u5206\u914d\uff0c\u7edd\u5927\u90e8\u5206\u90fd\u662f\u5728\u5806\u4e0a\u5206\u914d\uff0c\u5c11\u6570\u7ecf\u8fc7JIT\u7f16\u8bd1\u540e\u88ab\u62c6\u6563\u4e3a\u6807\u91cf\u7c7b\u578b\u5e76\u95f4\u63a5\u5728\u6808\u4e0a\u5206\u914d\u3002\u5728\u5806\u4e0a\u7684\u5206\u914d\u53c8\u53ef\u4ee5\u6709\u5982\u4e0b\u5206\u914d\uff0c\u4e3b\u8981\u5728\u65b0\u751f\u4ee3\u7684Eden\u533a\u5206\u914d\uff0c\u5982\u679c\u542f\u52a8\u4e86\u672c\u5730\u7ebf\u7a0b\u5206\u914d\u7f13\u51b2\uff0c\u5c06\u6309\u7167\u7ebf\u7a0b\u4f18\u5148\u5728TLAB\u4e0a\u5206\u914d\uff0c\u5c11\u6570\u76f4\u63a5\u5728\u8001\u5e74\u4ee3\u5206\u914d\uff0c\u865a\u62df\u673a\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u53c2\u6570\u4f9b\u6211\u4eec\u6765\u63a7\u5236\u5bf9\u8c61\u5185\u5b58\u7a7a\u95f4\u7684\u5206\u914d\u3002<\/p>\n<p>\u5806\u7684\u7ed3\u6784\u56fe\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160227095128177-1924983781.png\" alt=\"\" \/><\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u5c06\u4ece\u5e94\u7528\u7a0b\u5e8f\u7684\u89d2\u5ea6\u7406\u89e3\u5bf9\u8c61\u7684\u5206\u914d\u3002<\/p>\n<p>10.1 \u5bf9\u8c61\u4f18\u5148\u5728Eden\u533a\u5206\u914d<\/p>\n<p>\u5bf9\u8c61\u901a\u5e38\u5728\u65b0\u751f\u4ee3\u7684Eden\u533a\u8fdb\u884c\u5206\u914d\uff0c\u5f53Eden\u533a\u6ca1\u6709\u8db3\u591f\u7a7a\u95f4\u8fdb\u884c\u5206\u914d\u65f6\uff0c\u865a\u62df\u673a\u5c06\u53d1\u8d77\u4e00\u6b21Minor GC\uff0c\u4e0eMinor GC\u5bf9\u5e94\u7684\u662fMajor GC\u3001Full GC\u3002<\/p>\n<p>Minor GC:\u6307\u53d1\u751f\u5728\u65b0\u751f\u4ee3\u7684\u5783\u573e\u6536\u96c6\u52a8\u4f5c\uff0c\u975e\u5e38\u9891\u7e41\uff0c\u901f\u5ea6\u8f83\u5feb\u3002<\/p>\n<p>Major GC:\u6307\u53d1\u751f\u5728\u8001\u5e74\u4ee3\u7684GC\uff0c\u51fa\u73b0Major GC\uff0c\u7ecf\u5e38\u4f1a\u4f34\u968f\u4e00\u6b21Minor GC\uff0c\u540c\u65f6Minor GC\u4e5f\u4f1a\u5f15\u8d77Major GC\uff0c\u4e00\u822c\u5728GC\u65e5\u5fd7\u4e2d\u7edf\u79f0\u4e3aGC\uff0c\u4e0d\u9891\u7e41\u3002<\/p>\n<p>Full GC:\u6307\u53d1\u751f\u5728\u8001\u5e74\u4ee3\u548c\u65b0\u751f\u4ee3\u7684GC\uff0c\u901f\u5ea6\u5f88\u6162\uff0c\u9700\u8981Stop The World\u3002<\/p>\n<p>\u5982\u4e0b\u4ee3\u7801\u7247\u6bb5\u5c55\u793a\u4e86GC\u7684\u8fc7\u7a0b<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_4317485e-3ee4-402b-b5f7-d7a613a4f9a9\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_4317485e-3ee4-402b-b5f7-d7a613a4f9a9\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class AllocationTest {\n    private static final int _1MB = 1024 * 1024;\n\n    \/*\n     *     -Xms20M -Xmx20M -Xmn10M\n        -XX:SurvivorRatio=8\n        -XX:+PrintGCDetails\n        -XX:+UseSerialGC\n     * *\/\n    public static void testAllocation() {\n        byte[] allocation1, allocation2, allocation3, allocation4;\n        allocation1 = new byte[2 * _1MB];\n        allocation2 = new byte[2 * _1MB];\n        allocation3 = new byte[2 * _1MB];\n        allocation4 = new byte[4 * _1MB];\n    }\n    public static void main(String[] args) {\n        testAllocation();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>[GC (Allocation Failure) [DefNew: 7130K-&gt;515K(9216K), 0.0048317 secs] 7130K-&gt;6659K(19456K), 0.0048809 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]<br \/>\nHeap<br \/>\ndef new generation\u00a0\u00a0\u00a0total 9216K, used 4694K\u00a0[0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\neden space 8192K,\u00a0 51% used [0x00000000fec00000, 0x00000000ff014930, 0x00000000ff400000)<br \/>\nfrom space 1024K,\u00a0 50% used [0x00000000ff500000, 0x00000000ff580fa0, 0x00000000ff600000)<br \/>\nto\u00a0\u00a0 space 1024K,\u00a0\u00a0 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)<br \/>\ntenured generation\u00a0\u00a0\u00a0total 10240K, used 6144K\u00a0[0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\nthe space 10240K,\u00a0 60% used [0x00000000ff600000, 0x00000000ffc00030, 0x00000000ffc00200, 0x0000000100000000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2568K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<\/p>\n<p>\u8bf4\u660e\uff1a\u65b0\u751f\u4ee3\u53ef\u7528\u7684\u7a7a\u95f4\u4e3a9M = 8M\uff08Eden\u5bb9\u91cf\uff09 + 1M\uff08\u4e00\u4e2asurvivor\u5bb9\u91cf\uff09\uff0c\u5206\u914d\u5b8callocation1\u3001allocation2\u3001allocation3\u4e4b\u540e\uff0c\u65e0\u6cd5\u518d\u5206\u914dallocation4\uff0c\u4f1a\u53d1\u751f\u5206\u914d\u5931\u8d25\uff0c\u5219\u9700\u8981\u8fdb\u884c\u4e00\u6b21Minor GC\uff0csurvivor to\u533a\u57df\u7684\u5bb9\u91cf\u4e3a1M\uff0c\u65e0\u6cd5\u5bb9\u7eb3\u603b\u91cf\u4e3a6M\u7684\u4e09\u4e2a\u5bf9\u8c61\uff0c\u5219\u4f1a\u901a\u8fc7\u62c5\u4fdd\u673a\u5236\u5c06allocation1\u3001allocation2\u3001allocation3\u8f6c\u79fb\u5230\u8001\u5e74\u4ee3\uff0c\u7136\u540e\u518d\u5c06allocation4\u5206\u914d\u5728Eden\u533a\u3002<\/p>\n<p>10.2 \u5927\u5bf9\u8c61\u76f4\u63a5\u8fdb\u5165\u8001\u5e74\u4ee3<\/p>\n<p>\u9700\u8981\u5927\u91cf\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\u7684Java\u5bf9\u8c61\u79f0\u4e3a\u5927\u5bf9\u8c61\uff0c\u5927\u5bf9\u8c61\u7684\u51fa\u73b0\u4f1a\u5bfc\u81f4\u63d0\u524d\u89e6\u53d1\u5783\u573e\u6536\u96c6\u4ee5\u83b7\u53d6\u66f4\u5927\u7684\u8fde\u7eed\u7684\u7a7a\u95f4\u6765\u8fdb\u884c\u5927\u5bf9\u8c61\u7684\u5206\u914d\u3002\u865a\u62df\u673a\u63d0\u4f9b\u4e86-XX:PretenureSizeThreadshold\u53c2\u6570\u6765\u8bbe\u7f6e\u5927\u5bf9\u8c61\u7684\u9608\u503c\uff0c\u8d85\u8fc7\u9608\u503c\u7684\u5bf9\u8c61\u76f4\u63a5\u5206\u914d\u5230\u8001\u5e74\u4ee3\u3002<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_018f02f4-b523-4968-beb2-f2ff988eac9c\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_018f02f4-b523-4968-beb2-f2ff988eac9c\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class AllocationTest {\n    private static final int _1MB = 1024 * 1024;\n\n    \/*\n     *     -Xms20M -Xmx20M -Xmn10M\n        -XX:SurvivorRatio=8\n        -XX:+PrintGCDetails\n        -XX:+UseSerialGC\n        -XX:PretenureSizeThreshold=3145728(3M)\n     * *\/\n\n    public static void testPretenureSizeThreshold() {\n        byte[] allocation4 = new byte[5 * _1MB];\n    }\n\n    public static void main(String[] args) {\n        testPretenureSizeThreshold();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>Heap<br \/>\ndef new generation\u00a0\u00a0 total 9216K, used 1314K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\neden space 8192K,\u00a0 16% used [0x00000000fec00000, 0x00000000fed489d0, 0x00000000ff400000)<br \/>\nfrom space 1024K,\u00a0\u00a0 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)<br \/>\nto\u00a0\u00a0 space 1024K,\u00a0\u00a0 0% used [0x00000000ff500000, 0x00000000ff500000, 0x00000000ff600000)<br \/>\ntenured generation\u00a0\u00a0\u00a0total 10240K, used 5120K\u00a0[0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\nthe space 10240K,\u00a0 50% used [0x00000000ff600000, 0x00000000ffb00010, 0x00000000ffb00200, 0x0000000100000000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2567K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<br \/>\n\u8bf4\u660e\uff1a\u53ef\u4ee5\u770b\u52305MB\u7684\u5bf9\u8c61\u76f4\u63a5\u5206\u914d\u5728\u4e86\u8001\u5e74\u4ee3\u3002<\/p>\n<p>10.3 \u957f\u671f\u5b58\u6d3b\u7684\u5bf9\u8c61\u8fdb\u5165\u8001\u5e74\u4ee3<\/p>\n<p>\u6bcf\u4e2a\u5bf9\u8c61\u6709\u4e00\u4e2a\u5bf9\u8c61\u5e74\u9f84\u8ba1\u6570\u5668\uff0c\u4e0e\u524d\u9762\u7684\u5bf9\u8c61\u7684\u5b58\u50a8\u5e03\u5c40\u4e2d\u7684GC\u5206\u4ee3\u5e74\u9f84\u5bf9\u5e94\u3002\u5bf9\u8c61\u51fa\u751f\u5728Eden\u533a\u3001\u7ecf\u8fc7\u4e00\u6b21Minor GC\u540e\u4ecd\u7136\u5b58\u6d3b\uff0c\u5e76\u80fd\u591f\u88abSurvivor\u5bb9\u7eb3\uff0c\u8bbe\u7f6e\u5e74\u9f84\u4e3a1\uff0c\u5bf9\u8c61\u5728Survivor\u533a\u6bcf\u6b21\u7ecf\u8fc7\u4e00\u6b21Minor GC\uff0c\u5e74\u9f84\u5c31\u52a01\uff0c\u5f53\u5e74\u9f84\u8fbe\u5230\u4e00\u5b9a\u7a0b\u5ea6\uff08\u9ed8\u8ba415\uff09\uff0c\u5c31\u664b\u5347\u5230\u8001\u5e74\u4ee3\uff0c\u865a\u62df\u673a\u63d0\u4f9b\u4e86-XX:MaxTenuringThreshold\u6765\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_7ab1708a-a652-41a9-9ad2-7029afb24ac8\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_7ab1708a-a652-41a9-9ad2-7029afb24ac8\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class AllocationTest {\n    private static final int _1MB = 1024 * 1024;\n\n    \/*\n     *     -Xms20M -Xmx20M -Xmn10M\n        -XX:SurvivorRatio=8\n        -XX:+PrintGCDetails\n        -XX:+UseSerialGC\n        -XX:MaxTenuringThreshold=1\n        -XX:+PrintTenuringDistribution\n     * *\/\n    public static void testTenuringThreshold() {\n        byte[] allocation1, allocation2, allocation3;\n        allocation1 = new byte[_1MB \/ 4];\n        allocation2 = new byte[4 * _1MB];\n        allocation3 = new byte[4 * _1MB];\n        allocation3 = null;\n        allocation3 = new byte[4 * _1MB];\n    }\n\n    public static void main(String[] args) {\n        testPretenureSizeThreshold();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 1 (max 1)<br \/>\n&#8211; age\u00a0\u00a0 1:\u00a0\u00a0\u00a0\u00a0 790400 bytes,\u00a0\u00a0\u00a0\u00a0 790400 total<br \/>\n: 5174K-&gt;771K(9216K), 0.0050541 secs] 5174K-&gt;4867K(19456K), 0.0051088 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]<br \/>\n[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 1 (max 1)<br \/>\n: 4867K-&gt;0K(9216K), 0.0015279 secs] 8963K-&gt;4867K(19456K), 0.0016327 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]<br \/>\nHeap<br \/>\ndef new generation\u00a0\u00a0\u00a0total 9216K, used 4260K\u00a0[0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\neden space 8192K,\u00a0 52% used [0x00000000fec00000, 0x00000000ff0290e0, 0x00000000ff400000)<br \/>\nfrom space 1024K,\u00a0\u00a0 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)<br \/>\nto\u00a0\u00a0 space 1024K,\u00a0\u00a0 0% used [0x00000000ff500000, 0x00000000ff500000, 0x00000000ff600000)<br \/>\ntenured generation\u00a0\u00a0\u00a0total 10240K, used 4867K\u00a0[0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\nthe space 10240K,\u00a0 47% used [0x00000000ff600000, 0x00000000ffac0d30, 0x00000000ffac0e00, 0x0000000100000000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2562K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<\/p>\n<p>\u8bf4\u660e\uff1a\u53d1\u751f\u4e86\u4e24\u6b21Minor GC\uff0c\u7b2c\u4e00\u6b21\u662f\u5728\u7ed9allocation3\u8fdb\u884c\u5206\u914d\u7684\u65f6\u5019\u4f1a\u51fa\u73b0\u4e00\u6b21Minor GC\uff0c\u6b64\u65f6survivor\u533a\u57df\u4e0d\u80fd\u5bb9\u7eb3allocation2\uff0c\u4f46\u662f\u53ef\u4ee5\u5bb9\u7eb3allocation1\uff0c\u6240\u4ee5allocation1\u5c06\u4f1a\u8fdb\u5165survivor\u533a\u57df\u5e76\u4e14\u5e74\u9f84\u4e3a1\uff0c\u8fbe\u5230\u4e86\u9608\u503c\uff0c\u5c06\u5728\u4e0b\u4e00\u6b21GC\u65f6\u664b\u5347\u5230\u8001\u5e74\u4ee3\uff0c\u800callocation2\u5219\u4f1a\u901a\u8fc7\u62c5\u4fdd\u673a\u5236\u8fdb\u5165\u8001\u5e74\u4ee3\u3002\u7b2c\u4e8c\u6b21\u53d1\u751fGC\u662f\u5728\u7b2c\u4e8c\u6b21\u7ed9allocation3\u5206\u914d\u7a7a\u95f4\u65f6\uff0c\u8fd9\u65f6\uff0callocation1\u7684\u5e74\u9f84\u52a01\uff0c\u664b\u5347\u5230\u8001\u5e74\u4ee3\uff0c\u6b64\u6b21GC\u4e5f\u53ef\u4ee5\u6e05\u7406\u51fa\u539f\u6765allocation3\u5360\u636e\u76844MB\u7a7a\u95f4\uff0c\u5c06allocation3\u5206\u914d\u5728Eden\u533a\u3002\u6240\u4ee5\uff0c\u6700\u540e\u7684\u7ed3\u679c\u662fallocation1\u3001allocation2\u5728\u8001\u5e74\u4ee3\uff0callocation3\u5728Eden\u533a\u3002<\/p>\n<p>10.4 \u52a8\u6001\u5bf9\u8c61\u5e74\u9f84\u5224\u65ad<\/p>\n<p>\u5bf9\u8c61\u7684\u5e74\u9f84\u5230\u8fbe\u4e86MaxTenuringThreshold\u53ef\u4ee5\u8fdb\u5165\u8001\u5e74\u4ee3\uff0c\u540c\u65f6\uff0c\u5982\u679c\u5728survivor\u533a\u4e2d\u76f8\u540c\u5e74\u9f84\u6240\u6709\u5bf9\u8c61\u5927\u5c0f\u7684\u603b\u548c\u5927\u4e8esurvivor\u533a\u7684\u4e00\u534a\uff0c\u5e74\u9f84\u5927\u4e8e\u7b49\u4e8e\u8be5\u5e74\u9f84\u7684\u5bf9\u8c61\u5c31\u53ef\u4ee5\u76f4\u63a5\u8fdb\u5165\u8001\u5e74\u4ee3\u3002\u65e0\u9700\u7b49\u5230MaxTenuringThreshold\u4e2d\u8981\u6c42\u7684\u5e74\u9f84\u3002<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_70094dbb-f60c-4400-8ffc-fb6f2ce5fb0a\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_70094dbb-f60c-4400-8ffc-fb6f2ce5fb0a\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class AllocationTest {\n    private static final int _1MB = 1024 * 1024;\n\n    \/*\n     *     -Xms20M -Xmx20M -Xmn10M\n        -XX:SurvivorRatio=8\n        -XX:+PrintGCDetails\n        -XX:+UseSerialGC\n        -XX:MaxTenuringThreshold=15\n        -XX:+PrintTenuringDistribution\n     * *\/\n\n    public static void testTenuringThreshold2() {\n        byte[] allocation1, allocation2, allocation3, allocation4;\n        allocation1 = new byte[_1MB \/ 4];\n        allocation2 = new byte[_1MB \/ 4];\n        allocation3 = new byte[4 * _1MB];\n        allocation4 = new byte[4 * _1MB];\n        allocation4 = null;\n        allocation4 = new byte[4 * _1MB];\n    }\n\n    public static void main(String[] args) {\n        testPretenureSizeThreshold2();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 1 (max 15)<br \/>\n&#8211; age\u00a0\u00a0 1:\u00a0\u00a0\u00a0 1048576 bytes,\u00a0\u00a0\u00a0 1048576 total<br \/>\n: 5758K-&gt;1024K(9216K), 0.0049451 secs] 5758K-&gt;5123K(19456K), 0.0049968 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]<br \/>\n[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 15 (max 15)<br \/>\n: 5120K-&gt;0K(9216K), 0.0016442 secs] 9219K-&gt;5123K(19456K), 0.0016746 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]<br \/>\nHeap<br \/>\ndef new generation\u00a0\u00a0\u00a0total 9216K, used 4178K\u00a0[0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\neden space 8192K,\u00a0 51% used [0x00000000fec00000, 0x00000000ff014930, 0x00000000ff400000)<br \/>\nfrom space 1024K,\u00a0\u00a0 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)<br \/>\nto\u00a0\u00a0 space 1024K,\u00a0\u00a0 0% used [0x00000000ff500000, 0x00000000ff500000, 0x00000000ff600000)<br \/>\ntenured generation\u00a0\u00a0\u00a0total 10240K, used 5123K\u00a0[0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\nthe space 10240K,\u00a0 50% used [0x00000000ff600000, 0x00000000ffb00f80, 0x00000000ffb01000, 0x0000000100000000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2568K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<\/p>\n<p>\u7ed3\u679c\u8bf4\u660e\uff1a\u53d1\u751f\u4e86\u4e24\u6b21Minor GC\uff0c\u7b2c\u4e00\u6b21\u53d1\u751f\u5728\u7ed9allocation4\u5206\u914d\u5185\u5b58\u65f6\uff0c\u6b64\u65f6allocation1\u3001allocation2\u5c06\u4f1a\u8fdb\u5165survivor\u533a\uff0c\u800callocation3\u901a\u8fc7\u62c5\u4fdd\u673a\u5236\u5c06\u4f1a\u8fdb\u5165\u8001\u5e74\u4ee3\u3002\u7b2c\u4e8c\u6b21\u53d1\u751f\u5728\u7ed9allocation4\u5206\u914d\u5185\u5b58\u65f6\uff0c\u6b64\u65f6\uff0csurvivor\u533a\u7684allocation1\u3001allocation2\u8fbe\u5230\u4e86survivor\u533a\u5bb9\u91cf\u7684\u4e00\u534a\uff0c\u5c06\u4f1a\u8fdb\u5165\u8001\u5e74\u4ee3\uff0c\u6b64\u6b21GC\u53ef\u4ee5\u6e05\u7406\u51faallocation4\u539f\u6765\u76844MB\u7a7a\u95f4\uff0c\u5e76\u5c06allocation4\u5206\u914d\u5728Eden\u533a\u3002\u6700\u7ec8\uff0callocation1\u3001allocation2\u3001allocation3\u5728\u8001\u5e74\u4ee3\uff0callocation4\u5728Eden\u533a\u3002<\/p>\n<p>10.5 \u7a7a\u95f4\u5206\u914d\u62c5\u4fdd<\/p>\n<p>\u5728\u53d1\u751fMinor GC\u65f6\uff0c\u865a\u62df\u673a\u4f1a\u68c0\u67e5\u8001\u5e74\u4ee3\u8fde\u7eed\u7684\u7a7a\u95f2\u533a\u57df\u662f\u5426\u5927\u4e8e\u65b0\u751f\u4ee3\u6240\u6709\u5bf9\u8c61\u7684\u603b\u548c\uff0c\u82e5\u6210\u7acb\uff0c\u5219\u8bf4\u660eMinor GC\u662f\u5b89\u5168\u7684\uff0c\u5426\u5219\uff0c\u865a\u62df\u673a\u9700\u8981\u67e5\u770bHandlePromotionFailure\u7684\u503c\uff0c\u770b\u662f\u5426\u8fd0\u884c\u62c5\u4fdd\u5931\u8d25\uff0c\u82e5\u5141\u8bb8\uff0c\u5219\u865a\u62df\u673a\u7ee7\u7eed\u68c0\u67e5\u8001\u5e74\u4ee3\u6700\u5927\u53ef\u7528\u7684\u8fde\u7eed\u7a7a\u95f4\u662f\u5426\u5927\u4e8e\u5386\u6b21\u664b\u5347\u5230\u8001\u5e74\u4ee3\u5bf9\u8c61\u7684\u5e73\u5747\u5927\u5c0f\uff0c\u82e5\u5927\u4e8e\uff0c\u5c06\u5c1d\u8bd5\u8fdb\u884c\u4e00\u6b21Minor GC\uff1b\u82e5\u5c0f\u4e8e\u6216\u8005HandlePromotionFailure\u8bbe\u7f6e\u4e0d\u8fd0\u884c\u5192\u9669\uff0c\u90a3\u4e48\u6b64\u65f6\u5c06\u6539\u6210\u4e00\u6b21Full GC\uff0c\u4ee5\u4e0a\u662fJDK Update 24\u4e4b\u524d\u7684\u7b56\u7565\uff0c\u4e4b\u540e\u7684\u7b56\u7565\u6539\u53d8\u4e86\uff0c\u53ea\u8981\u8001\u5e74\u4ee3\u7684\u8fde\u7eed\u7a7a\u95f4\u5927\u4e8e\u65b0\u751f\u4ee3\u5bf9\u8c61\u603b\u5927\u5c0f\u6216\u8005\u5386\u6b21\u664b\u5347\u7684\u5e73\u5747\u5927\u5c0f\u5c31\u4f1a\u8fdb\u884cMinor GC\uff0c\u5426\u5219\u5c06\u8fdb\u884cFull GC\u3002<\/p>\n<p>\u5192\u9669\u662f\u6307\u7ecf\u8fc7\u4e00\u6b21Minor GC\u540e\u6709\u5927\u91cf\u5bf9\u8c61\u5b58\u6d3b\uff0c\u800c\u65b0\u751f\u4ee3\u7684survivor\u533a\u5f88\u5c0f\uff0c\u653e\u4e0d\u4e0b\u8fd9\u4e9b\u5927\u91cf\u5b58\u6d3b\u7684\u5bf9\u8c61\uff0c\u6240\u4ee5\u9700\u8981\u8001\u5e74\u4ee3\u8fdb\u884c\u5206\u914d\u62c5\u4fdd\uff0c\u628asurvivor\u533a\u65e0\u6cd5\u5bb9\u7eb3\u7684\u5bf9\u8c61\u76f4\u63a5\u8fdb\u5165\u8001\u5e74\u4ee3\u3002<\/p>\n<p>\u5177\u4f53\u7684\u6d41\u7a0b\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160227153608224-147105980.png\" alt=\"\" \/>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/616953\/201602\/616953-20160227153622724-1632196482.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\"><img decoding=\"async\" id=\"code_img_opened_e1c7df52-a408-44f0-8a59-c2ed43e01f59\" class=\"code_img_opened\" src=\"https:\/\/images.cnblogs.com\/OutliningIndicators\/ExpandedBlockStart.gif\" alt=\"\" \/><\/p>\n<div id=\"cnblogs_code_open_e1c7df52-a408-44f0-8a59-c2ed43e01f59\" class=\"cnblogs_code_hide\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public class AllocationTest {\n    private static final int _1MB = 1024 * 1024;\n\n    \/*\n     *     -Xms20M -Xmx20M -Xmn10M\n        -XX:SurvivorRatio=8\n        -XX:+PrintGCDetails\n        -XX:+UseSerialGC\n        -XX:+HandlePromotionFailure\n     * *\/\n\n    public static void testHandlePromotion() {\n        byte[] allocation1, allocation2, allocation3, allocation4, allocation5, allocation6, allocation7,\n        allocation8;\n        allocation1 = new byte[2 * _1MB];\n        allocation2 = new byte[2 * _1MB];\n        allocation3 = new byte[2 * _1MB];\n        allocation1 = null;\n        allocation4 = new byte[2 * _1MB];\n        allocation5 = new byte[2 * _1MB];\n        allocation6 = new byte[2 * _1MB];\n        allocation4 = null;\n        allocation5 = null;\n        allocation6 = null;\n        allocation7 = new byte[2 * _1MB];\n    }\n\n    public static void main(String[] args) {\n        testHandlePromotion();\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 1 (max 15)<br \/>\n&#8211; age\u00a0\u00a0 1:\u00a0\u00a0\u00a0\u00a0 528280 bytes,\u00a0\u00a0\u00a0\u00a0 528280 total<br \/>\n: 7294K-&gt;515K(9216K), 0.0040766 secs] 7294K-&gt;4611K(19456K), 0.0041309 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]<br \/>\n[GC (Allocation Failure) [DefNew<br \/>\nDesired survivor size 524288 bytes, new threshold 15 (max 15)<br \/>\n: 6818K-&gt;0K(9216K), 0.0012444 secs] 10914K-&gt;4611K(19456K), 0.0012760 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]<br \/>\nHeap<br \/>\ndef new generation\u00a0\u00a0\u00a0total 9216K, used 2130K\u00a0[0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)<br \/>\neden space 8192K,\u00a0 26% used [0x00000000fec00000, 0x00000000fee14930, 0x00000000ff400000)<br \/>\nfrom space 1024K,\u00a0\u00a0 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)<br \/>\nto\u00a0\u00a0 space 1024K,\u00a0\u00a0 0% used [0x00000000ff500000, 0x00000000ff500000, 0x00000000ff600000)<br \/>\ntenured generation\u00a0\u00a0\u00a0total 10240K, used 4611K\u00a0[0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)<br \/>\nthe space 10240K,\u00a0 45% used [0x00000000ff600000, 0x00000000ffa80d58, 0x00000000ffa80e00, 0x0000000100000000)<br \/>\nMetaspace\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used 2568K, capacity 4486K, committed 4864K, reserved 1056768K<br \/>\nclass space\u00a0\u00a0\u00a0 used 275K, capacity 386K, committed 512K, reserved 1048576K<\/p>\n<p>\u8bf4\u660e\uff1a\u53d1\u751f\u4e86\u4e24\u6b21GC\uff0c\u7b2c\u4e00\u6b21\u53d1\u751f\u5728\u7ed9allocation4\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u65f6\uff0c\u7531\u4e8e\u8001\u5e74\u4ee3\u7684\u8fde\u7eed\u53ef\u7528\u7a7a\u95f4\u5927\u4e8e\u5b58\u6d3b\u7684\u5bf9\u8c61\u603b\u548c\uff0c\u6240\u4ee5allocation2\u3001allocation3\u5c06\u4f1a\u8fdb\u5165\u8001\u5e74\u4ee3\uff0callocation1\u7684\u7a7a\u95f4\u5c06\u88ab\u56de\u6536\uff0callocation4\u5206\u914d\u5728\u65b0\u751f\u4ee3\uff1b\u7b2c\u4e8c\u6b21\u53d1\u751f\u5728\u7ed9allocation7\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u65f6\uff0c\u6b64\u6b21GC\u5c06allocation4\u3001allocation5\u3001allocation6\u6240\u5360\u7684\u5185\u5b58\u5168\u90e8\u56de\u6536\u3002\u6700\u540e\uff0callocation2\u3001allocation3\u5728\u8001\u5e74\u4ee3\uff0callocation7\u5728\u65b0\u751f\u4ee3\u3002<\/p>\n<p><strong>\u5341\u4e00\u3001\u603b\u7ed3<\/strong><\/p>\n<p>\u81f3\u6b64\uff0cJVM\u5783\u573e\u6536\u96c6\u90e8\u5206\u5c31\u5df2\u7ecf\u4ecb\u7ecd\u5b8c\u4e86\uff0c\u770b\u5b8c\u8fd9\u90e8\u5206\u6211\u4eec\u5e94\u8be5\u77e5\u9053JVM\u662f\u600e\u6837\u8fdb\u884c\u5783\u573e\u56de\u6536\u7684\uff0c\u5e76\u4e14\u5bf9JVM\u7684\u7406\u89e3\u66f4\u52a0\u52a0\u6df1\u3002<\/p>\n<p>\u82b1\u4e86\u5f88\u957f\u65f6\u95f4\uff0c\u7ec8\u4e8e\u5199\u5b8c\u4e86\u8fd9\u4e00\u90e8\u5206\uff0c\u8fd8\u662f\u6536\u83b7\u5f88\u591a\uff0c\u5728\u770b\u7684\u540c\u65f6\u4e0d\u65ad\u8bb0\u5f55\uff0c\u66f4\u8fdb\u4e00\u6b65\u52a0\u6df1\u4e86\u5370\u8c61\uff0c\u611f\u89c9\u8fd8\u4e0d\u9519\uff0c\u8c22\u8c22\u5404\u4f4d\u56ed\u53cb\u7684\u89c2\u770b~<\/p>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\u94fe\u63a5\uff1a<a href=\"http:\/\/www.open-open.com\/lib\/view\/open1429883238291.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.open-open.com\/lib\/view\/open1429883238291.html<\/a><\/p>\n<p>\u53c2\u8003\u6587\u732e\uff1a\u6df1\u5165Java\u865a\u62df\uff08\u539f\u4e66\u7b2c2\u7248\uff09\u3001\u6df1\u5165\u7406\u89e3Java\u865a\u62df\u673a-JVM\u9ad8\u7ea7\u7279\u6027\u4e0e\u6700\u4f73\u5b9e\u8df5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u5783\u573e\u56de\u6536 \u5982\u679c\u4e0d\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5185\u5b58\u8fdf\u65e9\u90fd\u4f1a\u88ab\u6d88\u8017\u7a7a\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u4e0d\u65ad\u7684\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u800c\u4e0d\u8fdb\u884c\u56de\u6536\u3002\u9664\u975e\u5185\u5b58\u65e0\u9650\u5927\uff0c\u6211\u4eec\u53ef\u4ee5\u4efb\u6027\u7684\u5206\u914d\u800c\u4e0d\u56de\u6536\uff0c\u4f46\u662f\u4e8b\u5b9e\u5e76\u975e\u5982\u6b64\u3002\u6240\u4ee5\uff0c\u5783\u573e\u56de\u6536\u662f\u5fc5\u987b\u7684\u3002 \u4e8c\u3001\u54ea\u4e9b\u5185\u5b58\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536 \u5bf9\u4e8e\u865a\u62df\u673a\u4e2d\u7ebf\u7a0b\u79c1\u6709\u7684\u533a\u57df\uff0c\u5982\u7a0b\u5e8f\u8ba1\u6570\u5668\u3001\u865a\u62df\u673a\u6808\u3001\u672c\u5730\u65b9\u6cd5\u6808\u90fd\u4e0d\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u81ea\u52a8\u8fdb\u884c\u7684\uff0c\u968f\u7740\u7ebf\u7a0b\u7684\u6d88\u4ea1\u800c\u6d88\u4ea1\uff0c\u4e0d\u9700\u8981\u6211\u4eec\u53bb\u56de\u6536\uff0c\u6bd4\u5982\u6808\u7684\u6808\u5e27\u7ed3\u6784\uff0c\u5f53\u8fdb\u5165\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u6808\u5e27\uff0c\u6808\u5e27\u5927\u5c0f\u4e5f\u53ef\u4ee5\u501f\u52a9\u7c7b\u4fe1\u606f\u786e\u5b9a\uff0c\u7136\u540e\u6808\u5e27\u5165\u6808\uff0c\u6267\u884c\u65b9\u6cd5\u4f53\uff0c\u9000\u51fa\u65b9\u6cd5\u65f6\uff0c\u6808\u5e27\u51fa\u6808\uff0c\u4e8e\u662f\u5176\u6240\u5360\u636e\u7684\u5185\u5b58\u7a7a\u95f4\u4e5f\u5c31\u88ab\u81ea\u52a8\u56de\u6536\u4e86\u3002\u800c\u5bf9\u4e8e\u865a\u62df\u673a\u4e2d\u7ebf\u7a0b\u5171\u4eab\u7684\u533a\u57df\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5982\u5806\u548c\u65b9\u6cd5\u533a\uff0c\u7ebf\u7a0b\u90fd\u4f1a\u5728\u8fd9\u4e24\u4e2a\u533a\u57df\u4ea7\u751f\u81ea\u8eab\u7684\u6570\u636e\uff0c\u5360\u636e\u4e00\u5b9a\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u5e76\u4e14\u8fd9\u4e9b\u6570\u636e\u53c8\u53ef\u80fd\u4f1a\u5b58\u5728\u76f8\u4e92\u5173\u8054\u7684\u5173\u7cfb\uff0c\u6240\u4ee5\uff0c\u8fd9\u90e8\u5206\u7684\u533a\u57df\u4e0d\u50cf\u7ebf\u7a0b\u79c1\u6709\u7684\u533a\u57df\u90a3\u6837\u53ef\u4ee5\u7b80\u5355\u81ea\u52a8\u7684\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u6b64\u90e8\u5206\u533a\u57df\u7684\u5783\u573e\u56de\u6536\u975e\u5e38\u590d\u6742\uff0c\u800c\u5783\u573e\u56de\u6536\u4e5f\u4e3b\u8981\u662f\u9488\u5bf9\u8fd9\u90e8\u5206\u533a\u57df\u3002 \u4e09\u3001\u5783\u573e\u6536\u96c6\u7b97\u6cd5 \u4efb\u4f55\u5783\u573e\u6536\u96c6\u7b97\u6cd5\u90fd\u5fc5\u987b\u505a\u4e24\u4ef6\u4e8b\u60c5\u3002\u9996\u5148\uff0c\u5b83\u5fc5\u987b\u68c0\u6d4b\u51fa\u5783\u573e\u5bf9\u8c61\u3002\u5176\u6b21\uff0c\u5b83\u5fc5\u987b\u56de\u6536\u5783\u573e\u5bf9\u8c61\u6240\u4f7f\u7528\u7684\u5806\u7a7a\u95f4\u5e76\u8fd8\u7ed9\u7a0b\u5e8f\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5982\u4f55\u68c0\u6d4b\u51fa\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u5783\u573e\u5bf9\u8c61\u5462\uff1f\u4e00\u822c\u6709\u4e24\u79cd\u7b97\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u30021. \u5f15\u7528\u8ba1\u6570\u7b97\u6cd5 2. \u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5\u3002 1.\u5f15\u7528\u8ba1\u6570\u7b97\u6cd5 \u5806\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u6709\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u88ab\u521b\u5efa\uff0c\u5e76\u628a\u6307\u5411\u8be5\u5bf9\u8c61\u7684\u5f15\u7528\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u65f6\uff0c\u5f15\u7528\u8ba1\u6570\u7f6e\u4e3a1\uff0c\u5f53\u518d\u628a\u8fd9\u4e2a\u5f15\u7528\u8d4b\u503c\u7ed9\u5176\u4ed6\u53d8\u91cf\u65f6\uff0c\u5f15\u7528\u8ba1\u6570\u52a01\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u8d85\u8fc7\u4e86\u751f\u547d\u5468\u671f\u6216\u8005\u88ab\u8bbe\u7f6e\u4e3a\u65b0\u503c\u65f6\uff0c\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u51cf1\uff0c\u4efb\u4f55\u5f15\u7528\u8ba1\u6570\u4e3a0\u7684\u5bf9\u8c61\u90fd\u53ef\u4ee5\u88ab\u5f53\u6210\u5783\u573e\u56de\u6536\u3002\u5f53\u4e00\u4e2a\u5bf9\u8c61\u88ab\u56de\u6536\u65f6\uff0c\u5b83\u6240\u5f15\u7528\u7684\u4efb\u4f55\u5bf9\u8c61\u8ba1\u6570\u51cf1\uff0c\u8fd9\u6837\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5176\u4ed6\u5bf9\u8c61\u4e5f\u88ab\u5f53\u5783\u573e\u56de\u6536\u3002 \u95ee\u9898\uff1a\u5f88\u96be\u68c0\u6d4b\u51fa\u5bf9\u8c61\u4e4b\u95f4\u7684\u989d\u76f8\u4e92\u5f15\u7528\uff08\u5f15\u7528\u5faa\u73af\u95ee\u9898\uff09 \u5982\u4e0b\u4ee3\u7801\u6bb5\u53ef\u4ee5\u4ece\u53cd\u9762\u9a8c\u8bc1\u865a\u62df\u673a\u7684\u5783\u573e\u56de\u6536\u4e0d\u662f\u91c7\u7528\u7684\u5f15\u7528\u8ba1\u6570\u3002 package com.leesf.chapter3; public class ReferenceCountingGC { public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-857","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=857"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/857\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}