Ejemplo n.º 1
0
 def test_rewrite_assembler_nonstandard_array(self):
     # a non-standard array is a bit hard to get; e.g. GcArray(Float)
     # is like that on Win32, but not on Linux.  Build one manually...
     NONSTD = lltype.GcArray(lltype.Float)
     nonstd_descr = get_array_descr(self.gc_ll_descr, NONSTD)
     nonstd_descr.tid = 6464
     nonstd_descr.basesize = 64  # <= hacked
     nonstd_descr.itemsize = 8
     nonstd_descr_gcref = 123
     self.check_rewrite("""
         [i0, p1]
         p0 = new_array(i0, descr=nonstd_descr)
         setarrayitem_gc(p0, i0, p1)
         jump(i0)
     """,
                        """
         [i0, p1]
         p0 = call_malloc_gc(ConstClass(malloc_array_nonstandard), \
                             64, 8,                                \
                             %(nonstd_descr.lendescr.offset)d,     \
                             6464, i0,                             \
                             descr=malloc_array_nonstandard_descr)
         cond_call_gc_wb_array(p0, i0, descr=wbdescr)
         setarrayitem_gc(p0, i0, p1)
         jump(i0)
     """,
                        nonstd_descr=nonstd_descr)
Ejemplo n.º 2
0
 def test_rewrite_assembler_nonstandard_array(self):
     # a non-standard array is a bit hard to get; e.g. GcArray(Float)
     # is like that on Win32, but not on Linux.  Build one manually...
     NONSTD = lltype.GcArray(lltype.Float)
     nonstd_descr = get_array_descr(self.gc_ll_descr, NONSTD)
     nonstd_descr.tid = 6464
     nonstd_descr.basesize = 64      # <= hacked
     nonstd_descr.itemsize = 8
     nonstd_descr_gcref = 123
     self.check_rewrite("""
         [i0, p1]
         p0 = new_array(i0, descr=nonstd_descr)
         setarrayitem_gc(p0, i0, p1)
         jump(i0)
     """, """
         [i0, p1]
         p0 = call_malloc_gc(ConstClass(malloc_array_nonstandard), \
                             64, 8,                                \
                             %(nonstd_descr.lendescr.offset)d,     \
                             6464, i0,                             \
                             descr=malloc_array_nonstandard_descr)
         cond_call_gc_wb_array(p0, i0, descr=wbdescr)
         setarrayitem_gc(p0, i0, p1)
         jump(i0)
     """, nonstd_descr=nonstd_descr)
Ejemplo n.º 3
0
def test_boehm():
    gc_ll_descr = gc.GcLLDescr_boehm(None, None, None)
    #
    record = []
    prev_malloc_fn_ptr = gc_ll_descr.malloc_fn_ptr
    def my_malloc_fn_ptr(size):
        p = prev_malloc_fn_ptr(size)
        record.append((size, p))
        return p
    gc_ll_descr.malloc_fn_ptr = my_malloc_fn_ptr
    #
    # ---------- gc_malloc ----------
    S = lltype.GcStruct('S', ('x', lltype.Signed))
    sizedescr = descr.get_size_descr(gc_ll_descr, S)
    p = gc_ll_descr.gc_malloc(sizedescr)
    assert record == [(sizedescr.size, p)]
    del record[:]
    # ---------- gc_malloc_array ----------
    A = lltype.GcArray(lltype.Signed)
    arraydescr = descr.get_array_descr(gc_ll_descr, A)
    p = gc_ll_descr.gc_malloc_array(10, arraydescr)
    assert record == [(arraydescr.basesize +
                       10 * arraydescr.itemsize, p)]
    del record[:]
    # ---------- gc_malloc_str ----------
    p = gc_ll_descr.gc_malloc_str(10)
    basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR, False)
    assert record == [(basesize + 10 * itemsize, p)]
    del record[:]
    # ---------- gc_malloc_unicode ----------
    p = gc_ll_descr.gc_malloc_unicode(10)
    basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
                                                              False)
    assert record == [(basesize + 10 * itemsize, p)]
    del record[:]
