### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v retrieving revision 1.61 diff -u -r1.61 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 2 Jul 2007 09:38:30 -0000 1.61 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 3 Jul 2007 16:23:48 -0000 @@ -361,17 +361,24 @@ void initialize(boolean reuseExistingFile) throws IOException { if (this.indexFile.exists()) { if (reuseExistingFile) { - RandomAccessFile file = new RandomAccessFile(this.indexFile, "r"); //$NON-NLS-1$ + FileInputStream stream = new FileInputStream(this.indexFile); + this.streamBuffer = new byte[BUFFER_READ_SIZE]; + this.bufferIndex = 0; + this.bufferEnd = stream.read(this.streamBuffer, 0, 128); try { - String signature = file.readUTF(); - if (!signature.equals(SIGNATURE)) - throw new IOException(Messages.exception_wrongFormat); - - this.headerInfoOffset = file.readInt(); - if (this.headerInfoOffset > 0) // file is empty if its not set - readHeaderInfo(file); + char[] signature = readStreamChars(stream); + if (!CharOperation.equals(signature, SIGNATURE_CHARS)) { + throw new IOException(Messages.exception_wrongFormat); + } + this.headerInfoOffset = readStreamInt(stream); + if (this.headerInfoOffset > 0) { // file is empty if its not set + stream.skip(this.headerInfoOffset - this.bufferEnd); // assume that the header info offset is over current buffer end + this.bufferIndex = 0; + this.bufferEnd = stream.read(this.streamBuffer, 0, this.streamBuffer.length); + readHeaderInfo(stream); + } } finally { - file.close(); + stream.close(); } return; } @@ -382,12 +389,19 @@ } } if (this.indexFile.createNewFile()) { - RandomAccessFile file = new RandomAccessFile(this.indexFile, "rw"); //$NON-NLS-1$ + FileOutputStream stream = new FileOutputStream(this.indexFile, false); try { - file.writeUTF(SIGNATURE); - file.writeInt(-1); // file is empty + this.streamBuffer = new byte[BUFFER_READ_SIZE]; + this.bufferIndex = 0; + writeStreamChars(stream, SIGNATURE_CHARS); + writeStreamInt(stream, -1); // file is empty + // write the buffer to the stream + if (this.bufferIndex > 0) { + stream.write(this.streamBuffer, 0, this.bufferIndex); + this.bufferIndex = 0; + } } finally { - file.close(); + stream.close(); } } else { if (DEBUG) @@ -750,28 +764,27 @@ this.streamBuffer = null; } } -private void readHeaderInfo(RandomAccessFile file) throws IOException { - file.seek(this.headerInfoOffset); +private void readHeaderInfo(FileInputStream stream) throws IOException { // must be same order as writeHeaderInfo() - this.numberOfChunks = file.readInt(); - this.sizeOfLastChunk = file.readUnsignedByte(); - this.documentReferenceSize = file.readUnsignedByte(); + this.numberOfChunks = readStreamInt(stream); + this.sizeOfLastChunk = this.streamBuffer[this.bufferIndex++] & 0xFF; + this.documentReferenceSize = this.streamBuffer[this.bufferIndex++] & 0xFF; this.chunkOffsets = new int[this.numberOfChunks]; for (int i = 0; i < this.numberOfChunks; i++) - this.chunkOffsets[i] = file.readInt(); + this.chunkOffsets[i] = readStreamInt(stream); - this.startOfCategoryTables = file.readInt(); + this.startOfCategoryTables = readStreamInt(stream); - int size = file.readInt(); + int size = readStreamInt(stream); this.categoryOffsets = new HashtableOfIntValues(size); this.categoryEnds = new HashtableOfIntValues(size); char[] previousCategory = null; int offset = -1; for (int i = 0; i < size; i++) { - char[] categoryName = INTERNED_CATEGORY_NAMES.get(file.readUTF().toCharArray()); - offset = file.readInt(); + char[] categoryName = INTERNED_CATEGORY_NAMES.get(readStreamChars(stream)); + offset = readStreamInt(stream); this.categoryOffsets.put(categoryName, offset); // cache offset to category table if (previousCategory != null) { this.categoryEnds.put(previousCategory, offset); // cache end of the category table #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.108 diff -u -r1.108 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 26 Jun 2007 11:05:39 -0000 1.108 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 3 Jul 2007 16:23:51 -0000 @@ -25,9 +25,13 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.core.ClassFile; +import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.SourceMethod; +import org.eclipse.jdt.internal.core.index.DiskIndex; +import org.eclipse.jdt.internal.core.index.Index; import org.eclipse.jdt.internal.core.search.AbstractSearchScope; import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; +import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.eclipse.jdt.internal.core.search.matching.MatchLocator; import org.eclipse.jdt.internal.core.search.matching.PatternLocator; import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern; @@ -7914,6 +7918,34 @@ } /** + * @bug 181488 [index] Lots of unbuffered sequential reads in DiskIndex + * @test Ensure that indexing does not happen while reopening workspace (see bug 195091) + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=181488" + */ +public void testBug181488a() throws CoreException { + waitUntilIndexesReady(); + IndexManager manager = JavaModelManager.getJavaModelManager().getIndexManager(); + Index index = manager.getIndex(JAVA_PROJECT.getPath(), true, false); + long lastModified = index.getIndexFile().lastModified(); + simulateExitRestart(); + waitUntilIndexesReady(); + Index newIndex = manager.getIndex(JAVA_PROJECT.getPath(), true, false); + assertEquals("Index file should be unchanged!!!", lastModified, newIndex.getIndexFile().lastModified()); +} +public void testBug181488b() throws CoreException { + IJavaProject project = createJavaProject("Bug181488"); + try { + waitUntilIndexesReady(); + IndexManager manager = JavaModelManager.getJavaModelManager().getIndexManager(); + Index index = manager.getIndex(project.getPath(), true, false); + assertEquals("Index file should at least contains the signature!!!", DiskIndex.SIGNATURE.length()+6, index.getIndexFile().length()); + } + finally { + deleteProject(project); + } +} + +/** * @bug 185452 [search] for all packages seems hung * @test Ensure that all package declarations are found only once * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=185452"