Package org.graalvm.tools.insight.heap
Class HeapDump.InstanceBuilder
java.lang.Object
org.graalvm.tools.insight.heap.HeapDump.InstanceBuilder
- Enclosing class:
HeapDump
Fills data for new object instance to put into 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 gathered field values into theHeapDump
.id()
The ID assigned to the instance.put
(String name, HeapDump.ObjectInstance value) Puts reference to another object as a value of the field.putBoolean
(String name, boolean value) Puts value into a field.Puts value into a field.Puts value into a field.Puts value into a field.Puts value into a field.Puts value into a field.Puts value into a field.Puts value into a field.
-
Method Details
-
put
Puts reference to another object as a value of the field.- Parameters:
name
- the name of the fieldvalue
- reference to object in theHeapDump
- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putByte
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putShort
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putInt
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putLong
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putFloat
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putDouble
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putBoolean
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
putChar
Puts value into a field.- Parameters:
name
- the name of the fieldvalue
- primitive value to assign to the field- Returns:
this
builder- Throws:
IllegalArgumentException
- if the field doesn't exist or its type isn't correct- Since:
- 21.1
-
dumpInstance
Dumps the gathered field values into theHeapDump
.- Returns:
- object representing the written instance
- Throws:
UncheckedIOException
- when an I/O error occurs- Since:
- 21.1
- See Also:
-
id
The ID assigned to the instance. Allows one to obtain ID of an instance before it is dumped into theHeapDump
.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();
- Returns:
- object reference for the instance that's going to be built when
dumpInstance()
method is invoked - Since:
- 21.1
-