def f(): for i in range(10): s = lltype.malloc(S) l1.append(s) l2.append(s) if i < 3: l3.append(s) l4.append(s) # We cheat here and only read the table which we later on # process ourselves, otherwise this test takes ages llop.gc__collect(lltype.Void) tb = rgc._heap_stats() a = 0 nr = 0 b = 0 c = 0 d = 0 e = 0 for i in range(len(tb)): if tb[i].count == 10: a += 1 nr = i if tb[i].count > 50: d += 1 for i in range(len(tb)): if tb[i].count == 4: b += 1 c += tb[i].links[nr] e += tb[i].size return d * 1000 + c * 100 + b * 10 + a
def f(): o = gethidden(10) llop.gc__collect(lltype.Void) for i in range(1000): # overwrite freed memory overwrite(lltype.malloc(A), i) a = reveal(o) return a.value
def f(): p = lltype.malloc(A, flavor='raw') p.value = 123 llop.gc__collect(lltype.Void) res = p.value lltype.free(p, flavor='raw') return res
def concat(j, dummy): lst = [] for i in range(j): lst.append(str(i)) result = len("".join(lst)) if we_are_translated(): llop.gc__collect(lltype.Void, 0) return result
def f(x, y): a = A() i = 0 while i < x: i += 1 a = A() llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) return b.num_deleted
def concat(j): lst = [] for i in range(j): lst.append(str(i)) result = len("".join(lst)) if we_are_translated(): # can't call llop.gc__collect directly llop.gc__collect(lltype.Void) return result
def h(): f = Weakrefable() f.x = 32 ref1 = get_weakref(f, g1) ref2 = get_weakref(f, g2) if f.x % 2 == 0: # start a new block to make sure ref2 dies before f ref2 = None f.x = 12 llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) return ref1
def f(): a = A() ref = weakref.ref(a) result = ref() is a ref = g() llop.gc__collect(lltype.Void) result = result and (ref() is None) # check that a further collection is fine llop.gc__collect(lltype.Void) result = result and (ref() is None) return result
def f(): s.a_dels = 0 s.b_dels = 0 A() B() C() A() B() C() llop.gc__collect(lltype.Void) return s.a_dels * 10 + s.b_dels
def malloc_a_lot(): i = 0 while i < 10: i += 1 a = [1] * 10 j = 0 while j < 20: j += 1 a.append(j) from pypy.rpython.lltypesystem.lloperation import llop from pypy.rpython.lltypesystem import lltype llop.gc__collect(lltype.Void)
def func(): a2 = A() a3 = A() id1 = compute_unique_id(a1) id2 = compute_unique_id(a2) id3 = compute_unique_id(a3) llop.gc__collect(lltype.Void) error = 0 if id1 != compute_unique_id(a1): error += 1 if id2 != compute_unique_id(a2): error += 2 if id3 != compute_unique_id(a3): error += 4 return error
def f(x): a = A() a.foo = x ref = weakref.ref(a) all = [None] * x i = 0 while i < x: all[i] = [i] * i i += 1 assert ref() is a llop.gc__collect(lltype.Void) assert ref() is a return a.foo + len(all)
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 return b.num_deleted
def f(): t1 = B() t1.x = 42 static.p = t1 x = 20 all = [None] * x i = 0 while i < x: # enough to cause a minor collect all[i] = [i] * i i += 1 i = static.p.x llop.gc__collect(lltype.Void) return static.p.x + i
def f(): x = 20 # for GenerationGC, enough for a minor collection a = A() a.foo = x ref = weakref.ref(a) all = [None] * x i = 0 while i < x: all[i] = [i] * i i += 1 assert ref() is a llop.gc__collect(lltype.Void) assert ref() is a return a.foo + len(all)
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 f(x): a = A() llop.gc__collect(lltype.Void) # 'a' is old, 'ref' is young ref = weakref.ref(a) # now trigger a minor collection all = [None] * x i = 0 while i < x: all[i] = [i] * i i += 1 # now 'a' is old, but 'ref' did not move assert ref() is a llop.gc__collect(lltype.Void) # now both 'a' and 'ref' have moved return ref() is a
def f(): main_ident = get_ident() assert main_ident == get_ident() state.freed_counter = 0 for i in range(50): state.done = 0 state.seen_value = 0 g(i) willing_to_wait_more = 1000 while not state.done: willing_to_wait_more -= 1 if not willing_to_wait_more: raise Exception("thread didn't start?") time.sleep(0.01) assert state.my_thread_ident != main_ident assert state.seen_value == i # try to force Boehm to do some freeing for i in range(3): llop.gc__collect(lltype.Void) return state.freed_counter
def f(_): i = 0 while i < len(examples): input, components, strict = examples[i] build_example(input) while state.time < len(letters): state.progress = False llop.gc__collect(lltype.Void) if not state.progress: break state.time += 1 # summarize the finalization order lst = [] for c in letters: lst.append('%s:%d' % (c, state.age[c])) summary = ', '.join(lst) # check that all instances have been finalized if -1 in state.age.values(): return error(i, summary, "not all instances finalized") # check that if a -> b and a and b are not in the same # strong component, then a is finalized strictly before b for c, d in strict: if state.age[c] >= state.age[d]: return error(i, summary, "%s should be finalized before %s" % (c, d)) # check that two instances in the same strong component # are never finalized during the same collection for component in components: seen = {} for c in component: age = state.age[c] if age in seen: d = seen[age] return error(i, summary, "%s and %s should not be finalized" " at the same time" % (c, d)) seen[age] = c i += 1 return "ok"
def f(x, y): a = A() i = 0 while i < x: i += 1 a = A() llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) aid = b.a.id b.a = None # check that __del__ is not called again llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) return b.num_deleted * 10 + aid + 100 * (b.a is None)
def f(i): if i: s.a_dels = 0 a = A() # this should not keep a alive s.a = cast_object_to_weakgcaddress(a) a = None llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) return s.a_dels
def run_once(): a = A() ida = compute_unique_id(a) b = B() idb = compute_unique_id(b) c = C() idc = compute_unique_id(c) llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) return ida, idb, idc
def f(): t1 = lltype.malloc(T1) t1.x = 42 static.p = t1 llop.gc__collect(lltype.Void) return static.p.x
def f(): make() llop.gc__collect(lltype.Void) return global_a.b.a.b.c
def g(a): llop.gc__collect(lltype.Void) for i in range(1000): prepare(B(), -1) # probably overwrites collected memory return a.value
def __del__(self): llop.gc__collect(lltype.Void) b.num_deleted += 1 C() C()
def f(): ref = g() llop.gc__collect(lltype.Void) llop.gc__collect(lltype.Void) result = a.count == 1 and (ref() is None) return result
def f(): make() llop.gc__collect(lltype.Void) return a.x.y
def f(i): a = A() f1(i) a.b = 1 llop.gc__collect(lltype.Void) return a.b
def append_to_list(i, j): box.lst.append([i] * 50) llop.gc__collect(lltype.Void) return box.lst[j][0]
def f(n): s1 = setup() llop.gc__collect(lltype.Void) return measure_length(s1)
def f(): p = lltype.malloc(B) llop.gc__collect(lltype.Void) p.a = lltype.malloc(A) return p.a.x