Package ru.ispras.microtesk.model.memory
Class MemoryAllocator
- java.lang.Object
-
- ru.ispras.microtesk.model.memory.MemoryAllocator
-
public final class MemoryAllocator extends java.lang.Object
The job of the MemoryAllocator class is to place data in the memory storage.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MemoryAllocator(MemoryDevice memory, int addressableUnitBitSize, java.math.BigInteger baseAddress)
Constructs a memory allocator object with the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.math.BigInteger
alignAddress(java.math.BigInteger address, int alignment)
Aligns the specified address by the specified length and returns the resulting aligned address.ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocate(java.math.BigInteger currentAddress, java.util.List<ru.ispras.fortress.data.types.bitvector.BitVector> data)
Allocates memory in the memory storage to hold data elements in the specified list and return the address (in addressable units) of the first element.ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data)
Allocates memory in the memory storage to hold the specified data and returns its address (in addressable units).ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector... data)
Allocates memory in the memory storage to hold data elements provided as arguments and return the address (in addressable units) of the first element.ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data, boolean align)
Allocates memory in the memory storage to hold the specified data and returns its address (in addressable units).ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data, int count)
Allocates memory in the memory storage to hold the specified number of the specified data and returns the address (in addressable units) of the first element.void
allocateAt(java.math.BigInteger address, ru.ispras.fortress.data.types.bitvector.BitVector data)
ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger>
allocateString(java.math.BigInteger currentAddress, java.lang.String string, boolean zeroTerm)
Allocates memory in the memory storage to store the specified string converted to the ASCII encoding and returns the address of string.int
bitsToAddressableUnits(int bitSize)
Returns the minimal number of addressable units required to store data of the specified size (in bits).int
getAddressableUnitBitSize()
Returns the size of an addressable unit.int
getAddressableUnitsInRegion()
Returns the number of addressable units in a memory region.int
getAddressBitSize()
java.math.BigInteger
getBaseAddress()
int
getRegionBitSize()
Returns the size of memory regions stored in the memory storage.void
reset()
void
setBaseAddress(java.math.BigInteger value)
java.lang.String
toString()
-
-
-
Constructor Detail
-
MemoryAllocator
protected MemoryAllocator(MemoryDevice memory, int addressableUnitBitSize, java.math.BigInteger baseAddress)
Constructs a memory allocator object with the specified parameters. Important precondition: memory region size must be a multiple of addressable unit size.- Parameters:
memory
- Memory storage to store the data.addressableUnitBitSize
- Size of an addressable unit in bits.baseAddress
- Address where allocation starts.- Throws:
java.lang.IllegalArgumentException
- if thememory
parameter isnull
; if the specified size of an addressable unit is negative or is not a divisor of memory region size.
-
-
Method Detail
-
alignAddress
public static java.math.BigInteger alignAddress(java.math.BigInteger address, int alignment)
Aligns the specified address by the specified length and returns the resulting aligned address.- Parameters:
address
- Address to be aligned.alignment
- Alignment length.- Returns:
- Aligned address.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters is negative.
-
getBaseAddress
public java.math.BigInteger getBaseAddress()
-
setBaseAddress
public void setBaseAddress(java.math.BigInteger value)
-
reset
public void reset()
-
getAddressableUnitBitSize
public int getAddressableUnitBitSize()
Returns the size of an addressable unit.- Returns:
- Size of an addressable unit in bits.
-
getRegionBitSize
public int getRegionBitSize()
Returns the size of memory regions stored in the memory storage.- Returns:
- Bit size of memory regions stored in the memory storage.
-
getAddressableUnitsInRegion
public int getAddressableUnitsInRegion()
Returns the number of addressable units in a memory region.- Returns:
- Number of addressable units in a memory region
-
getAddressBitSize
public int getAddressBitSize()
-
allocate
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data)
Allocates memory in the memory storage to hold the specified data and returns its address (in addressable units). The data is aligned in the memory by its size (in addressable units). Space between allocations is filled with zeros.- Parameters:
currentAddress
- Current address.data
- Data to be stored in the memory storage.- Returns:
- Address of the allocated memory (in addressable units) and the current address.
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
allocate
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data, boolean align)
Allocates memory in the memory storage to hold the specified data and returns its address (in addressable units). The data may be aligned in the memory by its size (in addressable units). Space between allocations is filled with zeros.- Parameters:
currentAddress
- Current address.data
- Data to be stored in the memory storage.align
- Alignment flag.- Returns:
- Address of the allocated memory (in addressable units) and the current address.
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
allocate
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector data, int count)
Allocates memory in the memory storage to hold the specified number of the specified data and returns the address (in addressable units) of the first element. The data is aligned in the memory by its size (in addressable units). Space between allocations is filled with zeros.- Parameters:
currentAddress
- Current address.data
- Data to be placed in the memory storage.count
- Number of copies to be placed in the memory storage.- Returns:
- Address of the allocated memory (in addressable units) and the current address.
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
allocate
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocate(java.math.BigInteger currentAddress, ru.ispras.fortress.data.types.bitvector.BitVector... data)
Allocates memory in the memory storage to hold data elements provided as arguments and return the address (in addressable units) of the first element. The data is aligned in memory by the size of data elements (in addressable units). Space between allocations (if any is left) is filled with zeros.- Parameters:
currentAddress
- Current address.data
- Collection of data elements to be stored in the memory storage.- Returns:
- Address of the first allocated element and the current address.
- Throws:
java.lang.IllegalArgumentException
- if the list is empty or it list elements have different sizes.
-
allocate
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocate(java.math.BigInteger currentAddress, java.util.List<ru.ispras.fortress.data.types.bitvector.BitVector> data)
Allocates memory in the memory storage to hold data elements in the specified list and return the address (in addressable units) of the first element. The data is aligned in memory by the size of data elements (in addressable units). Space between allocations (if any is left) is filled with zeros.- Parameters:
currentAddress
- Current address.data
- Collection of data elements to be stored in the memory storage.- Returns:
- Address of the first allocated element and the current address.
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
; if the list is empty or it list elements have different sizes.
-
allocateAt
public void allocateAt(java.math.BigInteger address, ru.ispras.fortress.data.types.bitvector.BitVector data)
-
allocateString
public ru.ispras.fortress.util.Pair<java.math.BigInteger,java.math.BigInteger> allocateString(java.math.BigInteger currentAddress, java.lang.String string, boolean zeroTerm)
Allocates memory in the memory storage to store the specified string converted to the ASCII encoding and returns the address of string. The ASCII string is copied to memory byte by byte so that each character could be addressable. Therefore, each byte is aligned by the boundary of an addressable units. If any space is left between characters, it is filled with zeros.- Parameters:
currentAddress
- Current address.string
- String to be placed in the memory.zeroTerm
- Specifies whether the string must be terminated with zero.- Returns:
- Address of the allocated ASCII string (in addressable units) and the current address.
- Throws:
java.lang.IllegalArgumentException
- if thestring
parameter equalsnull
; if failed to convert the string to the "US-ASCII" encoding.
-
bitsToAddressableUnits
public int bitsToAddressableUnits(int bitSize)
Returns the minimal number of addressable units required to store data of the specified size (in bits).- Parameters:
bitSize
- Size in bits.- Returns:
- Size in addressable units.
- Throws:
java.lang.IllegalArgumentException
- if thebitSize
argument is 0 or negative.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-