aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-13 14:46:37 +0800
committerTeddy <[email protected]>2013-08-13 14:46:37 +0800
commit2c48014df55c0e7b7b12ebff9bef8fe567a6d4d2 (patch)
treeb2bcd9cd8f8b5f433e6320895fac01dc431abbb3
parentbac19b8e0e820ef748439891f6bbd46aabb4fcf7 (diff)
gc optimization: pending listgc
-rw-r--r--Makefile2
-rw-r--r--gc.cpp18
-rw-r--r--gc.h1
3 files changed, 9 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index ce8a500..37142aa 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ sonsi: main.o parser.o builtin.o model.o eval.o exc.o consts.o types.o gc.o
g++ -o sonsi $^ -pg -lgmp
.cpp.o:
- g++ $< -c -O2 -DGMP_SUPPORT -Wall
+ g++ $< -c -O2 -DGMP_SUPPORT -Wall
clean:
rm -f *.o
diff --git a/gc.cpp b/gc.cpp
index 54248c3..13dfb3c 100644
--- a/gc.cpp
+++ b/gc.cpp
@@ -13,7 +13,6 @@ GarbageCollector::GarbageCollector() {
mapping.clear();
pend_cnt = 0;
pending_list = NULL;
- collecting = false;
}
GarbageCollector::PendingEntry::PendingEntry(
@@ -28,7 +27,7 @@ void GarbageCollector::expose(EvalObj *ptr) {
fprintf(stderr, "GC: 0x%llx exposed. count = %lu \"%s\"\n",
(ull)ptr, mapping[ptr] - 1, ptr->ext_repr().c_str());
#endif
- if (!--mapping[ptr] && collecting)
+ if (!--mapping[ptr])
{
#ifdef GC_DEBUG
fprintf(stderr, "GC: 0x%llx pending. \n", (ull)ptr);
@@ -40,19 +39,19 @@ void GarbageCollector::expose(EvalObj *ptr) {
void GarbageCollector::force() {
EvalObj **l = gcq, **r = l;
-/* for (PendingEntry *p = pending_list, *np; p; p = np)
+ for (PendingEntry *p = pending_list, *np; p; p = np)
{
np = p->next;
- *r++ = p->obj;
+ if (mapping[p->obj] == 0)
+ *r++ = p->obj;
delete p;
} // fetch the pending pointers in the list
// clear the list
- pending_list = NULL; */
- for (EvalObj2Int::iterator it = mapping.begin();
+ pending_list = NULL;
+/* for (EvalObj2Int::iterator it = mapping.begin();
it != mapping.end(); it++)
- if (it->second == 0) *r++ = it->first;
+ if (it->second == 0) *r++ = it->first;*/
- collecting = true;
#ifdef GC_INFO
fprintf(stderr, "%ld\n", mapping.size());
size_t cnt = 0;
@@ -96,7 +95,6 @@ void GarbageCollector::force() {
fprintf(stderr, "%llx => %s\n", (ull)it->first, it->first->ext_repr().c_str());
*/
#endif
- collecting = false;
}
EvalObj *GarbageCollector::attach(EvalObj *ptr) {
@@ -108,7 +106,7 @@ EvalObj *GarbageCollector::attach(EvalObj *ptr) {
fprintf(stderr, "GC: 0x%llx attached. count = %lu \"%s\"\n",
(ull)ptr, mapping[ptr], ptr->ext_repr().c_str());
#endif
- if (mapping.size() > GC_QUEUE_SIZE >> 2)
+ if (mapping.size() > GC_QUEUE_SIZE >> 1)
force();
return ptr; // passing through
}
diff --git a/gc.h b/gc.h
index 8380210..e807048 100644
--- a/gc.h
+++ b/gc.h
@@ -19,7 +19,6 @@ class GarbageCollector {
EvalObj2Int mapping;
size_t pend_cnt;
PendingEntry *pending_list;
- bool collecting;
public:
GarbageCollector();