예제 #1
0
파일: test_newgc.py 프로젝트: yuyichao/pypy
 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
예제 #2
0
 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
예제 #3
0
파일: test_newgc.py 프로젝트: yuyichao/pypy
 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
예제 #4
0
 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
예제 #5
0
 def f():
     ref = g()
     llop.gc__collect(lltype.Void, 1)
     b = ref()
     assert b is not None
     b.x = 101
     return ref() is b
예제 #6
0
 def f():
     ref = g()
     llop.gc__collect(lltype.Void, 1)
     b = ref()
     assert b is not None
     b.x = 101
     return ref() is b
예제 #7
0
 def g():
     a = A()
     a.x = 5
     wr = weakref.ref(a)
     llop.gc__collect(lltype.Void)  # make everything old
     assert wr() is not None
     assert a.x == 5
     return wr
예제 #8
0
 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
예제 #9
0
 def g():
     a = A()
     a.x = 5
     wr = weakref.ref(a)
     llop.gc__collect(lltype.Void)   # make everything old
     assert wr() is not None
     assert a.x == 5
     return wr
예제 #10
0
 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
예제 #11
0
 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
예제 #12
0
 def g():
     a = A()
     assert rgc.pin(a)
     a.x = 100
     wr = weakref.ref(a)
     llop.gc__collect(lltype.Void)
     assert wr() is not None
     assert a.x == 100
     return wr
예제 #13
0
 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
예제 #14
0
 def f(x):
     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
예제 #15
0
 def f(x):
     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
예제 #16
0
 def g():
     a = A()
     assert rgc.pin(a)
     a.x = 100
     wr = weakref.ref(a)
     llop.gc__collect(lltype.Void)
     assert wr() is not None
     assert a.x == 100
     return wr
예제 #17
0
 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
예제 #18
0
 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
예제 #19
0
 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
예제 #20
0
 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
예제 #21
0
 def f():
     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
예제 #22
0
 def f():
     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
예제 #23
0
 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
예제 #24
0
 def finalizer_trigger(self):
     while True:
         a = self.next_dead()
         if a is None:
             break
         llop.gc__collect(lltype.Void)
         b.num_deleted += 1
         if isinstance(a, C):
             b.num_deleted_c += 1
         else:
             C()
             C()
예제 #25
0
 def finalizer_trigger(self):
     while True:
         a = self.next_dead()
         if a is None:
             break
         llop.gc__collect(lltype.Void)
         b.num_deleted += 1
         if isinstance(a, C):
             b.num_deleted_c += 1
         else:
             C()
             C()
예제 #26
0
 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
예제 #27
0
 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
예제 #28
0
 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)
예제 #29
0
 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
예제 #30
0
 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)
예제 #31
0
 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)
예제 #32
0
 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
     print b.num_deleted_c
     return b.num_deleted
예제 #33
0
 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)
예제 #34
0
 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
     print b.num_deleted_c
     return b.num_deleted
예제 #35
0
 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
예제 #36
0
 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
예제 #37
0
 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
예제 #38
0
 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
예제 #39
0
 def f(x):
     A()
     i = 0
     while i < x:
         i += 1
         A()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     return b.num_deleted_1 + b.num_deleted_2 * 1000
예제 #40
0
 def f(x):
     A()
     i = 0
     while i < x:
         i += 1
         A()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     return b.num_deleted_1 + b.num_deleted_2 * 1000
예제 #41
0
파일: snippet.py 프로젝트: soIu/rpython
        def f(_):
            i = 0
            while i < len(examples):
                input, components, strict = examples[i]
                build_example(input)
                while state.time < len(letters):
                    from rpython.rlib.debug import debug_print
                    debug_print("STATE.TIME:", state.time)
                    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, age_of(c)))
                summary = ', '.join(lst)

                # check that all instances have been finalized
                if -1 in state.age:
                    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 age_of(c) >= age_of(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 = age_of(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"
예제 #42
0
파일: snippet.py 프로젝트: mozillazg/pypy
        def f(_):
            i = 0
            while i < len(examples):
                input, components, strict = examples[i]
                build_example(input)
                while state.time < len(letters):
                    from rpython.rlib.debug import debug_print
                    debug_print("STATE.TIME:", state.time)
                    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, age_of(c)))
                summary = ', '.join(lst)

                # check that all instances have been finalized
                if -1 in state.age:
                    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 age_of(c) >= age_of(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 = age_of(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"
예제 #43
0
 def f(x):
     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)
예제 #44
0
 def f(x):
     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)
예제 #45
0
 def f(x):
     b.triggered = 0
     g()
     i = 0
     while i < x:
         i += 1
         g()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     assert b.triggered > 0
     g(); g()     # two more
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     num_deleted = 0
     while fq.next_dead() is not None:
         num_deleted += 1
     return num_deleted + 1000 * b.triggered
예제 #46
0
 def f(x):
     b.triggered = 0
     g()
     i = 0
     while i < x:
         i += 1
         g()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     assert b.triggered > 0
     g()
     g()  # two more
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     num_deleted = 0
     while fq.next_dead() is not None:
         num_deleted += 1
     return num_deleted + 1000 * b.triggered
예제 #47
0
 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
예제 #48
0
 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
예제 #49
0
 def f():
     ref = g()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     result = a.count + (ref() is None)
     return result
예제 #50
0
 def __del__(self):
     llop.gc__collect(lltype.Void)
     b.num_deleted += 1
     C()
     C()
예제 #51
0
 def f(x):
     ref = weakref.ref(a)
     assert ref() is a
     llop.gc__collect(lltype.Void)
     return ref() is a
예제 #52
0
 def f():
     a = A()
     a.x = 10
     g(a)
     llop.gc__collect(lltype.Void)
     return a.x
예제 #53
0
 def f():
     ref = g()
     llop.gc__collect(lltype.Void)
     llop.gc__collect(lltype.Void)
     result = a.count + (ref() is None)
     return result
예제 #54
0
 def g():
     b = B()
     llop.gc__collect(lltype.Void)  # force 'b' to be old
     ref = weakref.ref(B())
     b.ref = ref
     return ref
예제 #55
0
 def __del__(self):
     llop.gc__collect(lltype.Void)
     b.num_deleted += 1
     C()
     C()
예제 #56
0
 def f():
     s1 = setup()
     llop.gc__collect(lltype.Void)
     return llmemory.cast_adr_to_ptr(getattr(s1, attrname),
                                     lltype.Ptr(T))
예제 #57
0
 def f(x):
     ref = weakref.ref(a)
     assert ref() is a
     llop.gc__collect(lltype.Void)
     return ref() is a
예제 #58
0
 def f():
     t1 = lltype.malloc(T1)
     t1.x = 42
     static.p = t1
     llop.gc__collect(lltype.Void)
     return static.p.x
예제 #59
0
 def f():
     t1 = lltype.malloc(T1)
     t1.x = 42
     static.p = t1
     llop.gc__collect(lltype.Void)
     return static.p.x
예제 #60
0
 def f():
     a = A()
     a.x = 10
     g(a)
     llop.gc__collect(lltype.Void)
     return a.x