Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Xenos2017-04-14 23:44:38 +0000
committerStefan Xenos2017-04-20 16:14:02 +0000
commit2e345a420f925595f85afc3af7c22dc809e5653f (patch)
tree7f25ecc1a83d6f1108f00c709434de99ac4d6523
parent07238913f56a97ba44a9303668e05bdac0c99e0a (diff)
downloadeclipse.jdt.core-2e345a420f925595f85afc3af7c22dc809e5653f.tar.gz
eclipse.jdt.core-2e345a420f925595f85afc3af7c22dc809e5653f.tar.xz
eclipse.jdt.core-2e345a420f925595f85afc3af7c22dc809e5653f.zip
Bug 512740 - disabling the new index should disable its rescan job
Disable the indexer when the enablement preference is disabled. Clear the page cache when the preference is disabled. Initiate reindexing when the preference is enabled. Change-Id: I082252bcf399e8d18196139bb1c1b7ddd1ca4fdc Signed-off-by: Stefan Xenos <sxenos@gmail.com>
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/db/ChunkCache.java26
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/indexer/Indexer.java54
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/JavaIndex.java3
3 files changed, 64 insertions, 19 deletions
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/db/ChunkCache.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/db/ChunkCache.java
index 3506e15ae3..7771a6429f 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/db/ChunkCache.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/db/ChunkCache.java
@@ -99,10 +99,10 @@ public final class ChunkCache {
while (true) {
Chunk chunk = this.fPageTable[this.fPointer];
if (chunk.fCacheHitFlag) {
- chunk.fCacheHitFlag= false;
- this.fPointer= (this.fPointer + 1) % this.fPageTable.length;
+ chunk.fCacheHitFlag = false;
+ this.fPointer = (this.fPointer + 1) % this.fPageTable.length;
} else {
- chunk.fCacheIndex= -1;
+ chunk.fCacheIndex = -1;
chunk.fDatabase.checkIfChunkReleased(chunk);
this.fPageTable[this.fPointer] = null;
return;
@@ -149,10 +149,10 @@ public final class ChunkCache {
this.fPointer= oldLength;
this.fPageTable= newTable;
} else {
- for (int i= newLength; i < oldLength; i++) {
- final Chunk chunk= this.fPageTable[i];
+ for (int i = newLength; i < oldLength; i++) {
+ Chunk chunk = this.fPageTable[i];
+ chunk.fCacheIndex = -1;
chunk.fDatabase.checkIfChunkReleased(chunk);
- chunk.fCacheIndex= -1;
}
Chunk[] newTable= new Chunk[newLength];
System.arraycopy(this.fPageTable, 0, newTable, 0, newLength);
@@ -166,4 +166,18 @@ public final class ChunkCache {
long maxLength= Math.min(maxSize / Database.CHUNK_SIZE, Integer.MAX_VALUE);
return Math.max(1, (int) maxLength);
}
+
+ public synchronized void clear() {
+ for (int i = 0; i < this.fPageTable.length; i++) {
+ Chunk chunk = this.fPageTable[i];
+ if (chunk == null) {
+ continue;
+ }
+ chunk.fCacheIndex = -1;
+ chunk.fDatabase.checkIfChunkReleased(chunk);
+ this.fPageTable[i] = null;
+ }
+ this.fTableIsFull = false;
+ this.fPointer = 0;
+ }
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/indexer/Indexer.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/indexer/Indexer.java
index 08bd027304..a175a360e9 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/indexer/Indexer.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/indexer/Indexer.java
@@ -47,6 +47,10 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobGroup;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
@@ -65,6 +69,7 @@ import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.nd.IReader;
import org.eclipse.jdt.internal.core.nd.Nd;
+import org.eclipse.jdt.internal.core.nd.db.ChunkCache;
import org.eclipse.jdt.internal.core.nd.db.Database;
import org.eclipse.jdt.internal.core.nd.db.IndexException;
import org.eclipse.jdt.internal.core.nd.java.FileFingerprint;
@@ -93,6 +98,18 @@ public final class Indexer {
public static boolean DEBUG_INSERTIONS;
public static boolean DEBUG_SELFTEST;
public static int DEBUG_LOG_SIZE_MB;
+ private static IPreferenceChangeListener listener = new IPreferenceChangeListener() {
+ @Override
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (JavaIndex.DISABLE_NEW_JAVA_INDEX.equals(event.getKey())) {
+ if (JavaIndex.isEnabled()) {
+ getInstance().rescanAll();
+ } else {
+ ChunkCache.getSharedInstance().clear();
+ }
+ }
+ }
+ };
// This is an arbitrary constant that is larger than the maximum number of ticks
// reported by SubMonitor and small enough that it won't overflow a long when multiplied by a large
@@ -145,6 +162,8 @@ public final class Indexer {
synchronized (mutex) {
if (indexer == null) {
indexer = new Indexer(JavaIndex.getGlobalNd(), ResourcesPlugin.getWorkspace().getRoot());
+ IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
+ preferences.addPreferenceChangeListener(listener);
}
return indexer;
}
@@ -174,18 +193,20 @@ public final class Indexer {
}
}
- if (runRescan) {
- // Force a rescan when re-enabling automatic indexing since we may have missed an update
- this.rescanJob.schedule();
- }
-
- if (!enabled) {
- // Wait for any existing indexing operations to finish when disabling automatic indexing since
- // we only want explicitly-triggered indexing operations to run after the method returns
- try {
- this.rescanJob.join(0, null);
- } catch (OperationCanceledException | InterruptedException e) {
- // Don't care
+ if (JavaIndex.isEnabled()) {
+ if (runRescan) {
+ // Force a rescan when re-enabling automatic indexing since we may have missed an update
+ this.rescanJob.schedule();
+ }
+
+ if (!enabled) {
+ // Wait for any existing indexing operations to finish when disabling automatic indexing since
+ // we only want explicitly-triggered indexing operations to run after the method returns
+ try {
+ this.rescanJob.join(0, null);
+ } catch (OperationCanceledException | InterruptedException e) {
+ // Don't care
+ }
}
}
}
@@ -944,6 +965,9 @@ public final class Indexer {
return;
}
}
+ if (!JavaIndex.isEnabled()) {
+ return;
+ }
this.rescanJob.schedule();
}
@@ -1001,6 +1025,9 @@ public final class Indexer {
}
public void waitForIndex(int waitingPolicy, IProgressMonitor monitor) {
+ if (!JavaIndex.isEnabled()) {
+ return;
+ }
switch (waitingPolicy) {
case IJob.ForceImmediate: {
break;
@@ -1019,6 +1046,9 @@ public final class Indexer {
}
public void rebuildIndex(IProgressMonitor monitor) throws CoreException {
+ if (!JavaIndex.isEnabled()) {
+ return;
+ }
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
this.nd.acquireWriteLock(subMonitor.split(1));
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/JavaIndex.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/JavaIndex.java
index c398f48bd1..5d06a269e4 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/JavaIndex.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/JavaIndex.java
@@ -37,6 +37,7 @@ import org.eclipse.jdt.internal.core.nd.indexer.FileStateCache;
import org.eclipse.jdt.internal.core.nd.util.CharArrayUtils;
public class JavaIndex {
+ public static final String DISABLE_NEW_JAVA_INDEX = "disableNewJavaIndex"; //$NON-NLS-1$
// Version constants
static final int CURRENT_VERSION = Nd.version(1, 49);
static final int MAX_SUPPORTED_VERSION = Nd.version(1, 49);
@@ -222,7 +223,7 @@ public class JavaIndex {
if (preferenceService == null) {
return true;
}
- return !preferenceService.getBoolean(JavaCore.PLUGIN_ID, "disableNewJavaIndex", false, //$NON-NLS-1$
+ return !preferenceService.getBoolean(JavaCore.PLUGIN_ID, DISABLE_NEW_JAVA_INDEX, false, //$NON-NLS-1$
null);
}

Back to the top