Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* core/gc.c: two bugs found in the new table code. first, hashes wer…

…en't being checked for forwarding pointers in the gc. second, the string table wasn't being updated with its new pointer. with these changes in place, my rigorous test of table allocation is passing.

 * example/gcbench-table.pn: a test of allocation a few hundred megs of tables.
  • Loading branch information...
commit c92f97281880c135ca555cee7a69942ec5b02a65 1 parent d30d68e
_why authored
Showing with 58 additions and 9 deletions.
  1. +3 −4 core/gc.c
  2. +5 −5 core/string.c
  3. +50 −0 example/gcbench-table.pn
View
7 core/gc.c
@@ -395,7 +395,7 @@ void *potion_mark_minor(Potion *P, const struct PNObject *ptr) {
GC_MINOR_UPDATE(((struct PNProto *)ptr)->asmb);
break;
case PN_TTABLE:
- GC_MINOR_UPDATE_TABLE(PN, ((struct PNTable *)ptr), 1);
+ GC_MINOR_UPDATE_TABLE(PN, (struct PNTable *)potion_fwd((PN)ptr), 1);
break;
case PN_TFLEX:
for (i = 0; i < PN_FLEX_SIZE(ptr); i++)
@@ -440,8 +440,7 @@ void *potion_mark_major(Potion *P, const struct PNObject *ptr) {
for (i = 0; i < ((struct PNClosure *)ptr)->extra; i++)
GC_MAJOR_UPDATE(((struct PNClosure *)ptr)->data[i]);
break;
- case PN_TTUPLE:
- {
+ case PN_TTUPLE: {
struct PNTuple * volatile t = (struct PNTuple *)potion_fwd((PN)ptr);
for (i = 0; i < t->len; i++)
GC_MAJOR_UPDATE(t->set[i]);
@@ -483,7 +482,7 @@ void *potion_mark_major(Potion *P, const struct PNObject *ptr) {
GC_MAJOR_UPDATE(((struct PNProto *)ptr)->asmb);
break;
case PN_TTABLE:
- GC_MAJOR_UPDATE_TABLE(PN, ((struct PNTable *)ptr), 1);
+ GC_MAJOR_UPDATE_TABLE(PN, (struct PNTable *)potion_fwd((PN)ptr), 1);
break;
case PN_TFLEX:
for (i = 0; i < PN_FLEX_SIZE(ptr); i++)
View
10 core/string.c
@@ -12,13 +12,13 @@
#include "khash.h"
#include "table.h"
-unsigned potion_add_str(Potion *P, PN self, PN s) {
+PN potion_add_str(Potion *P, PN self, PN s) {
int ret;
vPN(Table) t = (struct PNTable *)potion_fwd(self);
- unsigned k = kh_put(str, t, s, &ret);
+ kh_put(str, t, s, &ret);
PN_QUICK_FWD(struct PNTable *, t);
- PN_TOUCH(self);
- return k;
+ PN_TOUCH(t);
+ return t;
}
PN potion_lookup_str(Potion *P, PN self, const char *str) {
@@ -36,7 +36,7 @@ PN potion_str(Potion *P, const char *str) {
s->len = (unsigned int)len;
PN_MEMCPY_N(s->chars, str, char, len);
s->chars[len] = '\0';
- potion_add_str(P, P->strings, (PN)s);
+ P->strings = potion_add_str(P, P->strings, (PN)s);
val = (PN)s;
}
return val;
View
50 example/gcbench-table.pn
@@ -0,0 +1,50 @@
+tree_size = (i):
+ (1 << (i + 1)) - 1.
+
+populate_tree = (node, depth):
+ if (depth > 0):
+ depth--
+ node put("left", list(2))
+ node put("right", list(2))
+ populate_tree(node("left"), depth)
+ populate_tree(node("right"), depth).
+ .
+
+new_tree = (depth):
+ x = (left=nil, right=nil)
+ if (depth > 0):
+ x put("left", new_tree(depth - 1))
+ x put("right", new_tree(depth - 1)).
+ x.
+
+"Stretching memory with a table of depth 20\n" print
+temp = new_tree(20)
+temp = 0
+
+"Creating a long-lived table of depth 18\n" print
+longlived = new_tree(18)
+
+"Creating a long-lived array of 2000000 items\n" print
+ary = list(2000000)
+
+i = 4
+while (i <= 20):
+ iter = 2 * tree_size(20) / tree_size(i)
+ ("Creating ", iter, " tables of depth ", i, "\n") join print
+
+ j = 0
+ while (j < iter):
+ temp = (left=nil, right=nil)
+ populate_tree(temp, i)
+ temp = 0
+ j++.
+
+ j = 0
+ while (j < iter):
+ temp = new_tree(i)
+ temp = 0
+ j++.
+
+ i = i + 2.
+
+0

0 comments on commit c92f972

Please sign in to comment.
Something went wrong with that request. Please try again.