[pypy-svn] r68255 - pypy/branch/gc-compress/pypy/rpython/memory/gc

arigo at codespeak.net arigo at codespeak.net
Thu Oct 8 19:03:09 CEST 2009


Author: arigo
Date: Thu Oct  8 19:03:09 2009
New Revision: 68255

Modified:
   pypy/branch/gc-compress/pypy/rpython/memory/gc/generation.py
   pypy/branch/gc-compress/pypy/rpython/memory/gc/hybrid.py
   pypy/branch/gc-compress/pypy/rpython/memory/gc/marksweep.py
Log:
Fix these three GCs.


Modified: pypy/branch/gc-compress/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/memory/gc/generation.py	Thu Oct  8 19:03:09 2009
@@ -244,7 +244,7 @@
         newobj = SemiSpaceGC.make_a_copy(self, obj, objsize)
         # During a full collect, all copied objects might implicitly come
         # from the nursery.  In case they do, we must add this flag:
-        self.header(newobj).tid |= GCFLAG_NO_YOUNG_PTRS
+        self.header(newobj).addflag(GCFLAG_NO_YOUNG_PTRS)
         return newobj
         # history: this was missing and caused an object to become old but without the
         # flag set.  Such an object is bogus in the sense that the write_barrier doesn't
@@ -263,7 +263,7 @@
         while oldlist.non_empty():
             obj = oldlist.pop()
             hdr = self.header(obj)
-            hdr.tid |= GCFLAG_NO_YOUNG_PTRS
+            hdr.addflag(GCFLAG_NO_YOUNG_PTRS)
 
     def weakrefs_grow_older(self):
         while self.young_objects_with_weakrefs.non_empty():
@@ -293,7 +293,7 @@
         self.last_generation_root_objects = self.AddressStack()
         while stack.non_empty():
             obj = stack.pop()
-            self.header(obj).tid |= GCFLAG_NO_HEAP_PTRS
+            self.header(obj).addflag(GCFLAG_NO_HEAP_PTRS)
             # ^^^ the flag we just added will be removed immediately if
             # the object still contains pointers to younger objects
             self.trace(obj, self._trace_external_obj, obj)
@@ -360,7 +360,7 @@
             count += 1
             obj = oldlist.pop()
             hdr = self.header(obj)
-            hdr.tid |= GCFLAG_NO_YOUNG_PTRS
+            hdr.addflag(GCFLAG_NO_YOUNG_PTRS)
             self.trace_and_drag_out_of_nursery(obj)
         if self.config.gcconfig.debugprint:
             llop.debug_print(lltype.Void, "collect_oldrefs_to_nursery", count)
@@ -423,10 +423,10 @@
     # for the JIT: a minimal description of the write_barrier() method
     # (the JIT assumes it is of the shape
     #  "if newvalue.int0 & JIT_WB_IF_FLAG: remember_young_pointer()")
-    JIT_WB_IF_FLAG = GCFLAG_NO_YOUNG_PTRS
+    JIT_WB_IF_FLAG = "XXXX"  # GCFLAG_NO_YOUNG_PTRS
 
     def write_barrier(self, newvalue, addr_struct):
-        if self.header(addr_struct).tid & GCFLAG_NO_YOUNG_PTRS:
+        if self.header(addr_struct).getflags() & GCFLAG_NO_YOUNG_PTRS:
             self.remember_young_pointer(addr_struct, newvalue)
 
     def _setup_wb(self):
@@ -444,7 +444,7 @@
                          "nursery object with GCFLAG_NO_YOUNG_PTRS")
             if self.is_in_nursery(addr):
                 self.old_objects_pointing_to_young.append(addr_struct)
-                self.header(addr_struct).tid &= ~GCFLAG_NO_YOUNG_PTRS
+                self.header(addr_struct).delflag(GCFLAG_NO_YOUNG_PTRS)
             elif addr == NULL:
                 return
             self.write_into_last_generation_obj(addr_struct, addr)
@@ -453,23 +453,25 @@
 
     def assume_young_pointers(self, addr_struct):
         objhdr = self.header(addr_struct)
