Author: Armin Rigo <[email protected]>
Branch: guard-compatible
Changeset: r84599:016d5e77145e
Date: 2016-05-22 23:21 +0200
http://bitbucket.org/pypy/pypy/changeset/016d5e77145e/

Log:    A test checking most pieces of guard_compat, without invoking the
        rest of the backend

diff --git a/rpython/jit/backend/x86/test/test_guard_compat.py 
b/rpython/jit/backend/x86/test/test_guard_compat.py
--- a/rpython/jit/backend/x86/test/test_guard_compat.py
+++ b/rpython/jit/backend/x86/test/test_guard_compat.py
@@ -1,4 +1,11 @@
+import random
 from rpython.jit.backend.x86.guard_compat import *
+from rpython.jit.backend.detect_cpu import getcpuclass
+
+CPU = getcpuclass()
+
+class FakeStats(object):
+    pass
 
 
 def test_invalidate_cache():
@@ -62,3 +69,107 @@
         (new_gcref_3, new_asmaddr_3),
         (-1, 0),   # invalid
         ])
+
+def test_guard_compat():
+    cpu = CPU(rtyper=None, stats=FakeStats())
+    cpu.setup_once()
+
+    mc = codebuf.MachineCodeBlockWrapper()
+    for i in range(4 * WORD):
+        mc.writechar('\x00')   # 4 gctable entries; 'bchoices' will be #3
+    #
+    mc.PUSH(regloc.ebp)
+    mc.SUB(regloc.esp, regloc.imm(448 - 2*WORD)) # make a frame, and align 
stack
+    mc.LEA_rs(regloc.ebp.value, 48)
+    #
+    mc.PUSH(regloc.imm(0xdddd))
+    mc.PUSH(regloc.imm(0xaaaa))
+    mc.MOV(regloc.edx, regloc.edi)
+    mc.MOV(regloc.eax, regloc.esi)
+    mc.JMP(regloc.imm(cpu.assembler.guard_compat_search_tree))
+    sequel = mc.get_relative_pos()
+    #
+    mc.force_frame_size(448)
+    mc.SUB(regloc.eax, regloc.edx)
+    mc.ADD(regloc.esp, regloc.imm(448 - 2*WORD))
+    mc.POP(regloc.ebp)
+    mc.RET()
+    #
+    extra_paths = []
+    for i in range(11):
+        mc.force_frame_size(448)
+        extra_paths.append(mc.get_relative_pos())
+        mc.MOV(regloc.eax, regloc.imm(1000000 + i))
+        mc.ADD(regloc.esp, regloc.imm(448 - 2*WORD))
+        mc.POP(regloc.ebp)
+        mc.RET()
+    failure = extra_paths[10]
+    rawstart = mc.materialize(cpu, [])
+    call_me = 
rffi.cast(lltype.Ptr(lltype.FuncType([lltype.Ptr(BACKEND_CHOICES),
+                                                    llmemory.GCREF],
+                                                   lltype.Signed)),
+                        rawstart + 4 * WORD)
+
+    guard_compat_descr = GuardCompatibleDescr()
+    bchoices = initial_bchoices(guard_compat_descr,
+                                rffi.cast(llmemory.GCREF, 111111))
+    llop.raw_store(lltype.Void, rawstart, 3 * WORD, bchoices)
+
+    class FakeGuardToken:
+        guard_compat_bindex = 3
+        pos_jump_offset = sequel
+        pos_recovery_stub = failure
+        gcmap = rffi.cast(lltype.Ptr(jitframe.GCMAP), 0x10111213)
+        faildescr = guard_compat_descr
+    guard_token = FakeGuardToken()
+
+    patch_guard_compatible(guard_token, rawstart, rawstart)
+
+    # ---- ready ----
+
+    for i in range(5):
+        guard_compat_descr.find_compatible = "don't call"
+        gcref = rffi.cast(llmemory.GCREF, 111111)
+        print 'calling with the standard gcref'
+        res = call_me(bchoices, gcref)
+        assert res == 0xaaaa - 0xdddd
+        assert bchoices.bc_most_recent.gcref == gcref
+        assert bchoices.bc_most_recent.asmaddr == rawstart + sequel
+
+    seen = []
+    def call(cpu, descr):
+        print 'find_compatible returns 0'
+        seen.append(descr)
+        return 0
+
+    for i in range(5):
+        guard_compat_descr.find_compatible = call
+        gcref = rffi.cast(llmemory.GCREF, 123456 + i)
+        print 'calling with a gcref never seen before'
+        res = call_me(bchoices, gcref)
+        assert res == 1000010
+        assert len(seen) == 1 + i
+        assert bchoices.bc_most_recent.gcref == gcref
+        assert bchoices.bc_most_recent.asmaddr == rawstart + failure
+
+    # ---- grow bchoices ----
+
+    expected = {111111: (0xaaaa - 0xdddd, rawstart + sequel)}
+    for j in range(10):
+        print 'growing bchoices'
+        bchoices = add_in_tree(bchoices, rffi.cast(llmemory.GCREF, 111113 + j),
+                               rawstart + extra_paths[j])
+        expected[111113 + j] = (1000000 + j, rawstart + extra_paths[j])
+    llop.raw_store(lltype.Void, rawstart, 3 * WORD, bchoices)
+
+    for i in range(10):
+        lst = expected.items()
+        random.shuffle(lst)
+        for intgcref, (expected_res, expected_asmaddr) in lst:
+            guard_compat_descr.find_compatible = "don't call"
+            gcref = rffi.cast(llmemory.GCREF, intgcref)
+            print 'calling with new choice', intgcref
+            res = call_me(bchoices, gcref)
+            assert res == expected_res
+            assert bchoices.bc_most_recent.gcref == gcref
+            assert bchoices.bc_most_recent.asmaddr == expected_asmaddr
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to