Package org.objectweb.asm.tree.analysis
Class ComputeLimits
java.lang.Object
org.objectweb.asm.tree.analysis.ComputeLimits
Memory and time limits for potentially costly algorithms.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intThe size in bytes of the header of an array (class pointer, array length, etc).(package private) static final intThe size in bytes of the header of an object (class pointer, etc).private intThe remaining number of bytes which can be allocated by the algorithm using these limits.private longThe remaining number of "operations" which can be done by the algorithm using these limits.private static final StringError message when the memory limit is exceeded. -
Constructor Summary
ConstructorsConstructorDescriptionComputeLimits(int maxBytes, long maxOperations) Constructs new compute limits.ComputeLimits(ComputeLimits limits) Constructs a copy of the given compute limits. -
Method Summary
Modifier and TypeMethodDescription(package private) boolean[]checkNewBooleanArray(int length) Creates a new boolean array if this does not exceed the memory limits.(package private) voidcheckNewBytes(int numBytes) Checks if some bytes can be allocated without exceeding the limit.(package private) Object[]checkNewObjectArray(int length) Creates a new object array if this does not exceed the memory limits.(package private) voidcheckNewOperations(long numOperations) Checks if some operations can be done without exceeding the limit.
-
Field Details
-
TOO_MANY_ALLOCATED_BYTES
Error message when the memory limit is exceeded.- See Also:
-
OBJECT_HEADER_BYTES
static final int OBJECT_HEADER_BYTESThe size in bytes of the header of an object (class pointer, etc).- See Also:
-
ARRAY_HEADER_BYTES
static final int ARRAY_HEADER_BYTESThe size in bytes of the header of an array (class pointer, array length, etc).- See Also:
-
remainingBytes
private int remainingBytesThe remaining number of bytes which can be allocated by the algorithm using these limits. -
remainingOperations
private long remainingOperationsThe remaining number of "operations" which can be done by the algorithm using these limits.
-
-
Constructor Details
-
ComputeLimits
ComputeLimits(int maxBytes, long maxOperations) Constructs new compute limits.- Parameters:
maxBytes- the maximum number of bytes which can be allocated.maxOperations- the maximum number of "operations" which can be done. The definition of an operation depends on the algorithms using these limits. The number of operations done by an algorithm should be approximatively proportional to its runtime (and deterministic).
-
ComputeLimits
ComputeLimits(ComputeLimits limits) Constructs a copy of the given compute limits.- Parameters:
limits- the limits to copy.
-
-
Method Details
-
checkNewBooleanArray
boolean[] checkNewBooleanArray(int length) Creates a new boolean array if this does not exceed the memory limits.- Parameters:
length- the array length (number of elements).- Returns:
- the newly created array.
- Throws:
LimitExceededException- if the memory limit is exceeded.
-
checkNewObjectArray
Creates a new object array if this does not exceed the memory limits.- Parameters:
length- the array length (number of elements).- Returns:
- the newly created array.
- Throws:
LimitExceededException- if the memory limit is exceeded.
-
checkNewBytes
void checkNewBytes(int numBytes) Checks if some bytes can be allocated without exceeding the limit.- Parameters:
numBytes- the number of bytes to allocate.- Throws:
LimitExceededException- if the memory limit is exceeded.
-
checkNewOperations
void checkNewOperations(long numOperations) Checks if some operations can be done without exceeding the limit.- Parameters:
numOperations- the number of operations to perform.- Throws:
LimitExceededException- if the operations limit is exceeded.
-