Exemple #1
0
def test_constfold():
    layoutbuilder = TypeLayoutBuilder(FakeGC)
    tid1 = layoutbuilder.get_type_id(GC_A)
    tid2 = layoutbuilder.get_type_id(GC_S3)
    class MockGC:
        def set_query_functions(self, is_varsize,
                                has_gcptr_in_varsize,
                                is_gcarrayofgcptr,
                                *rest):
            self.is_varsize = is_varsize
            self.has_gcptr_in_varsize = has_gcptr_in_varsize
            self.is_gcarrayofgcptr = is_gcarrayofgcptr
    gc = MockGC()
    layoutbuilder.initialize_gc_query_function(gc)
    #
    def f():
        return (1 * gc.is_varsize(tid1) +
               10 * gc.has_gcptr_in_varsize(tid1) +
              100 * gc.is_gcarrayofgcptr(tid1) +
             1000 * gc.is_varsize(tid2) +
            10000 * gc.has_gcptr_in_varsize(tid2) +
           100000 * gc.is_gcarrayofgcptr(tid2))
    interp, graph = get_interpreter(f, [], backendopt=True)
    assert interp.eval_graph(graph, []) == 11001
    assert graph.startblock.exits[0].args == [Constant(11001, lltype.Signed)]
Exemple #2
0
def test_layout_builder(lltype2vtable=None):
    # XXX a very minimal test
    layoutbuilder = TypeLayoutBuilder(FakeGC, lltype2vtable)
    for T1, T2 in [(GC_A, GC_S), (GC_A2, GC_S2), (GC_S3, GC_S2)]:
        tid1 = layoutbuilder.get_type_id(T1)
        tid2 = layoutbuilder.get_type_id(T2)
        gcdata = GCData(layoutbuilder.type_info_group)
        lst1 = gcdata.q_varsize_offsets_to_gcpointers_in_var_part(tid1)
        lst2 = gcdata.q_offsets_to_gc_pointers(tid2)
        assert len(lst1) == len(lst2)
    return layoutbuilder
Exemple #3
0
def test_layout_builder(lltype2vtable=None):
    # XXX a very minimal test
    layoutbuilder = TypeLayoutBuilder(FakeGC, lltype2vtable)
    for T1, T2 in [(GC_A, GC_S), (GC_A2, GC_S2), (GC_S3, GC_S2)]:
        tid1 = layoutbuilder.get_type_id(T1)
        tid2 = layoutbuilder.get_type_id(T2)
        gcdata = GCData(layoutbuilder.type_info_group)
        lst1 = gcdata.q_varsize_offsets_to_gcpointers_in_var_part(tid1)
        lst2 = gcdata.q_offsets_to_gc_pointers(tid2)
        assert len(lst1) == len(lst2)
    return layoutbuilder
Exemple #4
0
class BaseDirectGCTest(object):
    GC_PARAMS = {}

    def get_extra_gc_params(self):
        return {}

    def setup_method(self, meth):
        from rpython.config.translationoption import get_combined_translation_config
        config = get_combined_translation_config(translating=True).translation
        self.stackroots = []
        GC_PARAMS = self.GC_PARAMS.copy()
        if hasattr(meth, 'GC_PARAMS'):
            GC_PARAMS.update(meth.GC_PARAMS)
        GC_PARAMS['translated_to_c'] = False
        GC_PARAMS.update(self.get_extra_gc_params())
        self.gc = self.GCClass(config, **GC_PARAMS)
        self.gc.DEBUG = True
        self.rootwalker = DirectRootWalker(self)
        self.gc.set_root_walker(self.rootwalker)
        self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
        self.get_type_id = self.layoutbuilder.get_type_id
        gcdata = self.layoutbuilder.initialize_gc_query_function(self.gc)
        ll_handlers = lltype.malloc(FIN_HANDLER_ARRAY, 0, immortal=True)
        gcdata.finalizer_handlers = llmemory.cast_ptr_to_adr(ll_handlers)
        self.gc.setup()

    def consider_constant(self, p):
        obj = p._obj
        TYPE = lltype.typeOf(obj)
        self.layoutbuilder.consider_constant(TYPE, obj, self.gc)

    def write(self, p, fieldname, newvalue):
        if self.gc.needs_write_barrier:
            addr_struct = llmemory.cast_ptr_to_adr(p)
            self.gc.write_barrier(addr_struct)
        setattr(p, fieldname, newvalue)

    def writearray(self, p, index, newvalue):
        if self.gc.needs_write_barrier:
            addr_struct = llmemory.cast_ptr_to_adr(p)
            if hasattr(self.gc, 'write_barrier_from_array'):
                self.gc.write_barrier_from_array(addr_struct, index)
            else:
                self.gc.write_barrier(addr_struct)
        p[index] = newvalue

    def malloc(self, TYPE, n=None):
        addr = self.gc.malloc(self.get_type_id(TYPE), n)
        debug_print(self.gc)
        obj_ptr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
        if not self.gc.malloc_zero_filled:
            zero_gc_pointers_inside(obj_ptr, TYPE)
        return obj_ptr