Ejemplo n.º 4
0
def test_boehm():
    gc_ll_descr = gc.GcLLDescr_boehm(None, None, None)
    #
    record = []
    prev_malloc_fn_ptr = gc_ll_descr.malloc_fn_ptr
    def my_malloc_fn_ptr(size):
        p = prev_malloc_fn_ptr(size)
        record.append((size, p))
        return p
    gc_ll_descr.malloc_fn_ptr = my_malloc_fn_ptr
    #
    # ---------- gc_malloc ----------
    S = lltype.GcStruct('S', ('x', lltype.Signed))
    sizedescr = descr.get_size_descr(gc_ll_descr, S)
    p = gc_ll_descr.gc_malloc(sizedescr)
    assert record == [(sizedescr.size, p)]
    del record[:]
    # ---------- gc_malloc_array ----------
    A = lltype.GcArray(lltype.Signed)
    arraydescr = descr.get_array_descr(gc_ll_descr, A)
    p = gc_ll_descr.gc_malloc_array(10, arraydescr)
    assert record == [(arraydescr.basesize +
                       10 * arraydescr.itemsize, p)]
    del record[:]
    # ---------- gc_malloc_str ----------
    p = gc_ll_descr.gc_malloc_str(10)
    basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR, False)
    assert record == [(basesize + 10 * itemsize, p)]
    del record[:]
    # ---------- gc_malloc_unicode ----------
    p = gc_ll_descr.gc_malloc_unicode(10)
    basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
                                                              False)
    assert record == [(basesize + 10 * itemsize, p)]
    del record[:]
Ejemplo n.º 5
0
 def test_gc_malloc_array(self):
     A = lltype.GcArray(lltype.Signed)
     arraydescr = descr.get_array_descr(self.gc_ll_descr, A)
     p = self.gc_ll_descr.gc_malloc_array(10, arraydescr)
     assert self.llop1.record == [
         ("varsize", arraydescr.tid, 10, repr(arraydescr.basesize),
          repr(arraydescr.itemsize), repr(arraydescr.lendescr.offset), p)
     ]
Ejemplo n.º 6
0
 def test_gc_malloc_array(self):
     A = lltype.GcArray(lltype.Signed)
     arraydescr = descr.get_array_descr(self.gc_ll_descr, A)
     p = self.gc_ll_descr.gc_malloc_array(10, arraydescr)
     assert self.llop1.record == [("varsize", arraydescr.tid, 10,
                                   repr(arraydescr.basesize),
                                   repr(arraydescr.itemsize),
                                   repr(arraydescr.lendescr.offset),
                                   p)]
Ejemplo n.º 7
0
 def test_write_barrier_before_setinteriorfield_gc(self):
     S1 = lltype.GcStruct('S1')
     INTERIOR = lltype.GcArray(('z', lltype.Ptr(S1)))
     interiordescr = get_array_descr(self.gc_ll_descr, INTERIOR)
     interiordescr.tid = 1291
     interiorlendescr = interiordescr.lendescr
     interiorzdescr = get_interiorfield_descr(self.gc_ll_descr,
                                              INTERIOR, 'z')
     self.check_rewrite("""
         [p1, p2]
         setinteriorfield_gc(p1, 0, p2, descr=interiorzdescr)
         jump(p1, p2)
     """, """
         [p1, p2]
         cond_call_gc_wb_array(p1, 0, descr=wbdescr)
         setinteriorfield_gc(p1, 0, p2, descr=interiorzdescr)
         jump(p1, p2)
     """, interiorzdescr=interiorzdescr)
Ejemplo n.º 8
0
 def test_write_barrier_before_setinteriorfield_gc(self):
     S1 = lltype.GcStruct('S1')
     INTERIOR = lltype.GcArray(('z', lltype.Ptr(S1)))
     interiordescr = get_array_descr(self.gc_ll_descr, INTERIOR)
     interiordescr.tid = 1291
     interiorlendescr = interiordescr.lendescr
     interiorzdescr = get_interiorfield_descr(self.gc_ll_descr, INTERIOR,
                                              'z')
     self.check_rewrite("""
         [p1, p2]
         setinteriorfield_gc(p1, 0, p2, descr=interiorzdescr)
         jump(p1, p2)
     """,
                        """
         [p1, p2]
         cond_call_gc_wb_array(p1, 0, descr=wbdescr)
         setinteriorfield_gc(p1, 0, p2, descr=interiorzdescr)
         jump(p1, p2)
     """,
                        interiorzdescr=interiorzdescr)
