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 Instance Methods Concrete Methods Modifier and Type Method Description void
align(java.math.BigInteger value)
java.math.BigInteger
allocate(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.java.math.BigInteger
allocate(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).java.math.BigInteger
allocate(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.java.math.BigInteger
allocate(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.java.math.BigInteger
allocateAsciiString(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.void
allocateAt(ru.ispras.fortress.data.types.bitvector.BitVector data, java.math.BigInteger address)
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()
java.math.BigInteger
getCurrentAddress()
int
getRegionBitSize()
Returns the size of memory regions stored in the memory storage.void
reset()
void
setBaseAddress(java.math.BigInteger value)
void
setCurrentAddress(java.math.BigInteger value)
void
setOrigin(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
-
getBaseAddress
public java.math.BigInteger getBaseAddress()
-
setBaseAddress
public void setBaseAddress(java.math.BigInteger value)
-
getCurrentAddress
public java.math.BigInteger getCurrentAddress()
-
setCurrentAddress
public void setCurrentAddress(java.math.BigInteger value)
-
reset
public void reset()
-
setOrigin
public void setOrigin(java.math.BigInteger value)
-
align
public void align(java.math.BigInteger value)
-
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 java.math.BigInteger allocate(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:
data
- Data to be stored in the memory storage.- Returns:
- Address of the allocated memory (in addressable units).
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
allocate
public java.math.BigInteger allocate(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:
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)
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
.
-
allocate
public java.math.BigInteger allocate(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:
data
- Collection of data elements to be stored in the memory storage.- Returns:
- Address of the first allocated element.
- Throws:
java.lang.IllegalArgumentException
- if the list is empty or it list elements have different sizes.
-
allocate
public java.math.BigInteger allocate(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:
data
- Collection of data elements to be stored in the memory storage.- Returns:
- Address of the first allocated element.
- Throws:
java.lang.IllegalArgumentException
- if the parameter isnull
; if the list is empty or it list elements have different sizes.
-
allocateAt
public void allocateAt(ru.ispras.fortress.data.types.bitvector.BitVector data, java.math.BigInteger address)
-
allocateAsciiString
public java.math.BigInteger allocateAsciiString(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:
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).
- 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
-
-