Class HeapDump.ClassBuilder
java.lang.Object
org.graalvm.tools.insight.heap.HeapDump.ClassBuilder
- Enclosing class:
HeapDump
Builds structure of a new class for the
HeapDump
.
Builder builder = HeapDump.newHeapBuilder(new FileOutputStream(hprof));
builder.dumpHeap((heap) -> {
final ClassInstance classActor = heap.newClass("cartoons.Actor").
field("name", String.class).
field("friend", Object.class).
field("age", int.class).
dumpClass();
final ObjectInstance jerry = heap.newInstance(classActor).
put("name", heap.dumpString("Jerry")).
putInt("age", 47).
// field 'friend' remains null
dumpInstance();
final ObjectInstance tom = heap.newInstance(classActor).
put("name", heap.dumpString("Tom")).
put("friend", jerry).
putInt("age", 32).
dumpInstance();
final ClassInstance classMain = heap.newClass("cartoons.Main").
field("tom", classActor).
field("jerry", classActor).
field("thread", java.lang.Thread.class).
dumpClass();
HeapDump.InstanceBuilder mainBuilder = heap.newInstance(classMain);
final ObjectInstance main = mainBuilder.id();
mainBuilder.put("tom", tom).put("jerry", jerry);
ObjectInstance cathingThread = heap.newThread("Catching Jerry").
addStackFrame(classActor, "tom", "Actor.java", -1, jerry, tom, main).
addStackFrame(classMain, "main", "Main.java", -1, main).
dumpThread();
mainBuilder.put("thread", cathingThread).dumpInstance();
});
- Since:
- 21.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionDumps the class definition into theHeapDump
.Adds new field with given name and type to the class definition.field
(String name, HeapDump.ClassInstance type) Adds new field with given name and type to the class definition.
-
Method Details
-
field
Adds new field with given name and type to the class definition. Primitivetype
(like (int.class
& co.) fields values are stored directly in theinstance dump
. Other types are references to otherinstances
in the dump.- Parameters:
name
- name of the fieldtype
- the type of the view- Returns:
this
builder- Since:
- 21.1
-
field
Adds new field with given name and type to the class definition. Values of such field are to otherinstances
in the dump.- Parameters:
name
- name of the fieldtype
- the type of the view- Returns:
this
builder- Since:
- 21.1
-
dumpClass
Dumps the class definition into theHeapDump
.- Returns:
- class instance to use when building instances
- Throws:
UncheckedIOException
- when an I/O error occurs- Since:
- 21.1
- See Also:
-