[pypy-commit] pypy gc-incminimark-pinning: added more test cases for gc object pinning.
groggi
noreply at buildbot.pypy.org
Mon Jun 2 17:23:48 CEST 2014
Author: Gregor Wegberg <code at gregorwegberg.com>
Branch: gc-incminimark-pinning
Changeset: r71811:ec36db23050d
Date: 2014-05-12 11:50 +0200
http://bitbucket.org/pypy/pypy/changeset/ec36db23050d/
Log: added more test cases for gc object pinning.
The main test case (test_simple_pin) still fails because of missing
implementation.
diff --git a/rpython/memory/gc/test/test_object_pinning.py b/rpython/memory/gc/test/test_object_pinning.py
--- a/rpython/memory/gc/test/test_object_pinning.py
+++ b/rpython/memory/gc/test/test_object_pinning.py
@@ -1,5 +1,5 @@
import py
-from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.memory.gc.incminimark import IncrementalMiniMarkGC
from test_direct import BaseDirectGCTest
@@ -7,13 +7,52 @@
S.become(lltype.GcStruct('S', ('someInt', lltype.Signed)))
class PinningGCTest(BaseDirectGCTest):
- def test_simple(self):
- someIntValue = 100
- obj = self.malloc(S)
- obj.someInt = someIntValue
- self.gc.pin(obj)
- self.gc.collect() # obj should still live
- assert obj.someInt == someIntValue
+
+ def test_simple_pin(self):
+ ptr = self.malloc(S)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ ptr.someInt = 100
+ assert self.gc.pin(adr)
+ self.gc.collect() # ptr should still live
+ assert ptr.someInt == 100
+
+ def test_pin_can_move(self):
+ # even a pinned ptrect is considered to be movable. Only the code
+ # that called pin() knows if it is currently movable or not.
+ # Additionally it could be unpinned anytime.
+ ptr = self.malloc(S)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ assert self.gc.can_move(adr)
+ assert self.gc.pin(adr)
+ assert self.gc.can_move(adr)
+
+ def test_pin_twice(self):
+ ptr = self.malloc(S)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ assert self.gc.pin(adr)
+ assert not self.gc.pin(adr)
+
+ # XXX test with multiple mallocs, and only part of them is pinned
+
class TestIncminimark(PinningGCTest):
- from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
\ No newline at end of file
+ from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
+
+ def test_pin_old(self):
+ ptr = self.malloc(S)
+ ptr.someInt = 100
+ self.stackroots.append(ptr)
+ self.gc.collect()
+ ptr = self.stackroots[0]
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ assert ptr.someInt == 100
+ assert not self.gc.is_in_nursery(adr)
+ assert not self.gc.pin(adr)
+ # ^^^ should not be possible, struct is already old and won't
+ # move.
+
+ # XXX test/define what happens if we try to pin an object that is too
+ # big for the nursery and will be raw-malloc'ed.
+
+ # XXX test/define what happens if pinned object already has a shadow
+ # => shadow handling.
More information about the pypy-commit
mailing list