6.6.8.1.8.1. Introspector

public class Introspector

This class could be used for any object contents/memory layout printing. How shall we find a memory layout of an object?

  • Obtain all object fields, including its parent class fields, recursively calling Class.getDeclaredFields on the class and its superclasses.
  • For all non-static fields (Field.getModifiers() & Modifiers.STATIC) obtain an offset of a field in its parent object using Unsafe.objectFieldOffset and a shallow field size : predefined values for primitives and either 4 or 8 bytes for object references.
  • For arrays, call Unsafe.arrayBaseOffset and Unsafe.arrayIndexScale. The total shallow size of an array would be offset + scale * Array.getLength(array) and, of course, a reference to the array itself (see previous point).
  • Do not forget that there may be a circular references in the object graph, so you will need to track all previously visited objects (IdentityHashMap is recommended for such cases).
Author:© quasardb - 2014

6.6.8.1.8.1.1. Methods

6.6.8.1.8.1.1.1. introspect

public ObjectInfo introspect(Object obj)

Get object information for any Java object. Do not pass primitives to this method because they will boxed and the information you will get will be related to a boxed version of your value.

Parameters:
  • obj – Object to introspect
Throws:
Returns:

Object info

Table Of Contents

Previous topic

6.6.8.1.8. com.b14.qdb.tools.profiler

Next topic

6.6.8.1.8.2. ObjectInfo