示例#1
0
文件: optimizer.py 项目: juokaz/pypy
 def make_guards(self, box):
     guards = []
     level = self.getlevel()
     if level == LEVEL_CONSTANT:
         op = ResOperation(rop.GUARD_VALUE, [box, self.box], None)
         guards.append(op)
     elif level == LEVEL_KNOWNCLASS:
         op = ResOperation(rop.GUARD_NONNULL_CLASS, [box, self.known_class],
                           None)
         guards.append(op)
     else:
         if level == LEVEL_NONNULL:
             op = ResOperation(rop.GUARD_NONNULL, [box], None)
             guards.append(op)
         if self.lenbound:
             lenbox = BoxInt()
             if self.lenbound.mode == MODE_ARRAY:
                 op = ResOperation(rop.ARRAYLEN_GC, [box], lenbox,
                                   self.lenbound.descr)
             elif self.lenbound.mode == MODE_STR:
                 op = ResOperation(rop.STRLEN, [box], lenbox,
                                   self.lenbound.descr)
             elif self.lenbound.mode == MODE_UNICODE:
                 op = ResOperation(rop.UNICODELEN, [box], lenbox,
                                   self.lenbound.descr)
             else:
                 debug_print("Unknown lenbound mode")
                 assert False
             guards.append(op)
             self.lenbound.bound.make_guards(lenbox, guards)
     return guards
示例#2
0
 def f():
     state.data = []
     state.datalen1 = 0
     state.datalen2 = 0
     state.datalen3 = 0
     state.datalen4 = 0
     state.threadlocals = my_gil_threadlocals
     state.threadlocals.setup_threads(space)
     subident = thread.start_new_thread(bootstrap, ())
     mainident = thread.get_ident()
     runme(True)
     still_waiting = 3000
     while len(state.data) < 2 * N:
         debug_print(len(state.data))
         if not still_waiting:
             raise ValueError("time out")
         still_waiting -= 1
         if not we_are_translated(): gil.before_external_call()
         time.sleep(0.01)
         if not we_are_translated(): gil.after_external_call()
     debug_print("leaving!")
     i1 = i2 = 0
     for tid, i in state.data:
         if tid == mainident:
             assert i == i1
             i1 += 1
         elif tid == subident:
             assert i == i2
             i2 += 1
         else:
             assert 0
     assert i1 == N + skew
     assert i2 == N - skew
     return len(state.data)
示例#3
0
def evaluateTerms(codes, scope):
    result = NullObject
    for code in codes:
        result = evaluateWithTraces(code, scope)
        if result is None:
            debug_print("Evaluation returned None!")
    return result
示例#4
0
 def debug_print(self, hdr='', bad=None):
     if bad is None:
         bad = {}
     debug_print(hdr + "VirtualState():")
     seen = {}
     for s in self.state:
         s.debug_print("    ", seen, bad)
示例#5
0
 def disable_noninlinable_function(self, greenkey):
     cell = self.JitCell.ensure_jit_cell_at_key(greenkey)
     cell.flags |= JC_DONT_TRACE_HERE
     debug_start("jit-disableinlining")
     loc = self.get_location_str(greenkey)
     debug_print("disabled inlining", loc)
     debug_stop("jit-disableinlining")
示例#6
0
 def _do(self, goal, func, *args, **kwds):
     title = func.task_title
     if goal in self.done:
         self.log.info("already done: %s" % title)
         return
     else:
         self.log.info("%s..." % title)
     debug_start('translation-task')
     debug_print('starting', goal)
     self.timer.start_event(goal)
     try:
         instrument = False
         try:
             if goal in PROFILE:
                 res = self._profile(goal, func)
             else:
                 res = func()
         except Instrument:
             instrument = True
         if not func.task_idempotent:
             self.done[goal] = True
         if instrument:
             self.proceed('compile')
             assert False, 'we should not get here'
     finally:
         try:
             debug_stop('translation-task')
             self.timer.end_event(goal)
         except (KeyboardInterrupt, SystemExit):
             raise
         except:
             pass
     #import gc; gc.dump_rpy_heap('rpyheap-after-%s.dump' % goal)
     return res
示例#7
0
def runUntilDone(vatManager, uv_loop, recorder):
    # This may take a while.
    anyVatHasTurns = vatManager.anyVatHasTurns()
    while anyVatHasTurns or ruv.loopAlive(uv_loop):
        for vat in vatManager.vats:
            if vat.hasTurns():
                with scopedVat(vat) as vat:
                    with recorder.context("Time spent in vats"):
                        vat.takeSomeTurns()

        if ruv.loopAlive(uv_loop):
            with recorder.context("Time spent in I/O"):
                ruv.cleanup()
                try:
                    if anyVatHasTurns:
                        # More work to be done, so don't block.
                        ruv.run(uv_loop, ruv.RUN_NOWAIT)
                    else:
                        # No more work to be done, so blocking is fine.
                        ruv.run(uv_loop, ruv.RUN_ONCE)
                except CompilerFailed as cf:
                    debug_print("Caught fatal exception while reacting:",
                            cf.formatError())
                    raise
                except UserException as ue:
                    debug_print("Caught exception while reacting:",
                            ue.formatError())

        anyVatHasTurns = vatManager.anyVatHasTurns()
示例#8
0
def runUntilDone(vatManager, uv_loop, recorder):
    # This may take a while.
    anyVatHasTurns = vatManager.anyVatHasTurns()
    while anyVatHasTurns or ruv.loopAlive(uv_loop):
        for vat in vatManager.vats:
            if vat.hasTurns():
                with scopedVat(vat) as vat:
                    with recorder.context("Time spent in vats"):
                        vat.takeSomeTurns()

        if ruv.loopAlive(uv_loop):
            with recorder.context("Time spent in I/O"):
                ruv.cleanup()
                try:
                    if anyVatHasTurns:
                        # More work to be done, so don't block.
                        ruv.run(uv_loop, ruv.RUN_NOWAIT)
                    else:
                        # No more work to be done, so blocking is fine.
                        ruv.run(uv_loop, ruv.RUN_ONCE)
                except CompilerFailed as cf:
                    debug_print("Caught fatal exception while reacting:",
                            cf.formatError())
                    raise
                except UserException as ue:
                    debug_print("Caught exception while reacting:",
                            ue.formatError())

        anyVatHasTurns = vatManager.anyVatHasTurns()
示例#9
0
 def malloc(self, TYPE, n=None):
     addr = self.gc.malloc(self.get_type_id(TYPE), n)
     debug_print(self.gc)
     obj_ptr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
     if not self.gc.malloc_zero_filled:
         zero_gc_pointers_inside(obj_ptr, TYPE)
     return obj_ptr
示例#10
0
 def invalidate(self, descr_repr=None):
     debug_start("jit-invalidate-quasi-immutable")
     # When this is called, all the loops that we record become
     # invalid: all GUARD_NOT_INVALIDATED in these loops (and
     # in attached bridges) must now fail.
     if self.looptokens_wrefs is None:
         # can't happen, but helps compiled tests
         return
     wrefs = self.looptokens_wrefs
     self.looptokens_wrefs = []
     invalidated = 0
     for wref in wrefs:
         looptoken = wref()
         if looptoken is not None:
             invalidated += 1
             looptoken.invalidated = True
             self.cpu.invalidate_loop(looptoken)
             # NB. we must call cpu.invalidate_loop() even if
             # looptoken.invalidated was already set to True.
             # It's possible to invalidate several times the
             # same looptoken; see comments in jit.backend.model
             # in invalidate_loop().
             if not we_are_translated():
                 self.cpu.stats.invalidated_token_numbers.add(
                     looptoken.number)
     debug_print("fieldname", descr_repr or "<unknown>", "invalidated",
                 invalidated)
     debug_stop("jit-invalidate-quasi-immutable")
示例#11
0
文件: env.py 项目: abhinavthomas/pypy
def get_L2cache_linux2_sparc():
    debug_start("gc-hardware")
    cpu = 0
    L2cache = sys.maxint
    while True:
        try:
            fd = os.open('/sys/devices/system/cpu/cpu' + assert_str0(str(cpu))
                         + '/l2_cache_size', os.O_RDONLY, 0644)
            try:
                line = os.read(fd, 4096)
            finally:
                os.close(fd)
            end = len(line) - 1
            assert end > 0
            number = int(line[:end])
        except OSError:
            break
        if number < L2cache:
            L2cache = number
        cpu += 1

    debug_print("L2cache =", L2cache)
    debug_stop("gc-hardware")
    if L2cache < sys.maxint:
        return L2cache
    else:
        # Print a top-level warning even in non-debug builds
        llop.debug_print(lltype.Void,
            "Warning: cannot find your CPU L2 cache size in "
            "/sys/devices/system/cpu/cpuX/l2_cache_size")
        return -1
示例#12
0
 def f(x):
     debug_start("mycat")
     debug_print("foo", 2, "bar", x)
     debug_stop("mycat")
     debug_flush()  # does nothing
     debug_offset()  # should not explode at least
     return have_debug_prints()
