public synchronized long calculateObjectSize(Object obj) {
    // Breadth-first traversal instead of naive depth-first with recursive
    // implementation, so we don't blow the stack traversing long linked lists.
    boolean init = true;
    try {
      for (;;) {
        visit(obj, init);
        init = false;
        if (mPending.isEmpty()) {
          return mSize;
        }
        obj = mPending.removeFirst();
      }
    } finally {
      mVisited.clear();
      mPending.clear();
      mSize = 0;
    }
  }
@Test
  public void testConstantMap() {
    Map<Long, CompositeObject> test = new ConcurrentHashMap<>();
    for (long i = 0; i < 4; i++) {
      test.put(i, new CompositeObject());
    }
    long size = mObjectSizeCalculator.calculateObjectSize(test);
    Set<Class<?>> testSet = new HashSet<>();
    testSet.add(CompositeObject.class);
    testSet.add(Long.class);
    ObjectSizeCalculator constantCalc = new ObjectSizeCalculator(
        MEMORY_LAYOUT_SPECIFICATION, testSet);
    assertEquals(size, constantCalc.calculateObjectSize(test));
  }