[pypy-commit] pypy rpython-hash: Boehm: remove completely the header, can't use an empty struct because

arigo pypy.commits at gmail.com
Sat Jan 28 03:59:00 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: rpython-hash
Changeset: r89816:63f63ce03c30
Date: 2017-01-28 09:58 +0100
http://bitbucket.org/pypy/pypy/changeset/63f63ce03c30/

Log:	Boehm: remove completely the header, can't use an empty struct
	because it still takes one byte and then there are alignment issues
	for OP_LENGTH_OF_SIMPLE_GCARRAY_FROM_OPAQUE

diff --git a/rpython/memory/gctransform/boehm.py b/rpython/memory/gctransform/boehm.py
--- a/rpython/memory/gctransform/boehm.py
+++ b/rpython/memory/gctransform/boehm.py
@@ -11,7 +11,7 @@
 class BoehmGCTransformer(GCTransformer):
     malloc_zero_filled = True
     FINALIZER_PTR = lltype.Ptr(lltype.FuncType([llmemory.Address], lltype.Void))
-    HDR = lltype.Struct("header")
+    NO_HEADER = True
 
     def __init__(self, translator, inline=False):
         super(BoehmGCTransformer, self).__init__(translator, inline=inline)
@@ -29,10 +29,7 @@
         ll_malloc_varsize_no_length = mh.ll_malloc_varsize_no_length
         ll_malloc_varsize = mh.ll_malloc_varsize
 
-        HDRPTR = lltype.Ptr(self.HDR)
-
         def ll_identityhash(addr):
-            obj = llmemory.cast_adr_to_ptr(addr, HDRPTR)
             h = ~llmemory.cast_adr_to_int(addr)
             return h
 
@@ -192,10 +189,6 @@
                           resulttype = lltype.Signed)
         hop.genop('int_invert', [v_int], resultvar=hop.spaceop.result)
 
-    def gcheader_initdata(self, obj):
-        hdr = lltype.malloc(self.HDR, immortal=True)
-        return hdr._obj
-
 
 ########## weakrefs ##########
 # Boehm: weakref objects are small structures containing only a Boehm
diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -610,10 +610,6 @@
     def special_funcptr_for_type(self, TYPE):
         return self.layoutbuilder.special_funcptr_for_type(TYPE)
 
-    def gc_header_for(self, obj):
-        hdr = self.gcdata.gc.gcheaderbuilder.header_of_object(obj)
-        return hdr
-
     def get_hash_offset(self, T):
         type_id = self.get_type_id(T)
         assert not self.gcdata.q_is_varsize(type_id)
@@ -1504,7 +1500,7 @@
 
     def gcheader_initdata(self, obj):
         o = lltype.top_container(obj)
-        hdr = self.gc_header_for(o)
+        hdr = self.gcdata.gc.gcheaderbuilder.header_of_object(o)
         return hdr._obj
 
     def get_finalizer_queue_index(self, hop):
diff --git a/rpython/memory/gctransform/refcounting.py b/rpython/memory/gctransform/refcounting.py
--- a/rpython/memory/gctransform/refcounting.py
+++ b/rpython/memory/gctransform/refcounting.py
@@ -76,7 +76,6 @@
         ll_malloc_varsize = mh.ll_malloc_varsize
 
         def ll_identityhash(addr):
-            obj = llmemory.cast_adr_to_ptr(addr, HDRPTR)
             h = llmemory.cast_adr_to_int(addr)
             return h
 
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -485,7 +485,7 @@
     so-called 'identity hash', which is the non-overridable default hash
     of Python.  Can be called for any RPython-level object that turns
     into a GC object, but not NULL.  The value will be different before
