Search in sources :

Example 1 with IAddressSpace

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

the class JniReader method getAddressSpaces.

/**
 * This method creates JNI address space and puts it into collection instance.
 *
 * @return Collection of address spaces
 */
public Collection<? extends IAddressSpace> getAddressSpaces() {
    if (null == addressSpaces) {
        addressSpaces = new ArrayList<IAddressSpace>(1);
        JniAddressSpace addressSpace = new JniAddressSpace(0, this);
        Iterator<? extends IProcess> ite = addressSpace.getProcesses().iterator();
        if (ite.hasNext()) {
            IProcess process = ite.next();
            /* This is sanity check. It should always be the JniProcess instance */
            if (process instanceof JniProcess) {
                JniProcess jniProcess = (JniProcess) process;
                /* Set ICore.PROCESSOR_TYPE_PROPERTY in the properties by checking the target architecture */
                int targetArchitecture = jniProcess.getTargetArchitecture();
                switch(targetArchitecture) {
                    case JniProcess.TARGET_TYPE_X86_32:
                        properties.setProperty(ICore.PROCESSOR_TYPE_PROPERTY, "x86");
                        break;
                    case JniProcess.TARGET_TYPE_X86_64:
                        properties.put(ICore.PROCESSOR_TYPE_PROPERTY, "amd64");
                        break;
                    case JniProcess.TARGET_TYPE_S390_31:
                    case JniProcess.TARGET_TYPE_S390_64:
                        properties.put(ICore.PROCESSOR_TYPE_PROPERTY, "s390");
                        break;
                    case JniProcess.TARGET_TYPE_PPC_32:
                    case JniProcess.TARGET_TYPE_PPC_64:
                        properties.put(ICore.PROCESSOR_TYPE_PROPERTY, "ppc");
                        break;
                    default:
                }
            }
        }
        addressSpaces.add(addressSpace);
    }
    return addressSpaces;
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess)

Example 2 with IAddressSpace

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

the class DDRInteractive method locateRuntimes.

