Skip to content

Apache Lucene open-source search software

LUCENE-9117: RamUsageEstimator hangs with AOT compilation. Removed any attempt to estimate Long.valueOf cache size: there will be some resulting overestimation but it shouldn't be harmful.

Dawid Weiss567706041d9b
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8efdbe8cf47..7a7122ba04a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -73,6 +73,9 @@ Bug fixes
* LUCENE-8663: NRTCachingDirectory.slowFileExists may open a file while
it's inaccessible. (Dawid Weiss)
+* LUCENE-9117: RamUsageEstimator hangs with AOT compilation. Removed any attempt to
+ estimate Long.valueOf cache size. (Cleber Muramoto, Dawid Weiss)
+
Other
* LUCENE-8768: Fix Javadocs build in Java 11. (Namgyu Kim)
diff --git a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
index 18d8acec3dd..21f6c98d0c4 100644
--- a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
+++ b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
@@ -122,7 +122,6 @@ public final class RamUsageEstimator {
/**
* JVMs typically cache small longs. This tries to find out what the range is.
*/
- static final long LONG_CACHE_MIN_VALUE, LONG_CACHE_MAX_VALUE;
static final int LONG_SIZE, STRING_SIZE;
/** For testing only */
@@ -190,19 +189,6 @@ public final class RamUsageEstimator {
NUM_BYTES_ARRAY_HEADER = NUM_BYTES_OBJECT_HEADER + Integer.BYTES;
}
- // get min/max value of cached Long class instances:
- long longCacheMinValue = 0;
- while (longCacheMinValue > Long.MIN_VALUE
- && Long.valueOf(longCacheMinValue - 1) == Long.valueOf(longCacheMinValue - 1)) {
- longCacheMinValue -= 1;
- }
- long longCacheMaxValue = -1;
- while (longCacheMaxValue < Long.MAX_VALUE
- && Long.valueOf(longCacheMaxValue + 1) == Long.valueOf(longCacheMaxValue + 1)) {
- longCacheMaxValue += 1;
- }
- LONG_CACHE_MIN_VALUE = longCacheMinValue;
- LONG_CACHE_MAX_VALUE = longCacheMaxValue;
LONG_SIZE = (int) shallowSizeOfInstance(Long.class);
STRING_SIZE = (int) shallowSizeOfInstance(String.class);
}
@@ -230,9 +216,6 @@ public final class RamUsageEstimator {
* cached by the JVM and its shallow size otherwise.
*/
public static long sizeOf(Long value) {
- if (value >= LONG_CACHE_MIN_VALUE && value <= LONG_CACHE_MAX_VALUE) {
- return 0;
- }
return LONG_SIZE;
}
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 8610afc727b..e4f05d8524c 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
@@ -208,8 +208,6 @@ public class TestRamUsageEstimator extends LuceneTestCase {
System.out.println("NUM_BYTES_OBJECT_HEADER = " + NUM_BYTES_OBJECT_HEADER);
System.out.println("NUM_BYTES_ARRAY_HEADER = " + NUM_BYTES_ARRAY_HEADER);
System.out.println("LONG_SIZE = " + LONG_SIZE);
- System.out.println("LONG_CACHE_MIN_VALUE = " + LONG_CACHE_MIN_VALUE);
- System.out.println("LONG_CACHE_MAX_VALUE = " + LONG_CACHE_MAX_VALUE);
}
@SuppressWarnings("unused")