[pypy-commit] pypy rgc-mem-pressure: Branch to add manual memory pressure. Useful for mallocing OpaquePtrs.
justinpeel
noreply at buildbot.pypy.org
Fri Oct 7 22:37:40 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: rgc-mem-pressure
Changeset: r47867:d78305bced3f
Date: 2011-10-07 14:37 -0600
http://bitbucket.org/pypy/pypy/changeset/d78305bced3f/
Log: Branch to add manual memory pressure. Useful for mallocing
OpaquePtrs.
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -255,6 +255,10 @@
except Exception:
return False # don't keep objects whose _freeze_() method explodes
+def add_memory_pressure(estimate):
+ """Add memory pressure for OpaquePtrs."""
+ pass
+
def get_rpy_memory_usage(gcref):
"NOT_RPYTHON"
# approximate implementation using CPython's type info
diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py
--- a/pypy/rpython/llinterp.py
+++ b/pypy/rpython/llinterp.py
@@ -172,7 +172,7 @@
def checkadr(addr):
assert lltype.typeOf(addr) is llmemory.Address
-
+
def is_inst(inst):
return isinstance(lltype.typeOf(inst), (ootype.Instance, ootype.BuiltinType, ootype.StaticMethod))
@@ -657,7 +657,7 @@
raise TypeError("graph with %r args called with wrong func ptr type: %r" %
(tuple([v.concretetype for v in args_v]), ARGS))
frame = self.newsubframe(graph, args)
- return frame.eval()
+ return frame.eval()
def op_direct_call(self, f, *args):
FTYPE = self.llinterpreter.typer.type_system.derefType(lltype.typeOf(f))
@@ -698,13 +698,13 @@
return ptr
except MemoryError:
self.make_llexception()
-
+
def op_malloc_nonmovable(self, TYPE, flags):
flavor = flags['flavor']
assert flavor == 'gc'
zero = flags.get('zero', False)
return self.heap.malloc_nonmovable(TYPE, zero=zero)
-
+
def op_malloc_nonmovable_varsize(self, TYPE, flags, size):
flavor = flags['flavor']
assert flavor == 'gc'
@@ -716,6 +716,9 @@
track_allocation = flags.get('track_allocation', True)
self.heap.free(obj, flavor='raw', track_allocation=track_allocation)
+ def add_memory_pressure(self, size):
+ self.heap.add_memory_pressure(size)
+
def op_shrink_array(self, obj, smallersize):
return self.heap.shrink_array(obj, smallersize)
@@ -1325,7 +1328,7 @@
func_graph = fn.graph
else:
# obj is an instance, we want to call 'method_name' on it
- assert fn is None
+ assert fn is None
self_arg = [obj]
func_graph = obj._TYPE._methods[method_name._str].graph
diff --git a/pypy/rpython/lltypesystem/llheap.py b/pypy/rpython/lltypesystem/llheap.py
--- a/pypy/rpython/lltypesystem/llheap.py
+++ b/pypy/rpython/lltypesystem/llheap.py
@@ -5,8 +5,7 @@
setfield = setattr
from operator import setitem as setarrayitem
-from pypy.rlib.rgc import collect
-from pypy.rlib.rgc import can_move
+from pypy.rlib.rgc import can_move, collect, add_memory_pressure
def setinterior(toplevelcontainer, inneraddr, INNERTYPE, newvalue,
offsets=None):
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -519,6 +519,7 @@
'decode_arg_def': LLOp(canraise=(Exception,)),
'getslice': LLOp(canraise=(Exception,)),
'check_and_clear_exc': LLOp(),
+ 'add_memory_pressure': LLOp(),
# __________ debugging __________
'debug_view': LLOp(),
diff --git a/pypy/rpython/memory/gctransform/framework.py b/pypy/rpython/memory/gctransform/framework.py
--- a/pypy/rpython/memory/gctransform/framework.py
+++ b/pypy/rpython/memory/gctransform/framework.py
@@ -385,6 +385,14 @@
[annmodel.SomeInteger(), annmodel.SomeInteger()],
annmodel.s_None, minimal_transform = False)
+ if getattr(GCClass, 'add_memory_pressure', False):
+ def add_memory_pressure(size):
+ gcdata.gc.raw_malloc_memory_pressure(size)
+ self.add_memory_pressure_ptr = getfun(
+ add_memory_pressure,
+ [annmodel.SomeInteger()],
+ annmodel.s_None, minimal_transform = False)
+
self.identityhash_ptr = getfn(GCClass.identityhash.im_func,
[s_gc, s_gcref],
annmodel.SomeInteger(),
diff --git a/pypy/rpython/memory/gctransform/transform.py b/pypy/rpython/memory/gctransform/transform.py
--- a/pypy/rpython/memory/gctransform/transform.py
+++ b/pypy/rpython/memory/gctransform/transform.py
@@ -63,7 +63,7 @@
gct.push_alive(v_result, self.llops)
elif opname not in ('direct_call', 'indirect_call'):
gct.push_alive(v_result, self.llops)
-
+
def rename(self, newopname):
@@ -118,7 +118,7 @@
self.minimalgctransformer = self.MinimalGCTransformer(self)
else:
self.minimalgctransformer = None
-
+
def get_lltype_of_exception_value(self):
if self.translator is not None:
exceptiondata = self.translator.rtyper.getexceptiondata()
@@ -399,7 +399,7 @@
def gct_gc_heap_stats(self, hop):
from pypy.rpython.memory.gc.base import ARRAY_TYPEID_MAP
-
+
return hop.cast_result(rmodel.inputconst(lltype.Ptr(ARRAY_TYPEID_MAP),
lltype.nullptr(ARRAY_TYPEID_MAP)))
@@ -427,7 +427,7 @@
assert flavor == 'raw'
assert not flags.get('zero')
return self.parenttransformer.gct_malloc_varsize(hop)
-
+
def gct_free(self, hop):
flags = hop.spaceop.args[1].value
flavor = flags['flavor']
@@ -502,7 +502,7 @@
stack_mh = mallocHelpers()
stack_mh.allocate = lambda size: llop.stack_malloc(llmemory.Address, size)
ll_stack_malloc_fixedsize = stack_mh._ll_malloc_fixedsize
-
+
if self.translator:
self.raw_malloc_fixedsize_ptr = self.inittime_helper(
ll_raw_malloc_fixedsize, [lltype.Signed], llmemory.Address)
@@ -541,7 +541,7 @@
resulttype=llmemory.Address)
if flags.get('zero'):
hop.genop("raw_memclear", [v_raw, c_size])
- return v_raw
+ return v_raw
def gct_malloc_varsize(self, hop, add_flags=None):
flags = hop.spaceop.args[1].value
@@ -559,6 +559,14 @@
def gct_malloc_nonmovable_varsize(self, *args, **kwds):
return self.gct_malloc_varsize(*args, **kwds)
+ def gct_add_memory_pressure(self, hop):
+ if hasattr(self, 'add_memory_pressure_ptr'):
+ op = hop.spaceop
+ size = hop.args[0]
+ hop.genop("direct_call",
+ [self.raw_malloc_memory_pressure_ptr,
+ size])
+
def varsize_malloc_helper(self, hop, flags, meth, extraargs):
def intconst(c): return rmodel.inputconst(lltype.Signed, c)
op = hop.spaceop
@@ -625,7 +633,7 @@
hop.genop("track_alloc_stop", [v])
hop.genop('raw_free', [v])
else:
- assert False, "%s has no support for free with flavor %r" % (self, flavor)
+ assert False, "%s has no support for free with flavor %r" % (self, flavor)
def gct_gc_can_move(self, hop):
return hop.cast_result(rmodel.inputconst(lltype.Bool, False))
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
@@ -65,6 +65,9 @@
gctypelayout.zero_gc_pointers(result)
return result
+ def add_memory_pressure(self, size):
+ self.gc.add_memory_pressure(self)
+
def shrink_array(self, p, smallersize):
if hasattr(self.gc, 'shrink_array'):
addr = llmemory.cast_ptr_to_adr(p)
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
@@ -593,7 +593,7 @@
return rgc.can_move(lltype.malloc(TP, 1))
assert self.interpret(func, []) == self.GC_CAN_MOVE
-
+
def test_malloc_nonmovable(self):
TP = lltype.GcArray(lltype.Char)
def func():
diff --git a/pypy/rpython/memory/test/test_transformed_gc.py b/pypy/rpython/memory/test/test_transformed_gc.py
--- a/pypy/rpython/memory/test/test_transformed_gc.py
+++ b/pypy/rpython/memory/test/test_transformed_gc.py
@@ -27,7 +27,7 @@
t.config.set(**extraconfigopts)
ann = t.buildannotator(policy=annpolicy.StrictAnnotatorPolicy())
ann.build_types(func, inputtypes)
-
+
if specialize:
t.buildrtyper().specialize()
if backendopt:
@@ -44,7 +44,7 @@
GC_CAN_MOVE = False
GC_CAN_MALLOC_NONMOVABLE = True
taggedpointers = False
-
+
def setup_class(cls):
funcs0 = []
funcs2 = []
@@ -155,7 +155,7 @@
return run, gct
else:
return run
-
+
class GenericGCTests(GCTest):
GC_CAN_SHRINK_ARRAY = False
@@ -190,7 +190,7 @@
j += 1
return 0
return malloc_a_lot
-
+
def test_instances(self):
run, statistics = self.runner("instances", statistics=True)
run([])
@@ -276,7 +276,7 @@
for i in range(1, 5):
res = run([i, i - 1])
assert res == i - 1 # crashes if constants are not considered roots
-
+
def define_string_concatenation(cls):
def concat(j, dummy):
lst = []
@@ -656,7 +656,7 @@
# return 2
return func
-
+
def test_malloc_nonmovable(self):
run = self.runner("malloc_nonmovable")
assert int(self.GC_CAN_MALLOC_NONMOVABLE) == run([])
@@ -676,7 +676,7 @@
return 2
return func
-
+
def test_malloc_nonmovable_fixsize(self):
run = self.runner("malloc_nonmovable_fixsize")
assert run([]) == int(self.GC_CAN_MALLOC_NONMOVABLE)
@@ -757,7 +757,7 @@
lltype.free(idarray, flavor='raw')
return 0
return f
-
+
def test_many_ids(self):
if not self.GC_CAN_TEST_ID:
py.test.skip("fails for bad reasons in lltype.py :-(")
@@ -812,7 +812,7 @@
else:
assert 0, "oups, not found"
return f, None, fix_graph_of_g
-
+
def test_do_malloc_operations(self):
run = self.runner("do_malloc_operations")
run([])
@@ -848,7 +848,7 @@
else:
assert 0, "oups, not found"
return f, None, fix_graph_of_g
-
+
def test_do_malloc_operations_in_call(self):
run = self.runner("do_malloc_operations_in_call")
run([])
@@ -859,7 +859,7 @@
l2 = []
l3 = []
l4 = []
-
+
def f():
for i in range(10):
s = lltype.malloc(S)
@@ -1079,7 +1079,7 @@
return 0
return f
-
+
def test_many_weakrefs(self):
run = self.runner("many_weakrefs")
run([])
@@ -1129,7 +1129,7 @@
def define_adr_of_nursery(cls):
class A(object):
pass
-
+
def f():
# we need at least 1 obj to allocate a nursery
a = A()
@@ -1145,9 +1145,9 @@
assert nt1 > nf1
assert nt1 == nt0
return 0
-
+
return f
-
+
def test_adr_of_nursery(self):
run = self.runner("adr_of_nursery")
res = run([])
@@ -1173,7 +1173,7 @@
def _teardown(self):
self.__ready = False # collecting here is expected
GenerationGC._teardown(self)
-
+
GC_PARAMS = {'space_size': 512*WORD,
'nursery_size': 128*WORD,
'translated_to_c': False}
More information about the pypy-commit
mailing list