changeset 59542:d36bd2b59c42

8246259: JFR: Fetch VM memory pools without using streams Reviewed-by: mgronlun
author egahlin
date Mon, 01 Jun 2020 22:55:22 +0200
parents f1da8c714ba1
children 843695160574
files src/jdk.jfr/share/classes/jdk/jfr/events/AbstractBufferStatisticsEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/DirectBufferStatisticsEvent.java
diffstat 2 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/AbstractBufferStatisticsEvent.java	Mon Jun 01 13:19:06 2020 -0700
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/AbstractBufferStatisticsEvent.java	Mon Jun 01 22:55:22 2020 +0200
@@ -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;
+    final long memoryUsed;
 
-    abstract BufferPool getBufferPool();
+    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);
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/DirectBufferStatisticsEvent.java	Mon Jun 01 13:19:06 2020 -0700
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/DirectBufferStatisticsEvent.java	Mon Jun 01 22:55:22 2020 +0200
@@ -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;
 }