Search in sources :

Example 11 with ImageModule

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

the class DTFJKickTyres method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    boolean useJExtract = false;
    if (args.length > 1) {
        if (args[1].toLowerCase().trim().equals("jextract")) {
            useJExtract = true;
        }
    }
    ImageFactory factory = null;
    if (useJExtract) {
        try {
            Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
            factory = (ImageFactory) jxfactoryclass.newInstance();
        } catch (Exception e) {
            System.out.println("Could not create a jextract based implementation of ImageFactory");
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        factory = new J9DDRImageFactory();
    }
    Image img = factory.getImage(new File(args[0]));
    Iterator<?> addressSpaceIt = img.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        ImageAddressSpace as = (ImageAddressSpace) addressSpaceIt.next();
        Iterator<?> processIt = as.getProcesses();
        while (processIt.hasNext()) {
            ImageProcess process = (ImageProcess) processIt.next();
            System.err.println("Got process " + process);
            try {
                System.err.println("Command line was " + process.getCommandLine());
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                System.err.println("Executable was: " + process.getExecutable());
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                System.err.println("Modules were:");
                Iterator<?> it = process.getLibraries();
                if (!it.hasNext()) {
                    System.err.println("No modules!");
                }
                while (it.hasNext()) {
                    ImageModule module = (ImageModule) it.next();
                    System.err.println("* " + module.getName());
                    Iterator<?> symIt = module.getSymbols();
                    while (symIt.hasNext()) {
                        Object symObj = symIt.next();
                        if (symObj instanceof ImageSymbol) {
                            ImageSymbol sym = (ImageSymbol) symObj;
                            if (sym.getName().toLowerCase().contains("environ")) {
                                System.err.println("X sym " + sym.getName() + " = " + sym.getAddress());
                            }
                        }
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                Properties env = process.getEnvironment();
                System.err.println("Environment");
                for (Object key : env.keySet()) {
                    System.err.println(key + " = " + env.getProperty((String) key));
                }
            } catch (Throwable t) {
                t.printStackTrace();
            }
            Iterator<?> runtimeIt = process.getRuntimes();
            while (runtimeIt.hasNext()) {
                JavaRuntime runtime = (JavaRuntime) runtimeIt.next();
                System.err.println("Got runtime: " + runtime);
                JavaVMInitArgs initArgs = runtime.getJavaVMInitArgs();
                Iterator<?> optionsIt = initArgs.getOptions();
                System.err.println("Options:");
                while (optionsIt.hasNext()) {
                    Object optionObj = optionsIt.next();
                    if (optionObj instanceof JavaVMOption) {
                        JavaVMOption option = (JavaVMOption) optionObj;
                        System.err.println("* " + option.getOptionString());
                    }
                }
            }
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageSymbol(com.ibm.dtfj.image.ImageSymbol) Image(com.ibm.dtfj.image.Image) Properties(java.util.Properties) ImageModule(com.ibm.dtfj.image.ImageModule) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaVMOption(com.ibm.dtfj.java.JavaVMOption) ImageProcess(com.ibm.dtfj.image.ImageProcess) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) File(java.io.File)

Example 12 with ImageModule

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

the class ImageProcessBuilder method addLibrary.

/**
 */
public ImageModule addLibrary(String name) {
    ImageModule module = null;
    if (name != null && (module = fImageProcess.getLibrary(name)) == null) {
        JCImageModule jcmodule = new JCImageModule(name);
        fImageProcess.addLibrary(jcmodule);
        module = jcmodule;
    }
    return module;
}
Also used : JCImageModule(com.ibm.dtfj.image.javacore.JCImageModule) ImageModule(com.ibm.dtfj.image.ImageModule) JCImageModule(com.ibm.dtfj.image.javacore.JCImageModule)

Example 13 with ImageModule

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

the class EnvironmentSectionParser method parseVersion.

/**
 * Parse the version information (1CIJAVAVERSION, and lines)
 * @throws ParserException
 */
private void parseVersion() throws ParserException {
    IAttributeValueMap results = null;
    // Process the version lines
    if ((results = processTagLineOptional(T_1CIJAVAVERSION)) != null) {
        int pointerSize = results.getIntValue(ICommonTypes.POINTER_SIZE);
        if (pointerSize != IBuilderData.NOT_AVAILABLE) {
            fImageProcessBuilder.setPointerSize(pointerSize);
        }
        String javaversion = results.getTokenValue(ARG_STRING);
        String checkString = "j2re 1.";
        // check that the core we are processing is from Java 5 or later
        if ((javaversion.toLowerCase().startsWith(checkString)) && (javaversion.length() > (checkString.length() + 1))) {
            String number = javaversion.substring(checkString.length(), javaversion.indexOf('.', checkString.length() + 1));
            try {
                int version = Integer.parseInt(number);
                if (version <= 4) {
                    throw new ParserException("Javacore files earlier than 1.5.0 are not supported");
                }
            } catch (NumberFormatException e) {
                handleError("Error determining Java version", e);
            }
        }
        results = processTagLineOptional(T_1CIVMVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        results = processTagLineOptional(T_1CIJITVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        results = processTagLineOptional(T_1CIGCVERSION);
        if (results != null) {
            javaversion = buildVersionString(javaversion, results);
        }
        if (javaversion != null) {
            fRuntimeBuilder.setJavaVersion(javaversion);
        }
    } else {
        processTagLineOptional(T_1CIVMVERSION);
        processTagLineOptional(T_1CIJITVERSION);
        processTagLineOptional(T_1CIGCVERSION);
    }
    results = processTagLineOptional(T_1CIJITMODES);
    if (results != null) {
        IParserToken token = results.getToken(JIT_MODE);
        if (token != null) {
            String value = token.getValue().trim();
            if (value.toLowerCase().startsWith("unavailable")) {
                // JIT was disabled with -Xint
                fRuntimeBuilder.setJITEnabled(false);
            } else {
                // JIT was operational but still could be disabled if -Xnojit was specified
                fRuntimeBuilder.setJITEnabled(true);
                String[] props = value.split(",");
                for (int i = 0; i < props.length; i++) {
                    // trim any white space
                    String item = props[i].trim();
                    int index = item.indexOf(' ');
                    if (index == -1) {
                        fRuntimeBuilder.addJITProperty(props[i], "<default value>");
                    } else {
                        String name = item.substring(0, index);
                        String pvalue = item.substring(index + 1);
                        fRuntimeBuilder.addJITProperty(name, pvalue);
                    }
                }
            }
        }
    }
    processTagLineOptional(T_1CIRUNNINGAS);
    // 1CISTARTTIME   JVM start time: 2015/07/17 at 13:31:04:547
    if ((results = processTagLineOptional(T_1CISTARTTIME)) != null) {
        String dateTimeString = results.getTokenValue(START_TIME);
        if (dateTimeString != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd 'at' HH:mm:ss:SSS");
            Date startDate = sdf.parse(dateTimeString, new ParsePosition(0));
            if (startDate != null) {
                fRuntimeBuilder.setStartTime(startDate.getTime());
            }
        }
    }
    // 1CISTARTNANO   JVM start nanotime: 3534023113503
    if ((results = processTagLineOptional(T_1CISTARTNANO)) != null) {
        String nanoTimeString = results.getTokenValue(START_NANO);
        if (nanoTimeString != null) {
            fRuntimeBuilder.setStartTimeNanos(Long.parseLong(nanoTimeString));
        }
    }
    if ((results = processTagLineOptional(T_1CIPROCESSID)) != null) {
        String pidStr = results.getTokenValue(PID_STRING);
        if (pidStr != null) {
            fImageBuilder.getCurrentAddressSpaceBuilder().getCurrentImageProcessBuilder().setID(pidStr);
        }
    }
    String cmdLine = null;
    if ((results = processTagLineOptional(T_1CICMDLINE)) != null) {
        cmdLine = results.getTokenValue(CMD_LINE);
        if ("[not available]".equals(cmdLine)) {
            cmdLine = null;
        } else {
            fImageProcessBuilder.setCommandLine(cmdLine);
        }
    }
    String home = null;
    if ((results = processTagLineOptional(T_1CIJAVAHOMEDIR)) != null) {
        ;
        home = results.getTokenValue(ARG_STRING);
    }
    String dlldir = null;
    if ((results = processTagLineOptional(T_1CIJAVADLLDIR)) != null) {
        ;
        dlldir = results.getTokenValue(ARG_STRING);
    }
    if (cmdLine != null) {
        if (dlldir != null) {
            // See if the command line starts with part of Java directory - if so add rest of path
            // Find position of first path separator
            int min1 = cmdLine.indexOf('/') + 1;
            if (min1 == 0)
                min1 = cmdLine.length();
            int min2 = cmdLine.indexOf('\\') + 1;
            if (min2 == 0)
                min2 = cmdLine.length();
            int min = Math.min(min1, min2);
            for (int i = cmdLine.length(); i > min; --i) {
                String prefix = cmdLine.substring(0, i);
                int j = dlldir.indexOf(prefix);
                if (j >= 0) {
                    cmdLine = dlldir.substring(0, j) + cmdLine;
                    break;
                }
            }
        }
        // Allow for spaces in the path by skipping over spaces in javadlldir
        int i = 0;
        if (dlldir != null) {
            for (i = dlldir.length(); i >= 0; --i) {
                if (cmdLine.startsWith(dlldir.substring(0, i))) {
                    break;
                }
            }
        }
        // Look for the rest of the command line
        int sp = cmdLine.indexOf(' ', i);
        String exec;
        if (sp >= 0) {
            exec = cmdLine.substring(0, sp);
        } else {
            exec = cmdLine;
        }
        ImageModule execMod = fImageProcessBuilder.addLibrary(exec);
        fImageProcessBuilder.setExecutable(execMod);
    }
    processTagLineOptional(T_1CISYSCP);
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ImageModule(com.ibm.dtfj.image.ImageModule) ParsePosition(java.text.ParsePosition)

Example 14 with ImageModule

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

the class StackSectionParser method parseStackLine.

/**
 * Parse the native stack line information
 * @throws ParserException
 */
private void parseStackLine() throws ParserException {
    IAttributeValueMap results = null;
    // Process the version lines
    while ((results = processTagLineOptional(T_BTTHREADID)) != null) {
        long threadID = results.getLongValue(STACK_THREAD);
        while ((results = processTagLineOptional(T_1BTSTACKENT)) != null) {
            String module = results.getTokenValue(STACK_MODULE);
            String routine = results.getTokenValue(STACK_ROUTINE);
            long address = results.getLongValue(STACK_PROC_ADDRESS);
            long routine_address = results.getLongValue(STACK_ROUTINE_ADDRESS);
            long offset = results.getLongValue(STACK_OFFSET);
            String file = results.getTokenValue(STACK_FILE);
            int line = results.getIntValue(STACK_LINE);
            // Allow for missing data
            if (routine_address == IBuilderData.NOT_AVAILABLE && address != IBuilderData.NOT_AVAILABLE && offset != IBuilderData.NOT_AVAILABLE) {
                routine_address = address - offset;
            } else if (offset == IBuilderData.NOT_AVAILABLE && address != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
                offset = address - routine_address;
            } else if (address == IBuilderData.NOT_AVAILABLE && offset != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
                address = routine_address + offset;
            }
            String name;
            if (module != null) {
                name = module;
            } else {
                name = "";
            }
            if (file != null) {
                name = name + "(" + file;
                if (line != IBuilderData.NOT_AVAILABLE) {
                    name = name + ":" + line;
                }
                name = name + ")";
            }
            if (module != null) {
                ImageModule mod = fImageProcessBuilder.addLibrary(module);
                if (routine != null && address != IBuilderData.NOT_AVAILABLE && offset != IBuilderData.NOT_AVAILABLE && routine_address != IBuilderData.NOT_AVAILABLE) {
                    fImageProcessBuilder.addRoutine(mod, routine, routine_address);
                    name = name + "::" + routine + (offset >= 0 ? "+" : "-") + offset;
                } else {
                    if (offset != IBuilderData.NOT_AVAILABLE) {
                        name = name + (offset >= 0 ? "+" : "-") + offset;
                    } else {
                        if (address != IBuilderData.NOT_AVAILABLE) {
                            name = name + "::0x" + Long.toHexString(address);
                        }
                    }
                }
            } else {
                if (routine != null) {
                    if (offset != IBuilderData.NOT_AVAILABLE) {
                        name = "::" + routine + (offset >= 0 ? "+" : "-") + offset;
                    } else {
                        name = "::" + routine;
                    }
                } else {
                    if (address != IBuilderData.NOT_AVAILABLE) {
                        name = "::0x" + Long.toHexString(address);
                    } else {
                        name = null;
                    }
                }
            }
            fImageProcessBuilder.addImageStackFrame(threadID, name, 0, address);
        }
    }
}
Also used : IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 15 with ImageModule

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

the class OpenCommand method createCombinedContext.

private void createCombinedContext(final Image loadedImage, final int major, final int minor, final ImageAddressSpace space, final ImageProcess proc, final JavaRuntime rt, String coreFilePath) {
    // take the DTFJ context and attempt to combine it with a DDR interactive one
    Object obj = ctx.getProperties().get(SessionProperties.SESSION_PROPERTY);
    if (obj == null) {
        logger.fine("Could not create a new context as the session property has not been set");
        return;
    }
    if (!(obj instanceof Session)) {
        logger.fine("Could not create a new context as the session type was not recognised [" + obj.getClass().getName() + "]");
        return;
    }
    JdmpviewContextManager mgr = (JdmpviewContextManager) ((ISession) obj).getContextManager();
    CombinedContext cc = (CombinedContext) mgr.createContext(loadedImage, major, minor, space, proc, rt);
    cc.startDDRInteractiveSession(loadedImage, out);
    cc.getProperties().put(CORE_FILE_PATH_PROPERTY, coreFilePath);
    cc.getProperties().put(IMAGE_FACTORY_PROPERTY, getFactory());
    if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
        cc.getProperties().put(VERBOSE_MODE_PROPERTY, "true");
    }
    try {
        // flag to indicate if native libs are required but not present
        boolean hasLibError = true;
        String os = cc.getImage().getSystemType().toLowerCase();
        if (os.contains("linux") || (os.contains("aix"))) {
            if (cc.getProcess() != null) {
                Iterator<?> modules = cc.getProcess().getLibraries();
                if (modules.hasNext()) {
                    obj = modules.next();
                    if (obj instanceof ImageModule) {
                        // there is at least one native lib available
                        hasLibError = false;
                    }
                }
            }
        } else {
            hasLibError = false;
        }
        if (hasLibError) {
            out.println("Warning : native libraries are not available for " + coreFilePath);
        }
    } catch (DataUnavailable e) {
        logger.log(Level.FINE, "Warning : native libraries are not available for " + coreFilePath);
    } catch (Exception e) {
        logger.log(Level.FINE, "Error determining if native libraries are required for " + coreFilePath, e);
    }
}
Also used : JdmpviewContextManager(com.ibm.jvm.dtfjview.JdmpviewContextManager) CombinedContext(com.ibm.jvm.dtfjview.CombinedContext) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageModule(com.ibm.dtfj.image.ImageModule) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException) IOException(java.io.IOException) ISession(com.ibm.jvm.dtfjview.spi.ISession) Session(com.ibm.jvm.dtfjview.Session)

Aggregations

ImageModule (com.ibm.dtfj.image.ImageModule)15 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)6 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)5 ImageProcess (com.ibm.dtfj.image.ImageProcess)5 Iterator (java.util.Iterator)5 CorruptData (com.ibm.dtfj.image.CorruptData)3 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)3 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)3 IOException (java.io.IOException)3 Image (com.ibm.dtfj.image.Image)2 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)2 ImageFactory (com.ibm.dtfj.image.ImageFactory)2 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)2 ImageSection (com.ibm.dtfj.image.ImageSection)1 ImageThread (com.ibm.dtfj.image.ImageThread)1 JCImageModule (com.ibm.dtfj.image.javacore.JCImageModule)1 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)1 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)1 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)1 ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)1