Search in sources :

Example 1 with JavaVMOption

use of com.ibm.dtfj.java.JavaVMOption in project openj9 by eclipse.

the class JavaVMOptionComparator method testEquals.

// getExtraInfo
// getOptionString
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaVMOption ddrVMOption = (JavaVMOption) ddrObject;
    JavaVMOption jextractVMOption = (JavaVMOption) jextractObject;
    // getExtraInfo
    if ((EXTRA_INFO & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrVMOption, jextractVMOption, "getExtraInfo");
    // getOptionString
    if ((OPTION_STRING & members) != 0)
        testJavaEquals(ddrVMOption, jextractVMOption, "getOptionString");
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption)

Example 2 with JavaVMOption

use of com.ibm.dtfj.java.JavaVMOption in project openj9 by eclipse.

the class DTFJUnitTest method getVMoption.

public static final String getVMoption(JavaRuntime rt, String optionName) {
    try {
        JavaVMInitArgs args = rt.getJavaVMInitArgs();
        Iterator<?> options = args.getOptions();
        while (options.hasNext()) {
            JavaVMOption option = (JavaVMOption) options.next();
            String data = option.getOptionString();
            if (data.startsWith(optionName)) {
                return data.substring(optionName.length());
            }
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot determine the value of " + optionName, e);
    }
    // no policy specified so using the default
    return "default";
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with JavaVMOption

use of com.ibm.dtfj.java.JavaVMOption in project openj9 by eclipse.

the class J9DDRImageProcess method getExecutablePathFromSystemProperties.

private String getExecutablePathFromSystemProperties() {
    Iterator<?> runtimeIt = getRuntimes();
    while (runtimeIt.hasNext()) {
        Object o = runtimeIt.next();
        if (o instanceof JavaRuntime) {
            JavaRuntime runtime = (JavaRuntime) o;
            try {
                JavaVMInitArgs args = runtime.getJavaVMInitArgs();
                Iterator<?> optionsIt = args.getOptions();
                Pattern javaHomePattern = Pattern.compile("-Djava.home=(.*)");
                while (optionsIt.hasNext()) {
                    Object optionObj = optionsIt.next();
                    if (optionObj instanceof JavaVMOption) {
                        JavaVMOption option = (JavaVMOption) optionObj;
                        Matcher m = javaHomePattern.matcher(option.getOptionString());
                        if (m.find()) {
                            String javaHome = m.group(1);
                            // Note this method not used on Windows - don't have to worry about .exe or \
                            return javaHome + "/bin/java";
                        }
                    }
                }
            } catch (Exception e) {
            // Ignore
            }
        }
    }
    return null;
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) DataUnavailableException(com.ibm.j9ddr.DataUnavailableException) DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 4 with JavaVMOption

use of com.ibm.dtfj.java.JavaVMOption 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 5 with JavaVMOption

use of com.ibm.dtfj.java.JavaVMOption in project openj9 by eclipse.

the class InfoMemoryCommand method printDbgmallocWarning.

private void printDbgmallocWarning(PrintStream out, JavaRuntime runtime) {
    try {
        boolean dbgmalloc = false;
        JavaVMInitArgs args = runtime.getJavaVMInitArgs();
        if (args != null) {
            Iterator<?> opts = args.getOptions();
            while (opts.hasNext()) {
                Object obj = opts.next();
                if (obj instanceof JavaVMOption) {
                    JavaVMOption opt = (JavaVMOption) obj;
                    if (COM_IBM_DBGMALLOC_PROPERTY.equals(opt.getOptionString())) {
                        dbgmalloc = true;
                    }
                }
            }
        }
        if (!dbgmalloc) {
            out.println();
            out.printf("Note: %s was not found in the Java VM init options.\nMemory allocated by some class library components will not have been recorded.\n", COM_IBM_DBGMALLOC_PROPERTY);
        }
    } catch (DataUnavailable du) {
        out.println("Java VM init options information unavailable.");
        logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
    } catch (CorruptDataException cde) {
        out.println("Corrupt Data encountered walking Java VM init options");
        logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
    }
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

JavaVMOption (com.ibm.dtfj.java.JavaVMOption)6 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)5 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageProcess (com.ibm.dtfj.image.ImageProcess)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 IOException (java.io.IOException)2 Image (com.ibm.dtfj.image.Image)1 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)1 ImageFactory (com.ibm.dtfj.image.ImageFactory)1 ImageModule (com.ibm.dtfj.image.ImageModule)1 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)1 DataUnavailableException (com.ibm.j9ddr.DataUnavailableException)1 DTFJCorruptDataException (com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException)1 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)1 CommandException (com.ibm.java.diagnostics.utils.commands.CommandException)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 Properties (java.util.Properties)1