{"id":4076,"date":"2019-04-02T18:17:17","date_gmt":"2019-04-02T10:17:17","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4076"},"modified":"2019-04-02T18:17:17","modified_gmt":"2019-04-02T10:17:17","slug":"%e4%b8%80%e4%b8%aa-system-gc-%e5%b0%b1%e8%83%bd%e8%ae%a9%e4%bd%a0%e5%9c%a8%e9%9d%a2%e8%af%95%e4%b8%ad%e8%a2%ab%e6%89%93%e5%87%bb%e5%88%b0%e6%80%80%e7%96%91%e4%ba%ba%e7%94%9f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4076","title":{"rendered":"\u4e00\u4e2a System.gc \u5c31\u80fd\u8ba9\u4f60\u5728\u9762\u8bd5\u4e2d\u88ab\u6253\u51fb\u5230\u6000\u7591\u4eba\u751f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4eba\u7684\u4e00\u751f\u4e2d\u53ef\u80fd\u4f1a\u906d\u9047\u5230\u65e0\u6570\u6b21\u6253\u51fb\u3002\u800c\u4eca\u5929\u6211\u5c31\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e2a\u4f60\u53ef\u80fd\u5ffd\u7565\u7684\u77e5\u8bc6\u70b9\uff1aSystem.gc\uff0c\u7ed9\u4f60\u4e13\u95e8\u6765\u4e00\u6b21\u964d\u7ef4\u6253\u51fb\u3002\u964d\u4f4e\u5230\u67d0\u4e2a\u7ec6\u5fae\u7684\u77e5\u8bc6\u70b9\uff0c\u8ba9\u4f60\u88ab\u6253\u51fb\u7684\u4f53\u65e0\u5b8c\u80a4\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g1ogfyuxgbj209v09ejs3.jpg\" alt=\"\" \/><figcaption>\u9762\u8bd5\u88ab\u6253\u51fb<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u4e00\uff1a\u5728 Java \u4e2d\uff0c\u5982\u4f55\u624b\u52a8\u7684\u8ba9 GC \u8fdb\u884c\u5783\u573e\u56de\u6536\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u65b9\u6cd5\u5176\u5b9e\u6709\u5f88\u591a\u79cd\u3002\u5e38\u89c1\u9a9a\u64cd\u4f5c\u6709 System.gc()\uff0c\u901a\u8fc7 jmap \u6765\u89e6\u53d1\uff0c\u6216\u8005\u901a\u8fc7 jvmti \u505a\u5f3a\u5236 GC \u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u4e8c\uff1aSystem.gc \u662f Full Gc \u5417\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">System.gc \u5176\u5b9e\u662f\u505a\u4e00\u6b21 full gc\u3002\u8fd9\u4e00\u70b9\u53ef\u4ee5\u6839\u636e DisableExplicitGC \u7684\u6ce8\u91ca\u8bf4\u660e\u6765\u770b\u3002Tells whether calling System.gc() does a full GC\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u4e09\uff1aSystem.gc \u7684\u5371\u5bb3\u662f\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a System.gc \u662f\u4e00\u4e2a Full gc\uff0c\u6240\u4ee5\u4f1a\u6682\u505c\u6574\u4e2a\u8fdb\u7a0b\u3002\u5982\u679c\u8fdb\u7a0b\u7ecf\u5e38\u88ab\u9891\u7e41\u6682\u505c\uff0c\u5c31\u8981\u6ce8\u610f\u8d85\u65f6\u3001\u5e76\u53d1\u7b49\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u56db\uff1a\u5982\u4f55\u907f\u514d System.gc \uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7 -XX:+DisableExplicitGC \u7981\u6389 System.gc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u4e94\uff1aSystem.gc \u7684 Full Gc \u5982\u4f55\u505a\u5230\u6682\u505c\u6574\u4e2a\u8fdb\u7a0b\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u91cc\u9762\u7684 GC \u6709\u4e00\u4e2a\u91cd\u8981\u7684\u7ebf\u7a0b VMThread\u3002\u5728 jvm \u91cc\uff0c\u8fd9\u4e2a\u7ebf\u7a0b\u4f1a\u4e0d\u65ad\u8f6e\u8be2\u5b83\u7684\u961f\u5217\uff0c\u8fd9\u4e2a\u961f\u5217\u91cc\u4e3b\u8981\u662f\u5b58\u4e00\u4e9b VM_operation \u7684\u52a8\u4f5c\uff0c\u6bd4\u5982\u6700\u5e38\u89c1\u7684\u5c31\u662f\u5185\u5b58\u5206\u914d\u5931\u8d25\u8981\u6c42\u505a GC \u64cd\u4f5c\u7684\u8bf7\u6c42\u7b49\uff0c\u5728\u5bf9 gc \u8fd9\u4e9b\u64cd\u4f5c\u6267\u884c\u7684\u65f6\u5019\u4f1a\u5148\u5c06\u5176\u4ed6\u4e1a\u52a1\u7ebf\u7a0b\u90fd\u8fdb\u5165\u5230\u5b89\u5168\u70b9\uff0c\u4e5f\u5c31\u662f\u8fd9\u4e9b\u7ebf\u7a0b\u4ece\u6b64\u4e0d\u518d\u6267\u884c\u4efb\u4f55\u5b57\u8282\u7801\u6307\u4ee4\uff0c\u53ea\u6709\u5f53\u51fa\u4e86\u5b89\u5168\u70b9\u7684\u65f6\u5019\u624d\u8ba9\u4ed6\u4eec\u7ee7\u7eed\u6267\u884c\u539f\u6765\u7684\u6307\u4ee4\uff0c\u56e0\u6b64\u8fd9\u5176\u5b9e\u5c31\u662f\u6211\u4eec\u8bf4\u7684 stop the world(STW)\uff0c\u6574\u4e2a\u8fdb\u7a0b\u76f8\u5f53\u4e8e\u9759\u6b62\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u8bd5\u9898\u516d\uff1a\u5e76\u884c\u7684 Full GC \u662f\u5426\u6709\u4e86\u89e3\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e76\u884c Full GC \u4e5f\u540c\u6837\u4f1a\u505a YGC \u548c CMS GC\uff0c\u4f46\u662f\u6548\u7387\u9ad8\u5c31\u641e\u5728 CMS GC \u662f\u8d70\u7684 background \u7684\uff0c\u6574\u4e2a\u6682\u505c\u7684\u8fc7\u7a0b\u4e3b\u8981\u662f YGC\u3001CMS_initMark\u3001CMS_remark \u51e0\u4e2a\u9636\u6bb5\u3002background \u987e\u540d\u601d\u4e49\u662f\u5728\u540e\u53f0\u505a\u7684\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5\u4e0d\u5f71\u54cd\u6b63\u5e38\u7684\u4e1a\u52a1\u7ebf\u7a0b\u8dd1\uff0c\u89e6\u53d1\u6761\u4ef6\u6bd4\u5982\u8bf4 old \u7684\u5185\u5b58\u5360\u6bd4\u8d85\u8fc7\u591a\u5c11\u7684\u65f6\u5019\u5c31\u53ef\u80fd\u89e6\u53d1\u4e00\u6b21 background \u5f0f\u7684 cms gc\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u7ecf\u5386 CMS GC \u7684\u6240\u6709\u9636\u6bb5\uff0c\u8be5\u6682\u505c\u7684\u6682\u505c\uff0c\u8be5\u5e76\u884c\u7684\u5e76\u884c\uff0c\u6548\u7387\u76f8\u5bf9\u6765\u8bf4\u8fd8\u6bd4\u8f83\u9ad8\uff0c\u6bd5\u7adf\u6709\u548c\u4e1a\u52a1\u7ebf\u7a0b\u5e76\u884c\u7684 gc \u9636\u6bb5\uff1b\u800c foreground \u5219\u4e0d\u7136\uff0c\u5b83\u53d1\u751f\u7684\u573a\u666f\u6bd4\u5982\u4e1a\u52a1\u7ebf\u7a0b\u8bf7\u6c42\u5206\u914d\u5185\u5b58\uff0c\u4f46\u662f\u5185\u5b58\u4e0d\u591f\u4e86\uff0c\u4e8e\u662f\u53ef\u80fd\u89e6\u53d1\u4e00\u6b21 cms gc\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u5fc5\u987b\u662f\u8981\u7b49\u5185\u5b58\u5206\u914d\u5230\u4e86\u7ebf\u7a0b\u624d\u80fd\u7ee7\u7eed\u5f80\u4e0b\u9762\u8d70\u7684\uff0c\u56e0\u6b64\u6574\u4e2a\u8fc7\u7a0b\u5fc5\u987b\u662fSTW\u7684\uff0c\u56e0\u6b64 CMS GC \u6574\u4e2a\u8fc7\u7a0b\u90fd\u662f\u6682\u505c\u5e94\u7528\u7684\uff0c\u4f46\u662f\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u5b83\u5e76\u4e0d\u662f\u6bcf\u4e2a\u9636\u6bb5\u90fd\u4f1a\u8d70\u7684\uff0c\u53ea\u8d70\u5176\u4e2d\u4e00\u4e9b\u9636\u6bb5\uff0c\u8fd9\u4e9b\u7701\u4e0b\u6765\u7684\u9636\u6bb5\u4e3b\u8981\u662f\u5e76\u884c\u9636\u6bb5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u51e0\u4e2a\u5173\u4e8e System.gc \u7684\u95ee\u9898\uff0c\u4f60\u662f\u5426\u88ab\u96f7\u5230\u4e86\u3002\u5176\u5b9e Java \u7684 Gc \u8fd8\u662f\u5f88\u590d\u6742\u7684\uff0c\u6211\u53ea\u662f\u964d\u4f4e\u7ef4\u5ea6\u5230\u4e86 System.gc \u8fd9\u4e2a\u5177\u4f53\u7684\u65b9\u6cd5\uff0c\u540e\u9762\u6709\u65f6\u95f4\u4e86\uff0c\u6211\u4eec\u5728\u7ee7\u7eed\u5206\u4eab\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4076\">\u4e00\u4e2a System.gc \u5c31\u80fd\u8ba9\u4f60\u5728\u9762\u8bd5\u4e2d\u88ab\u6253\u51fb\u5230\u6000\u7591\u4eba\u751f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4eba\u7684\u4e00\u751f\u4e2d\u53ef\u80fd\u4f1a\u906d\u9047\u5230\u65e0\u6570\u6b21\u6253\u51fb\u3002\u800c\u4eca\u5929\u6211\u5c31\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e2a\u4f60\u53ef\u80fd\u5ffd\u7565\u7684\u77e5\u8bc6\u70b9\uff1aSystem.gc\uff0c\u7ed9\u4f60\u4e13\u95e8\u6765\u4e00 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1174,328,262,731,1744],"class_list":["post-4076","post","type-post","status-publish","format-standard","hentry","category-java","tag-gc","tag-java","tag-jvm","tag-useparallelgc"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4076"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4076\/revisions"}],"predecessor-version":[{"id":4077,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4076\/revisions\/4077"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}