Example usage for java.lang.management RuntimeMXBean getInputArguments

List of usage examples for java.lang.management RuntimeMXBean getInputArguments

Introduction

In this page you can find the example usage for java.lang.management RuntimeMXBean getInputArguments.

Prototype

public java.util.List<String> getInputArguments();

Source Link

Document

Returns the input arguments passed to the Java virtual machine which does not include the arguments to the main method.

Usage

From source file:pl.edu.icm.visnow.system.main.VisNow.java

private void initMemory() {
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    List<String> aList = RuntimemxBean.getInputArguments();

    for (int i = 0; i < aList.size(); i++) {
        String str = aList.get(i);
        if (debug) {
            LOGGER.info("JVM input argument #" + i + ": " + str);
        }//from   ww  w  .j a v a2 s . c  o  m
        if (str.startsWith("-Xmx")) {
            String amount = str.substring(4, str.length() - 1);
            String unit = str.substring(str.length() - 1);
            try {
                memoryMax = Long.parseLong(amount);
                if (unit.equalsIgnoreCase("k")) {
                    memoryMax *= 1024L;
                } else if (unit.equalsIgnoreCase("m")) {
                    memoryMax *= 1024L * 1024L;
                } else if (unit.equalsIgnoreCase("g")) {
                    memoryMax *= 1024L * 1024L * 1024L;
                }
            } catch (NumberFormatException ex) {
                memoryMax = Long.MAX_VALUE;
                return;
            }
            if (debug) {
                LOGGER.info("VisNow started with maximum memory: " + memoryMax + " bytes");
            }
        }
    }

}

From source file:ro.nextreports.server.web.debug.InfoUtil.java

public static List<String> getJVMArguments() {
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    return runtimeBean.getInputArguments();
}

From source file:rocks.inspectit.shared.all.util.UnderlyingSystemInfo.java

/**
 * Tests if the compressed pointers are used. Note that this method will return true only if the
 * JVM is 64bit, ignoring the fact that the 32bit JVM can also have
 * <code>+UseCompressedOops</code> argument. This method has been tested with Sun & IBM virtual
 * machine, and behavior with different providers is unknown.
 * <p>/*from  ww  w.  j a  v  a2 s  . c o  m*/
 * IMPORTANT (SUN & ORACLE): Compressed oops is supported and enabled by default in Java SE 6u23
 * and later. In Java SE 7, use of compressed oops is the default for 64-bit JVM processes when
 * -Xmx isn't specified and for values of -Xmx less than 32 gigabytes. For JDK 6 before the 6u23
 * release, use the -XX:+UseCompressedOops flag with the java command to enable the feature.
 * <p>
 * IMPORTANT (IBM): From Java 6 SR 5, 64-bit JVMs recognize the following Oracle JVM options:
 * -XX:+UseCompressedOops This enables compressed references in 64-bit JVMs. It is identical to
 * specifying the -Xcompressedrefs option. -XX:-UseCompressedOops This prevents use of
 * compressed references in 64-bit JVMs.
 *
 * @return True only if JVM is 64bit and compressed oops are used.
 */
private static boolean isCompressedOops() {
    if (IS_64BIT) {
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        if (null != runtimeMXBean) {
            List<String> arguments = runtimeMXBean.getInputArguments();
            for (String argument : arguments) {
                if ((argument.indexOf("+UseCompressedOops") != -1)
                        || (argument.indexOf("compressedrefs") != -1)) {
                    return true;
                } else if (argument.indexOf("-UseCompressedOops") != -1) {
                    return false;
                }
            }
        }

        switch (getJvmProvider()) {
        case SUN:
        case ORACLE:
            if (getJavaVersion() == JavaVersion.JAVA_1_7) {
                long max = Runtime.getRuntime().maxMemory();
                return (max == Long.MAX_VALUE) || (max < MAX_COMPRESSED_OOPS_JAVA7_MEMORY);
            } else if (getJavaVersion() == JavaVersion.JAVA_1_6) {
                try {
                    int subversionIndexStart = JAVA_VERSION_TRIMMED.indexOf('_');
                    boolean isAbove6u23 = Integer
                            .parseInt(JAVA_VERSION_TRIMMED.substring(subversionIndexStart + 1)) >= 23;
                    return isAbove6u23;
                } catch (NumberFormatException e) {
                    break;
                }
            }
            break;

        default:
            break;
        }
    }
    return false;
}