use of com.ibm.dtfj.corereaders.DumpReader in project openj9 by eclipse.
the class DumpReaderAddressSpace method getBytesAt.
/* (non-Javadoc)
* @see com.ibm.dtfj.addressspace.IAbstractAddressSpace#getBytesAt(int, long, byte[])
*/
public int getBytesAt(int asid, long address, byte[] buffer) throws MemoryAccessException {
int size, bytesRead = 0;
while (bytesRead < buffer.length) {
long adjustedAddress = address + ((long) bytesRead & 0xFFFFFFFF);
MemoryRange match = _residentRange(asid, adjustedAddress);
long offset = adjustedAddress - match.getVirtualAddress();
long bytesAvailable = match.getSize() - offset;
// For 64-bit dumps, need to safely limit byte array size
if (bytesAvailable > (long) (Integer.MAX_VALUE)) {
size = buffer.length - bytesRead;
} else {
size = Math.min((int) bytesAvailable, buffer.length - bytesRead);
}
try {
if (match.isInCoreFile() == true) {
_reader.seek(match.getFileOffset() + offset);
byte[] temp = _reader.readBytes(size);
System.arraycopy(temp, 0, buffer, bytesRead, temp.length);
} else {
/*
* This memory range is not mapped into the core file, but is resident in
* an external library file, so read it from there.
*/
DumpReader reader = match.getLibraryReader();
if (reader != null) {
reader.seek(offset);
byte[] temp = reader.readBytes(size);
System.arraycopy(temp, 0, buffer, bytesRead, temp.length);
} else {
// No valid reader for this memory
throw new MemoryAccessException(asid, adjustedAddress, "Cannot read memory external to core file");
}
}
} catch (IOException e) {
throw new MemoryAccessException(asid, adjustedAddress, "IOException reading core file: " + e.getMessage());
}
bytesRead += size;
}
return bytesRead;
}
Aggregations