Author: Armin Rigo <ar...@tunes.org> Branch: stm-gc-2 Changeset: r63150:a775bcc0f708 Date: 2013-04-08 19:32 +0200 http://bitbucket.org/pypy/pypy/changeset/a775bcc0f708/
Log: Add a test. Various fixes, of course. diff --git a/rpython/memory/gc/stmshared.py b/rpython/memory/gc/stmshared.py --- a/rpython/memory/gc/stmshared.py +++ b/rpython/memory/gc/stmshared.py @@ -1,7 +1,7 @@ from rpython.rtyper.lltypesystem import lltype, llmemory, llarena, rffi from rpython.rlib.rarithmetic import LONG_BIT -from rpython.rlib.objectmodel import free_non_gc_object -from rpython.rlib.debug import fatalerror +from rpython.rlib.objectmodel import free_non_gc_object, we_are_translated +from rpython.rlib.debug import ll_assert, fatalerror from rpython.rlib import rthread WORD = LONG_BIT // 8 @@ -109,6 +109,9 @@ self.full_page_for_size = lltype.malloc(rffi.CArray(PAGE_PTR), length, flavor='raw', zero=True, immortal=True) + # + if not we_are_translated(): + self._seen_pages = set() def _malloc_size_class(self, size_class): """Malloc one object of the given size_class (== number of WORDs).""" @@ -123,6 +126,7 @@ # # The result is simply 'page.freeblock' result = page.freeblock + nsize = size_class << WORD_POWER_2 if page.nfree > 0: # # The 'result' was part of the chained list; read the next. @@ -139,7 +143,7 @@ page.freeblock = freeblock # pageaddr = llarena.getfakearenaaddress(llmemory.cast_ptr_to_adr(page)) - if freeblock - pageaddr > self.page_size - nsize: + if freeblock - pageaddr > self.sharedarea.page_size - nsize: # This was the last free block, so unlink the page from the # chained list and put it in the 'full_page_for_size' list. self.page_for_size[size_class] = page.nextpage @@ -166,6 +170,8 @@ if not result: fatalerror("FIXME: Out of memory! (should raise MemoryError)") return PAGE_NULL + if not we_are_translated(): + self._seen_pages.add(result) llarena.arena_reserve(result, llmemory.sizeof(PAGE_HEADER)) # # Initialize the fields of the resulting page @@ -184,7 +190,8 @@ some other data structure. Note that it is not zero-filled.""" nsize = llmemory.raw_malloc_usage(totalsize) if nsize <= self.sharedarea.small_request_threshold: - result = self._malloc_size_class(nsize >> WORD_POWER_2) + size_class = (nsize + WORD_POWER_2 - 1) >> WORD_POWER_2 + result = self._malloc_size_class(size_class) llarena.arena_reserve(result, _dummy_size(totalsize)) return result else: diff --git a/rpython/memory/gc/test/test_stmshared.py b/rpython/memory/gc/test/test_stmshared.py new file mode 100644 --- /dev/null +++ b/rpython/memory/gc/test/test_stmshared.py @@ -0,0 +1,21 @@ +from rpython.memory.gc.stmshared import WORD +from rpython.memory.gc.stmshared import StmGCSharedArea +from rpython.memory.gc.stmshared import StmGCThreadLocalAllocator + + +def test_simple(): + shared = StmGCSharedArea("gc", 10*WORD, 2*WORD) + shared.setup() + thl1 = StmGCThreadLocalAllocator(shared) + thl1.malloc_object(2*WORD-1) + assert len(thl1._seen_pages) == 1 + thl1.malloc_object(2*WORD) + assert len(thl1._seen_pages) == 1 + thl1.malloc_object(1*WORD) + assert len(thl1._seen_pages) == 2 + thl1.malloc_object(2*WORD) + assert len(thl1._seen_pages) == 2 + thl1.malloc_object(2*WORD) + assert len(thl1._seen_pages) == 3 + thl1.malloc_object(2*WORD) + assert len(thl1._seen_pages) == 3 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit