Author: Armin Rigo <[email protected]>
Branch: guard-compatible
Changeset: r84638:ddb6db2eb91a
Date: 2016-05-23 22:00 +0200
http://bitbucket.org/pypy/pypy/changeset/ddb6db2eb91a/
Log: Bah, I added the "jitframe" argument to the commented code and
forgot to add it to the real code. Fix tests in consequences (which
was a bit of a mess). Simplify the commented code even more to make
it clear it is pseudo-code.
diff --git a/rpython/jit/backend/x86/guard_compat.py
b/rpython/jit/backend/x86/guard_compat.py
--- a/rpython/jit/backend/x86/guard_compat.py
+++ b/rpython/jit/backend/x86/guard_compat.py
@@ -121,29 +121,23 @@
#
#
# invoke_find_compatible(bchoices, new_gcref, jitframe):
-# descr = bchoices.bc_faildescr
-# try:
-# jitframe.jf_gcmap = descr._backend_gcmap
-# result = descr.find_compatible(cpu, new_gcref)
-# if result == 0:
-# result = descr._backend_failure_recovery
-# else:
-# if result == -1:
-# result = descr._backend_sequel_label
-# bchoices = add_in_tree(bchoices, new_gcref, result)
-# descr.bchoices_addr[0] = bchoices # GC table
-# bchoices.bc_most_recent.gcref = new_gcref
-# bchoices.bc_most_recent.asmaddr = result
-# jitframe.jf_gcmap = 0
-# return result
-# except: # oops!
-# return descr._backend_failure_recovery
+# IN PSEUDO-CODE:
+# result = bchoices.bc_faildescr.find_compatible(cpu, new_gcref)
+# if result == 0:
+# result = descr._backend_failure_recovery
+# else:
+# if result == -1:
+# result = descr._backend_sequel_label
+# bchoices = add_in_tree(bchoices, new_gcref, result)
+# <if bchoices changed, update the GC table>
+# bchoices.bc_most_recent.gcref = new_gcref
+# bchoices.bc_most_recent.asmaddr = result
+# return result
#
# add_in_tree(bchoices, new_gcref, new_addr):
-# if bchoices.bc_list[len(bchoices.bc_list) - 1] != -1:
-# ...reallocate...
-# bchoices.bc_list[len(bchoices.bc_list) - 1].gcref = new_gcref
-# bchoices.bc_list[len(bchoices.bc_list) - 1].asmaddr = new_addr
+# if bchoices.bc_list does not end in -1, reallocate a bigger one
+# bchoices.bc_list[last].gcref = new_gcref
+# bchoices.bc_list[last].asmaddr = new_addr
# quicksort(bchoices.bc_list)
# return bchoices
#
@@ -255,15 +249,17 @@
INVOKE_FIND_COMPATIBLE_FUNC = lltype.Ptr(lltype.FuncType(
- [lltype.Ptr(BACKEND_CHOICES), llmemory.GCREF],
+ [lltype.Ptr(BACKEND_CHOICES), llmemory.GCREF,
+ lltype.Ptr(jitframe.JITFRAME)],
lltype.Signed))
@specialize.memo()
def make_invoke_find_compatible(cpu):
- def invoke_find_compatible(bchoices, new_gcref):
+ def invoke_find_compatible(bchoices, new_gcref, jitframe):
descr = bchoices.bc_faildescr
descr = cast_gcref_to_instance(GuardCompatibleDescr, descr)
try:
+ jitframe.jf_gcmap = descr._backend_gcmap
result = descr.find_compatible(cpu, new_gcref)
if result == 0:
result = descr._backend_failure_recovery
@@ -280,12 +276,13 @@
bchoices.bc_most_recent.gcref = gcref_to_unsigned(new_gcref)
bchoices.bc_most_recent.asmaddr = result
llop.gc_writebarrier(lltype.Void, bchoices)
- return result
except: # oops!
if not we_are_translated():
import sys, pdb
pdb.post_mortem(sys.exc_info()[2])
- return descr._backend_failure_recovery
+ result = descr._backend_failure_recovery
+ jitframe.jf_gcmap = lltype.nullptr(lltype.typeOf(jitframe.jf_gcmap).TO)
+ return result
return invoke_find_compatible
def add_in_tree(bchoices, new_gcref, new_asmaddr):
diff --git a/rpython/jit/backend/x86/test/test_compatible.py
b/rpython/jit/backend/x86/test/test_compatible.py
--- a/rpython/jit/backend/x86/test/test_compatible.py
+++ b/rpython/jit/backend/x86/test/test_compatible.py
@@ -78,41 +78,43 @@
mc.writechar('\x00') # 4 gctable entries; 'bchoices' will be #3
#
if IS_X86_64:
+ mc.MOV(regloc.ecx, regloc.edx)
mc.MOV(regloc.edx, regloc.edi)
mc.MOV(regloc.eax, regloc.esi)
elif IS_X86_32:
mc.MOV_rs(regloc.edx.value, 4)
mc.MOV_rs(regloc.eax.value, 8)
+ mc.MOV_rs(regloc.ecx.value, 12)
#
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.SUB(regloc.esp, regloc.imm(148 - 2*WORD)) # make a frame, and align
stack
+ mc.MOV(regloc.ebp, regloc.ecx)
#
mc.PUSH(regloc.imm(0xdddd))
mc.PUSH(regloc.imm(0xaaaa))
mc.JMP(regloc.imm(cpu.assembler.guard_compat_search_tree))
sequel = mc.get_relative_pos()
#
- mc.force_frame_size(448)
+ mc.force_frame_size(148)
mc.SUB(regloc.eax, regloc.edx)
- mc.ADD(regloc.esp, regloc.imm(448 - 2*WORD))
+ mc.ADD(regloc.esp, regloc.imm(148 - 2*WORD))
mc.POP(regloc.ebp)
mc.RET()
#
extra_paths = []
for i in range(11):
- mc.force_frame_size(448)
+ mc.force_frame_size(148)
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.ADD(regloc.esp, regloc.imm(148 - 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)
+ call_me = rffi.cast(lltype.Ptr(lltype.FuncType(
+ [lltype.Ptr(BACKEND_CHOICES), llmemory.GCREF,
+ lltype.Ptr(jitframe.JITFRAME)], lltype.Signed)),
+ rawstart + 4 * WORD)
guard_compat_descr = GuardCompatibleDescr()
bchoices = initial_bchoices(guard_compat_descr,
@@ -132,11 +134,16 @@
# ---- ready ----
+ frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
+ frame_info.clear()
+ frame_info.update_frame_depth(cpu.get_baseofs_of_frame_field(), 1000)
+ frame = jitframe.JITFRAME.allocate(frame_info)
+
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)
+ res = call_me(bchoices, gcref, frame)
assert res == 0xaaaa - 0xdddd
assert bchoices.bc_most_recent.gcref == 111111
assert bchoices.bc_most_recent.asmaddr == rawstart + sequel
@@ -151,7 +158,7 @@
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)
+ res = call_me(bchoices, gcref, frame)
assert res == 1000010
assert len(seen) == 1 + i
assert bchoices.bc_most_recent.gcref == 123456 + i
@@ -174,11 +181,13 @@
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)
+ res = call_me(bchoices, gcref, frame)
assert res == expected_res
assert bchoices.bc_most_recent.gcref == intgcref
assert bchoices.bc_most_recent.asmaddr == expected_asmaddr
+ lltype.free(frame_info, flavor='raw')
+
class TestCompatible(Jit386Mixin, test_compatible.TestCompatible):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit