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

The following examples show how to use java.lang.management.MemoryUsage#from() . 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: MemoryUsageCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void badTypeCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Integer(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          badMUItemTypes);
    CompositeData cd =
       new CompositeDataSupport(muct,
                                memoryUsageItemNames,
                                values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 2
Source File: MemoryUsageCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void badTypeCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Integer(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          badMUItemTypes);
    CompositeData cd =
       new CompositeDataSupport(muct,
                                memoryUsageItemNames,
                                values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 3
Source File: MemoryUsageCompositeData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void badTypeCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Integer(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          badMUItemTypes);
    CompositeData cd =
       new CompositeDataSupport(muct,
                                memoryUsageItemNames,
                                values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 4
Source File: MemoryUsageCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void badNameCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Long(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                           badMUItemNames,
                           badMUItemNames,
                           memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 badMUItemNames,
                                 values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 5
Source File: MemoryPoolAdapter.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
public long getTenuredMax()
  throws JMException
{
  CompositeData data
    = (CompositeData) _mbeanServer.getAttribute(getTenuredName(), "Usage");

  MemoryUsage usage = MemoryUsage.from(data);

  return usage.getMax();
}
 
Example 6
Source File: MemoryUsageCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void badNameCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Long(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                           badMUItemNames,
                           badMUItemNames,
                           memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 badMUItemNames,
                                 values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 7
Source File: MemoryUsageCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void badTypeCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Integer(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          badMUItemTypes);
    CompositeData cd =
       new CompositeDataSupport(muct,
                                memoryUsageItemNames,
                                values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 8
Source File: MemoryPoolAdapter.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
public long getEdenCommitted()
  throws JMException
{
  CompositeData data
    = (CompositeData) _mbeanServer.getAttribute(getEdenName(), "Usage");

  MemoryUsage usage = MemoryUsage.from(data);

  return usage.getCommitted();
}
 
Example 9
Source File: MemoryUsageCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void badNameCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Long(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                           badMUItemNames,
                           badMUItemNames,
                           memoryUsageItemTypes);
    CompositeData cd =
        new CompositeDataSupport(muct,
                                 badMUItemNames,
                                 values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 10
Source File: MemoryPoolAdapter.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
public long getEdenFree()
  throws JMException
{
  CompositeData data
    = (CompositeData) _mbeanServer.getAttribute(getEdenName(), "Usage");

  MemoryUsage usage = MemoryUsage.from(data);

  return usage.getMax() - usage.getUsed();
}
 
Example 11
Source File: MemoryUsageCompositeData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void badTypeCompositeData() throws Exception {
    final int K = 1024;
    final Object[] values = {
        new Integer(5 * K),
        new Long(1 * K),
        new Long(10 * K),
        new Long(2 * K),
        "Dummy",
        "Dummy",
    };

    CompositeType muct =
        new CompositeType("MyMemoryUsageCompositeType",
                          "CompositeType for MemoryUsage",
                          memoryUsageItemNames,
                          memoryUsageItemNames,
                          badMUItemTypes);
    CompositeData cd =
       new CompositeDataSupport(muct,
                                memoryUsageItemNames,
                                values);
    try {
        MemoryUsage u = MemoryUsage.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " +
            e.getMessage());
        return;
    }
    throw new RuntimeException(
        "IllegalArgumentException not thrown");
}
 
Example 12
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 13
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 14
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 15
Source File: MemoryNotifInfoCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static MemoryUsage getUsage(CompositeData cd) {
    CompositeData usageData = (CompositeData) cd.get(USAGE);
    return MemoryUsage.from(usageData);
}
 
Example 16
Source File: MemoryNotifInfoCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static MemoryUsage getUsage(CompositeData cd) {
    CompositeData usageData = (CompositeData) cd.get(USAGE);
    return MemoryUsage.from(usageData);
}
 
Example 17
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 18
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 19
Source File: MemoryNotifInfoCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static MemoryUsage getUsage(CompositeData cd) {
    CompositeData usageData = (CompositeData) cd.get(USAGE);
    return MemoryUsage.from(usageData);
}
 
Example 20
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);
}