aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Core/Executor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Core/Executor.cpp')
-rw-r--r--lib/Core/Executor.cpp67
1 files changed, 34 insertions, 33 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 854754b0..33cee9f9 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -2437,6 +2437,39 @@ void Executor::bindModuleConstants() {
}
}
+void Executor::checkMemoryUsage() {
+ if (!MaxMemory)
+ return;
+ if ((stats::instructions & 0xFFFF) == 0) {
+ // We need to avoid calling GetTotalMallocUsage() often because it
+ // is O(elts on freelist). This is really bad since we start
+ // to pummel the freelist once we hit the memory cap.
+ unsigned mbs = util::GetTotalMallocUsage() >> 20;
+ if (mbs > MaxMemory) {
+ if (mbs > MaxMemory + 100) {
+ // just guess at how many to kill
+ unsigned numStates = states.size();
+ unsigned toKill = std::max(1U, numStates - numStates * MaxMemory / mbs);
+ klee_warning("killing %d states (over memory cap)", toKill);
+ std::vector<ExecutionState *> arr(states.begin(), states.end());
+ for (unsigned i = 0, N = arr.size(); N && i < toKill; ++i, --N) {
+ unsigned idx = rand() % N;
+ // Make two pulls to try and not hit a state that
+ // covered new code.
+ if (arr[idx]->coveredNew)
+ idx = rand() % N;
+
+ std::swap(arr[idx], arr[N - 1]);
+ terminateStateEarly(*arr[N - 1], "Memory limit exceeded.");
+ }
+ }
+ atMemoryLimit = true;
+ } else {
+ atMemoryLimit = false;
+ }
+ }
+}
+
void Executor::run(ExecutionState &initialState) {
bindModuleConstants();
@@ -2522,39 +2555,7 @@ void Executor::run(ExecutionState &initialState) {
executeInstruction(state, ki);
processTimers(&state, MaxInstructionTime);
- if (MaxMemory) {
- if ((stats::instructions & 0xFFFF) == 0) {
- // We need to avoid calling GetMallocUsage() often because it
- // is O(elts on freelist). This is really bad since we start
- // to pummel the freelist once we hit the memory cap.
- unsigned mbs = util::GetTotalMallocUsage() >> 20;
- if (mbs > MaxMemory) {
- if (mbs > MaxMemory + 100) {
- // just guess at how many to kill
- unsigned numStates = states.size();
- unsigned toKill = std::max(1U, numStates - numStates*MaxMemory/mbs);
-
- klee_warning("killing %d states (over memory cap)", toKill);
-
- std::vector<ExecutionState*> arr(states.begin(), states.end());
- for (unsigned i=0,N=arr.size(); N && i<toKill; ++i,--N) {
- unsigned idx = rand() % N;
-
- // Make two pulls to try and not hit a state that
- // covered new code.
- if (arr[idx]->coveredNew)
- idx = rand() % N;
-
- std::swap(arr[idx], arr[N-1]);
- terminateStateEarly(*arr[N-1], "Memory limit exceeded.");
- }
- }
- atMemoryLimit = true;
- } else {
- atMemoryLimit = false;
- }
- }
- }
+ checkMemoryUsage();
updateStates(&state);
}