private void locateRuntimes(ICore reader) {
    currentCore = reader;
    Collection<? extends IAddressSpace> spaces = reader.getAddressSpaces();
    for (IAddressSpace thisSpace : spaces) {
        // indicates if a context has been allocated for the address space
        boolean hasCtxBeenAddedForAS = false;
        Collection<? extends IProcess> processes = thisSpace.getProcesses();
        for (IProcess thisProcess : processes) {
            hasCtxBeenAddedForAS = true;
            try {
                IVMData vmData = VMDataFactory.getVMData(thisProcess);
                if (vmData != null) {
                    contexts.add(new Context(thisProcess, vmData, nonVMCommands));
                } else {
                    addMissingJVMToContexts(thisProcess);
                }
            } catch (JVMNotDDREnabledException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (JVMNotFoundException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (MissingDDRStructuresException e) {
                addMissingJVMToContexts(thisProcess);
            } catch (IOException e) {
                System.err.println("Problem searching for VMData in process " + thisProcess);
                e.printStackTrace();
                // put the stack trace to the log
                Logger logger = Logger.getLogger(LoggerNames.LOGGER_INTERACTIVE_CONTEXT);
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                logger.logp(FINE, null, null, sw.toString());
            }
        }
        if (!hasCtxBeenAddedForAS) {
            ASNoProcess as = new ASNoProcess(thisSpace);
            addMissingJVMToContexts(as);
        }
    }
    if (contexts.size() == 0) {
        throw new RuntimeException("Couldn't find any address spaces in this dump");
    } else {
        // default to the first address space
        currentContext = contexts.get(0);
        for (Context ctx : contexts) {
            // but if there is one with a JVM in it, set it to that
            if (!(ctx.vmData instanceof MissingVMData)) {
                currentContext = ctx;
                break;
            }
        }
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) IOException(java.io.IOException) Logger(java.util.logging.Logger) IVMData(com.ibm.j9ddr.IVMData) JVMNotDDREnabledException(com.ibm.j9ddr.exceptions.JVMNotDDREnabledException) JVMNotFoundException(com.ibm.j9ddr.exceptions.JVMNotFoundException) StringWriter(java.io.StringWriter) MissingDDRStructuresException(com.ibm.j9ddr.exceptions.MissingDDRStructuresException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) PrintWriter(java.io.PrintWriter)

Example 3 with IAddressSpace

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

the class DDRInteractive method addDDRContextFromDTFJ.

private void addDDRContextFromDTFJ(Object dtfjctx) throws Exception {
    Method getAddressSpace = findMethod(dtfjctx.getClass(), "getAddressSpace", (Class<?>[]) null);
    Method getProcess = findMethod(dtfjctx.getClass(), "getProcess", (Class<?>[]) null);
    Method getRuntime = findMethod(dtfjctx.getClass(), "getRuntime", (Class<?>[]) null);
    Object addressSpace = getAddressSpace.invoke(dtfjctx, (Object[]) null);
    Object process = getProcess.invoke(dtfjctx, (Object[]) null);
    Object runtime = getRuntime.invoke(dtfjctx, (Object[]) null);
    if (addressSpace == null) {
        throw new IOException("Cannot create a context without an associated address space");
    }
    if (!(addressSpace instanceof J9DDRImageAddressSpace)) {
        throw new UnsupportedOperationException("The supplied DTFJ context is not backed by a DDR implementation");
    }
    IAddressSpace space = ((J9DDRImageAddressSpace) addressSpace).getIAddressSpace();
    IProcess proc = null;
    if (process != null) {
        proc = ((J9DDRImageProcess) process).getIProcess();
    }
    if (proc == null) {
        ASNoProcess as = new ASNoProcess(space);
        addMissingJVMToContexts(as);
        return;
    }
    if (runtime == null) {
        addMissingJVMToContexts(proc);
        return;
    }
    // DDR will cache the VM data, so if the DTFJ context has already found it then this should be in the cache
    IVMData vmData = VMDataFactory.getVMData(proc);
    if (vmData != null) {
        contexts.add(new Context(proc, vmData, nonVMCommands));
    } else {
        addMissingJVMToContexts(proc);
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) J9DDRImageAddressSpace(com.ibm.j9ddr.view.dtfj.image.J9DDRImageAddressSpace) Method(java.lang.reflect.Method) IOException(java.io.IOException) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) IVMData(com.ibm.j9ddr.IVMData)

Example 4 with IAddressSpace

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

the class BootstrapJUnitTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    try {
        String coreFileName = System.getProperty("ddr.core.file.name");
        if (coreFileName == null) {
            fail("Did not specify core file name with -Dddr.core.file.name");
        }
        ICore core = CoreReader.readCoreFile(coreFileName);
        List<IAddressSpace> addressSpaces = new ArrayList<IAddressSpace>(core.getAddressSpaces());
        for (IAddressSpace thisAS : addressSpaces) {
            for (IProcess thisProc : thisAS.getProcesses()) {
                try {
                    vmData = VMDataFactory.getVMData(thisProc);
                    return;
                } catch (IOException ex) {
                // This happens if we can't find a JVM or a blob. Keep looking
                }
            }
        }
        fail("Couldn't initialize VMData");
    } catch (FileNotFoundException e) {
        fail("Could not initialize VMData: " + e.getMessage());
    } catch (IOException e) {
        fail("Could not initialize VMData: " + e.getMessage());
    }
}
Also used : IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ICore(com.ibm.j9ddr.corereaders.ICore) IProcess(com.ibm.j9ddr.corereaders.memory.IProcess) BeforeClass(org.junit.BeforeClass)

Example 5 with IAddressSpace

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

the class DumpSegments method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Expected 1 argument, got " + args.length);
    }
    String filename = args[0];
    ICore core = CoreReader.readCoreFile(filename);
    Collection<? extends IAddressSpace> addressSpaces = core.getAddressSpaces();
    for (IAddressSpace as : addressSpaces) {
        System.err.println("Address space: " + as.getAddressSpaceId());
        List<? extends IMemoryRange> ranges = new ArrayList<IMemoryRange>(as.getMemoryRanges());
        Collections.sort(ranges);
        // System.err.println("Raw mappings");
        // for(IMemoryRange thisRange : ranges) {
        // System.err.println("Base: " +
        // Long.toHexString(thisRange.getBaseAddress()) + " - size: " +
        // Long.toHexString(thisRange.getSize()));
        // if (thisRange.getBaseAddress() == 0xf95f000) {
        // System.err.println("Found!");
        // }
        // }
        List<Range> localRanges = new LinkedList<Range>();
        for (IMemoryRange range : ranges) {
            Range newRange = new Range();
            newRange.base = range.getBaseAddress();
            newRange.size = range.getSize();
            localRanges.add(newRange);
        }
        localRanges = mergeRanges(localRanges);
        for (Range range : localRanges) {
            System.err.println("Base: " + Long.toHexString(range.base) + " - size: " + Long.toHexString(range.size));
            try {
                if (range.size > 7) {
                    /*
						 * Pick three addresses and read integers from them -
						 * proves that endian conversion is working
						 */
                    long address1 = range.base;
                    long address2 = range.base + range.size - 5;
                    long address3 = (address1 + address2) / 2;
                    System.err.print(Long.toHexString(address1) + " - ");
                    System.err.println(Integer.toHexString(as.getIntAt(address1)));
                    System.err.print(Long.toHexString(address2) + " - ");
                    System.err.println(Integer.toHexString(as.getIntAt(address2)));
                    System.err.print(Long.toHexString(address3) + " - ");
                    if (0xf971ffd == address3) {
                        System.err.println("Found!");
                    }
                    System.err.println(Integer.toHexString(as.getIntAt(address3)));
                }
            } catch (MemoryFault ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) IAddressSpace(com.ibm.j9ddr.corereaders.memory.IAddressSpace) ArrayList(java.util.ArrayList) ICore(com.ibm.j9ddr.corereaders.ICore) IMemoryRange(com.ibm.j9ddr.corereaders.memory.IMemoryRange) LinkedList(java.util.LinkedList)

Aggregations

IAddressSpace (com.ibm.j9ddr.corereaders.memory.IAddressSpace)8 IProcess (com.ibm.j9ddr.corereaders.memory.IProcess)4 IVMData (com.ibm.j9ddr.IVMData)3 ICore (com.ibm.j9ddr.corereaders.ICore)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)1 ProcessAddressSpace (com.ibm.j9ddr.corereaders.memory.ProcessAddressSpace)1 JVMNotDDREnabledException (com.ibm.j9ddr.exceptions.JVMNotDDREnabledException)1 JVMNotFoundException (com.ibm.j9ddr.exceptions.JVMNotFoundException)1 MissingDDRStructuresException (com.ibm.j9ddr.exceptions.MissingDDRStructuresException)1 J9DDRImageAddressSpace (com.ibm.j9ddr.view.dtfj.image.J9DDRImageAddressSpace)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 Logger (java.util.logging.Logger)1 BeforeClass (org.junit.BeforeClass)1