{"id":217,"date":"2024-09-28T11:19:09","date_gmt":"2024-09-28T03:19:09","guid":{"rendered":"https:\/\/newstrong.xyz\/?p=217"},"modified":"2024-09-28T11:19:09","modified_gmt":"2024-09-28T03:19:09","slug":"%e5%86%85%e5%ad%98%e6%b3%84%e9%9c%b2%ef%bc%88%e5%8d%81%ef%bc%89-koom%e9%ab%98%e6%80%a7%e8%83%bd%e7%ba%bf%e4%b8%8a%e5%86%85%e5%ad%98%e7%9b%91%e6%8e%a7%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/newstrong.top\/index.php\/2024\/09\/28\/%e5%86%85%e5%ad%98%e6%b3%84%e9%9c%b2%ef%bc%88%e5%8d%81%ef%bc%89-koom%e9%ab%98%e6%80%a7%e8%83%bd%e7%ba%bf%e4%b8%8a%e5%86%85%e5%ad%98%e7%9b%91%e6%8e%a7%e6%96%b9%e6%a1%88\/","title":{"rendered":"\u5185\u5b58\u6cc4\u9732\uff08\u5341\uff09&#8211; KOOM(\u9ad8\u6027\u80fd\u7ebf\u4e0a\u5185\u5b58\u76d1\u63a7\u65b9\u6848)"},"content":{"rendered":"<p><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"display: none;\">\n                        <path stroke-linecap=\"round\" d=\"M5,0 0,2.5 5,5z\" id=\"raphael-marker-block\" style=\"-webkit-tap-highlight-color: rgba(0, 0, 0, 0);\"><\/path>\n                    <\/svg><\/p>\n<pre><code>                <p><a href=\"https:\/\/gitee.com\/mirrors\/KOOM\/blob\/master\/README.zh-CN.md\" rel=\"nofollow\">KOOM\u4ecb\u7ecd<\/a><br> <a href=\"https:\/\/gitee.com\/mirrors\/KOOM\/blob\/master\/koom-java-leak\/README.zh-CN.md\" rel=\"nofollow\">OOMMonitor \u4ecb\u7ecd<\/a><br> <a href=\"https:\/\/zhuanlan.zhihu.com\/p\/594260931\" rel=\"nofollow\">KOOM\u7ebf\u4e0aAPM\u76d1\u63a7\u6700\u5168\u5256\u6790<\/a><br> <a href=\"https:\/\/juejin.cn\/post\/7007395579840069669\" rel=\"nofollow\">\u4e00\u6587\u770b\u61c2\u5feb\u624bKOOM\u9ad8\u6027\u80fd\u76d1\u63a7\u65b9\u6848<\/a><br> <a href=\"https:\/\/juejin.cn\/post\/6982121209144016910\" rel=\"nofollow\">KOOM \u6d45\u6790<\/a><br> <a href=\"https:\/\/juejin.cn\/post\/6991374693403983886\" rel=\"nofollow\">\u3010\u5f00\u6e90\u5e93\u5256\u6790\u3011KOOM V1.0.5 \u6e90\u7801\u89e3\u6790<\/a><\/p> <\/code><\/pre>\n<\/p>\n<div class=\"toc\">\n<h4>\u76ee\u5f55<\/h4>\n<ul>\n<li><a href=\"\" rel=\"nofollow\">KOOM \u529f\u80fd<\/a><\/li>\n<li>\n<ul>\n<li><a href=\"\" rel=\"nofollow\">1. Java Heap \u6cc4\u6f0f\u76d1\u63a7<\/a><\/li>\n<li>\n<ul>\n<li><a href=\"\" rel=\"nofollow\">1.1 OOMMonitor \u4ecb\u7ecd<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">1.2 OOMMonitor \u9002\u7528\u8303\u56f4<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">1.3 OOMMonitor \u63a5\u5165<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"\" rel=\"nofollow\">2. Native Heap \u6cc4\u6f0f\u76d1\u63a7<\/a><\/li>\n<li>\n<ul>\n<li><a href=\"\" rel=\"nofollow\">2.1 LeakMonitor \u4ecb\u7ecd<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">2.2 LeakMonitor \u9002\u7528\u8303\u56f4<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">2.3 LeakMonitor \u63a5\u5165<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"\" rel=\"nofollow\">3. Thread \u6cc4\u6f0f\u76d1\u63a7<\/a><\/li>\n<li>\n<ul>\n<li><a href=\"\" rel=\"nofollow\">3.1 ThreadLeakMonitor \u4ecb\u7ecd<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">3.2 ThreadLeakMonitor \u9002\u7528\u8303\u56f4<\/a><\/li>\n<li><a href=\"\" rel=\"nofollow\">3.3 ThreadLeakMonitor \u63a5\u5165<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<p> \u2003\u2003KOOM(Kwai OOM, Kill OOM)\u662f\u5feb\u624b\u6027\u80fd\u4f18\u5316\u56e2\u961f\u5728\u5904\u7406\u79fb\u52a8\u7aefOOM\u95ee\u9898\u7684\u8fc7\u7a0b\u4e2d\u6c89\u6dc0\u51fa\u7684\u4e00\u5957\u5b8c\u6574\u89e3\u51b3\u65b9\u6848\u3002 <\/p>\n<\/p>\n<h2>\n<a id=\"KOOM__11\"><\/a>KOOM \u529f\u80fd<\/h2>\n<p>Koom\u6d41\u7a0b\uff1a<br \/> <img decoding=\"async\" src=\"https:\/\/newstrong.xyz\/wp-content\/uploads\/2024\/09\/frc-cd91edd3b6d598c08df251da7362dc01.png\"><br \/> <strong>OOM\u95ee\u9898\u539f\u56e0\u5206\u7c7b<\/strong><\/p>\n<ol>\n<li>Java\u5806\u5185\u5b58\u6ea2\u51fa<\/li>\n<li>\u65e0\u8db3\u591f\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4<\/li>\n<li>FD(\u6587\u4ef6\u63cf\u8ff0\u7b26)\u8d85\u51fa\u9650\u5236<\/li>\n<li>\u7ebf\u7a0b\u6570\u91cf\u8d85\u51fa\u9650\u5236<\/li>\n<li>\u865a\u62df\u5185\u5b58\u4e0d\u8db3<\/li>\n<\/ol>\n<h3>\n<a id=\"1_Java_Heap__20\"><\/a>1. Java Heap \u6cc4\u6f0f\u76d1\u63a7<\/h3>\n<p>\u2003\u2003<code>koom-java-leak<\/code> \u6a21\u5757\u7528\u4e8e <strong>Java Heap<\/strong> \u6cc4\u6f0f\u76d1\u63a7\uff1a\u5b83\u5229\u7528 <code>Copy-on-write<\/code> \u673a\u5236 <code>fork<\/code> \u5b50\u8fdb\u7a0b dump Java Heap\uff0c\u89e3\u51b3\u4e86 dump \u8fc7\u7a0b\u4e2d app \u957f\u65f6\u95f4\u51bb\u7ed3\u7684\u95ee\u9898<\/p>\n<ul>\n<li>fork\u5b50\u8fdb\u7a0b\u53bb\u6267\u884cdumpHprofData\u65b9\u6cd5<\/li>\n<li>fork\u8fdb\u7a0b\u91c7\u7528\u7684\u662f\u201c<code>Copy On Write<\/code>\u201d\u6280\u672f\uff0c\u53ea\u6709\u5728\u8fdb\u884c<code>\u5199\u5165\u64cd\u4f5c<\/code>\u65f6\uff0c\u624d\u4f1a<code>\u4e3a\u5b50\u8fdb\u7a0b\u62f7\u8d1d\u5206\u914d\u72ec\u7acb\u7684\u5185\u5b58\u7a7a\u95f4<\/code>\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b50\u8fdb\u7a0b\u53ef\u4ee5\u548c\u7236\u8fdb\u7a0b<code>\u5171\u4eab\u540c\u4e2a\u5185\u5b58\u7a7a\u95f4<\/code>\uff0c\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u8981\u6267\u884c<strong>dumpHprofData<\/strong>\u65b9\u6cd5\u65f6\uff0c\u53ef\u4ee5\u5148<code>fork\u4e00\u4e2a\u5b50\u8fdb\u7a0b<\/code>\uff0c\u5b83\u62e5\u6709\u7236\u8fdb\u7a0b\u7684\u5185\u5b58\u526f\u672c\uff0c\u7136\u540e\u5728\u5b50\u8fdb\u7a0b\u4e2d\u6267\u884cdumpHprofData\u65b9\u6cd5\uff0c\u800c\u7236\u8fdb\u7a0b\u5219\u53ef\u4ee5\u6b63\u5e38\u7ee7\u7eed\u8fd0\u884c\u3002<br \/> <img decoding=\"async\" src=\"https:\/\/newstrong.xyz\/wp-content\/uploads\/2024\/09\/frc-cb67bac626ba87a5fd3f25a48ffc3f5a.png\"><br \/> \u2003\u2003hprof\u662f\u57fa\u4e8e<code>JVMTI<\/code>\u5b9e\u73b0\u7684\u5185\u5b58\u5206\u6790\u5668\u4ee3\u7406\uff0c\u5176\u8f6c\u50a8\u6587\u4ef6\u8bb0\u5f55\u4e86Java\u7684\u5185\u5b58\u955c\u50cf\uff08Heap Profile\uff09\uff0c\u5176\u4e2d\u8bb0\u5f55\u4e86\u5185\u5b58\u5806\u8be6\u7ec6\u7684\u4f7f\u7528\u4fe1\u606f\uff0c\u53ef\u7528\u4e8e\u5206\u6790Java\u7a0b\u5e8f\u5185\u5b58\u7684\u5404\u79cd\u6027\u80fd\u95ee\u9898\u3002<br \/> \u2003\u2003\u865a\u62df\u673a\u63d0\u4f9b\u7684Debug.dumpHprofData\u53ef\u4ee5\u5c06hprof\u6587\u4ef6\u8f93\u51fa\u5728\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\uff0c\u4f46\u662f\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u201c\u51bb\u7ed3\u201d\u6574\u4e2a\u5e94\u7528\u8fdb\u7a0b\uff0c\u9020\u6210\u6570\u79d2\u751a\u81f3\u6570\u5341\u79d2\u5185\u7528\u6237\u65e0\u6cd5\u64cd\u4f5c\uff0c\u5373<code>dump\u6587\u4ef6\u4e5f\u662f\u4f1a\u4ea7\u751fSTW(Stop the world)\uff0c\u8ddfGC\u4e00\u6837\u4f1a\u8ba9\u6240\u6709\u7ebf\u7a0b\u6302\u8d77\u3002<\/code>\n<\/li>\n<\/ul>\n<p><em>HeapMonitor.java<\/em><\/p>\n<pre><code>public boolean isTrigger() {\n    if (!started) {\n      return false;\n    }\n\n    HeapStatus heapStatus = currentHeapStatus();\n\n    if (heapStatus.isOverMaxThreshold) {\n      \/\/ \u5df2\u8fbe\u5230\u6700\u5927\u9600\u503c\uff0c\u5f3a\u5236\u89e6\u53d1trigger\uff0c\u9632\u6b62\u540e\u7eed\u51fa\u73b0\u5927\u5185\u5b58\u5206\u914d\u5bfc\u81f4OOM\u8fdb\u7a0bCrash\uff0c\u65e0\u6cd5\u89e6\u53d1trigger\n      KLog.i(TAG, \"heap used is over max ratio, force trigger and over times reset to 0\");\n      currentTimes = 0;\n      return true;\n    }\n\n    if (heapStatus.isOverThreshold) {\n      KLog.i(TAG, \"heap status used:\" + heapStatus.used \/ KConstants.Bytes.MB\n              + \", max:\" + heapStatus.max \/ KConstants.Bytes.MB\n              + \", last over times:\" + currentTimes);\n      if (heapThreshold.ascending()) {\n        \/\/ \u7b2c\u4e00\u6b21\u8fdb\u6765 \u6216\u8005 \u5f53\u524d\u5185\u5b58\u5360\u7528\u7387\u8ddf\u4e0a\u6b21\u9ad8 \u6216\u8005 \u5f53\u524d\u5185\u5b58\u5360\u7528\u7387\u8d85\u8fc7\u4e86\u6700\u5927\u7684\u9608\u503c\uff0895%\uff09\n        if (lastHeapStatus == null || heapStatus.used &gt;= lastHeapStatus.used || heapStatus.isOverMaxThreshold) {\n          currentTimes++;\n        } else {\n          KLog.i(TAG, \"heap status used is not ascending, and over times reset to 0\");\n          currentTimes = 0;\n        }\n      } else {\n        currentTimes++;\n      }\n    } else {\n      currentTimes = 0;\n    }\n\n    lastHeapStatus = heapStatus;\n    return currentTimes &gt;= heapThreshold.overTimes();\n  }\n<\/code><\/pre>\n<p>Koom\u4e2d\u8bbe\u7f6e\u4e86\u4e94\u79cd\u68c0\u6d4b\u5668<br \/> \u2460 HeapOOMTracker<br \/> \u2461 ThreadOOMTracker<br \/> \u2462 FdOOMTracker<br \/> \u2463 PhysicalMemoryOOMTracker<br \/> \u2464 FastHugeMemoryOOMTracker<br \/> <strong>\u524d\u4e09\u79cd<\/strong>\u79f0\u4e3a<code>\u957f\u671f\u9ad8\u5185\u5b58\u68c0\u6d4b\u5668<\/code>\uff0c\u68c0\u6d4b\u673a\u5236\u662f\u5f53\u8ba1\u7b97\u51fa\u5185\u5b58\u5360\u7528\u7387\u4e4b\u540e\uff0c\u6211\u4eec\u770b\u4e0b\u9762\u7684\u4e00\u4e2a\u5224\u65ad\u6761\u4ef6\uff0c\u5982\u679c<code>\u5185\u5b58\u5360\u7528\u7387\u8d85\u8fc7\u6211\u4eec\u8bbe\u5b9a\u7684\u4e00\u4e2a\u9608\u503c\uff08\u4f8b\u59820.8\uff09\uff0c\u800c\u4e14\u5f53\u524d\u5185\u5b58\u5360\u7528\u7387\u8ddf\u4e0a\u6b21\u6bd4\u8f83\u8d85\u8fc7\u4e86\u5343\u5206\u4e4b5<\/code>\uff0c\u90a3\u4e48<code>mOverThresholdCount<\/code>\u53d8\u91cf\u5c31\u4f1a<code>\u81ea\u589e1<\/code>\u3002<\/p>\n<blockquote>\n<p>Heap\u76d1\u6d4b\u673a\u5236\u662f\u7b2c\u4e00\u6b21\u8fdb\u6765 \u6216\u8005 \u5f53\u524d\u5185\u5b58\u5360\u7528\u7387\u8ddf\u4e0a\u6b21\u9ad8 \u6216\u8005<br \/> \u5f53\u524d\u5185\u5b58\u5360\u7528\u7387\u8d85\u8fc7\u4e86\u6700\u5927\u7684\u9608\u503c\uff0895%\uff09\uff0c\u4e09\u4e2a\u6761\u4ef6\u53ea\u8981\u6ee1\u8db3\u4e00\u4e2a\uff0c\u90a3\u4e48<code>mOverThresholdCount<\/code>\u53d8\u91cf\u5c31\u4f1a<code>\u81ea\u589e1<\/code><\/p>\n<\/blockquote>\n<p>\u2003\u2003\u56e0\u4e3a\u68c0\u6d4b\u662f\u4e00\u4e2a\u5faa\u73af\u7684\u8fc7\u7a0b\uff0c\u6240\u4ee5\u5f53\u7b2c\u4e00\u6b21\u8fdb\u6765\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4f1a\u81ea\u589e1\uff0c\u800c\u4e14\u4f1a\u5c06\u672c\u6b21\u7684\u5185\u5b58\u5360\u7528\u7387\u8d4b\u503c\u7ed9mLastHeapRatio\uff0c\u5f53\u4e0b\u6b21\u8fdb\u6765\u7684\u65f6\u5019\uff0c<code>\u5982\u679c\u5185\u5b58\u5360\u7528\u7387\u8f83\u4e0a\u6b21\u964d\u4f4e\u4e86\uff0c\u90a3\u4e48\u5c31\u4f1a\u91cd\u7f6e\u3002<\/code><br \/> \u2003\u2003\u5982\u6b64\u5f80\u590d\uff0c\u5f53<code>mOverThresholdCount\u8d85\u51fa\u6211\u4eec\u8bbe\u7f6e\u7684\u9608\u503c\uff08\u4f8b\u59823\u6b21\uff09<\/code>\uff0c\u6211\u4eec\u5c31\u8ba4\u5b9a\u7cfb\u7edf\u53d1\u751f\u4e86\u5185\u5b58\u6cc4\u6f0f\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u544a\u8b66\uff0c\u5e76dump\u5185\u5b58\u5feb\u7167\u5206\u6790\u95ee\u9898\u3002<br \/> \u5373 <strong>1\uff09\u5185\u5b58\u5360\u7528\u8d85\u8fc780%\uff0c2\uff09\u5e76\u4e14\u68c0\u6d4b\u5230\u4e863\u6b21<\/strong>\uff0c\u4e24\u4e2a\u6761\u4ef6\u540c\u65f6\u6ee1\u8db3\u5c31\u4f1a\u8fdb\u884cdump\u3002<br \/> <strong>\u7b2c\u56db\u79cd<\/strong>\u4ee3\u7801\u4e2d\u8fd4\u56defalse\u6ca1\u6709\u8fdb\u884c\u5904\u7406\u3002<br \/> <strong>\u7b2c\u4e94\u79cd<\/strong>\u79f0\u4e3a<code>\u9ad8\u5371\u5185\u5b58\u4e0e\u5feb\u901f\u589e\u957f\u68c0\u6d4b\u5668<\/code>\uff0c\u68c0\u6d4b\u673a\u5236\u662f<strong>\u5185\u5b58\u5360\u7528\u8d85\u8fc790%<strong>\u6216\u8005<\/strong>\u672c\u6b21\u68c0\u6d4b\u4e0e\u4e0a\u6b21\u68c0\u6d4b\u5185\u5b58\u5360\u7528\u8d85\u8fc7350M<\/strong>\uff0c\u6ee1\u8db3\u4e24\u4e2a\u6761\u4ef6\u4e4b\u4e00\u5c31\u4f1a\u8fdb\u884cdump\u3002<\/p>\n<h4>\n<a id=\"11_OOMMonitor__85\"><\/a>1.1 OOMMonitor \u4ecb\u7ecd<\/h4>\n<p>\u7528\u4e8e\u76d1\u63a7\u5e94\u7528\u7684 Java \u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u5b83\u7684\u6838\u5fc3\u539f\u7406\uff1a<\/p>\n<ul>\n<li>\u5468\u671f\u6027\u67e5\u8be2Java\u5806\u5185\u5b58\u3001\u7ebf\u7a0b\u6570\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u7b49\u8d44\u6e90\u5360\u7528\u60c5\u51b5\uff0c\u5f53\u8fde\u7eed\u591a\u6b21\u8d85\u8fc7\u8bbe\u5b9a\u9608\u503c\u6216\u7a81\u53d1\u6027\u8fde\u7eed\u5feb\u901f\u7a81\u7834\u9ad8\u9608\u503c\u65f6\uff0c\u89e6\u53d1\u955c\u50cf\u91c7\u96c6<\/li>\n<li>\u955c\u50cf\u91c7\u96c6\u91c7\u7528\u865a\u62df\u673a<code>supend-&gt;fork\u865a\u62df\u673a\u8fdb\u7a0b-&gt;\u865a\u62df\u673aresume-&gt;dump\u5185\u5b58\u955c\u50cf<\/code>\u7684\u7b56\u7565\uff0c\u5c06\u4f20\u7edfDump\u51bb\u7ed3\u8fdb\u7a0b20s\u7684\u65f6\u95f4\u7f29\u51cf\u81f320ms\u4ee5\u5185<\/li>\n<li>\u57fa\u4e8eshark\u6267\u884c\u955c\u50cf\u89e3\u6790\uff0c\u5e76\u9488\u5bf9shark\u505a\u4e86\u4e00\u7cfb\u5217\u8c03\u6574\u7528\u4e8e\u63d0\u5347\u6027\u80fd\uff0c\u5728\u624b\u673a\u8bbe\u5907\u6d4b\u5373\u53ef\u6267\u884c\u79bb\u7ebf\u5185\u5b58\u6cc4\u9732\u5224\u5b9a\u4e0e\u5f15\u7528\u94fe\u67e5\u627e\uff0c\u751f\u6210\u5206\u6790\u62a5\u544a<\/li>\n<\/ul>\n<h4>\n<a id=\"12_OOMMonitor__91\"><\/a>1.2 OOMMonitor \u9002\u7528\u8303\u56f4<\/h4>\n<ul>\n<li>\n<p>Android L \u53ca\u4ee5\u4e0a\uff08API level &gt;= 21\uff09<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301 armeabi-v7a arm64-v8a x86 x86-64<\/p>\n<\/li>\n<\/ul>\n<h4>\n<a id=\"13_OOMMonitor__96\"><\/a>1.3 OOMMonitor \u63a5\u5165<\/h4>\n<p><a href=\"https:\/\/gitee.com\/mirrors\/KOOM\/blob\/master\/koom-java-leak\/README.zh-CN.md\" rel=\"nofollow\">OOMMonitor \u63a5\u5165<\/a><\/p>\n<h3>\n<a id=\"2_Native_Heap__102\"><\/a>2. Native Heap \u6cc4\u6f0f\u76d1\u63a7<\/h3>\n<p>\u2003\u2003<code>koom-native-leak<\/code> \u6a21\u5757\u7528\u4e8e <strong>Native Heap<\/strong> \u6cc4\u6f0f\u76d1\u63a7\uff1a\u5b83\u5229\u7528 <code>Tracing garbage collection<\/code> \u673a\u5236\u5206\u6790\u6574\u4e2a Native Heap\uff0c\u76f4\u63a5\u8f93\u51fa\u6cc4\u6f0f\u5185\u5b58\u4fe1\u606f\u300c\u5927\u5c0f\u3001\u5206\u914d\u5806\u6808\u7b49\u300f\uff1b\u6781\u5927\u7684\u964d\u4f4e\u4e86\u4e1a\u52a1\u540c\u5b66\u5206\u6790\u3001\u89e3\u51b3\u5185\u5b58\u6cc4\u6f0f\u7684\u6210\u672c\u3002<\/p>\n<p>\u601d\u8def\u603b\u7ed3\uff1a<\/p>\n<ul>\n<li>hook malloc\/free\u7b49\u5185\u5b58\u5206\u914d\u5668\u65b9\u6cd5\uff0c\u7528\u4e8e\u8bb0\u5f55Native\u5185\u5b58\u5206\u914d\u5143\u6570\u636e[\u5927\u5c0f\u3001\u5806\u6808\u3001\u5730\u5740\u7b49]\u2013\u4f7f\u7528\u4e86\u7231\u5947\u827a\u7684xhook\u5e93<\/li>\n<li>\u5468\u671f\u6027\u7684\u4f7f\u7528mark-and-sweep\u5206\u6790\u6574\u4e2a\u8fdb\u7a0bNative Heap, \u83b7\u53d6\u4e0d\u53ef\u8fbe\u7684\u5185\u5b58\u5757\u4fe1\u606f[\u5730\u5740\u3001\u5927\u5c0f]\u2013\u4f7f\u7528\u5230google\u7684libmemunreachable\u5e93<\/li>\n<li>\u5229\u7528\u4e0d\u53ef\u8fbe\u7684\u5185\u5b58\u5757\u7684\u5730\u5740\u3001\u5927\u5c0f\u7b49\u4ece\u6211\u4eec\u8bb0\u5f55\u7684\u5143\u6570\u636e\u4e2d\u83b7\u53d6\u5176\u5206\u914d\u5806\u6808\uff0c\u4ea7\u51fa\u6cc4\u6f0f\u6570\u636e[\u4e0d\u53ef\u8fbe\u5185\u5b58\u5730\u5740\u3001\u5927\u5c0f\u3001\u5206\u914d\u5806\u6808\u7b49]<\/li>\n<\/ul>\n<h4>\n<a id=\"21_LeakMonitor__109\"><\/a>2.1 LeakMonitor \u4ecb\u7ecd<\/h4>\n<p>\u7528\u4e8e\u76d1\u63a7\u5e94\u7528\u7684 Native \u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u5b83\u7684\u6838\u5fc3\u539f\u7406\u5982\u4e0b:<\/p>\n<ul>\n<li>hook malloc\/free \u7b49\u5185\u5b58\u5206\u914d\u5668\u65b9\u6cd5\uff0c\u7528\u4e8e\u8bb0\u5f55 Native \u5185\u5b58\u5206\u914d\u5143\u6570\u636e\u300c\u5927\u5c0f\u3001\u5806\u6808\u3001\u5730\u5740\u7b49\u300d<\/li>\n<li>\u5468\u671f\u6027\u7684\u4f7f\u7528 mark-and-sweep \u5206\u6790\u6574\u4e2a\u8fdb\u7a0b Native Heap\uff0c\u83b7\u53d6\u4e0d\u53ef\u8fbe\u7684\u5185\u5b58\u5757\u4fe1\u606f\u300c\u5730\u5740\u3001\u5927\u5c0f\u300d<\/li>\n<li>\u5229\u7528\u4e0d\u53ef\u8fbe\u7684\u5185\u5b58\u5757\u7684\u5730\u5740\u3001\u5927\u5c0f\u7b49\u4ece\u6211\u4eec\u8bb0\u5f55\u7684\u5143\u6570\u636e\u4e2d\u83b7\u53d6\u5176\u5206\u914d\u5806\u6808\uff0c\u4ea7\u51fa\u6cc4\u6f0f\u6570\u636e\u300c\u4e0d\u53ef\u8fbe\u5185\u5b58\u5757\u5730\u5740\u3001\u5927\u5c0f\u3001\u5206\u914d\u5806\u6808\u7b49\u300d<\/li>\n<\/ul>\n<h4>\n<a id=\"22_LeakMonitor__115\"><\/a>2.2 LeakMonitor \u9002\u7528\u8303\u56f4<\/h4>\n<ul>\n<li>Android N \u53ca\u4ee5\u4e0a\uff08API level &gt;= 24\uff09<\/li>\n<li>\u4ec5\u652f\u6301 arm64-v8a<\/li>\n<\/ul>\n<h4>\n<a id=\"23_LeakMonitor__119\"><\/a>2.3 LeakMonitor \u63a5\u5165<\/h4>\n<p><a href=\"https:\/\/gitee.com\/mirrors\/KOOM\/blob\/master\/koom-native-leak\/README.zh-CN.md\" rel=\"nofollow\">LeakMonitor \u63a5\u5165<\/a><\/p>\n<h3>\n<a id=\"3_Thread__124\"><\/a>3. Thread \u6cc4\u6f0f\u76d1\u63a7<\/h3>\n<p>\u2003\u2003<code>koom-thread-leak<\/code> \u6a21\u5757\u7528\u4e8e <strong>Thread<\/strong> \u6cc4\u6f0f\u76d1\u63a7\uff1a\u5b83\u4f1a <code>hook \u7ebf\u7a0b\u7684\u751f\u547d\u5468\u671f\u51fd\u6570<\/code>\uff0c\u5468\u671f\u6027\u7684\u4e0a\u62a5\u6cc4\u6f0f\u7ebf\u7a0b\u4fe1\u606f\u3002<\/p>\n<h4>\n<a id=\"31_ThreadLeakMonitor__127\"><\/a>3.1 ThreadLeakMonitor \u4ecb\u7ecd<\/h4>\n<p>\u7528\u4e8e\u76d1\u63a7\u5e94\u7528\u7684\u7ebf\u7a0b\u6cc4\u6f0f\u95ee\u9898\uff0c\u5b83\u7684\u6838\u5fc3\u539f\u7406\uff1a<\/p>\n<ul>\n<li>hook pthread_create\/pthread_exit \u7b49\u7ebf\u7a0b\u65b9\u6cd5\uff0c\u7528\u4e8e\u8bb0\u5f55\u7ebf\u7a0b\u7684\u751f\u547d\u5468\u671f\u548c\u521b\u5efa\u5806\u6808\uff0c\u540d\u79f0\u7b49\u4fe1\u606f<\/li>\n<li>\u5f53\u53d1\u73b0\u4e00\u4e2ajoinable\u7684\u7ebf\u7a0b\u5728\u6ca1\u6709detach\u6216\u8005join\u7684\u60c5\u51b5\u4e0b\uff0c\u6267\u884c\u4e86pthread_exit\uff0c\u5219\u8bb0\u5f55\u4e0b\u6cc4\u9732\u7ebf\u7a0b\u4fe1\u606f<\/li>\n<li>\u5f53\u7ebf\u7a0b\u6cc4\u9732\u65f6\u95f4\u5230\u8fbe\u914d\u7f6e\u8bbe\u7f6e\u7684\u5ef6\u8fdf\u671f\u9650\u7684\u65f6\u5019\uff0c\u4e0a\u62a5\u7ebf\u7a0b\u6cc4\u9732\u4fe1\u606f<\/li>\n<\/ul>\n<h4>\n<a id=\"32_ThreadLeakMonitor__133\"><\/a>3.2 ThreadLeakMonitor \u9002\u7528\u8303\u56f4<\/h4>\n<ul>\n<li>Android N \u53ca\u4ee5\u4e0a\uff08API level &gt;= 24\uff09<\/li>\n<li>\u4ec5\u652f\u6301 arm64-v8a<\/li>\n<\/ul>\n<h4>\n<a id=\"33_ThreadLeakMonitor__137\"><\/a>3.3 ThreadLeakMonitor \u63a5\u5165<\/h4>\n<p><a href=\"https:\/\/gitee.com\/mirrors\/KOOM\/blob\/master\/koom-thread-leak\/README.zh-CN.md\" rel=\"nofollow\">ThreadLeakMonitor \u63a5\u5165<\/a><\/p>\n<p>\u6587\u7ae0\u6765\u6e90\u4e8e\u4e92\u8054\u7f51:<a href=\"https:\/\/blog.csdn.net\/xuyin1204\/article\/details\/129551609\" target=\"_blank\" rel=\"noopener\">\u5185\u5b58\u6cc4\u9732\uff08\u5341\uff09&#8211; KOOM(\u9ad8\u6027\u80fd\u7ebf\u4e0a\u5185\u5b58\u76d1\u63a7\u65b9\u6848)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>KOOM\u4ecb\u7ecd OOMMonitor \u4ecb\u7ecd KOOM\u7ebf\u4e0aAPM\u76d1\u63a7\u6700\u5168\u5256\u6790 \u4e00\u6587\u770b\u61c2\u5feb\u624bKOOM\u9ad8\u6027\u80fd\u76d1\u63a7\u65b9\u6848 &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":0,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media\/218"}],"wp:attachment":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}