|
Carl Chesser @che55er | che55er.io |
Why we take a heap dump and the two common commands.
What a .hprof contains, and why it can be huge.
How MAT reads, indexes, and queries the snapshot with Calcite for a richer query engine.
How MCP exposes heap analysis to an AI application.
A live walk through the Java heap workbench.
Why capture a heap dump?
OutOfMemoryError
Find which objects retained the heap and what application path kept them reachable.
Size the container workload
Understand heap, object, and retention patterns before choosing memory limits and headroom.
A heap dump shows what the JVM was holding at that moment.
What objects existed? How large were they? What kept them reachable?
What happened first, or which request created every object.
The memory occupied by the object itself, excluding the objects it references.
The memory that would become collectible if this object were removed from the graph.
A runtime-held reference, such as a thread or static field, that keeps objects reachable.
The number of instances of a class; many small objects can consume substantial memory in total.
jcmd: capture a heap dumpjcmd <PID> GC.heap_dump \
/tmp/service.hprof
The target JVM must generally be owned by the same OS user. Choose a destination with enough free space.
jmap: the traditional JDK commandjmap -dump:format=b,\
file=/tmp/service.hprof <PID>
This produces the same kind of binary heap-dump artifact for analysis.
What is actually inside a .hprof?
.hprof?
.hprof?
These tools are covered in the memory-analysis guide.
Open source since 2008.
Mature enough for large production heap dumps.
Versatile enough for reports, object graphs, retained sizes, and OQL.
Licensed under the Eclipse Public License 2.0.
.hprof file.index
.o2hprof.index
.o2c.index
.idx.index
.inbound.index
.outbound.index
.a2s.index
.domIn.index
.domOut.index
.o2ret.index
.threadsCreates a file-based index to assist in different forms of lookups.
Read, query, and extend heap analysis.
A mature engine for reading heap snapshots.
Indexes, retained sizes, dominators, references, reports, and OQL.
SELECT c.cacheLimit, c.innerCache.size
FROM cchesser.javaperf.workshop.cache.CleverCache c
OQL is not standard SQL.
MAT publishes a BNF grammar an agent can follow.
MAT OQL provides essential capabilities for quering data; however, it is quite limited.
For joins, grouping, sorting, and aggregation, add Apache Calcite based on the mat-calcite-plugin.
SELECT toString(file) AS url,
COUNT(*) AS copies,
SUM(retainedSize(this)) AS retained
FROM java.net.URL
GROUP BY toString(file)
HAVING COUNT(*) > 1
ORDER BY retained DESC
Now the agent can ask distribution and relationship questions in SQL.
Objects, fields, references, shallow size, retained size.
Stronger relational query layer over MAT’s heap-backed schema.
The workbench turns tool results into a conversation.
Ask a memory question in plain language.
Let the model choose how to resolve the question with the available tools.
It can further explore the data set through a clearly defined query language (OQL).
An AI application is configured with the MCP interface (server).
The MCP server describes inputs and outputs.
The model understands this protocol and then can utilize this to utilize specific tools for specific use-cases.
java-heap-mcp
Load a hprof file into a named project, build or reuse MAT indexes, and return a stable heap handle.
Tools return focused JSON summaries and rows instead of sending
the raw .hprof to the model.
heap_open_projectheap_get_overviewThe model never needs direct access to the raw heap file, it is able to access through well-defined MCP tools.
heap_load_dump
load/index a dump
heap_open_project
resume a cached project
heap_list_projects · heap_list_dumps
discover cached state
heap_unload_dump
release an active handle
heap_get_overview
summary, top classes,
dominators
heap_get_histogram
sort by
retained/shallow/count
heap_get_dominators
find retained-memory roots
heap_get_oql_grammar
learn the supported
SQL/OQL
heap_run_oql
query with limit + offset
heap_inspect_object
fields and references
heap_find_path_to_gc_roots
trace reachability
heap_find_leak_suspects
run MAT leak analysis
heap_get_overviewheap_get_histogramheap_inspect_objectheap_find_path_to_gc_rootsheap_run_oqlheap_find_leak_suspectsThe model chooses the next tool from the returned evidence.
The model returns declarative JSON.
The UI renders summaries, tables, charts, and graphs.
The same tool result can become a table.
Numeric rows can become a chart.
References can become a graph.
Browser local model (via ollama) MCP MAT heap dump.
You can also use any frontier model and coding agent to interact with this MCP server.
Just remember, your heap file contains sensitive data.
|
Carl Chesser @che55er · che55er.io jvmperf.net |