def alloc_hinted(hintp, map_size): flags = MAP_PRIVATE | MAP_ANONYMOUS prot = PROT_EXEC | PROT_READ | PROT_WRITE if we_are_translated(): flags = NonConstant(flags) prot = NonConstant(prot) return c_mmap_safe(hintp, map_size, prot, flags, -1, 0)
def clear_large_memory_chunk_aligned(addr, map_size): addr = rffi.cast(PTR, addr) flags = MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS prot = PROT_READ | PROT_WRITE if we_are_translated(): flags = NonConstant(flags) prot = NonConstant(prot) res = c_mmap_safe(addr, map_size, prot, flags, -1, 0) return res == addr
def alloc_hinted(hintp, map_size, hugetlb=False): debug_start("jit-alloc") debug_print("Map size: %d" % map_size) debug_stop("jit-alloc") flags = MAP_PRIVATE | MAP_ANONYMOUS if hugetlb: flags = flags | MAP_HUGETLB prot = PROT_EXEC | PROT_READ | PROT_WRITE if we_are_translated(): flags = NonConstant(flags) prot = NonConstant(prot) return c_mmap_safe(hintp, map_size, prot, flags, -1, 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) 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')
def q(self, code): "!q for quitting" if objectmodel.we_are_translated(): from rpython.rlib.nonconst import NonConstant os._exit(NonConstant(0)) else: os._exit(0)
def isvirtual(value): """ Returns if this value is virtual, while tracing, it's relatively conservative and will miss some cases. This is for advanced usage only. """ return NonConstant(False)
def isconstant(value): """ While tracing, returns whether or not the value is currently known to be constant. This is not perfect, values can become constant later. Mostly for use with @look_inside_iff. This is for advanced usage only. """ return NonConstant(False)
def f(): s = NonConstant('a') w_s = space.newutf8(s, 1) t, l = space.utf8_len_w(w_s) a = A() if l == 1: a.x = 1 else: raise Exception return a.x
def non_constant(bytecode, pool): from rpython.rlib.nonconst import NonConstant if NonConstant(False): pool = ConstantPool() pool.add_string("foo") pool.add_string("bazz") pool.add_classdescr(["a", "bc"], [("foo", 3), ("y", 5)]) return "123", pool else: return bytecode, pool
def fix_annotation(self): # the annotation of the class and its attributes must be completed # BEFORE we do the gc transform; this makes sure that everything is # annotated with the correct types if NonConstant(False): self.count = NonConstant(-42) self.num_major_collects = NonConstant(-42) self.arenas_count_before = NonConstant(-42) self.arenas_count_after = NonConstant(-42) self.arenas_bytes = NonConstant(r_uint(42)) self.rawmalloc_bytes_before = NonConstant(r_uint(42)) self.rawmalloc_bytes_after = NonConstant(r_uint(42)) self.fire()
def fix_annotation(self): # the annotation of the class and its attributes must be completed # BEFORE we do the gc transform; this makes sure that everything is # annotated with the correct types if NonConstant(False): self.count = NonConstant(-42) self.duration = NonConstant(r_longlong(-42)) self.duration_min = NonConstant(r_longlong(-42)) self.duration_max = NonConstant(r_longlong(-42)) self.oldstate = NonConstant(-42) self.newstate = NonConstant(-42) self.fire()
def fix_annotation(self): # the annotation of the class and its attributes must be completed # BEFORE we do the gc transform; this makes sure that everything is # annotated with the correct types if NonConstant(False): self.count = NonConstant(-42) self.duration = NonConstant(-53.2) self.duration_min = NonConstant(-53.2) self.duration_max = NonConstant(-53.2) self.total_memory_used = NonConstant(r_uint(42)) self.pinned_objects = NonConstant(-42) self.fire()
def set_param_enable_opts(self, value): from rpython.jit.metainterp.optimizeopt import ALL_OPTS_DICT, ALL_OPTS_NAMES d = {} if NonConstant(False): value = 'blah' # not a constant '' if value is None or value == 'all': value = ALL_OPTS_NAMES for name in value.split(":"): if name: if name not in ALL_OPTS_DICT: raise ValueError('Unknown optimization ' + name) d[name] = None self.enable_opts = d
def set_trace_too_long_hook(space, w_hook): """ set_trace_too_long_hook(hook) Set a hook (callable) that will be called each time we abort tracing because the trace is too long. The hook will be called with the signature: hook(jitdriver_name, greenkey) """ cache = space.fromcache(Cache) assert w_hook is not None cache.w_trace_too_long_hook = w_hook cache.in_recursion = NonConstant(False)
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_RDWR | os.O_CREAT, 0666) num = 10000 period = 0.0001 rvmprof.enable(fd, period, native=1) for i in range(num): res = main(code, 3) rvmprof.disable() os.close(fd) return 0
def set_optimize_hook(space, w_hook): """ set_optimize_hook(hook) Set a compiling hook that will be called each time a loop is optimized, but before assembler compilation. This allows adding additional optimizations on Python level. The hook will be called with the pypyjit.JitLoopInfo object. Refer to it's docstring for details. Result value will be the resulting list of operations, or None """ cache = space.fromcache(Cache) cache.w_optimize_hook = w_hook cache.in_recursion = NonConstant(False)
def set_compile_hook(space, w_hook): """ set_compile_hook(hook) 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) assert w_hook is not None cache.w_compile_hook = w_hook cache.in_recursion = NonConstant(False)
def entry_point(argv): # <vmprof-hack> if NonConstant(False): fake_vmprof_main(FakeVMProfCode(), 42) # </vmprof-hack> # seed = 0 if len(argv) > 1: seed = int(argv[1]) runner.init(seed) for name, meth in Runner.TESTS: print '-----', name, '-----' meth(runner) print '----- all done -----' runner.done() return 0
def hpy_err_Occurred_rpy(space): if we_are_translated(): # this function should never been called after translation. We can't # simply put an assert else the annotator complains that the function # returns Void, hack hack hack if NonConstant(False): return API.int(-42) assert False # # this is a bit of a hack: it will never aim to be correct in 100% of # cases, but since it's used only for tests, it's enough. If an # exception was raised by an HPy call, it must be stored in # ll2ctypes._callback_exc_info, waiting to be properly re-raised as # soon as we exit the C code, by # ll2ctypes:get_ctypes_trampoline:invoke_via_ctypes res = ll2ctypes._callback_exc_info is not None return API.int(res)
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) assert w_hook is not None cache.w_abort_hook = w_hook cache.in_recursion = NonConstant(False)
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
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
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
def fn(x): return NonConstant(x)
def fn(): return bool(NonConstant(False))
def nonconst_i(): return NonConstant(a)
def nonconst_l(): a = NonConstant([1, 2, 3]) return a[0]
def nonconst_f(): a = NonConstant(3) return a
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
def issubtype_w(self, w_sub, w_type): is_root(w_type) return NonConstant(True)