Search in sources :

Example 21 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project geode by apache.

the class HeapMemoryMonitor method getAllMemoryPoolNames.

/**
   * Returns the names of all available memory pools as a single string.
   */
private static String getAllMemoryPoolNames() {
    StringBuilder builder = new StringBuilder("[");
    for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) {
        builder.append("(Name=").append(memoryPoolBean.getName()).append(";Type=").append(memoryPoolBean.getType()).append(";UsageThresholdSupported=").append(memoryPoolBean.isUsageThresholdSupported()).append("), ");
    }
    if (builder.length() > 1) {
        builder.setLength(builder.length() - 2);
    }
    builder.append("]");
    return builder.toString();
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 22 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project Lucee by lucee.

the class MacAddressWrap method getMemoryUsageCompact.

public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct = new StructImpl();
    while (it.hasNext()) {
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
            continue;
        if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
            continue;
        double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
        sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType) Struct(lucee.runtime.type.Struct)

Example 23 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project checker-framework by typetools.

the class SourceChecker method printStats.

/**
 * Print resource usage statistics
 */
protected void printStats() {
    List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean memoryPool : memoryPools) {
        System.out.println("Memory pool " + memoryPool.getName() + " statistics");
        System.out.println("  Pool type: " + memoryPool.getType());
        System.out.println("  Peak usage: " + memoryPool.getPeakUsage());
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 24 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project Payara by payara.

the class MemoryReporter method getMemoryPoolReport.

private String getMemoryPoolReport() {
    final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder());
    final long millis = rmbean.getUptime();
    final String uptime = sm.getString("uptime", JVMInformationCollector.millis2HoursMinutesSeconds(millis));
    sb.append(uptime);
    for (final MemoryPoolMXBean m : pools) {
        final String n = m.getName();
        sb.append(sm.getString("memory.pool.name", n));
        MemoryUsage mu = m.getUsage();
        sb.append(mu2String(mu));
    }
    return (sb.toString());
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 25 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project oap by oaplatform.

the class ObjectSizeCalculator method getEffectiveMemoryLayoutSpecification.

@VisibleForTesting
static MemoryLayoutSpecification getEffectiveMemoryLayoutSpecification() {
    final String vmName = System.getProperty("java.vm.name");
    if (vmName == null || !(vmName.startsWith("Java HotSpot(TM) ") || vmName.startsWith("OpenJDK") || vmName.startsWith("TwitterJDK"))) {
        throw new UnsupportedOperationException("ObjectSizeCalculator only supported on HotSpot VM");
    }
    final String dataModel = System.getProperty("sun.arch.data.model");
    if ("32".equals(dataModel)) {
        // Running with 32-bit data model
        return new MemoryLayoutSpecification() {

            @Override
            public int getArrayHeaderSize() {
                return 12;
            }

            @Override
            public int getObjectHeaderSize() {
                return 8;
            }

            @Override
            public int getObjectPadding() {
                return 8;
            }

            @Override
            public int getReferenceSize() {
                return 4;
            }

            @Override
            public int getSuperclassFieldPadding() {
                return 4;
            }
        };
    } else if (!"64".equals(dataModel)) {
        throw new UnsupportedOperationException("Unrecognized value '" + dataModel + "' of sun.arch.data.model system property");
    }
    final String strVmVersion = System.getProperty("java.vm.version");
    final int vmVersion = Integer.parseInt(strVmVersion.substring(0, strVmVersion.indexOf('.')));
    if (vmVersion >= 17) {
        long maxMemory = 0;
        for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) {
            maxMemory += mp.getUsage().getMax();
        }
        if (maxMemory < 30L * 1024 * 1024 * 1024) {
            // for all memory pools (yes, including code cache).
            return new MemoryLayoutSpecification() {

                @Override
                public int getArrayHeaderSize() {
                    return 16;
                }

                @Override
                public int getObjectHeaderSize() {
                    return 12;
                }

                @Override
                public int getObjectPadding() {
                    return 8;
                }

                @Override
                public int getReferenceSize() {
                    return 4;
                }

                @Override
                public int getSuperclassFieldPadding() {
                    return 4;
                }
            };
        }
    }
    // In other cases, it's a 64-bit uncompressed OOPs object model
    return new MemoryLayoutSpecification() {

        @Override
        public int getArrayHeaderSize() {
            return 24;
        }

        @Override
        public int getObjectHeaderSize() {
            return 16;
        }

        @Override
        public int getObjectPadding() {
            return 8;
        }

        @Override
        public int getReferenceSize() {
            return 8;
        }

        @Override
        public int getSuperclassFieldPadding() {
            return 8;
        }
    };
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)107 MemoryUsage (java.lang.management.MemoryUsage)43 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)16 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)11 MemoryMXBean (java.lang.management.MemoryMXBean)10 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 ReflectionException (javax.management.ReflectionException)9 NotificationEmitter (javax.management.NotificationEmitter)8 MemoryType (java.lang.management.MemoryType)7 HashMap (java.util.HashMap)7 AttributeNotFoundException (javax.management.AttributeNotFoundException)7 IntrospectionException (javax.management.IntrospectionException)7 MBeanException (javax.management.MBeanException)7 Map (java.util.Map)6 Attribute (javax.management.Attribute)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ThreadMXBean (java.lang.management.ThreadMXBean)5 Test (org.junit.Test)5