Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: gc-minimark-pinning
Changeset: r54991:e38b2238ce3b
Date: 2012-05-08 17:34 +0200
http://bitbucket.org/pypy/pypy/changeset/e38b2238ce3b/

Log:    remove malloc_and_pin after discussions with armin

diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -119,40 +119,6 @@
         hop.exception_is_here()
         return hop.genop('gc_heap_stats', [], resulttype=hop.r_result)
 
-def malloc_and_pin(TP, n=None, zero=False):
-    """ Allocate a buffer and immediately pin it. If the GC does not support
-    pinning or cannot fulfill the request for some other reason, null ptr
-    is returned. Make sure you unpin this thing when you're done
-    """
-    return lltype.malloc(TP, n, zero=zero)
-
-class MallocAndPinEntry(ExtRegistryEntry):
-    _about_ = malloc_and_pin
-
-    def compute_result_annotation(self, s_TP, s_n=None, s_zero=None):
-        # basically return the same as malloc
-        from pypy.annotation.builtin import malloc
-        return malloc(s_TP, s_n, s_zero=s_zero)
-
-    def specialize_call(self, hop, i_zero=None):
-        assert hop.args_s[0].is_constant()
-        vlist = [hop.inputarg(lltype.Void, arg=0)]
-        opname = 'malloc_and_pin'
-        flags = {'flavor': 'gc'}
-        if i_zero is not None:
-            flags['zero'] = hop.args_s[i_zero].const
-            nb_args = hop.nb_args - 1
-        else:
-            nb_args = hop.nb_args
-        vlist.append(hop.inputconst(lltype.Void, flags))
-
-        if nb_args == 2:
-            vlist.append(hop.inputarg(lltype.Signed, arg=1))
-            opname = 'malloc_varsize_and_pin'
-
-        hop.exception_cannot_occur()
-        return hop.genop(opname, vlist, resulttype = hop.r_result.lowleveltype)
-
 @jit.oopspec('list.ll_arraycopy(source, dest, source_start, dest_start, 
length)')
 @specialize.ll()
 @enforceargs(None, None, int, int, int)
diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py
--- a/pypy/rpython/llinterp.py
+++ b/pypy/rpython/llinterp.py
@@ -702,18 +702,6 @@
         except MemoryError:
             self.make_llexception()
 
-    def op_malloc_and_pin(self, TYPE, flags):
-        flavor = flags['flavor']
-        assert flavor == 'gc'
-        zero = flags.get('zero', False)
-        return self.heap.malloc_and_pin(TYPE, zero=zero)
-
-    def op_malloc_varsize_and_pin(self, TYPE, flags, size):
-        flavor = flags['flavor']
-        assert flavor == 'gc'
-        zero = flags.get('zero', False)
-        return self.heap.malloc_varsize_and_pin(TYPE, size, zero=zero)
-
     def op_free(self, obj, flags):
         assert flags['flavor'] == 'raw'
         track_allocation = flags.get('track_allocation', True)
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
@@ -18,9 +18,6 @@
 def weakref_create_getlazy(objgetter):
     return weakref_create(objgetter())
 
-malloc_and_pin = malloc
-malloc_varsize_and_pin = malloc
-
 def shrink_array(p, smallersize):
     return False
 
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
@@ -357,8 +357,6 @@
 
     'malloc':               LLOp(canmallocgc=True),
     'malloc_varsize':       LLOp(canmallocgc=True),
-    'malloc_and_pin':    LLOp(canmallocgc=True),
-    'malloc_varsize_and_pin':LLOp(canmallocgc=True),
     'shrink_array':         LLOp(canrun=True),
     'zero_gc_pointers_inside': LLOp(),
     'free':                 LLOp(),
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
@@ -166,13 +166,6 @@
         # lots of cast and reverse-cast around...
         return llmemory.cast_ptr_to_adr(ref)
 
-    def malloc_fixedsize_and_pin(self, typeid, size):
-        return lltype.nullptr(llmemory.GCREF.TO)
-
-    def malloc_varsize_and_pin(self, typeid, length, size, itemsize,
-                               offset_to_length):
-        return lltype.nullptr(llmemory.GCREF.TO)
-
     def id(self, ptr):
         return lltype.cast_ptr_to_int(ptr)
 
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
@@ -581,20 +581,6 @@
         #
         return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
 
