Esempio n. 1
0
 def func():
     from pypy.rlib import rgc
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Esempio n. 2
0
 def func():
     from pypy.rlib import rgc
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Esempio n. 3
0
 def free_nonmovingbuffer(data, buf):
     """
     Either free a non-moving buffer or keep the original storage alive.
     """
     if rgc.can_move(data):
         lltype.free(buf, flavor='raw')
     else:
         keepalive_until_here(data)
Esempio n. 4
0
 def free_nonmovingbuffer(data, buf):
     """
     Either free a non-moving buffer or keep the original storage alive.
     """
     if rgc.can_move(data):
         lltype.free(buf, flavor='raw')
     else:
         keepalive_until_here(data)
Esempio n. 5
0
 def func():
     #try:
     a = rgc.malloc_nonmovable(TP, 3, zero=True)
     rgc.collect()
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Esempio n. 6
0
 def rewrite_assembler(self, cpu, operations):
     # Perform two kinds of rewrites in parallel:
     #
     # - Add COND_CALLs to the write barrier before SETFIELD_GC and
     #   SETARRAYITEM_GC operations.
     #
     # - Remove all uses of ConstPtrs away from the assembler.
     #   Idea: when running on a moving GC, we can't (easily) encode
     #   the ConstPtrs in the assembler, because they can move at any
     #   point in time.  Instead, we store them in 'gcrefs.list', a GC
     #   but nonmovable list; and here, we modify 'operations' to
     #   replace direct usage of ConstPtr with a BoxPtr loaded by a
     #   GETFIELD_RAW from the array 'gcrefs.list'.
     #
     newops = []
     for op in operations:
         if op.opnum == rop.DEBUG_MERGE_POINT:
             continue
         # ---------- replace ConstPtrs with GETFIELD_RAW ----------
         # xxx some performance issue here
         for i in range(len(op.args)):
             v = op.args[i]
             if isinstance(v, ConstPtr) and bool(v.value):
                 addr = self.gcrefs.get_address_of_gcref(v.value)
                 # ^^^even for non-movable objects, to record their presence
                 if rgc.can_move(v.value):
                     box = BoxPtr(v.value)
                     addr = cpu.cast_adr_to_int(addr)
                     newops.append(
                         ResOperation(rop.GETFIELD_RAW, [ConstInt(addr)],
                                      box, self.single_gcref_descr))
                     op.args[i] = box
         # ---------- write barrier for SETFIELD_GC ----------
         if op.opnum == rop.SETFIELD_GC:
             v = op.args[1]
             if isinstance(
                     v, BoxPtr) or (isinstance(v, ConstPtr)
                                    and bool(v.value)):  # store a non-NULL
                 self._gen_write_barrier(newops, op.args[0], v)
                 op = ResOperation(rop.SETFIELD_RAW,
                                   op.args,
                                   None,
                                   descr=op.descr)
         # ---------- write barrier for SETARRAYITEM_GC ----------
         if op.opnum == rop.SETARRAYITEM_GC:
             v = op.args[2]
             if isinstance(
                     v, BoxPtr) or (isinstance(v, ConstPtr)
                                    and bool(v.value)):  # store a non-NULL
                 self._gen_write_barrier(newops, op.args[0], v)
                 op = ResOperation(rop.SETARRAYITEM_RAW,
                                   op.args,
                                   None,
                                   descr=op.descr)
         # ----------
         newops.append(op)
     del operations[:]
     operations.extend(newops)
Esempio n. 7
0
 def func():
     try:
         a = rgc.malloc_nonmovable(TP)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Esempio n. 8
0
 def func():
     try:
         from pypy.rlib import rgc
         a = rgc.malloc_nonmovable(TP, 3)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Esempio n. 9
0
 def func():
     try:
         from pypy.rlib import rgc
         a = rgc.malloc_nonmovable(TP, 3)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Esempio n. 10