Ejemplo n.º 9
0
Archivo: gc.py Proyecto: weijiwei/pypy
 def _setup_str(self):
     self.str_descr = get_array_descr(self, rstr.STR)
     self.unicode_descr = get_array_descr(self, rstr.UNICODE)
     self.str_hash_descr = get_field_descr(self, rstr.STR, 'hash')
     self.unicode_hash_descr = get_field_descr(self, rstr.UNICODE, 'hash')
Ejemplo n.º 10
0
Archivo: llmodel.py Proyecto: Mu-L/pypy
 def arraydescrof(self, A):
     return get_array_descr(self.gc_ll_descr, A)
Ejemplo n.º 11
0
Archivo: gc.py Proyecto: mozillazg/pypy
 def _setup_str(self):
     self.str_descr     = get_array_descr(self, rstr.STR)
     self.unicode_descr = get_array_descr(self, rstr.UNICODE)
     self.str_hash_descr     = get_field_descr(self, rstr.STR,     'hash')
     self.unicode_hash_descr = get_field_descr(self, rstr.UNICODE, 'hash')
Ejemplo n.º 12
0
    def check_rewrite(self, frm_operations, to_operations, **namespace):
        S = lltype.GcStruct('S', ('x', lltype.Signed),
                                 ('y', lltype.Signed))
        sdescr = get_size_descr(self.gc_ll_descr, S)
        sdescr.tid = 1234
        #
        T = lltype.GcStruct('T', ('y', lltype.Signed),
                                 ('z', lltype.Ptr(S)),
                                 ('t', lltype.Signed))
        tdescr = get_size_descr(self.gc_ll_descr, T)
        tdescr.tid = 5678
        tzdescr = get_field_descr(self.gc_ll_descr, T, 'z')
        #
        A = lltype.GcArray(lltype.Signed)
        adescr = get_array_descr(self.gc_ll_descr, A)
        adescr.tid = 4321
        alendescr = adescr.lendescr
        #
        B = lltype.GcArray(lltype.Char)
        bdescr = get_array_descr(self.gc_ll_descr, B)
        bdescr.tid = 8765
        blendescr = bdescr.lendescr
        #
        C = lltype.GcArray(lltype.Ptr(S))
        cdescr = get_array_descr(self.gc_ll_descr, C)
        cdescr.tid = 8111
        clendescr = cdescr.lendescr
        #
        E = lltype.GcStruct('Empty')
        edescr = get_size_descr(self.gc_ll_descr, E)
        edescr.tid = 9000
        #
        vtable_descr = self.gc_ll_descr.fielddescr_vtable
        O = lltype.GcStruct('O', ('parent', rclass.OBJECT),
                                 ('x', lltype.Signed))
        o_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
        register_known_gctype(self.cpu, o_vtable, O)
        #
        tiddescr = self.gc_ll_descr.fielddescr_tid
        wbdescr = self.gc_ll_descr.write_barrier_descr
        WORD = globals()['WORD']
        #
        strdescr     = self.gc_ll_descr.str_descr
        unicodedescr = self.gc_ll_descr.unicode_descr
        strlendescr     = strdescr.lendescr
        unicodelendescr = unicodedescr.lendescr

        casmdescr = JitCellToken()
        clt = FakeLoopToken()
        clt._ll_initial_locs = [0, 8]
        frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
        clt.frame_info = frame_info
        frame_info.jfi_frame_depth = 13
        frame_info.jfi_frame_size = 255
        framedescrs = self.gc_ll_descr.getframedescrs(self.cpu)
        framelendescr = framedescrs.arraydescr.lendescr
        jfi_frame_depth = framedescrs.jfi_frame_depth
        jfi_frame_size = framedescrs.jfi_frame_size
        jf_frame_info = framedescrs.jf_frame_info
        signedframedescr = self.cpu.signedframedescr
        floatframedescr = self.cpu.floatframedescr
        casmdescr.compiled_loop_token = clt
        tzdescr = None # noone cares
        #
        namespace.update(locals())
        #
        for funcname in self.gc_ll_descr._generated_functions:
            namespace[funcname] = self.gc_ll_descr.get_malloc_fn(funcname)
            namespace[funcname + '_descr'] = getattr(self.gc_ll_descr,
                                                     '%s_descr' % funcname)
        #
        ops = parse(frm_operations, namespace=namespace)
        expected = parse(to_operations % Evaluator(namespace),
                         namespace=namespace)
        operations = self.gc_ll_descr.rewrite_assembler(self.cpu,
                                                        ops.operations,
                                                        [])
        equaloplists(operations, expected.operations)
        lltype.free(frame_info, flavor='raw')
