8238665: Add JFR event for direct memory statistics

Reviewed-by: egahlin, alanb
This commit is contained in:
Denghui Dong 2020-04-14 20:36:33 +02:00
parent 1cc71b41de
commit a62a0e5282
13 changed files with 276 additions and 27 deletions

View file

@ -26,10 +26,10 @@
package java.nio;
import jdk.internal.access.JavaLangRefAccess;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import jdk.internal.misc.VM.BufferPool;
import java.util.concurrent.atomic.AtomicLong;
@ -210,7 +210,7 @@ class Bits { // package-private
assert cnt >= 0 && reservedMem >= 0 && totalCap >= 0;
}
static final JavaNioAccess.BufferPool BUFFER_POOL = new JavaNioAccess.BufferPool() {
static final BufferPool BUFFER_POOL = new BufferPool() {
@Override
public String getName() {
return "direct";

View file

@ -30,6 +30,7 @@ import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.foreign.MemorySegmentProxy;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM.BufferPool;
import jdk.internal.vm.annotation.ForceInline;
import java.util.Spliterator;
@ -758,7 +759,7 @@ public abstract class Buffer {
SharedSecrets.setJavaNioAccess(
new JavaNioAccess() {
@Override
public JavaNioAccess.BufferPool getDirectBufferPool() {
public BufferPool getDirectBufferPool() {
return Bits.BUFFER_POOL;
}

View file

@ -26,20 +26,16 @@
package jdk.internal.access;
import jdk.internal.access.foreign.MemorySegmentProxy;
import jdk.internal.misc.VM.BufferPool;
import java.nio.Buffer;
import java.nio.ByteBuffer;
public interface JavaNioAccess {
/**
* Provides access to information on buffer usage.
* Used by {@code jdk.internal.misc.VM}.
*/
interface BufferPool {
String getName();
long getCount();
long getTotalCapacity();
long getMemoryUsed();
}
BufferPool getDirectBufferPool();
/**

View file

@ -27,10 +27,16 @@ package jdk.internal.misc;
import static java.lang.Thread.State.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import jdk.internal.access.SharedSecrets;
import sun.nio.ch.FileChannelImpl;
public class VM {
// the init level when the VM is fully initialized
@ -414,4 +420,34 @@ public class VM {
* object class in the archived graph.
*/
public static native void initializeFromArchive(Class<?> c);
/**
* Provides access to information on buffer usage.
*/
public interface BufferPool {
String getName();
long getCount();
long getTotalCapacity();
long getMemoryUsed();
}
private static class BufferPoolsHolder {
static final List<BufferPool> BUFFER_POOLS;
static {
ArrayList<BufferPool> bufferPools = new ArrayList<>(3);
bufferPools.add(SharedSecrets.getJavaNioAccess().getDirectBufferPool());
bufferPools.add(FileChannelImpl.getMappedBufferPool());
bufferPools.add(FileChannelImpl.getSyncMappedBufferPool());
BUFFER_POOLS = Collections.unmodifiableList(bufferPools);
}
}
/**
* @return the list of buffer pools.
*/
public static List<BufferPool> getBufferPools() {
return BufferPoolsHolder.BUFFER_POOLS;
}
}

View file

@ -45,11 +45,11 @@ import java.nio.channels.WritableByteChannel;
import java.util.Objects;
import jdk.internal.access.JavaIOFileDescriptorAccess;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.ExtendedMapMode;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import jdk.internal.misc.VM.BufferPool;
import jdk.internal.ref.Cleaner;
import jdk.internal.ref.CleanerFactory;
@ -1158,8 +1158,8 @@ public class FileChannelImpl
* Invoked by sun.management.ManagementFactoryHelper to create the management
* interface for mapped buffers.
*/
public static JavaNioAccess.BufferPool getMappedBufferPool() {
return new JavaNioAccess.BufferPool() {
public static BufferPool getMappedBufferPool() {
return new BufferPool() {
@Override
public String getName() {
return "mapped";
@ -1183,8 +1183,8 @@ public class FileChannelImpl
* Invoked by sun.management.ManagementFactoryHelper to create the management
* interface for sync mapped buffers.
*/
public static JavaNioAccess.BufferPool getSyncMappedBufferPool() {
return new JavaNioAccess.BufferPool() {
public static BufferPool getSyncMappedBufferPool() {
return new BufferPool() {
@Override
public String getName() {
return "mapped - 'non-volatile memory'";