Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: 
Changeset: r70144:a4dca0f2cdfe
Date: 2014-03-21 12:19 +0200
http://bitbucket.org/pypy/pypy/changeset/a4dca0f2cdfe/

Log:    merge

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -440,11 +440,10 @@
 
         return name
 
-    def getbuiltinmodule(self, name, force_init=False, reuse=True):
+    def getbuiltinmodule(self, name, force_init=False):
         w_name = self.wrap(name)
         w_modules = self.sys.get('modules')
         if not force_init:
-            assert reuse is True
             try:
                 return self.getitem(w_modules, w_name)
             except OperationError, e:
@@ -463,15 +462,7 @@
             # Initialize the module
             from pypy.interpreter.module import Module
             if isinstance(w_mod, Module):
-                if not reuse and w_mod.startup_called:
-                    # Create a copy of the module
-                    w_mod.getdict(self)  # unlazy w_initialdict
-                    w_new = self.wrap(Module(self, w_name))
-                    self.call_method(w_new.getdict(self), 'update',
-                                     w_mod.w_initialdict)
-                    w_mod = w_new
-                else:
-                    w_mod.init(self)
+                w_mod.init(self)
 
             # Add the module to sys.modules
             self.setitem(w_modules, w_name, w_mod)
diff --git a/pypy/module/_io/__init__.py b/pypy/module/_io/__init__.py
--- a/pypy/module/_io/__init__.py
+++ b/pypy/module/_io/__init__.py
@@ -8,6 +8,8 @@
     interpleveldefs = {
         'DEFAULT_BUFFER_SIZE': 'space.wrap(interp_iobase.DEFAULT_BUFFER_SIZE)',
         'BlockingIOError': 'interp_io.W_BlockingIOError',
+        'UnsupportedOperation':
+            'space.fromcache(interp_io.Cache).w_unsupportedoperation',
         '_IOBase': 'interp_iobase.W_IOBase',
         '_RawIOBase': 'interp_iobase.W_RawIOBase',
         '_BufferedIOBase': 'interp_bufferedio.W_BufferedIOBase',
@@ -26,16 +28,6 @@
         'IncrementalNewlineDecoder': 
'interp_textio.W_IncrementalNewlineDecoder',
     }
 
-    def init(self, space):
-        MixedModule.init(self, space)
-        w_UnsupportedOperation = space.call_function(
-            space.w_type,
-            space.wrap('UnsupportedOperation'),
-            space.newtuple([space.w_ValueError, space.w_IOError]),
-            space.newdict())
-        space.setattr(self, space.wrap('UnsupportedOperation'),
-                      w_UnsupportedOperation)
-
     def shutdown(self, space):
         # at shutdown, flush all open streams.  Ignore I/O errors.
         from pypy.module._io.interp_iobase import get_autoflusher
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -10,6 +10,12 @@
 from rpython.rtyper.module.ll_os_stat import STAT_FIELD_TYPES
 
 
+class Cache:
+    def __init__(self, space):
+        self.w_unsupportedoperation = space.new_exception_class(
+            "io.UnsupportedOperation",
+            space.newtuple([space.w_ValueError, space.w_IOError]))
+
 class W_BlockingIOError(W_IOError):
     def __init__(self, space):
         W_IOError.__init__(self, space)
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -579,8 +579,7 @@
         return space.call_method(find_info.w_loader, "load_module", 
w_modulename)
 
     if find_info.modtype == C_BUILTIN:
-        return space.getbuiltinmodule(find_info.filename, force_init=True,
-                                      reuse=reuse)
+        return space.getbuiltinmodule(find_info.filename, force_init=True)
 
     if find_info.modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION, 
PKG_DIRECTORY):
         w_mod = None
diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -203,6 +203,7 @@
 
     def test_builtin_reimport(self):
         # from https://bugs.pypy.org/issue1514
+        skip("fix me")
         import sys, marshal
 
         old = marshal.loads
@@ -222,6 +223,7 @@
         # taken from https://bugs.pypy.org/issue1514, with extra cases
         # that show a difference with CPython: we can get on CPython
         # several module objects for the same built-in module :-(
+        skip("several built-in module objects: not supported by pypy")
         import sys, marshal
 
         old = marshal.loads
diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -578,6 +578,7 @@
         assert hasattr(time, 'clock')
 
     def test_reimport_builtin_simple_case_2(self):
