Top Fields Constructors Methods
org.apache.derby.iapi.services.cache

public Class ClassSize

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, java.lang.reflect.Field, .Modifier, java.util.Arrays

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static boolean
private static final int
private static final int
private static final int
private static final int
pack-priv static boolean
private static final int
public static final int
private static final int
pack-priv static boolean
private static final int[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the size estimate, in bytes
estimateAndCatalogBase
(Class<T>
the class
cls
)

Estimate the static space taken up by a class instance.

public static int

Returns:

the estimated overhead of an array. The estimated size of an x[n] array is estimateArrayOverhead() + n*sizeOf(x).
estimateArrayOverhead
()

public static int

Returns:

the size estimate in bytes.
estimateBase
(Class<T>
A class
cl
)

Estimate the static space taken up by the fields of a class.

public static int

Returns:

the size estimate, in bytes
estimateBaseFromCatalog
(Class<T>
the class
cls
)

Estimate the static space taken up by a class instance from cataloged coefficients.

private static int
estimateBaseFromCatalog(Class<?> cls, boolean addToCatalog)

public static int

Returns:

the size estimate, in bytes
estimateBaseFromCoefficients
(int[]
the coefficients
coeff
)

Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.

public static int

Returns:

the estimate, in bytes
estimateHashEntrySize
()

Estimate the size of a Hashtable entry.

public static int

Returns:

the estimated size, in bytes
estimateMemoryUsage
(String
The string
str
)

Estimate the size of a string.

private static final int

Returns:

The reference size in bytes as specified or implied by the VM, or -1 if the reference size couldn't be determined.
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.

public static int

Returns:

the estimate of the size of a primitive int
getIntSize
()

public static int

Returns:

the estimate in bytes.
getRefSize
()

Get the estimate of the size of an object reference.

public static int[]

Returns:

an array of 2 integers. The first integer is the constant part of the function, the second is the reference size coefficient.
getSizeCoefficients
(Class<T>
A class whose instance size is to be estimated
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 final String

Returns:

The property value, or null if it doesn't exist or the required permission to read the property is missing.
getSystemProperty
(final String
name of the system property to read
propName
)

Attempts to read the specified system property.

private static void
runFinalization(Runtime runtime)

This method exists merely to suppress the "removal" warning.

public static void
setDummyCatalog()

do not try to use the catalog.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

booleanSizeback to summary
private static final int booleanSize
charSizeback to summary
private static final int charSize
doubleSizeback to summary
private static final int doubleSize
dummyCatalogback to summary
private static boolean dummyCatalog
floatSizeback to summary
private static final int floatSize
intSizeback to summary
private static final int intSize
longSizeback to summary
private static final int longSize
minObjectSizeback to summary
private static final int minObjectSize
noGuessback to summary
pack-priv static boolean noGuess
objectOverheadback to summary
private static final int objectOverhead
refSizeback to summary
public static final int refSize
shortSizeback to summary
private static final int shortSize
unitTestback to summary
pack-priv static boolean unitTest
wildGuessback to summary
private static final int[] wildGuess

Constructor Detail

ClassSizeback to summary
public ClassSize()

Method Detail

estimateAndCatalogBaseback to summary
public static int estimateAndCatalogBase(Class<T> cls)

Estimate the static space taken up by a class instance. Save the coefficients in a catalog.

Parameters
cls:Class<T>

the class

Returns:int

the size estimate, in bytes

See Also
estimateBaseFromCoefficients, see org.apache.derbyBuild.ClassSizeCrawler
estimateArrayOverheadback to summary
public static int estimateArrayOverhead()
Returns:int

the estimated overhead of an array. The estimated size of an x[n] array is estimateArrayOverhead() + n*sizeOf(x).

estimateBaseback to summary
public static int estimateBase(Class<T> 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.

Parameters
cl:Class<T>

A class

Returns:int

the size estimate in bytes.

See Also
estimateBaseFromCatalog
estimateBaseFromCatalogback to summary
public static int estimateBaseFromCatalog(Class<T> cls)

Estimate the static space taken up by a class instance from cataloged coefficients.

Parameters
cls:Class<T>

the class

Returns:int

the size estimate, in bytes

See Also
estimateBaseFromCoefficients, see org.apache.derbyBuild.ClassSizeCrawler
estimateBaseFromCatalogback to summary
private static int estimateBaseFromCatalog(Class<?> cls, boolean addToCatalog)
estimateBaseFromCoefficientsback to summary
public static int estimateBaseFromCoefficients(int[] coeff)

Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.

Parameters
coeff:int[]

the coefficients

Returns:int

the size estimate, in bytes

estimateHashEntrySizeback to summary
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:int

the estimate, in bytes

estimateMemoryUsageback to summary
public static int estimateMemoryUsage(String str)

Estimate the size of a string.

Parameters
str:String

The string

Returns:int

the estimated size, in bytes

fetchRefSizeFromSystemPropertiesback to summary
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:int

The reference size in bytes as specified or implied by the VM, or -1 if the reference size couldn't be determined.

getIntSizeback to summary
public static int getIntSize()
Returns:int

the estimate of the size of a primitive int

getRefSizeback to summary
public static int getRefSize()

Get the estimate of the size of an object reference.

Returns:int

the estimate in bytes.

getSizeCoefficientsback to summary
public static int[] getSizeCoefficients(Class<T> 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:Class<T>

A class whose instance size is to be estimated

Returns:int[]

an array of 2 integers. The first integer is the constant part of the function, the second is the reference size coefficient.

getSystemPropertyback to summary
private static final String getSystemProperty(final String propName)

Attempts to read the specified system property.

Parameters
propName:String

name of the system property to read

Returns:String

The property value, or null if it doesn't exist or the required permission to read the property is missing.

runFinalizationback to summary
private static void runFinalization(Runtime runtime)

This method exists merely to suppress the "removal" warning.

Annotations
@SuppressWarnings:deprecation, removal
setDummyCatalogback to summary
public static void setDummyCatalog()

do not try to use the catalog.