use of java.lang.management.MemoryPoolMXBean in project siddhi by wso2.
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;
}
};
}
use of java.lang.management.MemoryPoolMXBean in project felix by apache.
the class MemoryUsageSupport method getMemoryPoolsJson.
final String getMemoryPoolsJson() {
final StringBuilder buf = new StringBuilder();
buf.append("[");
long usedTotal = 0;
long initTotal = 0;
long committedTotal = 0;
long maxTotal = 0;
final List<MemoryPoolMXBean> pools = getMemoryPools();
for (MemoryPoolMXBean pool : pools) {
buf.append("{");
buf.append("'name':'").append(pool.getName()).append('\'');
buf.append(",'type':'").append(pool.getType()).append('\'');
MemoryUsage usage = pool.getUsage();
final long used = usage.getUsed();
formatNumber(buf, "used", used);
if (used > -1) {
usedTotal += used;
}
final long init = usage.getInit();
formatNumber(buf, "init", init);
if (init > -1) {
initTotal += init;
}
final long committed = usage.getCommitted();
formatNumber(buf, "committed", committed);
committedTotal += committed;
final long max = usage.getMax();
formatNumber(buf, "max", usage.getMax());
final long score;
if (max == -1 || used == -1) {
score = 100;
} else {
maxTotal += max;
score = 100L * used / max;
}
buf.append(",'score':'").append(score).append("%'");
buf.append("},");
}
// totalisation
buf.append("{");
buf.append("'name':'Total','type':'TOTAL'");
formatNumber(buf, "used", usedTotal);
formatNumber(buf, "init", initTotal);
formatNumber(buf, "committed", committedTotal);
formatNumber(buf, "max", maxTotal);
final long score = 100L * usedTotal / maxTotal;
buf.append(",'score':'").append(score).append("%'");
buf.append("}");
buf.append("]");
return buf.toString();
}
use of java.lang.management.MemoryPoolMXBean in project felix by apache.
the class MemoryUsageSupport method printMemoryPools.
final void printMemoryPools(final PrintHelper pw) {
final List<MemoryPoolMXBean> pools = getMemoryPools();
for (MemoryPoolMXBean pool : pools) {
final String title = String.format("%s (%s, %s)", pool.getName(), pool.getType(), (pool.isValid() ? "valid" : "invalid"));
pw.title(title, 1);
pw.keyVal("Memory Managers", Arrays.asList(pool.getMemoryManagerNames()));
pw.keyVal("Peak Usage", pool.getPeakUsage());
pw.keyVal("Usage", pool.getUsage());
if (pool.isUsageThresholdSupported()) {
pw.keyVal("Usage Threshold", String.format("%d, %s, #exceeded=%d", pool.getUsageThreshold(), pool.isUsageThresholdExceeded() ? "exceeded" : "not exceeded", pool.getUsageThresholdCount()));
} else {
pw.val("Usage Threshold: not supported");
}
pw.keyVal("Collection Usage", pool.getCollectionUsage());
if (pool.isCollectionUsageThresholdSupported()) {
pw.keyVal("Collection Usage Threshold", String.format("%d, %s, #exceeded=%d", pool.getCollectionUsageThreshold(), pool.isCollectionUsageThresholdExceeded() ? "exceeded" : "not exceeded", pool.getCollectionUsageThresholdCount()));
} else {
pw.val("Collection Usage Threshold: not supported");
}
}
}
use of java.lang.management.MemoryPoolMXBean in project leopard by tanhaichao.
the class JvmManagement method printMemoryPool.
public static void printMemoryPool() {
// 获取多个内存池的使用情况
System.out.println("=======================MemoryPoolMXBean============================ ");
List<MemoryPoolMXBean> mpmList = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mpm : mpmList) {
System.out.println("getUsage " + mpm.getUsage());
System.out.println("getMemoryManagerNames " + StringUtils.join(mpm.getMemoryManagerNames(), ","));
}
}
use of java.lang.management.MemoryPoolMXBean in project qpid-broker-j by apache.
the class BrokerAttributeInjector method getInjectedAttributes.
@Override
public Collection<ConfiguredObjectInjectedAttribute<?, ?>> getInjectedAttributes() {
List<ConfiguredObjectInjectedAttribute<?, ?>> attributes = new ArrayList<>();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
String poolName = memoryPoolMXBean.getName().replace(" ", "");
String attributeName = "jvmMemoryMaximum" + poolName;
try {
Method getMemoryPoolMaximum = BrokerAttributeInjector.class.getDeclaredMethod("getMemoryPoolMaximum", Broker.class, MemoryPoolMXBean.class);
final ConfiguredObjectInjectedAttribute<?, ?> injectedStatistic = new ConfiguredDerivedInjectedAttribute<>(attributeName, getMemoryPoolMaximum, new Object[] { memoryPoolMXBean }, false, false, "", false, "", "Maximum size of memory pool " + memoryPoolMXBean.getName(), _typeValidator);
attributes.add(injectedStatistic);
} catch (NoSuchMethodException e) {
LOGGER.warn("Failed to inject attribute '{}'", attributeName, e);
}
}
return attributes;
}
Aggregations