{"id":167,"date":"2024-12-11T17:07:26","date_gmt":"2024-12-11T17:07:26","guid":{"rendered":"https:\/\/www.isvmspace.com\/?p=167"},"modified":"2024-12-11T17:07:26","modified_gmt":"2024-12-11T17:07:26","slug":"jvm%e7%b3%bb%e5%88%97-%e5%9e%83%e5%9c%be%e6%94%b6%e9%9b%86%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.isvmspace.com\/?p=167","title":{"rendered":"JVM\u7cfb\u5217-\u5783\u573e\u6536\u96c6\u7b97\u6cd5"},"content":{"rendered":"<h1>\u5783\u573e\u6536\u96c6\uff08GC\uff09<\/h1>\n<p>Garbage Collection\u9700\u8981\u5b8c\u6210\u7684\u4e8b\u60c5\uff1a<br \/>\n1.\u54ea\u4e9b\u5185\u5b58\u9700\u8981\u56de\u6536\uff1f<br \/>\n2.\u4ec0\u4e48\u65f6\u5019\u56de\u6536\uff1f<br \/>\n3.\u5982\u4f55\u56de\u6536\uff1f<\/p>\n<h1>\u5982\u4f55\u5224\u65ad\u5bf9\u8c61\u53ef\u4ee5\u56de\u6536<\/h1>\n<h2>1.\u5f15\u7528\u8ba1\u6570\u7b97\u6cd5\uff08Reference Counting\uff09\uff1a<\/h2>\n<p>\u7ed9\u5bf9\u8c61\u6dfb\u52a0\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570\u5668\uff0c\u6bcf\u5f53\u6709\u4e00\u4e2a\u5730\u65b9\u5f15\u7528\u5b83\u65f6\uff0c\u8ba1\u6570\u5668\u5c31+1\uff0c\u5f53\u5f15\u7528\u5931\u6548\u65f6\uff0c\u8ba1\u6570\u5668-1\u3002\u5f53\u8ba1\u6570\u5668\u4e3a0\u65f6\u8868\u793a\u8be5\u5bf9\u8c61\u4e0d\u518d\u88ab\u5f15\u7528\u3002<br \/>\n<strong>\u4f18\u70b9\uff1a<\/strong>\u5b9e\u73b0\u7b80\u5355\u3001\u5224\u65ad\u6548\u7387\u9ad8<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>\u5f88\u96be\u89e3\u51b3\u5bf9\u8c61\u4e4b\u95f4\u5faa\u73af\u5f15\u7528\u7684\u95ee\u9898<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u5f15\u7528\u8ba1\u6570\u7b97\u6cd5.png\" alt=\"\" \/><\/p>\n<h2>2.\u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5\uff08Reachability Analysis\uff09\uff1a<\/h2>\n<p>\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u79f0\u4e3a\u201cGC Roots\u201d\u7684\u5bf9\u8c61\u4f5c\u4e3a\u8d77\u59cb\u70b9\uff0c\u4ece\u8fd9\u4e9b\u8282\u70b9\u5f00\u59cb\u5411\u4e0b\u641c\u7d22\uff0c\u641c\u7d22\u6240\u8d70\u8fc7\u7684\u8def\u5f84\u79f0\u4e3a\u5f15\u7528\u94fe(Reference Chain)\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u5230GC Roots\u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u5f15\u7528\u94fe\u65f6\uff0c\u5219\u8bf4\u660e\u8be5\u5bf9\u8c61\u662f\u4e0d\u53ef\u7528\u7684\u3002<\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong>\u66f4\u52a0\u7cbe\u786e\u548c\u4e25\u8c28\uff0c\u53ef\u4ee5\u5206\u6790\u51fa\u5faa\u73af\u6570\u636e\u7ed3\u6784\u76f8\u4e92\u5f15\u7528\u7684\u60c5\u51b5<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>\u5b9e\u73b0\u6bd4\u8f83\u590d\u6742\u3001\u9700\u8981\u5206\u6790\u5927\u91cf\u6570\u636e\uff0c\u6d88\u8017\u5927\u91cf\u65f6\u95f4\u3001\u5206\u6790\u8fc7\u7a0b\u9700\u8981GC\u505c\u987f<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u53ef\u8fbe\u6027\u5206\u6790\u7b97\u6cd5.png\" alt=\"\" \/><\/p>\n<p>Java\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f5c\u4e3aGC Roots\u7684\u5bf9\u8c61\u5305\u62ec\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n<ul>\n<li>\u865a\u62df\u673a\u6808\uff08\u6808\u5e27\u4e2d\u7684\u672c\u5730\u53d8\u91cf\u8868\uff09\u4e2d\u5f15\u7528\u7684\u5bf9\u8c61<\/li>\n<li>\u65b9\u6cd5\u533a\u4e2d\u7c7b\u9759\u6001\u5c5e\u6027\u5f15\u7528\u7684\u5bf9\u8c61<\/li>\n<li>\u65b9\u6cd5\u533a\u4e2d\u5e38\u91cf\u5f15\u7528\u7684\u5bf9\u8c61<\/li>\n<li>\u672c\u5730\u65b9\u6cd5\u6808\u4e2dJNI(\u5373\u4e00\u822c\u8bf4\u7684Native\u65b9\u6cd5)\u5e94\u7528\u7684\u5bf9\u8c61<\/li>\n<\/ul>\n<h1>\u5783\u573e\u6536\u96c6\u7b97\u6cd5<\/h1>\n<h3>\u6807\u8bb0-\u6e05\u9664\u7b97\u6cd5\uff08Mark-Sweep\uff09<\/h3>\n<p><strong>\u4f18\u70b9\uff1a<\/strong>\u662f\u6700\u57fa\u7840\u7684\u6536\u96c6\u7b97\u6cd5<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>\u6548\u7387\u4e0d\u9ad8\uff0c\u4ea7\u751f\u5185\u5b58\u788e\u7247<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u6807\u8bb0\u6e05\u9664\u7b97\u6cd5.png\" alt=\"\" \/><\/p>\n<h3>\u590d\u5236\u7b97\u6cd5\uff08Copying\uff09<\/h3>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><br \/>\n\u5b9e\u73b0\u7b80\u5355\uff0c\u6548\u7387\u9ad8\u3002\u89e3\u51b3\u4e86\u6807\u8bb0-\u6e05\u9664\u7b97\u6cd5\u5bfc\u81f4\u7684\u5185\u5b58\u788e\u7247\u95ee\u9898<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong><br \/>\n\u4ee3\u4ef7\u592a\u5927\uff0c\u5c06\u5185\u5b58\u7f29\u5c0f\u4e86\u4e00\u534a<\/p>\n<p>\u5546\u4e1a\u865a\u62df\u673a\u91c7\u7528\u8fd9\u949f\u7b97\u6cd5\u56de\u6536\u65b0\u751f\u4ee3\u3002<br \/>\nHotSpot\u865a\u62df\u673a\u9ed8\u8ba4\u6bd4\u4f8b\uff1a<br \/>\nEden:From:To = 8:1:1<br \/>\n\u5f53Survivor\u7a7a\u95f4\u4e0d\u8db3\u65f6\u4f9d\u8d56\u5176\u4ed6\u5185\u5b58\u8fdb\u884c\u5206\u914d\u62c5\u4fdd(Handler Promotion)<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u590d\u5236\u7b97\u6cd5.png\" alt=\"\" \/><\/p>\n<h3>\u6807\u8bb0-\u6574\u7406\u7b97\u6cd5\uff08Mark-Compact\uff09<\/h3>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><br \/>\n\u4e0d\u4f1a\u4ea7\u751f\u5185\u5b58\u788e\u7247<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong><br \/>\n\u6548\u7387\u66f4\u4f4e<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u6807\u8bb0\u6574\u7406.png\" alt=\"\" \/><\/p>\n<h3>\u5206\u4ee3\u6536\u96c6\u7b97\u6cd5\uff08Generational Collection\uff09<\/h3>\n<p>\u5bf9\u8c61\u9996\u5148\u5206\u914d\u5728Eden\u533a<br \/>\n\u65b0\u751f\u4ee3\u7a7a\u95f4\u4e0d\u8db3\u65f6\uff0c\u89e6\u53d1Minor GC\uff08\u8be5GC\u4f1a\u89e6\u53d1Stop-The-World\uff09\uff0c\u4f0a\u7538\u56ed\u548c\u5e78\u5b58\u533aFrom\u5b58\u6d3b\u7684\u5bf9\u8c61\u590d\u5236\u5230To\u533a\uff0c\u5b58\u6d3b\u7684\u5bf9\u8c61\u5e74\u9f84+1\uff0c\u5e76\u4e14\u4ea4\u6362From\u548cTo\u7684\u4f4d\u7f6e\uff0c\u5f53\u5e74\u9f84\u8fbe\u5230\u4e00\u5b9a\u7a0b\u5ea6\u65f6\uff0c\u5219\u664b\u5347\u81f3\u8001\u5e74\u4ee3<br \/>\n\u5f53\u8001\u5e74\u4ee3\u7a7a\u95f4\u4e0d\u8db3\u65f6\uff0c\u4f1a\u5148\u89e6\u53d1Minor GC\uff0c\u5982\u679c\u7a7a\u95f4\u4f9d\u65e7\u4e0d\u8db3\uff0c\u5219\u89e6\u53d1Full GC\uff0c Stop-The-World\u65f6\u95f4\u66f4\u957f<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.isvmspace.com\/wp-content\/uploads\/2023\/02\/\u5206\u4ee3\u6536\u96c6\u7b97\u6cd5.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5783\u573e\u6536\u96c6\uff08GC\uff09 Garbage Collection\u9700\u8981\u5b8c\u6210\u7684\u4e8b\u60c5\uff1a 1.\u54ea\u4e9b\u5185\u5b58\u9700\u8981\u56de\u6536\uff1f 2.\u4ec0\u4e48\u65f6\u5019\u56de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":2,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.isvmspace.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}