[pypy-commit] pypy gc-minimark-pinning: use some more pinning

fijal noreply at buildbot.pypy.org
Sun Apr 15 19:01:15 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: gc-minimark-pinning
Changeset: r54372:96e1dad774ae
Date: 2012-04-15 19:00 +0200
http://bitbucket.org/pypy/pypy/changeset/96e1dad774ae/

Log:	use some more pinning

diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -75,8 +75,15 @@
     With other moving GCs like the MiniMark GC, it can be True for some
     time, then False for the same object, when we are sure that it won't
     move any more.
+
+    We keep it for False when uncompiled, because malloc_and_pin would actually
+    return an object. This executes more interesting paths, but also:
+
+    x = malloc_and_pin(T)
+    if x:
+       assert not can_move(x)
     """
-    return True
+    return False
 
 class CanMoveEntry(ExtRegistryEntry):
     _about_ = can_move
@@ -200,17 +207,20 @@
     from pypy.rpython.lltypesystem.lloperation import llop
     from pypy.rlib.objectmodel import keepalive_until_here
 
+    TP = lltype.typeOf(p).TO
+    assert len(TP._names) == 2
+    field = getattr(p, TP._names[0])
+
+    if len(getattr(p, TP._arrayfld)) == smallerlength:
+        return p
     if llop.shrink_array(lltype.Bool, p, smallerlength):
         return p    # done by the GC
     # XXX we assume for now that the type of p is GcStruct containing a
     # variable array, with no further pointers anywhere, and exactly one
     # field in the fixed part -- like STR and UNICODE.
 
-    TP = lltype.typeOf(p).TO
     newp = lltype.malloc(TP, smallerlength)
 
-    assert len(TP._names) == 2
-    field = getattr(p, TP._names[0])
     setattr(newp, TP._names[0], field)
 
     ARRAY = getattr(TP, TP._arrayfld)
diff --git a/pypy/rpython/lltypesystem/llheap.py b/pypy/rpython/lltypesystem/llheap.py
--- a/pypy/rpython/lltypesystem/llheap.py
+++ b/pypy/rpython/lltypesystem/llheap.py
@@ -19,6 +19,7 @@
     return weakref_create(objgetter())
 
 malloc_and_pin = malloc
+malloc_varsize_and_pin = malloc
 
 def shrink_array(p, smallersize):
     return False
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -739,6 +739,8 @@
         # if 'buf' points inside 'data'.  This is only possible if we
         # followed the 2nd case in get_nonmovingbuffer(); in the first case,
         # 'buf' points to its own raw-malloced memory.
+        import pdb
+        pdb.set_trace()
         data = llstrtype(data)
         data_start = cast_ptr_to_adr(data) + \
             offsetof(STRTYPE, 'chars') + itemoffsetof(STRTYPE.chars, 0)
@@ -763,8 +765,15 @@
         Right now this is a version optimized for minimark which can pin values
         in the nursery.
         """
-        raw_buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
-        return raw_buf, lltype.nullptr(STRTYPE)
+        ll_s = rgc.malloc_and_pin(STRTYPE, count)
+        if not ll_s:
+            raw_buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
+            return raw_buf, lltype.nullptr(STRTYPE)
+        else:
+            data_start = cast_ptr_to_adr(ll_s) + \
+                offsetof(STRTYPE, 'chars') + itemoffsetof(STRTYPE.chars, 0)
+            raw_buf = cast(TYPEP, data_start)
+            return raw_buf, ll_s
     alloc_buffer._always_inline_ = True # to get rid of the returned tuple
     alloc_buffer._annenforceargs_ = [int]
 
@@ -777,7 +786,9 @@
         """
         assert allocated_size >= needed_size
 
-        if gc_buf and (allocated_size == needed_size):
+        if gc_buf:
+            if allocated_size != needed_size:
+                gc_buf = rgc.ll_shrink_array(gc_buf, needed_size)
             return hlstrtype(gc_buf)
 
         new_buf = lltype.malloc(STRTYPE, needed_size)
diff --git a/pypy/rpython/memory/gctransform/transform.py b/pypy/rpython/memory/gctransform/transform.py
--- a/pypy/rpython/memory/gctransform/transform.py
+++ b/pypy/rpython/memory/gctransform/transform.py
@@ -377,6 +377,12 @@
     def gct_zero_gc_pointers_inside(self, hop):
         pass
 
+    def gct_gc_pin(self, hop):
+        pass
+
+    def gct_gc_unpin(self, hop):
+        pass
+
     def gct_gc_writebarrier_before_copy(self, hop):
         # We take the conservative default and return False here, meaning
         # that rgc.ll_arraycopy() will do the copy by hand (i.e. with a
diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -7,11 +7,11 @@
 
 import os, sys, errno
 import py
-from pypy.rpython.module.support import ll_strcpy, OOSupport
-from pypy.tool.sourcetools import func_with_new_name, func_renamer
+from pypy.rpython.module.support import OOSupport
+from pypy.tool.sourcetools import func_renamer
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.rpython.extfunc import (
-    BaseLazyRegistering, lazy_register, register_external)
+    BaseLazyRegistering, register_external)
 from pypy.rpython.extfunc import registering, registering_if, extdef
 from pypy.annotation.model import (
     SomeInteger, SomeString, SomeTuple, SomeFloat, SomeUnicodeString)
@@ -20,15 +20,9 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.tool import rffi_platform as platform
 from pypy.rlib import rposix
-from pypy.tool.udir import udir
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.rpython.lltypesystem.rstr import mallocstr
-from pypy.rpython.annlowlevel import llstr
-from pypy.rpython.lltypesystem.llmemory import sizeof,\
-     itemoffsetof, cast_ptr_to_adr, cast_adr_to_ptr, offsetof
+from pypy.rpython.lltypesystem.llmemory import itemoffsetof, offsetof
 from pypy.rpython.lltypesystem.rstr import STR
-from pypy.rpython.annlowlevel import llstr
-from pypy.rlib import rgc
 from pypy.rlib.objectmodel import specialize
 
 str0 = SomeString(no_nul=True)


More information about the pypy-commit mailing list