Author: fijal Branch: memory-accounting Changeset: r92489:238b67adb061 Date: 2017-09-28 17:54 +0200 http://bitbucket.org/pypy/pypy/changeset/238b67adb061/
Log: write the number of raw malloced bytes into structs that are used for add_memory_pressure diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -71,6 +71,7 @@ self.needs_generic_instantiate = {} self.thread_local_fields = set() + self.memory_pressure_types = set() self.register_builtins() diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py --- a/rpython/memory/gctransform/framework.py +++ b/rpython/memory/gctransform/framework.py @@ -832,6 +832,22 @@ gct_fv_gc_malloc_varsize = gct_fv_gc_malloc + def gct_gc_add_memory_pressure(self, hop): + if hasattr(self, 'raw_malloc_memory_pressure_ptr'): + op = hop.spaceop + size = op.args[0] + if len(op.args) == 2: + v_fld = rmodel.inputconst(lltype.Void, "special_memory_pressure") + hop.genop("bare_setfield", [op.args[1], v_fld, size]) + v_adr = hop.genop("cast_ptr_to_adr", [op.args[1]], + resulttype=llmemory.Address) + else: + v_adr = rmodel.inputconst(llmemory.Address, llmemory.NULL) + return hop.genop("direct_call", + [self.raw_malloc_memory_pressure_ptr, + size, v_adr]) + + def gct_gc__collect(self, hop): op = hop.spaceop if len(op.args) == 1: diff --git a/rpython/memory/gctransform/transform.py b/rpython/memory/gctransform/transform.py --- a/rpython/memory/gctransform/transform.py +++ b/rpython/memory/gctransform/transform.py @@ -535,17 +535,7 @@ return self.varsize_malloc_helper(hop, flags, meth, []) def gct_gc_add_memory_pressure(self, hop): - if hasattr(self, 'raw_malloc_memory_pressure_ptr'): - op = hop.spaceop - size = op.args[0] - if len(op.args) == 2: - v_adr = hop.genop("cast_ptr_to_adr", [op.args[1]], - resulttype=llmemory.Address) - else: - v_adr = rmodel.inputconst(llmemory.Address, llmemory.NULL) - return hop.genop("direct_call", - [self.raw_malloc_memory_pressure_ptr, - size, v_adr]) + pass def varsize_malloc_helper(self, hop, flags, meth, extraargs): def intconst(c): return rmodel.inputconst(lltype.Signed, c) diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py --- a/rpython/rlib/rgc.py +++ b/rpython/rlib/rgc.py @@ -607,6 +607,11 @@ def compute_result_annotation(self, s_nbytes, s_object=None): from rpython.annotator import model as annmodel + if s_object is not None: + if not isinstance(s_object, annmodel.SomeInstance): + raise Exception("Wrong kind of object passed to " + "add memory pressure") + self.bookkeeper.memory_pressure_types.add(s_object.classdef) return annmodel.s_None def specialize_call(self, hop): diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py --- a/rpython/rtyper/rclass.py +++ b/rpython/rtyper/rclass.py @@ -523,6 +523,10 @@ if not attrdef.readonly and self.is_quasi_immutable(name): llfields.append(('mutate_' + name, OBJECTPTR)) + bookkeeper = self.rtyper.annotator.bookkeeper + if self.classdef in bookkeeper.memory_pressure_types: + llfields = [('special_memory_pressure', lltype.Signed)] + llfields + object_type = MkStruct(self.classdef.name, ('super', self.rbase.object_type), hints=hints, _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit