Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r62394:def044ae69a4 Date: 2013-03-17 13:54 -0700 http://bitbucket.org/pypy/pypy/changeset/def044ae69a4/
Log: merge diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -364,9 +364,10 @@ self._in_transaction = False self.isolation_level = isolation_level - self._cursors = [] + self.__cursors = [] + self.__cursors_counter = 0 self.__statements = [] - self.__statement_counter = 0 + self.__statements_counter = 0 self._statement_cache = _StatementCache(self, cached_statements) self.__func_cache = {} @@ -394,10 +395,7 @@ def close(self): self._check_thread() - for statement in self.__statements: - obj = statement() - if obj is not None: - obj._finalize() + self.__do_all_statements(Statement._finalize, True) if self._db: ret = _lib.sqlite3_close(self._db) @@ -469,13 +467,33 @@ exc.error_code = error_code return exc + def _remember_cursor(self, cursor): + self.__cursors.append(weakref.ref(cursor)) + self.__cursors_counter += 1 + if self.__cursors_counter < 200: + return + self.__cursors_counter = 0 + self.__cursors = [r for r in self.__cursors if r() is not None] + def _remember_statement(self, statement): self.__statements.append(weakref.ref(statement)) - self.__statement_counter += 1 + self.__statements_counter += 1 + if self.__statements_counter < 200: + return + self.__statements_counter = 0 + self.__statements = [r for r in self.__statements if r() is not None] - if self.__statement_counter % 100 == 0: - self.__statements = [ref for ref in self.__statements - if ref() is not None] + def __do_all_statements(self, action, reset_cursors): + for weakref in self.__statements: + statement = weakref() + if statement is not None: + action(statement) + + if reset_cursors: + for weakref in self.__cursors: + cursor = weakref() + if cursor is not None: + cursor._reset = True @_check_thread_wrap @_check_closed_wrap @@ -528,10 +546,7 @@ if not self._in_transaction: return - for statement in self.__statements: - obj = statement() - if obj is not None: - obj._reset() + self.__do_all_statements(Statement._reset, False) statement = c_void_p() ret = _lib.sqlite3_prepare_v2(self._db, b"COMMIT", -1, @@ -552,15 +567,7 @@ if not self._in_transaction: return - for statement in self.__statements: - obj = statement() - if obj is not None: - obj._reset() - - for cursor_ref in self._cursors: - cursor = cursor_ref() - if cursor: - cursor._reset = True + self.__do_all_statements(Statement._reset, True) statement = c_void_p() ret = _lib.sqlite3_prepare_v2(self._db, b"ROLLBACK", -1, @@ -787,14 +794,9 @@ __statement = None def __init__(self, con): - self.__initialized = True - self.__connection = con - if not isinstance(con, Connection): raise TypeError - con._check_thread() - con._check_closed() - con._cursors.append(weakref.ref(self)) + self.__connection = con self.arraysize = 1 self.row_factory = None @@ -804,11 +806,12 @@ self.__description = None self.__rowcount = -1 + con._check_thread() + con._remember_cursor(self) + + self.__initialized = True + def __del__(self): - try: - self.__connection._cursors.remove(weakref.ref(self)) - except (AttributeError, ValueError): - pass if self.__statement: self.__statement._reset() @@ -883,7 +886,6 @@ self.__rowcount += _lib.sqlite3_changes(self.__connection._db) finally: self.__locked = False - return self @__check_cursor_wrap @@ -921,9 +923,10 @@ if rc != _lib.SQLITE_DONE: _lib.sqlite3_finalize(statement) if rc == _lib.SQLITE_OK: - return self + break else: raise self.__connection._get_exception(rc) + rc = _lib.sqlite3_finalize(statement) if rc != _lib.SQLITE_OK: raise self.__connection._get_exception(rc) @@ -1000,6 +1003,7 @@ def __init__(self, connection, sql): self.__con = connection + self.__con._remember_statement(self) if not isinstance(sql, basestring): raise Warning("SQL is of wrong type. Must be string or unicode.") @@ -1027,10 +1031,9 @@ ret = _lib.sqlite3_prepare_v2(self.__con._db, sql, -1, byref(self._statement), byref(sql)) self._kind = Statement._DQL - if ret != _lib.SQLITE_OK: raise self.__con._get_exception(ret) - self.__con._remember_statement(self) + sql = sql.value.decode('utf-8') if _check_remaining_sql(sql): raise Warning("You can only execute one statement at a time.") diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -86,3 +86,8 @@ .. branch: vendor-rename Remove minor verison number from lib-python dirs to simplify stdlib upgrades. + +.. branch: jitframe-on-heap +Moves optimized JIT frames from stack to heap. As a side effect it enables +stackless to work well with the JIT on PyPy. Also removes a bunch of code from +the GC which fixes cannot find gc roots. diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -1,7 +1,14 @@ -import os, sys +import cStringIO +import os +import sys +import traceback +from errno import EINTR + from rpython.rlib import jit from rpython.rlib.objectmodel import we_are_translated -from errno import EINTR + +from pypy.interpreter import debug + AUTO_DEBUG = os.getenv('PYPY_DEBUG') RECORD_INTERPLEVEL_TRACEBACK = True @@ -61,7 +68,7 @@ if space is None: # this part NOT_RPYTHON exc_typename = str(self.w_type) - exc_value = str(w_value) + exc_value = str(w_value) else: w = space.wrap if space.is_w(space.type(self.w_type), space.w_str): @@ -95,7 +102,8 @@ def print_application_traceback(self, space, file=None): "NOT_RPYTHON: Dump a standard application-level traceback." - if file is None: file = sys.stderr + if file is None: + file = sys.stderr self.print_app_tb_only(file) print >> file, self.errorstr(space) @@ -130,8 +138,8 @@ def print_detailed_traceback(self, space=None, file=None): """NOT_RPYTHON: Dump a nice detailed interpreter- and application-level traceback, useful to debug the interpreter.""" - import traceback, cStringIO - if file is None: file = sys.stderr + if file is None: + file = sys.stderr f = cStringIO.StringIO() for i in range(len(self.debug_excs)-1, -1, -1): print >> f, "Traceback (interpreter-level):" @@ -144,7 +152,6 @@ self.print_app_tb_only(file) print >> file, '(application-level)', self.errorstr(space) if AUTO_DEBUG: - import debug debug.fire(self) @jit.unroll_safe @@ -174,7 +181,7 @@ # ("string", ...) ("string", ...) deprecated # (inst, None) (inst.__class__, inst) no # - w_type = self.w_type + w_type = self.w_type w_value = self.get_w_value(space) while space.is_true(space.isinstance(w_type, space.w_tuple)): w_type = space.getitem(w_type, space.wrap(0)) @@ -211,7 +218,7 @@ w_value = w_inst w_type = w_instclass - self.w_type = w_type + self.w_type = w_type self._w_value = w_value def _exception_getclass(self, space, w_inst): @@ -327,7 +334,7 @@ from rpython.rlib.unroll import unrolling_iterable attrs = ['x%d' % i for i in range(len(formats))] entries = unrolling_iterable(enumerate(attrs)) - # + class OpErrFmt(OperationError): def __init__(self, w_type, strings, *args): self.setup(w_type) @@ -336,6 +343,7 @@ for i, attr in entries: setattr(self, attr, args[i]) assert w_type is not None + def _compute_value(self): lst = [None] * (len(formats) + len(formats) + 1) for i, attr in entries: diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py --- a/pypy/interpreter/nestedscope.py +++ b/pypy/interpreter/nestedscope.py @@ -1,11 +1,13 @@ -from pypy.interpreter.error import OperationError -from pypy.interpreter import function, pycode, pyframe -from pypy.interpreter.baseobjspace import Wrappable -from pypy.interpreter.mixedmodule import MixedModule -from pypy.interpreter.astcompiler import consts from rpython.rlib import jit from rpython.tool.uid import uid +from pypy.interpreter import function, pycode, pyframe +from pypy.interpreter.astcompiler import consts +from pypy.interpreter.baseobjspace import Wrappable +from pypy.interpreter.error import OperationError +from pypy.interpreter.mixedmodule import MixedModule + + class Cell(Wrappable): "A simple container for a wrapped value." @@ -20,7 +22,7 @@ def get(self): if self.w_value is None: - raise ValueError, "get() from an empty cell" + raise ValueError("get() from an empty cell") return self.w_value def set(self, w_value): @@ -28,9 +30,9 @@ def delete(self): if self.w_value is None: - raise ValueError, "delete() on an empty cell" + raise ValueError("delete() on an empty cell") self.w_value = None - + def descr__cmp__(self, space, w_other): other = space.interpclass_w(w_other) if not isinstance(other, Cell): @@ -46,10 +48,10 @@ return space.cmp(self.w_value, other.w_value) def descr__reduce__(self, space): - w_mod = space.getbuiltinmodule('_pickle_support') - mod = space.interp_w(MixedModule, w_mod) + w_mod = space.getbuiltinmodule('_pickle_support') + mod = space.interp_w(MixedModule, w_mod) new_inst = mod.get('cell_new') - if self.w_value is None: #when would this happen? + if self.w_value is None: # when would this happen? return space.newtuple([new_inst, space.newtuple([])]) tup = [self.w_value] return space.newtuple([new_inst, space.newtuple([]), @@ -57,7 +59,7 @@ def descr__setstate__(self, space, w_state): self.w_value = space.getitem(w_state, space.wrap(0)) - + def __repr__(self): """ representation for debugging purposes """ if self.w_value is None: @@ -74,10 +76,9 @@ raise OperationError(space.w_ValueError, space.wrap("Cell is empty")) - super_initialize_frame_scopes = pyframe.PyFrame.initialize_frame_scopes -super_fast2locals = pyframe.PyFrame.fast2locals -super_locals2fast = pyframe.PyFrame.locals2fast +super_fast2locals = pyframe.PyFrame.fast2locals +super_locals2fast = pyframe.PyFrame.locals2fast class __extend__(pyframe.PyFrame): @@ -132,7 +133,7 @@ def fast2locals(self): super_fast2locals(self) # cellvars are values exported to inner scopes - # freevars are values coming from outer scopes + # freevars are values coming from outer scopes freevarnames = list(self.pycode.co_cellvars) if self.pycode.co_flags & consts.CO_OPTIMIZED: freevarnames.extend(self.pycode.co_freevars) @@ -197,11 +198,11 @@ except ValueError: varname = self.getfreevarname(varindex) if self.iscellvar(varindex): - message = "local variable '%s' referenced before assignment"%varname + message = "local variable '%s' referenced before assignment" % varname w_exc_type = self.space.w_UnboundLocalError else: message = ("free variable '%s' referenced before assignment" - " in enclosing scope"%varname) + " in enclosing scope" % varname) w_exc_type = self.space.w_NameError raise OperationError(w_exc_type, self.space.wrap(message)) else: diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py --- a/pypy/module/_continuation/interp_continuation.py +++ b/pypy/module/_continuation/interp_continuation.py @@ -29,7 +29,6 @@ if self.sthread is not None: raise geterror(self.space, "continulet already __init__ialized") sthread = build_sthread(self.space) - #workaround_disable_jit(sthread) # # hackish: build the frame "by hand", passing it the correct arguments space = self.space @@ -72,8 +71,7 @@ global_state.clear() raise geterror(self.space, "continulet already finished") self.check_sthread() - #workaround_disable_jit(self.sthread) - # + global_state.origin = self if to is None: # simple switch: going to self.h @@ -266,16 +264,6 @@ sthread = ec.stacklet_thread = SThread(space, ec) return sthread -def workaround_disable_jit(sthread): - # A bad workaround to kill the JIT anywhere in this thread. - # This forces all the frames. It's a bad workaround because - # it takes O(depth) time, and it will cause some "abort: - # vable escape" in the JIT. The goal is to prevent any frame - # from being still virtuals, because the JIT generates code - # to un-virtualizable them "on demand" by loading values based - # on FORCE_TOKEN, which is an address in the stack. - sthread.ec.force_all_frames() - # ____________________________________________________________ def permute(space, args_w): diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py --- a/pypy/module/pypyjit/interp_jit.py +++ b/pypy/module/pypyjit/interp_jit.py @@ -22,6 +22,7 @@ 'lastblock', 'is_being_profiled', 'w_globals', + 'w_f_trace', ] JUMP_ABSOLUTE = opmap['JUMP_ABSOLUTE'] @@ -37,9 +38,6 @@ def set_jitcell_at(newcell, next_instr, is_being_profiled, bytecode): bytecode.jit_cells[next_instr, is_being_profiled] = newcell -def confirm_enter_jit(next_instr, is_being_profiled, bytecode, frame, ec): - return (frame.w_f_trace is None and - ec.w_tracefunc is None) def can_never_inline(next_instr, is_being_profiled, bytecode): return False @@ -55,7 +53,6 @@ pypyjitdriver = PyPyJitDriver(get_printable_location = get_printable_location, get_jitcell_at = get_jitcell_at, set_jitcell_at = set_jitcell_at, - confirm_enter_jit = confirm_enter_jit, can_never_inline = can_never_inline, should_unroll_one_iteration = should_unroll_one_iteration, diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py --- a/pypy/module/test_lib_pypy/test_sqlite3.py +++ b/pypy/module/test_lib_pypy/test_sqlite3.py @@ -159,6 +159,7 @@ con.commit() except _sqlite3.OperationalError: pytest.fail("_sqlite3 knew nothing about the implicit ROLLBACK") + con.close() def test_statement_arg_checking(): con = _sqlite3.connect(':memory:') @@ -194,3 +195,4 @@ with pytest.raises(ValueError) as e: con.execute('insert into foo(x) values (?)', 2) assert str(e.value) == 'parameters are of unsupported type' + con.close() diff --git a/rpython/jit/backend/arm/assembler.py b/rpython/jit/backend/arm/assembler.py --- a/rpython/jit/backend/arm/assembler.py +++ b/rpython/jit/backend/arm/assembler.py @@ -1,43 +1,30 @@ from __future__ import with_statement + import os + +from rpython.jit.backend.arm import conditions as c, registers as r +from rpython.jit.backend.arm.arch import (WORD, DOUBLE_WORD, FUNC_ALIGN, + JITFRAME_FIXED_SIZE) +from rpython.jit.backend.arm.codebuilder import ARMv7Builder, OverwritingBuilder +from rpython.jit.backend.arm.locations import imm, StackLocation +from rpython.jit.backend.arm.opassembler import ResOpAssembler +from rpython.jit.backend.arm.regalloc import (Regalloc, + CoreRegisterManager, check_imm_arg, VFPRegisterManager, + operations as regalloc_operations, + operations_with_guard as regalloc_operations_with_guard) from rpython.jit.backend.llsupport import jitframe -from rpython.jit.backend.arm.helper.assembler import saved_registers -from rpython.jit.backend.arm import conditions as c -from rpython.jit.backend.arm import registers as r -from rpython.jit.backend.arm.arch import WORD, DOUBLE_WORD, FUNC_ALIGN, \ - N_REGISTERS_SAVED_BY_MALLOC, \ - JITFRAME_FIXED_SIZE -from rpython.jit.backend.arm.codebuilder import ARMv7Builder, OverwritingBuilder -from rpython.jit.backend.arm.locations import get_fp_offset, imm, StackLocation -from rpython.jit.backend.arm.regalloc import (Regalloc, ARMFrameManager, - CoreRegisterManager, check_imm_arg, - VFPRegisterManager, - operations as regalloc_operations, - operations_with_guard as regalloc_operations_with_guard) +from rpython.jit.backend.llsupport.assembler import DEBUG_COUNTER from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper from rpython.jit.backend.model import CompiledLoopToken -from rpython.jit.codewriter import longlong from rpython.jit.codewriter.effectinfo import EffectInfo -from rpython.jit.metainterp.history import AbstractFailDescr, INT, REF, FLOAT -from rpython.jit.metainterp.history import BoxInt, ConstInt -from rpython.jit.metainterp.resoperation import rop, ResOperation -from rpython.rlib import rgc -from rpython.rlib.objectmodel import we_are_translated, specialize +from rpython.jit.metainterp.history import AbstractFailDescr, FLOAT +from rpython.jit.metainterp.resoperation import rop +from rpython.rlib.debug import debug_print, debug_start, debug_stop +from rpython.rlib.jit import AsmInfo +from rpython.rlib.objectmodel import we_are_translated, specialize, compute_unique_id +from rpython.rlib.rarithmetic import r_uint from rpython.rtyper.annlowlevel import llhelper, cast_instance_to_gcref -from rpython.rtyper.lltypesystem import lltype, rffi, llmemory -from rpython.rtyper.lltypesystem.lloperation import llop -from rpython.jit.backend.arm.opassembler import ResOpAssembler -from rpython.rlib.debug import (debug_print, debug_start, debug_stop, - have_debug_prints, fatalerror) -from rpython.rlib.jit import AsmInfo -from rpython.rlib.objectmodel import compute_unique_id -from rpython.rlib.rarithmetic import intmask, r_uint - - -DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed), - ('type', lltype.Char), # 'b'ridge, 'l'abel or - # 'e'ntry point - ('number', lltype.Signed)) +from rpython.rtyper.lltypesystem import lltype, rffi class AssemblerARM(ResOpAssembler): @@ -121,18 +108,6 @@ self.loop_run_counters.append(struct) return struct - 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) - @specialize.argtype(1) def _inject_debugging_code(self, looptoken, operations, tp, number): if self._debug: @@ -278,7 +253,7 @@ mc.gen_load_int(r.r0.value, self.cpu.pos_exception()) mc.LDR_ri(r.r0.value, r.r0.value) mc.TST_rr(r.r0.value, r.r0.value) - # restore registers and return + # restore registers and return # We check for c.EQ here, meaning all bits zero in this case mc.POP([reg.value for reg in r.argument_regs] + [r.pc.value], cond=c.EQ) # @@ -602,7 +577,7 @@ self.mc.LDR_ri(r.lr.value, r.lr.value) # ldr lr, *lengh # calculate ofs self.mc.SUB_rr(r.ip.value, r.ip.value, r.sp.value) # SUB ip, current - # if ofs + # if ofs self.mc.CMP_rr(r.ip.value, r.lr.value) # CMP ip, lr self.mc.BL(self.stack_check_slowpath, c=c.HI) # call if ip > lr # @@ -758,7 +733,6 @@ self._check_frame_depth(self.mc, self._regalloc.get_gcmap(), expected_size=expected_size) - def _check_frame_depth(self, mc, gcmap, expected_size=-1): """ check if the frame is of enough depth to follow this bridge. Otherwise reallocate the frame in a helper. @@ -952,7 +926,7 @@ effectinfo = op.getdescr().get_extra_info() oopspecindex = effectinfo.oopspecindex asm_llong_operations[oopspecindex](self, op, arglocs, regalloc, fcond) - return fcond + return fcond def regalloc_emit_math(self, op, arglocs, fcond, regalloc): effectinfo = op.getdescr().get_extra_info() @@ -1075,7 +1049,6 @@ assert 0, 'unsupported case' def _mov_stack_to_loc(self, prev_loc, loc, cond=c.AL): - pushed = False if loc.is_reg(): assert prev_loc.type != FLOAT, 'trying to load from an \ incompatible location into a core register' @@ -1299,7 +1272,6 @@ self.store_reg(mc, r.ip, r.fp, ofs) - def not_implemented(msg): os.write(2, '[ARM/asm] %s\n' % msg) raise NotImplementedError(msg) 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 @@ -1,14 +1,23 @@ - +from rpython.jit.backend.llsupport import jitframe +from rpython.jit.backend.llsupport.memcpy import memcpy_fn +from rpython.jit.backend.llsupport.symbolic import WORD +from rpython.jit.metainterp.history import (INT, REF, FLOAT, JitCellToken, + ConstInt, BoxInt) +from rpython.jit.metainterp.resoperation import ResOperation, rop from rpython.rlib import rgc +from rpython.rlib.debug import debug_start, debug_stop, have_debug_prints from rpython.rlib.rarithmetic import r_uint -from rpython.jit.backend.llsupport.symbolic import WORD -from rpython.jit.backend.llsupport import jitframe -from rpython.jit.metainterp.history import INT, REF, FLOAT, JitCellToken from rpython.rtyper.annlowlevel import cast_instance_to_gcref from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.jit.backend.llsupport.memcpy import memcpy_fn -from rpython.rlib.debug import (debug_print, debug_start, debug_stop, - have_debug_prints) + + +DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', + # 'b'ridge, 'l'abel or # 'e'ntry point + ('i', lltype.Signed), + ('type', lltype.Char), + ('number', lltype.Signed) +) + class GuardToken(object): def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs, exc, @@ -203,3 +212,15 @@ # XXX here should be emitted guard_not_forced, but due # to incompatibilities in how it's done, we leave it for the # caller to deal with + + 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) 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 @@ -1,10 +1,11 @@ +import sys +import os -import sys, os from rpython.jit.backend.llsupport import symbolic, jitframe -from rpython.jit.backend.llsupport.assembler import GuardToken, BaseAssembler +from rpython.jit.backend.llsupport.assembler import GuardToken, BaseAssembler, DEBUG_COUNTER from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper from rpython.jit.backend.llsupport.gcmap import allocate_gcmap -from rpython.jit.metainterp.history import Const, Box, BoxInt, ConstInt +from rpython.jit.metainterp.history import Const, Box from rpython.jit.metainterp.history import AbstractFailDescr, INT, REF, FLOAT from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory from rpython.rtyper.lltypesystem.lloperation import llop @@ -23,7 +24,7 @@ imm0, imm1, FloatImmedLoc, RawEbpLoc, RawEspLoc) from rpython.rlib.objectmodel import we_are_translated, specialize from rpython.jit.backend.x86 import rx86, codebuf -from rpython.jit.metainterp.resoperation import rop, ResOperation +from rpython.jit.metainterp.resoperation import rop from rpython.jit.backend.x86 import support from rpython.rlib.debug import debug_print, debug_start, debug_stop from rpython.rlib import rgc @@ -34,17 +35,15 @@ from rpython.rlib.rarithmetic import intmask, r_uint from rpython.rlib.objectmodel import compute_unique_id + # darwin requires the stack to be 16 bytes aligned on calls. Same for gcc 4.5.0, # better safe than sorry CALL_ALIGN = 16 // WORD + def align_stack_words(words): return (words + CALL_ALIGN - 1) & ~(CALL_ALIGN-1) -DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed), - ('type', lltype.Char), # 'b'ridge, 'l'abel or - # 'e'ntry point - ('number', lltype.Signed)) class Assembler386(BaseAssembler): _regalloc = None @@ -240,7 +239,7 @@ propagate_exception_descr = rffi.cast(lltype.Signed, cast_instance_to_gcref(self.cpu.propagate_exception_descr)) ofs = self.cpu.get_ofs_of_frame_field('jf_descr') - self.mc.MOV_bi(ofs, propagate_exception_descr) + self.mc.MOV(RawEbpLoc(ofs), imm(propagate_exception_descr)) self.mc.MOV_rr(eax.value, ebp.value) # self._call_footer() @@ -747,18 +746,6 @@ targettoken._ll_loop_code += rawstart self.target_tokens_currently_compiling = None - 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) - @specialize.argtype(1) def _inject_debugging_code(self, looptoken, operations, tp, number): if self._debug: diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py --- a/rpython/rlib/rmmap.py +++ b/rpython/rlib/rmmap.py @@ -1,6 +1,5 @@ - from rpython.rtyper.tool import rffi_platform -from rpython.rtyper.lltypesystem import rffi, lltype, llmemory +from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rposix from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rlib.nonconst import NonConstant @@ -12,10 +11,7 @@ _POSIX = os.name == "posix" _MS_WINDOWS = os.name == "nt" -_LINUX = "linux" in sys.platform _64BIT = "64bit" in platform.architecture()[0] -_ARM = platform.machine().startswith('arm') -_PPC = platform.machine().startswith('ppc') _CYGWIN = "cygwin" == sys.platform class RValueError(Exception): @@ -30,7 +26,7 @@ if _POSIX: includes += ['unistd.h', 'sys/mman.h'] elif _MS_WINDOWS: - includes += ['winsock2.h','windows.h'] + includes += ['winsock2.h', 'windows.h'] class CConfig: _compilation_info_ = ExternalCompilationInfo( @@ -78,7 +74,7 @@ from rpython.rlib.rwin32 import NULL_HANDLE, INVALID_HANDLE_VALUE from rpython.rlib.rwin32 import DWORD, WORD, DWORD_PTR, LPDWORD from rpython.rlib.rwin32 import BOOL, LPVOID, LPCSTR, SIZE_T - from rpython.rlib.rwin32 import INT, LONG, PLONG + from rpython.rlib.rwin32 import LONG, PLONG # export the constants inside and outside. see __init__.py cConfig = rffi_platform.configure(CConfig) @@ -128,7 +124,7 @@ if _POSIX: has_mremap = cConfig['has_mremap'] c_mmap, c_mmap_safe = external('mmap', [PTR, size_t, rffi.INT, rffi.INT, - rffi.INT, off_t], PTR, macro=True) + rffi.INT, off_t], PTR, macro=True) # 'mmap' on linux32 is a macro that calls 'mmap64' _, c_munmap_safe = external('munmap', [PTR, size_t], rffi.INT) c_msync, _ = external('msync', [PTR, size_t, rffi.INT], rffi.INT) @@ -138,7 +134,7 @@ # this one is always safe _pagesize = rffi_platform.getintegerfunctionresult('getpagesize', - includes=includes) + includes=includes) _get_allocation_granularity = _get_page_size = lambda: _pagesize elif _MS_WINDOWS: @@ -150,13 +146,13 @@ 'SYSINFO_STRUCT', ("wProcessorArchitecture", WORD), ("wReserved", WORD), - ) + ) SYSINFO_UNION = rffi.CStruct( 'union SYSINFO_UNION', ("dwOemId", DWORD), ("_struct_", SYSINFO_STRUCT), - ) + ) # sorry, I can't find a way to insert the above # because the union field has no name SYSTEM_INFO = rffi_platform.Struct( @@ -209,7 +205,6 @@ VirtualFree = winexternal('VirtualFree', [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL) - def _get_page_size(): try: si = rffi.make(SYSTEM_INFO) @@ -493,14 +488,6 @@ # this is not checked return res elif _POSIX: -## XXX why is this code here? There is no equivalent in CPython -## if _LINUX: -## # alignment of the address -## value = cast(self.data, c_void_p).value -## aligned_value = value & ~(PAGESIZE - 1) -## # the size should be increased too. otherwise the final -## # part is not "msynced" -## new_size = size + value & (PAGESIZE - 1) res = c_msync(start, size, MS_SYNC) if res == -1: errno = rposix.get_errno() @@ -515,7 +502,7 @@ # check boundings if (src < 0 or dest < 0 or count < 0 or - src + count > self.size or dest + count > self.size): + src + count > self.size or dest + count > self.size): raise RValueError("source or destination out of range") datasrc = self.getptr(src) @@ -567,10 +554,9 @@ SetEndOfFile(self.file_handle) # create another mapping object and remap the file view res = CreateFileMapping(self.file_handle, NULL, PAGE_READWRITE, - newsize_high, newsize_low, self.tagname) + newsize_high, newsize_low, self.tagname) self.map_handle = res - dwErrCode = 0 if self.map_handle: data = MapViewOfFile(self.map_handle, FILE_MAP_WRITE, offset_high, offset_low, newsize) @@ -603,7 +589,7 @@ if len(value) != 1: raise RValueError("mmap assignment must be " - "single-character string") + "single-character string") if index < 0: index += self.size self.data[index] = value[0] @@ -614,12 +600,12 @@ if _POSIX: def mmap(fileno, length, flags=MAP_SHARED, - prot=PROT_WRITE | PROT_READ, access=_ACCESS_DEFAULT, offset=0): + prot=PROT_WRITE | PROT_READ, access=_ACCESS_DEFAULT, offset=0): fd = fileno # check access is not there when flags and prot are there - if access != _ACCESS_DEFAULT and ((flags != MAP_SHARED) or\ + if access != _ACCESS_DEFAULT and ((flags != MAP_SHARED) or (prot != (PROT_WRITE | PROT_READ))): raise RValueError("mmap can't specify both access and flags, prot.") @@ -771,8 +757,8 @@ pass # ignore non-seeking files and errors and trust map_size else: if not high and low <= sys.maxint: - size = low - else: + size = low + else: # not so sure if the signed/unsigned strictness is a good idea: high = rffi.cast(lltype.Unsigned, high) low = rffi.cast(lltype.Unsigned, low) @@ -866,7 +852,7 @@ case of a sandboxed process """ null = lltype.nullptr(rffi.VOIDP.TO) - res = VirtualAlloc(null, map_size, MEM_COMMIT|MEM_RESERVE, + res = VirtualAlloc(null, map_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE) if not res: raise MemoryError diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py --- a/rpython/rtyper/lltypesystem/ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/ll2ctypes.py @@ -44,7 +44,6 @@ _POSIX = os.name == "posix" _MS_WINDOWS = os.name == "nt" -_LINUX = "linux" in sys.platform _64BIT = "64bit" in host_platform.architecture()[0] @@ -70,7 +69,7 @@ return ctype() def do_allocation_in_far_regions(): - """On 32 bits: this reserves 1.25GB of address space, or 2.5GB on Linux, + """On 32 bits: this reserves 1.25GB of address space, or 2.5GB on POSIX, which helps test this module for address values that are signed or unsigned. @@ -87,18 +86,20 @@ if _64BIT: PIECESIZE = 0x80000000 else: - if _LINUX: + if _POSIX: PIECESIZE = 0x10000000 else: PIECESIZE = 0x08000000 PIECES = 10 flags = (0,) - if _LINUX: + if _POSIX: flags = (rmmap.MAP_PRIVATE|rmmap.MAP_ANONYMOUS|rmmap.MAP_NORESERVE, rmmap.PROT_READ|rmmap.PROT_WRITE) - if _MS_WINDOWS: + elif _MS_WINDOWS: flags = (rmmap.MEM_RESERVE,) # XXX seems not to work + else: + assert False # should always generate flags m = rmmap.mmap(-1, PIECES * PIECESIZE, *flags) m.close = lambda : None # leak instead of giving a spurious # error at CPython's shutdown _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit