View | Details | Raw Unified | Return to bug 181488 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/index/DiskIndex.java (-23 / +36 lines)
Lines 361-377 Link Here
361
void initialize(boolean reuseExistingFile) throws IOException {
361
void initialize(boolean reuseExistingFile) throws IOException {
362
	if (this.indexFile.exists()) {
362
	if (this.indexFile.exists()) {
363
		if (reuseExistingFile) {
363
		if (reuseExistingFile) {
364
			RandomAccessFile file = new RandomAccessFile(this.indexFile, "r"); //$NON-NLS-1$
364
			FileInputStream stream = new FileInputStream(this.indexFile);
365
			this.streamBuffer = new byte[BUFFER_READ_SIZE];
366
			this.bufferIndex = 0;
367
			this.bufferEnd = stream.read(this.streamBuffer, 0, 128);
365
			try {
368
			try {
366
				String signature = file.readUTF();
369
				char[] signature = readStreamChars(stream);
367
				if (!signature.equals(SIGNATURE))
370
				if (!CharOperation.equals(signature, SIGNATURE_CHARS)) {
368
					throw new IOException(Messages.exception_wrongFormat); 
371
					throw new IOException(Messages.exception_wrongFormat);
369
372
				}
370
				this.headerInfoOffset = file.readInt();
373
				this.headerInfoOffset = readStreamInt(stream);
371
				if (this.headerInfoOffset > 0) // file is empty if its not set
374
				if (this.headerInfoOffset > 0) { // file is empty if its not set
372
					readHeaderInfo(file);
375
					stream.skip(this.headerInfoOffset - this.bufferEnd); // assume that the header info offset is over current buffer end
376
					this.bufferIndex = 0;
377
					this.bufferEnd = stream.read(this.streamBuffer, 0, this.streamBuffer.length);
378
					readHeaderInfo(stream);
379
				}
373
			} finally {
380
			} finally {
374
				file.close();
381
				stream.close();
375
			}
382
			}
376
			return;
383
			return;
377
		}
384
		}
Lines 382-393 Link Here
382
		}
389
		}
383
	}
390
	}
384
	if (this.indexFile.createNewFile()) {
391
	if (this.indexFile.createNewFile()) {
385
		RandomAccessFile file = new RandomAccessFile(this.indexFile, "rw"); //$NON-NLS-1$
392
		FileOutputStream stream = new FileOutputStream(this.indexFile, false);
386
		try {
393
		try {
387
			file.writeUTF(SIGNATURE);
394
			this.streamBuffer = new byte[BUFFER_READ_SIZE];
388
			file.writeInt(-1); // file is empty
395
			this.bufferIndex = 0;
396
			writeStreamChars(stream, SIGNATURE_CHARS);
397
			writeStreamInt(stream, -1); // file is empty
398
			// write the buffer to the stream
399
			if (this.bufferIndex > 0) {
400
				stream.write(this.streamBuffer, 0, this.bufferIndex);
401
				this.bufferIndex = 0;
402
			}
389
		} finally {
403
		} finally {
390
			file.close();
404
			stream.close();
391
		}
405
		}
392
	} else {
406
	} else {
393
		if (DEBUG)
407
		if (DEBUG)
Lines 750-777 Link Here
750
		this.streamBuffer = null;
764
		this.streamBuffer = null;
751
	}
765
	}