+        skip("fix me")
         import sys, time
         time.foo = "bar"
         del sys.modules['time']
@@ -585,6 +586,7 @@
         assert not hasattr(time, 'foo')
 
     def test_reimport_builtin(self):
+        skip("fix me")
         import sys, time
         oldpath = sys.path
         time.tzset = "<test_reimport_builtin removed this>"
diff --git a/rpython/jit/backend/arm/opassembler.py 
b/rpython/jit/backend/arm/opassembler.py
--- a/rpython/jit/backend/arm/opassembler.py
+++ b/rpython/jit/backend/arm/opassembler.py
@@ -583,6 +583,10 @@
     emit_op_getfield_raw_pure = emit_op_getfield_gc
     emit_op_getfield_gc_pure = emit_op_getfield_gc
 
+    def emit_op_increment_debug_counter(self, op, arglocs, regalloc, fcond):
+        # XXX implement me
+        return fcond
+
     def emit_op_getinteriorfield_gc(self, op, arglocs, regalloc, fcond):
         (base_loc, index_loc, res_loc,
             ofs_loc, ofs, itemsize, fieldsize) = arglocs
diff --git a/rpython/jit/backend/arm/regalloc.py 
b/rpython/jit/backend/arm/regalloc.py
--- a/rpython/jit/backend/arm/regalloc.py
+++ b/rpython/jit/backend/arm/regalloc.py
@@ -849,6 +849,10 @@
     prepare_op_getfield_raw_pure = prepare_op_getfield_gc
     prepare_op_getfield_gc_pure = prepare_op_getfield_gc
 
+    def prepare_op_increment_debug_counter(self, op, fcond):
+        # XXX implement me
+        return []
+
     def prepare_op_getinteriorfield_gc(self, op, fcond):
         t = unpack_interiorfielddescr(op.getdescr())
         ofs, itemsize, fieldsize, sign = t
diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -553,6 +553,10 @@
         else:
             return self.bh_raw_load_i(struct, offset, descr)
 
+    def bh_increment_debug_counter(self, addr):
+        p = rffi.cast(rffi.CArrayPtr(lltype.Signed), addr)
+        p[0] += 1
+
     def unpack_arraydescr_size(self, arraydescr):
         from rpython.jit.backend.llsupport.symbolic import get_array_token
         from rpython.jit.backend.llsupport.descr import get_type_flag, 
FLAG_SIGNED
diff --git a/rpython/jit/backend/llsupport/assembler.py 
b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -15,7 +15,7 @@
 
 DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER',
     # 'b'ridge, 'l'abel or # 'e'ntry point
-    ('i', lltype.Signed),
+    ('i', lltype.Signed),      # first field, at offset 0
     ('type', lltype.Char),
     ('number', lltype.Signed)
 )
@@ -64,7 +64,6 @@
         self.cpu = cpu
         self.memcpy_addr = 0
         self.rtyper = cpu.rtyper
-        self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i')
         self._debug = False
 
     def setup_once(self):
@@ -265,14 +264,8 @@
     def _append_debugging_code(self, operations, tp, number, token):
         counter = self._register_counter(tp, number, token)
         c_adr = ConstInt(rffi.cast(lltype.Signed, counter))
-        box = BoxInt()
-        box2 = BoxInt()
-        ops = [ResOperation(rop.GETFIELD_RAW, [c_adr],
-                            box, descr=self.debug_counter_descr),
-               ResOperation(rop.INT_ADD, [box, ConstInt(1)], box2),
-               ResOperation(rop.SETFIELD_RAW, [c_adr, box2],
-                            None, descr=self.debug_counter_descr)]
-        operations.extend(ops)
+        operations.append(
+            ResOperation(rop.INCREMENT_DEBUG_COUNTER, [c_adr], None))
 
     def _register_counter(self, tp, number, token):
         # YYY very minor leak -- we need the counters to stay alive
diff --git a/rpython/jit/backend/test/runner_test.py 
b/rpython/jit/backend/test/runner_test.py
--- a/rpython/jit/backend/test/runner_test.py
+++ b/rpython/jit/backend/test/runner_test.py
@@ -4338,3 +4338,12 @@
         assert rffi.cast(lltype.Signed, a[0]) == -7654
         assert rffi.cast(lltype.Signed, a[1]) == 777
         lltype.free(a, flavor='raw')
