Author: Maciej Fijalkowski <[email protected]>
Branch: jitframe-on-heap
Changeset: r60712:b7bd1559a188
Date: 2013-01-30 11:24 +0200
http://bitbucket.org/pypy/pypy/changeset/b7bd1559a188/
Log: some ugly checks
diff --git a/rpython/jit/backend/llsupport/llmodel.py
b/rpython/jit/backend/llsupport/llmodel.py
--- a/rpython/jit/backend/llsupport/llmodel.py
+++ b/rpython/jit/backend/llsupport/llmodel.py
@@ -72,6 +72,16 @@
llop.gc_assume_young_pointers(lltype.Void, new_frame)
return lltype.cast_opaque_ptr(llmemory.GCREF, new_frame)
+ def realloc_frame_check(frame, size):
+ frame = lltype.cast_opaque_ptr(jitframe.JITFRAMEPTR, frame)
+ if size > len(frame.jf_frame) or size >
frame.jf_frame_info.jfi_frame_depth:
+ print "CHECK FAILED"
+ import pdb
+ pdb.set_trace()
+ assert False
+ print "SOMETHING INCREDIBLY FISHY"
+ return lltype.cast_opaque_ptr(llmemory.GCREF, frame)
+
if not translate_support_code:
fptr = llhelper(FUNC_TP, realloc_frame)
else:
@@ -84,6 +94,18 @@
mixlevelann.finish()
self.realloc_frame =
heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
+ if not translate_support_code:
+ fptr = llhelper(FUNC_TP, realloc_frame_check)
+ else:
+ FUNC = FUNC_TP.TO
+ args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
+ s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
+ mixlevelann = MixLevelHelperAnnotator(self.rtyper)
+ graph = mixlevelann.getgraph(realloc_frame, args_s, s_result)
+ fptr = mixlevelann.graph2delayed(graph, FUNC)
+ mixlevelann.finish()
+ self.realloc_frame_check =
heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
+
def _setup_exception_handling_untranslated(self):
# for running un-translated only, all exceptions occurring in the
# llinterpreter are stored in '_exception_emulator', which is then
diff --git a/rpython/jit/backend/x86/assembler.py
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -220,6 +220,27 @@
mc.RET()
self._stack_check_failure = mc.materialize(self.cpu.asmmemmgr, [])
+ mc = codebuf.MachineCodeBlockWrapper()
+ self._push_all_regs_to_frame(mc, [], self.cpu.supports_floats)
+ assert not IS_X86_32
+ # this is the gcmap stored by push_gcmap(mov=True) in
_check_stack_frame
+ mc.MOV_rs(ecx.value, WORD)
+ gcmap_ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
+ mc.MOV_br(gcmap_ofs, ecx.value)
+ # this is size that we're after, sanity checking only
+ mc.MOV_rs(esi.value, WORD*2)
+ # push first arg
+ mc.LEA_rb(edi.value, -base_ofs)
+ # align
+ mc.SUB_ri(esp.value, WORD)
+ mc.CALL(imm(self.cpu.realloc_frame_check))
+ mc.ADD_ri(esp.value, WORD)
+ mc.LEA_rm(ebp.value, (eax.value, base_ofs))
+ mc.MOV_bi(gcmap_ofs, 0)
+ self._pop_all_regs_from_frame(mc, [], self.cpu.supports_floats)
+ mc.RET()
+ self._stack_check_failure_2 = mc.materialize(self.cpu.asmmemmgr, [])
+
def _build_malloc_slowpath(self):
""" While arriving on slowpath, we have a gcpattern on stack,
nursery_head in eax and the size in edi - eax
@@ -553,6 +574,9 @@
looptoken._x86_fullsize = full_size
looptoken._x86_ops_offset = ops_offset
looptoken._x86_function_addr = rawstart
+ for label in self.labels_to_patch:
+ self._patch_stackadjust(label + rawstart, frame_depth +
JITFRAME_FIXED_SIZE)
+ self.labels_to_patch = None
self.fixup_target_tokens(rawstart)
self.teardown()
@@ -603,6 +627,9 @@
frame_depth + JITFRAME_FIXED_SIZE)
self._patch_stackadjust(stack_check_patch_ofs + rawstart, frame_depth)
self._patch_stackadjust(ofs2 + rawstart, frame_depth)
+ for label in self.labels_to_patch:
+ self._patch_stackadjust(label + rawstart, frame_depth)
+ self.labels_to_patch = None
self.fixup_target_tokens(rawstart)
self.update_frame_depth(frame_depth)
self.teardown()
@@ -667,7 +694,7 @@
baseofs = self.cpu.get_baseofs_of_frame_field()
self.current_clt.frame_info.set_frame_depth(baseofs, frame_depth)
- def _check_frame_depth(self, mc, gcmap, expected_size=-1):
+ def _check_frame_depth(self, mc, gcmap, expected_size=-1,
check_only=False):
""" check if the frame is of enough depth to follow this bridge.
Otherwise reallocate the frame in a helper.
There are other potential solutions
@@ -690,7 +717,10 @@
mc.MOV_si(WORD, expected_size)
ofs2 = mc.get_relative_pos() - 4
self.push_gcmap(mc, gcmap, mov=True)
- mc.CALL(imm(self._stack_check_failure))
+ if check_only:
+ mc.CALL(imm(self._stack_check_failure_2))
+ else:
+ mc.CALL(imm(self._stack_check_failure))
# patch the JG above
offset = mc.get_relative_pos() - jg_location
assert 0 < offset <= 127
@@ -792,6 +822,7 @@
def _assemble(self, regalloc, inputargs, operations):
self._regalloc = regalloc
+ self.labels_to_patch = []
regalloc.compute_hint_frame_locations(operations)
regalloc.walk_operations(inputargs, operations)
if we_are_translated() or self.cpu.dont_keepalive_stuff:
@@ -2486,6 +2517,12 @@
expected_size=expected_size)
self.mc.JMP(imm(target))
+ def label(self):
+ ofs, ofs2 = self._check_frame_depth(self.mc,
self._regalloc.get_gcmap(),
+ check_only=True)
+ self.labels_to_patch.append(ofs)
+ self.labels_to_patch.append(ofs2)
+
def malloc_cond(self, nursery_free_adr, nursery_top_adr, size, gcmap):
assert size & (WORD-1) == 0 # must be correctly aligned
self.mc.MOV(eax, heap(nursery_free_adr))
diff --git a/rpython/jit/backend/x86/regalloc.py
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -1322,6 +1322,7 @@
descr._x86_clt = self.assembler.current_clt
self.assembler.target_tokens_currently_compiling[descr] = None
self.possibly_free_vars_for_op(op)
+ self.assembler.label()
#
# if the LABEL's descr is precisely the target of the JUMP at the
# end of the same loop, i.e. if what we are compiling is a single
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit