[pypy-svn] r65223 - pypy/branch/pyjitpl5/pypy/jit/backend/x86
arigo at codespeak.net
arigo at codespeak.net
Mon May 11 18:51:37 CEST 2009
Author: arigo
Date: Mon May 11 18:51:35 2009
New Revision: 65223
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py
Log:
Slight clean-up of the calls to malloc.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py Mon May 11 18:51:35 2009
@@ -12,7 +12,6 @@
arg_pos, lower_byte, stack_pos)
from pypy.rlib.objectmodel import we_are_translated, specialize, compute_unique_id
from pypy.jit.backend.x86 import codebuf
-from pypy.jit.backend.x86.support import gc_malloc_fnaddr
from pypy.jit.backend.x86.ri386 import *
from pypy.jit.metainterp.resoperation import rop
@@ -105,8 +104,7 @@
self._exception_data = lltype.nullptr(rffi.CArray(lltype.Signed))
self._exception_addr = 0
self.mcstack = MachineCodeStack()
- self.gc_malloc_fn = gc_malloc_fnaddr(cpu.gcdescr)
-
+
def _get_log(self):
s = os.environ.get('PYPYJITLOG')
if not s:
@@ -146,7 +144,8 @@
self.mc = self.mcstack.next_mc()
self.mc2 = self.mcstack.next_mc()
# the address of the function called by 'new'
- self.malloc_func_addr = rffi.cast(lltype.Signed, self.gc_malloc_fn)
+ self.malloc_func_addr = rffi.cast(lltype.Signed,
+ self.cpu.gc_malloc_fn)
def eventually_log_operations(self, inputargs, operations, memo=None,
myid=0):
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py Mon May 11 18:51:35 2009
@@ -17,8 +17,6 @@
from pypy.jit.backend.x86.support import gc_malloc_fnaddr
from pypy.rlib.objectmodel import r_dict
-GC_MALLOC = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
-
VOID = 0
PTR = 1
INT = 2
@@ -103,6 +101,7 @@
self._setup_prebuilt_error('ovf', OverflowError)
self._setup_prebuilt_error('zer', ZeroDivisionError)
self.generated_mps = r_dict(const_descr_eq, const_descr_hash)
+ self.gc_malloc_fn = gc_malloc_fnaddr(gcdescr)
def _setup_prebuilt_error(self, prefix, Class):
if self.rtyper is not None: # normal case
@@ -511,21 +510,22 @@
self._base_do_setfield(fielddescr, args[0].getint(), args[1])
def do_new(self, args, descrsize):
- res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(descrsize.v[0])
- return BoxPtr(self.cast_int_to_gcref(res))
+ res = self.gc_malloc_fn(descrsize.v[0])
+ return BoxPtr(self.cast_adr_to_gcref(res))
def do_new_with_vtable(self, args, descrsize):
- res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(descrsize.v[0])
+ res = self.gc_malloc_fn(descrsize.v[0])
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = args[0].getint()
- return BoxPtr(self.cast_int_to_gcref(res))
+ return BoxPtr(self.cast_adr_to_gcref(res))
def do_new_array(self, args, arraydescr):
size_of_field, ofs, ptr = self.unpack_arraydescr(arraydescr)
num_elem = args[0].getint()
size = ofs + (1 << size_of_field) * num_elem
- res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(size)
+ res = self.gc_malloc_fn(size)
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = num_elem
- return BoxPtr(self.cast_int_to_gcref(res))
+ # XXX don't use 0 above!
+ return BoxPtr(self.cast_adr_to_gcref(res))
def _new_do_newstr(TP):
def do_newstr(self, args, descr=0):
@@ -533,9 +533,9 @@
self.translate_support_code)
num_elem = args[0].getint()
size = basesize + num_elem * itemsize
- res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(size)
+ res = self.gc_malloc_fn(size)
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
- return BoxPtr(self.cast_int_to_gcref(res))
+ return BoxPtr(self.cast_adr_to_gcref(res))
return do_newstr
do_newstr = _new_do_newstr(rstr.STR)
do_newunicode = _new_do_newstr(rstr.UNICODE)
@@ -663,7 +663,13 @@
return rffi.cast(lltype.Signed, x)
def cast_int_to_gcref(self, x):
- assert x == 0 or x > (1<<20) or x < (-1<<20)
+ if not we_are_translated():
+ assert x == 0 or x > (1<<20) or x < (-1<<20)
+ return rffi.cast(llmemory.GCREF, x)
+
+ def cast_adr_to_gcref(self, x):
+ if not we_are_translated():
+ assert x == 0 or x > (1<<20) or x < (-1<<20)
return rffi.cast(llmemory.GCREF, x)
def uhex(x):
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py Mon May 11 18:51:35 2009
@@ -1,8 +1,6 @@
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
from pypy.translator.tool.cbuild import ExternalCompilationInfo
-GC_MALLOC = lltype.Ptr(lltype.FuncType([lltype.Signed], llmemory.Address))
-
def gc_malloc__boehm(gcdescr):
"""Returns a pointer to the Boehm 'malloc' function."""
@@ -23,7 +21,10 @@
def gc_malloc_fnaddr(gcdescr):
"""Returns a pointer to the proper 'malloc' function."""
- name = gcdescr.config.translation.gctransformer
+ if gcdescr is not None:
+ name = gcdescr.config.translation.gctransformer
+ else:
+ name = "boehm"
try:
func = globals()['gc_malloc__' + name]
except KeyError:
More information about the Pypy-commit
mailing list