Ejemplo n.º 13
0
    def check_rewrite(self, frm_operations, to_operations, **namespace):
        S = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed))
        sdescr = get_size_descr(self.gc_ll_descr, S)
        sdescr.tid = 1234
        #
        T = lltype.GcStruct('T', ('y', lltype.Signed), ('z', lltype.Ptr(S)),
                            ('t', lltype.Signed))
        tdescr = get_size_descr(self.gc_ll_descr, T)
        tdescr.tid = 5678
        tzdescr = get_field_descr(self.gc_ll_descr, T, 'z')
        #
        A = lltype.GcArray(lltype.Signed)
        adescr = get_array_descr(self.gc_ll_descr, A)
        adescr.tid = 4321
        alendescr = adescr.lendescr
        #
        B = lltype.GcArray(lltype.Char)
        bdescr = get_array_descr(self.gc_ll_descr, B)
        bdescr.tid = 8765
        blendescr = bdescr.lendescr
        #
        C = lltype.GcArray(lltype.Ptr(S))
        cdescr = get_array_descr(self.gc_ll_descr, C)
        cdescr.tid = 8111
        clendescr = cdescr.lendescr
        #
        E = lltype.GcStruct('Empty')
        edescr = get_size_descr(self.gc_ll_descr, E)
        edescr.tid = 9000
        #
        vtable_descr = self.gc_ll_descr.fielddescr_vtable
        O = lltype.GcStruct('O', ('parent', rclass.OBJECT),
                            ('x', lltype.Signed))
        o_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
        register_known_gctype(self.cpu, o_vtable, O)
        #
        tiddescr = self.gc_ll_descr.fielddescr_tid
        wbdescr = self.gc_ll_descr.write_barrier_descr
        WORD = globals()['WORD']
        #
        strdescr = self.gc_ll_descr.str_descr
        unicodedescr = self.gc_ll_descr.unicode_descr
        strlendescr = strdescr.lendescr
        unicodelendescr = unicodedescr.lendescr
        strhashdescr = self.gc_ll_descr.str_hash_descr
        unicodehashdescr = self.gc_ll_descr.unicode_hash_descr

        casmdescr = JitCellToken()
        clt = FakeLoopToken()
        clt._ll_initial_locs = [0, 8]
        frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
        clt.frame_info = frame_info
        frame_info.jfi_frame_depth = 13
        frame_info.jfi_frame_size = 255
        framedescrs = self.gc_ll_descr.getframedescrs(self.cpu)
        framelendescr = framedescrs.arraydescr.lendescr
        jfi_frame_depth = framedescrs.jfi_frame_depth
        jfi_frame_size = framedescrs.jfi_frame_size
        jf_frame_info = framedescrs.jf_frame_info
        jf_savedata = framedescrs.jf_savedata
        jf_force_descr = framedescrs.jf_force_descr
        jf_descr = framedescrs.jf_descr
        jf_guard_exc = framedescrs.jf_guard_exc
        jf_forward = framedescrs.jf_forward
        jf_extra_stack_depth = framedescrs.jf_extra_stack_depth
        signedframedescr = self.cpu.signedframedescr
        floatframedescr = self.cpu.floatframedescr
        casmdescr.compiled_loop_token = clt
        #
        guarddescr = AbstractFailDescr()
        #
        namespace.update(locals())
        #
        for funcname in self.gc_ll_descr._generated_functions:
            namespace[funcname] = self.gc_ll_descr.get_malloc_fn(funcname)
            namespace[funcname + '_descr'] = getattr(self.gc_ll_descr,
                                                     '%s_descr' % funcname)
        #
        ops = parse(frm_operations, namespace=namespace)
        expected = parse(to_operations % Evaluator(namespace),
                         namespace=namespace)
        operations = self.gc_ll_descr.rewrite_assembler(
            self.cpu, ops.operations, [])
        equaloplists(operations, expected.operations)
        lltype.free(frame_info, flavor='raw')
Ejemplo n.º 14
0
Archivo: gc.py Proyecto: charred/pypy
 def _setup_str(self):
     self.str_descr     = get_array_descr(self, rstr.STR)
     self.unicode_descr = get_array_descr(self, rstr.UNICODE)
