Exemple #1
0
 def bound_reached(cell, *args):
     # bound reached, but we do a last check: if it is the first
     # time we reach the bound, or if another loop or bridge was
     # compiled since the last time we reached it, then decrease
     # the counter by a few percents instead.  It should avoid
     # sudden bursts of JIT-compilation, and also corner cases
     # where we suddenly compile more than one loop because all
     # counters reach the bound at the same time, but where
     # compiling all but the first one is pointless.
     curgen = warmrunnerdesc.memory_manager.current_generation
     curgen = chr(intmask(curgen) & 0xFF)  # only use 8 bits
     if we_are_translated() and curgen != cell.extra_delay:
         cell.counter = int(self.THRESHOLD_LIMIT * 0.98)
         cell.extra_delay = curgen
         return
     #
     if not confirm_enter_jit(*args):
         cell.counter = 0
         return
     # start tracing
     from pypy.jit.metainterp.pyjitpl import MetaInterp
     metainterp = MetaInterp(metainterp_sd, jitdriver_sd)
     # set counter to -2, to mean "tracing in effect"
     cell.counter = -2
     try:
         metainterp.compile_and_run_once(jitdriver_sd, *args)
     finally:
         if cell.counter == -2:
             cell.counter = 0
Exemple #2
0
 def bound_reached(cell, *args):
     # bound reached, but we do a last check: if it is the first
     # time we reach the bound, or if another loop or bridge was
     # compiled since the last time we reached it, then decrease
     # the counter by a few percents instead.  It should avoid
     # sudden bursts of JIT-compilation, and also corner cases
     # where we suddenly compile more than one loop because all
     # counters reach the bound at the same time, but where
     # compiling all but the first one is pointless.
     curgen = warmrunnerdesc.memory_manager.current_generation
     curgen = chr(intmask(curgen) & 0xFF)    # only use 8 bits
     if we_are_translated() and curgen != cell.extra_delay:
         cell.counter = int(self.THRESHOLD_LIMIT * 0.98)
         cell.extra_delay = curgen
         return
     #
     if not confirm_enter_jit(*args):
         cell.counter = 0
         return
     # start tracing
     from pypy.jit.metainterp.pyjitpl import MetaInterp
     metainterp = MetaInterp(metainterp_sd, jitdriver_sd)
     # set counter to -2, to mean "tracing in effect"
     cell.counter = -2
     try:
         metainterp.compile_and_run_once(jitdriver_sd, *args)
     finally:
         if cell.counter == -2:
             cell.counter = 0
Exemple #3
0
        def maybe_compile_and_run(*args):
            """Entry point to the JIT.  Called at the point with the
            can_enter_jit() hint.
            """
            globaldata = metainterp_sd.globaldata
            if NonConstant(False):
                # make sure we always see the saner optimizer from an
                # annotation point of view, otherwise we get lots of
                # blocked ops
                self.set_param_optimizer(OPTIMIZER_FULL)

            if vinfo is not None:
                virtualizable = args[vinfo.index_of_virtualizable]
                virtualizable = vinfo.cast_to_vtype(virtualizable)
                assert virtualizable != globaldata.blackhole_virtualizable, (
                    "reentering same frame via blackhole")

            # look for the cell corresponding to the current greenargs
            greenargs = args[:num_green_args]
            cell = get_jitcell(*greenargs)

            if cell.counter >= 0:
                # update the profiling counter
                n = cell.counter + self.increment_threshold
                if n <= self.THRESHOLD_LIMIT:       # bound not reached
                    cell.counter = n
                    return
                # bound reached; start tracing
                from pypy.jit.metainterp.pyjitpl import MetaInterp
                metainterp = MetaInterp(metainterp_sd)
                try:
                    loop_token = metainterp.compile_and_run_once(*args)
                except ContinueRunningNormally:
                    # the trace got too long, reset the counter
                    cell.counter = 0
                    raise
            else:
                # machine code was already compiled for these greenargs
                # get the assembler and fill in the boxes
                set_future_values(*args[num_green_args:])
                loop_token = cell.entry_loop_token

            # ---------- execute assembler ----------
            while True:     # until interrupted by an exception
                metainterp_sd.profiler.start_running()
                fail_index = metainterp_sd.cpu.execute_token(loop_token)
                metainterp_sd.profiler.end_running()
                fail_descr = globaldata.get_fail_descr_from_number(fail_index)
                loop_token = fail_descr.handle_fail(metainterp_sd)
Exemple #4
0
        def maybe_compile_and_run(threshold, *args):
            """Entry point to the JIT.  Called at the point with the
            can_enter_jit() hint.
            """
            if vinfo is not None:
                virtualizable = args[num_green_args + index_of_virtualizable]
                virtualizable = vinfo.cast_to_vtype(virtualizable)
            else:
                virtualizable = None

            # look for the cell corresponding to the current greenargs
            greenargs = args[:num_green_args]
            cell = get_jitcell(True, *greenargs)

            if cell.counter >= 0:
                # update the profiling counter
                n = cell.counter + threshold
                if n <= self.THRESHOLD_LIMIT:       # bound not reached
                    cell.counter = n
                    return
                if not confirm_enter_jit(*args):
                    cell.counter = 0
                    return
                # bound reached; start tracing
                from pypy.jit.metainterp.pyjitpl import MetaInterp
                metainterp = MetaInterp(metainterp_sd, jitdriver_sd)
                # set counter to -2, to mean "tracing in effect"
                cell.counter = -2
                try:
                    loop_token = metainterp.compile_and_run_once(jitdriver_sd,
                                                                 *args)
                finally:
                    if cell.counter == -2:
                        cell.counter = 0
            else:
                if cell.counter == -2:
                    # tracing already happening in some outer invocation of
                    # this function. don't trace a second time.
                    return
                assert cell.counter == -1
                if not confirm_enter_jit(*args):
                    return
                loop_token = cell.get_entry_loop_token()
                if loop_token is None:   # it was a weakref that has been freed
                    cell.counter = 0
                    return
                # machine code was already compiled for these greenargs
                # get the assembler and fill in the boxes
                set_future_values(*args[num_green_args:])

            # ---------- execute assembler ----------
            while True:     # until interrupted by an exception
                metainterp_sd.profiler.start_running()
                #debug_start("jit-running")
                fail_descr = warmrunnerdesc.execute_token(loop_token)
                #debug_stop("jit-running")
                metainterp_sd.profiler.end_running()
                loop_token = None     # for test_memmgr
                if vinfo is not None:
                    vinfo.reset_vable_token(virtualizable)
                loop_token = fail_descr.handle_fail(metainterp_sd,
                                                    jitdriver_sd)
