Files
openidea/src/features/debugger/memory/values.ts
T
ntbang0901 a3d1e57f3e feat(debugger): memory view for a paused JVM (#2648)
Adds a Memory tab to the Debug tool window for JVM sessions: loaded classes with instance counts and shallow sizes (with deltas between refreshes), read over the HotSpot attach listener (`GC.class_histogram`), falling back to counting reachable objects through the debugger on JDKs that cannot answer while suspended. While paused, a class's instances, an instance's fields and its referrers are listed through a JDWP link (the Kotlin adapter's path, and a jdtls bundle `java/jvm-inspect` for java-debug). Debug launches started by the IDE get `-XX:+StartAttachListener` unless the user's VM options decide otherwise (not on Windows).

New crates: ide-jdwp, ide-jvm-attach, ide-jvm-inspect. The bundled jar rebuilds byte-for-byte from build.py against the pinned JDT LS plugins.

Co-authored-by: ntbang0901 <121003585+ntbang0901@users.noreply.github.com>
2026-11-11 17:10:21 +08:00

38 lines
1.3 KiB
TypeScript

import type { JvmObjectRef, JvmValue } from "@/platform/ipc";
import { tx } from "@/platform/i18n";
import { formatCount } from "./rows";
const shortName = (typeName: string): string => typeName.slice(typeName.lastIndexOf(".") + 1);
/** One-line text of a value, built from what the debugger already sent: nothing is invoked in the debuggee. */
export function formatJvmValue(v: JvmValue): string {
switch (v.kind) {
case "null":
return "null";
case "primitive":
case "boxed":
return v.text;
case "string": {
if (v.text != null) return JSON.stringify(v.text);
const chars = formatCount(v.length);
return tx`String (${chars} chars)`;
}
case "object":
return `${shortName(v.typeName)}@${v.id}`;
case "array": {
const element = v.typeName.endsWith("[]") ? v.typeName.slice(0, -2) : v.typeName;
return `${shortName(element)}[${v.length}]`;
}
}
}
/** The reference to open `v` with, or null for values that are not objects. */
export function objectRef(generation: number, v: JvmValue): JvmObjectRef | null {
return v.kind === "null" || v.kind === "primitive" ? null : { generation, id: v.id };
}
/** Key of an object in `InstancesEntry.nodes`. */
export function refKey(r: JvmObjectRef): string {
return `${r.generation}:${r.id}`;
}