Example #1
0
File: test_gc.py Project: Mu-L/pypy
def test_custom_tracer():
    def indexof(no):
        return (frame_adr + jitframe.getofs('jf_frame') +
                jitframe.BASEITEMOFS + jitframe.SIGN_SIZE * no)

    frame_info = lltype.malloc(jitframe.JITFRAMEINFO, zero=True, flavor='raw')
    frame = lltype.malloc(jitframe.JITFRAME, 200, zero=True)
    frame.jf_frame_info = frame_info
    frame.jf_gcmap = lltype.malloc(jitframe.GCMAP, 4, flavor='raw')
    if sys.maxint == 2**31 - 1:
        max = r_uint(2**31)
    else:
        max = r_uint(2**63)
    frame.jf_gcmap[0] = r_uint(1 | 2 | 8 | 32 | 128) | max
    frame.jf_gcmap[1] = r_uint(0)
    frame.jf_gcmap[2] = r_uint(2 | 16 | 32 | 128)
    frame.jf_gcmap[3] = r_uint(0)
    frame_adr = llmemory.cast_ptr_to_adr(frame)
    #
    all_addrs = []

    class FakeGC:
        def _trace_callback(self, callback, arg1, arg2, addr):
            assert callback == "hello"
            assert arg1 == "world"
            assert arg2 == "foo"
            all_addrs.append(addr)

    jitframe.jitframe_trace(FakeGC(), frame_adr, "hello", "world", "foo")
    #
    counter = 0
    for name in jitframe.JITFRAME._names:
        TP = getattr(jitframe.JITFRAME, name)
        if isinstance(TP, lltype.Ptr) and TP.TO._gckind == 'gc':
            assert all_addrs[counter] == frame_adr + jitframe.getofs(name)
            counter += 1
    assert counter == 5
    # gcpattern
    assert all_addrs[5] == indexof(0)
    assert all_addrs[6] == indexof(1)
    assert all_addrs[7] == indexof(3)
    assert all_addrs[8] == indexof(5)
    assert all_addrs[9] == indexof(7)
    if sys.maxint == 2**31 - 1:
        assert all_addrs[10] == indexof(31)
        assert all_addrs[11] == indexof(65)
        assert all_addrs[12] == indexof(68)
        assert all_addrs[13] == indexof(69)
        assert all_addrs[14] == indexof(71)
    else:
        assert all_addrs[10] == indexof(63)
        assert all_addrs[11] == indexof(129)
        assert all_addrs[12] == indexof(132)
        assert all_addrs[13] == indexof(133)
        assert all_addrs[14] == indexof(135)

    assert len(all_addrs) == 15
    lltype.free(frame_info, flavor='raw')
    lltype.free(frame.jf_gcmap, flavor='raw')
Example #2
0
def test_custom_tracer():
    def indexof(no):
        return (frame_adr + jitframe.getofs('jf_frame') +
                jitframe.BASEITEMOFS + jitframe.SIGN_SIZE * no)
    
    frame_info = lltype.malloc(jitframe.JITFRAMEINFO, zero=True, flavor='raw')
    frame = lltype.malloc(jitframe.JITFRAME, 200, zero=True)
    frame.jf_frame_info = frame_info
    frame.jf_gcmap = lltype.malloc(jitframe.GCMAP, 4, flavor='raw')
    if sys.maxint == 2**31 - 1:
        max = r_uint(2 ** 31)
    else:
        max = r_uint(2 ** 63)
    frame.jf_gcmap[0] = r_uint(1 | 2 | 8 | 32 | 128) | max
    frame.jf_gcmap[1] = r_uint(0)
    frame.jf_gcmap[2] = r_uint(2 | 16 | 32 | 128)
    frame.jf_gcmap[3] = r_uint(0)
    frame_adr = llmemory.cast_ptr_to_adr(frame)
    #
    all_addrs = []
    class FakeGC:
        def _trace_callback(self, callback, arg, addr):
            assert callback == "hello"
            assert arg == "world"
            all_addrs.append(addr)
    jitframe.jitframe_trace(FakeGC(), frame_adr, "hello", "world")
    #
    counter = 0
    for name in jitframe.JITFRAME._names:
        TP = getattr(jitframe.JITFRAME, name)
        if isinstance(TP, lltype.Ptr) and TP.TO._gckind == 'gc': 
            assert all_addrs[counter] == frame_adr + jitframe.getofs(name)
            counter += 1
    assert counter == 5
    # gcpattern
    assert all_addrs[5] == indexof(0)
    assert all_addrs[6] == indexof(1)
    assert all_addrs[7] == indexof(3)
    assert all_addrs[8] == indexof(5)
    assert all_addrs[9] == indexof(7)
    if sys.maxint == 2**31 - 1:
        assert all_addrs[10] == indexof(31)
        assert all_addrs[11] == indexof(65)
        assert all_addrs[12] == indexof(68)
        assert all_addrs[13] == indexof(69)
        assert all_addrs[14] == indexof(71)
    else:
        assert all_addrs[10] == indexof(63)
        assert all_addrs[11] == indexof(129)
        assert all_addrs[12] == indexof(132)
        assert all_addrs[13] == indexof(133)
        assert all_addrs[14] == indexof(135)

    assert len(all_addrs) == 15
    lltype.free(frame_info, flavor='raw')
    lltype.free(frame.jf_gcmap, flavor='raw')