+
+    def test_increment_debug_counter(self):
+        foo = lltype.malloc(rffi.CArray(lltype.Signed), 1, flavor='raw')
+        foo[0] = 1789200
+        self.execute_operation(rop.INCREMENT_DEBUG_COUNTER,
+                               [ConstInt(rffi.cast(lltype.Signed, foo))],
+                               'void')
+        assert foo[0] == 1789201
+        lltype.free(foo, flavor='raw')
diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -434,8 +434,8 @@
             self.wb_slowpath[withcards + 2 * withfloats] = rawstart
 
     @rgc.no_release_gil
-    def assemble_loop(self, logger, loopname, inputargs, operations, looptoken,
-                      log):
+    def assemble_loop(self, inputargs, operations, looptoken, log,
+                      loopname, logger):
         '''adds the following attributes to looptoken:
                _ll_function_addr    (address of the generated func, as an int)
                _ll_loop_code       (debug: addr of the start of the ResOps)
@@ -514,8 +514,8 @@
                        size_excluding_failure_stuff - looppos)
 
     @rgc.no_release_gil
-    def assemble_bridge(self, logger, faildescr, inputargs, operations,
-                        original_loop_token, log):
+    def assemble_bridge(self, faildescr, inputargs, operations,
+                        original_loop_token, log, logger):
         if not we_are_translated():
             # Arguments should be unique
             assert len(set(inputargs)) == len(inputargs)
@@ -1469,6 +1469,14 @@
                                                 ofs_loc)
         self.load_from_mem(resloc, src_addr, fieldsize_loc, sign_loc)
 
+    def genop_discard_increment_debug_counter(self, op, arglocs):
+        # The argument should be an immediate address.  This should
+        # generate code equivalent to a GETFIELD_RAW, an ADD(1), and a
+        # SETFIELD_RAW.  Here we use the direct from-memory-to-memory
+        # increment operation of x86.
+        base_loc, = arglocs
+        self.mc.INC(mem(base_loc, 0))
+
     def genop_discard_setfield_gc(self, op, arglocs):
         base_loc, ofs_loc, size_loc, value_loc = arglocs
         assert isinstance(size_loc, ImmedLoc)
diff --git a/rpython/jit/backend/x86/regalloc.py 
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -1003,6 +1003,10 @@
     consider_getfield_raw_pure = consider_getfield_gc
     consider_getfield_gc_pure = consider_getfield_gc
 
+    def consider_increment_debug_counter(self, op):
+        base_loc = self.loc(op.getarg(0))
+        self.perform_discard(op, [base_loc])
+
     def consider_getarrayitem_gc(self, op):
         itemsize, ofs, sign = unpack_arraydescr(op.getdescr())
         args = op.getarglist()
diff --git a/rpython/jit/backend/x86/regloc.py 
b/rpython/jit/backend/x86/regloc.py
--- a/rpython/jit/backend/x86/regloc.py
+++ b/rpython/jit/backend/x86/regloc.py
@@ -488,12 +488,22 @@
             for possible_code in unrolling_location_codes:
                 if code == possible_code:
                     val = getattr(loc, "value_" + possible_code)()
-                    if self.WORD == 8 and possible_code == 'i' and not 
rx86.fits_in_32bits(val):
-                        self._load_scratch(val)
+                    # Faking out of certain operations for x86_64
+                    fits32 = rx86.fits_in_32bits
+                    if possible_code == 'i' and not fits32(val):
+                        self._load_scratch(val)    # for 'PUSH(imm)'
                         _rx86_getattr(self, name + 
"_r")(X86_64_SCRATCH_REG.value)
-                    else:
-                        methname = name + "_" + possible_code
-                        _rx86_getattr(self, methname)(val)
+                        return
+                    if possible_code == 'j' and not fits32(val):
+                        val = self._addr_as_reg_offset(val)
+                        _rx86_getattr(self, name + "_m")(val)
+                        return
+                    if possible_code == 'm' and not fits32(val[1]):
+                        val = self._fix_static_offset_64_m(val)
+                    if possible_code == 'a' and not fits32(val[3]):
+                        val = self._fix_static_offset_64_a(val)
+                    methname = name + "_" + possible_code
+                    _rx86_getattr(self, methname)(val)
 
         return func_with_new_name(INSN, "INSN_" + name)
 
@@ -600,6 +610,7 @@
     TEST8 = _binaryop('TEST8')
     BTS = _binaryop('BTS')
 
+    INC = _unaryop('INC')
     ADD = _binaryop('ADD')
     SUB = _binaryop('SUB')
     IMUL = _binaryop('IMUL')
diff --git a/rpython/jit/backend/x86/runner.py 
b/rpython/jit/backend/x86/runner.py
--- a/rpython/jit/backend/x86/runner.py
+++ b/rpython/jit/backend/x86/runner.py
@@ -93,16 +93,15 @@
 
     def compile_loop(self, inputargs, operations, looptoken, log=True,
                      name='', logger=None):
-        return self.assembler.assemble_loop(logger, name, inputargs, 
operations,
-                                            looptoken, log=log)
+        return self.assembler.assemble_loop(inputargs, operations, looptoken, 
log,
+                                            name, logger)
 
     def compile_bridge(self, faildescr, inputargs, operations,
                        original_loop_token, log=True, logger=None):
         clt = original_loop_token.compiled_loop_token
         clt.compiling_a_bridge()
-        return self.assembler.assemble_bridge(logger, faildescr, inputargs,
-                                              operations,
-                                              original_loop_token, log=log)
+        return self.assembler.assemble_bridge(faildescr, inputargs, operations,
+                                              original_loop_token, log, logger)
 
     def clear_latest_values(self, count):
         setitem = self.assembler.fail_boxes_ptr.setitem
diff --git a/rpython/jit/backend/x86/rx86.py b/rpython/jit/backend/x86/rx86.py
--- a/rpython/jit/backend/x86/rx86.py
+++ b/rpython/jit/backend/x86/rx86.py
@@ -470,6 +470,9 @@
 
     # ------------------------------ Arithmetic ------------------------------
 
+    INC_m = insn(rex_w, '\xFF', orbyte(0), mem_reg_plus_const(1))
+    INC_j = insn(rex_w, '\xFF', orbyte(0), abs_(1))
+
     ADD_ri,ADD_rr,ADD_rb,_,_,ADD_rm,ADD_rj,_,_ = common_modes(0)
     OR_ri, OR_rr, OR_rb, _,_,OR_rm, OR_rj, _,_ = common_modes(1)
     AND_ri,AND_rr,AND_rb,_,_,AND_rm,AND_rj,_,_ = common_modes(4)
diff --git a/rpython/jit/backend/x86/test/test_regloc.py 
b/rpython/jit/backend/x86/test/test_regloc.py
--- a/rpython/jit/backend/x86/test/test_regloc.py
+++ b/rpython/jit/backend/x86/test/test_regloc.py
@@ -373,3 +373,56 @@
                 '\x59'
         )
         assert cb.getvalue() == expected_instructions
+
+    # ------------------------------------------------------------
+
+    def test_push_immed64(self):
+        immed = 0x0123456789ABCDEF
+        cb = LocationCodeBuilder64()
+        cb.PUSH(imm(immed))
+        #
+        expected_instructions = (
+                # mov r11, 0x0123456789ABCDEF
+                '\x49\xBB\xEF\xCD\xAB\x89\x67\x45\x23\x01'
+                # push r11
+                '\x41\x53'
+        )
+        assert cb.getvalue() == expected_instructions
+
+    def test_inc_64bit_address_1(self):
+        base_addr = 0x0123456789ABCDEF
+        cb = LocationCodeBuilder64()
+        cb.INC(AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr))
+        # this case is a INC_j
+        #
+        expected_instructions = (
+                # mov r11, 0x0123456789ABCDEF
+                '\x49\xBB\xEF\xCD\xAB\x89\x67\x45\x23\x01'
+                # inc [r11]
+                '\x49\xFF\x03'
+        )
+        assert cb.getvalue() == expected_instructions
+
+    def test_inc_64bit_address_2(self):
+        py.test.skip("there is no unary instruction INSN_a so far")
+        base_addr = 0x0123456789ABCDEF
+        cb = LocationCodeBuilder64()
+        cb.INC(AddressLoc(ImmedLoc(0), edx, 3, base_addr))
+        # this case would be a INC_a
+        xxx
+
+    def test_inc_64bit_address_3(self):
+        base_addr = 0x0123456789ABCDEF
+        cb = LocationCodeBuilder64()
+        cb.INC(AddressLoc(eax, ImmedLoc(0), 0, base_addr))
+        # this case is a INC_m
+        #
+        expected_instructions = (
+                # mov r11, 0x0123456789ABCDEF
+                '\x49\xBB\xEF\xCD\xAB\x89\x67\x45\x23\x01'
+                # lea r11, [rax+r11]
+                '\x4E\x8D\x1C\x18'
+                # inc [r11]
+                '\x49\xFF\x03'
+        )
+        assert cb.getvalue() == expected_instructions
diff --git a/rpython/jit/backend/x86/test/test_runner.py 
b/rpython/jit/backend/x86/test/test_runner.py
--- a/rpython/jit/backend/x86/test/test_runner.py
+++ b/rpython/jit/backend/x86/test/test_runner.py
@@ -427,8 +427,8 @@
         debug._log = None
         #
         assert ops_offset is looptoken._x86_ops_offset
-        # 2*(getfield_raw/int_add/setfield_raw) + ops + None
-        assert len(ops_offset) == 2*3 + len(operations) + 1
+        # 2*increment_debug_counter + ops + None
+        assert len(ops_offset) == 2 + len(operations) + 1
         assert (ops_offset[operations[0]] <=
                 ops_offset[operations[1]] <=
                 ops_offset[operations[2]] <=
diff --git a/rpython/jit/codewriter/test/test_flatten.py 
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -73,7 +73,7 @@
     def guess_call_kind(self, op):
         return 'residual'
     def getcalldescr(self, op, oopspecindex=EffectInfo.OS_NONE,
-                     extraeffect=None):
+                     extraeffect=None, extradescr=None):
         try:
             name = op.args[0].value._obj._name
             if 'cannot_raise' in name or name.startswith('cast_'):
diff --git a/rpython/jit/codewriter/test/test_longlong.py 
b/rpython/jit/codewriter/test/test_longlong.py
--- a/rpython/jit/codewriter/test/test_longlong.py
+++ b/rpython/jit/codewriter/test/test_longlong.py
@@ -17,7 +17,7 @@
 class FakeBuiltinCallControl:
     def guess_call_kind(self, op):
         return 'builtin'
-    def getcalldescr(self, op, oopspecindex=None, extraeffect=None):
+    def getcalldescr(self, op, oopspecindex=None, extraeffect=None, 
extradescr=None):
         assert oopspecindex is not None    # in this test
         return 'calldescr-%d' % oopspecindex
     def calldescr_canraise(self, calldescr):
diff --git a/rpython/jit/metainterp/executor.py 
b/rpython/jit/metainterp/executor.py
--- a/rpython/jit/metainterp/executor.py
+++ b/rpython/jit/metainterp/executor.py
@@ -332,6 +332,7 @@
                     continue
             if value in (rop.FORCE_TOKEN,
                          rop.CALL_ASSEMBLER,
+                         rop.INCREMENT_DEBUG_COUNTER,
                          rop.COND_CALL_GC_WB,
                          rop.COND_CALL_GC_WB_ARRAY,
                          rop.DEBUG_MERGE_POINT,
diff --git a/rpython/jit/metainterp/optimizeopt/heap.py 
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -306,13 +306,13 @@
 
     def _optimize_CALL_DICT_LOOKUP(self, op):
         descrs = op.getdescr().get_extra_info().extradescrs
+        assert descrs        # translation hint
         descr1 = descrs[0]
-        descr2 = descrs[1]
-        if descr1 in self.cached_dict_reads:
+        try:
             d = self.cached_dict_reads[descr1]
-        else:
+        except KeyError:
             d = self.cached_dict_reads[descr1] = args_dict()
-            self.corresponding_array_descrs[descr2] = descr1
+            self.corresponding_array_descrs[descrs[1]] = descr1
         args = self.optimizer.make_args_key(op)
         try:
             res_v = d[args]
diff --git a/rpython/jit/metainterp/resoperation.py 
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -494,6 +494,7 @@
     # must be forced, however we need to execute it anyway
     '_NOSIDEEFFECT_LAST', # ----- end of no_side_effect operations -----
 
+    'INCREMENT_DEBUG_COUNTER/1',
     'SETARRAYITEM_GC/3d',
     'SETARRAYITEM_RAW/3d',
     'SETINTERIORFIELD_GC/3d',
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to