Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246259: JFR: Fetch VM memory pools without using streams
Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Jun 1, 2020
1 parent 5e5880d commit 567692e4ae0be6335dee9319841cf78c1ab57d6d
@@ -26,31 +26,36 @@
package jdk.jfr.events;

import jdk.internal.misc.VM.BufferPool;

import jdk.internal.misc.VM;
import jdk.jfr.*;
import jdk.jfr.internal.Type;

@Category({ "Java Application", "Statistics" })
public abstract class AbstractBufferStatisticsEvent extends AbstractJDKEvent {

AbstractBufferStatisticsEvent() {
BufferPool bufferPool = getBufferPool();

protected AbstractBufferStatisticsEvent(BufferPool bufferPool) {
count = bufferPool.getCount();
totalCapacity = bufferPool.getTotalCapacity();
memoryUsed = bufferPool.getMemoryUsed();
}

@Label("Count")
public long count;
final long count;

@Label("Total Capacity")
@DataAmount
public long totalCapacity;
final long totalCapacity;

@Label("Memory Used")
@DataAmount
public long memoryUsed;

abstract BufferPool getBufferPool();
final long memoryUsed;

static BufferPool findPoolByName(String name) {
for (BufferPool pool : VM.getBufferPools()) {
if (pool.getName().equals(name)) {
return pool;
}
}
throw new InternalError("No buffer pool with name " + name);
}
}
@@ -36,20 +36,15 @@
@Description("Statistics of direct buffer")
public final class DirectBufferStatisticsEvent extends AbstractBufferStatisticsEvent {

private static final BufferPool DIRECT_BUFFER_POOL = VM.getBufferPools().stream()
.filter(p -> "direct".equals(p.getName()))
.findFirst().get();
private static final BufferPool DIRECT_BUFFER_POOL = findPoolByName("direct");

public DirectBufferStatisticsEvent() {
super(DIRECT_BUFFER_POOL);
this.maxCapacity = VM.maxDirectMemory();
}

@Label("Maximum Capacity")
@Description("Maximum direct buffer capacity the process can use")
@DataAmount
public long maxCapacity;

BufferPool getBufferPool() {
return DIRECT_BUFFER_POOL;
}
final long maxCapacity;
}

0 comments on commit 567692e

Please sign in to comment.