Permalink
Browse files

* core/gc.c: deleting strings from the table that have fallen out of…

… use.
  • Loading branch information...
1 parent 9c12bd6 commit 1d2cd4be8f617729d7fbf985b717188348eaf13f _why committed Jul 29, 2009
Showing with 38 additions and 10 deletions.
  1. +4 −6 core/gc.c
  2. +31 −0 core/gc.h
  3. +3 −4 core/string.c
View
@@ -122,6 +122,8 @@ static int potion_gc_minor(Potion *P, int sz) {
(long)((void *)M->birth_hi - (void *)M->birth_storeptr));
potion_mark_stack(P, 1);
+ GC_MINOR_STRINGS();
+
wb = (void **)M->birth_storeptr;
for (storead = wb; storead < (void **)M->birth_hi; storead++) {
PN v = (PN)*storead;
@@ -191,6 +193,8 @@ static int potion_gc_major(Potion *P, int siz) {
scanptr = potion_mark_major(P, scanptr);
scanptr = 0;
+ GC_MAJOR_STRINGS();
+
pngc_page_delete((void *)prevoldlo, (char *)prevoldhi - (char *)prevoldlo);
prevoldlo = 0;
prevoldhi = 0;
@@ -412,9 +416,6 @@ void *potion_mark_minor(Potion *P, const struct PNObject *ptr) {
GC_KEEP(ptr);
pngc_mark_array(P, (_PN *)((struct PNCont *)ptr)->stack + 3, ((struct PNCont *)ptr)->len - 3, 1);
break;
- case PN_TSTRINGS:
- GC_MINOR_UPDATE_TABLE(str, ((struct PNTable *)ptr), 0);
- break;
}
done:
@@ -505,9 +506,6 @@ void *potion_mark_major(Potion *P, const struct PNObject *ptr) {
GC_KEEP(ptr);
pngc_mark_array(P, (_PN *)((struct PNCont *)ptr)->stack + 3, ((struct PNCont *)ptr)->len - 3, 2);
break;
- case PN_TSTRINGS:
- GC_MAJOR_UPDATE_TABLE(str, ((struct PNTable *)ptr), 0);
- break;
}
done:
View
@@ -113,6 +113,37 @@
} \
} while (0)
+#define GC_MINOR_STRINGS() do { \
+ unsigned k; \
+ GC_MINOR_UPDATE(P->strings); \
+ for (k = kh_begin(P->strings); k != kh_end(P->strings); ++k) \
+ if (kh_exist(str, P->strings, k)) { \
+ PN v = kh_key(str, P->strings, k); \
+ if (IN_BIRTH_REGION(v) && !IS_GC_PROTECTED(v)) { \
+ if (((struct PNFwd *)v)->fwd == POTION_COPIED) \
+ kh_key(str, P->strings, k) = ((struct PNFwd *)v)->ptr; \
+ else \
+ kh_del(str, P->strings, k); \
+ } \
+ } \
+} while (0)
+
+#define GC_MAJOR_STRINGS() do { \
+ unsigned k; \
+ GC_MAJOR_UPDATE(P->strings); \
+ for (k = kh_begin(P->strings); k != kh_end(P->strings); ++k) \
+ if (kh_exist(str, P->strings, k)) { \
+ PN v = kh_key(str, P->strings, k); \
+ if (!IS_GC_PROTECTED(v) && \
+ (IN_BIRTH_REGION(v) || IN_OLDER_REGION(v))) { \
+ if (((struct PNFwd *)v)->fwd == POTION_COPIED) \
+ kh_key(str, P->strings, k) = ((struct PNFwd *)v)->ptr; \
+ else \
+ kh_del(str, P->strings, k); \
+ } \
+ } \
+} while (0)
+
static inline int potion_birth_suggest(int need, volatile void *oldlo, volatile void *oldhi) {
int suggest = ((char *)oldhi - (char *)oldlo) / 2;
if (need * 2 > suggest) suggest = need * 2;
View
@@ -16,7 +16,6 @@ void potion_add_str(Potion *P, PN s) {
int ret;
kh_put(str, P->strings, s, &ret);
PN_QUICK_FWD(struct PNTable *, P->strings);
- PN_TOUCH(P->strings);
}
PN potion_lookup_str(Potion *P, const char *str) {
@@ -28,7 +27,7 @@ PN potion_lookup_str(Potion *P, const char *str) {
PN potion_str(Potion *P, const char *str) {
PN val = potion_lookup_str(P, str);
- if (!val) {
+ if (val == PN_NIL) {
size_t len = strlen(str);
vPN(String) s = PN_ALLOC_N(PN_TSTRING, struct PNString, len + 1);
s->len = (PN_SIZE)len;
@@ -49,7 +48,7 @@ PN potion_str2(Potion *P, char *str, size_t len) {
s->chars[len] = '\0';
exist = potion_lookup_str(P, s->chars);
- if (!exist) {
+ if (exist == PN_NIL) {
potion_add_str(P, (PN)s);
exist = (PN)s;
}
@@ -204,7 +203,7 @@ static PN potion_bytes_length(Potion *P, PN closure, PN self) {
// TODO: ensure it's UTF-8 data
PN potion_bytes_string(Potion *P, PN closure, PN self) {
PN exist = potion_lookup_str(P, PN_STR_PTR(self = potion_fwd(self)));
- if (!exist) {
+ if (exist == PN_NIL) {
PN_SIZE len = PN_STR_LEN(self);
vPN(String) s = PN_ALLOC_N(PN_TSTRING, struct PNString, len + 1);
s->len = len;

0 comments on commit 1d2cd4b

Please sign in to comment.