/** * Builds a new SizeOf that will filter fields according to the provided filter * @param fieldFilter The filter to apply * @param caching whether to cache reflected fields * @see SizeOfFilter */ public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
nullSafeAdd(toVisit, object); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled() && object != null) { traversalDebugMessage.append(object.getClass().getName()) warned = checkMaxDepth(maxDepth, abortWhenMaxDepthExceeded, warned, visited); if (!isSharedFlyweight(ref) && shouldWalkClass(refClass)) { if (refClass.isArray() && !refClass.getComponentType().isPrimitive()) { for (int i = 0; i < Array.getLength(ref); i++) { nullSafeAdd(toVisit, Array.get(ref, i)); for (Field field : getFilteredFields(refClass)) { try { nullSafeAdd(toVisit, field.get(ref)); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); long visitSize = calculateSize(ref); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { traversalDebugMessage.append(" ").append(visitSize).append("b\t\t")
/** * Returns the filtered fields for a particular type * * @param refClass the type * @return A collection of fields to be visited */ private Collection<Field> getFilteredFields(Class<?> refClass) { SoftReference<Collection<Field>> ref = fieldCache.get(refClass); Collection<Field> fieldList = ref != null ? ref.get() : null; if (fieldList != null) { return fieldList; } else { Collection<Field> result; result = sizeOfFilter.filterFields(refClass, getAllFields(refClass)); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { for (Field field : result) { if (Modifier.isTransient(field.getModifiers())) { LOG.debug("SizeOf engine walking transient field '{}' of class {}", field.getName(), refClass.getName()); } } } fieldCache.put(refClass, new SoftReference<Collection<Field>>(result)); return result; } }
/** * Measures the size in memory (heap) of the objects passed in, walking their graph down * Any overlap of the graphs being passed in will be recognized and only measured once * * @param maxDepth maximum depth of the object graph to traverse * @param abortWhenMaxDepthExceeded true if the object traversal should be aborted when the max depth is exceeded * @param obj the root objects of the graphs to measure * @return the total size in bytes for these objects * @see #sizeOf(Object) */ public Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj) { return new Size(walker.walk(maxDepth, abortWhenMaxDepthExceeded, obj), true); }
/** * Measures the size in memory (heap) of the objects passed in, walking their graph down * Any overlap of the graphs being passed in will be recognized and only measured once * * @param maxDepth maximum depth of the object graph to traverse * @param abortWhenMaxDepthExceeded true if the object traversal should be aborted when the max depth is exceeded * @param obj the root objects of the graphs to measure * @return the total size in bytes for these objects * @see #sizeOf(Object) */ public Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj) { return new Size(walker.walk(maxDepth, abortWhenMaxDepthExceeded, obj), true); }
nullSafeAdd(toVisit, object); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled() && object != null) { traversalDebugMessage.append(object.getClass().getName()) warned = checkMaxDepth(maxDepth, abortWhenMaxDepthExceeded, warned, visited); if (!isSharedFlyweight(ref) && shouldWalkClass(refClass)) { if (refClass.isArray() && !refClass.getComponentType().isPrimitive()) { for (int i = 0; i < Array.getLength(ref); i++) { nullSafeAdd(toVisit, Array.get(ref, i)); for (Field field : getFilteredFields(refClass)) { try { nullSafeAdd(toVisit, field.get(ref)); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); long visitSize = calculateSize(ref); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { traversalDebugMessage.append(" ").append(visitSize).append("b\t\t")
/** * Builds a new SizeOf that will filter fields according to the provided filter * @param fieldFilter The filter to apply * @param caching whether to cache reflected fields * @see SizeOfFilter */ public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
/** * Measures the size in memory (heap) of the objects passed in, walking their graph down * Any overlap of the graphs being passed in will be recognized and only measured once * * @param maxDepth maximum depth of the object graph to traverse * @param abortWhenMaxDepthExceeded true if the object traversal should be aborted when the max depth is exceeded * @param obj the root objects of the graphs to measure * @return the total size in bytes for these objects * @see #sizeOf(Object) */ public Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj) { return new Size(walker.walk(maxDepth, abortWhenMaxDepthExceeded, obj), true); }
/** * Returns the filtered fields for a particular type * * @param refClass the type * @return A collection of fields to be visited */ private Collection<Field> getFilteredFields(Class<?> refClass) { SoftReference<Collection<Field>> ref = fieldCache.get(refClass); Collection<Field> fieldList = ref != null ? ref.get() : null; if (fieldList != null) { return fieldList; } else { Collection<Field> result; result = sizeOfFilter.filterFields(refClass, getAllFields(refClass)); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { for (Field field : result) { if (Modifier.isTransient(field.getModifiers())) { LOG.debug("SizeOf engine walking transient field '{}' of class {}", field.getName(), refClass.getName()); } } } fieldCache.put(refClass, new SoftReference<Collection<Field>>(result)); return result; } }
nullSafeAdd(toVisit, object); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled() && object != null) { traversalDebugMessage.append(object.getClass().getName()) warned = checkMaxDepth(maxDepth, abortWhenMaxDepthExceeded, warned, visited); if (!isSharedFlyweight(ref) && shouldWalkClass(refClass)) { if (refClass.isArray() && !refClass.getComponentType().isPrimitive()) { for (int i = 0; i < Array.getLength(ref); i++) { nullSafeAdd(toVisit, Array.get(ref, i)); for (Field field : getFilteredFields(refClass)) { try { nullSafeAdd(toVisit, field.get(ref)); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); long visitSize = calculateSize(ref); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { traversalDebugMessage.append(" ").append(visitSize).append("b\t\t")
/** * Builds a new SizeOf that will filter fields according to the provided filter * @param fieldFilter The filter to apply * @param caching whether to cache reflected fields * @see SizeOfFilter */ public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
/** * Measures the size in memory (heap) of the objects passed in, walking their graph down * Any overlap of the graphs being passed in will be recognized and only measured once * * @param maxDepth maximum depth of the object graph to traverse * @param abortWhenMaxDepthExceeded true if the object traversal should be aborted when the max depth is exceeded * @param obj the root objects of the graphs to measure * @return the total size in bytes for these objects * @see #sizeOf(Object) */ public Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj) { try { return new Size(walker.walk(maxDepth, abortWhenMaxDepthExceeded, obj), true); } catch (MaxDepthExceededException e) { LOG.warn(e.getMessage()); return new Size(e.getMeasuredSize(), false); } }
/** * Returns the filtered fields for a particular type * * @param refClass the type * @return A collection of fields to be visited */ private Collection<Field> getFilteredFields(Class<?> refClass) { SoftReference<Collection<Field>> ref = fieldCache.get(refClass); Collection<Field> fieldList = ref != null ? ref.get() : null; if (fieldList != null) { return fieldList; } else { Collection<Field> result; result = sizeOfFilter.filterFields(refClass, getAllFields(refClass)); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { for (Field field : result) { if (Modifier.isTransient(field.getModifiers())) { LOG.debug("SizeOf engine walking transient field '{}' of class {}", field.getName(), refClass.getName()); } } } fieldCache.put(refClass, new SoftReference<Collection<Field>>(result)); return result; } }
nullSafeAdd(toVisit, object); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled() && object != null) { traversalDebugMessage.append(object.getClass().getName()) warned = checkMaxDepth(maxDepth, abortWhenMaxDepthExceeded, warned, visited); if (!isSharedFlyweight(ref) && shouldWalkClass(refClass)) { if (refClass.isArray() && !refClass.getComponentType().isPrimitive()) { for (int i = 0; i < Array.getLength(ref); i++) { nullSafeAdd(toVisit, Array.get(ref, i)); for (Field field : getFilteredFields(refClass)) { try { nullSafeAdd(toVisit, field.get(ref)); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); long visitSize = calculateSize(ref); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { traversalDebugMessage.append(" ").append(visitSize).append("b\t\t")
/** * Builds a new SizeOf that will filter fields according to the provided filter * @param fieldFilter The filter to apply * @param caching whether to cache reflected fields * @see SizeOfFilter */ public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
/** * Returns the filtered fields for a particular type * * @param refClass the type * @return A collection of fields to be visited */ private Collection<Field> getFilteredFields(Class<?> refClass) { SoftReference<Collection<Field>> ref = fieldCache.get(refClass); Collection<Field> fieldList = ref != null ? ref.get() : null; if (fieldList != null) { return fieldList; } else { Collection<Field> result; result = sizeOfFilter.filterFields(refClass, getAllFields(refClass)); if (USE_VERBOSE_DEBUG_LOGGING && LOG.isDebugEnabled()) { for (Field field : result) { if (Modifier.isTransient(field.getModifiers())) { LOG.debug("SizeOf engine walking transient field '{}' of class {}", field.getName(), refClass.getName()); } } } fieldCache.put(refClass, new SoftReference<Collection<Field>>(result)); return result; } }