private static void addHardcodedEstimators(HashMap<Class<?>, ObjectEstimator> byType) { // Add hacks for well-known collections and maps to avoid estimating them. byType.put(ArrayList.class, new CollectionEstimator(memoryModel.arrayList(), memoryModel.ref())); byType.put(LinkedList.class, new CollectionEstimator(memoryModel.linkedListBase(), memoryModel.linkedListEntry())); byType.put(HashSet.class, new CollectionEstimator(memoryModel.hashSetBase(), memoryModel.hashSetEntry())); byType.put(HashMap.class, new CollectionEstimator(memoryModel.hashMapBase(), memoryModel.hashMapEntry())); }
@Override protected int estimate(Object obj, HashMap<Class<?>, ObjectEstimator> parent, IdentityHashMap<Object, Boolean> uniqueObjects) { if (obj instanceof Collection<?>) { Collection<?> c = (Collection<?>) obj; int overhead = estimateOverhead(c.size()), elements = estimateCollectionElements(parent, c, null, uniqueObjects); return overhead + elements + memoryModel.object(); } else if (obj instanceof Map<?, ?>) { Map<?, ?> m = (Map<?, ?>) obj; int overhead = estimateOverhead(m.size()), elements = estimateMapElements(parent, m, null, uniqueObjects); return overhead + elements + memoryModel.object(); } throw new AssertionError(obj.getClass().getName()); }
referencedSize += memoryModel.object(); referencedSize += estimateCollectionElements(parent, c, e.field, uniqueObjects); referencedSize += ((CollectionEstimator) collEstimator).estimateOverhead(c.size()); } else { referencedSize += memoryModel.object(); referencedSize += estimateMapElements(parent, m, e.field, uniqueObjects); referencedSize += ((CollectionEstimator) collEstimator).estimateOverhead(m.size()); } else {
@Override protected int estimate(Object obj, HashMap<Class<?>, ObjectEstimator> parent, IdentityHashMap<Object, Boolean> uniqueObjects) { if (obj instanceof Collection<?>) { Collection<?> c = (Collection<?>) obj; int overhead = estimateOverhead(c.size()), elements = estimateCollectionElements(parent, c, null, uniqueObjects); return overhead + elements + memoryModel.object(); } else if (obj instanceof Map<?, ?>) { Map<?, ?> m = (Map<?, ?>) obj; int overhead = estimateOverhead(m.size()), elements = estimateMapElements(parent, m, null, uniqueObjects); return overhead + elements + memoryModel.object(); } throw new AssertionError(obj.getClass().getName()); }
private static void addHardcodedEstimators(HashMap<Class<?>, ObjectEstimator> byType) { // Add hacks for well-known collections and maps to avoid estimating them. byType.put(ArrayList.class, new CollectionEstimator(memoryModel.arrayList(), memoryModel.ref())); byType.put(LinkedList.class, new CollectionEstimator(memoryModel.linkedListBase(), memoryModel.linkedListEntry())); byType.put(HashSet.class, new CollectionEstimator(memoryModel.hashSetBase(), memoryModel.hashSetEntry())); byType.put(HashMap.class, new CollectionEstimator(memoryModel.hashMapBase(), memoryModel.hashMapEntry())); }
referencedSize += memoryModel.object(); referencedSize += estimateCollectionElements(parent, c, e.field, uniqueObjects); referencedSize += ((CollectionEstimator) collEstimator).estimateOverhead(c.size()); } else { referencedSize += memoryModel.object(); referencedSize += estimateMapElements(parent, m, e.field, uniqueObjects); referencedSize += ((CollectionEstimator) collEstimator).estimateOverhead(m.size()); } else {