-    def malloc_fixedsize_and_pin(self, typeid, size):
-        r = self.malloc_fixedsize_clear(typeid, size)
-        if not self.pin(llmemory.cast_ptr_to_adr(r)):
-            return lltype.nullptr(llmemory.GCREF.TO)
-        return r
-        
-    def malloc_varsize_and_pin(self, typeid, length, size, itemsize,
-                               offset_to_length):
-        r = self.malloc_varsize_clear(typeid, length, size, itemsize,
-                                      offset_to_length)
-        if not self.pin(llmemory.cast_ptr_to_adr(r)):
-            return lltype.nullptr(llmemory.GCREF.TO)
-        return r        
-
     def collect(self, gen=1):
         """Do a minor (gen=0) or major (gen>0) collection."""
         self.minor_collection()
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
@@ -283,14 +283,6 @@
         self.can_move_ptr = getfn(GCClass.can_move.im_func,
                                   [s_gc, annmodel.SomeAddress()],
                                   annmodel.SomeBool())
-        self.malloc_fixedsize_and_pin_ptr = getfn(
-            GCClass.malloc_fixedsize_and_pin,
-            [s_gc, s_typeid16, annmodel.SomeInteger(nonneg=True)],
-            s_gcref)
-        self.malloc_varsize_and_pin_ptr = getfn(
-            GCClass.malloc_varsize_and_pin,
-            [s_gc, s_typeid16] + [annmodel.SomeInteger(nonneg=True)] * 4,
-            s_gcref)
 
         if hasattr(GCClass, 'shrink_array'):
             self.shrink_array_ptr = getfn(
@@ -686,9 +678,7 @@
         if not 'varsize' in op.opname and not flags.get('varsize'):
             #malloc_ptr = self.malloc_fixedsize_ptr
             zero = flags.get('zero', False)
-            if op.opname == 'malloc_and_pin':
-                malloc_ptr = self.malloc_fixedsize_and_pin_ptr
-            elif (self.malloc_fast_ptr is not None and
+            if (self.malloc_fast_ptr is not None and
                 not c_has_finalizer.value and
                 (self.malloc_fast_is_clearing or not zero)):
                 malloc_ptr = self.malloc_fast_ptr
@@ -707,9 +697,7 @@
                                               info_varsize.ofstolength)
             c_varitemsize = rmodel.inputconst(lltype.Signed,
                                               info_varsize.varitemsize)
-            if op.opname == 'malloc_varsize_and_pin':
-                malloc_ptr = self.malloc_varsize_and_pin_ptr
-            elif self.malloc_varsize_clear_fast_ptr is not None:
+            if self.malloc_varsize_clear_fast_ptr is not None:
                 malloc_ptr = self.malloc_varsize_clear_fast_ptr
             else:
                 malloc_ptr = self.malloc_varsize_clear_ptr
@@ -1101,16 +1089,6 @@
                   resultvar=hop.spaceop.result)
         self.pop_roots(hop, livevars)
 
-    def gct_malloc_and_pin(self, hop):
-        TYPE = hop.spaceop.result.concretetype
-        v_raw = self.gct_fv_gc_malloc(hop, {'flavor': 'gc'}, TYPE.TO)
-        hop.cast_result(v_raw)
-
-    def gct_malloc_varisze_and_pin(self, hop):
-        TYPE = hop.spaceop.result.concretetype
-        v_raw = self.gct_fv_gc_malloc(hop, {'flavor': 'gc'}, TYPE.TO)
-        hop.cast_result(v_raw)
-
     def _set_into_gc_array_part(self, op):
         if op.opname == 'setarrayitem':
             return op.args[1]
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
@@ -1,4 +1,3 @@
-import py
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.objspace.flow.model import SpaceOperation, Variable, Constant, \
      c_last_exception, checkgraph
@@ -7,22 +6,18 @@
 from pypy.translator.unsimplify import starts_with_empty_block
 from pypy.translator.backendopt.support import var_needsgc
 from pypy.translator.backendopt import inline
