def get_location_str(greenkey): greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr) llres = fn(*greenargs) if not we_are_translated() and isinstance(llres, str): return llres return hlstr(llres)
def ll_portal_runner(*args): start = True while 1: try: # maybe enter from the function's start. Note that the # 'start' variable is constant-folded away because it's # the first statement in the loop. if start: maybe_compile_and_run( state.increment_function_threshold, *args) # # then run the normal portal function, i.e. the # interpreter's main loop. It might enter the jit # via maybe_enter_jit(), which typically ends with # handle_fail() being called, which raises on the # following exceptions --- catched here, because we # want to interrupt the whole interpreter loop. return support.maybe_on_top_of_llinterp(rtyper, portal_ptr)(*args) except jitexc.ContinueRunningNormally, e: args = () for ARGTYPE, attrname, count in portalfunc_ARGS: x = getattr(e, attrname)[count] x = specialize_value(ARGTYPE, x) args = args + (x,) start = False continue except jitexc.DoneWithThisFrameVoid: assert result_kind == 'void' return
def ll_portal_runner(*args): start = True while 1: try: # maybe enter from the function's start. Note that the # 'start' variable is constant-folded away because it's # the first statement in the loop. if start: maybe_compile_and_run( state.increment_function_threshold, *args) # # then run the normal portal function, i.e. the # interpreter's main loop. It might enter the jit # via maybe_enter_jit(), which typically ends with # handle_fail() being called, which raises on the # following exceptions --- catched here, because we # want to interrupt the whole interpreter loop. return support.maybe_on_top_of_llinterp( rtyper, portal_ptr)(*args) except jitexc.ContinueRunningNormally, e: args = () for ARGTYPE, attrname, count in portalfunc_ARGS: x = getattr(e, attrname)[count] x = specialize_value(ARGTYPE, x) args = args + (x, ) start = False continue except jitexc.DoneWithThisFrameVoid: assert result_kind == 'void' return
def get_location_str(greenkey): if not have_debug_prints_for("jit-"): return missing greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, printable_loc_ptr) llres = fn(*greenargs) if not we_are_translated() and isinstance(llres, str): return llres return hlstr(llres)
def get_jitcell(build, *greenargs): fn = support.maybe_on_top_of_llinterp(rtyper, get_jitcell_at_ptr) cellref = fn(*greenargs) # <hacks> if we_are_translated(): BASEJITCELL = lltype.typeOf(cellref) cell = cast_base_ptr_to_instance(JitCell, cellref) else: if isinstance(cellref, (BaseJitCell, type(None))): BASEJITCELL = None cell = cellref else: BASEJITCELL = lltype.typeOf(cellref) if cellref: cell = lltohlhack[rtyper.type_system.deref(cellref)] else: cell = None if not build: return cell if cell is None: cell = JitCell() # <hacks> if we_are_translated(): cellref = cast_object_to_ptr(BASEJITCELL, cell) else: if BASEJITCELL is None: cellref = cell else: if isinstance(BASEJITCELL, lltype.Ptr): cellref = lltype.malloc(BASEJITCELL.TO) else: assert False, "no clue" lltohlhack[rtyper.type_system.deref(cellref)] = cell # </hacks> fn = support.maybe_on_top_of_llinterp(rtyper, set_jitcell_at_ptr) fn(cellref, *greenargs) return cell
def get_location(greenkey): greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr) value_tuple = fn(*greenargs) values = [] for i, (sem_type,gen_type) in unrolled_types: if gen_type == "s": value = getattr(value_tuple, 'item' + str(i)) values.append(jl.wrap(sem_type,gen_type,hlstr(value))) elif gen_type == "i": value = getattr(value_tuple, 'item' + str(i)) values.append(jl.wrap(sem_type,gen_type,intmask(value))) else: raise NotImplementedError return values
def handle_jitexception(e): # XXX there are too many exceptions all around... while True: if isinstance(e, EnterJitAssembler): try: return e.execute() except jitexc.JitException as e: continue # if isinstance(e, jitexc.ContinueRunningNormally): args = () for ARGTYPE, attrname, count in portalfunc_ARGS: x = getattr(e, attrname)[count] x = specialize_value(ARGTYPE, x) args = args + (x,) try: result = support.maybe_on_top_of_llinterp(rtyper, portal_ptr)(*args) except jitexc.JitException as e: continue if result_kind != 'void': result = unspecialize_value(result) return result # if result_kind == 'void': if isinstance(e, jitexc.DoneWithThisFrameVoid): return None if result_kind == 'int': if isinstance(e, jitexc.DoneWithThisFrameInt): return e.result if result_kind == 'ref': if isinstance(e, jitexc.DoneWithThisFrameRef): return e.result if result_kind == 'float': if isinstance(e, jitexc.DoneWithThisFrameFloat): return e.result # if isinstance(e, jitexc.ExitFrameWithExceptionRef): value = ts.cast_to_baseclass(e.value) if not we_are_translated(): raise LLException(ts.get_typeptr(value), value) else: value = cast_base_ptr_to_instance(Exception, value) assert value is not None raise value # raise AssertionError("all cases should have been handled")
def handle_jitexception(e): # XXX there are too many exceptions all around... while True: if isinstance(e, EnterJitAssembler): try: return e.execute() except jitexc.JitException as e: continue # if isinstance(e, jitexc.ContinueRunningNormally): args = () for ARGTYPE, attrname, count in portalfunc_ARGS: x = getattr(e, attrname)[count] x = specialize_value(ARGTYPE, x) args = args + (x, ) try: result = support.maybe_on_top_of_llinterp( rtyper, portal_ptr)(*args) except jitexc.JitException as e: continue if result_kind != 'void': result = unspecialize_value(result) return result # if result_kind == 'void': if isinstance(e, jitexc.DoneWithThisFrameVoid): return None if result_kind == 'int': if isinstance(e, jitexc.DoneWithThisFrameInt): return e.result if result_kind == 'ref': if isinstance(e, jitexc.DoneWithThisFrameRef): return e.result if result_kind == 'float': if isinstance(e, jitexc.DoneWithThisFrameFloat): return e.result # if isinstance(e, jitexc.ExitFrameWithExceptionRef): value = ts.cast_to_baseclass(e.value) if not we_are_translated(): raise LLException(ts.get_typeptr(value), value) else: value = cast_base_ptr_to_instance(Exception, value) assert value is not None raise value # raise AssertionError("all cases should have been handled")
def ll_portal_runner(*args): try: # maybe enter from the function's start. maybe_compile_and_run(state.increment_function_threshold, *args) # # then run the normal portal function, i.e. the # interpreter's main loop. It might enter the jit # via maybe_enter_jit(), which typically ends with # handle_fail() being called, which raises on the # following exceptions --- catched here, because we # want to interrupt the whole interpreter loop. return support.maybe_on_top_of_llinterp(rtyper, portal_ptr)(*args) except jitexc.JitException as e: result = handle_jitexception(e) if result_kind != 'void': result = specialize_value(RESULT, result) return result
def ll_portal_runner(*args): try: # maybe enter from the function's start. maybe_compile_and_run( state.increment_function_threshold, *args) # # then run the normal portal function, i.e. the # interpreter's main loop. It might enter the jit # via maybe_enter_jit(), which typically ends with # handle_fail() being called, which raises on the # following exceptions --- catched here, because we # want to interrupt the whole interpreter loop. return support.maybe_on_top_of_llinterp(rtyper, portal_ptr)(*args) except jitexc.JitException as e: result = handle_jitexception(e) if result_kind != 'void': result = specialize_value(RESULT, result) return result
def get_unique_id(greenkey): greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, get_unique_id_ptr) return fn(*greenargs)
def confirm_enter_jit(*args): fn = support.maybe_on_top_of_llinterp(rtyper, confirm_enter_jit_ptr) return fn(*args)
def can_never_inline(*greenargs): fn = support.maybe_on_top_of_llinterp(rtyper, can_never_inline_ptr) return fn(*greenargs)
def should_unroll_one_iteration(greenkey): greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, inline_ptr) return fn(*greenargs)