Commits

Remi Meier  committed a855f87

stm: add get_contention() to app-level list (implemented only for IntegerListStrategy)

  • Participants
  • Parent commits 8ff2c3b
  • Branches stm-logging

Comments (0)

Files changed (2)

File pypy/objspace/std/listobject.py

 
 
 ############################################# ABORT CALLBACK
-
+AUTO_CHANGE_LIST_STRATEGY = False
 class ListOps:
     (GET_ITEM, SET_ITEM,
      APPEND) = range(3)
-    
+
 from pypy.rlib import rstm
 from pypy.rlib import rgc
 
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rpython.lltypesystem.lltype import (GcStruct, Signed,
-                                              Ptr, GcArray)
+                                              Ptr, GcArray, Float)
 from pypy.rpython.lltypesystem import rffi
-ITEMARRAY = GcArray(Signed)
+ITEMARRAY_SIGNED = GcArray(Signed)
+ITEMARRAY_FLOAT = GcArray(Float)
 INT_LIST = GcStruct("list", ("length", Signed),
-                    ("items", Ptr(ITEMARRAY)))
-erase_d, unerase_d = rerased.new_erasing_pair("data")
+                    ("items", Ptr(ITEMARRAY_SIGNED)))
+FLOAT_LIST = GcStruct("list", ("length", Signed),
+                      ("items", Ptr(ITEMARRAY_FLOAT)))
+
+erase_db, unerase_db = rerased.new_erasing_pair("data")
 def abort_callback(llobj, op):
     obj = rgc.try_cast_gcref_to_instance(W_ListObject, llobj)
     if obj is None:
             l = IntegerListStrategy.unerase(obj.lstorage)
             l_ref = rgc.cast_instance_to_gcref(l)
             lstruct = rffi.cast(Ptr(INT_LIST), l_ref)
-            contention += rstm.get_contention(erase_d(lstruct.items))
+            contention += rstm.get_contention(erase_db(lstruct.items))
 
         print op, obj, obj.strategy, contention
-        if op in (ListOps.GET_ITEM, ListOps.SET_ITEM) \
+        if AUTO_CHANGE_LIST_STRATEGY \
+          and op in (ListOps.GET_ITEM, ListOps.SET_ITEM) \
           and not isinstance(obj.strategy, IndirectObjectListStrategy) \
           and contention > 40000:
             print "Contention too high, switch to indirect object list strategy"
         argument reverse. Argument must be unwrapped."""
         self.strategy.sort(self, reverse)
 
+    def get_contention(self):
+        return self.strategy.get_contention(self)
+
 registerimplementation(W_ListObject)
 
 
     def is_empty_strategy(self):
         return False
 
+    def get_contention(self, w_list):
+        return 0
+
 
 class EmptyListStrategy(ListStrategy):
     """EmptyListStrategy is used when a W_List withouth elements is created.
     def getitems_int(self, w_list):
         return self.unerase(w_list.lstorage)
 
+    erase_d, unerase_d = rerased.new_erasing_pair("int_data")
+    erase_d = staticmethod(erase_d)
+    unerase_d = staticmethod(unerase_d)
+    def get_contention(self, w_list):
+        contention = 0
+        if we_are_translated():
+            contention = rstm.get_contention(w_list.lstorage)
+
+            l = self.unerase(w_list.lstorage)
+            l_ref = rgc.cast_instance_to_gcref(l)
+            lstruct = rffi.cast(Ptr(INT_LIST), l_ref)
+            contention = rstm.get_contention(self.erase_d(lstruct.items))
+        return contention
+
 class FloatListStrategy(AbstractUnwrappedStrategy, ListStrategy):
     _none_value = 0.0
     _applevel_repr = "float"
         if reverse:
             l.reverse()
 
+
 class StringListStrategy(AbstractUnwrappedStrategy, ListStrategy):
     _none_value = None
     _applevel_repr = "str"
     w_list.reverse()
     return space.w_None
 
+def list_get_contention__List(space, w_list):
+    result = w_list.get_contention()
+    return wrapint(space, result)
+
+
 # ____________________________________________________________
 # Sorting
 

File pypy/objspace/std/listtype.py

 from pypy.objspace.std.register_all import register_all
 from sys import maxint
 
+list_get_contention = SMM('get_contention', 1, doc='get contention of obj')
 list_append   = SMM('append', 2,
                     doc='L.append(object) -- append object to end')
 list_insert   = SMM('insert', 3,