[pypy-svn] r50288 - in pypy/branch/asmgcroot/pypy/rpython/memory: . gc gctransform
arigo at codespeak.net
arigo at codespeak.net
Thu Jan 3 15:17:12 CET 2008
Author: arigo
Date: Thu Jan 3 15:17:10 2008
New Revision: 50288
Modified:
pypy/branch/asmgcroot/pypy/rpython/memory/gc/base.py
pypy/branch/asmgcroot/pypy/rpython/memory/gc/generation.py
pypy/branch/asmgcroot/pypy/rpython/memory/gc/semispace.py
pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/asmgcroot.py
pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/framework.py
pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/stacklessframework.py
pypy/branch/asmgcroot/pypy/rpython/memory/gcwrapper.py
Log:
Yet Another intermediate check-in... Thinking about changing the approach.
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gc/base.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gc/base.py Thu Jan 3 15:17:10 2008
@@ -29,6 +29,9 @@
self.varsize_offsets_to_gcpointers_in_var_part = varsize_offsets_to_gcpointers_in_var_part
self.weakpointer_offset = weakpointer_offset
+ def set_root_walker(self, root_walker):
+ self.root_walker = root_walker
+
def write_barrier(self, oldvalue, newvalue, addr_struct):
pass
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gc/generation.py Thu Jan 3 15:17:10 2008
@@ -33,12 +33,10 @@
def __init__(self, AddressLinkedList,
nursery_size=128,
space_size=4096,
- max_space_size=sys.maxint//2+1,
- get_roots=None):
+ max_space_size=sys.maxint//2+1):
SemiSpaceGC.__init__(self, AddressLinkedList,
space_size = space_size,
- max_space_size = max_space_size,
- get_roots = get_roots)
+ max_space_size = max_space_size)
self.nursery_size = nursery_size
assert nursery_size <= space_size // 2
@@ -239,19 +237,15 @@
# if a prebuilt GcStruct contains a pointer to a young object,
# then the write_barrier must have ensured that the prebuilt
# GcStruct is in the list self.old_objects_pointing_to_young.
- roots = self.get_roots(with_static=False)
- count = 0
- while 1:
- root = roots.pop()
- if root == NULL:
- break
- count += 1
- obj = root.address[0]
- if self.is_in_nursery(obj):
- root.address[0] = self.copy(obj)
- if DEBUG_PRINT:
- llop.debug_print(lltype.Void, "collect_roots_in_nursery", count)
- free_non_gc_object(roots)
+ self.root_walker.walk_roots(
+ GenerationGC._collect_root_in_nursery, # stack roots
+ GenerationGC._collect_root_in_nursery, # static in prebuilt non-gc
+ None) # static in prebuilt gc
+
+ def _collect_root_in_nursery(self, root):
+ obj = root.address[0]
+ if self.is_in_nursery(obj):
+ root.address[0] = self.copy(obj)
def scan_objects_just_copied_out_of_nursery(self, scan):
while scan < self.free:
@@ -296,7 +290,7 @@
self.remember_young_pointer(addr_struct, newvalue)
def append_to_static_roots(self, pointer, arg):
- self.get_roots.append_static_root(pointer)
+ self.root_walker.append_static_root(pointer)
def move_to_static_roots(self, addr_struct):
objhdr = self.header(addr_struct)
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gc/semispace.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gc/semispace.py Thu Jan 3 15:17:10 2008
@@ -28,12 +28,10 @@
('tid', lltype.Signed))
def __init__(self, AddressLinkedList, space_size=4096,
- max_space_size=sys.maxint//2+1,
- get_roots=None):
+ max_space_size=sys.maxint//2+1):
MovingGCBase.__init__(self)
self.space_size = space_size
self.max_space_size = max_space_size
- self.get_roots = get_roots
self.gcheaderbuilder = GCHeaderBuilder(self.HDR)
self.AddressLinkedList = AddressLinkedList
@@ -228,13 +226,13 @@
return scan
def collect_roots(self):
- roots = self.get_roots()
- while 1:
- root = roots.pop()
- if root == NULL:
- break
- root.address[0] = self.copy(root.address[0])
- free_non_gc_object(roots)
+ self.root_walker.walk_roots(
+ SemiSpaceGC._collect_root, # stack roots
+ SemiSpaceGC._collect_root, # static in prebuilt non-gc structures
+ SemiSpaceGC._collect_root) # static in prebuilt gc objects
+
+ def _collect_root(self, root):
+ root.address[0] = self.copy(root.address[0])
def copy(self, obj):
# Objects not living the GC heap have all been initialized by
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/asmgcroot.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/asmgcroot.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/asmgcroot.py Thu Jan 3 15:17:10 2008
@@ -28,13 +28,14 @@
for var in livevars:
hop.genop("asm_gcroot", [var])
- def build_stack_root_iterator(self):
+ def build_root_walker(self):
gcdata = self.gcdata
+ gc = gcdata.gc
- class StackRootIterator:
+ class RootWalker:
_alloc_flavor_ = 'raw'
- def setup_root_stack():
+ def setup_root_stack(self):
# The gcmap table is a list of pairs of pointers:
# void *SafePointAddress;
# void *Shape;
@@ -44,7 +45,6 @@
gcmapstart = llop.llvm_gcmapstart(llmemory.Address)
gcmapend = llop.llvm_gcmapend(llmemory.Address)
insertion_sort(gcmapstart, gcmapend)
- setup_root_stack = staticmethod(setup_root_stack)
need_root_stack = False
@@ -52,8 +52,12 @@
gcdata.static_root_end.address[0] = adr
gcdata.static_root_end += sizeofaddr
append_static_root = staticmethod(append_static_root)
-
- def __init__(self, with_static=True):
+
+ def walk_roots(self, collect_stack_root,
+ collect_static_in_prebuilt_nongc,
+ collect_static_in_prebuilt_gc,
+ collect_finished):
+ ...
self.callee_data = lltype.malloc(ASM_STACKWALK, flavor="raw")
self.caller_data = lltype.malloc(ASM_STACKWALK, flavor="raw")
pypy_asm_stackwalk_init(self.caller_data)
@@ -186,10 +190,8 @@
ll_assert(i >= 0, "bad call to next_gcroot_from_current_frame")
liveoffset = self.liveoffsets.signed[i]
return self.callee_data[FRAME_PTR] + liveoffset
- ...
-
- return StackRootIterator
+ return RootWalker()
sizeofaddr = llmemory.sizeof(llmemory.Address)
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/framework.py Thu Jan 3 15:17:10 2008
@@ -133,15 +133,16 @@
sizeofaddr = llmemory.sizeof(llmemory.Address)
- StackRootIterator = self.build_stack_root_iterator()
- gcdata.gc = GCClass(AddressLinkedList, get_roots=StackRootIterator, **GC_PARAMS)
+ gcdata.gc = GCClass(AddressLinkedList, **GC_PARAMS)
+ root_walker = self.build_root_walker()
gcdata.set_query_functions(gcdata.gc)
+ gcdata.set_root_walker(gcdata.gc, root_walker)
self.num_pushs = 0
self.write_barrier_calls = 0
def frameworkgc_setup():
# run-time initialization code
- StackRootIterator.setup_root_stack()
+ root_walker.setup_root_stack()
gcdata.gc.setup()
bk = self.translator.annotator.bookkeeper
@@ -172,19 +173,19 @@
self.frameworkgc_setup_ptr = getfn(frameworkgc_setup, [],
annmodel.s_None)
- if StackRootIterator.need_root_stack:
- #self.pop_root_ptr = getfn(StackRootIterator.pop_root, [],
+ if RootWalker.need_root_stack:
+ #self.pop_root_ptr = getfn(RootWalker.pop_root, [],
# annmodel.SomeAddress(),
# inline = True)
- #self.push_root_ptr = getfn(StackRootIterator.push_root,
+ #self.push_root_ptr = getfn(RootWalker.push_root,
# [annmodel.SomeAddress()],
# annmodel.s_None,
# inline = True)
- self.incr_stack_ptr = getfn(StackRootIterator.incr_stack,
+ self.incr_stack_ptr = getfn(RootWalker.incr_stack,
[annmodel.SomeInteger()],
annmodel.SomeAddress(),
inline = True)
- self.decr_stack_ptr = getfn(StackRootIterator.decr_stack,
+ self.decr_stack_ptr = getfn(RootWalker.decr_stack,
[annmodel.SomeInteger()],
annmodel.SomeAddress(),
inline = True)
@@ -350,12 +351,12 @@
FLDTYPE = getattr(HDR, fldname)
fields.append(('_' + fldname, FLDTYPE))
- def build_stack_root_iterator(self):
+ def build_root_walker(self):
gcdata = self.gcdata
sizeofaddr = llmemory.sizeof(llmemory.Address)
rootstacksize = sizeofaddr * self.root_stack_depth
- class StackRootIterator:
+ class RootWalker:
_alloc_flavor_ = 'raw'
def setup_root_stack():
stackbase = llmemory.raw_malloc(rootstacksize)
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/stacklessframework.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/stacklessframework.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gctransform/stacklessframework.py Thu Jan 3 15:17:10 2008
@@ -37,6 +37,7 @@
## self.inline_helpers(graph)
def build_stack_root_iterator(self):
+ xxx
from pypy.rlib.rstack import stack_capture
sizeofaddr = llmemory.sizeof(llmemory.Address)
gcdata = self.gcdata
Modified: pypy/branch/asmgcroot/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/asmgcroot/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/asmgcroot/pypy/rpython/memory/gcwrapper.py Thu Jan 3 15:17:10 2008
@@ -11,13 +11,10 @@
def __init__(self, llinterp, flowgraphs, gc_class, GC_PARAMS={}):
self.AddressLinkedList = get_address_linked_list(10)
self.gc = gc_class(self.AddressLinkedList, **GC_PARAMS)
- def my_get_roots(with_static=True):
- return self.get_roots_from_llinterp(with_static)
- self.gc.get_roots = my_get_roots
+ self.gc.set_root_walker(LLInterpRootWalker(self))
self.llinterp = llinterp
self.prepare_graphs(flowgraphs)
self.gc.setup()
- my_get_roots.append_static_root = self.constantroots.append
def prepare_graphs(self, flowgraphs):
layoutbuilder = DirectRunLayoutBuilder(self.llinterp)
@@ -32,21 +29,6 @@
self.constantroots = list(layoutbuilder.addresses_of_static_ptrs)
self.constantrootsnongc = layoutbuilder.addresses_of_static_ptrs_in_nongc
- def get_roots_from_llinterp(self, with_static=True):
- sizeofaddr = llmemory.sizeof(llmemory.Address)
- ll = [llmemory.NULL] # end marker
- if with_static:
- for addrofaddr in self.constantroots:
- if addrofaddr.address[0]:
- ll.append(addrofaddr)
- for addrofaddr in self.constantrootsnongc:
- if addrofaddr.address[0]:
- ll.append(addrofaddr)
- for addrofaddr in self.llinterp.find_roots():
- if addrofaddr.address[0]:
- ll.append(addrofaddr)
- return RootLinkedList(ll)
-
# ____________________________________________________________
#
# Interface for the llinterp
@@ -120,14 +102,34 @@
return self.gc.id(ptr)
- # ____________________________________________________________
+# ____________________________________________________________
-class RootLinkedList(object):
+class LLInterpRootWalker:
_alloc_flavor_ = 'raw'
- def __init__(self, lst):
- self._lst = lst
- self.pop = lst.pop
+ def __init__(self, gcheap):
+ self.gcheap = gcheap
+
+ def append_static_root(self, pointer):
+ self.gcheap.constantroots.append(pointer)
+
+ def walk_roots(self, collect_stack_root,
+ collect_static_in_prebuilt_nongc,
+ collect_static_in_prebuilt_gc):
+ gcheap = self.gcheap
+ gc = gcheap.gc
+ if collect_static_in_prebuilt_gc:
+ for addrofaddr in gcheap.constantroots:
+ if addrofaddr.address[0]:
+ collect_static_in_prebuilt_gc(gc, addrofaddr)
+ if collect_static_in_prebuilt_nongc:
+ for addrofaddr in gcheap.constantrootsnongc:
+ if addrofaddr.address[0]:
+ collect_static_in_prebuilt_nongc(gc, addrofaddr)
+ if collect_stack_root:
+ for addrofaddr in gcheap.llinterp.find_roots():
+ if addrofaddr.address[0]:
+ collect_stack_root(gc, addrofaddr)
class DirectRunLayoutBuilder(gctypelayout.TypeLayoutBuilder):
More information about the Pypy-commit
mailing list