From 0dc0c5411fdf2fd002d070a5b4361ebf9205cb15 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 31 Jan 2012 02:14:24 +0000 Subject: Revert r149311 which failed to compile. Original log: Convert ProgramStateRef to a smart pointer for managing the reference counts of ProgramStates. This leads to a slight memory improvement, and a simplification of the logic for managing ProgramState objects. llvm-svn: 149336 --- clang/lib/StaticAnalyzer/Core/ProgramState.cpp | 38 +++++++++++--------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core/ProgramState.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index 459bf83ce5e..b8b9ad94df3 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -25,26 +25,6 @@ using namespace ento; // FIXME: Move this elsewhere. ConstraintManager::~ConstraintManager() {} -namespace clang { namespace ento { -/// Increments the number of times this state is referenced. - -void ProgramStateRetain(const ProgramState *state) { - ++const_cast(state)->refCount; -} - -/// Decrement the number of times this state is referenced. -void ProgramStateRelease(const ProgramState *state) { - assert(state->refCount > 0); - ProgramState *s = const_cast(state); - if (--s->refCount == 0) { - ProgramStateManager &Mgr = s->getStateManager(); - Mgr.StateSet.RemoveNode(s); - s->~ProgramState(); - Mgr.freeStates.push_back(s); - } -} -}} - ProgramState::ProgramState(ProgramStateManager *mgr, const Environment& env, StoreRef st, GenericDataMap gdm) : stateMgr(mgr), @@ -348,10 +328,23 @@ ProgramStateRef ProgramStateManager::getInitialState(const LocationContext *Init return getPersistentState(State); } +void ProgramStateManager::recycleUnusedStates() { + for (std::vector::iterator i = recentlyAllocatedStates.begin(), + e = recentlyAllocatedStates.end(); i != e; ++i) { + ProgramState *state = *i; + if (state->referencedByExplodedNode()) + continue; + StateSet.RemoveNode(state); + freeStates.push_back(state); + state->~ProgramState(); + } + recentlyAllocatedStates.clear(); +} + ProgramStateRef ProgramStateManager::getPersistentStateWithGDM( ProgramStateRef FromState, ProgramStateRef GDMState) { - ProgramState NewState(*FromState); + ProgramState NewState = *FromState; NewState.GDM = GDMState->GDM; return getPersistentState(NewState); } @@ -375,11 +368,12 @@ ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &State) { } new (newState) ProgramState(State); StateSet.InsertNode(newState, InsertPos); + recentlyAllocatedStates.push_back(newState); return newState; } ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const { - ProgramState NewSt(*this); + ProgramState NewSt = *this; NewSt.setStore(store); return getStateManager().getPersistentState(NewSt); } -- cgit v1.2.3