分析 Java heap dump、.hprof 文件、Eclipse MAT HTML 报告、Leak Suspects zip、Class Histogram、Dominator Tree、GC 异常、JVM OOM 或内存泄漏问题,并把 retained heap 证据关联回 Java/Kotlin/Spring/Quartz 项目代码,产出中文的根因判断、修复方案、验证计划和故障复盘文档。适用于用户要求分析 dump/hprof/heap dump/MAT 报告、内存泄漏、OOM、retained heap、dominator tree、RAMJobStore、ThreadLocal 泄漏、缓存泄漏、classloader 泄漏,或要求结合仓库代码优化内存问题的场景。
77
96%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
把 heap dump 证据转成可落地的工程诊断。优先给出有证据支撑的窄根因,不要泛泛罗列 JVM 调优建议。
定位分析材料。
.hprof、*Leak_Suspects*.zip、*System_Overview*.zip、*Top_Components*.zip、.threads、.index、MAT 导出的 HTML 报告。.hprof,不要停止;先用 Eclipse MAT 命令行生成报告。如果没有 MAT 报告,从 .hprof 生成报告。
ParseHeapDump.sh 或 MemoryAnalyzer。.hprof;如果要模拟无报告状态,只移动或清理 .index、.threads、*_Leak_Suspects.zip、*_System_Overview.zip、*_Top_Components.zip 等派生文件。ParseHeapDump.sh <dump.hprof> org.eclipse.mat.api:suspects org.eclipse.mat.api:overview org.eclipse.mat.api:top_components 生成三类报告。<name>_Leak_Suspects.zip<name>_System_Overview.zip<name>_Top_Components.zip<name>.threads<name>*.index优先读取 MAT 报告,而不是一上来硬啃原始 dump。
unzip -l 查看报告 zip 内容。index.html、pages/Class_Histogram*.html、pages/Top_Consumers*.html、pages/Thread_Overview*.html、pages/System_Properties*.html、Problem Suspect 页面。找 retained memory 的真正持有者。
把 dump 里的类名关联回代码。
rg 搜索类名、包名、框架类型、关键字段、job/cache/listener/scheduler API、配置项。形成可证伪的根因。
RAMJobStore 持有 trigger 是直接证据;大规模使用 RAMJobStore 是扩展性风险;deleteJob 用错 group 才是更具体的代码缺陷。给出修复方案。
验证。
输出结论。
查找 heap 相关文件:
find ~/Desktop -maxdepth 3 \( -iname '*.hprof' -o -iname '*dump*' -o -iname '*heap*' -o -iname '*Leak_Suspects*.zip' -o -iname '*System_Overview*.zip' -o -iname '*Top_Components*.zip' \) -print查找本机 Eclipse MAT 命令行:
command -v ParseHeapDump.sh || true
command -v MemoryAnalyzer || true
find /Applications "$HOME" -maxdepth 5 \( -iname 'ParseHeapDump.sh' -o -iname 'MemoryAnalyzer' \) -print 2>/dev/null从原始 hprof 生成 MAT 报告:
/Applications/MemoryAnalyzer.app/Contents/Eclipse/ParseHeapDump.sh \
/path/to/heap_dump.hprof \
org.eclipse.mat.api:suspects \
org.eclipse.mat.api:overview \
org.eclipse.mat.api:top_components生成后确认产物:
find /path/to/dump-dir -maxdepth 1 \( \
-name 'heap_dump*.index' \
-o -name 'heap_dump.threads' \
-o -name 'heap_dump_*Suspects.zip' \
-o -name 'heap_dump_*Overview.zip' \
-o -name 'heap_dump_*Components.zip' \
\) -print | sort查看 MAT 报告 zip:
unzip -l /path/to/heap_dump_Leak_Suspects.zip | sed -n '1,160p'安全提取 MAT HTML 文本:
TMP=/tmp/heap_report_$$
mkdir -p "$TMP/leak" "$TMP/overview" "$TMP/top"
unzip -q /path/to/heap_dump_Leak_Suspects.zip -d "$TMP/leak"
unzip -q /path/to/heap_dump_System_Overview.zip -d "$TMP/overview"
unzip -q /path/to/heap_dump_Top_Components.zip -d "$TMP/top"
python3 - "$TMP" <<'PY'
from pathlib import Path
import html, re, sys
base = Path(sys.argv[1])
for p in base.rglob("*.html"):
if p.name.startswith(("Class_Histogram", "Top_Consumers", "Thread_Overview", "System_Properties")) or p.name == "index.html":
s = p.read_text(errors="ignore")
s = re.sub(r"<script.*?</script>|<style.*?</style>", "", s, flags=re.S|re.I)
s = re.sub(r"<[^>]+>", "\n", s)
lines = [html.unescape(x.strip()) for x in s.splitlines() if x.strip()]
print(f"\n===== {p.relative_to(base)} =====")
print("\n".join(lines[:180]))
PY按可疑类和 API 回查代码:
rg -n "Quartz|RAMJobStore|CronTrigger|scheduleJob|deleteJob|ThreadLocal|Cache|put\\(|evict|shutdown|close\\(" src -g '*.kt' -g '*.java' -g '*.yml' -g '*.yaml' -g '*.properties'本技能沉淀自一次从原始 dump 重新生成报告的实测流程:
/Users/greysonfang/Desktop/heap_dump.hprof,大小约 2.6G。heap_dump*.index、heap_dump.threads、heap_dump_Leak_Suspects.zip、heap_dump_System_Overview.zip、heap_dump_Top_Components.zip。/Applications/MemoryAnalyzer.app/Contents/Eclipse/ParseHeapDump.sh。/Applications/MemoryAnalyzer.app/Contents/Eclipse/ParseHeapDump.sh \
/Users/greysonfang/Desktop/heap_dump.hprof \
org.eclipse.mat.api:suspects \
org.eclipse.mat.api:overview \
org.eclipse.mat.api:top_components.threads 和索引,再计算 Dominator Tree,最后输出三个报告 zip。heap_dump_Leak_Suspects.zip: 168Kheap_dump_System_Overview.zip: 140Kheap_dump_Top_Components.zip: 772KTop Components 阶段日志可能极多,终端输出被截断是正常的;只要进程退出码为 0 且报告 zip 存在即可继续分析。除非用户要求其他格式,使用下面结构输出:
# Java Heap Dump 排查结论
## 现象
- Dump / MAT 报告来源:
- 主要 retained heap:
- 关键对象数量:
## 根因
一句话结论。
## 证据链
| 证据 | 数值/位置 | 说明 |
| --- | --- | --- |
## 代码定位
- 文件:
- 调用链:
- 问题点:
## 修复方案
1. 立即修复:
2. 验证:
3. 上线/重启:
## 长期优化
- 监控:
- 架构/存储:
- 测试:如果 MAT 中出现 Quartz RAMJobStore、QuartzSchedulerResources、CronTriggerImpl、CronExpression、TriggerWrapper、TreeMap$Entry 或 JobKey 占据主要 retained heap,读取 references/quartz-ramjobstore.md。
94743cb
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.