Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2007-01-17 16:46:18 -0500
committerDoug Schaefer2007-01-17 16:46:18 -0500
commit9bbf3e941af6edf5df7cb384e9118c84921cdff2 (patch)
tree71557ed096df1d6436b662381d6b31d6bc8b1e87
parentd85fe7d32de3d88968e89504090ec334644aa25d (diff)
downloadorg.eclipse.cdt-9bbf3e941af6edf5df7cb384e9118c84921cdff2.tar.gz
org.eclipse.cdt-9bbf3e941af6edf5df7cb384e9118c84921cdff2.tar.xz
org.eclipse.cdt-9bbf3e941af6edf5df7cb384e9118c84921cdff2.zip
Bug 170542 - Removed the memory mapped files from the index database. The chunks now manage a byte array to reflect the contents of the file. An LRU cache make sure only lruMax chunks are in memory at a time. The chunks are marked dirty when changed and saved when flushed from the cache or when the PDOM write lock is released. Also tightened up the locking to make sure the databases are locked when accessed. There is now only one lock in the system since the LRU cache is for all databases opened.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java90
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java103
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java168
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java69
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java99
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/OpenDefinitionAction.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchBindingQuery.java20
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java23
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java50
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java60
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java19
16 files changed, 488 insertions, 274 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index d286f49a526..8b2d759b96f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -44,7 +44,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
@@ -58,10 +57,6 @@ public class PDOM extends PlatformObject
private Database db;
- // On Neutrino, we need to save the database to ensure the
- // buffer gets written to the file.
- private static boolean needSave = Platform.getOS() == Platform.OS_QNX;
-
public static final int VERSION = 11;
// 0 - the beginning of it all
// 1 - first change to kick off upgrades
@@ -81,28 +76,29 @@ public class PDOM extends PlatformObject
// Local caches
private BTree fileIndex;
- private Map linkageCache = new HashMap();
+ private Map _linkageCache; // Access only using getLinkageCache()
public PDOM(IPath dbPath) throws CoreException {
// Load up the database
db = new Database(dbPath.toOSString());
-
- if (db.getVersion() == VERSION) {
- // populate the linkage cache
- PDOMLinkage linkage = getFirstLinkage();
- while (linkage != null) {
- linkageCache.put(linkage.getLanguage().getId(), linkage);
- linkage = linkage.getNextLinkage();
+ }
+
+ private Map getLinkageCache() throws CoreException {
+ if (_linkageCache == null) {
+ _linkageCache = new HashMap();
+ if (!versionMismatch()) {
+ PDOMLinkage linkage = getFirstLinkage();
+ while (linkage != null) {
+ _linkageCache.put(linkage.getLanguage().getId(), linkage);
+ linkage = linkage.getNextLinkage();
+ }
}
}
+ return _linkageCache;
}
- public boolean versionMismatch() {
- if (db.getVersion() != VERSION) {
- db.setVersion(VERSION);
- return true;
- } else
- return false;
+ public boolean versionMismatch() throws CoreException {
+ return db.getVersion() != VERSION;
}
public Object getAdapter(Class adapter) {
@@ -181,16 +177,15 @@ public class PDOM extends PlatformObject
}
public void clear() throws CoreException {
- Database db = getDB();
// Clear out the database
- db.clear();
+ db.clear(VERSION);
// Zero out the File Index and Linkages
db.putInt(FILE_INDEX, 0);
fileIndex = null;
db.putInt(LINKAGES, 0);
- linkageCache.clear();
+ getLinkageCache().clear();
}
public boolean isEmpty() throws CoreException {
@@ -326,7 +321,7 @@ public class PDOM extends PlatformObject
}
public PDOMLinkage getLinkage(ILanguage language) throws CoreException {
- PDOMLinkage linkage = (PDOMLinkage)linkageCache.get(language.getId());
+ PDOMLinkage linkage = (PDOMLinkage)getLinkageCache().get(language.getId());
if (linkage != null)
return linkage;
@@ -350,7 +345,7 @@ public class PDOM extends PlatformObject
// First check the cache. We do a linear search since there will be very few linkages
// in a given database.
- Iterator i = linkageCache.values().iterator();
+ Iterator i = getLinkageCache().values().iterator();
while (i.hasNext()) {
PDOMLinkage linkage = (PDOMLinkage)i.next();
if (linkage.getRecord() == record)
@@ -366,15 +361,15 @@ public class PDOM extends PlatformObject
return getLinkage(db.getInt(LINKAGES));
}
- public PDOMLinkage[] getLinkages() {
- Collection values = linkageCache.values();
+ public PDOMLinkage[] getLinkages() throws CoreException {
+ Collection values = getLinkageCache().values();
return (PDOMLinkage[])values.toArray(new PDOMLinkage[values.size()]);
}
public void insertLinkage(PDOMLinkage linkage) throws CoreException {
linkage.setNext(db.getInt(LINKAGES));
db.putInt(LINKAGES, linkage.getRecord());
- linkageCache.put(linkage.getLanguage().getId(), linkage);
+ getLinkageCache().put(linkage.getLanguage().getId(), linkage);
}
public PDOMBinding getBinding(int record) throws CoreException {
@@ -386,52 +381,21 @@ public class PDOM extends PlatformObject
}
}
- // Read-write lock rules. Readers don't conflict with other readers,
- // Writers conflict with readers, and everyone conflicts with writers.
- private Object mutex = new Object();
- private int lockCount;
- private int waitingReaders;
-
public void acquireReadLock() throws InterruptedException {
- synchronized (mutex) {
- ++waitingReaders;
- while (lockCount < 0)
- mutex.wait();
- --waitingReaders;
- ++lockCount;
- }
+ Database.acquireLock();
}
public void releaseReadLock() {
- synchronized (mutex) {
- if (lockCount > 0)
- --lockCount;
- mutex.notifyAll();
- }
+ Database.releaseLock();
}
public void acquireWriteLock() throws InterruptedException {
- synchronized (mutex) {
- // Let the readers go first
- while (lockCount != 0 || waitingReaders > 0)
- mutex.wait();
- --lockCount;
- }
+ Database.acquireLock();
}
public void releaseWriteLock() {
- synchronized (mutex) {
- // save the database
- if (needSave)
- try {
- db.save();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- }
- if (lockCount < 0)
- ++lockCount;
- mutex.notifyAll();
- }
+ Database.saveAll();
+ Database.releaseLock();
fireChange();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
index 6fb676ab5df..5e99774f690 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
@@ -41,19 +41,19 @@ public class BTree {
return db.getInt(rootPointer);
}
- protected final void putRecord(Chunk chunk, int node, int index, int record) {
+ protected final void putRecord(Chunk chunk, int node, int index, int record) throws CoreException {
chunk.putInt(node + index * Database.INT_SIZE, record);
}
- protected final int getRecord(Chunk chunk, int node, int index) {
+ protected final int getRecord(Chunk chunk, int node, int index) throws CoreException {
return chunk.getInt(node + index * Database.INT_SIZE);
}
- protected final void putChild(Chunk chunk, int node, int index, int child) {
+ protected final void putChild(Chunk chunk, int node, int index, int child) throws CoreException {
chunk.putInt(node + OFFSET_CHILDREN + index * Database.INT_SIZE, child);
}
- protected final int getChild(Chunk chunk, int node, int index) {
+ protected final int getChild(Chunk chunk, int node, int index) throws CoreException {
return chunk.getInt(node + OFFSET_CHILDREN + index * Database.INT_SIZE);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java
index 3a32757839b..5284f610d77 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java
@@ -11,10 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.db;
import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel.MapMode;
import org.eclipse.core.runtime.CoreException;
@@ -24,83 +20,104 @@ import org.eclipse.core.runtime.CoreException;
*/
public class Chunk {
- private ByteBuffer buffer;
+ private final Database db;
+ private final int index;
+ private final byte[] buffer;
- // Cache info
- private Database db;
- int index;
+ Chunk lruPrev;
+ Chunk lruNext;
- Chunk(RandomAccessFile file, int offset) throws CoreException {
- index = offset / Database.CHUNK_SIZE;
+ private boolean dirty;
+
+ Chunk(Database db, int index) throws CoreException {
+ this.db = db;
+ this.index = index;
+ buffer = new byte[Database.CHUNK_SIZE];
+
try {
- buffer = file.getChannel().map(MapMode.READ_WRITE, offset, Database.CHUNK_SIZE);
- } catch (IOException e) {
- try {
- buffer = ByteBuffer.allocateDirect(Database.CHUNK_SIZE);
- file.seek(offset);
- file.getChannel().read(buffer);
- } catch (IOException e2) {
- throw new CoreException(new DBStatus(e2));
- }
+ db.file.seek(index * Database.CHUNK_SIZE);
+ db.file.read(buffer, 0, Database.CHUNK_SIZE);
+ } catch (IOException e) {
+ throw new CoreException(new DBStatus(e));
}
}
- public void save() throws CoreException {
- // if we're not memory mapped, write the buffer out to the file
- if (buffer instanceof MappedByteBuffer)
- ((MappedByteBuffer)buffer).force();
- else {
- try {
- db.file.seek(index * Database.CHUNK_SIZE);
- db.file.getChannel().write(buffer);
- } catch (IOException e) {
- throw new CoreException(new DBStatus(e));
- }
+ public final void save() throws CoreException {
+ if (!dirty)
+ return;
+
+ if (index == 0 && getInt(0) != 11)
+ return;
+
+ try {
+ db.file.seek(index * Database.CHUNK_SIZE);
+ db.file.write(buffer, 0, Database.CHUNK_SIZE);
+ dirty = false;
+ } catch (IOException e) {
+ throw new CoreException(new DBStatus(e));
}
}
public void putByte(int offset, byte value) {
- buffer.put(offset % Database.CHUNK_SIZE, value);
+ dirty = true;
+ buffer[offset % Database.CHUNK_SIZE] = value;
}
public byte getByte(int offset) {
- return buffer.get(offset % Database.CHUNK_SIZE);
+ return buffer[offset % Database.CHUNK_SIZE];
}
public byte[] getBytes(int offset, int length) {
byte[] bytes = new byte[length];
- buffer.position(offset % Database.CHUNK_SIZE);
- buffer.get(bytes, 0, length);
+ System.arraycopy(buffer, offset % Database.CHUNK_SIZE, bytes, 0, length);
return bytes;
}
public void putBytes(int offset, byte[] bytes) {
- buffer.position(offset % Database.CHUNK_SIZE);
- buffer.put(bytes, 0, bytes.length);
+ dirty = true;
+ System.arraycopy(bytes, 0, buffer, offset % Database.CHUNK_SIZE, bytes.length);
}
public void putInt(int offset, int value) {
- buffer.putInt(offset % Database.CHUNK_SIZE, value);
+ dirty = true;
+ int i = offset % Database.CHUNK_SIZE;
+ buffer[i++] = (byte)((value >>> 24) & 0xff);
+ buffer[i++] = (byte)((value >>> 16) & 0xff);
+ buffer[i++] = (byte)((value >>> 8) & 0xff);
+ buffer[i] = (byte)(value & 0xff);
}
public int getInt(int offset) {
- return buffer.getInt(offset % Database.CHUNK_SIZE);
+ int i = offset % Database.CHUNK_SIZE;
+ return ((buffer[i] & 0xff) << 24)
+ | ((buffer[i + 1] & 0xff) << 16)
+ | ((buffer[i + 2] & 0xff) << 8)
+ | (buffer[i + 3] & 0xff);
}
public void putChar(int offset, char value) {
- buffer.putChar(offset % Database.CHUNK_SIZE, value);
+ dirty = true;
+ int i = offset % Database.CHUNK_SIZE;
+ buffer[i] = (byte)((value >>> 8) & 0xff);
+ buffer[i + 1] = (byte)(value & 0xff);
}
public char getChar(int offset) {
- return buffer.getChar(offset % Database.CHUNK_SIZE);
+ int i = offset % Database.CHUNK_SIZE;
+ return (char)(((buffer[i] & 0xff) << 8) + (buffer[i + 1] & 0xff));
}
void clear(int offset, int length) {
- buffer.position(offset % Database.CHUNK_SIZE);
- buffer.put(new byte[length]);
+ dirty = true;
+ int i = offset % Database.CHUNK_SIZE;
+ while (length > 0) {
+ buffer[i++] = 0;
+ --length;
+ }
}
- void free() {
+ void free() throws CoreException {
+ save();
db.toc[index] = null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
index c4bdbe7fd99..edec622fe8b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
@@ -24,12 +24,15 @@ import org.eclipse.core.runtime.Status;
*/
public class Database {
+ // Access directly by the Chunks
final RandomAccessFile file;
Chunk[] toc;
private long malloced;
private long freed;
+ int version = 0;
+
// public for tests only, you shouldn't need these
public static final int VERSION_OFFSET = 0;
public static final int CHUNK_SIZE = 1024 * 16;
@@ -46,36 +49,42 @@ public class Database {
try {
file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$
- // Allocate chunk table, make sure we have at least one
long nChunks = file.length() / CHUNK_SIZE;
if (nChunks == 0) {
+ // New file, allocate the header chunk
+ file.seek(0);
+ file.write(new byte[CHUNK_SIZE]);
+
+ // Write out the version
+ file.seek(0);
+ file.writeInt(version);
+ nChunks = 1;
+ } else {
+ // Read in the version
file.seek(0);
- file.write(new byte[CHUNK_SIZE]); // the header chunk
- ++nChunks;
+ version = file.readInt();
}
toc = new Chunk[(int)nChunks];
- toc[0] = new Chunk(file, 0);
} catch (IOException e) {
throw new CoreException(new DBStatus(e));
}
}
public int getVersion() {
- return toc[0].getInt(0);
+ return version;
}
- public void setVersion(int version) {
- toc[0].putInt(0, version);
- }
-
/**
* Empty the contents of the Database, make it ready to start again
* @throws CoreException
*/
- public void clear() throws CoreException {
- // Clear out the memory headers
- toc[0].clear(4, DATA_AREA - 4);
+ public void clear(int version) throws CoreException {
+ // Clear out the data area and reset the version
+ Chunk chunk = getChunk(0);
+ chunk.putInt(0, version);
+ chunk.clear(4, DATA_AREA - 4);
+
// Add the remainder of the chunks backwards
for (int block = (toc.length - 1) * CHUNK_SIZE; block > 0; block -= CHUNK_SIZE) {
addBlock(getChunk(block), CHUNK_SIZE, block);
@@ -84,18 +93,6 @@ public class Database {
}
/**
- * This saves the chunks to the file. Normally this isn't necessary.
- * However if the memory map fails, direct byte buffers are used instead
- * and need to be saved back to disk.
- * @throws CoreException
- */
- public void save() throws CoreException {
- for (int i = 0; i < toc.length; ++i)
- if (toc[i] != null)
- toc[i].save();
- }
-
- /**
* Return the Chunk that contains the given offset.
*
* @param offset
@@ -104,10 +101,12 @@ public class Database {
public Chunk getChunk(int offset) throws CoreException {
int index = offset / CHUNK_SIZE;
Chunk chunk = toc[index];
+ boolean isNew = false;
if (chunk == null) {
- chunk = toc[index] = new Chunk(file, index * CHUNK_SIZE);
+ chunk = toc[index] = new Chunk(this, index);
+ isNew = true;
}
-
+ Database.lruPutFirst(chunk, isNew);
return chunk;
}
@@ -174,19 +173,20 @@ public class Database {
file.write(new byte[CHUNK_SIZE]);
toc = new Chunk[n + 1];
System.arraycopy(oldtoc, 0, toc, 0, n);
- toc[n] = new Chunk(file, offset);
+ toc[n] = new Chunk(this, n);
+ Database.lruPutFirst(toc[n], true);
return n;
} catch (IOException e) {
throw new CoreException(new DBStatus(e));
}
}
- private int getFirstBlock(int blocksize) {
- return toc[0].getInt((blocksize / MIN_SIZE) * INT_SIZE);
+ private int getFirstBlock(int blocksize) throws CoreException {
+ return getChunk(0).getInt((blocksize / MIN_SIZE) * INT_SIZE);
}
- private void setFirstBlock(int blocksize, int block) {
- toc[0].putInt((blocksize / MIN_SIZE) * INT_SIZE, block);
+ private void setFirstBlock(int blocksize, int block) throws CoreException {
+ getChunk(0).putInt((blocksize / MIN_SIZE) * INT_SIZE, block);
}
private void removeBlock(Chunk chunk, int blocksize, int block) throws CoreException {
@@ -304,4 +304,110 @@ public class Database {
System.out.println("Block size: " + bs + "=" + count);
}
}
+
+ // Chunk management
+ static private Chunk lruFirst;
+ static private Chunk lruLast;
+ static private int lruSize;
+ static private final int lruMax;
+ static private final int MEG = 1024 * 1024;
+
+ static {
+ String maxString = System.getProperty("cdt.index.lruMax"); //$NON-NLS-1$
+ if (maxString != null) {
+ int max = Integer.valueOf(maxString).intValue();
+ if (max > 0)
+ lruMax = max * MEG / CHUNK_SIZE;
+ else
+ lruMax = 64 * MEG / CHUNK_SIZE;
+ } else {
+ long max = Runtime.getRuntime().maxMemory();
+ if (max < 512 * MEG)
+ lruMax = (int)max / 8 / CHUNK_SIZE;
+ else
+ lruMax = 64 * MEG / CHUNK_SIZE;
+ }
+ }
+
+ static public final void lruPutFirst(Chunk chunk, boolean isNew) throws CoreException {
+ // If this chunk is already first, we're good
+ if (chunk == lruFirst)
+ return;
+
+ if (lockCount == 0)
+ // Accessing database without locking
+ CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, "Index not locked", new Exception())); //$NON-NLS-1$
+
+ if (!isNew) {
+ // Remove from current position in cache
+ if (chunk.lruPrev != null) {
+ chunk.lruPrev.lruNext = chunk.lruNext;
+ }
+ if (chunk.lruNext != null) {
+ chunk.lruNext.lruPrev = chunk.lruPrev;
+ } else {
+ // No next => New last
+ lruLast = chunk.lruPrev;
+ }
+ }
+
+ // Insert at front of cache
+ chunk.lruNext = lruFirst;
+ chunk.lruPrev = null;
+ if (lruFirst != null)
+ lruFirst.lruPrev = chunk;
+ lruFirst = chunk;
+ if (lruLast == null)
+ lruLast = chunk;
+
+ if (isNew) {
+ // New chunk, see if we need to release one
+ if (lruSize == lruMax) {
+ Chunk last = lruLast;
+ lruLast = last.lruPrev;
+ lruLast.lruNext = null;
+ last.free();
+ } else {
+ ++lruSize;
+ }
+ }
+ }
+
+ // Global locks on the databases
+ // Allow only one access at a time
+ private static Object mutex = new Object();
+ private static Thread lockOwner;
+ private static int lockCount;
+
+ public static void acquireLock() throws InterruptedException {
+ synchronized (mutex) {
+ if (lockOwner != Thread.currentThread())
+ while (lockCount > 0)
+ mutex.wait();
+ ++lockCount;
+ lockOwner = Thread.currentThread();
+ }
+ }
+
+ public static void releaseLock() {
+ synchronized (mutex) {
+ --lockCount;
+ if (lockCount == 0) {
+ lockOwner = null;
+ mutex.notify();
+ }
+ }
+ }
+
+ public static void saveAll() {
+ // save the database
+ try {
+ for (Chunk chunk = lruFirst; chunk != null; chunk = chunk.lruNext) {
+ chunk.save();
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java
index 1995d8fd7f1..7c8b6cc293a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java
@@ -29,6 +29,8 @@ public class PDOMFastIndexer implements IPDOMIndexer {
protected ICProject project;
+ private boolean isReindexing;
+
public PDOMFastIndexer() {
}
@@ -45,9 +47,16 @@ public class PDOMFastIndexer implements IPDOMIndexer {
new PDOMFastHandleDelta(this, delta));
}
- public void reindex() throws CoreException {
+ public synchronized void reindex() throws CoreException {
+ if (isReindexing)
+ return;
+ isReindexing = true;
+
CCorePlugin.getPDOMManager().enqueue(
new PDOMFastReindex(this));
}
+ synchronized void reindexingComplete() {
+ isReindexing = false;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java
index 5b792818189..baae827b320 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java
@@ -58,9 +58,11 @@ public abstract class PDOMFastIndexerJob implements IPDOMIndexerTask {
return;
// get the AST in a "Fast" way
+ pdom.acquireReadLock();
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
codeReaderFactory,
ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
+ pdom.releaseReadLock();
if (ast == null)
return;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java
index 5a6b63c5b40..5bddf67e616 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java
@@ -57,12 +57,20 @@ public class PDOMFastReindex extends PDOMFastIndexerJob {
long start = System.currentTimeMillis();
// First clear the pdom
- pdom.clear();
+ try {
+ pdom.acquireWriteLock();
+ pdom.clear();
+ pdom.releaseWriteLock();
+ } catch (InterruptedException e) {
+ return;
+ }
ISourceRoot[] roots = indexer.getProject().getAllSourceRoots();
for (int i = 0; i < roots.length; ++i)
addSources(roots[i], monitor);
+ indexer.reindexingComplete();
+
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
+ "/debug/pdomtimings"); //$NON-NLS-1$
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java
index 337a5ed8626..c99722eac5a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java
@@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.ui;
+import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
@@ -40,11 +41,18 @@ public class IndexLabelProvider extends LabelProvider {
public String getText(Object element) {
if (element == null) {
return "null :(";
- } else if (element instanceof PDOMNode) {
+ } else if (element instanceof PDOMNamedNode) {
+ PDOMNamedNode namedNode = (PDOMNamedNode)element;
+ IPDOM pdom = namedNode.getPDOM();
try {
+ pdom.acquireReadLock();
return ((PDOMNamedNode)element).getDBName().getString();
+ } catch (InterruptedException e) {
+ return e.getMessage();
} catch (CoreException e) {
return e.getMessage();
+ } finally {
+ pdom.releaseReadLock();
}
} else
return super.getText(element);
@@ -52,13 +60,19 @@ public class IndexLabelProvider extends LabelProvider {
public Image getImage(Object element) {
ImageDescriptor desc = null;
-
+
if (element instanceof IVariable)
desc = CElementImageProvider.getVariableImageDescriptor();
else if (element instanceof IFunction)
desc = CElementImageProvider.getFunctionImageDescriptor();
else if (element instanceof ICPPClassType) {
+ IPDOM pdom = null;
+ if (element instanceof PDOMNode)
+ pdom = ((PDOMNode)element).getPDOM();
+
try {
+ if (pdom != null)
+ pdom.acquireReadLock();
switch (((ICPPClassType)element).getKey()) {
case ICPPClassType.k_class:
desc = CElementImageProvider.getClassImageDescriptor();
@@ -70,8 +84,11 @@ public class IndexLabelProvider extends LabelProvider {
desc = CElementImageProvider.getUnionImageDescriptor();
break;
}
+ } catch (InterruptedException e) {
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
+ } finally {
+ pdom.releaseReadLock();
}
}
else if (element instanceof ICompositeType)
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
index e1527a1361a..cd969ef3a86 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
@@ -71,41 +71,46 @@ public class CountNodeAction extends IndexAction {
ICProject project = (ICProject)objs[i];
final PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project);
//pdom.getDB().reportFreeBlocks();
-
- pdom.getFileIndex().accept(new IBTreeVisitor() {
- public int compare(int record) throws CoreException {
- return 1;
- }
- public boolean visit(int record) throws CoreException {
- if (record != 0) {
- PDOMFile file = new PDOMFile(pdom, record);
- ++count[FILES];
- PDOMMacro macro = file.getFirstMacro();
- while (macro != null) {
- ++count[MACROS];
- macro = macro.getNextMacro();
+ try {
+ pdom.acquireReadLock();
+ pdom.getFileIndex().accept(new IBTreeVisitor() {
+ public int compare(int record) throws CoreException {
+ return 1;
+ }
+ public boolean visit(int record) throws CoreException {
+ if (record != 0) {
+ PDOMFile file = new PDOMFile(pdom, record);
+ ++count[FILES];
+ PDOMMacro macro = file.getFirstMacro();
+ while (macro != null) {
+ ++count[MACROS];
+ macro = macro.getNextMacro();
+ }
+ }
+ return true;
+ }
+ });
+ pdom.accept(new IPDOMVisitor() {
+ public boolean visit(IPDOMNode node) throws CoreException {
+ ++count[SYMBOLS];
+ if (node instanceof PDOMBinding) {
+ PDOMBinding binding = (PDOMBinding)node;
+ for (PDOMName name = binding.getFirstReference(); name != null; name = name.getNextInBinding())
+ ++count[REFS];
+ for (PDOMName name = binding.getFirstDeclaration(); name != null; name = name.getNextInBinding())
+ ++count[DECLS];
+ for (PDOMName name = binding.getFirstDefinition(); name != null; name = name.getNextInBinding())
+ ++count[DEFS];
}
+ return true;
}
- return true;
- }
- });
- pdom.accept(new IPDOMVisitor() {
- public boolean visit(IPDOMNode node) throws CoreException {
- ++count[SYMBOLS];
- if (node instanceof PDOMBinding) {
- PDOMBinding binding = (PDOMBinding)node;
- for (PDOMName name = binding.getFirstReference(); name != null; name = name.getNextInBinding())
- ++count[REFS];
- for (PDOMName name = binding.getFirstDeclaration(); name != null; name = name.getNextInBinding())
- ++count[DECLS];
- for (PDOMName name = binding.getFirstDefinition(); name != null; name = name.getNextInBinding())
- ++count[DEFS];
+ public void leave(IPDOMNode node) throws CoreException {
}
- return true;
- }
- public void leave(IPDOMNode node) throws CoreException {
- }
- });
+ });
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java
index 4efd80e467e..c04573d238e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java
@@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
@@ -30,6 +31,7 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -184,26 +186,39 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
if (parentElement instanceof ICProject) {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement);
int n = 0;
- PDOMLinkage firstLinkage = pdom.getFirstLinkage();
- for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage())
- ++n;
- if (n == 1) {
- // Skip linkages in hierarchy if there is only one
- return getChildren(firstLinkage);
+ try {
+ pdom.acquireReadLock();
+ PDOMLinkage firstLinkage = pdom.getFirstLinkage();
+ for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage())
+ ++n;
+ if (n == 1) {
+ // Skip linkages in hierarchy if there is only one
+ return getChildren(firstLinkage);
+ }
+ PDOMLinkage[] linkages = new PDOMLinkage[n];
+ int i = 0;
+ for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
+ linkages[i++] = linkage;
+ return linkages;
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
+ } else if (parentElement instanceof PDOMNode) {
+ PDOMNode node = (PDOMNode)parentElement;
+ IPDOM pdom = node.getPDOM();
+ try {
+ pdom.acquireReadLock();
+ Counter counter = new Counter();
+ node.accept(counter);
+ IPDOMNode[] children = new IPDOMNode[counter.count];
+ Children childrener = new Children(children);
+ node.accept(childrener);
+ return children;
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
}
- PDOMLinkage[] linkages = new PDOMLinkage[n];
- int i = 0;
- for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
- linkages[i++] = linkage;
- return linkages;
- } else if (parentElement instanceof IPDOMNode) {
- IPDOMNode node = (IPDOMNode)parentElement;
- Counter counter = new Counter();
- node.accept(counter);
- IPDOMNode[] children = new IPDOMNode[counter.count];
- Children childrener = new Children(children);
- node.accept(childrener);
- return children;
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
@@ -220,21 +235,33 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
try {
if (element instanceof ICProject) {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)element);
- PDOMLinkage[] linkages = pdom.getLinkages();
- if (linkages.length == 0)
- return false;
- else if (linkages.length == 1)
- // Skipping linkages if only one
- return hasChildren(linkages[0]);
- else
- return true;
+ try {
+ pdom.acquireReadLock();
+ PDOMLinkage[] linkages = pdom.getLinkages();
+ if (linkages.length == 0)
+ return false;
+ else if (linkages.length == 1)
+ // Skipping linkages if only one
+ return hasChildren(linkages[0]);
+ else
+ return true;
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
} else if (element instanceof IPDOMNode) {
HasChildren hasChildren = new HasChildren();
+ PDOMNode pdomNode = (PDOMNode)element;
+ IPDOM pdom = pdomNode.getPDOM();
try {
+ pdom.acquireReadLock();
((IPDOMNode)element).accept(hasChildren);
+ } catch (InterruptedException e) {
} catch (CoreException e) {
if (e.getStatus() != Status.OK_STATUS)
throw e;
+ } finally {
+ pdom.releaseReadLock();
}
return hasChildren.hasChildren;
}
@@ -401,12 +428,18 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
viewer.getControl().setFocus();
}
- public void handleChange(PDOM pdom) {
- viewer.getControl().getDisplay().asyncExec(new Runnable() {
- public void run() {
- viewer.refresh();
- }
- });
+ public void handleChange(final PDOM pdom) {
+ viewer.getControl().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ try {
+ pdom.acquireReadLock();
+ viewer.refresh();
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
+ }
+ });
}
public void elementChanged(ElementChangedEvent event) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/OpenDefinitionAction.java
index fa4d8b5bb20..8b1d524e16a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/OpenDefinitionAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/OpenDefinitionAction.java
@@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.ui.indexview;
+import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@@ -49,8 +50,11 @@ public class OpenDefinitionAction extends IndexAction {
if (!(objs[i] instanceof PDOMBinding))
continue;
+ PDOMBinding binding = (PDOMBinding)objs[i];
+ IPDOM pdom = binding.getPDOM();
+
try {
- PDOMBinding binding = (PDOMBinding)objs[i];
+ pdom.acquireReadLock();
PDOMName name = binding.getFirstDefinition();
if (name == null)
name = binding.getFirstDeclaration();
@@ -87,8 +91,11 @@ public class OpenDefinitionAction extends IndexAction {
textEditor.selectAndReveal(offset, length);
}
+ } catch (InterruptedException e) {
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
+ } finally {
+ pdom.releaseReadLock();
}
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchBindingQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchBindingQuery.java
index 2159e94aa7a..cb87479e172 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchBindingQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchBindingQuery.java
@@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.ui.CUIPlugin;
@@ -36,7 +37,14 @@ public class PDOMSearchBindingQuery extends PDOMSearchQuery {
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
- createMatches(binding.getLinkage().getLanguage(), binding);
+ IPDOM pdom = binding.getPDOM();
+ try {
+ pdom.acquireReadLock();
+ createMatches(binding.getLinkage().getLanguage(), binding);
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
return Status.OK_STATUS;
} catch (CoreException e) {
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
@@ -44,7 +52,15 @@ public class PDOMSearchBindingQuery extends PDOMSearchQuery {
}
public String getLabel() {
- return super.getLabel() + " " + binding.getName();
+ IPDOM pdom = binding.getPDOM();
+ try {
+ pdom.acquireReadLock();
+ return super.getLabel() + " " + binding.getName();
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
+ }
+ return super.getLabel();
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
index bfb854a409d..ffd03819202 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
@@ -11,6 +11,8 @@
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -42,13 +44,20 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
ILanguage language = tu.getLanguage();
- IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
- IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
-
- for (int i = 0; i < names.length; ++i) {
- IBinding binding = names[i].resolveBinding();
- if (binding != null)
- createMatches(language, binding);
+ IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(tu.getCProject());
+ try {
+ pdom.acquireReadLock();
+ IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
+ IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
+
+ for (int i = 0; i < names.length; ++i) {
+ IBinding binding = names[i].resolveBinding();
+ if (binding != null)
+ createMatches(language, binding);
+ }
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
}
return Status.OK_STATUS;
} catch (CoreException e) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
index 6789418ce76..34461080628 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
@@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.ui.search.actions;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -21,8 +22,10 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextSelection;
@@ -70,31 +73,42 @@ public class OpenDeclarationsAction extends SelectionParseAction {
if (binding != null && !(binding instanceof IProblemBinding)) {
final IASTName[] declNames = ast.getDeclarations(binding);
if (declNames.length > 0) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- try {
- open(declNames[0]);
- } catch (CoreException e) {
- CUIPlugin.getDefault().log(e);
- }
- };
- });
- } else if (binding instanceof PDOMBinding) {
- PDOMBinding pdomBinding = (PDOMBinding)binding;
- IASTName name = pdomBinding.getFirstDefinition();
- if (name == null)
- name = pdomBinding.getFirstDeclaration();
- if (name != null) {
- final IASTName dname = name;
+ IASTFileLocation fileloc = declNames[0].getFileLocation();
+ if (fileloc != null) {
+ final IPath path = new Path(fileloc.getFileName());
+ final int offset = fileloc.getNodeOffset();
+ final int length = fileloc.getNodeLength();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
- open(dname);
+ open(path, offset, length);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
- }
+ };
});
+ }
+ } else if (binding instanceof PDOMBinding) {
+ PDOMBinding pdomBinding = (PDOMBinding)binding;
+ IASTName name = pdomBinding.getFirstDefinition();
+ if (name == null)
+ name = pdomBinding.getFirstDeclaration();
+ if (name != null) {
+ IASTFileLocation fileloc = name.getFileLocation();
+ if (fileloc != null) {
+ final IPath path = new Path(fileloc.getFileName());
+ final int offset = fileloc.getNodeOffset();
+ final int length = fileloc.getNodeLength();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ try {
+ open(path, offset, length);
+ } catch (CoreException e) {
+ CUIPlugin.getDefault().log(e);
+ }
+ }
+ });
+ }
}
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java
index 0f928c53a00..d533fc658f9 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOM;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -19,8 +22,10 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextSelection;
@@ -59,30 +64,43 @@ public class OpenDefinitionAction extends SelectionParseAction {
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
if (workingCopy == null)
return Status.CANCEL_STATUS;
-
- IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
- IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
-
- if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
- IASTName searchName = selectedNames[0];
-
- IBinding binding = searchName.resolveBinding();
- if (binding != null) {
- final IASTName[] declNames = ast.getDefinitions(binding);
- if (declNames.length > 0) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- try {
- open(declNames[0]);
- } catch (CoreException e) {
- CUIPlugin.getDefault().log(e);
- }
- };
- });
+
+ IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
+ try {
+ pdom.acquireReadLock();
+ IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
+ IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
+
+ if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
+ IASTName searchName = selectedNames[0];
+
+ IBinding binding = searchName.resolveBinding();
+ if (binding != null) {
+ final IASTName[] declNames = ast.getDefinitions(binding);
+ if (declNames.length > 0) {
+ IASTFileLocation fileloc = declNames[0].getFileLocation();
+ if (fileloc != null) {
+ final IPath path = new Path(fileloc.getFileName());
+ final int offset = fileloc.getNodeOffset();
+ final int length = fileloc.getNodeLength();
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ try {
+ open(path, offset, length);
+ } catch (CoreException e) {
+ CUIPlugin.getDefault().log(e);
+ }
+ };
+ });
+ }
+ }
}
}
+ } catch (InterruptedException e) {
+ } finally {
+ pdom.releaseReadLock();
}
-
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java
index fd7fed1a295..13d7f6a10b2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java
@@ -14,8 +14,6 @@ package org.eclipse.cdt.internal.ui.search.actions;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
-import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
@@ -42,7 +40,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.text.BadLocationException;
@@ -521,22 +518,14 @@ public class SelectionParseAction extends Action {
*
* @param name
*/
- protected void open(IASTName name) throws CoreException {
- IASTFileLocation fileloc = name.getFileLocation();
- if (fileloc == null)
- // no source location - TODO spit out an error in the status bar
- return;
- int currentOffset = fileloc.getNodeOffset();
- int currentLength = fileloc.getNodeLength();
-
- IPath path = new Path(fileloc.getFileName());
+ protected void open(IPath path, int offset, int length) throws CoreException {
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0) {
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
try {
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
- marker.setAttribute(IMarker.CHAR_START, currentOffset);
- marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
+ marker.setAttribute(IMarker.CHAR_START, offset);
+ marker.setAttribute(IMarker.CHAR_END, offset + length);
IDE.gotoMarker(editor, marker);
marker.delete();
} catch (CoreException e) {
@@ -548,7 +537,7 @@ public class SelectionParseAction extends Action {
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
- textEditor.selectAndReveal(currentOffset, currentLength);
+ textEditor.selectAndReveal(offset, length);
}
}

Back to the top