def test_parsing_assembler(): if not autodetect().startswith('x86'): py.test.skip('x86 only test') backend_dump = "554889E5534154415541564157488DA500000000488B042590C5540148C7042590C554010000000048898570FFFFFF488B042598C5540148C7042598C554010000000048898568FFFFFF488B0425A0C5540148C70425A0C554010000000048898560FFFFFF488B0425A8C5540148C70425A8C554010000000048898558FFFFFF4C8B3C2550525B0149BB30E06C96FC7F00004D8B334983C60149BB30E06C96FC7F00004D89334981FF102700000F8D000000004983C7014C8B342580F76A024983EE014C89342580F76A024983FE000F8C00000000E9AEFFFFFF488B042588F76A024829E0483B042580EC3C01760D49BB05F30894FC7F000041FFD3554889E5534154415541564157488DA550FFFFFF4889BD70FFFFFF4889B568FFFFFF48899560FFFFFF48898D58FFFFFF4D89C7E954FFFFFF49BB00F00894FC7F000041FFD34440484C3D030300000049BB00F00894FC7F000041FFD34440484C3D070304000000" dump_start = 0x7f3b0b2e63d5 try: loop = parse(""" # Loop 0 : loop with 19 ops [p0, p1, p2, p3, i4] debug_merge_point(0, 0, '<code object f. file 'x.py'. line 2> #15 COMPARE_OP') +166: i6 = int_lt(i4, 10000) guard_true(i6, descr=<Guard0x3>) [p1, p0, p2, p3, i4] debug_merge_point(0, 0, '<code object f. file 'x.py'. line 2> #27 INPLACE_ADD') +179: i8 = int_add(i4, 1) debug_merge_point(0, 0, '<code object f. file 'x.py'. line 2> #31 JUMP_ABSOLUTE') +183: i10 = getfield_raw(40564608, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>) +191: i12 = int_sub(i10, 1) +195: setfield_raw(40564608, i12, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>) +203: i14 = int_lt(i12, 0) guard_false(i14, descr=<Guard0x4>) [p1, p0, p2, p3, i8, None] debug_merge_point(0, '<code object f. file 'x.py'. line 2> #9 LOAD_FAST') +213: jump(p0, p1, p2, p3, i8, descr=<Loop0>) +218: --end of the loop--""", backend_dump=backend_dump, dump_start=dump_start, backend_tp='x86_64') except ObjdumpNotFound: py.test.skip('no objdump found on path') cmp = loop.operations[1] assert 'jge' in cmp.asm assert '0x2710' in cmp.asm assert 'jmp' in loop.operations[-1].asm
def setup(): from rpython.jit.backend import detect_cpu if detect_cpu.autodetect().startswith(detect_cpu.MODEL_S390_64): raise VMProfPlatformUnsupported("rvmprof not supported on" " s390x CPUs for now") compile_extra = ['-DRPYTHON_LL2CTYPES'] platform.verify_eci(ExternalCompilationInfo( compile_extra=compile_extra, **eci_kwds)) eci = global_eci vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) return CInterface(locals())
def test_import_log_2(): if not autodetect().startswith("x86"): py.test.skip("x86 only test") _, loops = import_log(str(py.path.local(__file__).join("..", "logtest2.log"))) for loop in loops: loop.force_asm() assert "cmp" in loops[1].operations[2].asm
def setup_after_space_initialization(self): """NOT_RPYTHON""" if not self.space.config.translating: self.extra_interpdef('interp_pdb', 'interp_magic.interp_pdb') if self.space.config.objspace.std.withmethodcachecounter: self.extra_interpdef('method_cache_counter', 'interp_magic.method_cache_counter') self.extra_interpdef('reset_method_cache_counter', 'interp_magic.reset_method_cache_counter') if self.space.config.objspace.std.withmapdict: self.extra_interpdef('mapdict_cache_counter', 'interp_magic.mapdict_cache_counter') PYC_MAGIC = get_pyc_magic(self.space) self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC) # try: from rpython.jit.backend import detect_cpu model = detect_cpu.autodetect() self.extra_interpdef('cpumodel', 'space.wrap(%r)' % model) except Exception: if self.space.config.translation.jit: raise else: pass # ok fine to ignore in this case # if self.space.config.translation.jit: features = detect_cpu.getcpufeatures(model) self.extra_interpdef('jit_backend_features', 'space.wrap(%r)' % features)
def test_parsing_arm_assembler(): if not autodetect().startswith("arm"): py.test.skip("ARM only test") backend_dump = "F04F2DE9108B2DED2CD04DE20DB0A0E17CC302E3DFC040E300409CE5085084E2086000E3006084E504B084E500508CE508D04BE20000A0E10000A0E1B0A10DE30EA044E300A09AE501A08AE2B0910DE30E9044E300A089E5C0910DE30E9044E3009099E5019089E2C0A10DE30EA044E300908AE5010050E1700020E124A092E500C08AE00C90DCE5288000E3090058E10180A0030080A013297000E3090057E10170A0030070A013077088E1200059E30180A0030080A013099049E2050059E30190A0330090A023099088E1000059E30190A0130090A003099087E1000059E3700020E1010080E204200BE5D0210DE30E2044E3002092E5012082E2D0910DE30E9044E3002089E5010050E1700020E100C08AE00C90DCE5282000E3090052E10120A0030020A013297000E3090057E10170A0030070A013077082E1200059E30120A0030020A013099049E2050059E30190A0330090A023099082E1000059E30190A0130090A003099087E1000059E3700020E1010080E20D005BE10FF0A0A1700020E1D8FFFFEA68C100E301C04BE33CFF2FE105010803560000000000000068C100E301C04BE33CFF2FE105010803570000000000000068C100E301C04BE33CFF2FE105014003580000000000000068C100E301C04BE33CFF2FE1050140035900000000000000" dump_start = int(-0x4FFEE930) loop = parse( """ # Loop 5 (re StrMatchIn at 92 [17, 4, 0, 20, 393237, 21, 0, 29, 9, 1, 65535, 15, 4, 9, 3, 0, 1, 21, 1, 29, 9, 1, 65535, 15, 4, 9, 2, 0, 1, 1...) : loop with 38 ops [i0, i1, p2] +88: label(i0, i1, p2, descr=TargetToken(1081858608)) debug_merge_point(0, 're StrMatchIn at 92 [17. 4. 0. 20. 393237. 21. 0. 29. 9. 1. 65535. 15. 4. 9. 3. 0. 1. 21. 1. 29. 9. 1. 65535. 15. 4. 9. 2. 0. 1. 1...') +116: i3 = int_lt(i0, i1) guard_true(i3, descr=<Guard0x86>) [i1, i0, p2] +124: p4 = getfield_gc(p2, descr=<FieldP rpython.rlib.rsre.rsre_core.StrMatchContext.inst__string 36>) +128: i5 = strgetitem(p4, i0) +136: i7 = int_eq(40, i5) +152: i9 = int_eq(41, i5) +168: i10 = int_or(i7, i9) +172: i12 = int_eq(i5, 32) +184: i14 = int_sub(i5, 9) +188: i16 = uint_lt(i14, 5) +200: i17 = int_or(i12, i16) +204: i18 = int_is_true(i17) +216: i19 = int_or(i10, i18) +220: i20 = int_is_true(i19) guard_false(i20, descr=<Guard0x87>) [i1, i0, p2] +228: i22 = int_add(i0, 1) debug_merge_point(0, 're StrMatchIn at 92 [17. 4. 0. 20. 393237. 21. 0. 29. 9. 1. 65535. 15. 4. 9. 3. 0. 1. 21. 1. 29. 9. 1. 65535. 15. 4. 9. 2. 0. 1. 1...') +232: label(i22, i1, p2, p4, descr=TargetToken(1081858656)) debug_merge_point(0, 're StrMatchIn at 92 [17. 4. 0. 20. 393237. 21. 0. 29. 9. 1. 65535. 15. 4. 9. 3. 0. 1. 21. 1. 29. 9. 1. 65535. 15. 4. 9. 2. 0. 1. 1...') +264: i23 = int_lt(i22, i1) guard_true(i23, descr=<Guard0x88>) [i1, i22, p2] +272: i24 = strgetitem(p4, i22) +280: i25 = int_eq(40, i24) +296: i26 = int_eq(41, i24) +312: i27 = int_or(i25, i26) +316: i28 = int_eq(i24, 32) +328: i29 = int_sub(i24, 9) +332: i30 = uint_lt(i29, 5) +344: i31 = int_or(i28, i30) +348: i32 = int_is_true(i31) +360: i33 = int_or(i27, i32) +364: i34 = int_is_true(i33) guard_false(i34, descr=<Guard0x8a>) [i1, i22, p2] +372: i35 = int_add(i22, 1) debug_merge_point(0, 're StrMatchIn at 92 [17. 4. 0. 20. 393237. 21. 0. 29. 9. 1. 65535. 15. 4. 9. 3. 0. 1. 21. 1. 29. 9. 1. 65535. 15. 4. 9. 2. 0. 1. 1...') +376: jump(i35, i1, p2, p4, descr=TargetToken(1081858656)) +392: --end of the loop--""", backend_dump=backend_dump, dump_start=dump_start, backend_tp="arm_32", ) cmp = loop.operations[2] assert "cmp" in cmp.asm assert "bkpt" in loop.operations[-1].asm # the guard that would be patched
def test_import_log_2(): if not autodetect().startswith('x86'): py.test.skip('x86 only test') _, loops = import_log(str(py.path.local(__file__).join('..', 'logtest2.log'))) try: for loop in loops: loop.force_asm() except ObjdumpNotFound: py.test.skip('no objdump found on path') assert 'cmp' in loops[1].operations[2].asm
def test_jitted(): from rpython.jit.backend import detect_cpu if not detect_cpu.autodetect().startswith("x86"): py.test.skip("HAS_CODEMAP is only in the x86 jit backend for now") class MyCode: pass def get_name(mycode): raise NotImplementedError rvmprof.register_code_object_class(MyCode, get_name) jitdriver = jit.JitDriver( greens=["code"], reds="auto", is_recursive=True, get_unique_id=lambda code: rvmprof.get_unique_id(code) ) @rvmprof.vmprof_execute_code("mycode", lambda code, level, total_i: code) def mainloop(code, level, total_i): i = 20 while i > 0: jitdriver.jit_merge_point(code=code) i -= 1 if level > 0: mainloop(code, level - 1, total_i + i) if level == 0 and total_i == 0: p, length = traceback.traceback(20) traceback.walk_traceback(MyCode, my_callback, 42, p, length) lltype.free(p, flavor="raw") def my_callback(code, loc, arg): print code, loc, arg return 0 def f(argv): jit.set_param(jitdriver, "inlining", 0) code1 = MyCode() rvmprof.register_code(code1, "foo") mainloop(code1, 2, 0) return 0 t = Translation(f, None, gc="boehm") t.rtype() t.driver.pyjitpl_lltype() t.compile_c() stdout = t.driver.cbuilder.cmdexec("") r = re.compile("[<]MyCode object at 0x([0-9a-f]+)[>] (\d) 42\n") got = r.findall(stdout) addr = got[0][0] assert got == [(addr, "1"), (addr, "1"), (addr, "0")]
def setup(): if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64): raise VMProfPlatformUnsupported("rvmprof only supports" " x86-64 CPUs for now") ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof') SRC = ROOT.join('src') if sys.platform.startswith('linux'): libs = ['dl'] else: libs = [] eci_kwds = dict( include_dirs = [SRC], includes = ['rvmprof.h'], libraries = libs, separate_module_files = [SRC.join('rvmprof.c')], post_include_bits=['#define RPYTHON_VMPROF\n'], ) eci = ExternalCompilationInfo(**eci_kwds) platform.verify_eci(ExternalCompilationInfo( compile_extra=['-DRPYTHON_LL2CTYPES'], **eci_kwds)) vmprof_init = rffi.llexternal("vmprof_init", [rffi.INT, rffi.DOUBLE, rffi.CCHARP], rffi.CCHARP, compilation_info=eci) vmprof_enable = rffi.llexternal("vmprof_enable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT, compilation_info=eci, save_err=rffi.RFFI_SAVE_ERRNO) vmprof_register_virtual_function = rffi.llexternal( "vmprof_register_virtual_function", [rffi.CCHARP, rffi.LONG, rffi.INT], rffi.INT, compilation_info=eci) vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals", [rffi.INT], lltype.Void, compilation_info=eci) return CInterface(locals())
def make_trampoline_function(name, func, token, restok): from rpython.jit.backend import detect_cpu cont_name = 'rpyvmprof_f_%s_%s' % (name, token) tramp_name = 'rpyvmprof_t_%s_%s' % (name, token) orig_tramp_name = tramp_name func.c_name = cont_name func._dont_inline_ = True if sys.platform == 'darwin': # according to internet "At the time UNIX was written in 1974...." # "... all C functions are prefixed with _" cont_name = '_' + cont_name tramp_name = '_' + tramp_name PLT = "" else: PLT = "@PLT" assert detect_cpu.autodetect().startswith( detect_cpu.MODEL_X86_64), ("rvmprof only supports x86-64 CPUs for now") # mapping of argument count (not counting the final uid argument) to # the register that holds this uid argument reg = { 0: '%rdi', 1: '%rsi', 2: '%rdx', 3: '%rcx', 4: '%r8', 5: '%r9', } try: reg = reg[len(token)] except KeyError: raise NotImplementedError( "not supported: %r takes more than 5 arguments" % (func, )) target = udir.join('module_cache') target.ensure(dir=1) target = target.join('trampoline_%s_%s.vmprof.s' % (name, token)) target.write("""\ \t.text \t.globl\t%(tramp_name)s %(tramp_name)s: \t.cfi_startproc \tpushq\t%(reg)s \t.cfi_def_cfa_offset 16 \tcall %(cont_name)s%(PLT)s \taddq\t$8, %%rsp \t.cfi_def_cfa_offset 8 \tret \t.cfi_endproc """ % locals()) def tok2cname(tok): if tok == 'i': return 'long' if tok == 'r': return 'void *' raise NotImplementedError(repr(tok)) header = 'RPY_EXTERN %s %s(%s);\n' % (tok2cname( restok), orig_tramp_name, ', '.join([tok2cname(tok) for tok in token] + ['long'])) header += """\ static int cmp_%s(void *addr) { if (addr == %s) return 1; #ifdef VMPROF_ADDR_OF_TRAMPOLINE return VMPROF_ADDR_OF_TRAMPOLINE(addr); #undef VMPROF_ADDR_OF_TRAMPOLINE #else return 0; #endif #define VMPROF_ADDR_OF_TRAMPOLINE cmp_%s } """ % (tramp_name, orig_tramp_name, tramp_name) eci = ExternalCompilationInfo( post_include_bits=[header], separate_module_files=[str(target)], ) return rffi.llexternal(orig_tramp_name, [token2lltype(tok) for tok in token] + [lltype.Signed], token2lltype(restok), compilation_info=eci, _nowrapper=True, sandboxsafe=True, random_effects_on_gcobjs=True)
import py from rpython.jit.backend import detect_cpu cpu = detect_cpu.autodetect() def pytest_runtest_setup(item): if cpu != detect_cpu.MODEL_X86_64: py.test.skip("x86_64 tests only")
TP = lltype.typeOf(item) rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0] = item @specialize.arg(1) def free_raw_storage(storage, track_allocation=True): lltype.free(storage, flavor='raw', track_allocation=track_allocation) # ____________________________________________________________ # # Support for possibly-unaligned accesses from rpython.jit.backend import detect_cpu try: cpuname = detect_cpu.autodetect() misaligned_is_fine = cpuname.startswith('x86') or \ cpuname.startswith('s390x') or \ cpuname.startswith('ppc') del cpuname except detect_cpu.ProcessorAutodetectError: misaligned_is_fine = False class AlignmentError(NotImplementedError): "Means that raw_storage_{get,set}item was used on unaligned memory" # Tweak? It seems a reasonable value for any system out there: requiring # an aligned access to be up to 8-bytes-aligned, even for 64-bit data # types on 32-bit systems.
""" This conftest adds an option to run the translation tests which by default will be disabled. Also it disables the backend tests on non ARMv7 platforms """ import py, os from rpython.jit.backend import detect_cpu cpu = detect_cpu.autodetect() def pytest_addoption(parser): group = parser.getgroup('translation test options') group.addoption('--run-translation-tests', action="store_true", default=False, dest="run_translation_tests", help="run tests that translate code") def pytest_collect_directory(path, parent): if not cpu.startswith('arm'): py.test.skip("ARM(v7) tests skipped: cpu is %r" % (cpu,)) pytest_collect_file = pytest_collect_directory
def make_trampoline_function(name, func, token, restok): from rpython.jit.backend import detect_cpu cont_name = 'rpyvmprof_f_%s_%s' % (name, token) tramp_name = 'rpyvmprof_t_%s_%s' % (name, token) orig_tramp_name = tramp_name func.c_name = cont_name func._dont_inline_ = True if sys.platform == 'darwin': # according to internet "At the time UNIX was written in 1974...." # "... all C functions are prefixed with _" cont_name = '_' + cont_name tramp_name = '_' + tramp_name PLT = "" size_decl = "" type_decl = "" extra_align = "" else: PLT = "@PLT" type_decl = "\t.type\t%s, @function" % (tramp_name,) size_decl = "\t.size\t%s, .-%s" % ( tramp_name, tramp_name) extra_align = "\t.cfi_def_cfa_offset 8" assert detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64), ( "rvmprof only supports x86-64 CPUs for now") # mapping of argument count (not counting the final uid argument) to # the register that holds this uid argument reg = {0: '%rdi', 1: '%rsi', 2: '%rdx', 3: '%rcx', 4: '%r8', 5: '%r9', } try: reg = reg[len(token)] except KeyError: raise NotImplementedError( "not supported: %r takes more than 5 arguments" % (func,)) target = udir.join('module_cache') target.ensure(dir=1) target = target.join('trampoline_%s_%s.vmprof.s' % (name, token)) # NOTE! the tabs in this file are absolutely essential, things # that don't start with \t are silently ignored (<arigato>: WAT!?) target.write("""\ \t.text \t.globl\t%(tramp_name)s %(type_decl)s %(tramp_name)s: \t.cfi_startproc \tpushq\t%(reg)s \t.cfi_def_cfa_offset 16 \tcall %(cont_name)s%(PLT)s \taddq\t$8, %%rsp %(extra_align)s \tret \t.cfi_endproc %(size_decl)s """ % locals()) def tok2cname(tok): if tok == 'i': return 'long' if tok == 'r': return 'void *' raise NotImplementedError(repr(tok)) header = 'RPY_EXTERN %s %s(%s);\n' % ( tok2cname(restok), orig_tramp_name, ', '.join([tok2cname(tok) for tok in token] + ['long'])) header += """\ static int cmp_%s(void *addr) { if (addr == %s) return 1; #ifdef VMPROF_ADDR_OF_TRAMPOLINE return VMPROF_ADDR_OF_TRAMPOLINE(addr); #undef VMPROF_ADDR_OF_TRAMPOLINE #else return 0; #endif #define VMPROF_ADDR_OF_TRAMPOLINE cmp_%s } """ % (tramp_name, orig_tramp_name, tramp_name) eci = ExternalCompilationInfo( post_include_bits = [header], separate_module_files = [str(target)], ) return rffi.llexternal( orig_tramp_name, [token2lltype(tok) for tok in token] + [lltype.Signed], token2lltype(restok), compilation_info=eci, _nowrapper=True, sandboxsafe=True, random_effects_on_gcobjs=True)
# --allworkingmodules working_modules = default_modules.copy() working_modules.update([ "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd", "select", "zipimport", "_lsprof", "crypt", "signal", "_rawffi", "termios", "zlib", "bz2", "struct", "_hashlib", "_md5", "_sha", "_minimal_curses", "cStringIO", "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array", "binascii", "_multiprocessing", '_warnings', "_collections", "_multibytecodec", "micronumpy", "_continuation", "_cffi_backend", "_csv", "_cppyy", "_pypyjson", "_jitlog" ]) from rpython.jit.backend import detect_cpu try: if detect_cpu.autodetect().startswith('x86'): if not sys.platform.startswith('openbsd'): working_modules.add('_vmprof') working_modules.add('faulthandler') except detect_cpu.ProcessorAutodetectError: pass translation_modules = default_modules.copy() translation_modules.update([ "fcntl", "time", "select", "signal", "_rawffi", "zlib", "struct",
from rpython.jit.backend.detect_cpu import autodetect, ProcessorAutodetectError # accelerators for string operations using simd on regular word sizes (*not* # SSE instructions). this style is sometimes called SWAR (SIMD Within A # Register) or "broadword techniques" # XXX remove wordsize and endianness restrictions properly, so far only x86-64 # is tested USE_SIMD = False if LONG_BIT == 64: WORD_SIZE = 8 EVERY_BYTE_ONE = 0x0101010101010101 EVERY_BYTE_HIGHEST_BIT = 0x8080808080808080 try: if autodetect() == "x86-64": USE_SIMD = True except ProcessorAutodetectError: pass else: WORD_SIZE = 4 EVERY_BYTE_ONE = 0x01010101 EVERY_BYTE_HIGHEST_BIT = 0x80808080 # helpers unrolling_wordsize = unroll.unrolling_iterable(range(WORD_SIZE)) def char_repeated_word_width(ch): return r_uint(EVERY_BYTE_ONE) * ord(ch)
TP = lltype.typeOf(item) rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0] = item @specialize.arg(1) def free_raw_storage(storage, track_allocation=True): lltype.free(storage, flavor='raw', track_allocation=track_allocation) # ____________________________________________________________ # # Support for possibly-unaligned accesses from rpython.jit.backend import detect_cpu try: misaligned_is_fine = detect_cpu.autodetect().startswith('x86') except detect_cpu.ProcessorAutodetectError: misaligned_is_fine = False class AlignmentError(NotImplementedError): "Means that raw_storage_{get,set}item was used on unaligned memory" # Tweak? It seems a reasonable value for any system out there: requiring # an aligned access to be up to 8-bytes-aligned, even for 64-bit data # types on 32-bit systems. MAXIMUM_ALIGNMENT = 8 @specialize.memo()
from rpython.rlib import rthread, jit from rpython.rlib.objectmodel import we_are_translated from rpython.config.translationoption import get_translation_config from rpython.jit.backend import detect_cpu class VMProfPlatformUnsupported(Exception): pass # vmprof works only on x86 for now IS_SUPPORTED = False if sys.platform in ('darwin', 'linux', 'linux2') or sys.platform.startswith('freebsd'): try: IS_SUPPORTED = detect_cpu.autodetect().startswith('x86') except detect_cpu.ProcessorAutodetectError: pass ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof') SRC = ROOT.join('src') SHARED = SRC.join('shared') BACKTRACE = SHARED.join('libbacktrace') def make_eci(): if make_eci.called: raise ValueError("make_eci() should be called at most once") # compile_extra = ['-DRPYTHON_VMPROF'] separate_module_files = [
def raw_storage_setitem_unchecked(storage, index, item): "NOT_RPYTHON" TP = lltype.typeOf(item) rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0] = item @specialize.arg(1) def free_raw_storage(storage, track_allocation=True): lltype.free(storage, flavor='raw', track_allocation=track_allocation) # ____________________________________________________________ # # Support for possibly-unaligned accesses from rpython.jit.backend import detect_cpu try: misaligned_is_fine = detect_cpu.autodetect().startswith('x86') except detect_cpu.ProcessorAutodetectError: misaligned_is_fine = False class AlignmentError(NotImplementedError): "Means that raw_storage_{get,set}item was used on unaligned memory" # Tweak? It seems a reasonable value for any system out there: requiring # an aligned access to be up to 8-bytes-aligned, even for 64-bit data # types on 32-bit systems. MAXIMUM_ALIGNMENT = 8 @specialize.memo() def _get_alignment_mask(TP): size = rffi.sizeof(TP)
@not_rpython def _raw_storage_setitem_unchecked(storage, index, item): TP = lltype.typeOf(item) rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0] = item @specialize.arg(1) def free_raw_storage(storage, track_allocation=True): lltype.free(storage, flavor='raw', track_allocation=track_allocation) # ____________________________________________________________ # # Support for possibly-unaligned accesses from rpython.jit.backend import detect_cpu try: cpuname = detect_cpu.autodetect() misaligned_is_fine = cpuname.startswith('x86') or \ cpuname.startswith('s390x') or \ cpuname.startswith('ppc') del cpuname except detect_cpu.ProcessorAutodetectError: misaligned_is_fine = False class AlignmentError(NotImplementedError): "Means that raw_storage_{get,set}item was used on unaligned memory" # Tweak? It seems a reasonable value for any system out there: requiring # an aligned access to be up to 8-bytes-aligned, even for 64-bit data # types on 32-bit systems. MAXIMUM_ALIGNMENT = 8
# --allworkingmodules working_modules = default_modules.copy() working_modules.update([ "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd", "select", "zipimport", "_lsprof", "crypt", "signal", "_rawffi", "termios", "zlib", "bz2", "struct", "_hashlib", "_md5", "_sha", "_minimal_curses", "cStringIO", "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array", "binascii", "_multiprocessing", '_warnings', "_collections", "_multibytecodec", "micronumpy", "_continuation", "_cffi_backend", "_csv", "cppyy", "_pypyjson", ]) from rpython.jit.backend import detect_cpu try: if detect_cpu.autodetect().startswith('x86'): working_modules.add('_vmprof') except detect_cpu.ProcessorAutodetectError: pass translation_modules = default_modules.copy() translation_modules.update([ "fcntl", "time", "select", "signal", "_rawffi", "zlib", "struct", "_md5", "cStringIO", "array", "binascii", # the following are needed for pyrepl (and hence for the # interactive prompt/pdb) "termios", "_minimal_curses", ]) # XXX this should move somewhere else, maybe to platform ("is this posixish" # check or something)
from rpython.rtyper.lltypesystem.lloperation import llop from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rtyper.tool import rffi_platform as platform from rpython.rlib import rthread, jit from rpython.rlib.objectmodel import we_are_translated from rpython.config.translationoption import get_translation_config from rpython.jit.backend import detect_cpu class VMProfPlatformUnsupported(Exception): pass # vmprof works only on x86 for now IS_SUPPORTED = False if sys.platform in ('darwin', 'linux', 'linux2') or sys.platform.startswith('freebsd'): try: proc = detect_cpu.autodetect() IS_SUPPORTED = proc.startswith('x86') or proc == 'aarch64' except detect_cpu.ProcessorAutodetectError: print("PROCESSOR NOT DETECTED, SKIPPING VMPROF") ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof') SRC = ROOT.join('src') SHARED = SRC.join('shared') BACKTRACE = SHARED.join('libbacktrace') def make_eci(): if make_eci.called: raise ValueError("make_eci() should be called at most once") # compile_extra = ['-DRPYTHON_VMPROF'] separate_module_files = [