-from pypy.translator.backendopt import graphanalyze
 from pypy.translator.backendopt.canraise import RaiseAnalyzer
 from pypy.translator.backendopt.ssa import DataFlowFamilyBuilder
 from pypy.translator.backendopt.constfold import constant_fold_graph
 from pypy.annotation import model as annmodel
 from pypy.rpython import rmodel
-from pypy.rpython.memory import gc
 from pypy.rpython.memory.gctransform.support import var_ispyobj
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
 from pypy.rpython.rtyper import LowLevelOpList
 from pypy.rpython.rbuiltin import gen_cast
 from pypy.rlib.rarithmetic import ovfcheck
-import sys
-import os
 from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.translator.simplify import join_blocks, cleanup_graph
+from pypy.translator.simplify import cleanup_graph
 
 PyObjPtr = lltype.Ptr(lltype.PyObject)
 
@@ -560,12 +555,6 @@
         assert meth, "%s has no support for malloc_varsize with flavor %r" % 
(self, flavor)
         return self.varsize_malloc_helper(hop, flags, meth, [])
 
-    def gct_malloc_and_pin(self, *args, **kwds):
-        return self.gct_malloc(*args, **kwds)
-
-    def gct_malloc_varsize_and_pin(self, hop, *args, **kwds):
-        return self.gct_malloc_varsize(hop, *args, **kwds)
-
     def gct_gc_add_memory_pressure(self, hop):
         if hasattr(self, 'raw_malloc_memory_pressure_ptr'):
             op = hop.spaceop
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
@@ -56,25 +56,6 @@
             return lltype.malloc(TYPE, n, flavor=flavor, zero=zero,
                                  track_allocation=track_allocation)
 
-    def malloc_and_pin(self, TYPE, n=None, zero=False):
-        typeid = self.get_type_id(TYPE)
-        size = self.gc.fixed_size(typeid)
-        result = self.gc.malloc_fixedsize_and_pin(typeid, size)
-        if result:
-            assert self.gc.malloc_zero_filled
-        return lltype.cast_opaque_ptr(lltype.Ptr(TYPE), result)
-
-    def malloc_varsize_and_pin(self, TYPE, n=None, zero=False):
-        typeid = self.get_type_id(TYPE)
-        size = self.gc.fixed_size(typeid)
-        itemsize = self.gc.varsize_item_sizes(typeid)
-        offset_to_length = self.gc.varsize_offset_to_length(typeid)
-        result = self.gc.malloc_varsize_and_pin(typeid, n, size, itemsize,
-                                              offset_to_length)
-        if result:
-            assert self.gc.malloc_zero_filled
-        return lltype.cast_opaque_ptr(lltype.Ptr(TYPE), result)
-
     def add_memory_pressure(self, size):
         if hasattr(self.gc, 'raw_malloc_memory_pressure'):
             self.gc.raw_malloc_memory_pressure(size)
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
@@ -25,7 +25,6 @@
 class GCTest(object):
     GC_PARAMS = {}
     GC_CAN_MOVE = False
-    GC_CAN_MALLOC_AND_PIN = False
     GC_CAN_SHRINK_ARRAY = False
     GC_CAN_SHRINK_BIG_ARRAY = False
     BUT_HOW_BIG_IS_A_BIG_STRING = 3*WORD
@@ -592,36 +591,6 @@
             return rgc.can_move(lltype.malloc(TP, 1))
         assert self.interpret(func, []) == self.GC_CAN_MOVE
 
-
-    def test_malloc_and_pin(self):
-        TP = lltype.GcArray(lltype.Char)
-        def func():
-            a = rgc.malloc_and_pin(TP, 3)
-            adr = llmemory.cast_ptr_to_adr(a)
-            if a:
-                rgc.collect()
-                assert adr == llmemory.cast_ptr_to_adr(a)
-                keepalive_until_here(a)
-                return 1
-            return 0
-
-        assert self.interpret(func, []) == int(self.GC_CAN_MALLOC_AND_PIN)
-
-    def test_malloc_and_pin_fixsize(self):
-        S = lltype.GcStruct('S', ('x', lltype.Float))
-        TP = lltype.GcStruct('T', ('s', lltype.Ptr(S)))
-        def func():
-            try:
-                a = rgc.malloc_and_pin(TP)
-                if a:
-                    assert not rgc.can_move(a)
-                    return 1
-                return 0
-            except Exception:
-                return 2
-
-        assert self.interpret(func, []) == int(self.GC_CAN_MALLOC_AND_PIN)
-
     def test_shrink_array(self):
         from pypy.rpython.lltypesystem.rstr import STR
 
@@ -928,7 +897,6 @@
 class TestMiniMarkGC(TestSemiSpaceGC):
     from pypy.rpython.memory.gc.minimark import MiniMarkGC as GCClass
     GC_CAN_SHRINK_BIG_ARRAY = False
-    GC_CAN_MALLOC_AND_PIN = True
     BUT_HOW_BIG_IS_A_BIG_STRING = 11*WORD
 
     # those tests are here because they'll be messy and useless
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
@@ -1,10 +1,9 @@
 import py
-import sys
 import inspect
 from pypy.translator.c import gc
 from pypy.annotation import model as annmodel
 from pypy.annotation import policy as annpolicy
-from pypy.rpython.lltypesystem import lltype, llmemory, llarena, rffi, llgroup
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi, llgroup
 from pypy.rpython.memory.gctransform import framework
 from pypy.rpython.lltypesystem.lloperation import llop, void
 from pypy.rlib.objectmodel import compute_unique_id, we_are_translated
@@ -42,7 +41,6 @@
 class GCTest(object):
     gcpolicy = None
     GC_CAN_MOVE = False
-    GC_CAN_MALLOC_AND_PIN = False
     GC_CAN_ALWAYS_PIN = False
     taggedpointers = False
 
@@ -643,42 +641,6 @@
         res = run([])
         assert res == self.GC_CAN_MOVE
 
-    def define_malloc_and_pin(cls):
-        TP = lltype.GcArray(lltype.Char)
-        def func():
-            a = rgc.malloc_and_pin(TP, 3, zero=True)
-            if a:
-                assert not rgc.can_move(a)
-                rgc.unpin(a)
-                return 1
-            return 0
-
-        return func
-
-    def test_malloc_and_pin(self):
-        run = self.runner("malloc_and_pin")
-        assert int(self.GC_CAN_MALLOC_AND_PIN) == run([])
-
-    def define_malloc_and_pin_fixsize(cls):
-        S = lltype.GcStruct('S', ('x', lltype.Float))
-        TP = lltype.GcStruct('T', ('s', lltype.Ptr(S)))
-        def func():
-            try:
-                a = rgc.malloc_and_pin(TP)
-                if a:
-                    assert not rgc.can_move(a)
-                    rgc.unpin(a)
-                    return 1
-                return 0
-            except Exception:
-                return 2
-
-        return func
-
-    def test_malloc_and_pin_fixsize(self):
-        run = self.runner("malloc_and_pin_fixsize")
-        assert run([]) == int(self.GC_CAN_MALLOC_AND_PIN)
-
     def define_shrink_array(cls):
         from pypy.rpython.lltypesystem.rstr import STR
 
@@ -1222,7 +1184,6 @@
 
 class TestHybridGC(TestGenerationGC):
     gcname = "hybrid"
-    GC_CAN_MALLOC_AND_PIN = True
 
     class gcpolicy(gc.FrameworkGcPolicy):
         class transformerclass(framework.FrameworkGCTransformer):
@@ -1290,7 +1251,6 @@
     gcname = "minimark"
     GC_CAN_TEST_ID = True
     GC_CAN_ALWAYS_PIN = True
-    GC_CAN_MALLOC_AND_PIN = True
 
     class gcpolicy(gc.FrameworkGcPolicy):
         class transformerclass(framework.FrameworkGCTransformer):
diff --git a/pypy/translator/backendopt/removenoops.py 
b/pypy/translator/backendopt/removenoops.py
--- a/pypy/translator/backendopt/removenoops.py
+++ b/pypy/translator/backendopt/removenoops.py
@@ -1,8 +1,6 @@
-from pypy.objspace.flow.model import Block, Variable, Constant
-from pypy.rpython.lltypesystem.lltype import Void
+from pypy.objspace.flow.model import Variable, Constant
 from pypy.translator.backendopt.support import log
 from pypy.translator import simplify
