Skip to content

Apache Lucene open-source search software

Refactor the use of runFinalization in tests and benchmarks (#12768)

Chris Hegartyf2287e7ba667
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java
index 5c346664bf5..72253d33051 100644
--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java
+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java
@@ -46,6 +46,7 @@ import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.SuppressForbidden;
/**
* Data maintained by a performance test run.
@@ -204,7 +205,7 @@ public class PerfRunData implements Closeable {
resetInputs();
// release unused stuff
- System.runFinalization();
+ runFinalization();
System.gc();
// Re-init clock
@@ -482,4 +483,10 @@ public class PerfRunData implements Closeable {
public Map<String, AnalyzerFactory> getAnalyzerFactories() {
return analyzerFactories;
}
+
+ @SuppressWarnings("removal")
+ @SuppressForbidden(reason = "requires to run finalization")
+ private static void runFinalization() {
+ System.runFinalization();
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
index 3db8540e30a..86098cbe048 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
@@ -119,7 +119,7 @@ public class TestWeakIdentityMap extends LuceneTestCase {
int size = map.size();
for (int i = 0; size > 0 && i < 10; i++)
try {
- System.runFinalization();
+ runFinalization();
System.gc();
int newSize = map.size();
assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize);
@@ -232,7 +232,7 @@ public class TestWeakIdentityMap extends LuceneTestCase {
int size = map.size();
for (int i = 0; size > 0 && i < 10; i++)
try {
- System.runFinalization();
+ runFinalization();
System.gc();
int newSize = map.size();
assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize);
@@ -252,4 +252,10 @@ public class TestWeakIdentityMap extends LuceneTestCase {
InterruptedException ie) {
}
}
+
+ @SuppressWarnings("removal")
+ @SuppressForbidden(reason = "requires to run finalization")
+ private static void runFinalization() {
+ System.runFinalization();
+ }
}