[pypy-commit] pypy stacklet: Move some of the logic to _stacklet_asmgcc.

arigo noreply at buildbot.pypy.org
Sat Aug 6 18:04:39 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stacklet
Changeset: r46327:9b20671292c6
Date: 2011-08-06 17:55 +0200
http://bitbucket.org/pypy/pypy/changeset/9b20671292c6/

Log:	Move some of the logic to _stacklet_asmgcc.

diff --git a/pypy/module/_stacklet/interp_stacklet.py b/pypy/module/_stacklet/interp_stacklet.py
--- a/pypy/module/_stacklet/interp_stacklet.py
+++ b/pypy/module/_stacklet/interp_stacklet.py
@@ -68,7 +68,7 @@
         h = self.h
         if h:
             self.h = NULLHANDLE
-            rstacklet.destroy(self.sthread.thrd, h)
+            rstacklet.destroy(self.sthread.gcrootfinder, self.sthread.thrd, h)
 
     def consume_handle(self):
         h = self.h
diff --git a/pypy/rlib/_stacklet_asmgcc.py b/pypy/rlib/_stacklet_asmgcc.py
--- a/pypy/rlib/_stacklet_asmgcc.py
+++ b/pypy/rlib/_stacklet_asmgcc.py
@@ -179,24 +179,56 @@
                                       rstacklet.handle, sandboxsafe=True,
                                       _nowrapper=True)
 
+def stack_protected_call(callback):
+    p = suspendedstacks.acquire()
+    llop.gc_assume_young_pointers(lltype.Void,
+                                  llmemory.cast_ptr_to_adr(p))
+    r = pypy_asm_stackwalk2(callback, p.anchor)
+    p.handle = lltype.nullptr(rstacklet.handle.TO)
+    suspendedstacks.release(p)
+    return r
+
+def set_handle_on_most_recent(h):
+    index = suspendedstacks.current_index
+    if not h or rstacklet.is_empty_handle(h):
+        assert index == -1
+    else:
+        assert index >= 0
+        suspendedstacks.lst[index].handle = h
+        suspendedstacks.current_index = -1
+
+def _new_callback():
+    h = rstacklet._new(suspendedstacks._thrd,
+                       llhelper(rstacklet.run_fn, _new_runfn),
+                       lltype.nullptr(rffi.VOIDP.TO))
+    set_handle_on_most_recent(h)
+    return h
+
+def _new_runfn(h, arg):
+    llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
+    set_handle_on_most_recent(h)
+    return suspendedstacks._runfn(h, suspendedstacks._arg)
+
+def _switch_callback():
+    h = rstacklet._switch(suspendedstacks._thrd,
+                          suspendedstacks._switchto)
+    set_handle_on_most_recent(h)
+    return h
+
+
 class StackletGcRootFinder:
 
     @staticmethod
-    def stack_protected_call(callback):
-        p = suspendedstacks.acquire()
-        llop.gc_assume_young_pointers(lltype.Void,
-                                      llmemory.cast_ptr_to_adr(p))
-        r = pypy_asm_stackwalk2(callback, p.anchor)
-        p.handle = lltype.nullptr(rstacklet.handle.TO)
-        suspendedstacks.release(p)
-        return r
+    def new(thrd, runfn, arg):
+        suspendedstacks._thrd = thrd
+        suspendedstacks._runfn = runfn
+        suspendedstacks._arg = arg
+        return stack_protected_call(llhelper(FUNCNOARG_P, _new_callback))
 
     @staticmethod
-    def set_handle_on_most_recent(h):
-        index = suspendedstacks.current_index
-        if not h or rstacklet.is_empty_handle(h):
-            assert index == -1
-        else:
-            assert index >= 0
-            suspendedstacks.lst[index].handle = h
-            suspendedstacks.current_index = -1
+    def switch(thrd, h):
+        suspendedstacks._thrd = thrd
+        suspendedstacks._switchto = h
+        return stack_protected_call(llhelper(FUNCNOARG_P, _switch_callback))
+
+    destroy = staticmethod(rstacklet._destroy)
diff --git a/pypy/rlib/_stacklet_n_a.py b/pypy/rlib/_stacklet_n_a.py
--- a/pypy/rlib/_stacklet_n_a.py
+++ b/pypy/rlib/_stacklet_n_a.py
@@ -1,11 +1,6 @@
-
+from pypy.rlib import rstacklet
 
 class StackletGcRootFinder:
-
-    @staticmethod
-    def stack_protected_call(callback):
-        return callback()
-
-    @staticmethod
-    def set_handle_on_most_recent(h):
-        pass
+    new     = staticmethod(rstacklet._new)
+    switch  = staticmethod(rstacklet._switch)
+    destroy = staticmethod(rstacklet._destroy)
diff --git a/pypy/rlib/rstacklet.py b/pypy/rlib/rstacklet.py
--- a/pypy/rlib/rstacklet.py
+++ b/pypy/rlib/rstacklet.py
@@ -47,7 +47,7 @@
 _new = llexternal('stacklet_new', [thread_handle, run_fn, rffi.VOIDP],
                   handle)
 _switch = llexternal('stacklet_switch', [thread_handle, handle], handle)
-destroy = llexternal('stacklet_destroy', [thread_handle, handle], lltype.Void)
+_destroy = llexternal('stacklet_destroy', [thread_handle, handle], lltype.Void)
 
 _translate_pointer = llexternal("_stacklet_translate_pointer",
                                 [handle, llmemory.Address],
@@ -62,39 +62,15 @@
     return module.StackletGcRootFinder
 getgcclass._annspecialcase_ = 'specialize:memo'
 
-FUNCNOARG_P = lltype.Ptr(lltype.FuncType([], handle))
-
-class Starter:
-    pass
-starter = Starter()
-
 def new(gcrootfinder, thrd, runfn, arg):
-    starter.thrd = thrd
-    starter.runfn = llhelper(run_fn, runfn)
-    starter.arg = arg
     c = getgcclass(gcrootfinder)
-    starter.c = c
-    return c.stack_protected_call(llhelper(FUNCNOARG_P, _new_callback))
+    return c.new(thrd, llhelper(run_fn, runfn), arg)
 new._annspecialcase_ = 'specialize:arg(2)'
 
-def _new_callback():
-    h = _new(starter.thrd, llhelper(run_fn, _new_runfn),
-             lltype.nullptr(rffi.VOIDP.TO))
-    starter.c.set_handle_on_most_recent(h)
-    return h
+def switch(gcrootfinder, thrd, h):
+    c = getgcclass(gcrootfinder)
+    return c.switch(thrd, h)
 
-def _new_runfn(h, arg):
-    llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
-    starter.c.set_handle_on_most_recent(h)
-    return starter.runfn(h, starter.arg)
-
-def switch(gcrootfinder, thrd, h):
-    starter.thrd = thrd
-    starter.switchto = h
+def destroy(gcrootfinder, thrd, h):
     c = getgcclass(gcrootfinder)
-    return c.stack_protected_call(llhelper(FUNCNOARG_P, _switch_callback))
-
-def _switch_callback():
-    h = _switch(starter.thrd, starter.switchto)
-    starter.c.set_handle_on_most_recent(h)
-    return h
+    c.destroy(thrd, h)


More information about the pypy-commit mailing list