752
}
766
}
753
private void readHeaderInfo(RandomAccessFile file) throws IOException {
767
private void readHeaderInfo(FileInputStream stream) throws IOException {
754
	file.seek(this.headerInfoOffset);
755
768
756
	// must be same order as writeHeaderInfo()
769
	// must be same order as writeHeaderInfo()
757
	this.numberOfChunks = file.readInt();
770
	this.numberOfChunks = readStreamInt(stream);
758
	this.sizeOfLastChunk = file.readUnsignedByte();
771
	this.sizeOfLastChunk = this.streamBuffer[this.bufferIndex++] & 0xFF;
759
	this.documentReferenceSize = file.readUnsignedByte();
772
	this.documentReferenceSize = this.streamBuffer[this.bufferIndex++] & 0xFF;
760
773
761
	this.chunkOffsets = new int[this.numberOfChunks];
774
	this.chunkOffsets = new int[this.numberOfChunks];
762
	for (int i = 0; i < this.numberOfChunks; i++)
775
	for (int i = 0; i < this.numberOfChunks; i++)
763
		this.chunkOffsets[i] = file.readInt();
776
		this.chunkOffsets[i] = readStreamInt(stream);
764
777
765
	this.startOfCategoryTables = file.readInt();
778
	this.startOfCategoryTables = readStreamInt(stream);
766
779
767
	int size = file.readInt();
780
	int size = readStreamInt(stream);
768
	this.categoryOffsets = new HashtableOfIntValues(size);
781
	this.categoryOffsets = new HashtableOfIntValues(size);
769
	this.categoryEnds = new HashtableOfIntValues(size);
782
	this.categoryEnds = new HashtableOfIntValues(size);
770
	char[] previousCategory = null;
783
	char[] previousCategory = null;
771
	int offset = -1;
784
	int offset = -1;
772
	for (int i = 0; i < size; i++) {
785
	for (int i = 0; i < size; i++) {
773
		char[] categoryName = INTERNED_CATEGORY_NAMES.get(file.readUTF().toCharArray());
786
		char[] categoryName = INTERNED_CATEGORY_NAMES.get(readStreamChars(stream));
774
		offset = file.readInt();
787
		offset = readStreamInt(stream);
775
		this.categoryOffsets.put(categoryName, offset); // cache offset to category table
788
		this.categoryOffsets.put(categoryName, offset); // cache offset to category table
776
		if (previousCategory != null) {
789
		if (previousCategory != null) {
777
			this.categoryEnds.put(previousCategory, offset); // cache end of the category table
790
			this.categoryEnds.put(previousCategory, offset); // cache end of the category table
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+32 lines)
Lines 25-33 Link Here
25
25
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.core.ClassFile;
27
import org.eclipse.jdt.internal.core.ClassFile;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.SourceMethod;
29
import org.eclipse.jdt.internal.core.SourceMethod;
30
import org.eclipse.jdt.internal.core.index.DiskIndex;
31
import org.eclipse.jdt.internal.core.index.Index;
29
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
32
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
30
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
33
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
34
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
31
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
35
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
32
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
36
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
33
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
37
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
Lines 7914-7919 Link Here
7914
}
7918
}
7915
7919
7916
/**
7920
/**
7921
 * @bug 181488 [index] Lots of unbuffered sequential reads in DiskIndex
7922
 * @test Ensure that indexing does not happen while reopening workspace (see bug 195091)
7923
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=181488"
7924
 */
7925
public void testBug181488a() throws CoreException {
7926
	waitUntilIndexesReady();
7927
	IndexManager manager = JavaModelManager.getJavaModelManager().getIndexManager();
7928
	Index index = manager.getIndex(JAVA_PROJECT.getPath(), true, false);
7929
	long lastModified = index.getIndexFile().lastModified();
7930
	simulateExitRestart();
7931
	waitUntilIndexesReady();
7932
	Index newIndex = manager.getIndex(JAVA_PROJECT.getPath(), true, false);
7933
	assertEquals("Index file should be unchanged!!!", lastModified, newIndex.getIndexFile().lastModified());
7934
}
7935
public void testBug181488b() throws CoreException {
7936
	IJavaProject project = createJavaProject("Bug181488");
7937
	try {
7938
		waitUntilIndexesReady();
7939
		IndexManager manager = JavaModelManager.getJavaModelManager().getIndexManager();
7940
		Index index = manager.getIndex(project.getPath(), true, false);
7941
		assertEquals("Index file should at least contains the signature!!!", DiskIndex.SIGNATURE.length()+6, index.getIndexFile().length());
7942
	}
7943
	finally {
7944
		deleteProject(project);
7945
	}
7946
}
7947
7948
/**
7917
 * @bug 185452 [search] for all packages seems hung
7949
 * @bug 185452 [search] for all packages seems hung
7918
 * @test Ensure that all package declarations are found only once
7950
 * @test Ensure that all package declarations are found only once
7919
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=185452"
7951
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=185452"

Return to bug 181488