private static long getObjectSize(Object obj, boolean isArray, Instrumentation instr) {
    if (isArray) {
      return instr.getObjectSize(obj);
    }

    try {
      return classSizesCache.get(obj.getClass(), () -> instr.getObjectSize(obj));
    } catch (ExecutionException e) {
      throw new RuntimeException(e);
    }
  }
Returns the size of the given object. If the object is not an array, we check the cache first,
and update it as necessary.

@param obj the object.
@param isArray indicates if the given object is an array.
@param instr the instrumentation object to use for finding the object size
@return the size of the given object.
src/main/java/com/google/monitoring/runtime/instrumentation/AllocationRecorder.java