示例#13
0
def connectCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        fountResolver, drainResolver = unwrapList(resolvers)
        assert isinstance(fountResolver, LocalResolver)
        assert isinstance(drainResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                fountResolver.resolve(StreamFount(stream, vat))
                drainResolver.resolve(StreamDrain(stream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                fountResolver.smash(StrObject(error.decode("utf-8")))
                drainResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
示例#14
0
文件: env.py 项目: abhinavthomas/pypy
def get_total_memory_linux(filename):
    debug_start("gc-hardware")
    result = -1.0
    try:
        fd = os.open(filename, os.O_RDONLY, 0644)
        try:
            buf = os.read(fd, 4096)
        finally:
            os.close(fd)
    except OSError:
        pass
    else:
        if buf.startswith('MemTotal:'):
            start = _skipspace(buf, len('MemTotal:'))
            stop = start
            while stop < len(buf) and buf[stop].isdigit():
                stop += 1
            if start < stop:
                result = float(buf[start:stop]) * 1024.0   # assume kB
    if result < 0.0:
        debug_print("get_total_memory() failed")
        result = addressable_size
    else:
        debug_print("memtotal =", result)
        if result > addressable_size:
            result = addressable_size
    debug_stop("gc-hardware")
    return result
示例#15
0
def get_L2cache_linux2_sparc():
    debug_start("gc-hardware")
    cpu = 0
    L2cache = sys.maxint
    while True:
        try:
            fd = os.open(
                '/sys/devices/system/cpu/cpu' + assert_str0(str(cpu)) +
                '/l2_cache_size', os.O_RDONLY, 0644)
            try:
                line = os.read(fd, 4096)
            finally:
                os.close(fd)
            end = len(line) - 1
            assert end > 0
            number = int(line[:end])
        except OSError:
            break
        if number < L2cache:
            L2cache = number
        cpu += 1

    debug_print("L2cache =", L2cache)
    debug_stop("gc-hardware")
    if L2cache < sys.maxint:
        return L2cache
    else:
        # Print a top-level warning even in non-debug builds
        llop.debug_print(
            lltype.Void, "Warning: cannot find your CPU L2 cache size in "
            "/sys/devices/system/cpu/cpuX/l2_cache_size")
        return -1
示例#16
0
文件: endpoints.py 项目: dckc/typhon
def connectStreamCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        sourceResolver, sinkResolver = unwrapList(resolvers)
        assert isinstance(sourceResolver, LocalResolver)
        assert isinstance(sinkResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                wrappedStream = ruv.wrapStream(stream, 2)
                sourceResolver.resolve(StreamSource(wrappedStream, vat))
                sinkResolver.resolve(StreamSink(wrappedStream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                sourceResolver.smash(StrObject(error.decode("utf-8")))
                sinkResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
示例#17
0
 def dump(self, memo):
     if have_debug_prints():
         debug_start("jit-log-exported-state")
         debug_print("[" + ", ".join([x.repr_short(memo) for x in self.next_iteration_args]) + "]")
         for box in self.short_boxes:
             debug_print("  " + box.repr(memo))
         debug_stop("jit-log-exported-state")
示例#18
0
def get_L2cache_linux2_cpuinfo(filename="/proc/cpuinfo", label='cache size'):
    debug_start("gc-hardware")
    L2cache = sys.maxint
    try:
        fd = os.open(filename, os.O_RDONLY, 0644)
        try:
            data = []
            while True:
                buf = os.read(fd, 4096)
                if not buf:
                    break
                data.append(buf)
        finally:
            os.close(fd)
    except OSError:
        pass
    else:
        data = ''.join(data)
        linepos = 0
        while True:
            start = _findend(data, '\n' + label, linepos)
            if start < 0:
                break  # done
            linepos = _findend(data, '\n', start)
            if linepos < 0:
                break  # no end-of-line??
            # *** data[start:linepos] == "   : 2048 KB\n"
            start = _skipspace(data, start)
            if data[start] != ':':
                continue
            # *** data[start:linepos] == ": 2048 KB\n"
            start = _skipspace(data, start + 1)
            # *** data[start:linepos] == "2048 KB\n"
            end = start
            while '0' <= data[end] <= '9':
                end += 1
            # *** data[start:end] == "2048"
            if start == end:
                continue
            number = int(data[start:end])
            # *** data[end:linepos] == " KB\n"
            end = _skipspace(data, end)
            if data[end] not in ('K', 'k'):  # assume kilobytes for now
                continue
            number = number * 1024
            # for now we look for the smallest of the L2 caches of the CPUs
            if number < L2cache:
                L2cache = number

    debug_print("L2cache =", L2cache)
    debug_stop("gc-hardware")

    if L2cache < sys.maxint:
        return L2cache
    else:
        # Print a top-level warning even in non-debug builds
        llop.debug_print(
            lltype.Void,
            "Warning: cannot find your CPU L2 cache size in /proc/cpuinfo")
        return -1
示例#19
0
文件: test_gil.py 项目: charred/pypy
 def f():
     state.data = []
     state.datalen1 = 0
     state.datalen2 = 0
     state.datalen3 = 0
     state.datalen4 = 0
     state.threadlocals = gil.GILThreadLocals()
     state.threadlocals.setup_threads(space)
     thread.gc_thread_prepare()
     subident = thread.start_new_thread(bootstrap, ())
     mainident = thread.get_ident()
     runme(True)
     still_waiting = 3000
     while len(state.data) < 2*N:
         debug_print(len(state.data))
         if not still_waiting:
             raise ValueError("time out")
         still_waiting -= 1
         if not we_are_translated(): gil.before_external_call()
         time.sleep(0.01)
         if not we_are_translated(): gil.after_external_call()
     debug_print("leaving!")
     i1 = i2 = 0
     for tid, i in state.data:
         if tid == mainident:
             assert i == i1; i1 += 1
         elif tid == subident:
             assert i == i2; i2 += 1
         else:
             assert 0
     assert i1 == N + skew
     assert i2 == N - skew
     return len(state.data)
示例#20
0
 def malloc(self, TYPE, n=None):
     addr = self.gc.malloc(self.get_type_id(TYPE), n)
     debug_print(self.gc)
     obj_ptr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
     if not self.gc.malloc_zero_filled:
         zero_gc_pointers_inside(obj_ptr, TYPE)
     return obj_ptr
示例#21
0
文件: env.py 项目: abhinavthomas/pypy
def get_L2cache_linux2_cpuinfo_s390x(filename="/proc/cpuinfo", label='cache3'):
    debug_start("gc-hardware")
    L2cache = sys.maxint
    try:
        fd = os.open(filename, os.O_RDONLY, 0644)
        try:
            data = []
            while True:
                buf = os.read(fd, 4096)
                if not buf:
                    break
                data.append(buf)
        finally:
            os.close(fd)
    except OSError:
        pass
    else:
        data = ''.join(data)
        linepos = 0
        while True:
            start = _findend(data, '\n' + label, linepos)
            if start < 0:
                break    # done
            linepos = _findend(data, '\n', start)
            if linepos < 0:
                break    # no end-of-line??
            # *** data[start:linepos] == "   : level=2 type=Instruction scope=Private size=2048K ..."
            start = _skipspace(data, start)
            if data[start] != ':':
                continue
            # *** data[start:linepos] == ": level=2 type=Instruction scope=Private size=2048K ..."
            start = _skipspace(data, start + 1)
            # *** data[start:linepos] == "level=2 type=Instruction scope=Private size=2048K ..."
            start += 44
            end = start
            while '0' <= data[end] <= '9':
                end += 1
            # *** data[start:end] == "2048"
            if start == end:
                continue
            number = int(data[start:end])
            # *** data[end:linepos] == " KB\n"
            end = _skipspace(data, end)
            if data[end] not in ('K', 'k'):    # assume kilobytes for now
                continue
            number = number * 1024
            # for now we look for the smallest of the L2 caches of the CPUs
            if number < L2cache:
                L2cache = number

    debug_print("L2cache =", L2cache)
    debug_stop("gc-hardware")

    if L2cache < sys.maxint:
        return L2cache
    else:
        # Print a top-level warning even in non-debug builds
        llop.debug_print(lltype.Void,
            "Warning: cannot find your CPU L2 cache size in /proc/cpuinfo")
        return -1
示例#22
0
文件: warmstate.py 项目: charred/pypy
 def disable_noninlinable_function(self, greenkey):
     cell = self.jit_cell_at_key(greenkey)
     cell.dont_trace_here = True
     debug_start("jit-disableinlining")
     loc = self.get_location_str(greenkey)
     debug_print("disabled inlining", loc)
     debug_stop("jit-disableinlining")
示例#23
0
def load_linklet_from_fasl(file_name, set_version=False):
    from pycket.fasl import Fasl
    from pycket.env import w_version
    from pycket.util import console_log
    from pycket.ast_vs_sexp import deserialize_loop

    debug_start("loading-linklet")
    debug_print("Loading linklet from fasl -- %s" % file_name)
    sexp = Fasl().to_sexp_from_file(file_name)
    version_sexp, linklet_sexp = W_String.make(""), None
    if set_version:
        version_sexp = sexp.car()
        linklet_sexp = sexp.cdr()
    else:
        linklet_sexp = sexp
    linklet = None
    if "zo" in file_name:
        linklet = deserialize_loop(linklet_sexp)
    else:
        console_log("Run pycket with --make-linklet-zos to make the compiled zo files for bootstrap linklets", 1)
        compile_linklet = get_primitive("compile-linklet")
        linklet = compile_linklet.call_interpret([linklet_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false])

    if set_version:
        ver = version_sexp.as_str_ascii()
        console_log("Setting the version to %s" % ver)
        w_version.set_version(ver)

    debug_stop("loading-linklet")
    return linklet, version_sexp
示例#24
0
    def debug_print(self, indent, seen, bad, metainterp_sd=None):
        mark = ''
        if self in bad:
            mark = '*'
        if self.level == LEVEL_UNKNOWN:
            l = "Unknown"
        elif self.level == LEVEL_NONNULL:
            l = "NonNull"
        elif self.level == LEVEL_KNOWNCLASS:
            addr = self.known_class.getaddr()
            if metainterp_sd:
                name = metainterp_sd.get_name_from_address(addr)
            else:
                name = "?"
            l = "KnownClass(%s)" % name
        else:
            assert self.level == LEVEL_CONSTANT
            const = self.constbox
            if isinstance(const, ConstInt):
                l = "ConstInt(%s)" % (const.value, )
            elif isinstance(const, ConstPtr):
                if const.value:
                    l = "ConstPtr"
                else:
                    l = "ConstPtr(null)"
            else:
                assert isinstance(const, ConstFloat)
                l = "ConstFloat(%s)" % const.getfloat()

        lb = ''
        if self.lenbound:
            lb = ', ' + self.lenbound.bound.__repr__()

        debug_print(indent + mark + 'NotVirtualInfo(%d' % self.position +
                    ', ' + l + ', ' + self.intbound.__repr__() + lb + ')')
示例#25
0
文件: optimizer.py 项目: charred/pypy
 def make_guards(self, box):
     guards = []
     if self.level == LEVEL_CONSTANT:
         op = ResOperation(rop.GUARD_VALUE, [box, self.box], None)
         guards.append(op)
     elif self.level == LEVEL_KNOWNCLASS:
         op = ResOperation(rop.GUARD_NONNULL, [box], None)
         guards.append(op)
         op = ResOperation(rop.GUARD_CLASS, [box, self.known_class], None)
         guards.append(op)
     else:
         if self.level == LEVEL_NONNULL:
             op = ResOperation(rop.GUARD_NONNULL, [box], None)
             guards.append(op)
         self.intbound.make_guards(box, guards)
         if self.lenbound:
             lenbox = BoxInt()
             if self.lenbound.mode == MODE_ARRAY:
                 op = ResOperation(rop.ARRAYLEN_GC, [box], lenbox, self.lenbound.descr)
             elif self.lenbound.mode == MODE_STR:
                 op = ResOperation(rop.STRLEN, [box], lenbox, self.lenbound.descr)
             elif self.lenbound.mode == MODE_UNICODE:
                 op = ResOperation(rop.UNICODELEN, [box], lenbox, self.lenbound.descr)
             else:
                 debug_print("Unknown lenbound mode")
                 assert False
             guards.append(op)
             self.lenbound.bound.make_guards(lenbox, guards)
     return guards
示例#26
0
文件: driver.py 项目: yuyichao/pypy
 def _do(self, goal, func, *args, **kwds):
     title = func.task_title
     if goal in self.done:
         self.log.info("already done: %s" % title)
         return
     else:
         self.log.info("%s..." % title)
     debug_start('translation-task')
     debug_print('starting', goal)
     self.timer.start_event(goal)
     try:
         instrument = False
         try:
             if goal in PROFILE:
                 res = self._profile(goal, func)
             else:
                 res = func()
         except Instrument:
             instrument = True
         if not func.task_idempotent:
             self.done[goal] = True
         if instrument:
             self.proceed('compile')
             assert False, 'we should not get here'
     finally:
         try:
             debug_stop('translation-task')
             self.timer.end_event(goal)
         except (KeyboardInterrupt, SystemExit):
             raise
         except:
             pass
     #import gc; gc.dump_rpy_heap('rpyheap-after-%s.dump' % goal)
     return res
示例#27
0
 def f():
     state.data = []
     state.datalen1 = 0
     state.datalen2 = 0
     state.datalen3 = 0
     state.datalen4 = 0
     state.threadlocals = my_gil_threadlocals
     state.threadlocals.setup_threads(space)
     subident = thread.start_new_thread(bootstrap, ())
     mainident = thread.get_ident()
     runme(True)
     still_waiting = 3000
     while len(state.data) < 2*N:
         debug_print(len(state.data))
         if not still_waiting:
             llop.debug_print(lltype.Void, "timeout. progress: "
                              "%d of 2*N (= %f%%)" % \
                              (len(state.data), 2*N, 100*len(state.data)/(2.0*N)))
             raise ValueError("time out")
         still_waiting -= 1
         if not we_are_translated(): rgil.release()
         time.sleep(0.1)
         if not we_are_translated(): rgil.acquire()
     debug_print("leaving!")
     i1 = i2 = 0
     for tid, i in state.data:
         if tid == mainident:
             assert i == i1; i1 += 1
         elif tid == subident:
             assert i == i2; i2 += 1
         else:
             assert 0
     assert i1 == N + skew
     assert i2 == N - skew
     return len(state.data)
示例#28
0
 def f(x):
     debug_start("mycat")
     debug_print("foo", 2, "bar", x)
     debug_stop("mycat")
     debug_flush() # does nothing
     debug_offset() # should not explode at least
     return have_debug_prints()
示例#29
0
 def can_be_packed(self, lnode, rnode, origin_pack, forward):
     """ Check to ensure that two nodes might be packed into a Pair.
     """
     if isomorphic(lnode.getoperation(), rnode.getoperation()):
         # even if a guard depends on the previous it is able to
         lop = lnode.getoperation()
         independent = lnode.independent(rnode)
         if independent:
             if forward and origin_pack.is_accumulating():
                 # in this case the splitted accumulator must
                 # be combined. This case is not supported
                 debug_print("splitted accum must be flushed here (not supported)")
                 raise NotAVectorizeableLoop
             #
             if self.contains_pair(lnode, rnode):
                 return None
             #
             if origin_pack is None:
                 op = lnode.getoperation()
                 if rop.is_primitive_load(op.opnum):
                     return Pair(lnode, rnode)
                 else:
                     return Pair(lnode, rnode)
             if self.profitable_pack(lnode, rnode, origin_pack, forward):
                 return Pair(lnode, rnode)
         else:
             if self.contains_pair(lnode, rnode):
                 return None
             if origin_pack is not None:
                 return self.accumulates_pair(lnode, rnode, origin_pack)
     return None
示例#30
0
def compile_trace(metainterp, resumekey):
    """Try to compile a new bridge leading from the beginning of the history
    to some existing place.
    """

    from rpython.jit.metainterp.optimizeopt import optimize_trace

    # The history contains new operations to attach as the code for the
    # failure of 'resumekey.guard_op'.
    #
    # Attempt to use optimize_bridge().  This may return None in case
    # it does not work -- i.e. none of the existing old_loop_tokens match.
    
    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    if isinstance(resumekey, ResumeAtPositionDescr):
        inline_short_preamble = False
    else:
        inline_short_preamble = True
    inputargs = metainterp.history.inputargs[:]
    operations = metainterp.history.operations
    label = ResOperation(rop.LABEL, inputargs)
    jitdriver_sd = metainterp.jitdriver_sd
    enable_opts = jitdriver_sd.warmstate.enable_opts

    call_pure_results = metainterp.call_pure_results

    if operations[-1].getopnum() == rop.JUMP:
        data = BridgeCompileData(label, operations[:],
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts,
                                 inline_short_preamble=inline_short_preamble)
    else:
        data = SimpleCompileData(label, operations[:],
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts)
    try:
        info, newops = optimize_trace(metainterp_sd, jitdriver_sd,
                                      data, metainterp.box_names_memo)
    except InvalidLoop:
        #pdb.post_mortem(sys.exc_info()[2])
        debug_print("compile_new_bridge: got an InvalidLoop")
        # XXX I am fairly convinced that optimize_bridge cannot actually raise
        # InvalidLoop
        debug_print('InvalidLoop in compile_new_bridge')
        return None

    new_trace = create_empty_loop(metainterp)
    new_trace.operations = newops
    if info.quasi_immutable_deps:
        new_trace.quasi_immutable_deps = info.quasi_immutable_deps
    if info.final():
        new_trace.inputargs = info.inputargs
        target_token = new_trace.operations[-1].getdescr()
        resumekey.compile_and_attach(metainterp, new_trace, inputargs)
        record_loop_or_bridge(metainterp_sd, new_trace)
        return target_token
    new_trace.inputargs = info.renamed_inputargs
    metainterp.retrace_needed(new_trace, info)
    return None
示例#31
0
def load_linklet_from_fasl(file_name, set_version=False):
    from pycket.fasl import Fasl
    from pycket.env import w_version
    from pycket.util import console_log
    from pycket.ast_vs_sexp import deserialize_loop

    debug_start("loading-linklet")
    debug_print("Loading linklet from fasl -- %s" % file_name)
    sexp = Fasl().to_sexp_from_file(file_name)
    version_sexp, linklet_sexp = W_String.make(""), None
    if set_version:
        version_sexp = sexp.car()
        linklet_sexp = sexp.cdr()
    else:
        linklet_sexp = sexp
    linklet = None
    if "zo" in file_name:
        linklet = deserialize_loop(linklet_sexp)
    else:
        console_log("Run pycket with --make-linklet-zos to make the compiled zo files for bootstrap linklets", 1)
        compile_linklet = get_primitive("compile-linklet")
        linklet = compile_linklet.call_interpret([linklet_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false])

    if set_version:
        ver = version_sexp.as_str_ascii()
        console_log("Setting the version to %s" % ver)
        w_version.set_version(ver)

    debug_stop("loading-linklet")
    return linklet, version_sexp
示例#32
0
def evaluateTerms(codes, scope):
    result = NullObject
    for code in codes:
        result = evaluateWithTraces(code, scope)
        if result is None:
            debug_print("Evaluation returned None!")
    return result
示例#33
0
        def errorWithSpan(self, problem, span):
            """
            Throw a fatal error with span information.
            """

            debug_print(problem.encode("utf-8"))
            raise CompilerFailed(problem, span)
示例#34
0
 def debug_print(self, hdr="", bad=None, metainterp_sd=None):
     if bad is None:
         bad = {}
     debug_print(hdr + "VirtualState():")
     seen = {}
     for s in self.state:
         s.debug_print("    ", seen, bad, metainterp_sd)
示例#35
0
文件: unroll.py 项目: cimarieta/usp
 def dump(self, memo):
     if have_debug_prints():
         debug_start("jit-log-exported-state")
         debug_print("[" + ", ".join([x.repr_short(memo) for x in self.next_iteration_args]) + "]")
         for box in self.short_boxes:
             debug_print("  " + box.repr(memo))
         debug_stop("jit-log-exported-state")
示例#36
0
文件: model.py 项目: soIu/rpython
 def compiling_a_bridge(self):
     self.cpu.tracker.total_compiled_bridges += 1
     self.bridges_count += 1
     debug_start("jit-mem-looptoken-alloc")
     debug_print("allocating Bridge #", self.bridges_count, "of Loop #",
                 self.number)
     debug_stop("jit-mem-looptoken-alloc")
示例#37
0
 def debug_print(self, hdr='', bad=None, metainterp_sd=None):
     if bad is None:
         bad = {}
     debug_print(hdr + "VirtualState():")
     seen = {}
     for s in self.state:
         s.debug_print("    ", seen, bad, metainterp_sd)
示例#38
0
 def disable_noninlinable_function(self, greenkey):
     cell = self.JitCell.ensure_jit_cell_at_key(greenkey)
     cell.flags |= JC_DONT_TRACE_HERE
     debug_start("jit-disableinlining")
     loc = self.get_location_str(greenkey)
     debug_print("disabled inlining", loc)
     debug_stop("jit-disableinlining")
示例#39
0
def get_total_memory_linux(filename):
    debug_start("gc-hardware")
    result = -1.0
    try:
        fd = os.open(filename, os.O_RDONLY, 0644)
        try:
            buf = os.read(fd, 4096)
        finally:
            os.close(fd)
    except OSError:
        pass
    else:
        if buf.startswith('MemTotal:'):
            start = _skipspace(buf, len('MemTotal:'))
            stop = start
            while stop < len(buf) and buf[stop].isdigit():
                stop += 1
            if start < stop:
                result = float(buf[start:stop]) * 1024.0  # assume kB
    if result < 0.0:
        debug_print("get_total_memory() failed")
        result = addressable_size
    else:
        debug_print("memtotal =", result)
        if result > addressable_size:
            result = addressable_size
    debug_stop("gc-hardware")
    return result
示例#40
0
文件: unroll.py 项目: Mu-L/pypy
 def optimize_bridge(self, trace, runtime_boxes, call_pure_results,
                     inline_short_preamble, box_names_memo, resumestorage):
     from rpython.jit.metainterp.optimizeopt.bridgeopt import deserialize_optimizer_knowledge
     frontend_inputargs = trace.inputargs
     trace = trace.get_iter()
     self.optunroll._check_no_forwarding([trace.inputargs])
     if resumestorage:
         deserialize_optimizer_knowledge(self, resumestorage,
                                         frontend_inputargs,
                                         trace.inputargs)
     info, ops = self.propagate_all_forward(trace, call_pure_results, False)
     jump_op = info.jump_op
     cell_token = jump_op.getdescr()
     assert isinstance(cell_token, JitCellToken)
     if not inline_short_preamble or len(cell_token.target_tokens) == 1:
         self.jump_to_preamble(cell_token, jump_op)
         return info, self._newoperations[:]
     # force all the information that does not go to the short
     # preamble at all
     self.flush()
     for a in jump_op.getarglist():
         self.force_box_for_end_of_preamble(a)
     try:
         vs = self.optunroll.jump_to_existing_trace(jump_op,
                                                    None,
                                                    runtime_boxes,
                                                    force_boxes=False)
     except InvalidLoop:
         self.jump_to_preamble(cell_token, jump_op)
         return info, self._newoperations[:]
     if vs is None:
         return info, self._newoperations[:]
     warmrunnerdescr = self.metainterp_sd.warmrunnerdesc
     limit = warmrunnerdescr.memory_manager.retrace_limit
     if cell_token.retraced_count < limit:
         cell_token.retraced_count += 1
         debug_print('Retracing (%d/%d)' %
                     (cell_token.retraced_count, limit))
     else:
         # Try forcing boxes to avoid jumping to the preamble
         try:
             vs = self.optunroll.jump_to_existing_trace(jump_op,
                                                        None,
                                                        runtime_boxes,
                                                        force_boxes=True)
         except InvalidLoop:
             pass
         if vs is None:
             return info, self._newoperations[:]
         debug_print("Retrace count reached, jumping to preamble")
         self.jump_to_preamble(cell_token, jump_op)
         return info, self._newoperations[:]
     exported_state = self.optunroll.export_state(info.jump_op.getarglist(),
                                                  info.inputargs,
                                                  runtime_boxes,
                                                  box_names_memo)
     exported_state.quasi_immutable_deps = self.quasi_immutable_deps
     self._clean_optimization_info(self._newoperations)
     return exported_state, self._newoperations
示例#41
0
文件: compile.py 项目: sota/pypy-old
def compile_trace(metainterp, resumekey, runtime_boxes):
    """Try to compile a new bridge leading from the beginning of the history
    to some existging place.
    """

    from rpython.jit.metainterp.optimizeopt import optimize_trace

    # The history contains new operations to attach as the code for the
    # failure of 'resumekey.guard_op'.
    #
    # Attempt to use optimize_bridge().  This may return None in case
    # it does not work -- i.e. none of the existing old_loop_tokens match.

    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    if isinstance(resumekey, ResumeAtPositionDescr):
        inline_short_preamble = False
    else:
        inline_short_preamble = True
    inputargs = metainterp.history.inputargs[:]
    trace = metainterp.history.trace
    jitdriver_sd = metainterp.jitdriver_sd
    enable_opts = jitdriver_sd.warmstate.enable_opts

    call_pure_results = metainterp.call_pure_results

    if metainterp.history.ends_with_jump:
        data = BridgeCompileData(trace, runtime_boxes,
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts,
                                 inline_short_preamble=inline_short_preamble)
    else:
        data = SimpleCompileData(trace,
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts)
    try:
        info, newops = optimize_trace(metainterp_sd, jitdriver_sd,
                                      data, metainterp.box_names_memo)
    except InvalidLoop:
        #pdb.post_mortem(sys.exc_info()[2])
        debug_print("compile_new_bridge: got an InvalidLoop")
        # XXX I am fairly convinced that optimize_bridge cannot actually raise
        # InvalidLoop
        debug_print('InvalidLoop in compile_new_bridge')
        return None

    new_trace = create_empty_loop(metainterp)
    new_trace.operations = newops
    if info.quasi_immutable_deps:
        new_trace.quasi_immutable_deps = info.quasi_immutable_deps
    if info.final():
        new_trace.inputargs = info.inputargs
        target_token = new_trace.operations[-1].getdescr()
        resumekey.compile_and_attach(metainterp, new_trace, inputargs)
        record_loop_or_bridge(metainterp_sd, new_trace)
        return target_token
    new_trace.inputargs = info.renamed_inputargs
    metainterp.retrace_needed(new_trace, info)
    return None
示例#42
0
def _instantiate_linklet(file_name_for_log, linkl):
    debug_start("instantiating-linklet")
    debug_print("Instantiating : %s" % file_name_for_log)
    instantiate_linklet = get_primitive("instantiate-linklet")
    linkl_instance = instantiate_linklet.call_interpret([linkl, w_null, w_false, w_false])
    debug_print("DONE Instantiating %s ...."  % file_name_for_log)
    debug_stop("instantiating-linklet")
    return linkl_instance
示例#43
0
def evaluateWithTraces(code, scope):
    try:
        machine = SmallCaps.withDictScope(code, scope)
        machine.run()
        return machine.pop()
    except UserException as ue:
        debug_print("Caught exception:", ue.formatError())
        return None
示例#44
0
def evaluateWithTraces(code, scope):
    try:
        machine = SmallCaps.withDictScope(code, scope)
        machine.run()
        return machine.pop()
    except UserException as ue:
        debug_print("Caught exception:", ue.formatError())
        return None
示例#45
0
def _instantiate_linklet(file_name_for_log, linkl):
    debug_start("instantiating-linklet")
    debug_print("Instantiating : %s" % file_name_for_log)
    instantiate_linklet = get_primitive("instantiate-linklet")
    linkl_instance = instantiate_linklet.call_interpret([linkl, w_null, w_false, w_false])
    debug_print("DONE Instantiating %s ...."  % file_name_for_log)
    debug_stop("instantiating-linklet")
    return linkl_instance
示例#46
0
 def debug_print(self, logops):
     if 0:
         debug_start('jit-short-boxes')
         for box, op in self.short_boxes.items():
             if op:
                 debug_print(logops.repr_of_arg(box) + ': ' + logops.repr_of_resop(op))
             else:
                 debug_print(logops.repr_of_arg(box) + ': None')
         debug_stop('jit-short-boxes')
示例#47
0
 def debug_print(self, logops):
     if 0:
         debug_start('jit-short-boxes')
         for box, op in self.short_boxes.items():
             if op:
                 debug_print(logops.repr_of_arg(box) + ': ' + logops.repr_of_resop(op))
             else:
                 debug_print(logops.repr_of_arg(box) + ': None')
         debug_stop('jit-short-boxes')
示例#48
0
文件: hybrid.py 项目: charred/pypy
 def _check_rawsize_alloced(self, size_estimate):
     self.large_objects_collect_trigger -= size_estimate
     if self.large_objects_collect_trigger < 0:
         debug_start("gc-rawsize-collect")
         debug_print("allocated", (self._initial_trigger -
                                   self.large_objects_collect_trigger),
                     "bytes, triggering full collection")
         self.semispace_collect()
         debug_stop("gc-rawsize-collect")
示例#49
0
 def log_loop_from_trace(self, trace, memo):
     if not have_debug_prints():
         return
     inputargs, ops = self._unpack_trace(trace)
     debug_start("jit-log-noopt")
     debug_print("# Traced loop or bridge with", len(ops), "ops")
     logops = self._log_operations(inputargs, ops, None, memo)
     debug_stop("jit-log-noopt")
     return logops
示例#50
0
 def debug_print(self, logops):
     if 0:
         debug_start("jit-short-boxes")
         for box, op in self.short_boxes.items():
             if op:
                 debug_print(logops.repr_of_arg(box) + ": " + logops.repr_of_resop(op))
             else:
                 debug_print(logops.repr_of_arg(box) + ": None")
         debug_stop("jit-short-boxes")
示例#51
0
文件: snippet.py 项目: mozillazg/pypy
 def finalizer_trigger(self):
     from rpython.rlib.debug import debug_print
     while True:
         a = self.next_dead()
         if a is None:
             break
         debug_print("DEL:", a.key)
         assert age_of(a.key) == -1
         set_age_of(a.key, state.time)
         state.progress = True
示例#52
0
文件: snippet.py 项目: soIu/rpython
 def finalizer_trigger(self):
     from rpython.rlib.debug import debug_print
     while True:
         a = self.next_dead()
         if a is None:
             break
         debug_print("DEL:", a.key)
         assert age_of(a.key) == -1
         set_age_of(a.key, state.time)
         state.progress = True
示例#53
0
文件: hybrid.py 项目: sota/pypy-old
 def _check_rawsize_alloced(self, size_estimate):
     self.large_objects_collect_trigger -= size_estimate
     if self.large_objects_collect_trigger < 0:
         debug_start("gc-rawsize-collect")
         debug_print(
             "allocated",
             (self._initial_trigger - self.large_objects_collect_trigger),
             "bytes, triggering full collection")
         self.semispace_collect()
         debug_stop("gc-rawsize-collect")
示例#54
0
 def _invalid_write(self, message, offset, length, descr, value):
     debug_start('jit-log-rawbuffer')
     debug_print('Invalid write: %s' % message)
     debug_print("  offset: %d" % offset)
     debug_print("  length: %d" % length)
     debug_print("  descr:  %s" % self._repr_of_descr(descr))
     debug_print("  value:  %s" % self._repr_of_value(value))
     self._dump_to_log()
     debug_stop('jit-log-rawbuffer')
     raise InvalidRawWrite
示例#55
0
def optimize_vector(trace, metainterp_sd, jitdriver_sd, warmstate,
                    loop_info, loop_ops, jitcell_token=None):
    """ Enter the world of SIMD. Bails if it cannot transform the trace. """
    user_code = not jitdriver_sd.vec and warmstate.vec_all
    e = len(loop_ops)-1
    assert e > 0
    assert rop.is_final(loop_ops[e].getopnum())
    loop = VectorLoop(loop_info.label_op, loop_ops[:e], loop_ops[-1])
    if user_code and user_loop_bail_fast_path(loop, warmstate):
        return loop_info, loop_ops
    # the original loop (output of optimize_unroll)
    info = LoopVersionInfo(loop_info)
    version = info.snapshot(loop)
    loop.setup_vectorization()
    try:
        debug_start("vec-opt-loop")
        metainterp_sd.logger_noopt.log_loop([], loop.finaloplist(label=True), -2, None, None, "pre vectorize")
        metainterp_sd.profiler.count(Counters.OPT_VECTORIZE_TRY)
        #
        start = time.clock()
        opt = VectorizingOptimizer(metainterp_sd, jitdriver_sd, warmstate.vec_cost)
        index_vars = opt.run_optimization(info, loop)
        gso = GuardStrengthenOpt(index_vars)
        gso.propagate_all_forward(info, loop, user_code)
        end = time.clock()
        #
        metainterp_sd.profiler.count(Counters.OPT_VECTORIZED)
        metainterp_sd.logger_noopt.log_loop([], loop.finaloplist(label=True), -2, None, None, "post vectorize")
        nano = int((end-start)*10.0**9)
        debug_print("# vecopt factor: %d opcount: (%d -> %d) took %dns" % \
                      (opt.unroll_count+1, len(version.loop.operations), len(loop.operations), nano))
        debug_stop("vec-opt-loop")
        #
        info.label_op = loop.label
        return info, loop.finaloplist(jitcell_token=jitcell_token, reset_label_token=False)
    except NotAVectorizeableLoop:
        debug_stop("vec-opt-loop")
        # vectorization is not possible
        return loop_info, version.loop.finaloplist()
    except NotAProfitableLoop:
        debug_stop("vec-opt-loop")
        # cost model says to skip this loop
        return loop_info, version.loop.finaloplist()
    except Exception as e:
        debug_stop("vec-opt-loop")
        debug_print("failed to vectorize loop. THIS IS A FATAL ERROR!")
        if we_are_translated():
            from rpython.rtyper.lltypesystem import lltype
            from rpython.rtyper.lltypesystem.lloperation import llop
            llop.debug_print_traceback(lltype.Void)
        else:
            raise
    finally:
        loop.teardown_vectorization()
    return loop_info, loop_ops
示例#56
0
 def debug_print(self, indent, seen, bad, metainterp_sd):
     mark = ""
     if self in bad:
         mark = "*"
     self.debug_header(indent + mark)
     if self not in seen:
         seen[self] = True
         for s in self.fieldstate:
             s.debug_print(indent + "    ", seen, bad, metainterp_sd)
     else:
         debug_print(indent + "    ...")