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
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
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
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
def failnbail_transformation(msg): msg = '%s\n' % msg if we_are_translated(): llop.debug_print(lltype.Void, msg) else: import pdb; pdb.set_trace() raise NotImplementedError(msg)
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)
def check_size(self, size=-1): if size == -1: size = self.size if size >= 2**19: msg = '[S390X/literalpool] size exceeded %d >= %d\n' % (size, 2**19) if we_are_translated(): llop.debug_print(lltype.Void, msg) raise PoolOverflow(msg)
def check_size(self, size=-1): if size == -1: size = self.size if size >= 2**19: msg = '[S390X/literalpool] size exceeded %d >= %d\n' % (size, 2** 19) if we_are_translated(): llop.debug_print(lltype.Void, msg) raise PoolOverflow(msg)
def f(): ref = g() llop.gc__collect(lltype.Void, 1) # start a major cycle # at this point the stack is scanned, and the weakref points # to an object not found, but still reachable: b = ref() llop.debug_print(lltype.Void, b) assert b is not None llop.gc__collect(lltype.Void) # finish the major cycle # assert does not crash, because 'b' is still kept alive b.x = 42 return ref() is b
def get_L2cache_linux2_cpuinfo_s390x(filename="/proc/cpuinfo", label='cache2'): 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 start = _findend(data, 'size=', start) if start < 0: break end = _findend(data, ' ', start) - 1 if end < 0: break linepos = end size = data[start:end] last_char = len(size) - 1 assert 0 <= last_char < len(size) if size[last_char] not in ('K', 'k'): # assume kilobytes for now continue number = int(size[:last_char]) * 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
def get_L2cache_linux2_cpuinfo_s390x(filename="/proc/cpuinfo", label='cache2'): 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 start = _findend(data, 'size=', start) if start < 0: break end = _findend(data, ' ', start) - 1 if end < 0: break linepos = end size = data[start:end] last_char = len(size)-1 assert 0 <= last_char < len(size) if size[last_char] not in ('K', 'k'): # assume kilobytes for now continue number = int(size[:last_char])* 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
def f(x, y): persistent_a1 = A() persistent_a2 = A() i = 0 while i < x: i += 1 a = A() persistent_a3 = A() persistent_a4 = A() llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) b.bla = persistent_a1.id + persistent_a2.id + persistent_a3.id + persistent_a4.id # NB print would create a static root! llop.debug_print(lltype.Void, b.num_deleted_c) return b.num_deleted
def _check_invariants(self): if not we_are_translated(): # make sure no duplicates assert len(dict.fromkeys(self.reg_bindings.values())) == len(self.reg_bindings) rev_regs = dict.fromkeys(self.reg_bindings.values()) for reg in self.free_regs: assert reg not in rev_regs assert len(rev_regs) + len(self.free_regs) == len(self.all_regs) else: assert len(self.reg_bindings) + len(self.free_regs) == len(self.all_regs) assert len(self.temp_boxes) == 0 if self.longevity: for v in self.reg_bindings: if v not in self.longevity: llop.debug_print(lltype.Void, "variable %s not in longevity\n" % v.repr({})) assert self.longevity[v][1] > self.position
def get_L2cache_darwin(): """Try to estimate the best nursery size at run-time, depending on the machine we are running on. """ debug_start("gc-hardware") L2cache = get_darwin_sysctl_signed("hw.l2cachesize") L3cache = get_darwin_sysctl_signed("hw.l3cachesize") debug_print("L2cache =", L2cache) debug_print("L3cache =", L3cache) debug_stop("gc-hardware") mangled = L2cache + L3cache if mangled > 0: return mangled else: # Print a top-level warning even in non-debug builds llop.debug_print(lltype.Void, "Warning: cannot find your CPU L2 cache size with sysctl()") return -1
def get_L2cache_darwin(): """Try to estimate the best nursery size at run-time, depending on the machine we are running on. """ debug_start("gc-hardware") L2cache = get_darwin_sysctl_signed("hw.l2cachesize") L3cache = get_darwin_sysctl_signed("hw.l3cachesize") debug_print("L2cache =", L2cache) debug_print("L3cache =", L3cache) debug_stop("gc-hardware") mangled = L2cache + L3cache if mangled > 0: return mangled else: # Print a top-level warning even in non-debug builds llop.debug_print( lltype.Void, "Warning: cannot find your CPU L2 cache size with sysctl()") return -1
def l(y, x, t): llop.debug_print(lltype.Void, y, x, t)
def not_implemented(msg): msg = '[llsupport/regalloc] %s\n' % msg if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg)
def externfn(node): llop.debug_print(lltype.Void, compute_unique_id(node), node.value, node.extra) return node.value * 2
def rewrite(self, operations, gcrefs_output_list): # we can only remember one malloc since the next malloc can possibly # collect; but we can try to collapse several known-size mallocs into # one, both for performance and to reduce the number of write # barriers. We do this on each "basic block" of operations, which in # this case means between CALLs or unknown-size mallocs. # self.gcrefs_output_list = gcrefs_output_list self.gcrefs_map = None self.gcrefs_recently_loaded = None operations = self.remove_bridge_exception(operations) self._changed_op = None for i in range(len(operations)): op = operations[i] if op.get_forwarded(): msg = '[rewrite] operations at %d has forwarded info %s\n' % (i, op.repr({})) if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg) if op.getopnum() == rop.DEBUG_MERGE_POINT: continue if op is self._changed_op: op = self._changed_op_to # ---------- GC_LOAD/STORE transformations -------------- if self.transform_to_gc_load(op): continue # ---------- turn NEWxxx into CALL_MALLOC_xxx ---------- if rop.is_malloc(op.opnum): self.handle_malloc_operation(op) continue if (rop.is_guard(op.opnum) or self.could_merge_with_next_guard(op, i, operations)): self.emit_pending_zeros() elif rop.can_malloc(op.opnum): self.emitting_an_operation_that_can_collect() elif op.getopnum() == rop.LABEL: self.emit_label() # ---------- write barriers ---------- if self.gc_ll_descr.write_barrier_descr is not None: if op.getopnum() == rop.SETFIELD_GC: self.consider_setfield_gc(op) self.handle_write_barrier_setfield(op) continue if op.getopnum() == rop.SETINTERIORFIELD_GC: self.handle_write_barrier_setinteriorfield(op) continue if op.getopnum() == rop.SETARRAYITEM_GC: self.consider_setarrayitem_gc(op) self.handle_write_barrier_setarrayitem(op) continue else: # this is dead code, but in case we have a gc that does # not have a write barrier and does not zero memory, we would # need to clal it if op.getopnum() == rop.SETFIELD_GC: self.consider_setfield_gc(op) elif op.getopnum() == rop.SETARRAYITEM_GC: self.consider_setarrayitem_gc(op) # ---------- call assembler ----------- if OpHelpers.is_call_assembler(op.getopnum()): self.handle_call_assembler(op) continue if op.getopnum() == rop.JUMP or op.getopnum() == rop.FINISH: self.emit_pending_zeros() # self.emit_op(op) return self._newops
def get_L2cache_linux2_ia64(): debug_start("gc-hardware") cpu = 0 L2cache = sys.maxint L3cache = sys.maxint while True: cpudir = '/sys/devices/system/cpu/cpu' + assert_str0(str(cpu)) index = 0 while True: cachedir = cpudir + '/cache/index' + assert_str0(str(index)) try: fd = os.open(cachedir + '/level', os.O_RDONLY, 0644) try: level = int(os.read(fd, 4096)[:-1]) finally: os.close(fd) except OSError: break if level not in (2, 3): index += 1 continue try: fd = os.open(cachedir + '/size', os.O_RDONLY, 0644) try: data = os.read(fd, 4096) finally: os.close(fd) except OSError: break end = 0 while '0' <= data[end] <= '9': end += 1 if end == 0: index += 1 continue if data[end] not in ('K', 'k'): # assume kilobytes for now index += 1 continue number = int(data[:end]) number *= 1024 if level == 2: if number < L2cache: L2cache = number if level == 3: if number < L3cache: L3cache = number index += 1 if index == 0: break cpu += 1 mangled = L2cache + L3cache debug_print("L2cache =", mangled) debug_stop("gc-hardware") if mangled > 0: return mangled else: # Print a top-level warning even in non-debug builds llop.debug_print( lltype.Void, "Warning: cannot find your CPU L2 & L3 cache size in " "/sys/devices/system/cpu/cpuX/cache") return -1
def set_forwarded(self, forwarded_to): llop.debug_print(lltype.Void, "setting forwarded on:", self.__class__.__name__) raise SettingForwardedOnAbstractValue()
def get_L2cache_linux2_ia64(): debug_start("gc-hardware") cpu = 0 L2cache = sys.maxint L3cache = sys.maxint while True: cpudir = '/sys/devices/system/cpu/cpu' + assert_str0(str(cpu)) index = 0 while True: cachedir = cpudir + '/cache/index' + assert_str0(str(index)) try: fd = os.open(cachedir + '/level', os.O_RDONLY, 0644) try: level = int(os.read(fd, 4096)[:-1]) finally: os.close(fd) except OSError: break if level not in (2, 3): index += 1 continue try: fd = os.open(cachedir + '/size', os.O_RDONLY, 0644) try: data = os.read(fd, 4096) finally: os.close(fd) except OSError: break end = 0 while '0' <= data[end] <= '9': end += 1 if end == 0: index += 1 continue if data[end] not in ('K', 'k'): # assume kilobytes for now index += 1 continue number = int(data[:end]) number *= 1024 if level == 2: if number < L2cache: L2cache = number if level == 3: if number < L3cache: L3cache = number index += 1 if index == 0: break cpu += 1 mangled = L2cache + L3cache debug_print("L2cache =", mangled) debug_stop("gc-hardware") if mangled > 0: return mangled else: # Print a top-level warning even in non-debug builds llop.debug_print(lltype.Void, "Warning: cannot find your CPU L2 & L3 cache size in " "/sys/devices/system/cpu/cpuX/cache") return -1
def notimplemented_comp_op(self, op, res_in_cc): llop.debug_print(lltype.Void, "[ARM64/regalloc] %s not implemented" % op.getopname()) raise NotImplementedError(op)
def not_implemented(msg): msg = '[ppc/vector_ext] %s\n' % msg if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg)
def rewrite(self, operations, gcrefs_output_list): # we can only remember one malloc since the next malloc can possibly # collect; but we can try to collapse several known-size mallocs into # one, both for performance and to reduce the number of write # barriers. We do this on each "basic block" of operations, which in # this case means between CALLs or unknown-size mallocs. # self.gcrefs_output_list = gcrefs_output_list self.gcrefs_map = None self.gcrefs_recently_loaded = None operations = self.remove_bridge_exception(operations) self._changed_op = None for i in range(len(operations)): op = operations[i] if op.get_forwarded(): msg = '[rewrite] operations at %d has forwarded info %s\n' % ( i, op.repr({})) if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg) if op.getopnum() == rop.DEBUG_MERGE_POINT: continue if op is self._changed_op: op = self._changed_op_to # ---------- GC_LOAD/STORE transformations -------------- if self.transform_to_gc_load(op): continue # ---------- turn NEWxxx into CALL_MALLOC_xxx ---------- if rop.is_malloc(op.opnum): self.handle_malloc_operation(op) continue if (rop.is_guard(op.opnum) or self.could_merge_with_next_guard(op, i, operations)): self.emit_pending_zeros() elif rop.can_malloc(op.opnum): self.emitting_an_operation_that_can_collect() elif op.getopnum() == rop.LABEL: self.emit_label() # ---------- write barriers ---------- if self.gc_ll_descr.write_barrier_descr is not None: if op.getopnum() == rop.SETFIELD_GC: self.consider_setfield_gc(op) self.handle_write_barrier_setfield(op) continue if op.getopnum() == rop.SETINTERIORFIELD_GC: self.handle_write_barrier_setinteriorfield(op) continue if op.getopnum() == rop.SETARRAYITEM_GC: self.consider_setarrayitem_gc(op) self.handle_write_barrier_setarrayitem(op) continue else: # this is dead code, but in case we have a gc that does # not have a write barrier and does not zero memory, we would # need to call it if op.getopnum() == rop.SETFIELD_GC: self.consider_setfield_gc(op) elif op.getopnum() == rop.SETARRAYITEM_GC: self.consider_setarrayitem_gc(op) # ---------- call assembler ----------- if OpHelpers.is_call_assembler(op.getopnum()): self.handle_call_assembler(op) continue if op.getopnum() == rop.JUMP or op.getopnum() == rop.FINISH: self.emit_pending_zeros() # self.emit_op(op) return self._newops
def notimplemented_guard_op(self, op, prevop): llop.debug_print(lltype.Void, "[ARM64/regalloc] %s not implemented" % op.getopname()) raise NotImplementedError(op)
def debug_assert(boolresult, msg): if not boolresult: llop.debug_print(lltype.Void, "\n\nassert failed: %s\n\n" % msg) assert boolresult
def fn(): llop.debug_print(lltype.Void, "hello world")
def notimplemented(self, op): msg = '[PPC/regalloc] %s not implemented\n' % op.getopname() if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg)
def not_implemented(msg): msg = "[llsupport/regalloc] %s\n" % msg if we_are_translated(): llop.debug_print(lltype.Void, msg) raise NotImplementedError(msg)