You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2023/01/01 23:05:42 UTC

[lucene] branch main updated: Fix detection of Hotspot in TestRamUsageEstimator so it works with OpenJ9 that has the bean, but without properties (#12058)

This is an automated email from the ASF dual-hosted git repository.

uschindler pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new e2ee09d0c56 Fix detection of Hotspot in TestRamUsageEstimator so it works with OpenJ9 that has the bean, but without properties (#12058)
e2ee09d0c56 is described below

commit e2ee09d0c56fcd60da9368bd2898587df09c894d
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Mon Jan 2 00:05:36 2023 +0100

    Fix detection of Hotspot in TestRamUsageEstimator so it works with OpenJ9 that has the bean, but without properties (#12058)
---
 lucene/CHANGES.txt                                 |  3 +++
 .../apache/lucene/util/TestRamUsageEstimator.java  | 23 +++++++++-------------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 11aa3666a8a..ba9386f8a5c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -217,6 +217,9 @@ Bug Fixes
 
 * GITHUB#12020: Fixes bug whereby very flat polygons can incorrectly contain intersecting geometries. (Craig Taverner)
 
+* GITHUB#12058: Fix detection of Hotspot in TestRamUsageEstimator so it works with OpenJ9.
+  (Uwe Schindler)
+
 Optimizations
 ---------------------
 * GITHUB#11738: Optimize MultiTermQueryConstantScoreWrapper when a term is present that matches all
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
index bb0bba8ffd1..8e0bd13507e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
@@ -18,10 +18,8 @@ package org.apache.lucene.util;
 
 import static org.apache.lucene.tests.util.RamUsageTester.ramUsed;
 import static org.apache.lucene.util.RamUsageEstimator.COMPRESSED_REFS_ENABLED;
-import static org.apache.lucene.util.RamUsageEstimator.HOTSPOT_BEAN_CLASS;
 import static org.apache.lucene.util.RamUsageEstimator.JVM_IS_HOTSPOT_64BIT;
 import static org.apache.lucene.util.RamUsageEstimator.LONG_SIZE;
-import static org.apache.lucene.util.RamUsageEstimator.MANAGEMENT_FACTORY_CLASS;
 import static org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_ARRAY_HEADER;
 import static org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_ALIGNMENT;
 import static org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_HEADER;
@@ -30,11 +28,14 @@ import static org.apache.lucene.util.RamUsageEstimator.shallowSizeOf;
 import static org.apache.lucene.util.RamUsageEstimator.shallowSizeOfInstance;
 import static org.apache.lucene.util.RamUsageEstimator.sizeOf;
 
+import java.lang.management.CompilationMXBean;
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Random;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
@@ -204,18 +205,12 @@ public class TestRamUsageEstimator extends LuceneTestCase {
 
   public void testHotspotBean() {
     assumeTrue("testHotspotBean only works on 64bit JVMs.", Constants.JRE_IS_64BIT);
-    try {
-      Class.forName(MANAGEMENT_FACTORY_CLASS);
-    } catch (ClassNotFoundException e) {
-      assumeNoException("testHotspotBean does not work on Java 8+ compact profile.", e);
-    }
-    try {
-      Class.forName(HOTSPOT_BEAN_CLASS);
-    } catch (ClassNotFoundException e) {
-      assumeNoException(
-          "testHotspotBean only works on Hotspot (OpenJDK, Oracle) virtual machines.", e);
-    }
-
+    assumeTrue(
+        "testHotspotBean only works on Hotspot (OpenJDK, Oracle) virtual machines.",
+        Optional.ofNullable(ManagementFactory.getCompilationMXBean())
+            .map(CompilationMXBean::getName)
+            .orElse("Unknown")
+            .startsWith("HotSpot"));
     assertTrue(
         "We should have been able to detect Hotspot's internal settings from the management bean.",
         JVM_IS_HOTSPOT_64BIT);