Commits

Armin Rigo committed 5467c01

- choose an arbitrary upper limit, and beyond it, generate a regular
malloc_array even if the length is constant

- fix boehm translation

  • Participants
  • Parent commits 3ab2729
  • Branches op_malloc_gc

Comments (0)

Files changed (3)

pypy/jit/backend/llsupport/gc.py

 class GcLLDescr_boehm(GcLLDescription):
     kind                  = 'boehm'
     moving_gc             = False
+    round_up              = False
     gcrootmap             = None
     write_barrier_descr   = None
     fielddescr_tid        = None
 class GcLLDescr_framework(GcLLDescription):
     DEBUG = False    # forced to True by x86/test/test_zrpy_gc.py
     kind = 'framework'
+    round_up = True
 
     def __init__(self, gcdescr, translator, rtyper, llop1=llop,
                  really_not_translated=False):

pypy/jit/backend/llsupport/rewrite.py

                 pass    # total_size is still -1
         elif arraydescr.itemsize == 0:
             total_size = arraydescr.basesize
-        if total_size >= 0:
+        if 0 <= total_size <= 0xffffff:     # up to 16MB, arbitrarily
             self.gen_malloc_nursery(total_size, op.result)
             self.gen_initialize_tid(op.result, arraydescr.tid)
             self.gen_initialize_len(op.result, v_length, arraydescr.lendescr)
         """Try to generate or update a CALL_MALLOC_NURSERY.
         If that fails, generate a plain CALL_MALLOC_GC instead.
         """
-        if size <= (sys.maxint & ~(WORD-1)):
-            size = self.round_up_for_allocation(size)
-        else:
-            size = sys.maxint  #corner case: generate a malloc that always fail
-        #
+        size = self.round_up_for_allocation(size)
         if not self.gc_ll_descr.can_use_nursery_malloc(size):
             self.gen_malloc_fixedsize(size, v_result)
             return
         self.gen_write_barrier(v_base, v_value)
 
     def round_up_for_allocation(self, size):
+        if not self.gc_ll_descr.round_up:
+            return size
         if self.gc_ll_descr.translate_support_code:
             from pypy.rpython.lltypesystem import llarena
             return llarena.round_up_for_allocation(

pypy/jit/backend/llsupport/test/test_rewrite.py

             jump()
         """, """
             [p1]
-            p0 = call_malloc_gc(ConstClass(malloc_fixedsize), 104, \
+            p0 = call_malloc_gc(ConstClass(malloc_fixedsize), 102, \
                                 descr=malloc_fixedsize_descr)
             setfield_gc(p0, ConstClass(o_vtable), descr=vtable_descr)
             jump()
             jump()
         """)
 
+    def test_rewrite_assembler_huge_size(self):
+        # "huge" is defined as "larger than 0xffffff bytes, or 16MB"
+        self.check_rewrite("""
+            []
+            p0 = new_array(20000000, descr=bdescr)
+            jump()
+        """, """
+            []
+            p0 = call_malloc_gc(ConstClass(malloc_array), 1, \
+                                %(bdescr.tid)d, 20000000,    \
+                                descr=malloc_array_descr)
+            jump()
+        """)
+
     def test_new_with_vtable(self):
         self.check_rewrite("""
             []