cmState: Avoid accumulating snapshot storage for short-lived scopes

We need to keep only certain snapshot types and their ancestors.
Also keep those needed for backtraces.
This commit is contained in:
Brad King 2015-11-24 15:00:47 -05:00
parent f21dc4a81c
commit 5f860ebb67
3 changed files with 34 additions and 0 deletions

View File

@ -403,6 +403,10 @@ cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot,
: Context(cc) : Context(cc)
, Snapshot(snapshot) , Snapshot(snapshot)
{ {
if (this->Snapshot.IsValid())
{
this->Snapshot.Keep();
}
} }
cmListFileBacktrace::~cmListFileBacktrace() cmListFileBacktrace::~cmListFileBacktrace()

View File

@ -27,6 +27,7 @@ struct cmState::SnapshotDataType
cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot; cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope; cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
cmState::SnapshotType SnapshotType; cmState::SnapshotType SnapshotType;
bool Keep;
cmLinkedTree<std::string>::iterator ExecutionListFile; cmLinkedTree<std::string>::iterator ExecutionListFile;
cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
BuildSystemDirectory; BuildSystemDirectory;
@ -755,6 +756,7 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
pos->DirectoryParent = this->SnapshotData.Root(); pos->DirectoryParent = this->SnapshotData.Root();
pos->ScopeParent = this->SnapshotData.Root(); pos->ScopeParent = this->SnapshotData.Root();
pos->SnapshotType = BaseType; pos->SnapshotType = BaseType;
pos->Keep = true;
pos->BuildSystemDirectory = pos->BuildSystemDirectory =
this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root()); this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
pos->ExecutionListFile = pos->ExecutionListFile =
@ -787,6 +789,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
pos->DirectoryParent = originSnapshot.Position; pos->DirectoryParent = originSnapshot.Position;
pos->ScopeParent = originSnapshot.Position; pos->ScopeParent = originSnapshot.Position;
pos->SnapshotType = BuildsystemDirectoryType; pos->SnapshotType = BuildsystemDirectoryType;
pos->Keep = true;
pos->BuildSystemDirectory = pos->BuildSystemDirectory =
this->BuildsystemDirectory.Push( this->BuildsystemDirectory.Push(
originSnapshot.Position->BuildSystemDirectory); originSnapshot.Position->BuildSystemDirectory);
@ -822,6 +825,7 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine; pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand; pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = FunctionCallType; pos->SnapshotType = FunctionCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push( pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName); originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos; pos->BuildSystemDirectory->DirectoryEnd = pos;
@ -846,6 +850,7 @@ cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine; pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand; pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = MacroCallType; pos->SnapshotType = MacroCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push( pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName); originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid()); assert(originSnapshot.Position->Vars.IsValid());
@ -865,6 +870,7 @@ cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine; pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand; pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = CallStackType; pos->SnapshotType = CallStackType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push( pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName); originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid()); assert(originSnapshot.Position->Vars.IsValid());
@ -884,6 +890,7 @@ cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine; pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand; pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = VariableScopeType; pos->SnapshotType = VariableScopeType;
pos->Keep = false;
pos->PolicyScope = originSnapshot.Position->Policies; pos->PolicyScope = originSnapshot.Position->Policies;
assert(originSnapshot.Position->Vars.IsValid()); assert(originSnapshot.Position->Vars.IsValid());
@ -906,6 +913,7 @@ cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
pos->EntryPointLine = entryPointLine; pos->EntryPointLine = entryPointLine;
pos->EntryPointCommand = entryPointCommand; pos->EntryPointCommand = entryPointCommand;
pos->SnapshotType = InlineListFileType; pos->SnapshotType = InlineListFileType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push( pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName); originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos; pos->BuildSystemDirectory->DirectoryEnd = pos;
@ -919,6 +927,7 @@ cmState::CreatePolicyScopeSnapshot(cmState::Snapshot originSnapshot)
PositionType pos = this->SnapshotData.Push(originSnapshot.Position, PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
*originSnapshot.Position); *originSnapshot.Position);
pos->SnapshotType = PolicyScopeType; pos->SnapshotType = PolicyScopeType;
pos->Keep = false;
pos->BuildSystemDirectory->DirectoryEnd = pos; pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies; pos->PolicyScope = originSnapshot.Position->Policies;
return cmState::Snapshot(this, pos); return cmState::Snapshot(this, pos);
@ -937,6 +946,21 @@ cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
prevPos->BuildSystemDirectory->CompileOptions.size(); prevPos->BuildSystemDirectory->CompileOptions.size();
prevPos->BuildSystemDirectory->DirectoryEnd = prevPos; prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
if (!pos->Keep && this->SnapshotData.IsLast(pos))
{
if (pos->Vars != prevPos->Vars)
{
assert(this->VarTree.IsLast(pos->Vars));
this->VarTree.Pop(pos->Vars);
}
if (pos->ExecutionListFile != prevPos->ExecutionListFile)
{
assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
this->ExecutionListFiles.Pop(pos->ExecutionListFile);
}
this->SnapshotData.Pop(pos);
}
return Snapshot(this, prevPos); return Snapshot(this, prevPos);
} }
@ -999,6 +1023,11 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
this->ComputeRelativePathTopBinary(); this->ComputeRelativePathTopBinary();
} }
void cmState::Snapshot::Keep()
{
this->Position->Keep = true;
}
void cmState::Snapshot::SetListFile(const std::string& listfile) void cmState::Snapshot::SetListFile(const std::string& listfile)
{ {
*this->Position->ExecutionListFile = listfile; *this->Position->ExecutionListFile = listfile;

View File

@ -62,6 +62,7 @@ public:
std::vector<std::string> ClosureKeys() const; std::vector<std::string> ClosureKeys() const;
bool RaiseScope(std::string const& var, const char* varDef); bool RaiseScope(std::string const& var, const char* varDef);
void Keep();
void SetListFile(std::string const& listfile); void SetListFile(std::string const& listfile);
std::string GetExecutionListFile() const; std::string GetExecutionListFile() const;