Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] CDT 1_2 Version: Indexer patch for Bug 51232


This patch adds a layer of separation between the indexer and the parser by running the parser in its own thread. This allows the indexer to finish all jobs regardless of the individual parser outcomes. Also fixed a potential EOF bug while reading stored indexes.

This patch is for 1.2 only (a separate patch is coming for 2.0).

- Bogdan

Index: index/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/ChangeLog,v
retrieving revision 1.24.2.2
diff -u -r1.24.2.2 ChangeLog
--- index/ChangeLog	3 Feb 2004 16:09:16 -0000	1.24.2.2
+++ index/ChangeLog	10 Feb 2004 17:09:52 -0000
@@ -1,3 +1,17 @@
+2004-02-10 Bogdan Gheorghe
+	PR 51232
+	
+	- Added a layer of separation between the parser and the indexer: we now
+	  create a worker thread to run the parser in. This allows the indexer to 
+	  finish all scheduled jobs regardless of how the parser performs on
+	  individual files (i.e. indexing no longer affected by parser failures)
+	  
+	- Modified some of the stored index block reading routines to use separate
+	  counters, thus avoiding potential EOF exceptions.
+	  
+    * index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
+	* index/org/eclipse/cdt/internal/core/index/search/indexing/SourceIndexer.java
+	
 2004-02-03 Alain Magloire
 
 	PR 51106
Index: index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java,v
retrieving revision 1.4
diff -u -r1.4 BlocksIndexInput.java
--- index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java	26 Sep 2003 17:53:31 -0000	1.4
+++ index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java	10 Feb 2004 17:09:52 -0000
@@ -30,6 +30,7 @@
 	protected FileListBlock currentFileListBlock;
 	protected int currentFileListBlockNum;
 	protected int currentIndexBlockNum;
+	protected int currentIncludeBlockNum;
 	protected IndexBlock currentIndexBlock;
 	protected IndexBlock currentIncludeIndexBlock;
 	private RandomAccessFile raf;
@@ -408,7 +409,7 @@
 		//if end of the current block, we load the next one.
 		boolean endOfBlock= !currentIncludeIndexBlock.nextEntry(currentIncludeEntry);
 		if (endOfBlock) {
-			currentIncludeIndexBlock= getIndexBlock(++currentIndexBlockNum);
+			currentIncludeIndexBlock= getIndexBlock(++currentIncludeBlockNum);
 			currentIncludeIndexBlock.nextEntry(currentWordEntry);
 		}
 	}
@@ -418,8 +419,8 @@
 	protected void setFirstInclude() throws IOException {
 		includePosition= 1;
 		if (getNumIncludes() > 0) {
-			currentIndexBlockNum= summary.getFirstIncludeBlockNum();
-			currentIncludeIndexBlock= getIndexBlock(currentIndexBlockNum);
+			currentIncludeBlockNum= summary.getFirstIncludeBlockNum();
+			currentIncludeIndexBlock= getIndexBlock(currentIncludeBlockNum);
 			currentIncludeEntry= new IncludeEntry(0);
 			currentIncludeIndexBlock.reset();
 			currentIncludeIndexBlock.nextEntry(currentIncludeEntry);
Index: index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java,v
retrieving revision 1.13
diff -u -r1.13 SourceIndexer.java
--- index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java	1 Oct 2003 22:15:34 -0000	1.13
+++ index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java	10 Feb 2004 17:09:52 -0000
@@ -88,7 +88,18 @@
 							ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor ), 
 							requestor, ParserMode.COMPLETE_PARSE, language );
 		
-		boolean retVal = parser.parse();
+		ParserRunner p = new ParserRunner(parser);
+		Thread t = new Thread(p, "CDT Indexer Parser Runner");
+		t.start();
+		
+		try{
+			t.join();
+		}
+		catch (InterruptedException e){
+			org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner InterruptedException - file: " + resourceFile.getFullPath(), ICLogConstants.CDT);
+		}
+		
+		boolean retVal = p.getResult();
 		
 		if (!retVal)
 			org.eclipse.cdt.internal.core.model.Util.log(null, "Failed to index " + resourceFile.getFullPath(), ICLogConstants.CDT);
@@ -103,12 +114,33 @@
 	/**
 	 * Sets the document types the <code>IIndexer</code> handles.
 	 */
-	
 	public void setFileTypes(String[] fileTypes){}
 	/* (non-Javadoc)
 	 * @see org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer#getResourceFile()
 	 */
 	public IFile getResourceFile() {
 		return resourceFile;
+	}
+	
+	class ParserRunner implements Runnable {
+		IParser parser;
+		boolean retVal;
+		ParserRunner(IParser parser){
+			this.parser = parser;
+		}
+		/* (non-Javadoc)
+		 * @see java.lang.Runnable#run()
+		 */
+		public void run() {
+			try{
+				retVal=parser.parse();
+			}
+			catch (Exception e){
+				org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner Exception " + resourceFile.getFullPath() + " Message: " + e.getMessage(), ICLogConstants.CDT);
+			}
+		}
+		
+		boolean getResult(){ return retVal;}
+		
 	}
 }

Back to the top