[pypy-commit] stmgc c8-card-marking: Support card marking in duhton-c8. Change the "stop" argument passed

arigo noreply at buildbot.pypy.org
Mon Mar 2 17:05:13 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: c8-card-marking
Changeset: r1687:cba4ee0e9be6
Date: 2015-03-02 16:32 +0100
http://bitbucket.org/pypy/stmgc/changeset/cba4ee0e9be6/

Log:	Support card marking in duhton-c8. Change the "stop" argument
	passed to stmcb_trace_cards() to be always within range.

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -926,17 +926,6 @@
 }
 
 
-char _stm_write_slowpath_card_extra(object_t *obj)
-{
-    /* the PyPy JIT calls this function directly if it finds that an
-       array doesn't have the GCFLAG_CARDS_SET */
-    bool mark_card = obj_should_use_cards(STM_SEGMENT->segment_base, obj);
-    write_slowpath_common(obj, mark_card);
-    return mark_card;
-    /* XXX likely, this whole function can be removed now */
-}
-
-
 void _stm_write_slowpath_card(object_t *obj, uintptr_t index)
 {
     dprintf_test(("write_slowpath_card(%p, %lu)\n",
@@ -946,7 +935,8 @@
        If the object is large enough, ask it to set up the object for
        card marking instead. */
     if (!(obj->stm_flags & GCFLAG_CARDS_SET)) {
-        char mark_card = _stm_write_slowpath_card_extra(obj);
+        bool mark_card = obj_should_use_cards(STM_SEGMENT->segment_base, obj);
+        write_slowpath_common(obj, mark_card);
         if (!mark_card)
             return;
     }
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -274,6 +274,13 @@
 
             uintptr_t start = get_card_index_to_index(card_index);
             uintptr_t stop = get_card_index_to_index(card_index + 1);
+            if (card_index == last_card_index) {
+                assert(stop >= size);
+                stop = size;
+            }
+            else {
+                assert(stop < size);
+            }
 
             dprintf(("trace_cards on %p with start:%lu stop:%lu\n",
                      obj, start, stop));
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -85,7 +85,6 @@
 
 void _stm_write_slowpath(object_t *);
 void _stm_write_slowpath_card(object_t *, uintptr_t);
-char _stm_write_slowpath_card_extra(object_t *);
 object_t *_stm_allocate_slowpath(ssize_t);
 object_t *_stm_allocate_external(ssize_t);
 void _stm_become_inevitable(const char*);
diff --git a/duhton-c8/demo/long_list.duh b/duhton-c8/demo/long_list.duh
new file mode 100644
--- /dev/null
+++ b/duhton-c8/demo/long_list.duh
@@ -0,0 +1,7 @@
+
+(setq a (list))
+
+(setq i 0)
+(while (< i 10000000)
+  (append a i)
+  (setq i (+ i 1)))
diff --git a/duhton-c8/duhton.h b/duhton-c8/duhton.h
--- a/duhton-c8/duhton.h
+++ b/duhton-c8/duhton.h
@@ -31,6 +31,8 @@
 
 
 typedef void(*trace_fn)(struct DuObject_s *, void visit(object_t **));
+typedef void(*trace_cards_fn)(struct DuObject_s *, void visit(object_t **),
+                              uintptr_t start, uintptr_t stop);
 typedef size_t(*bytesize_fn)(struct DuObject_s *);
 typedef void(*print_fn)(DuObject *);
 typedef DuObject *(*eval_fn)(DuObject *, DuObject *);
@@ -46,6 +48,9 @@
     len_fn dt_is_true;
     len_fn dt_length;
     bytesize_fn dt_bytesize;
+    uintptr_t dt_cards_offset;
+    uintptr_t dt_cards_itemsize;
+    trace_cards_fn dt_trace_cards;
 } DuType;
 
 /* keep this list in sync with object.c's Du_Types[] */
@@ -181,6 +186,7 @@
 
 #define _du_read1(p1)           stm_read((object_t *)(p1))
 #define _du_write1(p1)          stm_write((object_t *)(p1))
+#define _du_write1_card(p, i)   stm_write_card((object_t *)(p), (i))
 
 #define INIT_PREBUILT(p)       ((typeof(p))stm_setup_prebuilt((object_t *)(p)))
 
diff --git a/duhton-c8/listobject.c b/duhton-c8/listobject.c
--- a/duhton-c8/listobject.c
+++ b/duhton-c8/listobject.c
@@ -26,6 +26,15 @@
     }
 }
 
+void tuple_trace_cards(struct DuTupleObject_s *ob, void visit(object_t **),
+                       uintptr_t start, uintptr_t stop)
+{
+    int i;
+    for (i = start; i < stop; i++) {
+        visit((object_t **)&ob->ob_items[i]);
+    }
+}
+
 size_t tuple_bytesize(struct DuTupleObject_s *ob)
 {
     return sizeof(DuTupleObject) + (ob->ob_capacity - 1) * sizeof(DuObject *);
@@ -91,7 +100,7 @@
     int i, newcount = olditems->ob_count + 1;
 
     if (newcount <= olditems->ob_capacity) {
-        _du_write1(olditems);
+        _du_write1_card(olditems, newcount-1);
         olditems->ob_items[newcount-1] = x;
         olditems->ob_count = newcount;
     } else {                    /* allocate new one */
@@ -144,9 +153,9 @@
     _du_read1(ob);
     DuTupleObject *p = ob->ob_tuple;
 
-    _du_write1(p);
     if (index < 0 || index >= p->ob_count)
         Du_FatalError("list_set: index out of range");
+    _du_write1_card(p, index);
     p->ob_items[index] = newitem;
 }
 
@@ -188,6 +197,9 @@
     (len_fn)NULL,
     (len_fn)NULL,
     (bytesize_fn)tuple_bytesize,
+    offsetof(struct DuTupleObject_s, ob_items),
+    sizeof(DuObject *),
+    (trace_cards_fn)tuple_trace_cards,
 };
 
 DuType DuList_Type = {
diff --git a/duhton-c8/object.c b/duhton-c8/object.c
--- a/duhton-c8/object.c
+++ b/duhton-c8/object.c
@@ -37,16 +37,23 @@
 void stmcb_get_card_base_itemsize(struct object_s *obj,
                                   uintptr_t offset_itemsize[2])
 {
-    abort();
+    DuType *tp = Du_Types[((struct DuObject_s *)obj)->type_id];
+    offset_itemsize[0] = tp->dt_cards_offset;
+    offset_itemsize[1] = tp->dt_cards_itemsize;
 }
 void stmcb_trace_cards(struct object_s *obj, void visit(object_t **),
                        uintptr_t start, uintptr_t stop)
 {
-    abort();
+    DuType *tp = Du_Types[((struct DuObject_s *)obj)->type_id];
+    tp->dt_trace_cards((struct DuObject_s *)obj, visit, start, stop);
 }
+long stmcb_obj_supports_cards(struct object_s *obj)
+{
+    DuType *tp = Du_Types[((struct DuObject_s *)obj)->type_id];
+    return tp->dt_trace_cards != NULL;
+}
+
 void stmcb_commit_soon(void) { }
-long stmcb_obj_supports_cards(struct object_s *obj) {return 0;}
-
 
 
 DuObject *DuObject_New(DuType *tp)


More information about the pypy-commit mailing list