summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-02 22:58:55 +0000
committerandreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf>2014-11-02 22:58:55 +0000
commitcba02d09ec724def40975240290a30a78d33db8a (patch)
tree01d1b61e6fd7d2ce3c05be08d9c91d3f182baa26 /src
parenta0de8d148f79af1ef96626e9aa561f9360d77045 (diff)
fixed gc sweep rooting detection, added new gc unit test
git-svn-id: file:///var/local/svn/basicwriter@92 daaaf23c-2e50-4459-9457-1e69db5a47bf
Diffstat (limited to 'src')
-rw-r--r--src/core/dom/Node.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/core/dom/Node.cpp b/src/core/dom/Node.cpp
index 627ee74..ad114bf 100644
--- a/src/core/dom/Node.cpp
+++ b/src/core/dom/Node.cpp
@@ -207,16 +207,15 @@ void NodeManager::delRef(Node *tar, Node *src, bool all)
if (dTar->refInCount() == 0) {
delNode(tar, dTar);
} else if (dTar->rootRefCount == 0) {
+ // Call the tracing garbage collector if the number of marked nodes
+ // is larger than the threshold value and this function was not
+ // called from inside the delNode function
marked.insert(tar);
+ if (marked.size() >= threshold) {
+ sweep();
+ }
}
}
-
- // Call the tracing garbage collector if the number of marked nodes is
- // larger than the threshold value and this function was not called from
- // inside the delNode function
- if (deletionRecursionDepth == 0 && marked.size() >= threshold) {
- sweep();
- }
}
void NodeManager::delNode(Node *n, NodeDescriptor *descr)
@@ -236,21 +235,21 @@ void NodeManager::delNode(Node *n, NodeDescriptor *descr)
}
}
- // Perform the actual deletion if the recursion level is zero
- if (deletionRecursionDepth == 0) {
- purgeDeleted();
- }
+ purgeDeleted();
}
void NodeManager::purgeDeleted()
{
- ScopedIncrement incr{deletionRecursionDepth};
- for (Node *n : deleted) {
- marked.erase(n);
- nodes.erase(n);
- delete n;
+ // Perform the actual deletion if the recursion level is zero
+ if (deletionRecursionDepth == 0 && !deleted.empty()) {
+ ScopedIncrement incr{deletionRecursionDepth};
+ for (Node *n : deleted) {
+ marked.erase(n);
+ nodes.erase(n);
+ delete n;
+ }
+ deleted.clear();
}
- deleted.clear();
}
void NodeManager::sweep()
@@ -263,8 +262,8 @@ void NodeManager::sweep()
while (!marked.empty()) {
// Repeat until all nodes in the "marked" list have been visited
while (!marked.empty()) {
- // Increment the deletionRecursionDepth counter to prevent deletion of nodes
- // while sweep is running
+ // Increment the deletionRecursionDepth counter to prevent deletion
+ // of nodes while sweep is running
ScopedIncrement incr{deletionRecursionDepth};
// Fetch the next node in the "marked" list and remove it
Node *curNode = *(marked.begin());
@@ -286,14 +285,20 @@ void NodeManager::sweep()
continue;
}
+ // If this node is rooted, the complete visited subgraph is
+ // rooted
+ if (descr->rootRefCount > 0) {
+ isReachable = true;
+ break;
+ }
+
// Iterate over all nodes leading to the current one
for (auto &src : descr->refIn) {
Node *srcNode = src.first;
// Abort if the node is nullptr or already in the reachable
// list
- if (srcNode == nullptr ||
- reachable.find(srcNode) != reachable.end()) {
+ if (reachable.find(srcNode) != reachable.end()) {
isReachable = true;
break;
} else if (visited.find(srcNode) == visited.end()) {
@@ -316,9 +321,6 @@ void NodeManager::sweep()
}
}
- // Decrement deletionRecursionDepth
- deletionRecursionDepth--;
-
// Now purge all nodes marked for deletion
purgeDeleted();
}