Class ClassSize
- java.lang.Object
-
- org.apache.derby.iapi.services.cache.ClassSize
-
public class ClassSize extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static intbooleanSizeprivate static intcharSizeprivate static intdoubleSizeprivate static booleandummyCatalogprivate static intfloatSizeprivate static intintSizeprivate static intlongSizeprivate static intminObjectSize(package private) static booleannoGuessprivate static intobjectOverheadstatic intrefSizeprivate static intshortSize(package private) static booleanunitTestprivate static int[]wildGuess
-
Constructor Summary
Constructors Constructor Description ClassSize()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intestimateAndCatalogBase(java.lang.Class cls)Estimate the static space taken up by a class instance.static intestimateArrayOverhead()static intestimateBase(java.lang.Class cl)Estimate the static space taken up by the fields of a class.static intestimateBaseFromCatalog(java.lang.Class cls)Estimate the static space taken up by a class instance from cataloged coefficients.private static intestimateBaseFromCatalog(java.lang.Class<?> cls, boolean addToCatalog)static intestimateBaseFromCoefficients(int[] coeff)Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.static intestimateHashEntrySize()Estimate the size of a Hashtable entry.static intestimateMemoryUsage(java.lang.String str)Estimate the size of a string.private static intfetchRefSizeFromSystemProperties()Tries to determine the reference size in bytes by checking whether the VM we're running in is 32 or 64 bit by looking at the system properties.static intgetIntSize()static intgetRefSize()Get the estimate of the size of an object reference.static int[]getSizeCoefficients(java.lang.Class cl)The estimate of the size of a class instance depends on whether the JVM uses 32 or 64 bit addresses, that is it depends on the size of an object reference.private static java.lang.StringgetSystemProperty(java.lang.String propName)Attempts to read the specified system property.static voidsetDummyCatalog()do not try to use the catalog.
-
-
-
Field Detail
-
refSize
public static final int refSize
-
objectOverhead
private static final int objectOverhead
- See Also:
- Constant Field Values
-
booleanSize
private static final int booleanSize
- See Also:
- Constant Field Values
-
charSize
private static final int charSize
- See Also:
- Constant Field Values
-
shortSize
private static final int shortSize
- See Also:
- Constant Field Values
-
intSize
private static final int intSize
- See Also:
- Constant Field Values
-
longSize
private static final int longSize
- See Also:
- Constant Field Values
-
floatSize
private static final int floatSize
- See Also:
- Constant Field Values
-
doubleSize
private static final int doubleSize
- See Also:
- Constant Field Values
-
minObjectSize
private static final int minObjectSize
-
dummyCatalog
private static boolean dummyCatalog
-
noGuess
static boolean noGuess
-
unitTest
static boolean unitTest
-
wildGuess
private static final int[] wildGuess
-
-
Method Detail
-
setDummyCatalog
public static void setDummyCatalog()
do not try to use the catalog.
-
getRefSize
public static int getRefSize()
Get the estimate of the size of an object reference.- Returns:
- the estimate in bytes.
-
getIntSize
public static int getIntSize()
- Returns:
- the estimate of the size of a primitive int
-
getSizeCoefficients
public static int[] getSizeCoefficients(java.lang.Class cl)
The estimate of the size of a class instance depends on whether the JVM uses 32 or 64 bit addresses, that is it depends on the size of an object reference. It is a linear function of the size of a reference, e.g. 24 + 5*r where r is the size of a reference (usually 4 or 8 bytes). This method returns the coefficients of the linear function, e.g. {24, 5} in the above example.- Parameters:
cl- A class whose instance size is to be estimated- Returns:
- an array of 2 integers. The first integer is the constant part of the function, the second is the reference size coefficient.
-
estimateBaseFromCoefficients
public static int estimateBaseFromCoefficients(int[] coeff)
Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.- Parameters:
coeff- the coefficients- Returns:
- the size estimate, in bytes
-
estimateBaseFromCatalog
public static int estimateBaseFromCatalog(java.lang.Class cls)
Estimate the static space taken up by a class instance from cataloged coefficients.- Parameters:
cls- the class- Returns:
- the size estimate, in bytes
- See Also:
estimateBaseFromCoefficients(int[]),see org.apache.derbyBuild.ClassSizeCrawler
-
estimateBaseFromCatalog
private static int estimateBaseFromCatalog(java.lang.Class<?> cls, boolean addToCatalog)
-
estimateAndCatalogBase
public static int estimateAndCatalogBase(java.lang.Class cls)
Estimate the static space taken up by a class instance. Save the coefficients in a catalog.- Parameters:
cls- the class- Returns:
- the size estimate, in bytes
- See Also:
estimateBaseFromCoefficients(int[]),see org.apache.derbyBuild.ClassSizeCrawler
-
estimateBase
public static int estimateBase(java.lang.Class cl)
Estimate the static space taken up by the fields of a class. This includes the space taken up by by references (the pointer) but not by the referenced object. So the estimated size of an array field does not depend on the size of the array. Similarly the size of an object (reference) field does not depend on the object.- Returns:
- the size estimate in bytes. Note that this method will throw a SecurityException if the SecurityManager does not let this class execute the method Class.getDeclaredFields(). If this is a concern try to compute the size coefficients at build time. see org.apache.derbyBuild.ClassSizeCrawler
- See Also:
estimateBaseFromCatalog(java.lang.Class)
-
estimateArrayOverhead
public static int estimateArrayOverhead()
- Returns:
- the estimated overhead of an array. The estimated size of an x[n] array is estimateArrayOverhead() + n*sizeOf(x).
-
estimateHashEntrySize
public static int estimateHashEntrySize()
Estimate the size of a Hashtable entry. In Java 1.2 we can use Map.entry, but this is not available in earlier versions of Java.- Returns:
- the estimate, in bytes
-
estimateMemoryUsage
public static int estimateMemoryUsage(java.lang.String str)
Estimate the size of a string.- Returns:
- the estimated size, in bytes
-
fetchRefSizeFromSystemProperties
private static final int fetchRefSizeFromSystemProperties()
Tries to determine the reference size in bytes by checking whether the VM we're running in is 32 or 64 bit by looking at the system properties.- Returns:
- The reference size in bytes as specified or implied by the VM,
or
-1if the reference size couldn't be determined.
-
getSystemProperty
private static final java.lang.String getSystemProperty(java.lang.String propName)
Attempts to read the specified system property.- Parameters:
propName- name of the system property to read- Returns:
- The property value, or
nullif it doesn't exist or the required permission to read the property is missing.
-
-