javac ast indices: flush index on low memory

This commit is contained in:
Dmitry Batkovich
2016-11-01 18:00:12 +03:00
parent fd4ee8caed
commit c2a117e9c5
2 changed files with 37 additions and 5 deletions
@@ -15,6 +15,7 @@
*/
package org.jetbrains.jps.backwardRefs;
import com.intellij.openapi.util.LowMemoryWatcher;
import com.intellij.util.Function;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
@@ -34,7 +35,10 @@ import org.jetbrains.jps.model.java.compiler.JavaCompilers;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static com.sun.tools.javac.code.Flags.PRIVATE;
@@ -45,10 +49,23 @@ public class BackwardReferenceIndexWriter {
private final CompilerBackwardReferenceIndex myIndex;
private final boolean myRebuild;
private final LowMemoryWatcher myMemWatcher;
private final Object myCloseLock = new Object();
private boolean myClosed;
private BackwardReferenceIndexWriter(CompilerBackwardReferenceIndex index, boolean rebuild) {
myIndex = index;
myRebuild = rebuild;
myMemWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
synchronized (myCloseLock) {
if (!myClosed) {
myIndex.flush();
}
}
}
});
}
public static void closeIfNeed() {
@@ -94,10 +111,6 @@ public class BackwardReferenceIndexWriter {
return SystemProperties.getBooleanProperty(PROP_KEY, false);
}
void close() {
myIndex.close();
}
synchronized LightRef.JavaLightClassRef asClassUsage(Symbol name) {
return new LightRef.JavaLightClassRef(myIndex.getByteSeqEum().enumerate(bytes(name)));
}
@@ -207,6 +220,14 @@ public class BackwardReferenceIndexWriter {
}
}
private void close() {
synchronized (myCloseLock) {
myClosed = true;
myMemWatcher.stop();
myIndex.close();
}
}
private void directlyWriteHierarchyIndices(CompilerBackwardReferenceIndex.LightDefinition classId, LightRef.JavaLightClassRef[] superIds) {
for (LightRef.JavaLightClassRef superId : superIds) {
myIndex.getBackwardHierarchyMap().put(superId, classId);
@@ -203,6 +203,17 @@ public class CompilerBackwardReferenceIndex {
}
}
void flush() {
myBackwardHierarchyMap.flush(false);
myBackwardReferenceMap.flush(false);
myBackwardClassDefinitionMap.flush(false);
myHierarchyMap.flush(false);
myReferenceMap.flush(false);
myClassDefinitionMap.flush(false);
myNameEnumerator.force();
myFilePathEnumerator.force();
}
public static void removeIndexFiles(File buildDir) {
final File indexDir = getIndexDir(buildDir);
if (indexDir.exists()) {