Java Code Examples for java.lang.management.MemoryUsage#getInit()

The following examples show how to use java.lang.management.MemoryUsage#getInit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryData.java    From openjdk-systemtest with Apache License 2.0 6 votes vote down vote up
private void checkMemoryUsage (MemoryUsage memUsage, String usage_type, String connect_type) {
	// Get the elements of a MemoryUsage object and check they are valid
	long init   = memUsage.getInit();
	long used   = memUsage.getUsed();
	long commit = memUsage.getCommitted();
	long max    = memUsage.getMax();

	String formatter = "        ";
	if(usage_type.contains("Non")){
		formatter = "    ";
	} else if (usage_type.contains("Current")) {
		formatter = "     ";
	} else if (usage_type.contains("Peak")) {
		formatter = "        ";
	} else if (usage_type.contains("Collection")) {
		formatter = "  ";
	}
	out.println("  " + usage_type + " Memory Usage:" + formatter + memUsage.toString());

	checkMemoryUsageElements(connect_type, usage_type, init, max, commit, used);
}
 
Example 2
Source File: TestNewSizeFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Get young gen memory usage.
 *
 *  For G1 it is EdenUsage + SurvivorUsage,
 *  for other GCs it is EdenUsage + 2 * SurvivorUsage.
 *  For G1 max value is just LONG_MAX.
 *  For all GCs used value is 0.
 */
private static MemoryUsage getYoungGenUsage() {
    MemoryUsage edenUsage = HeapRegionUsageTool.getEdenUsage();
    MemoryUsage survivorUsage = HeapRegionUsageTool.getSurvivorUsage();
    long edenUsageInit = edenUsage.getInit();
    long edenUsageCommited = edenUsage.getCommitted();
    long survivorUsageInit = survivorUsage.getInit();
    long survivorUsageCommited = survivorUsage.getCommitted();

    if (YOUNG_GC_TYPE == GCTypes.YoungGCType.G1) {
        return new MemoryUsage(edenUsageInit + survivorUsageInit, 0,
                edenUsageCommited + survivorUsageCommited, Long.MAX_VALUE);
    } else {
        return new MemoryUsage(edenUsageInit + survivorUsageInit * 2, 0,
                edenUsageCommited + survivorUsageCommited * 2,
                edenUsage.getMax() + survivorUsage.getMax() * 2);
    }
}
 
Example 3
Source File: MemorySampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMMemSignature())) {
		return new IMonitoringRecord[] {};
	}

	final MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
	final MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage();
	final MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage();

	return new IMonitoringRecord[] { new MemoryRecord(timestamp, hostname, vmName, heapMemoryUsage.getMax(), heapMemoryUsage.getUsed(),
			heapMemoryUsage.getCommitted(), heapMemoryUsage.getInit(), nonHeapMemoryUsage.getMax(), nonHeapMemoryUsage.getUsed(),
			nonHeapMemoryUsage.getCommitted(), nonHeapMemoryUsage.getInit(), memoryBean.getObjectPendingFinalizationCount()), };
}
 
Example 4
Source File: DiagnosticTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void logMemoryUsage(StringBuilder sb, MemoryUsage usage, String label) {
//        long used, commited;
        long init, max;
        init = usage.getInit();
//        used = usage.getUsed();
//        commited = usage.getCommitted();
        max = usage.getMax();
//        sb.append(label).append(" usage: used ").append(formatBytes(used)) // NOI18N
//                .append(" of ").append(formatBytes(commited)); // NOI18N
        sb.append(label).append(" usage: initial ").append(formatBytes(init)) // NOI18N
                .append(" maximum ").append(formatBytes(max)).append('\n'); // NOI18N
    }
 
Example 5
Source File: TestNewSizeFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Verify that actual young gen size conforms NewSize and MaxNewSize values.
 */
public static Void verifyNewSize(long newSize, long maxNewSize,
        long initialHeapSize, long maxHeapSize) {
    long alignedNewSize = alignGenSize(newSize);
    long alignedMaxNewSize = alignGenSize(maxNewSize);
    long alignedXms = alignHeapSize(initialHeapSize);
    long alignedXmx = alignHeapSize(maxHeapSize);

    MemoryUsage youngGenUsage = getYoungGenUsage();
    long initSize = youngGenUsage.getInit();
    long commitedSize = youngGenUsage.getCommitted();
    long maxSize = youngGenUsage.getMax();

    if (newSize != -1) {
        if (initSize < alignedNewSize) {
            throw new RuntimeException("initial new size < NewSize value: "
                    + initSize + " < " + alignedNewSize);
        }

        if (commitedSize < alignedNewSize) {
            throw new RuntimeException("actual new size < NewSize value: "
                    + commitedSize + " < " + alignedNewSize);
        }

        // for G1 max new size == committed new size
        if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
                && maxSize < alignedNewSize) {
            throw new RuntimeException("max new size < NewSize value: "
                    + maxSize + " < " + alignedNewSize);
        }
    }

    if (maxNewSize != -1) {
        if (initSize > alignedMaxNewSize) {
            throw new RuntimeException("initial new size > MaxNewSize value: "
                    + initSize + " > " + alignedMaxNewSize);
        }

        if (commitedSize > alignedMaxNewSize) {
            throw new RuntimeException("actual new size > MaxNewSize value: "
                    + commitedSize + " > " + alignedMaxNewSize);
        }

        if (alignedXms != alignedXmx) {
            if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
                    && maxSize != alignedMaxNewSize) {
                throw new RuntimeException("max new size != MaxNewSize value: "
                        + maxSize + " != " + alignedMaxNewSize);
            }
        } else {
            if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
                    && maxSize != alignedNewSize) {
                throw new RuntimeException("max new size != NewSize for case InitialHeapSize == MaxHeapSize value: "
                        + maxSize + " != " + alignedNewSize + " HeapSize == " + alignedXms);
            }
        }
    }
    return null;
}
 
