[pypy-svn] r77044 - in pypy/branch/gen2-gc/pypy/rpython/memory/gc: . test

arigo at codespeak.net arigo at codespeak.net
Mon Sep 13 17:29:55 CEST 2010


Author: arigo
Date: Mon Sep 13 17:29:54 2010
New Revision: 77044

Modified:
   pypy/branch/gen2-gc/pypy/rpython/memory/gc/gen2.py
   pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_gen2.py
Log:
More tests.


Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/gen2.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/gen2.py	(original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/gen2.py	Mon Sep 13 17:29:54 2010
@@ -114,6 +114,7 @@
     def __init__(self, arena_size, page_size, small_request_threshold):
         self.arena_size = arena_size
         self.page_size = page_size
+        self.small_request_threshold = small_request_threshold
         #
         # 'pageaddr_for_size': for each size N between WORD and
         # small_request_threshold (included), contains either NULL or
@@ -237,7 +238,7 @@
     assert isinstance(addr, llarena.fakearenaaddress)
     shift = 4     # for testing, we assume that the whole arena is not
                   # on a page boundary
-    ofs = ((addr.offset - shift) & ~(page_size-1)) + shift
+    ofs = ((addr.offset - shift) // page_size) * page_size + shift
     return llarena.fakearenaaddress(addr.arena, ofs)
 
 # ____________________________________________________________

Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_gen2.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_gen2.py	(original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_gen2.py	Mon Sep 13 17:29:54 2010
@@ -143,15 +143,71 @@
     assert ac.arenas_start.nfreepages == 3
     assert ac.arenas_end.nfreepages == 4
     #
-    a0 = getarena(ac, 0, 2)
-    a1 = getarena(ac, 1, 2)
+    a0 = getarena(ac, 0, total=2)
+    a1 = getarena(ac, 1, total=2)
     page = ac.allocate_new_page(1); checkpage(ac, page, a0, 2)
     page = ac.allocate_new_page(2); checkpage(ac, page, a0, 3)
-    assert getarena(ac, 0, 2) is a0
+    assert getarena(ac, 0, total=2) is a0
     page = ac.allocate_new_page(3); checkpage(ac, page, a0, 4)
-    assert getarena(ac, 0, 1) is a1
+    assert getarena(ac, 0, total=1) is a1
     page = ac.allocate_new_page(4); checkpage(ac, page, a1, 0)
     page = ac.allocate_new_page(5); checkpage(ac, page, a1, 2)
     page = ac.allocate_new_page(6); checkpage(ac, page, a1, 3)
     page = ac.allocate_new_page(7); checkpage(ac, page, a1, 4)
     assert ac.arenas_start is ac.arenas_end is None
+
+
+def checkobj(arena, num_page, pos_obj, obj):
+    pageaddr = arena.arena_base + SHIFT + num_page * arena.page_size
+    assert obj == pageaddr + hdrsize + pos_obj
+
+
+def test_malloc_common_case():
+    pagesize = hdrsize + 7*WORD
+    ac = arena_collection_for_test(pagesize, "#23..2 ")
+    a0 = getarena(ac, 0, total=1)
+    obj = ac.malloc(2*WORD); checkobj(a0, 5, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 1, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 3, 0*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 3, 2*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 3, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 0*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 2*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 6, 0*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 6, 2*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 6, 4*WORD, obj)
+
+def test_malloc_mixed_sizes():
+    pagesize = hdrsize + 7*WORD
+    ac = arena_collection_for_test(pagesize, "#23..2 ")
+    a0 = getarena(ac, 0, total=1)
+    obj = ac.malloc(2*WORD); checkobj(a0, 5, 4*WORD, obj)
+    obj = ac.malloc(3*WORD); checkobj(a0, 2, 3*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 1, 4*WORD, obj)
+    obj = ac.malloc(3*WORD); checkobj(a0, 3, 0*WORD, obj)  # 3rd page -> size 3
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 0*WORD, obj)  # 4th page -> size 2
+    obj = ac.malloc(3*WORD); checkobj(a0, 3, 3*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 2*WORD, obj)
+    obj = ac.malloc(3*WORD); checkobj(a0, 6, 0*WORD, obj)  # 6th page -> size 3
+    obj = ac.malloc(2*WORD); checkobj(a0, 4, 4*WORD, obj)
+    obj = ac.malloc(3*WORD); checkobj(a0, 6, 3*WORD, obj)
+
+def test_malloc_new_arena():
+    pagesize = hdrsize + 7*WORD
+    ac = arena_collection_for_test(pagesize, "#23..2 ")
+    a0 = getarena(ac, 0, total=1)
+    obj = ac.malloc(5*WORD); checkobj(a0, 3, 0*WORD, obj)  # 3rd page -> size 5
+    obj = ac.malloc(4*WORD); checkobj(a0, 4, 0*WORD, obj)  # 4th page -> size 4
+    obj = ac.malloc(1*WORD); checkobj(a0, 6, 0*WORD, obj)  # 6th page -> size 1
+    assert ac.arenas_start is ac.arenas_end is None  # no more free page
+    obj = ac.malloc(1*WORD); checkobj(a0, 6, 1*WORD, obj)
+    obj = ac.malloc(5*WORD)
+    a1 = getarena(ac, 0, total=1)
+    pass;                    checkobj(a1, 0, 0*WORD, obj)  # a1/0 -> size 5
+    obj = ac.malloc(1*WORD); checkobj(a0, 6, 2*WORD, obj)
+    obj = ac.malloc(5*WORD); checkobj(a1, 1, 0*WORD, obj)  # a1/1 -> size 5
+    obj = ac.malloc(1*WORD); checkobj(a0, 6, 3*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 5, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a0, 1, 4*WORD, obj)
+    obj = ac.malloc(2*WORD); checkobj(a1, 2, 0*WORD, obj)  # a1/2 -> size 2



More information about the Pypy-commit mailing list