[pypy-commit] pypy stmgc-c7: _ll_hashtable_list

arigo noreply at buildbot.pypy.org
Sun Feb 1 11:21:28 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r75620:dce2ea23c327
Date: 2015-02-01 11:21 +0100
http://bitbucket.org/pypy/pypy/changeset/dce2ea23c327/

Log:	_ll_hashtable_list

diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -1,5 +1,6 @@
 from rpython.rlib.objectmodel import we_are_translated, specialize
 from rpython.rlib.objectmodel import CDefinedIntSymbolic, stm_ignored
+from rpython.rlib.rarithmetic import r_uint
 from rpython.rlib.nonconst import NonConstant
 from rpython.rlib import rgc
 from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory
@@ -199,6 +200,20 @@
                                    lltype.nullptr(_STM_HASHTABLE_ENTRY_ARRAY))
 
 @dont_look_inside
+def _ll_hashtable_list(h):
+    upper_bound = llop.stm_hashtable_length_upper_bound(lltype.Signed,
+                                                        h.ll_raw_hashtable)
+    array = lltype.malloc(_STM_HASHTABLE_ENTRY_ARRAY, upper_bound,
+                          flavor='raw')
+    count = llop.stm_hashtable_list(lltype.Signed, h, h.ll_raw_hashtable,
+                                    array)
+    return (array, count)
+
+ at dont_look_inside
+def _ll_hashtable_freelist(h, array):
+    lltype.free(array, flavor='raw')
+
+ at dont_look_inside
 def _ll_hashtable_lookup(h, key):
     return llop.stm_hashtable_lookup(_STM_HASHTABLE_ENTRY_P,
                                      h, h.ll_raw_hashtable, key)
@@ -209,6 +224,8 @@
                                  adtmeths={'get': _ll_hashtable_get,
                                            'set': _ll_hashtable_set,
                                            'len': _ll_hashtable_len,
+                                          'list': _ll_hashtable_list,
+                                      'freelist': _ll_hashtable_freelist,
                                         'lookup': _ll_hashtable_lookup})
 NULL_HASHTABLE = lltype.nullptr(_HASHTABLE_OBJ)
 
@@ -272,6 +289,16 @@
     def len(self):
         return len(self._content)
 
+    def list(self):
+        items = [self.lookup(key) for key in self._content]
+        count = len(items)
+        for i in range(3):
+            items.append("additional garbage for testing")
+        return items, count
+
+    def freelist(self, array):
+        pass
+
     def lookup(self, key):
         assert type(key) is int
         return EntryObjectForTest(self, key)
@@ -280,6 +307,7 @@
     def __init__(self, hashtable, key):
         self.hashtable = hashtable
         self.key = key
+        self.index = r_uint(key)
 
     def _getobj(self):
         return self.hashtable.get(self.key)
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
@@ -465,6 +465,7 @@
     'stm_hashtable_read':     LLOp(),
     'stm_hashtable_write':    LLOp(),
     'stm_hashtable_lookup':   LLOp(),
+    'stm_hashtable_length_upper_bound': LLOp(),
     'stm_hashtable_list'  :   LLOp(),
     'stm_hashtable_tracefn':  LLOp(),
 
diff --git a/rpython/translator/stm/funcgen.py b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -320,6 +320,12 @@
     return '%s = stm_hashtable_lookup((object_t *)%s, %s, %s);' % (
         result, arg0, arg1, arg2)
 
+def stm_hashtable_length_upper_bound(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    result = funcgen.expr(op.result)
+    return '%s = stm_hashtable_length_upper_bound(%s);' % (
+        result, arg0)
+
 def stm_hashtable_list(funcgen, op):
     arg0 = funcgen.expr(op.args[0])
     arg1 = funcgen.expr(op.args[1])
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -1,6 +1,7 @@
 import py
 from rpython.rlib import rstm, rgc, objectmodel
 from rpython.rlib.debug import debug_print
+from rpython.rlib.rarithmetic import intmask
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rtyper.rclass import OBJECTPTR
@@ -583,6 +584,12 @@
             assert cast_gcref_to_instance(X, entry.object) is None
             assert h.len() == 1
             #
+            array, count = h.list()
+            assert count == 1
+            assert intmask(array[0].index) == -1234
+            assert cast_gcref_to_instance(X, array[0].object) is x1
+            h.freelist(array)
+            #
             print "ok!"
             return 0
 


More information about the pypy-commit mailing list