Exemple #5
0
class BaseDirectGCTest(object):
    GC_PARAMS = {}

    def setup_method(self, meth):
        from rpython.config.translationoption import get_combined_translation_config
        config = get_combined_translation_config(translating=True).translation
        self.stackroots = []
        GC_PARAMS = self.GC_PARAMS.copy()
        if hasattr(meth, 'GC_PARAMS'):
            GC_PARAMS.update(meth.GC_PARAMS)
        GC_PARAMS['translated_to_c'] = False
        self.gc = self.GCClass(config, **GC_PARAMS)
        self.gc.DEBUG = True
        self.rootwalker = DirectRootWalker(self)
        self.gc.set_root_walker(self.rootwalker)
        self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
        self.get_type_id = self.layoutbuilder.get_type_id
        gcdata = self.layoutbuilder.initialize_gc_query_function(self.gc)
        ll_handlers = lltype.malloc(FIN_HANDLER_ARRAY, 0, immortal=True)
        gcdata.finalizer_handlers = llmemory.cast_ptr_to_adr(ll_handlers)
        self.gc.setup()

    def consider_constant(self, p):
        obj = p._obj
        TYPE = lltype.typeOf(obj)
        self.layoutbuilder.consider_constant(TYPE, obj, self.gc)

    def write(self, p, fieldname, newvalue):
        if self.gc.needs_write_barrier:
            addr_struct = llmemory.cast_ptr_to_adr(p)
            self.gc.write_barrier(addr_struct)
        setattr(p, fieldname, newvalue)

    def writearray(self, p, index, newvalue):
        if self.gc.needs_write_barrier:
            addr_struct = llmemory.cast_ptr_to_adr(p)
            if hasattr(self.gc, 'write_barrier_from_array'):
                self.gc.write_barrier_from_array(addr_struct, index)
            else:
                self.gc.write_barrier(addr_struct)
        p[index] = newvalue

    def malloc(self, TYPE, n=None):
        addr = self.gc.malloc(self.get_type_id(TYPE), n)
        debug_print(self.gc)
        obj_ptr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
        if not self.gc.malloc_zero_filled:
            zero_gc_pointers_inside(obj_ptr, TYPE)
        return obj_ptr
Exemple #6
0
 def setup_method(self, meth):
     from rpython.config.translationoption import get_combined_translation_config
     config = get_combined_translation_config(translating=True).translation
     self.stackroots = []
     GC_PARAMS = self.GC_PARAMS.copy()
     if hasattr(meth, 'GC_PARAMS'):
         GC_PARAMS.update(meth.GC_PARAMS)
     GC_PARAMS['translated_to_c'] = False
     self.gc = self.GCClass(config, **GC_PARAMS)
     self.gc.DEBUG = True
     self.rootwalker = DirectRootWalker(self)
     self.gc.set_root_walker(self.rootwalker)
     self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
     self.get_type_id = self.layoutbuilder.get_type_id
     self.layoutbuilder.initialize_gc_query_function(self.gc)
     self.gc.setup()