Ejemplo n.º 15
0
 def arraydescrof(self, A):
     return get_array_descr(self.gc_ll_descr, A)
Ejemplo n.º 16
0
    def check_rewrite(self, frm_operations, to_operations, **namespace):
        S = lltype.GcStruct('S', ('x', lltype.Signed),
                                 ('y', lltype.Signed))
        sdescr = get_size_descr(self.gc_ll_descr, S)
        sdescr.tid = 1234
        #
        T = lltype.GcStruct('T', ('y', lltype.Signed),
                                 ('z', lltype.Ptr(S)),
                                 ('t', lltype.Signed))
        tdescr = get_size_descr(self.gc_ll_descr, T)
        tdescr.tid = 5678
        tzdescr = get_field_descr(self.gc_ll_descr, T, 'z')
        #
        A = lltype.GcArray(lltype.Signed)
        adescr = get_array_descr(self.gc_ll_descr, A)
        adescr.tid = 4321
        alendescr = adescr.lendescr
        #
        B = lltype.GcArray(lltype.Char)
        bdescr = get_array_descr(self.gc_ll_descr, B)
        bdescr.tid = 8765
        blendescr = bdescr.lendescr
        #
        C = lltype.GcArray(lltype.Ptr(S))
        cdescr = get_array_descr(self.gc_ll_descr, C)
        cdescr.tid = 8111
        clendescr = cdescr.lendescr
        #
        E = lltype.GcStruct('Empty')
        edescr = get_size_descr(self.gc_ll_descr, E)
        edescr.tid = 9000
        #
        vtable_descr = self.gc_ll_descr.fielddescr_vtable
        O = lltype.GcStruct('O', ('parent', rclass.OBJECT),
                                 ('x', lltype.Signed))
        o_descr = self.cpu.sizeof(O, True)
        o_vtable = globals()['o_vtable']
        #
        tiddescr = self.gc_ll_descr.fielddescr_tid
        wbdescr = self.gc_ll_descr.write_barrier_descr
        WORD = globals()['WORD']
        #
        strdescr     = self.gc_ll_descr.str_descr
        unicodedescr = self.gc_ll_descr.unicode_descr
        strlendescr     = strdescr.lendescr
        unicodelendescr = unicodedescr.lendescr
        strhashdescr     = self.gc_ll_descr.str_hash_descr
        unicodehashdescr = self.gc_ll_descr.unicode_hash_descr

        casmdescr = JitCellToken()
        clt = FakeLoopToken()
        clt._ll_initial_locs = [0, 8]
        frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
        clt.frame_info = frame_info
        frame_info.jfi_frame_depth = 13
        frame_info.jfi_frame_size = 255
        framedescrs = self.gc_ll_descr.getframedescrs(self.cpu)
        framelendescr = framedescrs.arraydescr.lendescr
        jfi_frame_depth = framedescrs.jfi_frame_depth
        jfi_frame_size = framedescrs.jfi_frame_size
        jf_frame_info = framedescrs.jf_frame_info
        jf_savedata = framedescrs.jf_savedata
        jf_force_descr = framedescrs.jf_force_descr
        jf_descr = framedescrs.jf_descr
        jf_guard_exc = framedescrs.jf_guard_exc
        jf_forward = framedescrs.jf_forward
        jf_extra_stack_depth = framedescrs.jf_extra_stack_depth
        signedframedescr = self.cpu.signedframedescr
        floatframedescr = self.cpu.floatframedescr
        casmdescr.compiled_loop_token = clt
        #
        guarddescr = AbstractFailDescr()
        #
        namespace.update(locals())
        #
        for funcname in self.gc_ll_descr._generated_functions:
            namespace[funcname] = self.gc_ll_descr.get_malloc_fn(funcname)
            namespace[funcname + '_descr'] = getattr(self.gc_ll_descr,
                                                     '%s_descr' % funcname)
        #
        ops = parse(frm_operations, namespace=namespace)
        expected = parse(to_operations % Evaluator(namespace),
                         namespace=namespace)
        operations = self.gc_ll_descr.rewrite_assembler(self.cpu,
                                                        ops.operations,
                                                        [])
        remap = {}
        for a, b in zip(ops.inputargs, expected.inputargs):
            remap[b] = a
        equaloplists(operations, expected.operations, remap=remap)
        lltype.free(frame_info, flavor='raw')