Search in sources :

Example 16 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class DTFJUnitTest method buildContext.

private static TestContext buildContext(ImageFactory imageFactory, File coreFile) throws IOException {
    TestContext ctx = new DTFJUnitTest.TestContext();
    Image image = imageFactory.getImage(coreFile);
    ctx.setImage(image);
    Iterator<?> addressSpaceIt = image.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        Object asObj = addressSpaceIt.next();
        if (asObj instanceof CorruptData) {
            System.err.println("Corrupt AddressSpace returned: " + asObj);
        } else if (asObj instanceof ImageAddressSpace) {
            ImageAddressSpace as = (ImageAddressSpace) asObj;
            ctx.setSpace(as);
            Iterator<?> processIterator = as.getProcesses();
            while (processIterator.hasNext()) {
                Object processObj = processIterator.next();
                if (processObj instanceof CorruptData) {
                    System.err.println("Corrupt ImageProcess returned: " + asObj);
                } else if (processObj instanceof ImageProcess) {
                    ImageProcess process = (ImageProcess) processObj;
                    ctx.setProcess(process);
                    Iterator<?> runtimeIterator = process.getRuntimes();
                    while (runtimeIterator.hasNext()) {
                        Object runtimeObj = runtimeIterator.next();
                        if (runtimeObj instanceof CorruptData) {
                            System.err.println("Corrupt ImageProcess returned: " + asObj);
                        } else if (runtimeObj instanceof JavaRuntime) {
                            JavaRuntime runtime = (JavaRuntime) runtimeObj;
                            ctx.setRuntime(runtime);
                            return ctx;
                        } else {
                            throw new ClassCastException("Unexpected type from Runtime iterator: " + runtimeObj.getClass() + ": " + runtimeObj);
                        }
                    }
                } else {
                    throw new ClassCastException("Unexpected type from Process iterator: " + processObj.getClass() + ": " + processObj);
                }
            }
        } else {
            throw new ClassCastException("Unexpected type from AddressSpace iterator: " + asObj.getClass() + ": " + asObj);
        }
    }
    throw new RuntimeException("Could not find a Java Runtime");
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.CorruptData) Image(com.ibm.dtfj.image.Image)

Example 17 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class JCImageAddressSpace method getCurrentProcess.

/**
 * At the moment, just the last process to be added
 */
public ImageProcess getCurrentProcess() {
    ImageProcess currentProcess = null;
    int size = fProcesses.size();
    if (size > 0) {
        currentProcess = (ImageProcess) fProcesses.get(size - 1);
    }
    return currentProcess;
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess)

Example 18 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class Utils method _extractAddressSpace.

// CMVC 175488 : fixed so that this function returns an address space which contains a process
// rather than the first address space it finds.
public static ImageAddressSpace _extractAddressSpace(Image loadedImage) {
    ImageAddressSpace space = null;
    Iterator spaces = loadedImage.getAddressSpaces();
    // object returned through DTFJ iterators
    Object obj = null;
    while (spaces.hasNext()) {
        obj = spaces.next();
        if (obj instanceof ImageAddressSpace) {
            space = (ImageAddressSpace) obj;
            Iterator procs = space.getProcesses();
            while (procs.hasNext()) {
                obj = procs.next();
                if (obj instanceof ImageProcess) {
                    return space;
                }
            }
        }
    }
    // failed to find an address space which contains a process.
    return null;
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 19 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class InfoThreadCommand method printProcessInfo.

private void printProcessInfo(String id, Map threads) {
    Iterator itProcess;
    ImageProcess ip;
    boolean found = false;
    ip = ctx.getProcess();
    _pointerSize = ip.getPointerSize();
    out.print(" process id: ");
    try {
        out.print(ip.getID());
    } catch (DataUnavailable d) {
        out.print(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
    }
    out.print("\n\n");
    found = printThreadInfo(id, threads);
    if (!found) {
        out.print(" no native threads found with specified id\n");
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 20 with ImageProcess

use of com.ibm.dtfj.image.ImageProcess in project openj9 by eclipse.

the class InfoProcCommand method printCommandLine.

private void printCommandLine() {
    ImageProcess ip = ctx.getProcess();
    out.print("\t Command line:\n\t  ");
    try {
        String commandLine = ip.getCommandLine();
        if (null == commandLine)
            out.print("<null>");
        else
            out.print(commandLine);
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
    } catch (DataUnavailable e) {
        out.print("Could not determine command line");
    }
    out.println();
    out.println();
    // Print the VM initialization options, similar to javacore.
    try {
        JavaVMInitArgs args = ctx.getRuntime().getJavaVMInitArgs();
        if (args != null) {
            out.print("\t Java VM init options: ");
            Iterator<?> opts = args.getOptions();
            while (opts.hasNext()) {
                out.println();
                Object obj = opts.next();
                if (obj instanceof JavaVMOption) {
                    JavaVMOption opt = (JavaVMOption) obj;
                    out.print("\t  " + opt.getOptionString());
                    if (opt.getExtraInfo().getAddress() != 0) {
                        out.print(" " + Utils.toHex(opt.getExtraInfo()));
                    }
                }
            }
        } else {
            out.print(Exceptions.getDataUnavailableString());
        }
    } catch (Exception cde) {
        // in the event of an exception getting the VM init options, just print the original message
        out.print(Exceptions.getDataUnavailableString());
    }
    out.print("\n");
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption) ImageProcess(com.ibm.dtfj.image.ImageProcess) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

ImageProcess (com.ibm.dtfj.image.ImageProcess)22 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)11 Iterator (java.util.Iterator)11 CorruptData (com.ibm.dtfj.image.CorruptData)9 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)9 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)8 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)8 Image (com.ibm.dtfj.image.Image)6 ImageModule (com.ibm.dtfj.image.ImageModule)5 ImageFactory (com.ibm.dtfj.image.ImageFactory)4 JavaObject (com.ibm.dtfj.java.JavaObject)3 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)2 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)2 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)2 File (java.io.File)2 IOException (java.io.IOException)2