[pypy-svn] r68419 - in pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86: . test

fijal at codespeak.net fijal at codespeak.net
Wed Oct 14 10:14:58 CEST 2009


Author: fijal
Date: Wed Oct 14 10:14:57 2009
New Revision: 68419

Modified:
   pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/assembler.py
   pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/regalloc.py
   pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/test/test_gc_integration.py
Log:
Support for new_with_vtable


Modified: pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/assembler.py	Wed Oct 14 10:14:57 2009
@@ -523,7 +523,10 @@
         arglocs = arglocs[:-1]
         self.call(self.malloc_func_addr, arglocs, eax)
         # xxx ignore NULL returns for now
-        self.mc.MOV(mem(eax, self.cpu.vtable_offset), loc_vtable)
+        self.set_vtable(eax, loc_vtable)
+
+    def set_vtable(self, loc, loc_vtable):
+        self.mc.MOV(mem(loc, self.cpu.vtable_offset), loc_vtable)
 
     # XXX genop_new is abused for all varsized mallocs with Boehm, for now
     # (instead of genop_new_array, genop_newstr, genop_newunicode)

Modified: pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/regalloc.py	Wed Oct 14 10:14:57 2009
@@ -623,37 +623,46 @@
         self.PerformDiscard(op, arglocs)
         self.rm.possibly_free_vars(op.args)
 
+    def _fastpath_malloc(self, op, descr):
+        gc_ll_descr = self.assembler.cpu.gc_ll_descr
+        tmp0 = TempBox()
+        self.rm.force_allocate_reg(op.result, selected_reg=eax)
+        self.rm.force_allocate_reg(tmp0, selected_reg=edx)
+        for k, v in self.rm.reg_bindings.items():
+            if v is ecx:
+                push_reg = ecx
+                break
+        else:
+            push_reg = None
+        self.assembler.malloc_cond_fixedsize(
+            gc_ll_descr.get_nursery_free_addr(),
+            gc_ll_descr.get_nursery_top_addr(),
+            descr.size, descr.tid, push_reg,
+            gc_ll_descr.get_malloc_fixedsize_slowpath_addr(),
+            )
+        self.rm.possibly_free_var(tmp0)
+
     def consider_new(self, op, ignored):
         gc_ll_descr = self.assembler.cpu.gc_ll_descr
         if gc_ll_descr.can_inline_malloc(op.descr):
-            tmp0 = TempBox()
-            self.rm.force_allocate_reg(op.result, selected_reg=eax)
-            self.rm.force_allocate_reg(tmp0, selected_reg=edx)
-            for k, v in self.rm.reg_bindings.items():
-                if v is ecx:
-                    push_reg = ecx
-                    break
-            else:
-                push_reg = None
-            self.assembler.malloc_cond_fixedsize(
-                gc_ll_descr.get_nursery_free_addr(),
-                gc_ll_descr.get_nursery_top_addr(),
-                op.descr.size, op.descr.tid, push_reg,
-                gc_ll_descr.get_malloc_fixedsize_slowpath_addr(),
-                )
-            self.rm.possibly_free_var(tmp0)
-            return
-        args = gc_ll_descr.args_for_new(op.descr)
-        arglocs = [imm(x) for x in args]
-        return self._call(op, arglocs)
+            self._fastpath_malloc(op, op.descr)
+        else:
+            args = gc_ll_descr.args_for_new(op.descr)
+            arglocs = [imm(x) for x in args]
+            return self._call(op, arglocs)
 
     def consider_new_with_vtable(self, op, ignored):
         classint = op.args[0].getint()
         descrsize = self.assembler.cpu.class_sizes[classint]
-        args = self.assembler.cpu.gc_ll_descr.args_for_new(descrsize)
-        arglocs = [imm(x) for x in args]
-        arglocs.append(self.loc(op.args[0]))
-        return self._call(op, arglocs)
+        if self.assembler.cpu.gc_ll_descr.can_inline_malloc(descrsize):
+            self._fastpath_malloc(op, descrsize)
+            self.assembler.set_vtable(eax, imm(classint))
+            # result of fastpath malloc is in eax
+        else:
+            args = self.assembler.cpu.gc_ll_descr.args_for_new(descrsize)
+            arglocs = [imm(x) for x in args]
+            arglocs.append(self.loc(op.args[0]))
+            return self._call(op, arglocs)
 
     def consider_newstr(self, op, ignored):
         gc_ll_descr = self.assembler.cpu.gc_ll_descr

Modified: pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/test/test_gc_integration.py
==============================================================================
--- pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/test/test_gc_integration.py	(original)
+++ pypy/branch/inline-fastpath-malloc/pypy/jit/backend/x86/test/test_gc_integration.py	Wed Oct 14 10:14:57 2009
@@ -214,6 +214,7 @@
 
     def setup_method(self, method):
         cpu = CPU(None, None)
+        cpu.vtable_offset = 4
         cpu.gc_ll_descr = GCDescrFastpathMalloc()
 
         NODE = lltype.Struct('node', ('tid', lltype.Signed),
@@ -221,11 +222,19 @@
         nodedescr = cpu.sizeof(NODE)     # xxx hack: NODE is not a GcStruct
         valuedescr = cpu.fielddescrof(NODE, 'value')
 
-        self.namespace = locals().copy()
         self.cpu = cpu
         self.nodedescr = nodedescr
-        self.valuedescr = valuedescr
-    
+        vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
+        vtable_int = cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(vtable))
+        NODE2 = lltype.Struct('node2', ('tid', lltype.Signed),
+                                  ('vtable', lltype.Ptr(rclass.OBJECT_VTABLE)))
+        descrsize = cpu.sizeof(NODE2)
+        cpu.set_class_sizes({vtable_int: descrsize})
+        self.descrsize = descrsize
+        self.vtable_int = vtable_int
+
+        self.namespace = locals().copy()
+        
     def test_malloc_fastpath(self):
         ops = '''
         [i0]
@@ -260,3 +269,18 @@
         gc_ll_descr = self.cpu.gc_ll_descr
         nadr = rffi.cast(lltype.Signed, gc_ll_descr.nursery)
         assert gc_ll_descr.addrs[0] == nadr + 8
+
+    def test_new_with_vtable(self):
+        ops = '''
+        [i0, i1]
+        p0 = new_with_vtable(ConstClass(vtable))
+        guard_class(p0, ConstClass(vtable)) [i0]
+        finish(i1)
+        '''
+        self.interpret(ops, [0, 1])
+        assert self.getint(0) == 1
+        gc_ll_descr = self.cpu.gc_ll_descr
+        assert gc_ll_descr.nursery[0] == self.descrsize.tid
+        assert gc_ll_descr.nursery[1] == self.vtable_int
+        nurs_adr = rffi.cast(lltype.Signed, gc_ll_descr.nursery)
+        assert gc_ll_descr.addrs[0] == nurs_adr + 8



More information about the Pypy-commit mailing list