Author: Stefan Beyer <h...@sbeyer.at> Branch: cpyext-gc-cycle Changeset: r95602:65ead3f78618 Date: 2018-04-12 10:21 +0200 http://bitbucket.org/pypy/pypy/changeset/65ead3f78618/
Log: Removed unnecessary code diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h --- a/pypy/module/cpyext/include/object.h +++ b/pypy/module/cpyext/include/object.h @@ -14,8 +14,7 @@ #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) #define PY_REFCNT_FROM_PYPY (4L << ((long)(log(PY_SSIZE_T_MAX) / log(2) - 2))) -#define PY_REFCNT_GREEN (4L << ((long)(log(PY_SSIZE_T_MAX) / log(2) - 7))) -#define PY_REFCNT_OVERFLOW (1L << ((long)(log(PY_SSIZE_T_MAX) / log(2) - 7) / 2L - 1L)) +#define PY_REFCNT_OVERFLOW (1L << ((long)(log(PY_SSIZE_T_MAX) / log(2) - 4) - 1L)) #define PY_REFCNT_MASK ((PY_REFCNT_OVERFLOW << 1L) - 1L) #define Py_RETURN_NONE return (((((PyObject *)(Py_None))->ob_refcnt & PY_REFCNT_OVERFLOW) == 0) ? \ ((PyObject *)(Py_None))->ob_refcnt++ : Py_IncRef((PyObject *)(Py_None))), Py_None @@ -48,12 +47,11 @@ Py_IncRef((PyObject *)(ob)); \ } while (0) #define Py_DECREF(ob) do { \ - if (!(((PyObject *)(ob))->ob_refcnt & PY_REFCNT_GREEN) || \ - (((PyObject *)(ob))->ob_refcnt & PY_REFCNT_OVERFLOW)) \ - Py_DecRef((PyObject *)(ob)); \ + if ((((PyObject *)(ob))->ob_refcnt & PY_REFCNT_OVERFLOW)) \ + Py_DecRef((PyObject *)(ob)); \ else if (--((PyObject *)(ob))->ob_refcnt & PY_REFCNT_MASK) \ ; \ - else if ((!((PyObject *)(ob))->ob_refcnt) & PY_REFCNT_FROM_PYPY) \ + else \ _Py_Dealloc((PyObject *)(ob)); \ } while (0) diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py --- a/pypy/module/cpyext/pyobject.py +++ b/pypy/module/cpyext/pyobject.py @@ -18,9 +18,8 @@ from rpython.rtyper.annlowlevel import llhelper, cast_instance_to_base_ptr from rpython.rlib import rawrefcount, jit from rpython.rlib.debug import ll_assert, fatalerror, debug_print -from rpython.rlib.rawrefcount import ( - REFCNT_MASK, REFCNT_FROM_PYPY, REFCNT_OVERFLOW, REFCNT_CYCLE_BUFFERED, - REFCNT_CLR_MASK, REFCNT_CLR_GREEN, REFCNT_CLR_PURPLE) +from rpython.rlib.rawrefcount import (REFCNT_MASK, REFCNT_FROM_PYPY, + REFCNT_OVERFLOW) from pypy.module.cpyext.api import slot_function from pypy.module.cpyext.typeobjectdefs import visitproc @@ -401,31 +400,13 @@ rawrefcount.decref(pyobj) rc = pyobj.c_ob_refcnt if rc & REFCNT_MASK == 0: - if rc & REFCNT_FROM_PYPY == 0 and rc & REFCNT_CLR_MASK != REFCNT_CLR_PURPLE: - state = space.fromcache(State) - generic_cpy_call(space, state.C._Py_Dealloc, pyobj) - elif rc & REFCNT_CLR_MASK != REFCNT_CLR_GREEN: - possible_root(space, pyobj) + state = space.fromcache(State) + generic_cpy_call(space, state.C._Py_Dealloc, pyobj) #else: # w_obj = rawrefcount.to_obj(W_Root, ref) # if w_obj is not None: # assert pyobj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY -@jit.dont_look_inside -def possible_root(space, obj): - #debug_print("possible root", obj) - rc = obj.c_ob_refcnt - if not obj.c_ob_type or not obj.c_ob_type.c_tp_traverse: - #debug_print("mark green", obj) - rc = rc & ~REFCNT_CLR_MASK | REFCNT_CLR_GREEN - elif rc & REFCNT_CLR_MASK != REFCNT_CLR_PURPLE: - rc = rc & ~REFCNT_CLR_MASK | REFCNT_CLR_PURPLE - if rc & REFCNT_CYCLE_BUFFERED == 0: - #debug_print("mark purple", obj) - rawrefcount.buffer_pyobj(obj) - rc = rc | REFCNT_CYCLE_BUFFERED - obj.c_ob_refcnt = rc - @cpython_api([PyObject], lltype.Void) def Py_IncRef(space, obj): incref(space, obj) diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py --- a/rpython/memory/gc/incminimark.py +++ b/rpython/memory/gc/incminimark.py @@ -3067,9 +3067,6 @@ objint = llmemory.cast_adr_to_int(obj, "symbolic") self._pyobj(pyobject).c_ob_pypy_link = objint - def rawrefcount_buffer_pyobj(self, pyobject): - self.rrc_buffered.append(pyobject) - def rawrefcount_from_obj(self, gcobj): obj = llmemory.cast_ptr_to_adr(gcobj) if self.is_in_nursery(obj): @@ -3254,12 +3251,11 @@ self.rrc_more_pyobjects_to_scan = self.AddressStack() def _rrc_mark_cpyobj(self, pyobj): - from rpython.rlib.rawrefcount import (REFCNT_CLR_GRAY, - REFCNT_CLR_MASK) + from rpython.rlib.rawrefcount import REFCNT_VISITED # if the pyobj is not marked, remember it and if there is a linked pypy # object also remember it - if pyobj.c_ob_refcnt & REFCNT_CLR_MASK != REFCNT_CLR_GRAY: - pyobj.c_ob_refcnt = REFCNT_CLR_GRAY + if pyobj.c_ob_refcnt & REFCNT_VISITED != REFCNT_VISITED: + pyobj.c_ob_refcnt |= REFCNT_VISITED pyobject = llmemory.cast_ptr_to_adr(pyobj) self.rrc_more_pyobjects_to_scan.append(pyobject) intobj = pyobj.c_ob_pypy_link @@ -3270,8 +3266,7 @@ self.objects_to_trace.append(obj) def _rrc_major_scan_non_rc_roots(self, pyobject, ignore): - from rpython.rlib.rawrefcount import (REFCNT_CLR_GRAY, - REFCNT_CLR_MASK) + from rpython.rlib.rawrefcount import REFCNT_VISITED # check in the object header of the linked pypy object, if it is marked # or not pyobj = self._pyobj(pyobject) @@ -3279,9 +3274,9 @@ obj = llmemory.cast_int_to_adr(intobj) hdr = self.header(obj) if hdr.tid & GCFLAG_VISITED: - if pyobj.c_ob_refcnt & REFCNT_CLR_MASK != REFCNT_CLR_GRAY: # TODO change to black, but make white default + if pyobj.c_ob_refcnt & REFCNT_VISITED != REFCNT_VISITED: # process the pyobject now - pyobj.c_ob_refcnt = REFCNT_CLR_GRAY + pyobj.c_ob_refcnt |= REFCNT_VISITED self.rrc_pyobjects_to_trace.append(pyobject) else: # save the pyobject for later, in case its linked object becomes diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py --- a/rpython/memory/gc/test/test_rawrefcount.py +++ b/rpython/memory/gc/test/test_rawrefcount.py @@ -128,13 +128,6 @@ r1.base.c_ob_refcnt = 1 return r1 - def _rawrefcount_buffer_obj(self, obj): - from rpython.rlib.rawrefcount import REFCNT_CLR_MASK, REFCNT_CLR_PURPLE - rc = obj.base.c_ob_refcnt - obj.base.c_ob_refcnt = rc & ~REFCNT_CLR_MASK | REFCNT_CLR_PURPLE - objaddr = llmemory.cast_ptr_to_adr(obj) - self.gc.rawrefcount_buffer_pyobj(objaddr) - def test_rawrefcount_objects_basic(self, old=False): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) 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 @@ -490,10 +490,6 @@ GCClass.rawrefcount_mark_deallocating, [s_gc, s_gcref, SomeAddress()], annmodel.s_None) - self.rawrefcount_buffer_pyobj = getfn( - GCClass.rawrefcount_buffer_pyobj, - [s_gc, SomeAddress()], - annmodel.s_None) self.rawrefcount_from_obj_ptr = getfn( GCClass.rawrefcount_from_obj, [s_gc, s_gcref], SomeAddress(), inline = True) @@ -1346,13 +1342,6 @@ [self.rawrefcount_mark_deallocating, self.c_const_gc, v_gcobj, v_pyobject]) - def gct_gc_rawrefcount_buffer_pyobj(self, hop): - [v_pyobject] = hop.spaceop.args - assert v_pyobject.concretetype == llmemory.Address - hop.genop("direct_call", - [self.rawrefcount_buffer_pyobj, self.c_const_gc, - v_pyobject]) - def gct_gc_rawrefcount_from_obj(self, hop): [v_gcobj] = hop.spaceop.args assert v_gcobj.concretetype == llmemory.GCREF diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py --- a/rpython/rlib/rawrefcount.py +++ b/rpython/rlib/rawrefcount.py @@ -17,31 +17,9 @@ # Flags REFCNT_FROM_PYPY = 1 << MAX_BIT - 2 # Reference from a pypy object REFCNT_FROM_PYPY_LIGHT = (1 << MAX_BIT - 1) + REFCNT_FROM_PYPY # Light reference from a pypy object -REFCNT_CYCLE_BUFFERED = 1 << MAX_BIT - 3 # Object in roots buffer (for potential cycles) -REFCNT_IN_WAVEFRONT = 1 << MAX_BIT - 4 # Object in any wavefront - -# Offsets and sizes -REFCNT_CLR_OFFS = MAX_BIT - 7 -REFCNT_CRC_OFFS = REFCNT_CLR_OFFS / 2 -REFCNT_BITS = REFCNT_CRC_OFFS - 1 - -# Concurrent cycle collection colors -REFCNT_CLR_BLACK = 0 << REFCNT_CLR_OFFS # In use or free (default) -REFCNT_CLR_GRAY = 1 << REFCNT_CLR_OFFS # Possible member of cycle -REFCNT_CLR_YELLOW = 2 << REFCNT_CLR_OFFS # Member of garbage cycle -REFCNT_CLR_PURPLE = 3 << REFCNT_CLR_OFFS # Possible root of cycle -REFCNT_CLR_GREEN = 4 << REFCNT_CLR_OFFS # Acyclic -REFCNT_CLR_ORANGE = 5 << REFCNT_CLR_OFFS # In orange wavefront (might change to YELLOW + IN_WAVEFRONT + phase = 3) -REFCNT_CLR_MASK = 7 << REFCNT_CLR_OFFS - -# Cyclic reference count with overflow bit -REFCNT_CRC_OVERFLOW = 1 << REFCNT_CRC_OFFS + REFCNT_BITS -REFCNT_CRC_MASK = (1 << REFCNT_CRC_OFFS + REFCNT_BITS + 1) - 1 -REFCNT_CRC = 1 < REFCNT_CRC_OFFS - -# True reference count with overflow bit -REFCNT_OVERFLOW = 1 << REFCNT_BITS -REFCNT_MASK = (1 << REFCNT_BITS + 1) - 1 +REFCNT_VISITED = 1 << MAX_BIT - 3 # Object visited during marking +REFCNT_OVERFLOW = 1 << MAX_BIT - 4 # Overflow bit for reference count +REFCNT_MASK = (REFCNT_OVERFLOW << 1) - 1 # Mask for reference count (including overflow bit) PYOBJ_HDR = lltype.Struct('GCHdr_PyObject', ('c_ob_refcnt', lltype.Signed), @@ -101,7 +79,6 @@ def overflow_get(obj): return _refcount_overflow[objectmodel.current_object_addr_as_int(obj)] -# TODO: _cyclic_refcount_overflow = dict() @not_rpython def init(dealloc_trigger_callback=None, tp_traverse=None): @@ -161,10 +138,6 @@ ob.c_ob_pypy_link = _build_pypy_link(marker) @not_rpython -def buffer_pyobj(ob): - pass # TODO: implement? - -@not_rpython def from_obj(OB_PTR_TYPE, p): ob = _pypy2ob.get(p) if ob is None: @@ -350,18 +323,6 @@ hop.genop('direct_call', [c_func]) class Entry(ExtRegistryEntry): - _about_ = buffer_pyobj - - def compute_result_annotation(self, s_ob): - pass - - def specialize_call(self, hop): - name = 'gc_rawrefcount_buffer_pyobj' - hop.exception_cannot_occur() - v_ob = hop.inputarg(hop.args_r[0], arg=0) - hop.genop(name, [_unspec_ob(hop, v_ob)]) - -class Entry(ExtRegistryEntry): _about_ = from_obj def compute_result_annotation(self, s_OB_PTR_TYPE, s_p): diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py --- a/rpython/rtyper/llinterp.py +++ b/rpython/rtyper/llinterp.py @@ -969,9 +969,6 @@ def op_gc_rawrefcount_mark_deallocating(self, *args): raise NotImplementedError("gc_rawrefcount_mark_deallocating") - def op_gc_rawrefcount_buffer_pyobj(self, *args): - raise NotImplementedError("gc_rawrefcount_buffer_pyobj") - def op_gc_rawrefcount_next_dead(self, *args): raise NotImplementedError("gc_rawrefcount_next_dead") diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py --- a/rpython/rtyper/lltypesystem/lloperation.py +++ b/rpython/rtyper/lltypesystem/lloperation.py @@ -494,7 +494,6 @@ 'gc_rawrefcount_create_link_pypy': LLOp(), 'gc_rawrefcount_create_link_pyobj': LLOp(), 'gc_rawrefcount_mark_deallocating': LLOp(), - 'gc_rawrefcount_buffer_pyobj': LLOp(), 'gc_rawrefcount_from_obj': LLOp(sideeffects=False), 'gc_rawrefcount_to_obj': LLOp(sideeffects=False), 'gc_rawrefcount_next_dead': LLOp(), _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit