--- old/src/java.base/share/classes/jdk/internal/misc/VM.java 2020-03-13 22:36:08.453901473 +0800 +++ new/src/java.base/share/classes/jdk/internal/misc/VM.java 2020-03-13 22:36:08.254907310 +0800 @@ -27,10 +27,16 @@ 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 @@ * 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 BUFFER_POOLS; + + static { + ArrayList 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 getBufferPools() { + return BufferPoolsHolder.BUFFER_POOLS; + } }