Author: Gregor Wegberg <[email protected]>
Branch: gc-incminimark-pinning
Changeset: r71808:267d6a45eb2a
Date: 2014-05-08 14:35 +0200
http://bitbucket.org/pypy/pypy/changeset/267d6a45eb2a/

Log:    GC transformation now replaces rgc.pin/rgc.unpin with actual GC pin
        function.

        RFile example compiles and runs.

diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -175,6 +175,12 @@
     def can_move(self, addr):
         return False
 
+    def pin(self, addr):
+        return False
+
+    def unpin(self, addr):
+        pass
+
     def set_max_heap_size(self, size):
         raise NotImplementedError
 
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -65,6 +65,9 @@
 from rpython.rlib.debug import ll_assert, debug_print, debug_start, debug_stop
 from rpython.rlib.objectmodel import specialize
 
+# XXX remove (groggi)
+from rpython.rlib.debug import debug_print, debug_start, debug_stop
+
 
 #
 # Handles the objects in 2 generations:
@@ -891,6 +894,16 @@
         """Overrides the parent can_move()."""
         return self.is_in_nursery(obj)
 
+    def pin(self, obj):
+        debug_start("groggi-incminimark-pin")
+        debug_stop("groggi-incminimark-pin")
+        return False
+
+
+    def unpin(self, obj):
+        debug_start("groggi-incminimark-unpin")
+        debug_stop("groggi-incminimark-unpin")
+
 
     def shrink_array(self, obj, smallerlength):
         #
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
@@ -456,6 +456,16 @@
                                             annmodel.SomeInteger(nonneg=True)],
                                            annmodel.s_None)
 
+        # XXX understand this, correct? (groggi)
+        self.pin_ptr = getfn(GCClass.pin,
+                             [s_gc, s_gcref],
+                             annmodel.SomeBool())
+
+        # XXX understand this, correct? (groggi)
+        self.unpin_ptr = getfn(GCClass.unpin,
+                               [s_gc, s_gcref],
+                               annmodel.s_None)
+
         self.write_barrier_ptr = None
         self.write_barrier_from_array_ptr = None
         if GCClass.needs_write_barrier:
@@ -967,6 +977,15 @@
                                   self.c_const_gc,
                                   v_size])
 
+    def gct_gc_pin(self, hop):
+        op = hop.spaceop
+        hop.genop("direct_call", [self.pin_ptr, self.c_const_gc, op.args[0]],
+                  resultvar=op.result)
+
+    def gct_gc_unpin(self, hop):
+        op = hop.spaceop
+        hop.genop("direct_call", [self.unpin_ptr, self.c_const_gc, op.args[0]])
+
     def gct_gc_thread_run(self, hop):
         assert self.translator.config.translation.thread
         if hasattr(self.root_walker, 'thread_run_ptr'):
diff --git a/rpython/memory/gcwrapper.py b/rpython/memory/gcwrapper.py
--- a/rpython/memory/gcwrapper.py
+++ b/rpython/memory/gcwrapper.py
@@ -5,6 +5,9 @@
 from rpython.memory import gctypelayout
 from rpython.flowspace.model import Constant
 
+# XXX remove (groggi)
+from rpython.rlib.debug import debug_print, debug_start, debug_stop
+
 
 class GCManagedHeap(object):
 
@@ -122,6 +125,16 @@
     def can_move(self, addr):
         return self.gc.can_move(addr)
 
+    def pin(self, addr):
+        debug_start("groggi-gcwrapper-pin")
+        debug_stop("groggi-gcwrapper-pin")
+        return self.gc.pin(addr)
+
+    def unpin(self, addr):
+        debug_start("groggi-gcwrapper-unpin")
+        self.gc.unpin(addr)
+        debug_stop("groggi-gcwrapper-unpin")
+
     def weakref_create_getlazy(self, objgetter):
         # we have to be lazy in reading the llinterp variable containing
         # the 'obj' pointer, because the gc.malloc() call below could
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -8,6 +8,9 @@
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rtyper.lltypesystem import lltype, llmemory
 
+# XXX remove (groggi)
+from rpython.rlib.debug import debug_print, debug_start, debug_stop
+
 # ____________________________________________________________
 # General GC features
 
@@ -36,6 +39,8 @@
     # XXX doc string based on gc-minimark-pinning branch
     # XXX use doc string a basis for implementation behavior
     # XXX update doc string to match actual behavior
+    debug_start("groggi-rgc-pin")
+    debug_stop("groggi-rgc-pin")
     return False
 
 def unpin(obj):
@@ -602,5 +607,32 @@
         hop.exception_cannot_occur()
         return hop.genop('gc_gcflag_extra', vlist, resulttype = hop.r_result)
 
+class Entry(ExtRegistryEntry): # XXX understand this, is it correct? (groggi)
+    _about_ = pin
+
+    def compute_result_annotation(self, s_arg):
+        from rpython.annotator.model import SomeBool
+        return SomeBool()
+
+    def specialize_call(self, hop):
+        hop.exception_cannot_occur()
+        v_obj, = hop.inputargs(hop.args_r[0])
+        v_addr = hop.genop('cast_ptr_to_adr', [v_obj],
+                           resulttype=llmemory.Address)
+        return hop.genop('gc_pin', [v_addr], resulttype=lltype.Bool)
+
+class Entry(ExtRegistryEntry): # XXX understand this, is it correct? (groggi)
+    _about_ = unpin
+
+    def compute_result_annotation(self, s_arg):
+        pass
+
+    def specialize_call(self, hop):
+        hop.exception_cannot_occur()
+        v_obj, = hop.inputargs(hop.args_r[0])
+        v_addr = hop.genop('cast_ptr_to_adr', [v_obj],
+                           resulttype=llmemory.Address)
+        hop.genop('gc_unpin', [v_addr])
+
 def lltype_is_gc(TP):
     return getattr(getattr(TP, "TO", None), "_gckind", "?") == 'gc'
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -859,6 +859,12 @@
     def op_gc_stack_bottom(self):
         pass       # marker for trackgcroot.py
 
+    def op_gc_pin(self, obj):
+        return self.heap.pin(obj)
+
+    def op_gc_unpin(self, obj):
+        self.heap.unpin(obj)
+
     def op_gc_detach_callback_pieces(self):
         raise NotImplementedError("gc_detach_callback_pieces")
     def op_gc_reattach_callback_pieces(self):
diff --git a/rpython/rtyper/lltypesystem/llheap.py 
b/rpython/rtyper/lltypesystem/llheap.py
--- a/rpython/rtyper/lltypesystem/llheap.py
+++ b/rpython/rtyper/lltypesystem/llheap.py
@@ -32,3 +32,10 @@
 
 def thread_die():
     pass
+
+def pin(obj):
+    return False
+
+def unpin(obj):
+    raise AssertionError("pin() always returns False, "
+                         "so unpin() should not be called")
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -480,6 +480,8 @@
     'gc_writebarrier':      LLOp(canrun=True),
     'gc_writebarrier_before_copy': LLOp(canrun=True),
     'gc_heap_stats'       : LLOp(canmallocgc=True),
+    'gc_pin'              : LLOp(canrun=True), # XXX understand this, correct? 
(groggi)
+    'gc_unpin'            : LLOp(canrun=True), # XXX understand this, correct? 
(groggi)
 
     'gc_get_rpy_roots'    : LLOp(),
     'gc_get_rpy_referents': LLOp(),
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to