CLI and debug adapter (DAP) that allows to inspect Java heap dumps (.hprof files) via OQL
Requires Java 22
mvn packagehprofdap communicates via stdio.
Configure a debug-adapter client to spawn:
java \
-Dpolyglot.engine.WarnInterpreterOnly=false \
-jar path/to/repo/target/hprofdap-0.1.0-jar-with-dependencies.jarCurrently only the launch type is supported with one additional configuration
property: filepath, which is expected to be a absolute path to the .hprof file
you want to analyze.
dap.adapters.hprof = {
type = "executable",
command = os.getenv("JDK22") .. "/bin/java", -- or just "java"
args = {
"-Dpolyglot.engine.WarnInterpreterOnly=false",
"-jar",
vim.fn.expand("~/path/to/hprofdap/target/hprofdap-1.0-jar-with-dependencies.jar"),
}
}
dap.configurations.java = {
{
name = "hprof",
request = "launch",
type = "hprof",
filepath = function()
return require("dap.utils").pick_file({
executables = false,
filter = "%.hprof$"
})
end,
},
}A .hprof file cannot be executed, therefore most of the functionality
available during a regular debug session won't work. There are no breakpoints
to hit, no stopped events, or anything like that.
Instead you can query the heap dump via OQL via the debug adapter's client's
evaluate functionality.
Some examples of OQL queries:
select file from java.io.File file
select file.path from java.io.File file
select s from int[] s where s.length > 4000
Start hprofdap with jdwp enabled and use the bundled .vscode/launch.json
attach configuration
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005