Author: Armin Rigo <ar...@tunes.org> Branch: stm-gc Changeset: r54428:8f3f4e2f10be Date: 2012-04-16 16:43 +0200 http://bitbucket.org/pypy/pypy/changeset/8f3f4e2f10be/
Log: Start to rewrite test_stmgc.py. diff --git a/pypy/rpython/memory/gc/stmgc.py b/pypy/rpython/memory/gc/stmgc.py --- a/pypy/rpython/memory/gc/stmgc.py +++ b/pypy/rpython/memory/gc/stmgc.py @@ -190,47 +190,6 @@ return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF) - def _malloc_local_raw(self, tls, size): - # for _stm_write_barrier_global(): a version of malloc that does - # no initialization of the malloc'ed object - xxxxxxxx - size_gc_header = self.gcheaderbuilder.size_gc_header - totalsize = size_gc_header + size - result = self._allocate_bump_pointer(tls, totalsize) - llarena.arena_reserve(result, totalsize) - obj = result + size_gc_header - return obj - - - def _malloc_global_raw(self, tls, size): - # For collection: allocates enough space for a global object from - # the main_tls. The argument 'tls' is the current (local) GCTLS. - # We try to do it by reserving "pages" of memory from the global - # area at once, and subdividing here. - size_gc_header = self.gcheaderbuilder.size_gc_header - totalsize = size_gc_header + size - freespace = tls.global_stop - tls.global_free - if freespace < llmemory.raw_malloc_usage(totalsize): - self._malloc_global_more(tls, llmemory.raw_malloc_usage(totalsize)) - result = tls.global_free - tls.global_free = result + totalsize - llarena.arena_reserve(result, totalsize) - obj = result + size_gc_header - return obj - - @dont_inline - def _malloc_global_more(self, tls, totalsize): - xxxxxxxxxxxxxxxxx - if totalsize < self.tls_page_size: - totalsize = self.tls_page_size - main_tls = self.main_thread_tls - self.acquire(self.mutex_lock) - result = self._allocate_bump_pointer(main_tls, totalsize) - self.release(self.mutex_lock) - tls.global_free = result - tls.global_stop = result + totalsize - - def collect(self, gen=1): self.get_tls().local_collection() if gen > 0: @@ -392,14 +351,6 @@ self.stm_normalize_global = stm_normalize_global # ---------- - - def acquire(self, lock): - ll_thread.acquire_NOAUTO(lock, True) - - def release(self, lock): - ll_thread.release_NOAUTO(lock) - - # ---------- # id() and identityhash() support def id_or_identityhash(self, gcobj, is_hash): diff --git a/pypy/rpython/memory/gc/stmtls.py b/pypy/rpython/memory/gc/stmtls.py --- a/pypy/rpython/memory/gc/stmtls.py +++ b/pypy/rpython/memory/gc/stmtls.py @@ -138,9 +138,9 @@ """Stop a transaction: do a local collection to empty the nursery and track which objects are still alive now, and then mark all these objects as global.""" - self.local_collection() + self.local_collection(end_of_transaction=1) if not self.local_nursery_is_empty(): - self.local_collection(run_finalizers=False) + self.local_collection(end_of_transaction=2) self._promote_locals_to_globals() self._disable_mallocs() @@ -154,7 +154,7 @@ # ------------------------------------------------------------ - def local_collection(self, run_finalizers=True): + def local_collection(self, end_of_transaction=0): """Do a local collection. This should be equivalent to a minor collection only, but the GC is not generational so far, so it is for now the same as a full collection --- but only on LOCAL diff --git a/pypy/rpython/memory/gc/test/test_stmgc.py b/pypy/rpython/memory/gc/test/test_stmgc.py --- a/pypy/rpython/memory/gc/test/test_stmgc.py +++ b/pypy/rpython/memory/gc/test/test_stmgc.py @@ -132,6 +132,10 @@ def fake_weakpointer_offset(tid): return llmemory.offsetof(WR, 'wadr') +class FakeRootWalker: + def walk_current_stack_roots(self, *args): + pass # no stack roots in this test file + class StmGCTests: GCClass = StmGC @@ -146,6 +150,7 @@ self.gc.get_size = fake_get_size self.gc.trace = fake_trace self.gc.weakpointer_offset = fake_weakpointer_offset + self.gc.root_walker = FakeRootWalker() self.gc.setup() def teardown_method(self, meth): @@ -159,18 +164,22 @@ # ---------- # test helpers - def malloc(self, STRUCT, weakref=False): + def malloc(self, STRUCT, weakref=False, globl='auto'): size = llarena.round_up_for_allocation(llmemory.sizeof(STRUCT)) tid = lltype.cast_primitive(llgroup.HALFWORD, 123) gcref = self.gc.malloc_fixedsize_clear(tid, size, contains_weakptr=weakref) realobj = lltype.cast_opaque_ptr(lltype.Ptr(STRUCT), gcref) addr = llmemory.cast_ptr_to_adr(realobj) + if globl == 'auto': + globl = (self.gc.stm_operations.threadnum == 0) + if globl: + self.gc.header(addr).tid |= GCFLAG_GLOBAL return realobj, addr def select_thread(self, threadnum): self.gc.stm_operations.threadnum = threadnum if threadnum not in self.gc.stm_operations._tls_dict: - self.gc.setup_thread(False) + self.gc.setup_thread() self.gc.start_transaction() def gcsize(self, S): return (llmemory.raw_malloc_usage(llmemory.sizeof(self.gc.HDR)) + @@ -313,15 +322,20 @@ assert u_adr == t_adr def test_write_barrier_main_thread(self): - t, t_adr = self.malloc(S) - obj = self.gc.stm_writebarrier(t_adr) # main thread + t, t_adr = self.malloc(S, globl=False) + obj = self.gc.stm_writebarrier(t_adr) # main thread, but not global assert obj == t_adr + def test_write_barrier_global(self): + t, t_adr = self.malloc(S, globl=True) + obj = self.gc.stm_writebarrier(t_adr) # global, even if main thread + assert obj != t_adr + def test_commit_transaction_empty(self): self.select_thread(1) s, s_adr = self.malloc(S) t, t_adr = self.malloc(S) - self.gc.collector.commit_transaction() # no roots + self.gc.commit_transaction() # no roots main_tls = self.gc.main_thread_tls assert main_tls.nursery_free == main_tls.nursery_start # empty @@ -339,15 +353,14 @@ assert main_tls.nursery_free != main_tls.nursery_start # contains s old_value = main_tls.nursery_free # - self.gc.collector.commit_transaction() + self.gc.commit_transaction() # assert main_tls.nursery_free == old_value # no new object assert s.b == 12345 # not updated by the GC code assert t.b == 67890 # still valid - def _commit_transaction_with_one_reference(self, tls_page_size): - self.gc.tls_page_size = tls_page_size - # + def test_commit_transaction_with_one_reference(self): + py.test.skip("rewrite me") sr, sr_adr = self.malloc(SR) assert sr.s1 == lltype.nullptr(S) assert sr.sr2 == lltype.nullptr(SR) @@ -361,27 +374,18 @@ assert tr.sr2 == lltype.nullptr(SR) tr.s1 = t # - main_tls = self.gc.main_thread_tls - old_value = main_tls.nursery_free + tls = self.gc.get_tls() + old_value = tls.nursery_free # - self.gc.collector.commit_transaction() + tls.stop_transaction() # - consumed = main_tls.nursery_free - old_value + consumed = tls.nursery_free - old_value expected = self.gcsize(S) # round this value up to tls_page_size if expected < tls_page_size: expected = tls_page_size assert consumed == expected - def test_commit_transaction_with_one_reference_1(self): - self._commit_transaction_with_one_reference(1) - - def test_commit_transaction_with_one_reference_N1(self): - N1 = self.gcsize(S)-1 - self._commit_transaction_with_one_reference(N1) - - def test_commit_transaction_with_one_reference_128(self): - self._commit_transaction_with_one_reference(128) - def test_commit_transaction_with_graph(self): + py.test.skip("rewrite me") self.gc.tls_page_size = 1 sr1, sr1_adr = self.malloc(SR) sr2, sr2_adr = self.malloc(SR) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit