Search in sources :

Example 1 with DetailedDumpMemorySource

use of com.ibm.j9ddr.corereaders.memory.DetailedDumpMemorySource in project openj9 by eclipse.

the class MemoryInfoStream method readFrom.

public void readFrom(MiniDumpReader dump, boolean is64Bit, Collection<? extends IMemorySource> ranges) throws IOException {
    dump.seek(getLocation());
    int sizeOfHeader = 0;
    int sizeOfEntry = 0;
    long numberOfEntries = 0;
    HashMap<Long, Properties> memoryInfo = new HashMap<Long, Properties>();
    // The header is 2 ULONGs, which are 32 bit and a ULONG64
    sizeOfHeader = dump.readInt();
    sizeOfEntry = dump.readInt();
    numberOfEntries = dump.readLong();
    // The thread info structures follow the header.
    /* Each structure is:
			ULONG64 BaseAddress;
			ULONG64 AllocationBase;
			ULONG32 AllocationProtect;
			ULONG32 __alignment1;
			ULONG64 RegionSize;
			ULONG32 State;
			ULONG32 Protect;
			ULONG32 Type;
			ULONG32 __alignment2;
		 */
    // We should be exactly here already but to be safe.
    dump.seek(getLocation() + sizeOfHeader);
    for (int i = 0; i < numberOfEntries; i++) {
        Properties props = new Properties();
        long baseAddress = dump.readLong();
        long allocationBase = dump.readLong();
        int allocationProtect = dump.readInt();
        // alignment1
        dump.readInt();
        long regionSize = dump.readLong();
        int state = dump.readInt();
        int protect = dump.readInt();
        int type = dump.readInt();
        // alignment2
        dump.readInt();
        props.put("state", decodeStateFlags(state));
        props.put("state_flags", String.format("0x%X", state));
        props.put("size", String.format(is64Bit ? "0x%016X" : "0x%08X", regionSize));
        if (state != STATE_MEM_FREE) {
            // For free memory allocation base, allocation protect, protect and type are undefined.
            props.put("allocationBase", String.format(is64Bit ? "0x%016X" : "0x%08X", allocationBase));
            props.put("allocationProtect", decodeProtectFlags(allocationProtect));
            props.put("allocationProtect_flags", String.format("0x%X", allocationProtect));
            props.put("protect", decodeProtectFlags(protect));
            setReadWriteExecProperties(protect, props);
            props.put("protect_flags", String.format("0x%X", protect));
            props.put("type", decodeTypeFlags(type));
            props.put("type_flags", String.format("0x%X", allocationProtect));
        } else {
            // Free memory is not accessible.
            props.setProperty(READABLE, FALSE);
            props.setProperty(WRITABLE, FALSE);
            props.setProperty(EXECUTABLE, FALSE);
        }
        memoryInfo.put(new Long(baseAddress), props);
    }
    /* Merge the extra properties into the memory info. */
    Iterator<? extends IMemorySource> memoryIterator = ranges.iterator();
    List<IMemorySource> newRanges = new ArrayList<IMemorySource>(memoryInfo.size());
    while (memoryIterator.hasNext()) {
        IMemorySource m = memoryIterator.next();
        Properties p = memoryInfo.remove(m.getBaseAddress());
        if (p != null && m instanceof DumpMemorySource) {
            DetailedDumpMemorySource newSource = new DetailedDumpMemorySource((DumpMemorySource) m, p);
            newSource.getProperties().putAll(p);
            newRanges.add(newSource);
        } else {
            newRanges.add(m);
        }
    }
    // Add sections we didn't find as unbacked memory!
    // (There should be at least one huge one in the middle if this is 64 bit.)
    Iterator<Entry<Long, Properties>> propsIterator = memoryInfo.entrySet().iterator();
    while (propsIterator.hasNext()) {
        Entry<Long, Properties> e = propsIterator.next();
        long size = Long.parseLong(((String) e.getValue().get("size")).substring(2), 16);
        String explanation = "Windows MINIDUMP_MEMORY_INFO entry included but data not included in dump";
        if ("MEM_FREE".equals(e.getValue().get("state"))) {
            explanation = "Free memory, unallocated";
        }
        UnbackedMemorySource m = new UnbackedMemorySource(e.getKey(), size, explanation);
        m.getProperties().putAll(e.getValue());
        newRanges.add(m);
    }
    Collections.sort(newRanges, new Comparator<IMemorySource>() {

        public int compare(IMemorySource o1, IMemorySource o2) {
            if (o1.getBaseAddress() > o2.getBaseAddress()) {
                return 1;
            } else if (o1.getBaseAddress() < o2.getBaseAddress()) {
                return -1;
            }
            return 0;
        }
    });
    dump.setMemorySources(newRanges);
}
Also used : DetailedDumpMemorySource(com.ibm.j9ddr.corereaders.memory.DetailedDumpMemorySource) DumpMemorySource(com.ibm.j9ddr.corereaders.memory.DumpMemorySource) IMemorySource(com.ibm.j9ddr.corereaders.memory.IMemorySource) DetailedDumpMemorySource(com.ibm.j9ddr.corereaders.memory.DetailedDumpMemorySource) HashMap(java.util.HashMap) UnbackedMemorySource(com.ibm.j9ddr.corereaders.memory.UnbackedMemorySource) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Entry(java.util.Map.Entry)

Aggregations

DetailedDumpMemorySource (com.ibm.j9ddr.corereaders.memory.DetailedDumpMemorySource)1 DumpMemorySource (com.ibm.j9ddr.corereaders.memory.DumpMemorySource)1 IMemorySource (com.ibm.j9ddr.corereaders.memory.IMemorySource)1 UnbackedMemorySource (com.ibm.j9ddr.corereaders.memory.UnbackedMemorySource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1