[pypy-svn] r28968 - pypy/dist/pypy/rpython/memory
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Jun 19 21:35:33 CEST 2006
Author: cfbolz
Date: Mon Jun 19 21:35:32 2006
New Revision: 28968
Modified:
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/gctransform.py
Log:
check at transformation time (instead of at runtime) whether a malloced object
needs a finalizer. tested a translation with this. seems to be slightly faster
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Mon Jun 19 21:35:32 2006
@@ -157,18 +157,19 @@
def malloc(self, typeid, length=0):
size = self.fixed_size(typeid)
+ needs_finalizer = bool(self.getfinalizer(typeid))
if self.is_varsize(typeid):
itemsize = self.varsize_item_sizes(typeid)
offset_to_length = self.varsize_offset_to_length(typeid)
ref = self.malloc_varsize(typeid, length, size, itemsize,
- offset_to_length, True)
+ offset_to_length, True, needs_finalizer)
else:
- ref = self.malloc_fixedsize(typeid, size, True)
+ ref = self.malloc_fixedsize(typeid, size, True, needs_finalizer)
# XXX lots of cast and reverse-cast around, but this malloc()
# should eventually be killed
return llmemory.cast_ptr_to_adr(ref)
- def malloc_fixedsize(self, typeid, size, can_collect):
+ def malloc_fixedsize(self, typeid, size, can_collect, has_finalizer=False):
if can_collect and self.bytes_malloced > self.bytes_malloced_threshold:
self.collect()
size_gc_header = self.gcheaderbuilder.size_gc_header
@@ -182,18 +183,18 @@
result = raw_malloc(tot_size)
hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
hdr.typeid = typeid << 1
- if not self.getfinalizer(typeid):
- hdr.next = self.malloced_objects
- self.malloced_objects = hdr
- else:
+ if has_finalizer:
hdr.next = self.malloced_objects_with_finalizer
self.malloced_objects_with_finalizer = hdr
+ else:
+ hdr.next = self.malloced_objects
+ self.malloced_objects = hdr
self.bytes_malloced = bytes_malloced
result += size_gc_header
return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
def malloc_varsize(self, typeid, length, size, itemsize, offset_to_length,
- can_collect):
+ can_collect, has_finalizer=False):
if can_collect and self.bytes_malloced > self.bytes_malloced_threshold:
self.collect()
size_gc_header = self.gcheaderbuilder.size_gc_header
@@ -210,12 +211,12 @@
(result + size_gc_header + offset_to_length).signed[0] = length
hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
hdr.typeid = typeid << 1
- if not self.getfinalizer(typeid):
- hdr.next = self.malloced_objects
- self.malloced_objects = hdr
- else:
+ if has_finalizer:
hdr.next = self.malloced_objects_with_finalizer
self.malloced_objects_with_finalizer = hdr
+ else:
+ hdr.next = self.malloced_objects
+ self.malloced_objects = hdr
self.bytes_malloced = bytes_malloced
result += size_gc_header
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Mon Jun 19 21:35:32 2006
@@ -914,12 +914,12 @@
GCClass.malloc_fixedsize.im_func,
[s_gc, annmodel.SomeInteger(nonneg=True),
annmodel.SomeInteger(nonneg=True),
- annmodel.SomeBool()], s_gcref,
+ annmodel.SomeBool(), annmodel.SomeBool()], s_gcref,
inline = False)
self.malloc_varsize_ptr = getfn(
GCClass.malloc_varsize.im_func,
[s_gc] + [annmodel.SomeInteger(nonneg=True) for i in range(5)]
- + [annmodel.SomeBool()], s_gcref)
+ + [annmodel.SomeBool(), annmodel.SomeBool()], s_gcref)
self.collect_ptr = getfn(GCClass.collect.im_func,
[s_gc], annmodel.s_None)
@@ -1214,6 +1214,9 @@
args = [self.malloc_varsize_ptr, self.c_const_gc, c_type_id,
v_length, c_size, c_varitemsize, c_ofstolength,
c_can_collect]
+ c_has_finalizer = rmodel.inputconst(
+ lltype.Bool, bool(self.finalizer_funcptr_for_type(TYPE)))
+ args.append(c_has_finalizer)
v = varoftype(llmemory.GCREF)
newop = SpaceOperation("direct_call", args, v)
ops, index = self.protect_roots(newop, livevars, block,
More information about the Pypy-commit
mailing list