[pypy-svn] r49839 - in pypy/branch/lazy-write-barrier/pypy/rpython/memory: . gc gctransform
fijal at codespeak.net
fijal at codespeak.net
Sun Dec 16 16:11:35 CET 2007
Author: fijal
Date: Sun Dec 16 16:11:35 2007
New Revision: 49839
Modified:
pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/base.py
pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/generation.py
pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/semispace.py
pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctransform/framework.py
pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctypelayout.py
Log:
* Keep stackroots non-gc first, iterate backwards
* Cleanup gctypelayout in order to get rid of hacks
* Few renames.
Modified: pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/base.py (original)
+++ pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/base.py Sun Dec 16 16:11:35 2007
@@ -6,6 +6,7 @@
moving_gc = False
needs_write_barrier = False
needs_zero_gc_pointers = True
+ prebuilt_gc_objects_are_static_roots = True
def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
is_gcarrayofgcptr,
Modified: pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/generation.py Sun Dec 16 16:11:35 2007
@@ -15,7 +15,7 @@
# The following flag is set for static roots which are not on the list
# of static roots yet, but will appear with write barrier
-GCFLAG_NEVER_SET = 1 << (GCFLAGSHIFT+2)
+GCFLAG_NO_HEAP_PTRS = 1 << (GCFLAGSHIFT+2)
DEBUG_PRINT = False
@@ -27,6 +27,7 @@
"""
inline_simple_malloc = True
needs_write_barrier = True
+ prebuilt_gc_objects_are_static_roots = True
def __init__(self, AddressLinkedList,
nursery_size=128,
@@ -141,7 +142,7 @@
SemiSpaceGC.init_gc_object(self, addr, typeid, flags)
def init_gc_object_immortal(self, addr, typeid,
- flags=GCFLAG_NO_YOUNG_PTRS|GCFLAG_NEVER_SET):
+ flags=GCFLAG_NO_YOUNG_PTRS|GCFLAG_NO_HEAP_PTRS):
SemiSpaceGC.init_gc_object_immortal(self, addr, typeid, flags)
def semispace_collect(self, size_changing=False):
@@ -300,7 +301,7 @@
def move_to_static_roots(self, addr_struct):
objhdr = self.header(addr_struct)
- objhdr.tid &= ~GCFLAG_NEVER_SET
+ objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
self.trace(addr_struct, self.append_to_static_roots, None)
def remember_young_pointer(self, addr_struct, addr):
@@ -311,7 +312,6 @@
oldhdr.forw = self.old_objects_pointing_to_young
self.old_objects_pointing_to_young = addr_struct
oldhdr.tid &= ~GCFLAG_NO_YOUNG_PTRS
- if oldhdr.tid & GCFLAG_NEVER_SET:
+ if oldhdr.tid & GCFLAG_NO_HEAP_PTRS:
self.move_to_static_roots(addr_struct)
- llop.debug_print(lltype.Void, "new statc root", self.created)
remember_young_pointer.dont_inline = True
Modified: pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/semispace.py (original)
+++ pypy/branch/lazy-write-barrier/pypy/rpython/memory/gc/semispace.py Sun Dec 16 16:11:35 2007
@@ -235,7 +235,6 @@
if root == NULL:
break
root.address[0] = self.copy(root.address[0])
- llop.debug_print(lltype.Void, "collected: ", counter)
free_non_gc_object(roots)
def copy(self, obj):
Modified: pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctransform/framework.py Sun Dec 16 16:11:35 2007
@@ -126,9 +126,8 @@
immortal=True, zero=True)
a_random_address = llmemory.cast_ptr_to_adr(foo)
gcdata.static_root_start = a_random_address # patched in finish()
- gcdata.static_root_nongcstart = a_random_address # patched in finish()
+ gcdata.static_root_nongcend = a_random_address # patched in finish()
gcdata.static_root_end = a_random_address # patched in finish()
- gcdata.static_root_real_end = a_random_address
self.gcdata = gcdata
self.malloc_fnptr_cache = {}
@@ -154,14 +153,11 @@
'static_root_start',
annmodel.SomeAddress())
data_classdef.generalize_attr(
- 'static_root_nongcstart',
+ 'static_root_nongcend',
annmodel.SomeAddress())
data_classdef.generalize_attr(
'static_root_end',
annmodel.SomeAddress())
- data_classdef.generalize_attr(
- 'static_root_real_end',
- annmodel.SomeAddress())
annhelper = annlowlevel.MixLevelHelperAnnotator(self.translator.rtyper)
@@ -382,18 +378,16 @@
def __init__(self, with_static=True):
self.stack_current = gcdata.root_stack_top
if with_static:
- self.static_current = gcdata.static_root_start
+ self.static_current = gcdata.static_root_end - sizeofaddr
else:
- self.static_current = gcdata.static_root_nongcstart
- self.with_static = with_static
+ self.static_current = gcdata.static_root_nongcend - sizeofaddr
def pop(self):
- if self.with_static:
- while self.static_current != gcdata.static_root_end:
- result = self.static_current
- self.static_current += sizeofaddr
- if result.address[0].address[0] != llmemory.NULL:
- return result.address[0]
+ while self.static_current != gcdata.static_root_start:
+ result = self.static_current
+ self.static_current -= sizeofaddr
+ if result.address[0].address[0] != llmemory.NULL:
+ return result.address[0]
while self.stack_current != gcdata.root_stack_base:
self.stack_current -= sizeofaddr
if self.stack_current.address[0] != llmemory.NULL:
@@ -446,21 +440,20 @@
ll_instance = rmodel.inputconst(r_gcdata, self.gcdata).value
addresses_of_static_ptrs = (
- self.layoutbuilder.addresses_of_static_ptrs +
- self.layoutbuilder.addresses_of_static_ptrs_in_nongc)
+ self.layoutbuilder.addresses_of_static_ptrs_in_nongc +
+ self.layoutbuilder.addresses_of_static_ptrs)
log.info("found %s static roots" % (len(addresses_of_static_ptrs), ))
additional_ptrs = self.layoutbuilder.additional_roots_sources
log.info("additional %d potential static roots" % additional_ptrs)
ll_static_roots_inside = lltype.malloc(lltype.Array(llmemory.Address),
len(addresses_of_static_ptrs) +
- int(additional_ptrs),
+ additional_ptrs,
immortal=True)
for i in range(len(addresses_of_static_ptrs)):
ll_static_roots_inside[i] = addresses_of_static_ptrs[i]
- ll_instance.inst_static_root_start = llmemory.cast_ptr_to_adr(ll_static_roots_inside) + llmemory.ArrayItemsOffset(lltype.Array(llmemory.Address))
- ll_instance.inst_static_root_nongcstart = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(self.layoutbuilder.addresses_of_static_ptrs)
- ll_instance.inst_static_root_end = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * (len(ll_static_roots_inside) - additional_ptrs)
- ll_instance.inst_static_root_real_end = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(ll_static_roots_inside)
+ ll_instance.inst_static_root_start = llmemory.cast_ptr_to_adr(ll_static_roots_inside) + llmemory.ArrayItemsOffset(lltype.Array(llmemory.Address)) + llmemory.sizeof(llmemory.Address) * (-1)
+ ll_instance.inst_static_root_nongcend = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(self.layoutbuilder.addresses_of_static_ptrs_in_nongc)
+ ll_instance.inst_static_root_end = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(addresses_of_static_ptrs)
newgcdependencies = []
newgcdependencies.append(self.gcdata.type_info_table)
Modified: pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctypelayout.py (original)
+++ pypy/branch/lazy-write-barrier/pypy/rpython/memory/gctypelayout.py Sun Dec 16 16:11:35 2007
@@ -286,12 +286,7 @@
return
self.seen_roots[id(value)] = True
- # XXX hack, a lot of gengc details here
- from pypy.rpython.memory.gc.generation import GenerationGC
- if isinstance(gc, GenerationGC):
- gen_gc = True
- else:
- gen_gc = False
+ lazy_write_barrier = gc.prebuilt_gc_objects_are_static_roots
if isinstance(TYPE, (lltype.GcStruct, lltype.GcArray)):
typeid = self.get_type_id(TYPE)
@@ -305,15 +300,15 @@
# they could be changed later to point to GC heap objects.
adr = llmemory.cast_ptr_to_adr(value._as_ptr())
if TYPE._gckind == "gc":
- if gen_gc:
- for a in gc_pointers_inside(value, adr):
+ if lazy_write_barrier:
+ for a in gc_pointers_inside(value, adr, mutable_only=False):
self.additional_roots_sources += 1
return
else:
appendto = self.addresses_of_static_ptrs
else:
appendto = self.addresses_of_static_ptrs_in_nongc
- for a in mutable_gc_pointers_inside(value, adr):
+ for a in gc_pointers_inside(value, adr):
appendto.append(a)
# ____________________________________________________________
@@ -350,51 +345,32 @@
def weakpointer_offset(TYPE):
if TYPE == WEAKREF:
return llmemory.offsetof(WEAKREF, "weakptr")
- return -1
-
-def gc_pointers_inside(v, adr):
- t = lltype.typeOf(v)
- if isinstance(t, lltype.Struct):
- for n, t2 in t._flds.iteritems():
- if isinstance(t2, lltype.Ptr) and t2.TO._gckind == 'gc':
- yield adr + llmemory.offsetof(t, n)
- elif isinstance(t2, (lltype.Array, lltype.Struct)):
- for a in gc_pointers_inside(getattr(v, n),
- adr + llmemory.offsetof(t, n)):
- yield a
- elif isinstance(t, lltype.Array):
- if isinstance(t.OF, lltype.Ptr) and t.OF.TO._gckind == 'gc':
- for i in range(len(v.items)):
- yield adr + llmemory.itemoffsetof(t, i)
- elif isinstance(t.OF, lltype.Struct):
- for i in range(len(v.items)):
- for a in gc_pointers_inside(v.items[i],
- adr + llmemory.itemoffsetof(t, i)):
- yield a
-
+ return -1
-def mutable_gc_pointers_inside(v, adr):
+def gc_pointers_inside(v, adr, mutable_only=True):
t = lltype.typeOf(v)
if isinstance(t, lltype.Struct):
- if t._hints.get('immutable'):
+ if mutable_only and t._hints.get('immutable'):
return
for n, t2 in t._flds.iteritems():
if isinstance(t2, lltype.Ptr) and t2.TO._gckind == 'gc':
yield adr + llmemory.offsetof(t, n)
elif isinstance(t2, (lltype.Array, lltype.Struct)):
- for a in mutable_gc_pointers_inside(getattr(v, n),
- adr + llmemory.offsetof(t, n)):
+ for a in gc_pointers_inside(getattr(v, n),
+ adr + llmemory.offsetof(t, n),
+ mutable_only):
yield a
elif isinstance(t, lltype.Array):
- if t._hints.get('immutable'):
+ if mutable_only and t._hints.get('immutable'):
return
if isinstance(t.OF, lltype.Ptr) and t.OF.TO._gckind == 'gc':
for i in range(len(v.items)):
yield adr + llmemory.itemoffsetof(t, i)
elif isinstance(t.OF, lltype.Struct):
for i in range(len(v.items)):
- for a in mutable_gc_pointers_inside(v.items[i],
- adr + llmemory.itemoffsetof(t, i)):
+ for a in gc_pointers_inside(v.items[i],
+ adr + llmemory.itemoffsetof(t, i),
+ mutable_only):
yield a
def zero_gc_pointers(p):
More information about the Pypy-commit
mailing list