|
Lines 8-13
Link Here
|
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Markus Schorn - initial API and implementation |
9 |
* Markus Schorn - initial API and implementation |
| 10 |
* IBM Corporation |
10 |
* IBM Corporation |
|
|
11 |
* Sergey Prigogin (Google) |
| 11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 12 |
package org.eclipse.cdt.internal.core.pdom; |
13 |
package org.eclipse.cdt.internal.core.pdom; |
| 13 |
|
14 |
|
|
Lines 46-51
Link Here
|
| 46 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; |
47 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; |
| 47 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; |
48 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; |
| 48 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
49 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
|
|
50 |
import org.eclipse.cdt.core.index.IIndexInclude; |
| 49 |
import org.eclipse.cdt.core.parser.IProblem; |
51 |
import org.eclipse.cdt.core.parser.IProblem; |
| 50 |
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; |
52 |
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; |
| 51 |
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; |
53 |
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; |
|
Lines 68-73
Link Here
|
| 68 |
* @since 4.0 |
70 |
* @since 4.0 |
| 69 |
*/ |
71 |
*/ |
| 70 |
abstract public class PDOMWriter { |
72 |
abstract public class PDOMWriter { |
|
|
73 |
// TODO(sprigogin): Remove SEMI_TRANSACTIONAL_UPDATES and ALLOW_LOCK_YIELDING constants and simplify the code. |
| 74 |
public static boolean SEMI_TRANSACTIONAL_UPDATES = true; |
| 75 |
public static boolean ALLOW_LOCK_YIELDING = true; |
| 71 |
public static int SKIP_ALL_REFERENCES= -1; |
76 |
public static int SKIP_ALL_REFERENCES= -1; |
| 72 |
public static int SKIP_TYPE_REFERENCES= 1; |
77 |
public static int SKIP_TYPE_REFERENCES= 1; |
| 73 |
public static int SKIP_MACRO_REFERENCES= 2; |
78 |
public static int SKIP_MACRO_REFERENCES= 2; |
|
Lines 200-210
Link Here
|
| 200 |
if (fShowActivity) { |
205 |
if (fShowActivity) { |
| 201 |
trace("Indexer: adding " + ifl.getURI()); //$NON-NLS-1$ |
206 |
trace("Indexer: adding " + ifl.getURI()); //$NON-NLS-1$ |
| 202 |
} |
207 |
} |
| 203 |
index.acquireWriteLock(readlockCount); |
|
|
| 204 |
long start= System.currentTimeMillis(); |
| 205 |
Throwable th= null; |
208 |
Throwable th= null; |
|
|
209 |
YieldableIndexLock lock = new YieldableIndexLock(index, readlockCount, flushIndex); |
| 210 |
lock.acquire(); |
| 206 |
try { |
211 |
try { |
| 207 |
storeFileInIndex(index, ifl, symbolMap, linkageID, configHash, contextIncludes); |
212 |
storeFileInIndex(index, ifl, symbolMap, linkageID, configHash, contextIncludes, lock); |
| 208 |
} catch (RuntimeException e) { |
213 |
} catch (RuntimeException e) { |
| 209 |
th= e; |
214 |
th= e; |
| 210 |
} catch (PDOMNotImplementedError e) { |
215 |
} catch (PDOMNotImplementedError e) { |
|
Lines 214-220
Link Here
|
| 214 |
} catch (AssertionError e) { |
219 |
} catch (AssertionError e) { |
| 215 |
th= e; |
220 |
th= e; |
| 216 |
} finally { |
221 |
} finally { |
| 217 |
index.releaseWriteLock(readlockCount, flushIndex); |
222 |
lock.release(); |
| 218 |
} |
223 |
} |
| 219 |
if (th != null) { |
224 |
if (th != null) { |
| 220 |
stati.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing, |
225 |
stati.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing, |
|
Lines 223-229
Link Here
|
| 223 |
if (i < ifls.length - 1) { |
228 |
if (i < ifls.length - 1) { |
| 224 |
updateFileCount(0, 0, 1); // update header count |
229 |
updateFileCount(0, 0, 1); // update header count |
| 225 |
} |
230 |
} |
| 226 |
fStatistics.fAddToIndexTime += System.currentTimeMillis() - start; |
231 |
fStatistics.fAddToIndexTime += lock.getCumulativeLockTime(); |
| 227 |
} |
232 |
} |
| 228 |
} |
233 |
} |
| 229 |
} |
234 |
} |
|
Lines 448-487
Link Here
|
| 448 |
|
453 |
|
| 449 |
private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location, |
454 |
private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location, |
| 450 |
Map<IIndexFileLocation, Symbols> symbolMap, int linkageID, int configHash, |
455 |
Map<IIndexFileLocation, Symbols> symbolMap, int linkageID, int configHash, |
| 451 |
Set<IASTPreprocessorIncludeStatement> contextIncludes) throws CoreException { |
456 |
Set<IASTPreprocessorIncludeStatement> contextIncludes, YieldableIndexLock lock) |
|
|
457 |
throws CoreException, InterruptedException { |
| 452 |
Set<IIndexFileLocation> clearedContexts= Collections.emptySet(); |
458 |
Set<IIndexFileLocation> clearedContexts= Collections.emptySet(); |
| 453 |
IIndexFragmentFile file= index.getWritableFile(linkageID, location); |
459 |
IIndexFragmentFile file; |
| 454 |
if (file != null) { |
460 |
long timestamp = fResolver.getLastModified(location); |
| 455 |
clearedContexts= new HashSet<IIndexFileLocation>(); |
461 |
if (SEMI_TRANSACTIONAL_UPDATES) { |
| 456 |
index.clearFile(file, clearedContexts); |
462 |
// In fine grained locking mode we create a temporary PDOMFile with zero timestamp, |
|
|
463 |
// add names to it, then replace contents of the old file from the temporary one, then |
| 464 |
// delete the temporary file. The write lock on the index is periodically yielded while |
| 465 |
// adding names to the temporary file, if the process takes long time. |
| 466 |
IIndexFragmentFile oldFile = index.getWritableFile(linkageID, location); |
| 467 |
if (oldFile != null) { |
| 468 |
IIndexInclude[] includedBy = index.findIncludedBy(oldFile); |
| 469 |
if (includedBy.length > 0) { |
| 470 |
clearedContexts= new HashSet<IIndexFileLocation>(); |
| 471 |
for (IIndexInclude include : includedBy) { |
| 472 |
clearedContexts.add(include.getIncludedByLocation()); |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
file= index.addUncommittedFile(linkageID, location); |
| 457 |
} else { |
477 |
} else { |
| 458 |
file= index.addFile(linkageID, location); |
478 |
file= index.getWritableFile(linkageID, location); |
|
|
479 |
if (file != null) { |
| 480 |
clearedContexts= new HashSet<IIndexFileLocation>(); |
| 481 |
index.clearFile(file, clearedContexts); |
| 482 |
} else { |
| 483 |
file= index.addFile(linkageID, location); |
| 484 |
} |
| 485 |
file.setTimestamp(timestamp); |
| 459 |
} |
486 |
} |
| 460 |
file.setTimestamp(fResolver.getLastModified(location)); |
487 |
try { |
| 461 |
file.setScannerConfigurationHashcode(configHash); |
488 |
file.setScannerConfigurationHashcode(configHash); |
| 462 |
Symbols lists= symbolMap.get(location); |
489 |
Symbols lists= symbolMap.get(location); |
| 463 |
if (lists != null) { |
490 |
if (lists != null) { |
| 464 |
IASTPreprocessorStatement[] macros= lists.fMacros.toArray(new IASTPreprocessorStatement[lists.fMacros.size()]); |
491 |
IASTPreprocessorStatement[] macros= lists.fMacros.toArray(new IASTPreprocessorStatement[lists.fMacros.size()]); |
| 465 |
IASTName[][] names= lists.fNames.toArray(new IASTName[lists.fNames.size()][]); |
492 |
IASTName[][] names= lists.fNames.toArray(new IASTName[lists.fNames.size()][]); |
| 466 |
for (IASTName[] name2 : names) { |
493 |
for (IASTName[] name2 : names) { |
| 467 |
final IASTName name= name2[0]; |
494 |
final IASTName name= name2[0]; |
| 468 |
if (name != null) { |
495 |
if (name != null) { |
| 469 |
ASTInternal.setFullyResolved(name.getBinding(), true); |
496 |
ASTInternal.setFullyResolved(name.getBinding(), true); |
|
|
497 |
} |
| 470 |
} |
498 |
} |
| 471 |
} |
499 |
|
| 472 |
|
500 |
IncludeInformation[] includeInfos= new IncludeInformation[lists.fIncludes.size()]; |
| 473 |
IncludeInformation[] includeInfos= new IncludeInformation[lists.fIncludes.size()]; |
501 |
for (int i= 0; i < lists.fIncludes.size(); i++) { |
| 474 |
for (int i= 0; i < lists.fIncludes.size(); i++) { |
502 |
final IASTPreprocessorIncludeStatement include = lists.fIncludes.get(i); |
| 475 |
final IASTPreprocessorIncludeStatement include = lists.fIncludes.get(i); |
503 |
final IncludeInformation info= includeInfos[i]= new IncludeInformation(); |
| 476 |
final IncludeInformation info= includeInfos[i]= new IncludeInformation(); |
504 |
info.fStatement= include; |
| 477 |
info.fStatement= include; |
505 |
if (include.isResolved()) { |
| 478 |
if (include.isResolved()) { |
506 |
info.fLocation= fResolver.resolveASTPath(include.getPath()); |
| 479 |
info.fLocation= fResolver.resolveASTPath(include.getPath()); |
507 |
info.fIsContext= include.isActive() && |
| 480 |
info.fIsContext= include.isActive() && |
508 |
(contextIncludes.contains(include) || clearedContexts.contains(info.fLocation)); |
| 481 |
(contextIncludes.contains(include) || clearedContexts.contains(info.fLocation)); |
509 |
} |
| 482 |
} |
510 |
} |
|
|
511 |
index.setFileContent(file, linkageID, includeInfos, macros, names, fResolver, |
| 512 |
SEMI_TRANSACTIONAL_UPDATES && ALLOW_LOCK_YIELDING ? lock : null); |
| 513 |
} |
| 514 |
if (SEMI_TRANSACTIONAL_UPDATES) { |
| 515 |
file.setTimestamp(timestamp); |
| 516 |
file = index.commitUncommittedFile(); |
| 483 |
} |
517 |
} |
| 484 |
index.setFileContent(file, linkageID, includeInfos, macros, names, fResolver); |
518 |
} finally { |
|
|
519 |
index.clearUncommittedFile(); |
| 485 |
} |
520 |
} |
| 486 |
return file; |
521 |
return file; |
| 487 |
} |
522 |
} |