[pypy-svn] r47658 - pypy/dist/pypy/rpython/memory/gc
arigo at codespeak.net
arigo at codespeak.net
Sat Oct 20 23:22:29 CEST 2007
Author: arigo
Date: Sat Oct 20 23:22:29 2007
New Revision: 47658
Modified:
pypy/dist/pypy/rpython/memory/gc/generation.py
pypy/dist/pypy/rpython/memory/gc/semispace.py
Log:
Replace the default_gcflags class attribute with method overriding that
changes the default value of an argument. I think none of the two
approaches is much stranger than the other, and this version might allow
better constant-propagation.
Modified: pypy/dist/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/dist/pypy/rpython/memory/gc/generation.py Sat Oct 20 23:22:29 2007
@@ -20,7 +20,6 @@
"""
inline_simple_malloc = True
needs_write_barrier = True
- default_gcflags = GCFLAG_NO_YOUNG_PTRS # for old and static objects
def __init__(self, AddressLinkedList,
nursery_size=128,
@@ -70,7 +69,8 @@
if raw_malloc_usage(totalsize) > self.nursery_top - result:
result = self.collect_nursery()
llarena.arena_reserve(result, totalsize)
- self.init_young_gc_object(result, typeid)
+ # GCFLAG_NO_YOUNG_PTRS is never set on young objs
+ self.init_gc_object(result, typeid, flags=0)
self.nursery_free = result + totalsize
if contains_weakptr:
self.young_objects_with_weakrefs.append(result + size_gc_header)
@@ -94,15 +94,20 @@
if raw_malloc_usage(totalsize) > self.nursery_top - result:
result = self.collect_nursery()
llarena.arena_reserve(result, totalsize)
- self.init_young_gc_object(result, typeid)
+ # GCFLAG_NO_YOUNG_PTRS is never set on young objs
+ self.init_gc_object(result, typeid, flags=0)
(result + size_gc_header + offset_to_length).signed[0] = length
self.nursery_free = result + llarena.round_up_for_allocation(totalsize)
return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
- def init_young_gc_object(self, addr, typeid):
- hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
- #hdr.forw = NULL -- unneeded, the space is initially filled with zero
- hdr.tid = typeid # GCFLAG_NO_YOUNG_PTRS is never set on young objs
+ # override the init_gc_object methods to change the default value of 'flags',
+ # used by objects that are directly created outside the nursery by the SemiSpaceGC.
+ # These objects must have the GCFLAG_NO_YOUNG_PTRS flag set immediately.
+ def init_gc_object(self, addr, typeid, flags=GCFLAG_NO_YOUNG_PTRS):
+ SemiSpaceGC.init_gc_object(self, addr, typeid, flags)
+
+ def init_gc_object_immortal(self, addr, typeid, flags=GCFLAG_NO_YOUNG_PTRS):
+ SemiSpaceGC.init_gc_object_immortal(self, addr, typeid, flags)
def semispace_collect(self, size_changing=False):
self.reset_young_gcflags() # we are doing a full collection anyway
Modified: pypy/dist/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/semispace.py (original)
+++ pypy/dist/pypy/rpython/memory/gc/semispace.py Sat Oct 20 23:22:29 2007
@@ -20,7 +20,6 @@
class SemiSpaceGC(MovingGCBase):
_alloc_flavor_ = "raw"
inline_simple_malloc = True
- default_gcflags = 0
HDR = lltype.Struct('header', ('forw', llmemory.Address),
('tid', lltype.Signed))
@@ -215,9 +214,8 @@
# Objects not living the GC heap have all been initialized by
# setting their 'forw' address so that it points to themselves.
# The logic below will thus simply return 'obj' if 'obj' is prebuilt.
-## print "copying regularly", obj,
if self.is_forwarded(obj):
-## print "already copied to", self.get_forwarding_address(obj)
+ #llop.debug_print(lltype.Void, obj, "already copied to", self.get_forwarding_address(obj))
return self.get_forwarding_address(obj)
else:
newaddr = self.free
@@ -226,7 +224,9 @@
raw_memcopy(obj - self.size_gc_header(), newaddr, totalsize)
self.free += totalsize
newobj = newaddr + self.size_gc_header()
-## print "to", newobj
+ #llop.debug_print(lltype.Void, obj, "copied to", newobj,
+ # "tid", self.header(obj).tid,
+ # "size", totalsize)
self.set_forwarding_address(obj, newobj)
return newobj
@@ -283,15 +283,15 @@
def get_type_id(self, addr):
return self.header(addr).tid & TYPEID_MASK
- def init_gc_object(self, addr, typeid):
+ def init_gc_object(self, addr, typeid, flags=0):
hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
#hdr.forw = NULL -- unneeded, the space is initially filled with zero
- hdr.tid = typeid | self.default_gcflags
+ hdr.tid = typeid | flags
- def init_gc_object_immortal(self, addr, typeid):
+ def init_gc_object_immortal(self, addr, typeid, flags=0):
# immortal objects always have forward to themselves
hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
- hdr.tid = typeid | self.default_gcflags | GCFLAG_IMMORTAL
+ hdr.tid = typeid | flags | GCFLAG_IMMORTAL
self.init_forwarding(addr + self.gcheaderbuilder.size_gc_header)
def init_forwarding(self, obj):
More information about the Pypy-commit
mailing list