Class ComputeLimits

java.lang.Object
org.objectweb.asm.tree.analysis.ComputeLimits

final class ComputeLimits extends Object
Memory and time limits for potentially costly algorithms.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final int
    The size in bytes of the header of an array (class pointer, array length, etc).
    (package private) static final int
    The size in bytes of the header of an object (class pointer, etc).
    private int
    The remaining number of bytes which can be allocated by the algorithm using these limits.
    private long
    The remaining number of "operations" which can be done by the algorithm using these limits.
    private static final String
    Error message when the memory limit is exceeded.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ComputeLimits(int maxBytes, long maxOperations)
    Constructs new compute limits.
    Constructs a copy of the given compute limits.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) boolean[]
    Creates a new boolean array if this does not exceed the memory limits.
    (package private) void
    checkNewBytes(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) void
    checkNewOperations(long numOperations)
    Checks if some operations can be done without exceeding the limit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TOO_MANY_ALLOCATED_BYTES

      private static final String TOO_MANY_ALLOCATED_BYTES
      Error message when the memory limit is exceeded.
      See Also:
    • OBJECT_HEADER_BYTES

      static final int OBJECT_HEADER_BYTES
      The size in bytes of the header of an object (class pointer, etc).
      See Also:
    • ARRAY_HEADER_BYTES

      static final int ARRAY_HEADER_BYTES
      The size in bytes of the header of an array (class pointer, array length, etc).
      See Also:
    • remainingBytes

      private int remainingBytes
      The remaining number of bytes which can be allocated by the algorithm using these limits.
    • remainingOperations

      private long remainingOperations
      The 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

      Object[] checkNewObjectArray(int length)
      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.