[pypy-svn] r51790 - in pypy/branch/unified-rtti/pypy: rpython/memory rpython/memory/gctransform translator/c
arigo at codespeak.net
arigo at codespeak.net
Fri Feb 22 13:49:06 CET 2008
Author: arigo
Date: Fri Feb 22 13:49:05 2008
New Revision: 51790
Modified:
pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py
pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py
pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py
pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py
pypy/branch/unified-rtti/pypy/rpython/memory/gctypelayout.py
pypy/branch/unified-rtti/pypy/rpython/memory/gcwrapper.py
pypy/branch/unified-rtti/pypy/translator/c/gc.py
Log:
Progress on the framework gc transformer.
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py Fri Feb 22 13:49:05 2008
@@ -92,7 +92,7 @@
if TYPE in self.finalizer_funcptrs:
return self.finalizer_funcptrs[TYPE]
- rtti = lltype.getRuntimeTypeInfo(TYPE, self.rtticache)
+ rtti = self.gcheaderbuilder.getRtti(TYPE)
destrptr = rtti.destructor_funcptr
if destrptr is not None:
DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py Fri Feb 22 13:49:05 2008
@@ -1,4 +1,4 @@
-from pypy.rpython.memory.gctransform.transform import GCTransformer
+from pypy.rpython.memory.gctransform.transform import GCTransformer, RTTIPTR
from pypy.rpython.memory.gctransform.support import find_gc_ptrs_in_type, \
ll_call_destructor, type_contains_pyobjs, var_ispyobj
from pypy.rpython.lltypesystem import lltype, llmemory
@@ -107,14 +107,13 @@
# for regular translation: pick the GC from the config
GCClass, GC_PARAMS = choose_gc_from_config(translator.config)
+ gc = GCClass(**GC_PARAMS)
+ self.setgcheaderbuilder(gc.gcheaderbuilder)
self.layoutbuilder = TransformerLayoutBuilder(self)
self.get_type_id = self.layoutbuilder.get_type_id
- # set up dummy a table, to be overwritten with the real one in finish()
- type_info_table = lltype._ptr(
- lltype.Ptr(gctypelayout.GCData.TYPE_INFO_TABLE),
- "delayed!type_info_table", solid=True)
- gcdata = gctypelayout.GCData(type_info_table)
+ gcdata = gctypelayout.GCData(self.gcheaderbuilder)
+ gcdata.gc = gc
# initialize the following two fields with a random non-NULL address,
# to make the annotator happy. The fields are patched in finish()
@@ -128,7 +127,6 @@
self.gcdata = gcdata
self.malloc_fnptr_cache = {}
- gcdata.gc = GCClass(**GC_PARAMS)
root_walker = self.build_root_walker()
gcdata.set_query_functions(gcdata.gc)
gcdata.gc.set_root_walker(root_walker)
@@ -190,7 +188,7 @@
malloc_fixedsize_clear_meth = GCClass.malloc_fixedsize_clear.im_func
self.malloc_fixedsize_clear_ptr = getfn(
malloc_fixedsize_clear_meth,
- [s_gc, annmodel.SomeInteger(nonneg=True),
+ [s_gc, annmodel.SomePtr(RTTIPTR),
annmodel.SomeInteger(nonneg=True),
annmodel.SomeBool(), annmodel.SomeBool(),
annmodel.SomeBool()], s_gcref,
@@ -199,7 +197,7 @@
malloc_fixedsize_meth = GCClass.malloc_fixedsize.im_func
self.malloc_fixedsize_ptr = getfn(
malloc_fixedsize_meth,
- [s_gc, annmodel.SomeInteger(nonneg=True),
+ [s_gc, annmodel.SomePtr(RTTIPTR),
annmodel.SomeInteger(nonneg=True),
annmodel.SomeBool(), annmodel.SomeBool(),
annmodel.SomeBool()], s_gcref,
@@ -207,13 +205,10 @@
else:
malloc_fixedsize_meth = None
self.malloc_fixedsize_ptr = self.malloc_fixedsize_clear_ptr
-## self.malloc_varsize_ptr = getfn(
-## GCClass.malloc_varsize.im_func,
-## [s_gc] + [annmodel.SomeInteger(nonneg=True) for i in range(5)]
-## + [annmodel.SomeBool(), annmodel.SomeBool()], s_gcref)
self.malloc_varsize_clear_ptr = getfn(
GCClass.malloc_varsize_clear.im_func,
- [s_gc] + [annmodel.SomeInteger(nonneg=True) for i in range(5)]
+ [s_gc, annmodel.SomePtr(RTTIPTR)]
+ + [annmodel.SomeInteger(nonneg=True) for i in range(4)]
+ [annmodel.SomeBool(), annmodel.SomeBool()], s_gcref)
self.collect_ptr = getfn(GCClass.collect.im_func,
[s_gc], annmodel.s_None)
@@ -256,7 +251,7 @@
s_True = annmodel.SomeBool(); s_True .const = True
self.malloc_varsize_clear_fast_ptr = getfn(
malloc_varsize_clear_fast,
- [s_gc, annmodel.SomeInteger(nonneg=True),
+ [s_gc, annmodel.SomePtr(RTTIPTR),
annmodel.SomeInteger(nonneg=True),
annmodel.SomeInteger(nonneg=True),
annmodel.SomeInteger(nonneg=True),
@@ -340,7 +335,7 @@
return self.layoutbuilder.finalizer_funcptr_for_type(TYPE)
def finish_tables(self):
- table = self.layoutbuilder.flatten_table()
+ table = self.layoutbuilder.id_of_type
log.info("assigned %s typeids" % (len(table), ))
log.info("added %s push/pop stack root instructions" % (
self.num_pushs, ))
@@ -348,13 +343,6 @@
log.info("inserted %s write barrier calls" % (
self.write_barrier_calls, ))
- # replace the type_info_table pointer in gcdata -- at this point,
- # the database is in principle complete, so it has already seen
- # the delayed pointer. We need to force it to consider the new
- # array now.
-
- self.gcdata.type_info_table._become(table)
-
# XXX because we call inputconst already in replace_malloc, we can't
# modify the instance, we have to modify the 'rtyped instance'
# instead. horrors. is there a better way?
@@ -388,13 +376,15 @@
def write_typeid_list(self):
"""write out the list of type ids together with some info"""
from pypy.tool.udir import udir
+ # for debugging, we put unique numbers in typeinfo.flags
+ lines = []
+ for TYPE, typeid in self.layoutbuilder.id_of_type.iteritems():
+ typeinfo = self.gcheaderbuilder.cast_rtti_to_typeinfo(typeid)
+ lines.append("%6d %s\n" % (typeinfo.flags, TYPE))
+ lines.sort()
# XXX not ideal since it is not per compilation, but per run
f = udir.join("typeids.txt").open("w")
- all = [(typeid, TYPE)
- for TYPE, typeid in self.layoutbuilder.id_of_type.iteritems()]
- all.sort()
- for typeid, TYPE in all:
- f.write("%s %s\n" % (typeid, TYPE))
+ f.writelines(lines)
f.close()
def transform_graph(self, graph):
@@ -424,8 +414,8 @@
assert PTRTYPE.TO == TYPE
type_id = self.get_type_id(TYPE)
- c_type_id = rmodel.inputconst(lltype.Signed, type_id)
- info = self.layoutbuilder.type_info_list[type_id]
+ c_type_id = rmodel.inputconst(RTTIPTR, type_id)
+ info = self.gcheaderbuilder.cast_rtti_to_typeinfo(type_id)
c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
has_finalizer = bool(self.finalizer_funcptr_for_type(TYPE))
c_has_finalizer = rmodel.inputconst(lltype.Bool, has_finalizer)
@@ -475,8 +465,8 @@
assert PTRTYPE.TO == TYPE
type_id = self.get_type_id(TYPE)
- c_type_id = rmodel.inputconst(lltype.Signed, type_id)
- info = self.layoutbuilder.type_info_list[type_id]
+ c_type_id = rmodel.inputconst(RTTIPTR, type_id)
+ info = self.gcheaderbuilder.cast_rtti_to_typeinfo(type_id)
c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
has_finalizer = bool(self.finalizer_funcptr_for_type(TYPE))
assert not has_finalizer
@@ -540,8 +530,8 @@
type_id = self.get_type_id(WEAKREF)
- c_type_id = rmodel.inputconst(lltype.Signed, type_id)
- info = self.layoutbuilder.type_info_list[type_id]
+ c_type_id = rmodel.inputconst(RTTIPTR, type_id)
+ info = self.gcheaderbuilder.cast_rtti_to_typeinfo(type_id)
c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
malloc_ptr = self.malloc_fixedsize_ptr
c_has_finalizer = rmodel.inputconst(lltype.Bool, False)
@@ -682,17 +672,17 @@
class TransformerLayoutBuilder(gctypelayout.TypeLayoutBuilder):
def __init__(self, transformer):
- super(TransformerLayoutBuilder, self).__init__()
+ self.gcheaderbuilder = transformer.gcheaderbuilder
+ super(TransformerLayoutBuilder, self).__init__(self.gcheaderbuilder)
self.transformer = transformer
self.offsettable_cache = {}
def make_finalizer_funcptr_for_type(self, TYPE):
- rtti = get_rtti(TYPE)
- if rtti is not None and hasattr(rtti._obj, 'destructor_funcptr'):
- destrptr = rtti._obj.destructor_funcptr
+ rtti = self.gcheaderbuilder.getRtti(TYPE)
+ destrptr = rtti.destructor_funcptr
+ if destrptr is not None:
DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
else:
- destrptr = None
DESTR_ARG = None
assert not type_contains_pyobjs(TYPE), "not implemented"
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py Fri Feb 22 13:49:05 2008
@@ -148,7 +148,7 @@
llops.genop("direct_call", [self.decrefptr, v_adr])
def gct_fv_gc_malloc(self, hop, flags, TYPE, c_size):
- rtti = self.gcheaderbuilder.getTypeInfo(TYPE)
+ rtti = self.gcheaderbuilder.getRtti(TYPE)
c_rtti = rmodel.inputconst(RTTIPTR, rtti)
v_raw = hop.genop("direct_call",
[self.malloc_fixedsize_ptr, c_size, c_rtti],
@@ -157,7 +157,7 @@
def gct_fv_gc_malloc_varsize(self, hop, flags, TYPE, v_length, c_const_size, c_item_size,
c_offset_to_length):
- rtti = self.gcheaderbuilder.getTypeInfo(TYPE)
+ rtti = self.gcheaderbuilder.getRtti(TYPE)
c_rtti = rmodel.inputconst(RTTIPTR, rtti)
if c_offset_to_length is None:
v_raw = hop.genop("direct_call",
@@ -187,7 +187,7 @@
return # you don't really have an RPython deallocator for PyObjects
assert TYPE._gckind == 'gc'
- rtti = self.gcheaderbuilder.getTypeInfo(TYPE)
+ rtti = self.gcheaderbuilder.getRtti(TYPE)
destrptr = rtti.destructor_funcptr
if destrptr is not None:
DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py Fri Feb 22 13:49:05 2008
@@ -682,7 +682,7 @@
p = value._as_ptr()
if not self.gcheaderbuilder.get_header(p):
hdr = self.gcheaderbuilder.new_header(p)
- hdr.typeptr = self.gcheaderbuilder.getTypeInfo(TYPE)
+ hdr.typeptr = self.gcheaderbuilder.getRtti(TYPE)
self.initialize_constant_header(hdr, TYPE, value)
def initialize_constant_header(self, hdr, TYPE, value):
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctypelayout.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctypelayout.py Fri Feb 22 13:49:05 2008
@@ -129,6 +129,10 @@
"""Encode the shape of the TYPE into the TYPE_INFO structure 'info'."""
offsets = offsets_to_gc_pointers(TYPE)
info.flags = get_type_flags(TYPE)
+ # for debugging, we also encode a unique non-zero identifier in the .flags
+ builder.idcount += 1
+ info.flags += T_first_unused_bit * builder.idcount
+
info.ofstoptrs = builder.offsets2table(offsets, TYPE)
info.finalizer = builder.make_finalizer_funcptr_for_type(TYPE)
info.weakptrofs = weakpointer_offset(TYPE)
@@ -169,6 +173,7 @@
def __init__(self, gcheaderbuilder):
self.id_of_type = {} # {LLTYPE: fully-initialized-RTTIPTR}
+ self.idcount = 0
self.seen_roots = {}
# the following are lists of addresses of gc pointers living inside the
# prebuilt structures. It should list all the locations that could
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gcwrapper.py Fri Feb 22 13:49:05 2008
@@ -86,8 +86,8 @@
# we have to be lazy in reading the llinterp variable containing
# the 'obj' pointer, because the gc.malloc() call below could
# move it around
- type_info = self.get_type_info(gctypelayout.WEAKREF)
- addr = self.gc.malloc(type_info, None, zero=False)
+ typeid = self.get_type_id(gctypelayout.WEAKREF)
+ addr = self.gc.malloc(typeid, None, zero=False)
result = llmemory.cast_adr_to_ptr(addr, gctypelayout.WEAKREFPTR)
result.weakptr = llmemory.cast_ptr_to_adr(objgetter())
return llmemory.cast_ptr_to_weakrefptr(result)
Modified: pypy/branch/unified-rtti/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/gc.py (original)
+++ pypy/branch/unified-rtti/pypy/translator/c/gc.py Fri Feb 22 13:49:05 2008
@@ -16,7 +16,7 @@
def common_gcheader_definition(self, defnode):
if defnode.db.gctransformer is not None:
- HDR = defnode.db.gctransformer.HDR
+ HDR = defnode.db.gctransformer.gcheaderbuilder.HDR
return [(name, HDR._flds[name]) for name in HDR._names]
else:
return []
@@ -25,7 +25,7 @@
if defnode.db.gctransformer is not None:
gct = defnode.db.gctransformer
hdr = gct.gcheaderbuilder.header_of_object(top_container(defnode.obj))
- HDR = gct.HDR
+ HDR = gct.gcheaderbuilder.HDR
return [getattr(hdr, fldname) for fldname in HDR._names]
else:
return []
@@ -59,7 +59,7 @@
# for rtti node
def get_real_rtti_type(self):
- return self.transformerclass.TYPEINFO
+ return self.db.gctransformer.gcheaderbuilder.TYPEINFO
def convert_rtti(self, obj):
return self.db.gctransformer.convert_rtti(obj)
More information about the Pypy-commit
mailing list