Exemple #7
0
 def setup_method(self, meth):
     from rpython.config.translationoption import get_combined_translation_config
     config = get_combined_translation_config(translating=True).translation
     self.stackroots = []
     GC_PARAMS = self.GC_PARAMS.copy()
     if hasattr(meth, 'GC_PARAMS'):
         GC_PARAMS.update(meth.GC_PARAMS)
     GC_PARAMS['translated_to_c'] = False
     self.gc = self.GCClass(config, **GC_PARAMS)
     self.gc.DEBUG = True
     self.rootwalker = DirectRootWalker(self)
     self.gc.set_root_walker(self.rootwalker)
     self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
     self.get_type_id = self.layoutbuilder.get_type_id
     gcdata = self.layoutbuilder.initialize_gc_query_function(self.gc)
     ll_handlers = lltype.malloc(FIN_HANDLER_ARRAY, 0, immortal=True)
     gcdata.finalizer_handlers = llmemory.cast_ptr_to_adr(ll_handlers)
     self.gc.setup()
Exemple #8
0
def test_constfold():
    layoutbuilder = TypeLayoutBuilder(FakeGC)
    tid1 = layoutbuilder.get_type_id(GC_A)
    tid2 = layoutbuilder.get_type_id(GC_S3)

    class MockGC:
        def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
                                is_gcarrayofgcptr, *rest):
            self.is_varsize = is_varsize
            self.has_gcptr_in_varsize = has_gcptr_in_varsize
            self.is_gcarrayofgcptr = is_gcarrayofgcptr

    gc = MockGC()
    layoutbuilder.initialize_gc_query_function(gc)

    #
    def f():
        return (1 * gc.is_varsize(tid1) + 10 * gc.has_gcptr_in_varsize(tid1) +
                100 * gc.is_gcarrayofgcptr(tid1) + 1000 * gc.is_varsize(tid2) +
                10000 * gc.has_gcptr_in_varsize(tid2) +
                100000 * gc.is_gcarrayofgcptr(tid2))

    interp, graph = get_interpreter(f, [], backendopt=True)
    assert interp.eval_graph(graph, []) == 11001
    assert graph.startblock.exits[0].args == [Constant(11001, lltype.Signed)]
Exemple #9
0
 def setup_method(self, meth):
     from rpython.config.translationoption import get_combined_translation_config
     config = get_combined_translation_config(translating=True).translation
     self.stackroots = []
     GC_PARAMS = self.GC_PARAMS.copy()
     if hasattr(meth, 'GC_PARAMS'):
         GC_PARAMS.update(meth.GC_PARAMS)
     GC_PARAMS['translated_to_c'] = False
     self.gc = self.GCClass(config, **GC_PARAMS)
     self.gc.DEBUG = True
     self.rootwalker = DirectRootWalker(self)
     self.gc.set_root_walker(self.rootwalker)
     self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
     self.get_type_id = self.layoutbuilder.get_type_id
     self.layoutbuilder.initialize_gc_query_function(self.gc)
     self.gc.setup()
Exemple #10
0
 def setup_method(self, meth):
     from rpython.config.translationoption import get_combined_translation_config
     config = get_combined_translation_config(translating=True).translation
     self.stackroots = []
     GC_PARAMS = self.GC_PARAMS.copy()
     if hasattr(meth, 'GC_PARAMS'):
         GC_PARAMS.update(meth.GC_PARAMS)
     GC_PARAMS['translated_to_c'] = False
     self.gc = self.GCClass(config, **GC_PARAMS)
     self.gc.DEBUG = True
     self.rootwalker = DirectRootWalker(self)
     self.gc.set_root_walker(self.rootwalker)
     self.layoutbuilder = TypeLayoutBuilder(self.GCClass)
     self.get_type_id = self.layoutbuilder.get_type_id
     gcdata = self.layoutbuilder.initialize_gc_query_function(self.gc)
     ll_handlers = lltype.malloc(FIN_HANDLER_ARRAY, 0, immortal=True)
     gcdata.finalizer_handlers = llmemory.cast_ptr_to_adr(ll_handlers)
     self.gc.setup()