-        if objhdr.tid & GCFLAG_NO_YOUNG_PTRS:
+        flags = objhdr.getflags()
+        if flags & GCFLAG_NO_YOUNG_PTRS:
             self.old_objects_pointing_to_young.append(addr_struct)
-            objhdr.tid &= ~GCFLAG_NO_YOUNG_PTRS
-        if objhdr.tid & GCFLAG_NO_HEAP_PTRS:
-            objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
+            objhdr.delflag(GCFLAG_NO_YOUNG_PTRS)
+        if flags & GCFLAG_NO_HEAP_PTRS:
+            objhdr.delflag(GCFLAG_NO_HEAP_PTRS)
             self.last_generation_root_objects.append(addr_struct)
 
     def write_into_last_generation_obj(self, addr_struct, addr):
         objhdr = self.header(addr_struct)
-        if objhdr.tid & GCFLAG_NO_HEAP_PTRS:
+        flags = objhdr.getflags()
+        if flags & GCFLAG_NO_HEAP_PTRS:
             if not self.is_last_generation(addr):
-                objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
+                objhdr.delflag(GCFLAG_NO_HEAP_PTRS)
                 self.last_generation_root_objects.append(addr_struct)
 
     def is_last_generation(self, obj):
         # overridden by HybridGC
-        return (self.header(obj).tid & GCFLAG_EXTERNAL) != 0
+        return (self.header(obj).getflags() & GCFLAG_EXTERNAL) != 0
 
     def _compute_id(self, obj):
         if self.is_in_nursery(obj):
@@ -500,15 +502,15 @@
         """Check the invariants about 'obj' that should be true
         between collections."""
         SemiSpaceGC.debug_check_object(self, obj)
-        tid = self.header(obj).tid
-        if tid & GCFLAG_NO_YOUNG_PTRS:
+        flags = self.header(obj).getflags()
+        if flags & GCFLAG_NO_YOUNG_PTRS:
             ll_assert(not self.is_in_nursery(obj),
                       "nursery object with GCFLAG_NO_YOUNG_PTRS")
             self.trace(obj, self._debug_no_nursery_pointer, None)
         elif not self.is_in_nursery(obj):
             ll_assert(self._d_oopty.contains(obj),
                       "missing from old_objects_pointing_to_young")
-        if tid & GCFLAG_NO_HEAP_PTRS:
+        if flags & GCFLAG_NO_HEAP_PTRS:
             ll_assert(self.is_last_generation(obj),
                       "GCFLAG_NO_HEAP_PTRS on non-3rd-generation object")
             self.trace(obj, self._debug_no_gen1or2_pointer, None)
@@ -537,10 +539,10 @@
                 self._debug_check_flag_2, None)
 
     def _debug_check_flag_1(self, obj, ignored):
