当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactoryHelper类代码示例

本文整理汇总了Java中sun.management.ManagementFactoryHelper的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactoryHelper类的具体用法?Java ManagementFactoryHelper怎么用?Java ManagementFactoryHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ManagementFactoryHelper类属于sun.management包,在下文中一共展示了ManagementFactoryHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
/**
 * Template method for testing. Prints tested method's info before
 * {@linkplain #test()} and after {@linkplain #test()} or on thrown
 * exception.
 *
 * @throws RuntimeException if method {@linkplain #test()} throws any
 *                          exception
 * @see #test()
 */
protected final void runTest() {
    if (ManagementFactoryHelper.getCompilationMXBean() == null) {
        System.err.println(
                "Warning: test is not applicable in interpreted mode");
        return;
    }
    System.out.println("at test's start:");
    printInfo();
    try {
        test();
    } catch (Exception e) {
        System.out.printf("on exception '%s':", e.getMessage());
        printInfo();
        e.printStackTrace();
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RuntimeException(e);
    }
    System.out.println("at test's end:");
    printInfo();
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:32,代码来源:CompilerWhiteBoxTest.java

示例2: executeDcmd

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
private static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    String cmdString = cmd + " " +
        Arrays.stream(args).collect(Collectors.joining(" "));
    File f = new File("dcmdoutput-" + cmd + "-" + System.currentTimeMillis() + ".txt");
    System.out.println("Output from Dcmd '" + cmdString + "' is being written to file " + f);
    try (FileWriter fw = new FileWriter(f)) {
        fw.write("> " + cmdString + ":");
        String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
        fw.write(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:NMTHelper.java

示例3: test

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
private final void test() {
    System.gc();
    MemoryUsagePrinter.printMemoryUsage("init");

    allocate();
    MemoryUsagePrinter.printMemoryUsage("allocated");
    MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    free();
    MemoryUsagePrinter.printMemoryUsage("free");
    MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
            "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
            + "%s = %s%n%s = %s",
            MIN_FREE_RATIO_FLAG_NAME,
            ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
            MAX_FREE_RATIO_FLAG_NAME,
            ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
    ));
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:22,代码来源:TestHumongousShrinkHeap.java

示例4: executeDcmd

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
private static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    try {
        System.out.print("> " + cmd + " ");
        for (String s : args) {
            System.out.print(s + " ");
        }
        System.out.println(":");
        String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
        System.out.println(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:20,代码来源:NMTHelper.java

示例5: getVMOption

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
protected static String getVMOption(String name) {
    Objects.requireNonNull(name);
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    VMOption tmp;
    try {
        tmp = diagnostic.getVMOption(name);
    } catch (IllegalArgumentException e) {
        tmp = null;
    }
    return (tmp == null ? null : tmp.getValue());
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:20,代码来源:CompilerWhiteBoxTest.java

示例6: doMethodInBacktraceTestB

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
private void doMethodInBacktraceTestB() throws Exception {
    // Start a thread which blocks in method
    Thread t = new Thread(RedefineMethodInBacktraceTargetB::methodToRedefine);
    t.setDaemon(true);
    t.start();

    // Wait here until the new thread is in the method we want to redefine
    called.await();

    // Now redefine the class while the method is still on the stack of the new thread
    doRedefine(RedefineMethodInBacktraceTargetB.class);

    // Do thread dumps in two different ways (to exercise different code paths)
    // while the old class is still on the stack

    ThreadInfo[] tis = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false);
    for(ThreadInfo ti : tis) {
        System.out.println(ti);
    }

    String[] threadPrintArgs = {};
    Object[] dcmdArgs = {threadPrintArgs};
    String[] signature = {String[].class.getName()};
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature));

    // release the thread
    stop.countDown();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:RedefineMethodInBacktraceApp.java

示例7: getDiagnosticCommandMBean

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
static synchronized DiagnosticCommandMBean getDiagnosticCommandMBean() {
    VMManagement jvm = ManagementFactoryHelper.getVMManagement();

    // Remote Diagnostic Commands may not be supported
    if (diagCommandMBean == null && jvm.isRemoteDiagnosticCommandsSupported()) {
        diagCommandMBean = new DiagnosticCommandImpl(jvm);
    }
    return diagCommandMBean;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DiagnosticCommandImpl.java

示例8: main

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
public static void main(String[] args) {
    HotSpotDiagnosticMXBean hsd = ManagementFactoryHelper.getDiagnosticMXBean();

    // 打印虚拟机的某个配置参数的值
    VMOption vmo = hsd.getVMOption("UseCompressedOops");
    System.out.println(vmo.getName() + " | " + vmo.getValue());

    hsd.getDiagnosticOptions().stream().forEach(System.out::println);
}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:10,代码来源:PrintVmOptions.java

示例9: main

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    System.out.println("Max memory= " + MAX_MEMORY + " bytes");

    int obj_size = 0;
    long seconds_to_run = 0;
    if (args.length != 2) {
        throw new RuntimeException("Object size argument must be supplied");
    } else {
        obj_size = Integer.parseInt(args[0]);
        seconds_to_run = Integer.parseInt(args[1]);
    }
    System.out.println("Objects size= " + obj_size + " bytes");
    System.out.println("Seconds to run=" + seconds_to_run);

    int region_size =
        Integer.parseInt(diagnostic.getVMOption("G1HeapRegionSize").getValue());
    if (obj_size < (region_size / 2)) {
        throw new RuntimeException("Object size " + obj_size +
                                   " is not humongous with region size " + region_size);
    }

    ExecutorService executor =
        Executors.newFixedThreadPool(THREAD_COUNT, new NamedThreadFactory());
    System.out.println("Starting " + THREAD_COUNT + " threads");

    for (int i = 0; i < THREAD_COUNT; i++) {
        executor.execute(new Runner(obj_size));
    }

    Thread.sleep(seconds_to_run * 1000);
    executor.shutdownNow();

    if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
        System.err.println("Thread pool did not terminate after 10 seconds after shutdown");
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:39,代码来源:TestGreyReclaimedHumongousObjects.java

示例10: prepareMessageCommittedIsNotLess

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
private String prepareMessageCommittedIsNotLess() {
    return String.format(
            "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
            + "%s = %s%n%s = %s",
            MIN_FREE_RATIO_FLAG_NAME,
            ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
            MAX_FREE_RATIO_FLAG_NAME,
            ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
    );
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:11,代码来源:TestShrinkDefragmentedHeap.java

示例11: testingG1GC

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
public static boolean testingG1GC() {
    HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    VMOption option = diagnostic.getVMOption("UseG1GC");
    if (option.getValue().equals("false")) {
      System.out.println("Skipping this test. It is only a G1 test.");
      return false;
    }
    return true;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:11,代码来源:TestSummarizeRSetStatsTools.java

示例12: main

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
public static void main(String[] args) {
  HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

  String expectedValue = getExpectedValue(args);
  VMOption option = diagnostic.getVMOption("G1HeapRegionSize");
  if (!expectedValue.equals(option.getValue())) {
    throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + option.getValue());
  }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:10,代码来源:TestG1HeapRegionSize.java

示例13: getVMOption

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
public static String getVMOption(String name) {
    String result;
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    result = diagnostic.getVMOption(name).getValue();
    return result;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:15,代码来源:Utils.java

示例14: main

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
public static void main(String[] args) {
  HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

  VMOption option = diagnostic.getVMOption("UseG1GC");
  if (option.getValue().equals("false")) {
    System.out.println("Skipping this test. It is only a G1 test.");
    return;
  }

  String expectedValue = getExpectedValue(args);
  option = diagnostic.getVMOption("G1HeapRegionSize");
  if (!expectedValue.equals(option.getValue())) {
    throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + option.getValue());
  }
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:16,代码来源:TestG1HeapRegionSize.java

示例15: initialize

import sun.management.ManagementFactoryHelper; //导入依赖的package包/类
/**
 * Initialize ThreadInfo object
 *
 * @param t             Thread
 * @param state         Thread state
 * @param lockObj       Object on which the thread is blocked
 * @param lockOwner     the thread holding the lock
 * @param blockedCount  Number of times blocked to enter a lock
 * @param blockedTime   Approx time blocked to enter a lock
 * @param waitedCount   Number of times waited on a lock
 * @param waitedTime    Approx time waited on a lock
 * @param stackTrace    Thread stack trace
 * @param lockedMonitors List of locked monitors
 * @param lockedSynchronizers List of locked synchronizers
 */
private void initialize(Thread t, int state, Object lockObj, Thread lockOwner,
                        long blockedCount, long blockedTime,
                        long waitedCount, long waitedTime,
                        StackTraceElement[] stackTrace,
                        MonitorInfo[] lockedMonitors,
                        LockInfo[] lockedSynchronizers) {
    this.threadId = t.getId();
    this.threadName = t.getName();
    this.threadState = ManagementFactoryHelper.toThreadState(state);
    this.suspended = ManagementFactoryHelper.isThreadSuspended(state);
    this.inNative = ManagementFactoryHelper.isThreadRunningNative(state);
    this.blockedCount = blockedCount;
    this.blockedTime = blockedTime;
    this.waitedCount = waitedCount;
    this.waitedTime = waitedTime;

    if (lockObj == null) {
        this.lock = null;
        this.lockName = null;
    } else {
        this.lock = new LockInfo(lockObj);
        this.lockName =
            lock.getClassName() + '@' +
                Integer.toHexString(lock.getIdentityHashCode());
    }
    if (lockOwner == null) {
        this.lockOwnerId = -1;
        this.lockOwnerName = null;
    } else {
        this.lockOwnerId = lockOwner.getId();
        this.lockOwnerName = lockOwner.getName();
    }
    if (stackTrace == null) {
        this.stackTrace = NO_STACK_TRACE;
    } else {
        this.stackTrace = stackTrace;
    }
    this.lockedMonitors = lockedMonitors;
    this.lockedSynchronizers = lockedSynchronizers;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:56,代码来源:ThreadInfo.java


注:本文中的sun.management.ManagementFactoryHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。