-from pypy import conftest
 
 def remove_unaryops(graph, opnames):
     """Removes unary low-level ops with a name appearing in the opnames list.
diff --git a/pypy/translator/c/test/test_newgc.py 
b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -1,13 +1,12 @@
 import py
 import sys, os, inspect
 
-from pypy.objspace.flow.model import summary
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.memory.test import snippet
 from pypy.rlib import rgc
 from pypy.rlib.objectmodel import keepalive_until_here
-from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
+from pypy.rlib.rstring import StringBuilder
 from pypy.tool.udir import udir
 from pypy.translator.interactive import Translation
 from pypy.annotation import policy as annpolicy
@@ -19,7 +18,6 @@
     removetypeptr = False
     taggedpointers = False
     GC_CAN_MOVE = False
-    GC_CAN_MALLOC_AND_PIN = False
     GC_CAN_SHRINK_ARRAY = False
 
     _isolated_func = None
@@ -723,25 +721,6 @@
     def test_can_move(self):
         assert self.run('can_move') == self.GC_CAN_MOVE
 
-    def define_malloc_and_pin(cls):
-        TP = lltype.GcArray(lltype.Char)
-        def func():
-            try:
-                a = rgc.malloc_and_pin(TP, 3)
-                if a:
-                    assert not rgc.can_move(a)
-                    rgc.unpin(a)
-                    return 1
-                return 0
-            except Exception:
-                return 2
-
-        return func
-
-    def test_malloc_and_pin(self):
-        res = self.run('malloc_and_pin')
-        assert res == self.GC_CAN_MALLOC_AND_PIN
-
     def define_resizable_buffer(cls):
         from pypy.rpython.lltypesystem.rstr import STR
 
@@ -1438,7 +1417,6 @@
 class TestMiniMarkGC(TestSemiSpaceGC):
     gcpolicy = "minimark"
     should_be_moving = True
-    GC_CAN_MALLOC_AND_PIN = True
     GC_CAN_SHRINK_ARRAY = True
 
     def test_gc_heap_stats(self):
diff --git a/pypy/translator/exceptiontransform.py 
b/pypy/translator/exceptiontransform.py
--- a/pypy/translator/exceptiontransform.py
+++ b/pypy/translator/exceptiontransform.py
@@ -1,14 +1,13 @@
 from pypy.translator.simplify import join_blocks, cleanup_graph
 from pypy.translator.unsimplify import copyvar, varoftype
 from pypy.translator.unsimplify import insert_empty_block, split_block
-from pypy.translator.backendopt import canraise, inline, support, removenoops
+from pypy.translator.backendopt import canraise, inline
 from pypy.objspace.flow.model import Block, Constant, Variable, Link, \
-    c_last_exception, SpaceOperation, checkgraph, FunctionGraph, mkentrymap
+    c_last_exception, SpaceOperation, FunctionGraph, mkentrymap
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem import lloperation
 from pypy.rpython import rtyper
-from pypy.rpython import rclass
 from pypy.rpython.rmodel import inputconst
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.rlib.rarithmetic import r_singlefloat
@@ -255,9 +254,7 @@
               len(block.operations) and
               (block.exits[0].args[0].concretetype is lltype.Void or
                block.exits[0].args[0] is block.operations[-1].result) and
-              block.operations[-1].opname not in ('malloc',     # special cases
-                                                  'malloc_and_pin',
-                                                  'malloc_varsize_and_pin')):
+              block.operations[-1].opname != 'malloc'):     # special cases
             last_operation -= 1
         lastblock = block
         for i in range(last_operation, -1, -1):
@@ -438,14 +435,6 @@
             flavor = spaceop.args[1].value['flavor']
             if flavor == 'gc':
                 insert_zeroing_op = True
-        elif spaceop.opname in ['malloc_and_pin', 'malloc_varsize_and_pin']:
-            # xxx we cannot insert zero_gc_pointers_inside after
-            # malloc_and_pin, because it can return null.  For now
-            # we simply always force the zero=True flag on
-            # malloc_and_pin.
-            c_flags = spaceop.args[1]
-            c_flags.value = c_flags.value.copy()
-            spaceop.args[1].value['zero'] = True
         # NB. when inserting more special-cases here, keep in mind that
         # you also need to list the opnames in transform_block()
         # (see "special cases")
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to