From 2c48014df55c0e7b7b12ebff9bef8fe567a6d4d2 Mon Sep 17 00:00:00 2001 From: Teddy Date: Tue, 13 Aug 2013 14:46:37 +0800 Subject: gc optimization: pending list --- Makefile | 2 +- gc.cpp | 18 ++++++++---------- gc.h | 1 - 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(); -- cgit v1.2.3-70-g09d2