0
File: gc.py Progetto: alkorzt/pypy
 def rewrite_assembler(self, cpu, operations):
     # Perform two kinds of rewrites in parallel:
     #
     # - Add COND_CALLs to the write barrier before SETFIELD_GC and
     #   SETARRAYITEM_GC operations.
     #
     # - Remove all uses of ConstPtrs away from the assembler.
     #   Idea: when running on a moving GC, we can't (easily) encode
     #   the ConstPtrs in the assembler, because they can move at any
     #   point in time.  Instead, we store them in 'gcrefs.list', a GC
     #   but nonmovable list; and here, we modify 'operations' to
     #   replace direct usage of ConstPtr with a BoxPtr loaded by a
     #   GETFIELD_RAW from the array 'gcrefs.list'.
     #
     newops = []
     for op in operations:
         if op.opnum == rop.DEBUG_MERGE_POINT:
             continue
         # ---------- replace ConstPtrs with GETFIELD_RAW ----------
         # xxx some performance issue here
         for i in range(len(op.args)):
             v = op.args[i]
             if isinstance(v, ConstPtr) and bool(v.value):
                 addr = self.gcrefs.get_address_of_gcref(v.value)
                 # ^^^even for non-movable objects, to record their presence
                 if rgc.can_move(v.value):
                     box = BoxPtr(v.value)
                     addr = cpu.cast_adr_to_int(addr)
                     newops.append(ResOperation(rop.GETFIELD_RAW,
                                                [ConstInt(addr)], box,
                                                self.single_gcref_descr))
                     op.args[i] = box
         # ---------- write barrier for SETFIELD_GC ----------
         if op.opnum == rop.SETFIELD_GC:
             v = op.args[1]
             if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
                                          bool(v.value)): # store a non-NULL
                 self._gen_write_barrier(newops, op.args[0], v)
                 op = ResOperation(rop.SETFIELD_RAW, op.args, None,
                                   descr=op.descr)
         # ---------- write barrier for SETARRAYITEM_GC ----------
         if op.opnum == rop.SETARRAYITEM_GC:
             v = op.args[2]
             if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
                                          bool(v.value)): # store a non-NULL
                 self._gen_write_barrier(newops, op.args[0], v)
                 op = ResOperation(rop.SETARRAYITEM_RAW, op.args, None,
                                   descr=op.descr)
         # ----------
         newops.append(op)
     del operations[:]
     operations.extend(newops)
Esempio n. 11
0
 def convert_to_imm(self, c):
     if isinstance(c, ConstInt):
         return imm(c.value)
     elif isinstance(c, ConstPtr):
         if we_are_translated() and c.value and rgc.can_move(c.value):
             print "convert_to_imm: ConstPtr needs special care"
             raise AssertionError
         return imm(rffi.cast(lltype.Signed, c.value))
     elif isinstance(c, ConstAddr):
         return imm(ll2ctypes.cast_adr_to_int(c.value))
     else:
         print "convert_to_imm: got a %s" % c
         raise AssertionError
Esempio n. 12
0
 def get_nonmovingbuffer(data):
     """
     Either returns a non-moving copy or performs neccessary pointer
     arithmetic to return a pointer to the characters of a string if the
     string is already nonmovable.  Must be followed by a
     free_nonmovingbuffer call.
     """
     if rgc.can_move(data):
         count = len(data)
         buf = lltype.malloc(TYPEP.TO, count, flavor="raw")
         for i in range(count):
             buf[i] = data[i]
         return buf
     else:
         data_start = cast_ptr_to_adr(llstrtype(data)) + offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
         return cast(TYPEP, data_start)
Esempio n. 13
0
 def get_nonmovingbuffer(data):
     """
     Either returns a non-moving copy or performs neccessary pointer
     arithmetic to return a pointer to the characters of a string if the
     string is already nonmovable.  Must be followed by a
     free_nonmovingbuffer call.
     """
     if rgc.can_move(data):
         count = len(data)
         buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
         for i in range(count):
             buf[i] = data[i]
         return buf
     else:
         data_start = cast_ptr_to_adr(llstrtype(data)) + \
             offsetof(STRTYPE, 'chars') + itemoffsetof(STRTYPE.chars, 0)
         return cast(TYPEP, data_start)
Esempio n. 14
0
 def func():
     from pypy.rlib import rgc
     return rgc.can_move(lltype.malloc(TP, 1))
Esempio n. 15
0
 def f(i):
     if i:
         return rgc.can_move(lltype.malloc(T0))
     else:
         return rgc.can_move(lltype.malloc(T1, 1))
Esempio n. 16
0
 def func():
     return rgc.can_move(lltype.malloc(TP, 1))
Esempio n. 17
0
 def func():
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Esempio n. 18
0
 def f(i):
     if i:
         return rgc.can_move(lltype.malloc(T0))
     else:
         return rgc.can_move(lltype.malloc(T1, 1))
Esempio n. 19
0
 def fn():
     return rgc.can_move(A())
Esempio n. 20
0
 def func():
     from pypy.rlib import rgc
     return rgc.can_move(lltype.malloc(TP, 1))
Esempio n. 21
0
 def fn():
     return rgc.can_move(A())
Esempio n. 22
0
 def func():
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1