Package com.linkedin.venice.memory
Class ClassSizeEstimator
- java.lang.Object
-
- com.linkedin.venice.memory.ClassSizeEstimator
-
public class ClassSizeEstimator extends java.lang.Object
Utility class to help in implementingMeasurable.getHeapSize()
. A couple of important points: 1. This utility class does not "measure" the heap size, but rather attempts to "predict" it, based on knowledge of the internals of the JVM. If any of the assumptions are wrong, then of course the results will be inaccurate. 2. This utility class assumes we are using the HotSpot JVM.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getClassOverhead(java.lang.Class<?> c)
This function provides the "shallow size" of each instance of the given class, meaning that all pointers are considered to be null.
-
-
-
Method Detail
-
getClassOverhead
public static int getClassOverhead(@Nonnull java.lang.Class<?> c)
This function provides the "shallow size" of each instance of the given class, meaning that all pointers are considered to be null. Intended usage: This function is a helper to make it easier to implementMeasurable.getHeapSize()
. It should not be called on the hot path. Rather, it should be called at most once per JVM runtime per class of interest and the result should be stored in a static field. If an instance of a measured class contains only primitive fields or all its non-primitive fields are null, then the result of this function is effectively the heap size of that instance. If these conditions are not true, then a function should be implemented which uses this class overhead as a base and then adds the size of any referenced Objects. For example, seeInstanceSizeEstimator.getObjectSize(Object)
.- Parameters:
c
- TheClass
for which to predict the "shallow overhead", as defined above.- Returns:
- The base overhead of the class, which can be any positive number (including zero).
-
-