Example 6
Source File: MemoryUsageCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 7
Source File: MemoryUsageCompositeData.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 8
Source File: MemoryUsageCompositeData.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 9
Source File: MemoryUsageCompositeData.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 10
Source File: MemoryUsageCompositeData.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 11
Source File: MemoryUsageCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 12
Source File: MemoryUsageCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 13
Source File: MemoryUsageCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 14
Source File: MemoryUsageCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 15
Source File: MemoryUsageCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 16
Source File: MemoryUsageCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 17
Source File: MemoryMonitor.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
public void installMonitor(){
        //get all the GarbageCollectorMXBeans - there's one for each heap generation
        //so probably two - the old generation and young generation
        List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
        //Install a notification handler for each bean
        for (GarbageCollectorMXBean gcbean : gcbeans) {
            NotificationEmitter emitter = (NotificationEmitter) gcbean;
            //use an anonymously generated listener for this example
            // - proper code should really use a named class
            NotificationListener listener = new NotificationListener() {
                //keep a count of the total time spent in GCs
                long totalGcDuration = 0;

                //implement the notifier callback handler
                @Override
                public void handleNotification(Notification notification, Object handback) {
                    //we only handle GARBAGE_COLLECTION_NOTIFICATION notifications here
                    if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                        //get the information associated with this notification
                        GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
                        //get all the info and pretty print it
                        //Get the information about each memory space, and pretty print it
                        Map<String, MemoryUsage> membefore = info.getGcInfo().getMemoryUsageBeforeGc();
                        Map<String, MemoryUsage> mem = info.getGcInfo().getMemoryUsageAfterGc();
                        long memInit=0;
                        long memCommitted=0;
                        long memMax=0;
                        long memUsed=0;
//                        MemoryUsage before;

                        for (Map.Entry<String, MemoryUsage> entry : mem.entrySet()) {
                            String name = entry.getKey();
                            MemoryUsage memdetail = entry.getValue();
                             memInit += memdetail.getInit();
                             memCommitted += memdetail.getCommitted();
                             memMax += memdetail.getMax();
                             memUsed += memdetail.getUsed();
 //                           MemoryUsage before = membefore.get(name);
//                            System.out.print(name + (memCommitted==memMax?"(fully expanded)":"(still expandable)") +"used: "+(beforepercent/10)+"."+(beforepercent%10)+"%->"+(percent/10)+"."+(percent%10)+"%("+((memUsed/1048576)+1)+"MB) / ");
                        }
//                        System.out.println(" Mem max (max used or available?)"+memMax/100000+" mem used (before or after?)"+memUsed/100000+" mem committed? ="+memCommitted/1000000);
                        if(memMax>maxMemMax)
                            maxMemMax=memMax;
                        if(memUsed>maxMemUsed)
                            maxMemUsed=memUsed;
                        if(memCommitted>maxMemCommitted)
                            maxMemCommitted= memCommitted;
                    }
                }
            };
            //Add the listener
            emitter.addNotificationListener(listener, null, null);
        }
    }
 
Example 18
Source File: MemoryUsageCompositeData.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 19
Source File: MemoryUsageCompositeData.java    From native-obfuscator with GNU General Public License v3.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}
 
Example 20
Source File: MemoryUsageCompositeData.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void createGoodCompositeData() throws Exception {
    final int K = 1024;
    // these values are synchronized with the item names
    final Object[] values = {
        new Long(5 * K),  // committed
        new Long(1 * K),  // init
        new Long(10 * K), // max
        new Long(2 * K),  // used
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 memoryUsageItemNames,
                                 values);
    MemoryUsage u = MemoryUsage.from(cd);
    if (u.getInit() != ((Long) values[INIT]).longValue()) {
        throw new RuntimeException("init = " + u.getInit() +
           " expected = " + values[INIT]);
    }
    if (u.getUsed() != ((Long) values[USED]).longValue()) {
        throw new RuntimeException("used = " + u.getUsed() +
           " expected = " + values[USED]);
    }
    if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
        throw new RuntimeException("committed = " + u.getCommitted() +
           " expected = " + values[COMMITTED]);
    }
    if (u.getMax() != ((Long) values[MAX]).longValue()) {
        throw new RuntimeException("max = " + u.getMax() +
           " expected = " + values[MAX]);
    }
    System.out.println(u);
}