-    and after translation.
+    and after translation (WARNING: this is a change with older RPythons!)
     """
     assert x is not None
     return object.__hash__(x)
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -645,7 +645,7 @@
     OP_CAST_OPAQUE_PTR = OP_CAST_POINTER
 
     def OP_LENGTH_OF_SIMPLE_GCARRAY_FROM_OPAQUE(self, op):
-        return ('%s = *(long *)(((char *)%s) + sizeof(struct pypy_header0));'
+        return ('%s = *(long *)(((char *)%s) + RPY_SIZE_OF_GCHEADER);'
                 '  /* length_of_simple_gcarray_from_opaque */'
             % (self.expr(op.result), self.expr(op.args[0])))
 
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -12,7 +12,9 @@
 from rpython.rlib.rfloat import isfinite, isinf
 
 
-def needs_gcheader(T):
+def needs_gcheader(gctransformer, T):
+    if getattr(gctransformer, 'NO_HEADER', False):   # for boehm
+        return False
     if not isinstance(T, ContainerType):
         return False
     if T._gckind != 'gc':
@@ -87,7 +89,7 @@
         STRUCT = self.STRUCT
         if self.varlength is not None:
             self.normalizedtypename = db.gettype(STRUCT, who_asks=self)
-        if needs_gcheader(self.STRUCT):
+        if needs_gcheader(db.gctransformer, self.STRUCT):
             HDR = db.gcpolicy.struct_gcheader_definition(self)
             if HDR is not None:
                 gc_field = ("_gcheader", db.gettype(HDR, who_asks=self))
@@ -213,7 +215,7 @@
         self.computegcinfo(db.gcpolicy)
         if self.varlength is not None:
             self.normalizedtypename = db.gettype(ARRAY, who_asks=self)
-        if needs_gcheader(ARRAY):
+        if needs_gcheader(db.gctransformer, ARRAY):
             HDR = db.gcpolicy.array_gcheader_definition(self)
             if HDR is not None:
                 gc_field = ("_gcheader", db.gettype(HDR, who_asks=self))
@@ -546,8 +548,8 @@
 
     def __init__(self, db, T, obj):
         ContainerNode.__init__(self, db, T, obj)
-        if needs_gcheader(T):
-            gct = self.db.gctransformer
+        gct = self.db.gctransformer
+        if needs_gcheader(gct, T):
             if gct is not None:
                 self.gc_init = gct.gcheader_initdata(self.obj)
             else:
@@ -577,7 +579,7 @@
 
         data = []
 
-        if needs_gcheader(T):
+        if needs_gcheader(self.db.gctransformer, T):
             data.append(('gcheader', self.gc_init))
 
         for name in defnode.fieldnames:
@@ -631,8 +633,8 @@
 
     def __init__(self, db, T, obj):
         ContainerNode.__init__(self, db, T, obj)
-        if needs_gcheader(T):
-            gct = self.db.gctransformer
+        gct = self.db.gctransformer
+        if needs_gcheader(gct, T):
             if gct is not None:
                 self.gc_init = gct.gcheader_initdata(self.obj)
             else:
@@ -655,7 +657,7 @@
     def initializationexpr(self, decoration=''):
         T = self.getTYPE()
         yield '{'
-        if needs_gcheader(T):
+        if needs_gcheader(self.db.gctransformer, T):
             lines = generic_initializationexpr(self.db, self.gc_init, 'gcheader',
                                                '%sgcheader' % (decoration,))
             for line in lines:
diff --git a/rpython/translator/c/src/mem.h b/rpython/translator/c/src/mem.h
--- a/rpython/translator/c/src/mem.h
+++ b/rpython/translator/c/src/mem.h
@@ -135,6 +135,12 @@
 #define OP_GC_FQ_NEXT_DEAD(tag, r)       (r = NULL)
 #endif
 
+#if defined(PYPY_USING_BOEHM_GC) || defined(PYPY_USING_NO_GC_AT_ALL)
+#  define RPY_SIZE_OF_GCHEADER  0
+#else
+#  define RPY_SIZE_OF_GCHEADER  sizeof(struct pypy_header0)
+#endif
+
 /************************************************************/
 /* weakref support */
 


More information about the pypy-commit mailing list