move reachabilityFence to ObjectUtils

This commit is contained in:
peter
2019-03-19 13:57:24 +01:00
parent a228e3dac4
commit 3a79d7fb48
3 changed files with 11 additions and 8 deletions
@@ -1460,8 +1460,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
Document document = getDocument(getFile());
data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(document, getProject()), document.getText());
}
//noinspection ResultOfMethodCallIgnored
hardRefToFileElement.hashCode(); // use it so gc won't collect it
ObjectUtils.reachabilityFence(hardRefToFileElement);
return elapsed;
}
@@ -37,6 +37,13 @@ public class ObjectUtils {
public static Object sentinel(@NotNull String name) {
return new Sentinel(name);
}
/**
* They promise in http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-February/051312.html that
* the object reference won't be removed by JIT and GC-ed until this call.
*/
public static void reachabilityFence(@SuppressWarnings("unused") Object o) {}
private static class Sentinel {
private final String myName;
@@ -16,6 +16,7 @@
package com.intellij.util.ref;
import com.intellij.diagnostic.ThreadDumper;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.TestOnly;
import java.beans.Introspector;
@@ -40,7 +41,7 @@ public class GCUtil {
//long started = System.nanoTime();
ReferenceQueue<Object> q = new ReferenceQueue<>();
SoftReference<Object> ref = new SoftReference<>(new Object(), q);
reachabilityFence(ref.get());
ObjectUtils.reachabilityFence(ref.get());
System.gc();
@@ -52,7 +53,7 @@ public class GCUtil {
// using ref is important as to loop to finish with several iterations: long runs of the method (~80 run of PsiModificationTrackerTest)
// discovered 'ref' being collected and loop iterated 100 times taking a lot of time
reachabilityFence(ref.get());
ObjectUtils.reachabilityFence(ref.get());
//System.out.println("Done gc'ing refs:" + ((System.nanoTime() - started) / 1000000));
}
@@ -102,10 +103,6 @@ public class GCUtil {
return until.getAsBoolean();
}
// They promise in http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-February/051312.html that
// the object reference won't be removed by JIT and GC-ed until this call
private static void reachabilityFence(@SuppressWarnings("unused") Object o) {}
/**
* Using java beans (e.g. Groovy does it) results in all referenced class infos being cached in ThreadGroupContext. A valid fix
* would be to hold BeanInfo objects on soft references, but that should be done in JDK. So let's clear this cache manually for now,