[pypy-commit] pypy stmgc-c8-dictstrategy: Change cast_instance_to_gcref() to erase()/unerase(), which is better for the purpose
arigo
noreply at buildbot.pypy.org
Thu Nov 26 11:32:11 EST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c8-dictstrategy
Changeset: r80978:de0731edb16f
Date: 2015-11-26 16:33 +0000
http://bitbucket.org/pypy/pypy/changeset/de0731edb16f/
Log: Change cast_instance_to_gcref() to erase()/unerase(), which is
better for the purpose
diff --git a/pypy/module/pypystm/hashtable.py b/pypy/module/pypystm/hashtable.py
--- a/pypy/module/pypystm/hashtable.py
+++ b/pypy/module/pypystm/hashtable.py
@@ -7,10 +7,10 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from rpython.rlib import rstm
+from rpython.rlib import rstm, rerased
from rpython.rlib.rarithmetic import intmask
-from rpython.rtyper.annlowlevel import cast_gcref_to_instance
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
+
+erase, unerase = rerased.new_erasing_pair("stmdictitem")
class W_Hashtable(W_Root):
@@ -23,11 +23,11 @@
gcref = self.h.get(key)
if not gcref:
space.raise_key_error(space.wrap(key))
- return cast_gcref_to_instance(W_Root, gcref)
+ return unerase(gcref)
@unwrap_spec(key=int)
def setitem_w(self, key, w_value):
- self.h.set(key, cast_instance_to_gcref(w_value))
+ self.h.set(key, erase(w_value))
@unwrap_spec(key=int)
def delitem_w(self, space, key):
@@ -46,16 +46,16 @@
gcref = self.h.get(key)
if not gcref:
return w_default
- return cast_gcref_to_instance(W_Root, gcref)
+ return unerase(gcref)
@unwrap_spec(key=int, w_default=WrappedDefault(None))
def setdefault_w(self, space, key, w_default):
entry = self.h.lookup(key)
gcref = entry.object
if not gcref:
- self.h.writeobj(entry, cast_instance_to_gcref(w_default))
+ self.h.writeobj(entry, erase(w_default))
return w_default
- return cast_gcref_to_instance(W_Root, gcref)
+ return unerase(gcref)
def len_w(self, space):
return space.wrap(self.h.len())
@@ -67,7 +67,7 @@
def values_w(self, space):
array, count = self.h.list()
- lst_w = [cast_gcref_to_instance(W_Root, array[i].object)
+ lst_w = [unerase(array[i].object)
for i in range(count)]
return space.newlist(lst_w)
@@ -75,7 +75,7 @@
array, count = self.h.list()
lst_w = [space.newtuple([
space.wrap(intmask(array[i].index)),
- cast_gcref_to_instance(W_Root, array[i].object)])
+ unerase(array[i].object)])
for i in range(count)]
return space.newlist(lst_w)
@@ -120,13 +120,13 @@
class W_HashtableIterValues(W_BaseHashtableIter):
def get_final_value(self, space, entry):
- return cast_gcref_to_instance(W_Root, entry.object)
+ return unerase(entry.object)
class W_HashtableIterItems(W_BaseHashtableIter):
def get_final_value(self, space, entry):
return space.newtuple([
space.wrap(intmask(entry.index)),
- cast_gcref_to_instance(W_Root, entry.object)])
+ unerase(entry.object)])
def W_Hashtable___new__(space, w_subtype):
diff --git a/pypy/module/pypystm/queue.py b/pypy/module/pypystm/queue.py
--- a/pypy/module/pypystm/queue.py
+++ b/pypy/module/pypystm/queue.py
@@ -8,9 +8,9 @@
from pypy.interpreter.error import OperationError, oefmt
from pypy.module.thread.error import wrap_thread_error
-from rpython.rlib import rstm
-from rpython.rtyper.annlowlevel import cast_gcref_to_instance
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
+from rpython.rlib import rstm, rerased
+
+erase, unerase = rerased.new_erasing_pair("stmdictitem")
class Cache:
@@ -27,7 +27,7 @@
"""Put an item into the queue.
This queue does not support a maximum size.
"""
- self.q.put(cast_instance_to_gcref(w_item))
+ self.q.put(erase(w_item))
@unwrap_spec(block=int)
def get_w(self, space, block=1, w_timeout=None):
@@ -54,7 +54,7 @@
if not gcref:
raise OperationError(space.fromcache(Cache).w_Empty,
space.w_None)
- return cast_gcref_to_instance(W_Root, gcref)
+ return unerase(gcref)
def task_done_w(self, space):
"""Indicate that a formerly enqueued task is complete.
diff --git a/pypy/module/pypystm/stmdict.py b/pypy/module/pypystm/stmdict.py
--- a/pypy/module/pypystm/stmdict.py
+++ b/pypy/module/pypystm/stmdict.py
@@ -7,15 +7,15 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from rpython.rlib import rstm, jit, rgc
+from rpython.rlib import rstm, jit, rgc, rerased
from rpython.rlib.objectmodel import specialize, we_are_translated
-from rpython.rtyper.annlowlevel import cast_gcref_to_instance
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
from rpython.rtyper.lltypesystem import lltype, llmemory
ARRAY = lltype.GcArray(llmemory.GCREF)
PARRAY = lltype.Ptr(ARRAY)
+erase, unerase = rerased.new_erasing_pair("stmdictitem")
+
# XXX: should have identity-dict strategy
def really_find_equal_item(space, h, w_key):
@@ -57,7 +57,7 @@
def _find_equal_item(space, array, w_key):
# result by this function is based on 'array'. If the entry
# changes, the result is stale.
- w_item = cast_gcref_to_instance(W_Root, array[0])
+ w_item = unerase(array[0])
if space.eq_w(w_key, w_item):
return 0
if len(array) > 2:
@@ -70,7 +70,7 @@
i = 2
limit = len(array) # fixed size
while True:
- w_item = cast_gcref_to_instance(W_Root, array[i])
+ w_item = unerase(array[i])
if space.eq_w(w_key, w_item):
return i
i += 2
@@ -89,7 +89,7 @@
if i < 0: # or not array
return None
# found
- w_value = cast_gcref_to_instance(W_Root, array[i + 1])
+ w_value = unerase(array[i + 1])
L = len(array) - 2
if L == 0:
narray = lltype.nullptr(ARRAY)
@@ -107,7 +107,7 @@
def getitem(space, h, w_key):
entry, array, i = really_find_equal_item(space, h, w_key)
if array and i >= 0:
- return cast_gcref_to_instance(W_Root, array[i + 1])
+ return unerase(array[i + 1])
space.raise_key_error(w_key)
def setitem(space, h, w_key, w_value):
@@ -115,7 +115,7 @@
if array:
if i >= 0:
# already there, update the value
- array[i + 1] = cast_instance_to_gcref(w_value)
+ array[i + 1] = erase(w_value)
return
L = len(array)
narray = lltype.malloc(ARRAY, L + 2)
@@ -123,8 +123,8 @@
else:
narray = lltype.malloc(ARRAY, 2)
L = 0
- narray[L] = cast_instance_to_gcref(w_key)
- narray[L + 1] = cast_instance_to_gcref(w_value)
+ narray[L] = erase(w_key)
+ narray[L + 1] = erase(w_value)
h.writeobj(entry, lltype.cast_opaque_ptr(llmemory.GCREF, narray))
def delitem(space, h, w_key):
@@ -156,7 +156,7 @@
def get_w(self, space, w_key, w_default):
entry, array, i = really_find_equal_item(space, self.h, w_key)
if array and i >= 0:
- return cast_gcref_to_instance(W_Root, array[i + 1])
+ return unerase(array[i + 1])
return w_default
def pop_w(self, space, w_key, w_default=None):
@@ -174,15 +174,15 @@
if array:
if i >= 0:
# already there, return the existing value
- return cast_gcref_to_instance(W_Root, array[i + 1])
+ return unerase(array[i + 1])
L = len(array)
narray = lltype.malloc(ARRAY, L + 2)
ll_arraycopy(array, narray, 0, 0, L)
else:
narray = lltype.malloc(ARRAY, 2)
L = 0
- narray[L] = cast_instance_to_gcref(w_key)
- narray[L + 1] = cast_instance_to_gcref(w_default)
+ narray[L] = erase(w_key)
+ narray[L + 1] = erase(w_default)
self.h.writeobj(entry, lltype.cast_opaque_ptr(llmemory.GCREF, narray))
return w_default
@@ -205,7 +205,7 @@
j = offset
limit = len(subarray)
while j < limit:
- w_item = cast_gcref_to_instance(W_Root, subarray[j])
+ w_item = unerase(subarray[j])
result_list_w.append(w_item)
j += 2
return result_list_w
@@ -219,8 +219,8 @@
j = 0
limit = len(subarray)
while j < limit:
- w_key = cast_gcref_to_instance(W_Root, subarray[j])
- w_value = cast_gcref_to_instance(W_Root, subarray[j + 1])
+ w_key = unerase(subarray[j])
+ w_value = unerase(subarray[j + 1])
result_list_w.append(space.newtuple([w_key, w_value]))
j += 2
return result_list_w
@@ -289,17 +289,17 @@
class W_STMDictIterKeys(W_BaseSTMDictIter):
def get_final_value(self, space, array, index):
- return cast_gcref_to_instance(W_Root, array[index])
+ return unerase(array[index])
class W_STMDictIterValues(W_BaseSTMDictIter):
def get_final_value(self, space, array, index):
- return cast_gcref_to_instance(W_Root, array[index + 1])
+ return unerase(array[index + 1])
class W_STMDictIterItems(W_BaseSTMDictIter):
def get_final_value(self, space, array, index):
return space.newtuple([
- cast_gcref_to_instance(W_Root, array[index]),
- cast_gcref_to_instance(W_Root, array[index + 1])])
+ unerase(array[index]),
+ unerase(array[index + 1])])
def W_STMDict___new__(space, w_subtype):
diff --git a/pypy/module/pypystm/stmset.py b/pypy/module/pypystm/stmset.py
--- a/pypy/module/pypystm/stmset.py
+++ b/pypy/module/pypystm/stmset.py
@@ -7,16 +7,16 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app
-from rpython.rlib import rstm, jit
+from rpython.rlib import rstm, jit, rerased
from rpython.rlib.rgc import ll_arraycopy
from rpython.rlib.objectmodel import specialize
-from rpython.rtyper.annlowlevel import cast_gcref_to_instance
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
from rpython.rtyper.lltypesystem import lltype, llmemory
ARRAY = lltype.GcArray(llmemory.GCREF)
PARRAY = lltype.Ptr(ARRAY)
+erase, unerase = rerased.new_erasing_pair("stmdictitem")
+
# XXX: should have identity-dict strategy
def really_find_equal_item(space, h, w_key):
@@ -58,7 +58,7 @@
def _find_equal_item(space, array, w_key):
# result by this function is based on 'array'. If the entry
# changes, the result is stale.
- w_item = cast_gcref_to_instance(W_Root, array[0])
+ w_item = unerase(array[0])
if space.eq_w(w_key, w_item):
return 0
if len(array) > 1:
@@ -71,7 +71,7 @@
i = 1
limit = len(array)
while True:
- w_item = cast_gcref_to_instance(W_Root, array[i])
+ w_item = unerase(array[i])
if space.eq_w(w_key, w_item):
return i
i += 1
@@ -102,7 +102,7 @@
narray = lltype.malloc(ARRAY, 1)
L = 0
- narray[L] = cast_instance_to_gcref(w_key)
+ narray[L] = erase(w_key)
self.h.writeobj(entry, lltype.cast_opaque_ptr(llmemory.GCREF, narray))
def try_remove(self, space, w_key):
@@ -143,7 +143,7 @@
subarray = lltype.cast_opaque_ptr(PARRAY, array[i].object)
assert subarray
for j in range(len(subarray)):
- w_item = cast_gcref_to_instance(W_Root, subarray[j])
+ w_item = unerase(subarray[j])
result_list_w.append(w_item)
return result_list_w
@@ -188,7 +188,7 @@
self.next_from_same_hash = index + 1
self.next_array = array
#
- return cast_gcref_to_instance(W_Root, array[index])
+ return unerase(array[index])
def _cleanup_(self):
raise Exception("seeing a prebuilt %r object" % (
diff --git a/rpython/rlib/rerased.py b/rpython/rlib/rerased.py
--- a/rpython/rlib/rerased.py
+++ b/rpython/rlib/rerased.py
@@ -128,6 +128,7 @@
# ---------- implementation-specific ----------
class Erased(object):
+ _TYPE = llmemory.GCREF
def __init__(self, x, identity):
self._x = x
self._identity = identity
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -394,7 +394,7 @@
def _live_items(self):
return [self.lookup(key) for key, v in self._content.items()
- if v.object != NULL_GCREF]
+ if v.object]
def len(self):
return len(self._live_items())
More information about the pypy-commit
mailing list