@Test public void testSizeOf() throws Exception { Assume.assumeThat(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), is(CURRENT_JVM_INFORMATION.getObjectAlignment())); SizeOf sizeOf = new CrossCheckingSizeOf(); String version = System.getProperty("java.version"); if (version.startsWith("1.5")) { if (IS_64_BIT) { verify64bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(136L)); } else { verify32bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(80L)); } } else if (version.startsWith("1.6")) { if (IS_64_BIT) { if (IS_JROCKIT) { verify64bitJRockit4GBCompressedRefsSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(144L)); } else if (IS_IBM) { verify64bitIBMSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(224L)); } else if (COMPRESSED_OOPS) { verify64bitCompressedOopsSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(112L)); } else { verify64bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(176L)); } } else if (IS_IBM) { verify32bitIBMSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(112L)); } else if (IS_JROCKIT) { verify32bitJRockitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(144L)); } else { verify32bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(104L)); } } else if (version.startsWith("1.7")) { if (IS_64_BIT) { if (COMPRESSED_OOPS) { verify64bitCompressedOopsSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(120L)); } else { verify64bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(192L)); } } else { verify32bitSizes(sizeOf); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), is(112L)); } } else { Assert.fail(); } List<Object> list1 = new ArrayList<Object>(); List<Object> list2 = new ArrayList<Object>(); Object someInstance = new Object(); list1.add(someInstance); list2.add(someInstance); assertThat(deepSizeOf(sizeOf, list1), is(deepSizeOf(sizeOf, list2))); assertThat(deepSizeOf(sizeOf, list1, list2) < (deepSizeOf(sizeOf, list1) + deepSizeOf(sizeOf, list2)), is(true)); list2.add(new Object()); assertThat(deepSizeOf(sizeOf, list2) > deepSizeOf(sizeOf, list1), is(true)); }
public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); abstract long sizeOf(Object obj); Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); abstract long sizeOf(Object obj); Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj);  }