[pypy-commit] pypy boehm-rawrefcount: Integration in-progress
arigo
pypy.commits at gmail.com
Wed Sep 7 05:28:31 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: boehm-rawrefcount
Changeset: r86922:a6e4b73b6de0
Date: 2016-09-07 11:27 +0200
http://bitbucket.org/pypy/pypy/changeset/a6e4b73b6de0/
Log: Integration in-progress
diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py
--- a/rpython/rlib/rawrefcount.py
+++ b/rpython/rlib/rawrefcount.py
@@ -4,10 +4,11 @@
# This is meant for pypy's cpyext module, but is a generally
# useful interface over our GC. XXX "pypy" should be removed here
#
-import sys, weakref
-from rpython.rtyper.lltypesystem import lltype, llmemory
+import sys, weakref, py
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.rtyper.extregistry import ExtRegistryEntry
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib import rgc
@@ -229,6 +230,11 @@
v_p, v_ob = hop.inputargs(*hop.args_r)
hop.exception_cannot_occur()
hop.genop(name, [_unspec_p(hop, v_p), _unspec_ob(hop, v_ob)])
+ #
+ if hop.rtyper.annotator.translator.config.translation.gc == "boehm":
+ c_func = hop.inputconst(lltype.typeOf(func_boehm_eci),
+ func_boehm_eci)
+ hop.genop('direct_call', [c_func])
class Entry(ExtRegistryEntry):
@@ -281,3 +287,10 @@
v_ob = hop.genop('gc_rawrefcount_next_dead', [],
resulttype = llmemory.Address)
return _spec_ob(hop, v_ob)
+
+src_dir = py.path.local(__file__).dirpath() / 'src'
+boehm_eci = ExternalCompilationInfo(
+ post_include_bits = [(src_dir / 'boehm-rawrefcount.h').read()],
+ separate_module_files = [(src_dir / 'boehm-rawrefcount.c')],
+)
+func_boehm_eci = rffi.llexternal_use_eci(boehm_eci)
diff --git a/rpython/rlib/src/boehm-rawrefcount.c b/rpython/rlib/src/boehm-rawrefcount.c
--- a/rpython/rlib/src/boehm-rawrefcount.c
+++ b/rpython/rlib/src/boehm-rawrefcount.c
@@ -6,6 +6,12 @@
#include <gc/gc.h>
#include <gc/gc_mark.h>
+#ifdef TEST_BOEHM_RAWREFCOUNT
+# define RPY_EXTERN /* nothing */
+#else
+# include "common_header.h"
+#endif
+
#define REFCNT_FROM_PYPY (LONG_MAX / 4 + 1)
@@ -172,7 +178,9 @@
bucket chain, but it should be small with very high
probability */
pyobj_t *result = p->pyobj;
+#ifdef TEST_BOEHM_RAWREFCOUNT
printf("next_dead: %p\n", result);
+#endif
assert(result->ob_refcnt == REFCNT_FROM_PYPY);
p->pyobj = NULL;
*pp = p->next_in_bucket;
@@ -238,7 +246,9 @@
assert(p != NULL);
assert(p->ob_refcnt >= REFCNT_FROM_PYPY);
+#ifdef TEST_BOEHM_RAWREFCOUNT
printf("plist[%d].gcenc: %p ", (int)i, plist[i].gcenc);
+#endif
if ((plist[i].gcenc & 1) ^ (p->ob_refcnt == REFCNT_FROM_PYPY)) {
/* ob_refcnt > FROM_PYPY: non-zero regular refcnt,
@@ -249,8 +259,10 @@
*/
plist[i].gcenc = ~plist[i].gcenc;
}
+#ifdef TEST_BOEHM_RAWREFCOUNT
printf("-> %p\n", plist[i].gcenc);
- }
+#endif
+ }
plist = plist[0].next_in_bucket;
}
if (hash_mask_bucket > 0)
diff --git a/rpython/rlib/src/boehm-rawrefcount.h b/rpython/rlib/src/boehm-rawrefcount.h
--- a/rpython/rlib/src/boehm-rawrefcount.h
+++ b/rpython/rlib/src/boehm-rawrefcount.h
@@ -1,6 +1,8 @@
-#include "common_header.h"
-#define OP_GC_RAWREFCOUNT_INIT(callback, r) /* nothing */
+/* Missing:
+ OP_GC_RAWREFCOUNT_INIT(callback, r): the callback is not supported here
+ OP_GC_RAWREFCOUNT_CREATE_LINK_PYOBJ(): not implemented, maybe not needed
+*/
#define OP_GC_RAWREFCOUNT_CREATE_LINK_PYPY(gcobj, pyobj, r) \
gc_rawrefcount_create_link_pypy(gcobj, pyobj)
@@ -12,7 +14,7 @@
r = gc_rawrefcount_to_obj(pyobj)
#define OP_GC_RAWREFCOUNT_NEXT_DEAD(r) \
- r = gc_rawrefcount_next()
+ r = gc_rawrefcount_next_dead()
RPY_EXTERN void gc_rawrefcount_create_link_pypy(/*gcobj_t*/void *gcobj,
diff --git a/rpython/rlib/test/test_rawrefcount.py b/rpython/rlib/test/test_rawrefcount.py
--- a/rpython/rlib/test/test_rawrefcount.py
+++ b/rpython/rlib/test/test_rawrefcount.py
@@ -214,6 +214,7 @@
class TestTranslated(StandaloneTests):
+ _GC = 'incminimark'
def test_full_translation(self):
class State:
@@ -226,29 +227,37 @@
def make_p():
p = W_Root(42)
ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
+ ob.c_ob_refcnt += REFCNT_FROM_PYPY
rawrefcount.create_link_pypy(p, ob)
- ob.c_ob_refcnt += REFCNT_FROM_PYPY
assert rawrefcount.from_obj(PyObject, p) == ob
assert rawrefcount.to_obj(W_Root, ob) == p
return ob, p
FTYPE = rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER
+ has_callback = (self._GC != "boehm")
def entry_point(argv):
- ll_dealloc_trigger_callback = llhelper(FTYPE, dealloc_trigger)
- rawrefcount.init(ll_dealloc_trigger_callback)
+ if has_callback:
+ ll_dealloc_trigger_callback = llhelper(FTYPE, dealloc_trigger)
+ rawrefcount.init(ll_dealloc_trigger_callback)
ob, p = make_p()
if state.seen != []:
print "OB COLLECTED REALLY TOO SOON"
return 1
+ if rawrefcount.next_dead(PyObject) != lltype.nullptr(PyObjectS):
+ print "got a next_dead() really too soon"
+ return 1
rgc.collect()
if state.seen != []:
print "OB COLLECTED TOO SOON"
return 1
+ if rawrefcount.next_dead(PyObject) != lltype.nullptr(PyObjectS):
+ print "got a next_dead() too soon"
+ return 1
objectmodel.keepalive_until_here(p)
p = None
rgc.collect()
- if state.seen != [1]:
+ if has_callback and state.seen != [1]:
print "OB NOT COLLECTED"
return 1
if rawrefcount.next_dead(PyObject) != ob:
@@ -262,7 +271,11 @@
return 0
self.config = get_combined_translation_config(translating=True)
- self.config.translation.gc = "incminimark"
+ self.config.translation.gc = self._GC
t, cbuilder = self.compile(entry_point)
data = cbuilder.cmdexec('hi there')
assert data.startswith('OK!\n')
+
+
+class TestBoehm(TestTranslated):
+ _GC = "boehm"
diff --git a/rpython/rlib/test/test_rawrefcount_boehm.py b/rpython/rlib/test/test_rawrefcount_boehm.py
--- a/rpython/rlib/test/test_rawrefcount_boehm.py
+++ b/rpython/rlib/test/test_rawrefcount_boehm.py
@@ -4,7 +4,7 @@
TEST_CODE = r"""
-#define RPY_EXTERN /* nothing */
+#define TEST_BOEHM_RAWREFCOUNT
#include "boehm-rawrefcount.c"
static gcobj_t *alloc_gcobj(void) /* for tests */
More information about the pypy-commit
mailing list