[pypy-commit] pypy gc-minimark-pinning: test and more boilerplate
fijal
noreply at buildbot.pypy.org
Thu Apr 12 15:37:00 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: gc-minimark-pinning
Changeset: r54310:afd55b84ac33
Date: 2012-04-12 14:32 +0200
http://bitbucket.org/pypy/pypy/changeset/afd55b84ac33/
Log: test and more boilerplate
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -503,7 +503,9 @@
def specialize_call(self, hop):
hop.exception_cannot_occur()
v_obj, = hop.inputargs(hop.args_r[0])
- hop.genop('gc_pin', [v_obj])
+ v_addr = hop.genop('cast_ptr_to_adr', [v_obj],
+ resulttype=llmemory.Address)
+ hop.genop('gc_pin', [v_addr])
class UnpinEntry(ExtRegistryEntry):
_about_ = unpin
@@ -514,4 +516,6 @@
def specialize_call(self, hop):
hop.exception_cannot_occur()
v_obj, = hop.inputargs(hop.args_r[0])
- hop.genop('gc_unpin', [v_obj])
+ v_addr = hop.genop('cast_ptr_to_adr', [v_obj],
+ resulttype=llmemory.Address)
+ hop.genop('gc_unpin', [v_addr])
diff --git a/pypy/rpython/memory/gc/base.py b/pypy/rpython/memory/gc/base.py
--- a/pypy/rpython/memory/gc/base.py
+++ b/pypy/rpython/memory/gc/base.py
@@ -18,9 +18,11 @@
needs_write_barrier = False
malloc_zero_filled = False
prebuilt_gc_objects_are_static_roots = True
+ can_always_pin_objects = False
object_minimal_size = 0
gcflag_extra = 0 # or a real GC flag that is always 0 when not collecting
+
def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
translated_to_c=True):
self.gcheaderbuilder = GCHeaderBuilder(self.HDR)
@@ -176,6 +178,12 @@
def can_move(self, addr):
return False
+ def pin(self, addr):
+ pass
+
+ def unpin(self, addr):
+ pass
+
def set_max_heap_size(self, size):
raise NotImplementedError
diff --git a/pypy/rpython/memory/gc/minimark.py b/pypy/rpython/memory/gc/minimark.py
--- a/pypy/rpython/memory/gc/minimark.py
+++ b/pypy/rpython/memory/gc/minimark.py
@@ -130,6 +130,7 @@
needs_write_barrier = True
prebuilt_gc_objects_are_static_roots = False
malloc_zero_filled = True # xxx experiment with False
+ can_always_pin_objects = True
gcflag_extra = GCFLAG_FINALIZATION_ORDERING
# All objects start with a HDR, i.e. with a field 'tid' which contains
diff --git a/pypy/rpython/memory/gcwrapper.py b/pypy/rpython/memory/gcwrapper.py
--- a/pypy/rpython/memory/gcwrapper.py
+++ b/pypy/rpython/memory/gcwrapper.py
@@ -123,6 +123,12 @@
def can_move(self, addr):
return self.gc.can_move(addr)
+ def pin(self, addr):
+ self.gc.pin(addr)
+
+ def unpin(self, addr):
+ self.gc.unpin(addr)
+
def weakref_create_getlazy(self, objgetter):
# we have to be lazy in reading the llinterp variable containing
# the 'obj' pointer, because the gc.malloc() call below could
diff --git a/pypy/rpython/memory/test/test_gc.py b/pypy/rpython/memory/test/test_gc.py
--- a/pypy/rpython/memory/test/test_gc.py
+++ b/pypy/rpython/memory/test/test_gc.py
@@ -746,6 +746,25 @@
res = self.interpret(fn, [])
assert res == ord('y')
+ def test_pinning(self):
+ def f(i):
+ s = str(i)
+ if not rgc.can_move(s):
+ return 13
+ sum = 0
+ with rgc.pinned_object(s):
+ sum += int(rgc.can_move(s))
+ sum += 10 * int(rgc.can_move(s))
+ return sum
+
+ res = self.interpret(f, [10])
+ if not self.GCClass.moving_gc:
+ assert res == 13
+ elif self.GCClass.can_always_pin_objects:
+ assert res == 10
+ else:
+ assert res == 11
+
from pypy.rlib.objectmodel import UnboxedValue
class TaggedBase(object):
More information about the pypy-commit
mailing list