You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/04/29 08:29:40 UTC

[GitHub] [bookkeeper] Shoothzj commented on a diff in pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Shoothzj commented on code in PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#discussion_r861573603


##########
stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/main/java/org/apache/bookkeeper/stats/prometheus/PrometheusMetricsProvider.java:
##########
@@ -223,9 +224,11 @@ private void registerMetrics(Collector collector) {
         AtomicLong tmpDirectMemoryUsage = null;
 
         try {
-            Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");
-            field.setAccessible(true);
-            tmpDirectMemoryUsage = (AtomicLong) field.get(null);
+            Class<?> name = Class.forName("java.nio.Bits");
+            String fieldName = SystemUtils.IS_JAVA_1_8 ? "reservedMemory" : "RESERVED_MEMORY";
+            Field reservedMemory = name.getDeclaredField(fieldName);
+            reservedMemory.setAccessible(true);
+            tmpDirectMemoryUsage = (AtomicLong) reservedMemory.get(null);

Review Comment:
   @dlg99 It's a stataic method, FieldUtils doesn't work



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org