Interface TraceMemoryOperations
- All Known Subinterfaces:
InternalTraceMemoryOperations,TraceMemoryManager,TraceMemorySpace
- All Known Implementing Classes:
DBTraceMemoryManager,DBTraceMemorySpace
This models memory over the course of an arbitrary number of snaps. The duration between snaps is
unspecified. However, the mapping of snaps to real time ought to be strictly monotonic.
Observations of memory are recorded using the putBytes(long, Address, ByteBuffer) and
related methods. Those observations, and some related deductions can be retrieved using the
getBytes(long, Address, ByteBuffer) and related methods. Many of the get methods
permit the retrieval of the most recent observations. This is useful as an observed value in
memory is presumed unchanged until another observation is made. Observations of bytes in memory
cause the state at the same location and snap to become TraceMemoryState.KNOWN. These
states can be manipulated directly; however, this is recommended only to record read failures,
using the state TraceMemoryState.ERROR. A state of null is equivalent to
TraceMemoryState.UNKNOWN and indicates no observation has been made.
Negative snaps may have different semantics than positive, since negative snaps are used as
"scratch space". These snaps are not presumed to have any temporal relation to their neighbors,
or any other snap for that matter. Clients may use the description field of the
TraceSnapshot to indicate a relationship to another snap. Operations which seek the
"most-recent" data might not retrieve anything from scratch snaps, and writing to a scratch snap
might not cause any changes to others. Note the "integrity" of data where the memory state is not
TraceMemoryState.KNOWN may be neglected to some extent. For example, writing bytes to
snap -10 may cause bytes in snap -9 to change, where the effected range at snap -9 has state
TraceMemoryState.UNKNOWN. The time semantics are not necessarily prohibited in scratch
space, but implementations may choose cheaper semantics if desired. Clients should be wary not to
accidentally rely on implied temporal relationships in scratch space.
-
Method Summary
Modifier and TypeMethodDescriptionfindBytes(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Search the given address range at the given snap for a given byte patterndefault AddressSetViewgetAddressesWithState(long snap, AddressSetView set, Predicate<TraceMemoryState> predicate) Get at least the subset of addresses having state satisfying the given predicategetAddressesWithState(long snap, Predicate<TraceMemoryState> predicate) Get the addresses having state satisfying the given predicategetAddressesWithState(Lifespan span, AddressSetView set, Predicate<TraceMemoryState> predicate) Get at least the subset of addresses having state satisfying the given predicategetAddressesWithState(Lifespan lifespan, Predicate<TraceMemoryState> predicate) Get the addresses having state satisfying the given predicate at any time in the specified lifespanintGet the block size used by internal storage.default MemBuffergetBufferAt(long snap, Address start) Get a view of a particular snap as a memory buffer using the base language's byte ordergetBufferAt(long snap, Address start, ByteOrder byteOrder) Get a view of a particular snap as a memory bufferintgetBytes(long snap, Address start, ByteBuffer buf) Read the most recent bytes from the given snap and addressdefault intgetBytes(long snap, Register register, ByteBuffer buf) Get the most-recent bytes of a given register at the given timeintgetBytes(TracePlatform platform, long snap, Register register, ByteBuffer buf) Get the most-recent bytes of a given register at the given timegetMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and addressgetMostRecentStates(long snap, AddressRange range) Break a range of addresses into smaller ranges each mapped to its most recent state at the given timegetSnapOfMostRecentChangeToBlock(long snap, Address address) Find the internal storage block that most-recently defines the value at the given snap and address, and return the block's snap.Get the state of memory at a given snap and addressdefault TraceMemoryStateAssert that a register's range has a single state at the given snap and get that stategetState(TracePlatform platform, long snap, Register register) Assert that a register's range has a single state at the given snap and get that stategetStates(long snap, AddressRange range) Break a range of addresses into smaller ranges each mapped to its state at the given snapBreak the register's range into smaller ranges each mapped to its state at the given snapgetStates(TracePlatform platform, long snap, Register register) Break the register's range into smaller ranges each mapped to its state at the given snapgetTrace()Get the trace to which the memory manager belongsdefault RegisterValueGet the most-recent value of a given register at the given timegetValue(TracePlatform platform, long snap, Register register) Get the most-recent value of a given register at the given timeintgetViewBytes(long snap, Address start, ByteBuffer buf) Read the most recent bytes from the given snap and address, following schedule forksgetViewMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and address, following schedule forksgetViewMostRecentStateEntry(long snap, AddressRange range, Predicate<TraceMemoryState> predicate) Get the entry recording the most recent state since the given snap within the given range that satisfies a given predicate, following schedule forksgetViewState(long snap, Address address) Get the state of memory at a given snap and address, following schedule forksdefault RegisterValuegetViewValue(long snap, Register register) Get the most-recent value of a given register at the given time, following schedule forksgetViewValue(TracePlatform platform, long snap, Register register) Get the most-recent value of a given register at the given timedefault booleanisKnown(long snap, AddressRange range) Check if a range addresses are all knownstatic booleanisStateEntirely(AddressRange range, Collection<Map.Entry<TraceAddressSnapRange, TraceMemoryState>> stateEntries, TraceMemoryState state) Check if the return value ofgetStates(long, AddressRange)or similar represents a single entry of the given state.voidpack()Optimize storage spaceintputBytes(long snap, Address start, ByteBuffer buf) Write bytes at the given snap and addressdefault intputBytes(long snap, Register register, ByteBuffer buf) Write bytes at the given snap and register addressintputBytes(TracePlatform platform, long snap, Register register, ByteBuffer buf) voidremoveBytes(long snap, Address start, int len) Remove bytes from the given time and locationdefault voidremoveValue(long snap, Register register) Remove a value from the given time and registervoidremoveValue(TracePlatform platform, long snap, Register register) voidsetState(long snap, AddressRange range, TraceMemoryState state) Set the state of memory over a given time and address rangevoidsetState(long snap, Address start, Address end, TraceMemoryState state) voidsetState(long snap, Address address, TraceMemoryState state) voidsetState(long snap, AddressSetView set, TraceMemoryState state) Set the state of memory over a given time and address setdefault voidsetState(long snap, Register register, TraceMemoryState state) Set the state of a given register at a given timevoidsetState(TracePlatform platform, long snap, Register register, TraceMemoryState state) Set the state of a given register at a given timedefault intsetValue(long snap, RegisterValue value) Set the value of a register at the given snapintsetValue(TracePlatform platform, long snap, RegisterValue value)
-
Method Details
-
isStateEntirely
static boolean isStateEntirely(AddressRange range, Collection<Map.Entry<TraceAddressSnapRange, TraceMemoryState>> stateEntries, TraceMemoryState state) Check if the return value ofgetStates(long, AddressRange)or similar represents a single entry of the given state.This method returns false if there is not exactly one entry of the given state whose range covers the given range. As a special case, an empty collection will cause this method to return true iff state is
TraceMemoryState.UNKNOWN.- Parameters:
range- the range to check, usually that passed togetStates(long, AddressRange).stateEntries- the collection returned bygetStates(long, AddressRange).state- the expected state- Returns:
- true if the state matches
-
getTrace
Trace getTrace()Get the trace to which the memory manager belongs- Returns:
- the trace
-
setState
Set the state of memory over a given time and address rangeSetting state to
TraceMemoryState.KNOWNvia this method is not recommended. Setting bytes will automatically update the state accordingly.- Parameters:
snap- the timerange- the rangestate- the state
-
setState
- See Also:
-
setState
- See Also:
-
setState
Set the state of memory over a given time and address set- See Also:
-
getState
Get the state of memory at a given snap and addressIf the location's state has not been set, the result is
null, which impliesTraceMemoryState.UNKNOWN.- Parameters:
snap- the timeaddress- the location- Returns:
- the state
-
getViewState
Get the state of memory at a given snap and address, following schedule forks- Parameters:
snap- the timeaddress- the location- Returns:
- the state, and the snap where it was found
-
getMostRecentStateEntry
Map.Entry<TraceAddressSnapRange,TraceMemoryState> getMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and addressThe entry includes the entire entry at that snap. Parts occluded by more recent snaps are not subtracted from the entry's address range.
- Parameters:
snap- the timeaddress- the location- Returns:
- the entry including the entire recorded range
-
getViewMostRecentStateEntry
Map.Entry<TraceAddressSnapRange,TraceMemoryState> getViewMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and address, following schedule forks- Parameters:
snap- the latest time to consideraddress- the address- Returns:
- the most-recent entry
-
getViewMostRecentStateEntry
Map.Entry<TraceAddressSnapRange,TraceMemoryState> getViewMostRecentStateEntry(long snap, AddressRange range, Predicate<TraceMemoryState> predicate) Get the entry recording the most recent state since the given snap within the given range that satisfies a given predicate, following schedule forks- Parameters:
snap- the latest time to considerrange- the range of addressespredicate- a predicate on the state- Returns:
- the most-recent entry
-
getAddressesWithState
default AddressSetView getAddressesWithState(long snap, AddressSetView set, Predicate<TraceMemoryState> predicate) Get at least the subset of addresses having state satisfying the given predicate- Parameters:
snap- the timeset- the set to examinepredicate- a predicate on state to search for- Returns:
- the address set
- See Also:
-
getAddressesWithState
AddressSetView getAddressesWithState(Lifespan span, AddressSetView set, Predicate<TraceMemoryState> predicate) Get at least the subset of addresses having state satisfying the given predicateThe implementation may provide a larger view than requested, but within the requested set, only ranges satisfying the predicate may be present. Use
AddressSetView.intersect(AddressSetView)withsetif a strict subset is required.Because
TraceMemoryState.UNKNOWNis not explicitly stored in the map, to compute the set ofTraceMemoryState.UNKNOWNaddresses, use the predicatestate -> state != null && state != TraceMemoryState.UNKNOWNand subtract the result fromset.- Parameters:
span- the range of timeset- the set to examinepredicate- a predicate on state to search for- Returns:
- the address set
-
getAddressesWithState
Get the addresses having state satisfying the given predicateThe implementation may provide a view that updates with changes. Behavior is not well defined for predicates testing for
TraceMemoryState.UNKNOWN.- Parameters:
snap- the timepredicate- a predicate on state to search for- Returns:
- the address set
-
getAddressesWithState
Get the addresses having state satisfying the given predicate at any time in the specified lifespanThe implementation may provide a view that updates with changes. Behavior is not well defined for predicates testing for
TraceMemoryState.UNKNOWN.- Parameters:
lifespan- the span of timepredicate- a predicate on state to search for- Returns:
- the address set
-
getStates
Collection<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getStates(long snap, AddressRange range) Break a range of addresses into smaller ranges each mapped to its state at the given snapNote that
TraceMemoryState.UNKNOWNentries will not appear in the result. Gaps in the returned entries are implied to beTraceMemoryState.UNKNOWN.- Parameters:
snap- the timerange- the range to examine- Returns:
- the map of ranges to states
-
isKnown
Check if a range addresses are all known- Parameters:
snap- the timerange- the range to examine- Returns:
- true if the entire range is
TraceMemoryState.KNOWN
-
getMostRecentStates
Iterable<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getMostRecentStates(TraceAddressSnapRange within) Break a range of addresses into smaller ranges each mapped to its most recent state at the given timeTypically
withinis the box whose width is the address range to break down and whose height is from "negative infinity" to the "current" snap.In this context, "most recent" means the latest state other than
TraceMemoryState.UNKNOWN.- Parameters:
within- a box intersecting entries to consider- Returns:
- an iterable over the snap ranges and states
-
getMostRecentStates
default Iterable<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getMostRecentStates(long snap, AddressRange range) - See Also:
-
putBytes
Write bytes at the given snap and addressThis will attempt to read
Buffer.remaining()bytes starting atBuffer.position()from the source bufferbufand write them into memory at the specified time and location. The affected region is also updated toTraceMemoryState.KNOWN. The written bytes are assumed effective for all future snaps up to the next write.- Parameters:
snap- the timestart- the locationbuf- the source buffer of bytes- Returns:
- the number of bytes written
-
getBytes
Read the most recent bytes from the given snap and addressThis will attempt to read
Buffer.remaining()of the most recent bytes from memory at the specified time and location and write them into the destination bufferbufstarting atBuffer.position(). Where bytes in memory have no defined value, values in the destination buffer are unspecified. The implementation may leave those bytes in the destination buffer unmodified, or it may write zeroes.- Parameters:
snap- the timestart- the locationbuf- the destination buffer of bytes- Returns:
- the number of bytes read
-
getViewBytes
Read the most recent bytes from the given snap and address, following schedule forksThis behaves similarly to
getBytes(long, Address, ByteBuffer), except it checks for theTraceMemoryState.KNOWNstate among each involved snap range and reads the applicable address ranges, preferring the most recent. Where memory is never known the buffer is left unmodified.- Parameters:
snap- the timestart- the locationbuf- the destination buffer of bytes- Returns:
- the number of bytes read
-
findBytes
Address findBytes(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Search the given address range at the given snap for a given byte pattern- Parameters:
snap- the time to searchrange- the address range to searchdata- the values to search formask- a mask on the bits ofdata; or null to match all bytes exactlyforward- true to return the match with the lowest address inrange, false for the highest address.monitor- a monitor for progress reporting and canceling- Returns:
- the minimum address of the matched bytes, or
nullif not found
-
removeBytes
Remove bytes from the given time and locationThis deletes all observed bytes from the given address through length at the given snap. If there were no observations in the range at exactly the given snap, this has no effect. If there were, then those observations are removed. The next time those bytes are read, they will have a value from a previous snap, or no value at all. The affected region's state is also deleted, i.e., set to
null, implyingTraceMemoryState.UNKNOWN.Note, use of this method is discouraged. The more observations within the same range that follow the deleted observation, the more expensive this operation typically is, since all of those observations may need to be updated.
- Parameters:
snap- the timestart- the locationlen- the number of bytes to remove
-
getBufferAt
Get a view of a particular snap as a memory bufferThe bytes read by this buffer are the most recent bytes written before the given snap
- Parameters:
snap- the snapstart- the starting addressbyteOrder- the byte ordering for this buffer- Returns:
- the memory buffer
-
getBufferAt
Get a view of a particular snap as a memory buffer using the base language's byte order- See Also:
-
getSnapOfMostRecentChangeToBlock
Find the internal storage block that most-recently defines the value at the given snap and address, and return the block's snap.This method reveals portions of the internal storage so that clients can optimize difference computations by eliminating corresponding ranges defined by the same block. If the underlying implementation cannot answer this question, this returns the given snap.
- Parameters:
snap- the timeaddress- the location- Returns:
- the most snap for the most recent containing block
-
getBlockSize
int getBlockSize()Get the block size used by internal storage.This method reveals portions of the internal storage so that clients can optimize searches. If the underlying implementation cannot answer this question, this returns 0.
- Returns:
- the block size
-
pack
void pack()Optimize storage spaceThis gives the implementation an opportunity to clean up garbage, apply compression, etc., in order to best use the storage space. Because memory observations can be sparse, a trace's memory is often compressible, and observations are not often modified or deleted, packing is recommended whenever the trace is saved to disk.
-
setState
Set the state of a given register at a given timeSetting state to
TraceMemoryState.KNOWNvia this method is not recommended. Setting bytes will automatically update the state accordingly.- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the registerstate- the state
-
setState
Set the state of a given register at a given timeSetting state to
TraceMemoryState.KNOWNvia this method is not recommended. Setting bytes will automatically update the state accordingly.- Parameters:
snap- the timeregister- the registerstate- the state
-
getState
Assert that a register's range has a single state at the given snap and get that state- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the register to examine- Returns:
- the state
- Throws:
IllegalStateException- if the register is mapped to more than one state. SeegetStates(long, Register)
-
getState
Assert that a register's range has a single state at the given snap and get that state- Parameters:
snap- the timeregister- the register to examine- Returns:
- the state
- Throws:
IllegalStateException- if the register is mapped to more than one state. SeegetStates(long, Register)
-
getStates
Collection<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getStates(TracePlatform platform, long snap, Register register) Break the register's range into smaller ranges each mapped to its state at the given snapIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the register to examine- Returns:
- the map of ranges to states
-
getStates
default Collection<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getStates(long snap, Register register) Break the register's range into smaller ranges each mapped to its state at the given snapIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
snap- the timeregister- the register to examine- Returns:
- the map of ranges to states
-
setValue
- Parameters:
platform- the platform whose language defines the registersnap- the snapvalue- the register value- Returns:
- the number of bytes written
- See Also:
-
setValue
Set the value of a register at the given snapIf the register is memory mapped, this will delegate to the appropriate space. In those cases, the assignment affects all threads.
IMPORTANT: The trace database cannot track the state (
TraceMemoryState.KNOWN, etc.) with per-bit accuracy. It only has byte precision. If the given value specifies, e.g., only a single bit, then the entire byte will become markedTraceMemoryState.KNOWN, even though the remaining 7 bits could technically be unknown.- Parameters:
snap- the snapvalue- the register value- Returns:
- the number of bytes written
-
putBytes
- Parameters:
platform- the platform whose language defines the registersnap- the snapregister- the register to modifybuf- the buffer of bytes to write- Returns:
- the number of bytes written
- See Also:
-
putBytes
Write bytes at the given snap and register addressIf the register is memory mapped, this will delegate to the appropriate space. In those cases, the assignment affects all threads.
Note that bit-masked registers are not properly heeded. If the caller wishes to preserve non-masked bits, it must first retrieve the current value and combine it with the desired value. The caller must also account for any bit shift in the passed buffer. Alternatively, consider
setValue(long, RegisterValue).- Parameters:
snap- the snapregister- the register to modifybuf- the buffer of bytes to write- Returns:
- the number of bytes written
-
getValue
Get the most-recent value of a given register at the given timeIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the register- Returns:
- the value
-
getValue
Get the most-recent value of a given register at the given timeIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
snap- the timeregister- the register- Returns:
- the value
-
getViewValue
Get the most-recent value of a given register at the given timeIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the register- Returns:
- the value
-
getViewValue
Get the most-recent value of a given register at the given time, following schedule forksIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
snap- the timeregister- the register- Returns:
- the value
-
getBytes
Get the most-recent bytes of a given register at the given timeIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
platform- the platform whose language defines the registersnap- the timeregister- the registerbuf- the destination buffer- Returns:
- the number of bytes read
-
getBytes
Get the most-recent bytes of a given register at the given timeIf the register is memory mapped, this will delegate to the appropriate space.
- Parameters:
snap- the timeregister- the registerbuf- the destination buffer- Returns:
- the number of bytes read
-
removeValue
- Parameters:
platform- the platform whose language defines the registersnap- the snapregister- the register- See Also:
-
removeValue
Remove a value from the given time and registerIf the register is memory mapped, this will delegate to the appropriate space.
IMPORANT: The trace database cannot track the state (
TraceMemoryState.KNOWN, etc.) with per-bit accuracy. It only has byte precision. If the given register specifies, e.g., only a single bit, then the entire byte will become markedTraceMemoryState.UNKNOWN, even though the remaining 7 bits could technically be known.- Parameters:
snap- the snapregister- the register
-