Exemple #5
0
        def maybe_compile_and_run(*args):
            """Entry point to the JIT.  Called at the point with the
            can_enter_jit() hint.
            """
            globaldata = metainterp_sd.globaldata
            if NonConstant(False):
                # make sure we always see the saner optimizer from an
                # annotation point of view, otherwise we get lots of
                # blocked ops
                self.set_param_optimizer(OPTIMIZER_FULL)

            if vinfo is not None:
                virtualizable = args[vinfo.index_of_virtualizable]
                virtualizable = vinfo.cast_to_vtype(virtualizable)
            else:
                virtualizable = None

            # look for the cell corresponding to the current greenargs
            greenargs = args[:num_green_args]
            cell = get_jitcell(*greenargs)

            if cell.counter >= 0:
                # update the profiling counter
                n = cell.counter + self.increment_threshold
                if n <= self.THRESHOLD_LIMIT:       # bound not reached
                    cell.counter = n
                    return
                if not confirm_enter_jit(*args):
                    cell.counter = 0
                    return
                # bound reached; start tracing
                from pypy.jit.metainterp.pyjitpl import MetaInterp
                metainterp = MetaInterp(metainterp_sd)
                # set counter to -2, to mean "tracing in effect"
                cell.counter = -2
                try:
                    loop_token = metainterp.compile_and_run_once(*args)
                except ContinueRunningNormally:
                    # the trace got too long, reset the counter
                    cell.counter = 0
                    self.disable_noninlinable_function(metainterp)
                    raise
                finally:
                    if cell.counter == -2:
                        cell.counter = 0
            else:
                if cell.counter == -2:
                    # tracing already happening in some outer invocation of
                    # this function. don't trace a second time.
                    return
                assert cell.counter == -1
                if not confirm_enter_jit(*args):
                    return
                # machine code was already compiled for these greenargs
                # get the assembler and fill in the boxes
                set_future_values(*args[num_green_args:])
                loop_token = cell.entry_loop_token

            # ---------- execute assembler ----------
            while True:     # until interrupted by an exception
                metainterp_sd.profiler.start_running()
                debug_start("jit-running")
                fail_descr = metainterp_sd.cpu.execute_token(loop_token)
                debug_stop("jit-running")
                metainterp_sd.profiler.end_running()
                if vinfo is not None:
                    vinfo.reset_vable_token(virtualizable)
                loop_token = fail_descr.handle_fail(metainterp_sd)
Exemple #6
0
        def maybe_compile_and_run(*args):
            """Entry point to the JIT.  Called at the point with the
            can_enter_jit() hint.
            """
            globaldata = metainterp_sd.globaldata
            if NonConstant(False):
                # make sure we always see the saner optimizer from an
                # annotation point of view, otherwise we get lots of
                # blocked ops
                self.set_param_optimizer(OPTIMIZER_FULL)

            if vinfo is not None:
                virtualizable = args[vinfo.index_of_virtualizable]
                virtualizable = vinfo.cast_to_vtype(virtualizable)
            else:
                virtualizable = None

            # look for the cell corresponding to the current greenargs
            greenargs = args[:num_green_args]
            cell = get_jitcell(*greenargs)

            if cell.counter >= 0:
                # update the profiling counter
                n = cell.counter + self.increment_threshold
                if n <= self.THRESHOLD_LIMIT:  # bound not reached
                    cell.counter = n
                    return
                if not confirm_enter_jit(*args):
                    cell.counter = 0
                    return
                # bound reached; start tracing
                from pypy.jit.metainterp.pyjitpl import MetaInterp

                metainterp = MetaInterp(metainterp_sd)
                # set counter to -2, to mean "tracing in effect"
                cell.counter = -2
                try:
                    loop_token = metainterp.compile_and_run_once(*args)
                except ContinueRunningNormally:
                    # the trace got too long, reset the counter
                    cell.counter = 0
                    self.disable_noninlinable_function(metainterp)
                    raise
                finally:
                    if cell.counter == -2:
                        cell.counter = 0
            else:
                if cell.counter == -2:
                    # tracing already happening in some outer invocation of
                    # this function. don't trace a second time.
                    return
                assert cell.counter == -1
                if not confirm_enter_jit(*args):
                    return
                # machine code was already compiled for these greenargs
                # get the assembler and fill in the boxes
                set_future_values(*args[num_green_args:])
                loop_token = cell.entry_loop_token

            # ---------- execute assembler ----------
            while True:  # until interrupted by an exception
                metainterp_sd.profiler.start_running()
                debug_start("jit-running")
                fail_descr = metainterp_sd.cpu.execute_token(loop_token)
                debug_stop("jit-running")
                metainterp_sd.profiler.end_running()
                if vinfo is not None:
                    vinfo.reset_vable_token(virtualizable)
                loop_token = fail_descr.handle_fail(metainterp_sd)