DelegatingObjectReferenceReader.kt
TLDR
The DelegatingObjectReferenceReader
class is an internal class that implements the ReferenceReader
interface. It delegates the reading of object references to different reference readers based on the type of the object.
Classes
DelegatingObjectReferenceReader
The DelegatingObjectReferenceReader
class is responsible for reading object references. It implements the ReferenceReader<HeapObject>
interface. This class has the following properties:
-
classReferenceReader
: A reference reader specifically forHeapClass
objects. -
instanceReferenceReader
: A reference reader specifically forHeapInstance
objects. -
objectArrayReferenceReader
: A reference reader specifically forHeapObjectArray
objects.
The class has a single method:
read(source: HeapObject): Sequence<Reference>
This method takes a source
object of type HeapObject
and returns a sequence of Reference
objects.
- If the
source
object is of typeHeapClass
, the method delegates the reading of references to theclassReferenceReader
and returns the result. - If the
source
object is of typeHeapInstance
, the method delegates the reading of references to theinstanceReferenceReader
and returns the result. - If the
source
object is of typeHeapObjectArray
, the method delegates the reading of references to theobjectArrayReferenceReader
and returns the result. - If the
source
object is of typeHeapPrimitiveArray
, the method returns an empty sequence.
package shark
import shark.HeapObject.HeapClass
import shark.HeapObject.HeapInstance
import shark.HeapObject.HeapObjectArray
import shark.HeapObject.HeapPrimitiveArray
internal class DelegatingObjectReferenceReader(
private val classReferenceReader: ReferenceReader<HeapClass>,
private val instanceReferenceReader: ReferenceReader<HeapInstance>,
private val objectArrayReferenceReader: ReferenceReader<HeapObjectArray>,
) : ReferenceReader<HeapObject> {
override fun read(source: HeapObject): Sequence<Reference> {
return when(source) {
is HeapClass -> classReferenceReader.read(source)
is HeapInstance -> instanceReferenceReader.read(source)
is HeapObjectArray -> objectArrayReferenceReader.read(source)
is HeapPrimitiveArray -> emptySequence()
}
}
}