[pypy-commit] pypy raw-memory-pressure-nursery: (fijal, arigo) be a bit more precise about stored sizes

fijal noreply at buildbot.pypy.org
Tue Feb 14 19:42:00 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: raw-memory-pressure-nursery
Changeset: r52468:d78b4be75ced
Date: 2012-02-14 20:41 +0200
http://bitbucket.org/pypy/pypy/changeset/d78b4be75ced/

Log:	(fijal, arigo) be a bit more precise about stored sizes

diff --git a/pypy/rpython/memory/gc/minimark.py b/pypy/rpython/memory/gc/minimark.py
--- a/pypy/rpython/memory/gc/minimark.py
+++ b/pypy/rpython/memory/gc/minimark.py
@@ -52,8 +52,6 @@
 from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask, r_uint
 from pypy.rlib.rarithmetic import LONG_BIT_SHIFT
 from pypy.rlib.debug import ll_assert, debug_print, debug_start, debug_stop
-from pypy.rlib.objectmodel import we_are_translated
-from pypy.tool.sourcetools import func_with_new_name
 
 #
 # Handles the objects in 2 generations:
@@ -113,8 +111,9 @@
 # one bit per 'card_page_indices' indices.
 GCFLAG_HAS_CARDS    = first_gcflag << 5
 GCFLAG_CARDS_SET    = first_gcflag << 6     # <- at least one card bit is set
+GCFLAG_OWNS_RAW_MEMORY = first_gcflag << 7
 
-TID_MASK            = (first_gcflag << 7) - 1
+TID_MASK            = (first_gcflag << 8) - 1
 
 
 FORWARDSTUB = lltype.GcStruct('forwarding_stub',
@@ -740,6 +739,19 @@
                 self.next_major_collection_threshold = self.max_heap_size
 
     def raw_malloc_memory_pressure(self, obj, sizehint):
+        size = self.get_size(obj)
+        if obj + size == self.nursery_free:
+            sizehint = llarena.round_up_for_allocation(sizehint, WORD)
+            if (self.nursery_top - self.nursery_free) < sizehint:
+                self.nursery_free = self.nursery_top
+            else:
+                self.nursery_free.signed[0] = sizehint
+                self.header(obj).tid |= GCFLAG_OWNS_RAW_MEMORY
+                self.nursery_free += sizehint
+                return
+        self._raw_malloc_memory_pressure_major(sizehint)
+
+    def _raw_malloc_memory_pressure_major(self, sizehint):
         self.next_major_collection_threshold -= sizehint
         if self.next_major_collection_threshold < 0:
             # cannot trigger a full collection now, but we can ensure
@@ -1448,6 +1460,10 @@
         #
         # Copy it.  Note that references to other objects in the
         # nursery are kept unchanged in this step.
+        if self.header(obj).tid & GCFLAG_OWNS_RAW_MEMORY:
+            raw_memory_size = (obj + size).signed[0]
+            self.major_collection_threshold -= raw_memory_size
+            self.header(obj).tid &= ~GCFLAG_OWNS_RAW_MEMORY
         llmemory.raw_memcopy(obj - size_gc_header, newhdr, totalsize)
         #
         # Set the old object's tid to -42 (containing all flags) and
diff --git a/pypy/rpython/memory/gc/test/test_direct.py b/pypy/rpython/memory/gc/test/test_direct.py
--- a/pypy/rpython/memory/gc/test/test_direct.py
+++ b/pypy/rpython/memory/gc/test/test_direct.py
@@ -594,8 +594,15 @@
         assert ord(addr_byte.char[0]) == 0x01 | 0x04  # bits 0 and 2
 
     def test_memory_pressure(self):
-        
-        
+        obj = self.malloc(S)
+        nursery_size = self.gc.nursery_size
+        self.gc.raw_malloc_memory_pressure(llmemory.cast_ptr_to_adr(obj),
+                                           nursery_size / 2)
+        obj2 = self.malloc(S)
+        self.gc.raw_malloc_memory_pressure(llmemory.cast_ptr_to_adr(obj2),
+                                           nursery_size / 2)
+        # obj should be dead by now
+        assert self.gc.nursery_free == self.gc.nursery        
 
     test_writebarrier_before_copy_preserving_cards.GC_PARAMS = {
         "card_page_indices": 4}


More information about the pypy-commit mailing list