Java Code Examples for java.lang.management.ManagementFactory.getCompilationMXBean()

The following are Jave code examples for showing how to use getCompilationMXBean() of the java.lang.management.ManagementFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: swage   File: CompilationTimeSensor.java   View Source Code Vote up 6 votes
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    CompilationMXBean mxBean = ManagementFactory.getCompilationMXBean();

    // Compilation time may not be supported on some platforms, skip if so.
    if (!mxBean.isCompilationTimeMonitoringSupported()) {
        return;
    }

    long total = mxBean.getTotalCompilationTime();
    metricContext.record(TOTAL_COMPILATION_TIME, total, Unit.MILLISECOND);
    metricContext.record(COMPILATION_TIME, total - prevTotal, Unit.MILLISECOND);

    this.prevTotal = total;
}
 
Example 2
Project: incubator-netbeans   File: DiagnosticTask.java   View Source Code Vote up 4 votes
private String logParams() {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Diagnostic information\n");
        try {
            RuntimeMXBean         rmBean     = ManagementFactory.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = ManagementFactory.getCompilationMXBean();
//            ThreadMXBean          tmBean     = ManagementFactory.getThreadMXBean();
            MemoryMXBean          memoryBean = ManagementFactory.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = ManagementFactory.getClassLoadingMXBean();

//            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//            ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
//            com.sun.management.OperatingSystemMXBean sunOSMBean  =
//               ManagementFactory.getSunOperatingSystemMXBean();

//            Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
//            System.out.println("System properties");
//            for (Map.Entry<String, String> entry: props.entrySet()) {
//                System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
//            }
            sb.append("Input arguments:");
            for (String s: rmBean.getInputArguments()) {
                sb.append("\n\t").append(s);
            }
            
            if (cmpMBean != null) {
                sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
            }
            
            // Memory
            MemoryUsage usage = memoryBean.getHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Heap memory");
            usage = memoryBean.getNonHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Non heap memory");
            for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
                sb.append("Garbage collector: ").append(gcMBean.getName())
                        .append(" (Collections=").append(gcMBean.getCollectionCount())
                        .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
                        .append(")\n");
            }
            
            // classes
            int clsLoaded;
            long clsTotal, clsUnloaded;
            clsLoaded = clMBean.getLoadedClassCount();
            clsTotal = clMBean.getTotalLoadedClassCount();
            clsUnloaded = clMBean.getUnloadedClassCount();
            sb.append("Classes: loaded=").append(clsLoaded)
                    .append(" total loaded=").append(clsTotal)
                    .append(" unloaded ").append(clsUnloaded).append('\n');

//        } catch (MalformedObjectNameException ex) {
//            Logger.getLogger("global").log(Level.WARNING, null, ex);
        } catch (NullPointerException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
        return sb.toString();
    }
 
Example 3
Project: OpenJSharp   File: JvmCompilationImpl.java   View Source Code Vote up 4 votes
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 4
Project: jdk8u-jdk   File: JvmCompilationImpl.java   View Source Code Vote up 4 votes
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 5
Project: openjdk-jdk10   File: CompileTheWorld.java   View Source Code Vote up 4 votes
/**
 * Entry point. Compiles classes in {@code paths}
 *
 * @param paths paths to jar/zip, dir contains classes, or to .lst file
 *              contains list of classes to compile
 */
public static void main(String[] paths) {
    if (paths.length == 0) {
        throw new IllegalArgumentException("Expect a path to a compile target.");
    }
    String logfile = Utils.LOG_FILE;
    PrintStream os = null;
    if (logfile != null) {
        try {
            os = new PrintStream(Files.newOutputStream(Paths.get(logfile)));
        } catch (IOException io) {
        }
    }
    if (os != null) {
        OUT = os;
    }

    boolean passed = false;

    try {
        try {
            if (ManagementFactory.getCompilationMXBean() == null) {
                throw new RuntimeException(
                        "CTW can not work in interpreted mode");
            }
        } catch (java.lang.NoClassDefFoundError e) {
            // compact1, compact2 support
        }
        ExecutorService executor = createExecutor();
        long start = System.currentTimeMillis();
        try {
            Arrays.stream(paths)
                  .map(PathHandler::create)
                  .flatMap(List::stream)
                  .forEach(p -> {
                      try {
                          p.process(executor);
                      } finally {
                          p.close();
                      }
                    });
        } finally {
            await(executor);
        }
        CompileTheWorld.OUT.printf("Done (%d classes, %d methods, %d ms)%n",
                PathHandler.getProcessedClassCount(),
                Compiler.getMethodCount(),
                System.currentTimeMillis() - start);
        passed = true;
    } catch (Throwable t){
        t.printStackTrace(ERR);
    } finally {
        try {
            OUT.close();
        } catch (Throwable ignore) {
        }
        // <clinit> might have started new threads
        System.exit(passed ? 0 : 1);
    }
}
 
Example 6
Project: java-performance   File: Compilation.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();
    System.out.println("Total compilation time: " + compilationMXBean.getTotalCompilationTime());
}
 
Example 7
Project: OpenJSharp   File: JVM_MANAGEMENT_MIB_IMPL.java   View Source Code Vote up 3 votes
/**
 * Factory method for "JvmCompilation" group metadata class.
 *
 * You can redefine this method if you need to replace the default
 * generated metadata class with your own customized class.
 *
 * @param groupName Name of the group ("JvmCompilation")
 * @param groupOid  OID of this group
 * @param groupObjname ObjectName for this group (may be null)
 * @param server    MBeanServer for this group (may be null)
 *
 * @return An instance of the metadata class generated for the
 *         "JvmCompilation" group (JvmCompilationMeta)
 *
 **/
protected JvmCompilationMeta
    createJvmCompilationMetaNode(String groupName,
                                 String groupOid,
                                 ObjectName groupObjname,
                                 MBeanServer server)  {
    // If there is no compilation system, the jvmCompilation  will not
    // be instantiated.
    //
    if (ManagementFactory.getCompilationMXBean() == null) return null;
    return super.createJvmCompilationMetaNode(groupName,groupOid,
                                              groupObjname,server);
}
 
Example 8
Project: jdk8u-jdk   File: JVM_MANAGEMENT_MIB_IMPL.java   View Source Code Vote up 3 votes
/**
 * Factory method for "JvmCompilation" group metadata class.
 *
 * You can redefine this method if you need to replace the default
 * generated metadata class with your own customized class.
 *
 * @param groupName Name of the group ("JvmCompilation")
 * @param groupOid  OID of this group
 * @param groupObjname ObjectName for this group (may be null)
 * @param server    MBeanServer for this group (may be null)
 *
 * @return An instance of the metadata class generated for the
 *         "JvmCompilation" group (JvmCompilationMeta)
 *
 **/
protected JvmCompilationMeta
    createJvmCompilationMetaNode(String groupName,
                                 String groupOid,
                                 ObjectName groupObjname,
                                 MBeanServer server)  {
    // If there is no compilation system, the jvmCompilation  will not
    // be instantiated.
    //
    if (ManagementFactory.getCompilationMXBean() == null) return null;
    return super.createJvmCompilationMetaNode(groupName,groupOid,
                                              groupObjname,server);
}