Author: Remi Meier <[email protected]>
Branch: stmgc-c8-gcc
Changeset: r79657:12865f558081
Date: 2015-09-16 15:43 +0200
http://bitbucket.org/pypy/pypy/changeset/12865f558081/
Log: wip: making mapdict_cache a noconflict object
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -9,7 +9,7 @@
BaseValueIterator, BaseItemIterator, _never_equal_to_string
)
from pypy.objspace.std.typeobject import MutableCell
-
+from rpython.rlib.objectmodel import we_are_translated
# ____________________________________________________________
# attribute shapes
@@ -843,16 +843,32 @@
INVALID_CACHE_ENTRY.map_wref = weakref.ref(_invalid_cache_entry_map)
# different from any real map ^^^
+from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper import annlowlevel
+MAPDICT_CACHE = lltype.GcArray(llmemory.GCREF)
+PMAPDICT_CACHE = lltype.Ptr(MAPDICT_CACHE)
+NULL_MAPDICTCACHE = lltype.nullptr(MAPDICT_CACHE)
+
+
def init_mapdict_cache(pycode):
num_entries = len(pycode.co_names_w)
- pycode._mapdict_caches = [INVALID_CACHE_ENTRY] * num_entries
+ # pycode._mapdict_caches = [INVALID_CACHE_ENTRY] * num_entries
+ if pycode.space.config.translation.stm:
+ from rpython.rlib.rstm import allocate_noconflict
+ pycode._mapdict_caches = allocate_noconflict(MAPDICT_CACHE,
num_entries)
+ else:
+ pycode._mapdict_caches = lltype.malloc(MAPDICT_CACHE, num_entries)
+ #
+ for i in range(num_entries):
+ pycode._mapdict_caches[i] =
annlowlevel.cast_instance_to_gcref(INVALID_CACHE_ENTRY)
+
@jit.dont_look_inside
def _fill_cache(pycode, nameindex, map, version_tag, storageindex,
w_method=None):
- entry = pycode._mapdict_caches[nameindex]
+ entry = annlowlevel.cast_gcref_to_instance(CacheEntry,
pycode._mapdict_caches[nameindex])
if entry is INVALID_CACHE_ENTRY:
entry = CacheEntry()
- pycode._mapdict_caches[nameindex] = entry
+ pycode._mapdict_caches[nameindex] =
annlowlevel.cast_instance_to_gcref(entry)
entry.map_wref = weakref.ref(map)
entry.version_tag = version_tag
entry.storageindex = storageindex
@@ -863,7 +879,7 @@
def LOAD_ATTR_caching(pycode, w_obj, nameindex):
# this whole mess is to make the interpreter quite a bit faster; it's not
# used if we_are_jitted().
- entry = pycode._mapdict_caches[nameindex]
+ entry = annlowlevel.cast_gcref_to_instance(CacheEntry,
pycode._mapdict_caches[nameindex])
map = w_obj._get_mapdict_map()
if entry.is_valid_for_map(map) and entry.w_method is None:
# everything matches, it's incredibly fast
@@ -920,7 +936,7 @@
def LOOKUP_METHOD_mapdict(f, nameindex, w_obj):
pycode = f.getcode()
- entry = pycode._mapdict_caches[nameindex]
+ entry = annlowlevel.cast_gcref_to_instance(CacheEntry,
pycode._mapdict_caches[nameindex])
if entry.is_valid_for_obj(w_obj):
w_method = entry.w_method
if w_method is not None:
diff --git a/pypy/objspace/std/test/test_mapdict.py
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -719,7 +719,7 @@
def check(space, w_func, name):
w_code = space.getattr(w_func, space.wrap('func_code'))
nameindex = map(space.str_w, w_code.co_names_w).index(name)
- entry = w_code._mapdict_caches[nameindex]
+ entry = annlowlevel.cast_gcref_to_instance(CacheEntry,
w_code._mapdict_caches[nameindex])
entry.failure_counter = 0
entry.success_counter = 0
INVALID_CACHE_ENTRY.failure_counter = 0
@@ -727,7 +727,7 @@
w_res = space.call_function(w_func)
assert space.eq_w(w_res, space.wrap(42))
#
- entry = w_code._mapdict_caches[nameindex]
+ entry = annlowlevel.cast_gcref_to_instance(CacheEntry,
w_code._mapdict_caches[nameindex])
if entry is INVALID_CACHE_ENTRY:
failures = successes = 0
else:
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -189,11 +189,15 @@
size = llmemory.sizeof(TP.TO)
return llop.stm_allocate_preexisting(TP, size, p)
+@dont_look_inside
@specialize.ll()
def allocate_noconflict(GCTYPE, n=None):
"""Return a new instance of GCTYPE that never generates conflicts when
reading or writing to it. However, modifications may get lost
and are not guaranteed to propagate."""
+ if not we_are_translated(): # for tests
+ return lltype.malloc(GCTYPE, n=n)
+ #
if n is None:
return llop.stm_malloc_noconflict(lltype.Ptr(GCTYPE))
else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit