Search in sources :

Example 1 with DumpReader

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;
}
Also used : MemoryRange(com.ibm.dtfj.corereaders.MemoryRange) DumpReader(com.ibm.dtfj.corereaders.DumpReader) IOException(java.io.IOException) MemoryAccessException(com.ibm.dtfj.corereaders.MemoryAccessException)

Aggregations

DumpReader (com.ibm.dtfj.corereaders.DumpReader)1 MemoryAccessException (com.ibm.dtfj.corereaders.MemoryAccessException)1 MemoryRange (com.ibm.dtfj.corereaders.MemoryRange)1 IOException (java.io.IOException)1