-        ll_assert(not (self.header(obj).tid & GCFLAG_NO_YOUNG_PTRS),
+        ll_assert(not (self.header(obj).getflags() & GCFLAG_NO_YOUNG_PTRS),
                   "unexpected GCFLAG_NO_YOUNG_PTRS")
     def _debug_check_flag_2(self, obj, ignored):
-        ll_assert(not (self.header(obj).tid & GCFLAG_NO_HEAP_PTRS),
+        ll_assert(not (self.header(obj).getflags() & GCFLAG_NO_HEAP_PTRS),
                   "unexpected GCFLAG_NO_HEAP_PTRS")
 
     def debug_check_can_copy(self, obj):

Modified: pypy/branch/gc-compress/pypy/rpython/memory/gc/hybrid.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/memory/gc/hybrid.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/memory/gc/hybrid.py	Thu Oct  8 19:03:09 2009
@@ -34,10 +34,10 @@
 #   * last_generation_root_objects: gen3 objs that point to gen1or2 objs
 #
 # How to tell the objects apart:
-#   * external:      tid & GCFLAG_EXTERNAL
+#   * external:      flags & GCFLAG_EXTERNAL
 #   * gen1:          is_in_nursery(obj)
-#   * gen3:          (tid & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
-#                           (GCFLAG_EXTERNAL|GCFLAG_AGE_MAX)
+#   * gen3:          (flags & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
+#                             (GCFLAG_EXTERNAL|GCFLAG_AGE_MAX)
 #
 # Some invariants:
 #   * gen3 are either GCFLAG_NO_HEAP_PTRS or in 'last_generation_root_objects'
@@ -222,7 +222,6 @@
     def realloc(self, ptr, newlength, fixedsize, itemsize, lengthofs, grow):
         size_gc_header = self.size_gc_header()
         addr = llmemory.cast_ptr_to_adr(ptr)
-        tid = self.get_type_id(addr)
         nonvarsize = size_gc_header + fixedsize
         try:
             varsize = ovfcheck(itemsize * newlength)
@@ -253,8 +252,7 @@
         return llmemory.cast_adr_to_ptr(result + size_gc_header, llmemory.GCREF)
 
     def can_move(self, addr):
-        tid = self.header(addr).tid
-        return not (tid & GCFLAG_EXTERNAL)
+        return not (self.header(addr).getflags() & GCFLAG_EXTERNAL)
 
     def malloc_varsize_collecting_nursery(self, totalsize):
         result = self.collect_nursery()
@@ -343,9 +341,9 @@
             self._nonmoving_copy_size = 0
 
     def _set_gcflag_unvisited(self, obj, ignored):
-        ll_assert(not (self.header(obj).tid & GCFLAG_UNVISITED),
+        ll_assert(not (self.header(obj).getflags() & GCFLAG_UNVISITED),
                   "bogus GCFLAG_UNVISITED on gen3 obj")
-        self.header(obj).tid |= GCFLAG_UNVISITED
+        self.header(obj).addflag(GCFLAG_UNVISITED)
 
     def collect_roots(self):
         if not self.is_collecting_gen3():
@@ -364,18 +362,20 @@
         # ones with GCFLAG_FORWARDED set and GCFLAG_UNVISITED not set.
         # This is equivalent to self.is_forwarded() for all objects except
         # the ones obtained by raw_malloc.
-        flags = self.header(obj).tid & (GCFLAG_FORWARDED|GCFLAG_UNVISITED)
-        return flags == GCFLAG_FORWARDED
+        flags = self.header(obj).getflags()
+        return ((flags & (GCFLAG_FORWARDED|GCFLAG_UNVISITED)) ==
+                GCFLAG_FORWARDED)
 
     def is_last_generation(self, obj):
-        return ((self.header(obj).tid & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
+        flags = self.header(obj).getflags()
+        return ((flags & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
                 (GCFLAG_EXTERNAL|GCFLAG_AGE_MAX))
 
     def visit_external_object(self, obj):
         hdr = self.header(obj)
-        if hdr.tid & GCFLAG_UNVISITED:
+        if hdr.getflags() & GCFLAG_UNVISITED:
             # This is a not-visited-yet raw_malloced object.
-            hdr.tid -= GCFLAG_UNVISITED
+            hdr.delflag(GCFLAG_UNVISITED)
             self.rawmalloced_objects_to_trace.append(obj)
 
     def make_a_copy(self, obj, objsize):
@@ -384,26 +384,26 @@
         # If they don't, we count how many times they are copied and when
         # some threshold is reached we make the copy a non-movable "external"
         # object.  The threshold is MAX_SEMISPACE_AGE.
-        tid = self.header(obj).tid
+        flags = self.header(obj).getflags()
         # XXX the following logic is not doing exactly what is explained
         # above: any object without GCFLAG_NO_YOUNG_PTRS has its age not
         # incremented.  This is accidental: it means that objects that
         # are very often modified to point to young objects don't reach
         # the 3rd generation.  For now I'll leave it this way because
         # I'm not sure that it's a bad thing.
-        if not (tid & GCFLAG_NO_YOUNG_PTRS):
-            tid |= GCFLAG_NO_YOUNG_PTRS    # object comes from the nursery
-        elif (tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX:
-            tid += GCFLAG_AGE_ONE
+        if not (flags & GCFLAG_NO_YOUNG_PTRS):
+            flags |= GCFLAG_NO_YOUNG_PTRS    # object comes from the nursery
+        elif (flags & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX:
+            flags += GCFLAG_AGE_ONE
         else:
             newobj = self.make_a_nonmoving_copy(obj, objsize)
             if newobj:
                 return newobj
-            tid &= ~GCFLAG_AGE_MASK
+            flags &= ~GCFLAG_AGE_MASK
         # skip GenerationGC.make_a_copy() as we already did the right
         # thing about GCFLAG_NO_YOUNG_PTRS
         newobj = SemiSpaceGC.make_a_copy(self, obj, objsize)
-        self.header(newobj).tid = tid
+        self.header(newobj).setflags(flags)
         return newobj
 
     def make_a_nonmoving_copy(self, obj, objsize):
@@ -420,7 +420,7 @@
         llmemory.raw_memcopy(obj - self.size_gc_header(), newaddr, totalsize)
         newobj = newaddr + self.size_gc_header()
         hdr = self.header(newobj)
-        hdr.tid |= self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS
+        hdr.addflag(self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS)
         # GCFLAG_UNVISITED is not set
         # GCFLAG_NO_HEAP_PTRS is not set either, conservatively.  It may be
         # set by the next collection's collect_last_generation_roots().
@@ -485,7 +485,7 @@
             newgen3roots = self.AddressStack()
             while gen3roots.non_empty():
                 obj = gen3roots.pop()
-                if not (self.header(obj).tid & GCFLAG_UNVISITED):
+                if not (self.header(obj).getflags() & GCFLAG_UNVISITED):
                     newgen3roots.append(obj)
             gen3roots.delete()
             self.last_generation_root_objects = newgen3roots
@@ -500,8 +500,8 @@
         alive_count = alive_size = dead_count = dead_size = 0
         while objects.non_empty():
             obj = objects.pop()
-            tid = self.header(obj).tid
-            if tid & GCFLAG_UNVISITED:
+            flags = self.header(obj).getflags()
+            if flags & GCFLAG_UNVISITED:
                 if self.config.gcconfig.debugprint:
                     dead_count+=1
                     dead_size+=raw_malloc_usage(self.get_size(obj))
@@ -514,24 +514,24 @@
                 if generation == 3:
                     surviving_objects.append(obj)
                 elif generation == 2:
-                    ll_assert((tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
+                    ll_assert((flags & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
                               "wrong age for generation 2 object")
-                    tid += GCFLAG_AGE_ONE
-                    if (tid & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX:
+                    flags += GCFLAG_AGE_ONE
+                    if (flags & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX:
                         # the object becomes part of generation 3
                         self.gen3_rawmalloced_objects.append(obj)
                         # GCFLAG_NO_HEAP_PTRS not set yet, conservatively
                         self.last_generation_root_objects.append(obj)
                     else:
                         # the object stays in generation 2
-                        tid |= GCFLAG_UNVISITED
+                        flags |= GCFLAG_UNVISITED
                         surviving_objects.append(obj)
-                    self.header(obj).tid = tid
+                    self.header(obj).setflags(flags)
                 elif generation == -2:
                     # the object stays in generation -2
-                    tid |= GCFLAG_UNVISITED
+                    flags |= GCFLAG_UNVISITED
                     surviving_objects.append(obj)
-                    self.header(obj).tid = tid
+                    self.header(obj).setflags(flags)
         objects.delete()
         if generation == 2:
             self.gen2_rawmalloced_objects = surviving_objects
@@ -575,8 +575,8 @@
         """Check the invariants about 'obj' that should be true
         between collections."""
         GenerationGC.debug_check_object(self, obj)
-        tid = self.header(obj).tid
-        if tid & GCFLAG_UNVISITED:
+        flags = self.header(obj).getflags()
+        if flags & GCFLAG_UNVISITED:
             ll_assert(self._d_gen2ro.contains(obj),
                       "GCFLAG_UNVISITED on non-gen2 object")
 
@@ -589,20 +589,20 @@
             self.gen3_rawmalloced_objects.foreach(self._debug_check_gen3, None)
 
     def _debug_check_gen2(self, obj, ignored):
-        tid = self.header(obj).tid
-        ll_assert(bool(tid & GCFLAG_EXTERNAL),
+        flags = self.header(obj).getflags()
+        ll_assert(bool(flags & GCFLAG_EXTERNAL),
                   "gen2: missing GCFLAG_EXTERNAL")
-        ll_assert(bool(tid & GCFLAG_UNVISITED),
+        ll_assert(bool(flags & GCFLAG_UNVISITED),
                   "gen2: missing GCFLAG_UNVISITED")
-        ll_assert((tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
+        ll_assert((flags & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
                   "gen2: age field too large")
     def _debug_check_gen3(self, obj, ignored):
-        tid = self.header(obj).tid
-        ll_assert(bool(tid & GCFLAG_EXTERNAL),
+        flags = self.header(obj).getflags()
+        ll_assert(bool(flags & GCFLAG_EXTERNAL),
                   "gen3: missing GCFLAG_EXTERNAL")
-        ll_assert(not (tid & GCFLAG_UNVISITED),
+        ll_assert(not (flags & GCFLAG_UNVISITED),
                   "gen3: unexpected GCFLAG_UNVISITED")
-        ll_assert((tid & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX,
+        ll_assert((flags & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX,
                   "gen3: wrong age field")
 
     def can_malloc_nonmovable(self):

Modified: pypy/branch/gc-compress/pypy/rpython/memory/gc/marksweep.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/memory/gc/marksweep.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/memory/gc/marksweep.py	Thu Oct  8 19:03:09 2009
@@ -4,7 +4,7 @@
 from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE
 from pypy.rpython.memory.support import get_address_stack
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rlib.objectmodel import free_non_gc_object
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.rarithmetic import ovfcheck
@@ -25,7 +25,9 @@
     HDRPTR = lltype.Ptr(HDR)
     # need to maintain a linked list of malloced objects, since we used the
     # systems allocator and can't walk the heap
-    HDR.become(lltype.Struct('header', ('typeid', lltype.Signed),
+    HDR.become(lltype.Struct('header', ('typeid16', rffi.USHORT),
+                                       ('mark', lltype.Bool),
+                                       ('curpool_flag', lltype.Bool),
                                        ('next', HDRPTR)))
 
     POOL = lltype.GcStruct('gc_pool')
@@ -75,14 +77,14 @@
         if self.bytes_malloced > self.bytes_malloced_threshold:
             self.collect()
 
-    def write_malloc_statistics(self, typeid, size, result, varsize):
+    def write_malloc_statistics(self, typeid16, size, result, varsize):
         pass
 
-    def write_free_statistics(self, typeid, result):
+    def write_free_statistics(self, typeid16, result):
         pass
 
-    def malloc_fixedsize(self, typeid, size, can_collect, has_finalizer=False,
-                         contains_weakptr=False):
+    def malloc_fixedsize(self, typeid16, size, can_collect,
+                         has_finalizer=False, contains_weakptr=False):
         if can_collect:
             self.maybe_collect()
         size_gc_header = self.gcheaderbuilder.size_gc_header
@@ -97,7 +99,9 @@
         if not result:
             raise memoryError
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
-        hdr.typeid = typeid << 1
+        hdr.typeid16 = typeid16
+        hdr.mark = False
+        hdr.curpool_flag = False
         if has_finalizer:
             hdr.next = self.malloced_objects_with_finalizer
             self.malloced_objects_with_finalizer = hdr
@@ -109,13 +113,13 @@
             self.malloced_objects = hdr
         self.bytes_malloced = bytes_malloced
         result += size_gc_header
-        #llop.debug_print(lltype.Void, 'malloc typeid', typeid,
+        #llop.debug_print(lltype.Void, 'malloc typeid', typeid16,
         #                 '->', llmemory.cast_adr_to_int(result))
-        self.write_malloc_statistics(typeid, tot_size, result, False)
+        self.write_malloc_statistics(typeid16, tot_size, result, False)
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
     malloc_fixedsize._dont_inline_ = True
 
-    def malloc_fixedsize_clear(self, typeid, size, can_collect,
+    def malloc_fixedsize_clear(self, typeid16, size, can_collect,
                                has_finalizer=False, contains_weakptr=False):
         if can_collect:
             self.maybe_collect()
@@ -132,7 +136,9 @@
             raise memoryError
         raw_memclear(result, tot_size)
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
-        hdr.typeid = typeid << 1
+        hdr.typeid16 = typeid16
+        hdr.mark = False
+        hdr.curpool_flag = False
         if has_finalizer:
             hdr.next = self.malloced_objects_with_finalizer
             self.malloced_objects_with_finalizer = hdr
@@ -144,14 +150,14 @@
             self.malloced_objects = hdr
         self.bytes_malloced = bytes_malloced
         result += size_gc_header
-        #llop.debug_print(lltype.Void, 'malloc typeid', typeid,
+        #llop.debug_print(lltype.Void, 'malloc typeid', typeid16,
         #                 '->', llmemory.cast_adr_to_int(result))
-        self.write_malloc_statistics(typeid, tot_size, result, False)
+        self.write_malloc_statistics(typeid16, tot_size, result, False)
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
     malloc_fixedsize_clear._dont_inline_ = True
 
-    def malloc_varsize(self, typeid, length, size, itemsize, offset_to_length,
-                       can_collect):
+    def malloc_varsize(self, typeid16, length, size, itemsize,
+                       offset_to_length, can_collect):
         if can_collect:
             self.maybe_collect()
         size_gc_header = self.gcheaderbuilder.size_gc_header
@@ -169,20 +175,22 @@
             raise memoryError
         (result + size_gc_header + offset_to_length).signed[0] = length
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
-        hdr.typeid = typeid << 1
+        hdr.typeid16 = typeid16
+        hdr.mark = False
+        hdr.curpool_flag = False
         hdr.next = self.malloced_objects
         self.malloced_objects = hdr
         self.bytes_malloced = bytes_malloced
             
         result += size_gc_header
         #llop.debug_print(lltype.Void, 'malloc_varsize length', length,
-        #                 'typeid', typeid,
+        #                 'typeid', typeid16,
         #                 '->', llmemory.cast_adr_to_int(result))
-        self.write_malloc_statistics(typeid, tot_size, result, True)
+        self.write_malloc_statistics(typeid16, tot_size, result, True)
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
     malloc_varsize._dont_inline_ = True
 
-    def malloc_varsize_clear(self, typeid, length, size, itemsize,
+    def malloc_varsize_clear(self, typeid16, length, size, itemsize,
                              offset_to_length, can_collect):
         if can_collect:
             self.maybe_collect()
@@ -202,16 +210,18 @@
         raw_memclear(result, tot_size)        
         (result + size_gc_header + offset_to_length).signed[0] = length
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
-        hdr.typeid = typeid << 1
+        hdr.typeid16 = typeid16
+        hdr.mark = False
+        hdr.curpool_flag = False
         hdr.next = self.malloced_objects
         self.malloced_objects = hdr
         self.bytes_malloced = bytes_malloced
             
         result += size_gc_header
         #llop.debug_print(lltype.Void, 'malloc_varsize length', length,
-        #                 'typeid', typeid,
+        #                 'typeid', typeid16,
         #                 '->', llmemory.cast_adr_to_int(result))
-        self.write_malloc_statistics(typeid, tot_size, result, True)
+        self.write_malloc_statistics(typeid16, tot_size, result, True)
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
     malloc_varsize_clear._dont_inline_ = True
 
@@ -251,10 +261,10 @@
         hdr = self.malloced_objects_with_finalizer
         while hdr:
             next = hdr.next
-            typeid = hdr.typeid >> 1
+            typeid = hdr.typeid16
             gc_info = llmemory.cast_ptr_to_adr(hdr)
             obj = gc_info + size_gc_header
-            if not hdr.typeid & 1:
+            if not hdr.mark:
                 self.add_reachable_to_stack(obj, objects)
             addr = llmemory.cast_ptr_to_adr(hdr)
             size = self.fixed_size(typeid)
@@ -271,31 +281,30 @@
             curr = objects.pop()
             gc_info = curr - size_gc_header
             hdr = llmemory.cast_adr_to_ptr(gc_info, self.HDRPTR)
-            if hdr.typeid & 1:
+            if hdr.mark:
                 continue
             self.add_reachable_to_stack(curr, objects)
-            hdr.typeid = hdr.typeid | 1
+            hdr.mark = True
         objects.delete()
         # also mark self.curpool
         if self.curpool:
             gc_info = llmemory.cast_ptr_to_adr(self.curpool) - size_gc_header
             hdr = llmemory.cast_adr_to_ptr(gc_info, self.HDRPTR)
-            hdr.typeid = hdr.typeid | 1
+            hdr.mark = True
         # go through the list of objects containing weak pointers
         # and kill the links if they go to dead objects
         # if the object itself is not marked, free it
         hdr = self.objects_with_weak_pointers
         surviving = lltype.nullptr(self.HDR)
         while hdr:
-            typeid = hdr.typeid >> 1
+            typeid = hdr.typeid16
             next = hdr.next
             addr = llmemory.cast_ptr_to_adr(hdr)
             size = self.fixed_size(typeid)
             estimate = raw_malloc_usage(size_gc_header + size)
-            if hdr.typeid & 1:
-                typeid = hdr.typeid >> 1
+            if hdr.mark:
                 offset = self.weakpointer_offset(typeid)
-                hdr.typeid = hdr.typeid & (~1)
+                hdr.mark = False
                 gc_info = llmemory.cast_ptr_to_adr(hdr)
                 weakref_obj = gc_info + size_gc_header
                 pointing_to = (weakref_obj + offset).address[0]
@@ -306,7 +315,7 @@
                     # pointed to object will die
                     # XXX what to do if the object has a finalizer which resurrects
                     # the object?
-                    if not hdr_pointing_to.typeid & 1:
+                    if not hdr_pointing_to.mark:
                         (weakref_obj + offset).address[0] = NULL
                 hdr.next = surviving
                 surviving = hdr
@@ -331,7 +340,7 @@
             ppnext += llmemory.offsetof(self.POOLNODE, 'linkedlist')
             hdr = poolnode.linkedlist
             while hdr:  #sweep
-                typeid = hdr.typeid >> 1
+                typeid = hdr.typeid16
                 next = hdr.next
                 addr = llmemory.cast_ptr_to_adr(hdr)
                 size = self.fixed_size(typeid)
@@ -339,8 +348,8 @@
                     length = (addr + size_gc_header + self.varsize_offset_to_length(typeid)).signed[0]
                     size += self.varsize_item_sizes(typeid) * length
                 estimate = raw_malloc_usage(size_gc_header + size)
-                if hdr.typeid & 1:
-                    hdr.typeid = hdr.typeid & (~1)
+                if hdr.mark:
+                    hdr.mark = False
                     ppnext.address[0] = addr
                     ppnext = llmemory.cast_ptr_to_adr(hdr)
                     ppnext += llmemory.offsetof(self.HDR, 'next')
@@ -423,17 +432,17 @@
         last = lltype.nullptr(self.HDR)
         while hdr:
             next = hdr.next
-            if hdr.typeid & 1:
+            if hdr.mark:
                 hdr.next = lltype.nullptr(self.HDR)
                 if not self.malloced_objects_with_finalizer:
                     self.malloced_objects_with_finalizer = hdr
                 else:
                     last.next = hdr
-                hdr.typeid = hdr.typeid & (~1)
+                hdr.mark = False
                 last = hdr
             else:
                 obj = llmemory.cast_ptr_to_adr(hdr) + size_gc_header
-                finalizer = self.getfinalizer(hdr.typeid >> 1)
+                finalizer = self.getfinalizer(hdr.typeid16)
                 # make malloced_objects_with_finalizer consistent
                 # for the sake of a possible collection caused by finalizer
                 if not self.malloced_objects_with_finalizer:
@@ -473,7 +482,7 @@
         size_gc_header = self.gcheaderbuilder.size_gc_header
         gc_info = gcobjectaddr - size_gc_header
         hdr = llmemory.cast_adr_to_ptr(gc_info, self.HDRPTR)
-        hdr.typeid = hdr.typeid & (~1)
+        hdr.mark = False
 
     STAT_HEAP_USAGE     = 0
     STAT_BYTES_MALLOCED = 1
@@ -483,7 +492,7 @@
         size_gc_header = self.gcheaderbuilder.size_gc_header
         gc_info = obj - size_gc_header
         hdr = llmemory.cast_adr_to_ptr(gc_info, self.HDRPTR)
-        return hdr.typeid >> 1
+        return hdr.typeid16
 
     def add_reachable_to_stack(self, obj, objects):
         self.trace(obj, self._add_reachable, objects)
@@ -504,13 +513,17 @@
 
     def init_gc_object(self, addr, typeid):
         hdr = llmemory.cast_adr_to_ptr(addr, self.HDRPTR)
-        hdr.typeid = typeid << 1
+        hdr.typeid16 = typeid
+        hdr.mark = False
+        hdr.curpool_flag = False
 
     def init_gc_object_immortal(self, addr, typeid, flags=0):
         # prebuilt gc structures always have the mark bit set
         # ignore flags
         hdr = llmemory.cast_adr_to_ptr(addr, self.HDRPTR)
-        hdr.typeid = (typeid << 1) | 1
+        hdr.typeid16 = typeid
+        hdr.mark = True
+        hdr.curpool_flag = False
 
     # experimental support for thread cloning
     def x_swap_pool(self, newpool):
@@ -566,7 +579,6 @@
         # in the specified pool.  A new pool is built to contain the
         # copies, and the 'gcobjectptr' and 'pool' fields of clonedata
         # are adjusted to refer to the result.
-        CURPOOL_FLAG = sys.maxint // 2 + 1
 
         # install a new pool into which all the mallocs go
         curpool = self.x_swap_pool(lltype.nullptr(X_POOL))
@@ -583,7 +595,7 @@
         hdr = hdr.next   # skip the POOL object itself
         while hdr:
             next = hdr.next
-            hdr.typeid |= CURPOOL_FLAG   # mark all objects from malloced_list
+            hdr.curpool_flag = True   # mark all objects from malloced_list
             hdr.next = lltype.nullptr(self.HDR)  # abused to point to the copy
             oldobjects.append(llmemory.cast_ptr_to_adr(hdr))
             hdr = next
@@ -600,12 +612,11 @@
                 continue   # pointer is NULL
             oldhdr = llmemory.cast_adr_to_ptr(oldobj_addr - size_gc_header,
                                               self.HDRPTR)
-            typeid = oldhdr.typeid
-            if not (typeid & CURPOOL_FLAG):
+            if not oldhdr.curpool_flag:
                 continue   # ignore objects that were not in the malloced_list
             newhdr = oldhdr.next      # abused to point to the copy
             if not newhdr:
-                typeid = (typeid & ~CURPOOL_FLAG) >> 1
+                typeid = oldhdr.typeid16
                 size = self.fixed_size(typeid)
                 # XXX! collect() at the beginning if the free heap is low
                 if self.is_varsize(typeid):
@@ -631,11 +642,15 @@
                 newhdr_addr = newobj_addr - size_gc_header
                 newhdr = llmemory.cast_adr_to_ptr(newhdr_addr, self.HDRPTR)
 
-                saved_id   = newhdr.typeid    # XXX hack needed for genc
+                saved_id   = newhdr.typeid16  # XXX hack needed for genc
+                saved_flg1 = newhdr.mark
+                saved_flg2 = newhdr.curpool_flag
                 saved_next = newhdr.next      # where size_gc_header == 0
                 raw_memcopy(oldobj_addr, newobj_addr, size)
-                newhdr.typeid = saved_id
-                newhdr.next   = saved_next
+                newhdr.typeid16     = saved_id
+                newhdr.mark         = saved_flg1
+                newhdr.curpool_flag = saved_flg2
+                newhdr.next         = saved_next
 
                 offsets = self.offsets_to_gc_pointers(typeid)
                 i = 0
@@ -669,7 +684,7 @@
         next = lltype.nullptr(self.HDR)
         while oldobjects.non_empty():
             hdr = llmemory.cast_adr_to_ptr(oldobjects.pop(), self.HDRPTR)
-            hdr.typeid &= ~CURPOOL_FLAG   # reset the flag
+            hdr.curpool_flag = False   # reset the flag
             hdr.next = next
             next = hdr
         oldobjects.delete()



More information about the Pypy-commit mailing list