Пример #1
0
def set_abort_hook(space, w_hook):
    """ set_abort_hook(hook)

    Set a hook (callable) that will be called each time there is tracing
    aborted due to some reason.

    The hook will be called with the signature:

        hook(jitdriver_name, greenkey, reason, operations)

    Reason is a string, the meaning of other arguments is the same
    as attributes on JitLoopInfo object.
    """
    cache = space.fromcache(Cache)
    if space.is_w(w_hook, space.w_None):
        w_hook = None
    cache.w_abort_hook = w_hook
    cache.in_recursion = NonConstant(False)
Пример #2
0
def main(argv=[]):
    rthread.get_ident()  # force TLOFS_thread_ident
    if NonConstant(False):
        # Hack to give os.open() the correct annotation
        os.open('foo', 1, 1)
    code1 = MyCode(6500)
    fd = os.open(PROF_FILE, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666)
    rvmprof.enable(fd, 0.01)
    #
    code2 = MyCode(9100)
    stop = time.time() + 1
    while time.time() < stop:
        interpret(code1)
        interpret(code2)
    #
    rvmprof.disable()
    os.close(fd)
    return 0
Пример #3
0
def set_compile_hook(space, w_hook, operations=True):
    """ set_compile_hook(hook, operations=True)

    Set a compiling hook that will be called each time a loop is compiled.

    The hook will be called with the pypyjit.JitLoopInfo object. Refer to it's
    docstring for details.

    Note that jit hook is not reentrant. It means that if the code
    inside the jit hook is itself jitted, it will get compiled, but the
    jit hook won't be called for that.
    """
    cache = space.fromcache(Cache)
    if space.is_w(w_hook, space.w_None):
        w_hook = None
    cache.w_compile_hook = w_hook
    cache.compile_hook_with_ops = operations
    cache.in_recursion = NonConstant(False)
Пример #4
0
 def f():
     if NonConstant(False):
         # Hack to give os.open() the correct annotation
         os.open('foo', 1, 1)
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     if we_are_translated():
         num = 100000000
         period = 0.0001
     else:
         num = 10000
         period = 0.9
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Пример #5
0
    def walk_stack_from(self):
        curframe = lltype.malloc(WALKFRAME, flavor='raw')
        otherframe = lltype.malloc(WALKFRAME, flavor='raw')

        # Walk over all the pieces of stack.  They are in a circular linked
        # list of structures of 7 words, the 2 first words being prev/next.
        # The anchor of this linked list is:
        anchor = llmemory.cast_ptr_to_adr(gcrootanchor)
        initialframedata = anchor.address[1]
        stackscount = 0
        while initialframedata != anchor:  # while we have not looped back
            self.walk_frames(curframe, otherframe, initialframedata)
            # Then proceed to the next piece of stack
            initialframedata = initialframedata.address[1]
            stackscount += 1
        #
        # for the JIT: rpy_fastgil may contain an extra framedata
        rpy_fastgil = rgil.gil_fetch_fastgil().signed[0]
        if rpy_fastgil != 1:
            ll_assert(rpy_fastgil != 0, "walk_stack_from doesn't have the GIL")
            initialframedata = rffi.cast(llmemory.Address, rpy_fastgil)
            #
            # very rare issue: initialframedata.address[0] is uninitialized
            # in this case, but "retaddr = callee.frame_address.address[0]"
            # reads it.  If it happens to be exactly a valid return address
            # inside the C code, then bad things occur.
            initialframedata.address[0] = llmemory.NULL
            #
            self.walk_frames(curframe, otherframe, initialframedata)
            stackscount += 1
        #
        expected = rffi.stackcounter.stacks_counter
        if NonConstant(0):
            rffi.stackcounter.stacks_counter += 42  # hack to force it
        ll_assert(not (stackscount < expected), "non-closed stacks around")
        ll_assert(not (stackscount > expected), "stacks counter corruption?")
        lltype.free(otherframe, flavor='raw')
        lltype.free(curframe, flavor='raw')
Пример #6
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        if NonConstant(False):
            # Hack to give os.open() the correct annotation
            os.open('foo', 1, 1)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        modtable = ModTable()
        modtable.enter_module(module_name)
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        modtable.exit_module(module_name, ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            if config.get('save-callgraph', False):
                with open('callgraph.dot', 'w') as outfile:
                    env.callgraph.write_dot_file(outfile)
            shutdown(env)
        return 0
Пример #7
0
 def fn():
     return bool(NonConstant(False))
Пример #8
0
 def nonconst_l():
     a = NonConstant([1, 2, 3])
     return a[0]
Пример #9
0
def current_trace_length():
    """During JIT tracing, returns the current trace length (as a constant).
    If not tracing, returns -1."""
    if NonConstant(False):
        return 73
    return -1
Пример #10
0
def w_obj_or_none():
    if NonConstant(False):
        return None
    return w_some_obj()
Пример #11
0
 def bigint_w(self, space, allow_conversion=True):
     from rpython.rlib.rbigint import rbigint
     x = 42
     if we_are_translated():
         x = NonConstant(x)
     return rbigint.fromint(x)
Пример #12
0
 def int_w(self, space, allow_conversion=True):
     return NonConstant(-42)
Пример #13
0
 def len_w(self, w_obj):
     return NonConstant(37)
Пример #14
0
 def hash_w(self, w_obj):
     return NonConstant(32)
Пример #15
0
 def is_true(self, w_obj):
     is_root(w_obj)
     return NonConstant(False)
Пример #16
0
 def str_w(self, space):
     return NonConstant("foobar")
Пример #17
0
 def utf8_w(self, space):
     return NonConstant("foobar")
Пример #18
0
 def utf8_len_w(self, space):
     return NonConstant((NonConstant("utf8len_foobar"), NonConstant(14)))
Пример #19
0
 def uint_w(self, space):
     return r_uint(NonConstant(42))
Пример #20
0
 def check():
     scope_w = [w_some_obj()] * NonConstant(42)
     w_result = activation._run(self, scope_w)
     is_root(w_result)
Пример #21
0
def w_some_obj():
    if NonConstant(False):
        return W_Root()
    return W_MyObject()
Пример #22
0
 def setdictvalue(self, space, attr, w_value):
     attr + "xx"   # check that it's a string
     is_root(w_value)
     return NonConstant(True)
Пример #23
0
 def issubtype_w(self, w_sub, w_type):
     is_root(w_type)
     return NonConstant(True)
Пример #24
0
 def isinstance_w(self, w_inst, w_type):
     is_root(w_inst)
     is_root(w_type)
     return NonConstant(True)
Пример #25
0
 def nonconst_f():
     a = NonConstant(3)
     return a
Пример #26
0
 def decode_index4(self, w_index_or_slice, seqlength):
     is_root(w_index_or_slice)
     return (NonConstant(42), NonConstant(42),
             NonConstant(42), NonConstant(42))
Пример #27
0
 def nonconst_i():
     return NonConstant(a)
Пример #28
0
 def deldictvalue(self, space, attr):
     attr + "xx"   # check that it's a string
     return NonConstant(True)
Пример #29
0
 def fn(x):
     return NonConstant(x)
Пример #30
0
 def is_generator(self, w_obj):
     return NonConstant(False)