kdevplatform/language/duchain
duchain.cpp
Go to the documentation of this file.
81 const uint minimumFinalCleanupCheckContextsPercentage = 10; //Check at least n% of all top-contexts during cleanup
96 //An entry for the item-repository that holds some meta-data. Behind this entry, the actual ParsingEnvironmentFileData is stored.
158 return sizeof(EnvironmentInformationItem) + DUChainItemSystem::self().dynamicSize(*m_file->d_func());
163 new (item) EnvironmentInformationItem(m_index, DUChainItemSystem::self().dynamicSize(*m_file->d_func()));
166 reinterpret_cast<DUChainBaseData*>(reinterpret_cast<char*>(item) + sizeof(EnvironmentInformationItem));
178 // DUChainItemSystem::self().callDestructor((DUChainBaseData*)(((char*)item) + sizeof(EnvironmentInformationItem)));
221 //We only compare the declaration. This allows us implementing a map, although the item-repository
254 EnvironmentInformationListRequest(const IndexedString& file, const EnvironmentInformationListItem& item) : m_file(
372 reinterpret_cast<StaticParsingEnvironmentData*>(new char[sizeof(StaticParsingEnvironmentData)]);
376 f.read(reinterpret_cast<char*>(ParsingEnvironmentFile::m_staticData), sizeof(StaticParsingEnvironmentData));
386 QFile f(globalItemRepositoryRegistry().path() + QLatin1String("/available_top_context_indices"));
437 qCDebug(LANGUAGE) << "removed a top-context that was reference-counted:" << context->url().str() <<
455 //DUChain is write-locked, so we can do whatever we want on the top-context, including deleting it
513 info->makeDynamic(); //By doing this, we make sure the data is actually being destroyed in the destructor
560 //First store all the possible indices into the KDevVarLengthArray, so we can unlock the mutex before processing them.
562 QMutexLocker lock(m_environmentListInfo.mutex()); //Lock the mutex to make sure the item isn't changed while it's being iterated
568 //Process the indices in a separate step after copying them from the array, so we don't need m_environmentListInfo.mutex locked,
767 Q_ASSERT(!instance->lock()->currentThreadHasReadLock() && !instance->lock()->currentThreadHasWriteLock());
770 //This is used to stop all parsing before starting to do the cleanup. This way less happens during the
771 //soft cleanups, and we have a good chance that during the "hard" cleanup only few data has to be written.
837 //Unload all top-contexts that don't have a reference-count and that are not imported by a referenced one
844 //Now unload contexts, but only ones that are not imported by any other currently loaded context
846 //the du-chain in an invalid state. Thus we can only unload contexts that are not imported by any
883 //Since we've released the write-lock in between, we've got to call store() again to be sure that none of the data is dynamic
925 //The ParsingEnvironmentFilePointer is only referenced once. This means that it does not belong to any
949 f.write(reinterpret_cast<const char*>(ParsingEnvironmentFile::m_staticData), sizeof(StaticParsingEnvironmentData));
956 QFile f(globalItemRepositoryRegistry().path() + QLatin1String("/available_top_context_indices"));
961 f.write(reinterpret_cast<const char*>(m_availableTopContextIndices.data()), m_availableTopContextIndices.size() * sizeof(uint));
973 qCDebug(LANGUAGE) << "time spent doing cleanup:" << elapsedMS << "ms - top-contexts still open:" <<
993 QHash<uint, ParsingEnvironmentFilePointer>::iterator it = m_indexEnvironmentInformations.find(topContextIndex);
1019 //Due to multi-threading, we must do this check after locking the mutex, so we can be sure we don't create the same item twice at the same time
1068 int percentageOfContexts = (visitor.checkContexts.size() * 100) / minimumFinalCleanupCheckContextsPercentage;
1075 startPos = QRandomGenerator::global()->bounded(visitor.checkContexts.size() - checkContextsCount);
1107 QExplicitlySharedDataPointer<ParsingEnvironmentFile> info(instance->environmentFileForDocument(top));
1119 const QList<QExplicitlySharedDataPointer<ParsingEnvironmentFile>> importers = info->importers();
1123 //Do breadth first search, so less imports/importers have to be loaded, and a lower depth is reached
1153 ParsingEnvironmentFilePointer>::iterator start = m_fileEnvironmentInformations.lowerBound(url);
1157 for (QMultiMap<IndexedString, ParsingEnvironmentFilePointer>::iterator it = start; it != end; ++it) {
1202 ItemRepository<EnvironmentInformationListItem, EnvironmentInformationListRequest> m_environmentListInfo;
1222 connect(ICore::self()->documentController(), &IDocumentController::documentClosed, this, &DUChain::documentClosed);
1245 QString baseDir = QProcessEnvironment::systemEnvironment().value(QStringLiteral("KDEV_DUCHAIN_DIR"), cacheDir);
1256 ItemRepositoryRegistry::initialize(repositoryPathForSession(ICore::self()->activeSessionLock()));
1369 if (ParsingEnvironmentFile* alreadyHave = sdDUChainPrivate->findInformation(file->indexedTopContext().index())) {
1428 TopDUContext* DUChain::chainForDocument(const KDevelop::IndexedString& document, bool proxyContext) const
1435 const QList<ParsingEnvironmentFilePointer> list = sdDUChainPrivate->getEnvironmentInformation(document);
1452 if (!ctx->parsingEnvironmentFile() || (ctx->parsingEnvironmentFile()->isProxyContext() == proxyContext))
1474 for (auto it = sdDUChainPrivate->m_chainsByUrl.lowerBound(document); it != sdDUChainPrivate->m_chainsByUrl.end();
1485 TopDUContext* DUChain::chainForDocument(const QUrl& document, const KDevelop::ParsingEnvironment* environment,
1491 ParsingEnvironmentFilePointer DUChain::environmentFileForDocument(const IndexedString& document,
1499 const QList<ParsingEnvironmentFilePointer> list = sdDUChainPrivate->getEnvironmentInformation(document);
1501 // qCDebug(LANGUAGE) << document.str() << ": matching" << list.size() << (onlyProxyContexts ? "proxy-contexts" : (noProxyContexts ? "content-contexts" : "contexts"));
1504 if (envFilePtr && (envFilePtr->isProxyContext() == proxyContext) && envFilePtr->matchEnvironment(environment) &&
1505 // Verify that the environment-file and its top-context are "good": The top-context must exist,
1515 QList<ParsingEnvironmentFilePointer> DUChain::allEnvironmentFiles(const IndexedString& document)
1520 ParsingEnvironmentFilePointer DUChain::environmentFileForDocument(IndexedTopDUContext topContext) const
1528 TopDUContext* DUChain::chainForDocument(const IndexedString& document, const ParsingEnvironment* environment,
1533 ParsingEnvironmentFilePointer envFile = environmentFileForDocument(document, environment, proxyContext);
1583 //Check whether the document has an attached environment-manager, and whether that one thinks the document needs to be updated.
1586 qCDebug(LANGUAGE) << "Document needs update, using best priority since it just got activated:" << doc->url();
1633 //Do instant highlighting only if all imports are loaded, to make sure that we don't block the user-interface too long
1635 //This is not exactly right, as the direct imports don't necessarily equal the real imports used by uses
1660 if (needsUpdate || !(standardContext->features() & TopDUContext::AllDeclarationsContextsAndUses)) {
1661 ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(doc->url()),
1683 ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(doc->url()),
1726 //Acquire write-lock of the repository, so when kdevelop crashes in that process, the repository is discarded
1727 //Crashes here may happen in an inconsistent state, thus this makes sense, to protect the user from more crashes
1733 sdDUChainPrivate->doMoreCleanup(); //Must be done _before_ finalCleanup, else we may be deleting yet needed data
1740 //Acquire write-lock of the repository, so when kdevelop crashes in that process, the repository is discarded
1741 //Crashes here may happen in an inconsistent state, thus this makes sense, to protect the user from more crashes
1764 static QAtomicInt& currentId(globalItemRepositoryRegistry().customCounter(QStringLiteral("Top-Context Counter"),
1786 //qCWarning(LANGUAGE) << "tried to decrease reference-count for" << top->url().str() << "but this top-context is not referenced";
1804 void DUChain::emitUpdateReady(const IndexedString& url, const ReferencedTopDUContext& topContext)
1812 KDevelop::ReferencedTopDUContext DUChain::waitForUpdate(const KDevelop::IndexedString& document,
1826 QMetaObject::invokeMethod(ICore::self()->languageController()->backgroundParser(), "parseDocuments");
1839 void DUChain::updateContextForUrl(const IndexedString& document, TopDUContext::Features minFeatures,
Allows simple indirect access to top-contexts with on-demand loading.
Definition: indexedtopducontext.h:35
void rebuildDynamicImportStructure()
Definition: topducontext.cpp:519
Customized write locker for the definition-use chain.
Definition: duchainlock.h:148
IndexedString urlForIndex(uint index) const
Returns the url for the given top-context index if available. This does have some cost,...
Definition: duchain.cpp:1399
Customized read locker for the definition-use chain.
Definition: duchainlock.h:114
int findIndex(const T &t) const
static PersistentSymbolTable & self()
Definition: persistentsymboltable.cpp:494
bool remove(const T &value)
void initInstantiationInformationRepository()
Definition: instantiationinformation.cpp:152
static DUChainLock * lock()
Retrieve the read write lock for the entire definition-use chain.
Definition: duchain.cpp:1283
int size() const
KDEVPLATFORMLANGUAGE_EXPORT KDevelop::TopDUContext * standardContextForUrl(const QUrl &url, bool preferProxyContext=false)
Asks the language-plugins for standard-contexts for the given url, and returns one if available.
Definition: duchainutils.cpp:273
static TopDUContext * load(uint topContextIndex)
Loads the top-context from disk, or returns zero on failure.
Definition: topducontextdynamicdata.cpp:594
static Utils::BasicSetRepository * repository()
Definition: topducontext.cpp:48
QList< IndexedString > indexedDocuments() const
Only used for debugging at the moment Prefer that over the QUrl version for performance reasons.
Definition: duchain.cpp:1554
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
#define DEFINE_LIST_MEMBER_HASH(container, member, type)
Definition: appendedlist.h:218
void setInDuChain(bool)
This flag is only used by DUChain, never change it from outside.
Definition: topducontext.cpp:1120
QList< TopDUContext * > allChains() const
Return a list of all chains available.
Definition: duchain.cpp:1288
KDevelop can unload unused top-context at any time.
Definition: topducontext.h:59
void updateContextForUrl(const IndexedString &document, TopDUContext::Features minFeatures, QObject *notifyReady=nullptr, int priority=1) const
Makes sure the standard-context for the given url is up-to-date.
Definition: duchain.cpp:1839
KDEVPLATFORMLANGUAGE_EXPORT TopDUContext * contentContextFromProxyContext(TopDUContext *top)
Returns the content-context associated to the given proxy-contex.
Definition: duchainutils.cpp:247
void reserve(int size)
QProcessEnvironment systemEnvironment()
void initDeclarationRepositories()
Definition: declaration.cpp:73
ReferencedTopDUContext m_topContext
Definition: waitforupdate.h:43
Global mapping of one Declaration-Ids to multiple Definitions, protected through DUChainLock.
Definition: definitions.h:40
void clearCache()
Definition: persistentsymboltable.cpp:183
T * data()
bool contains(const T &value) const
void emitUpdateReady(const KDevelop::IndexedString &url, const KDevelop::ReferencedTopDUContext &topContext)
Call this after you have modified the DUChain data associated with the file url.
Definition: duchain.cpp:1804
int size() const
bool isInMemory(uint topContextIndex) const
Returns whether the top-context with the given index is currently loaded in memory.
Definition: duchain.cpp:1394
Customized read/write locker for the definition-use chain.
Definition: duchainlock.h:53
QExplicitlySharedDataPointer< ParsingEnvironmentFile > parsingEnvironmentFile() const
Definition: topducontext.cpp:567
void reserve(int alloc)
KDevelop::ReferencedTopDUContext waitForUpdate(const KDevelop::IndexedString &document, KDevelop::TopDUContext::Features minFeatures, bool proxyContext=false)
Convenience-function similar to updateContextForUrl that blocks this thread until the update of the g...
Definition: duchain.cpp:1812
void addDocumentChain(TopDUContext *chain)
Registers a new definition-use chain for the given document.
Definition: duchain.cpp:1320
QTime currentTime()
#define ENSURE_CHAIN_READ_LOCKED
Macros for ensuring the DUChain is locked properly.
Definition: duchainlock.h:37
TopDUContext * chainForDocument(const QUrl &document, bool proxyContext=false) const
Return any chain for the given document If available, the version accepting IndexedString should be u...
Definition: duchain.cpp:1389
void start(int msec)
const IndexedIdentifier & globalIndexedImportIdentifier()
This is the identifier that can be used to search namespace-import declarations, and should be used t...
Definition: ducontext.cpp:96
static bool deleted()
Returns true if the global duchain instance has already been deleted.
Definition: duchain.cpp:1776
#define FOREACH_FUNCTION(item, container)
Foreach macro that takes a container and a function-name, and will iterate through the vector returne...
Definition: appendedlist.h:213
bool currentThreadHasReadLock()
Determines if the current thread has a read lock.
Definition: duchainlock.cpp:115
void unlock()
void copy(const DUChainBaseData &from, DUChainBaseData &to, bool constant) const
This just calls the correct constructor on the target.
Definition: duchainregister.cpp:84
const_iterator constBegin() const
const_iterator constEnd() const
bool usingImportsCache() const
Definition: topducontext.cpp:465
bool compareToDisk()
Compares the whole duchain and all its repositories in the current state to disk When the comparison ...
Definition: duchain.cpp:1874
ParsingEnvironmentFilePointer environmentFileForDocument(const IndexedString &document, const ParsingEnvironment *environment, bool proxyContext=false) const
Find the environment-file of a chain that fits into the given environment.
Definition: duchain.cpp:1491
void timeout()
static Definitions * definitions()
Returns the structure that manages mapping between definitions and declarations.
Definition: duchain.cpp:1694
Use this as base-class to define new parsing-environments.
Definition: parsingenvironment.h:79
void deleteSelf()
Called by DUChain::removeDocumentChain to destroy this top-context.
Definition: topducontext.cpp:591
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
bool currentThreadHasWriteLock() const
Determines if the current thread has a write lock.
Definition: duchainlock.cpp:201
static Uses * uses()
Returns the structure that manages mapping between declarations, and which top level contexts contain...
Definition: duchain.cpp:1689
QThread * currentThread()
static uint newTopContextIndex()
Allocates a new identity for a new top-context, no lock needed. The returned value is never zero.
Definition: duchain.cpp:1750
void usleep(unsigned long usecs)
static QString repositoryPathForSession(const KDevelop::ISessionLock::Ptr &session)
Definition: duchain.cpp:1241
static IndexedString loadUrl(uint topContextIndex)
Loads only the url out of the data stored on disk for the top-context.
Definition: topducontextdynamicdata.cpp:535
Definition: waitforupdate.h:29
QString applicationName()
bool lock()
Acquire the write lock (again). Uses the same timeout given to the constructor.
Definition: duchainlock.cpp:269
const Identifier & globalImportIdentifier()
We leak here, to prevent a possible crash during destruction, as the destructor of Identifier is not ...
Definition: ducontext.cpp:84
bool contains(const T &value) const
void emitDeclarationSelected(const KDevelop::DeclarationPointer &decl)
Emits the declarationSelected signal, so other parties can notice it.
Definition: duchain.cpp:1796
virtual qint64 size() const
void disablePersistentStorage(bool disable=true)
If you call this, the persistent disk-storage structure will stay unaffected, and no duchain cleanup ...
Definition: duchain.cpp:1859
This represents all information about a specific parsed file that is needed to match the file to a pa...
Definition: parsingenvironment.h:118
bool imports(const DUContext *origin, const CursorInRevision &position) const override
Determine if this chain imports another chain recursively.
Definition: topducontext.cpp:1030
static bool fileExists(uint topContextIndex)
Definition: topducontextdynamicdata.cpp:508
void storeToDisk()
Stores the whole duchain and all its repositories in the current state to disk The duchain must not b...
Definition: duchain.cpp:1864
qint64 read(char *data, qint64 maxSize)
uint dynamicSize(const DUChainBaseData &data) const
Calls the dynamicSize(..) member on the given data, in the most special class. Since we cannot use vi...
Definition: duchainregister.cpp:70
void updateContextEnvironment(TopDUContext *context, ParsingEnvironmentFile *file)
Changes the environment attached to the given top-level context, and updates the management-structure...
Definition: duchain.cpp:1294
TopDUContext * data() const
Returns the top-context represented by this indexed top-context.
Definition: indexedtopducontext.cpp:49
void relock()
Global mapping of Declaration-Ids to top-contexts, protected through DUChainLock.
Definition: uses.h:37
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
void removeDocumentChain(KDevelop::TopDUContext *document)
Removes the given top-context from the duchain, and deletes it.
Definition: duchain.cpp:1305
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
Definition: abstractfunctiondeclaration.cpp:27
const_iterator insert(const T &value)
int size() const
const Identifier & globalAliasIdentifier()
This is the identifier that can be used to search namespace-alias declarations.
Definition: ducontext.cpp:90
QList< ParsingEnvironmentFilePointer > allEnvironmentFiles(const IndexedString &document)
Returns the list of the environment-infos of all versions of the given document.
Definition: duchain.cpp:1515
static Utils::BasicSetRepository * repository()
Definition: persistentsymboltable.cpp:58
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QExplicitlySharedDataPointer< ParsingEnvironmentFile > ParsingEnvironmentFilePointer
Definition: duchain.h:40
int msecsTo(const QTime &t) const
const IndexedIdentifier & globalIndexedAliasIdentifier()
This is the identifier that can be used to search namespace-alias declarations.
Definition: ducontext.cpp:102
int fetchAndAddRelaxed(int valueToAdd)
bool isOnDisk() const
Whether this top-context has a stored version on disk.
Definition: topducontext.cpp:1125
IndexedTopDUContext indexed() const
Returns an indexed representation of this top-context. Indexed representations stay valid even if the...
Definition: topducontext.cpp:532
Definition: duchainbase.h:59
class TopDUContextDynamicData * m_dynamicData
Definition: topducontext.h:381
QList< TopDUContext * > chainsForDocument(const QUrl &document) const
Return all chains for the given document that are currently in memory.
Definition: duchain.cpp:1459
void setParsingEnvironmentFile(ParsingEnvironmentFile *)
Definition: topducontext.cpp:636
#define START_APPENDED_LISTS(container)
use this if the class does not have a base class that also uses appended lists
Definition: appendedlist.h:250
T value(int i) const
void initModificationRevisionSetRepository()
QString value(const QString &name, const QString &defaultValue) const
qint64 write(const char *data, qint64 maxSize)
static DUChainItemSystem & self()
Access the static DUChainItemSystem instance.
Definition: duchainregister.cpp:93
void deleteOnDisk()
Stores all remnants of this top-context that are on disk. The top-context will be fully dynamic after...
Definition: topducontextdynamicdata.cpp:634
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:37:28 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:37:28 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.