Example #3
0
def test_custom_tracer():
    def indexof(no):
        return (frame_adr + jitframe.getofs('jf_frame') +
                jitframe.BASEITEMOFS + jitframe.SIGN_SIZE * no)
    
    frame_info = lltype.malloc(jitframe.JITFRAMEINFO, zero=True, flavor='raw')
    frame = lltype.malloc(jitframe.JITFRAME, 200, zero=True)
    frame.jf_frame_info = frame_info
    frame.jf_gcmap = lltype.malloc(jitframe.GCMAP, 4, flavor='raw')
    if sys.maxint == 2**31 - 1:
        max = r_uint(2 ** 31)
    else:
        max = r_uint(2 ** 63)
    frame.jf_gcmap[0] = r_uint(1 | 2 | 8 | 32 | 128) | max
    frame.jf_gcmap[1] = r_uint(0)
    frame.jf_gcmap[2] = r_uint(2 | 16 | 32 | 128)
    frame.jf_gcmap[3] = r_uint(0)
    frame_adr = llmemory.cast_ptr_to_adr(frame)
    all_addrs = []
    next = jitframe.jitframe_trace(frame_adr, llmemory.NULL)
    while next:
        all_addrs.append(next)
        next = jitframe.jitframe_trace(frame_adr, next)
    counter = 0
    for name in jitframe.JITFRAME._names:
        TP = getattr(jitframe.JITFRAME, name)
        if isinstance(TP, lltype.Ptr) and TP.TO._gckind == 'gc': 
            assert all_addrs[counter] == frame_adr + jitframe.getofs(name)
            counter += 1
    # gcpattern
    assert all_addrs[5] == indexof(0)
    assert all_addrs[6] == indexof(1)
    assert all_addrs[7] == indexof(3)
    assert all_addrs[8] == indexof(5)
    assert all_addrs[9] == indexof(7)
    if sys.maxint == 2**31 - 1:
        assert all_addrs[10] == indexof(31)
        assert all_addrs[11] == indexof(33 + 32)
    else:
        assert all_addrs[10] == indexof(63)
        assert all_addrs[11] == indexof(65 + 64)

    assert len(all_addrs) == 5 + 6 + 4
    # 5 static fields, 4 addresses from gcmap, 2 from gcpattern
    lltype.free(frame_info, flavor='raw')
    lltype.free(frame.jf_gcmap, flavor='raw')
Example #4
0
 def indexof(no):
     return (frame_adr + jitframe.getofs('jf_frame') +
             jitframe.BASEITEMOFS + jitframe.SIGN_SIZE * no)
Example #5
0
 def indexof(no):
     return (frame_adr + jitframe.getofs('jf_frame') +
             jitframe.BASEITEMOFS + jitframe.SIGN_SIZE * no)