Esempio n. 1
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = rthread.set_stacksize(int(argv[1]))
     if error != 0:
         os.write(2, "set_stacksize(%d) returned %d\n" % (
             int(argv[1]), error))
         raise AssertionError
     # malloc a bit
     s1 = State(); s2 = State(); s3 = State()
     s1.x = 0x11111111; s2.x = 0x22222222; s3.x = 0x33333333
     # start 3 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = rthread.start_new_thread(bootstrap, ())
     ident2 = rthread.start_new_thread(bootstrap, ())
     ident3 = rthread.start_new_thread(bootstrap, ())
     # wait for the 3 threads to finish
     while True:
         if state.count == 3:
             break
         time.sleep(0.1)      # invokes before/after
     # check that the malloced structures were not overwritten
     assert s1.x == 0x11111111
     assert s2.x == 0x22222222
     assert s3.x == 0x33333333
     os.write(1, "done\n")
     return 0
Esempio n. 2
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = rthread.set_stacksize(int(argv[1]))
     if error != 0:
         os.write(
             2,
             "set_stacksize(%d) returned %d\n" % (int(argv[1]), error))
         raise AssertionError
     # malloc a bit
     s1 = State()
     s2 = State()
     s3 = State()
     s1.x = 0x11111111
     s2.x = 0x22222222
     s3.x = 0x33333333
     # start 3 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = rthread.start_new_thread(bootstrap, ())
     ident2 = rthread.start_new_thread(bootstrap, ())
     ident3 = rthread.start_new_thread(bootstrap, ())
     # wait for the 3 threads to finish
     while True:
         if state.count == 3:
             break
         time.sleep(0.1)  # invokes before/after
     # check that the malloced structures were not overwritten
     assert s1.x == 0x11111111
     assert s2.x == 0x22222222
     assert s3.x == 0x33333333
     os.write(1, "done\n")
     return 0
Esempio n. 3
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     ident1 = new_thread()
     ident2 = new_thread()
     #
     gc.collect()
     #
     ident3 = new_thread()
     ident4 = new_thread()
     ident5 = new_thread()
     # wait for the 5 threads to finish
     while True:
         gc.collect()
         if len(state.xlist) == 5:
             break
         time.sleep(0.1)  # invokes before/after
     # check that the malloced structures were not overwritten
     assert x2.head == 51
     assert x2.tail.head == 62
     assert x2.tail.tail.head == 74
     assert x2.tail.tail.tail is None
     # check the structures produced by the threads
     for i in range(5):
         assert state.xlist[i].head == 123
         assert state.xlist[i].tail.head == 456
         assert state.xlist[i].tail.tail is None
         os.write(1, "%d ok\n" % (i + 1))
     return 0
Esempio n. 4
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     ident1 = new_thread()
     ident2 = new_thread()
     #
     gc.collect()
     #
     ident3 = new_thread()
     ident4 = new_thread()
     ident5 = new_thread()
     # wait for the 5 threads to finish
     while True:
         gc.collect()
         if len(state.xlist) == 5:
             break
         time.sleep(0.1)      # invokes before/after
     # check that the malloced structures were not overwritten
     assert x2.head == 51
     assert x2.tail.head == 62
     assert x2.tail.tail.head == 74
     assert x2.tail.tail.tail is None
     # check the structures produced by the threads
     for i in range(5):
         assert state.xlist[i].head == 123
         assert state.xlist[i].tail.head == 456
         assert state.xlist[i].tail.tail is None
         os.write(1, "%d ok\n" % (i+1))
     return 0
Esempio n. 5
0
    def test_call_release_gil(self):
        py.test.skip("xxx fix this test: the code is now assuming that "
                     "'before' is just rgil.release_gil(), and 'after' is "
                     "only needed if 'rpy_fastgil' was not changed.")
        # note that we can't test floats here because when untranslated
        # people actually wreck xmm registers
        cpu = self.cpu
        l = []
        copied_stack = [None]

        def before():
            # put nonsense on the top of shadowstack
            frame = rffi.cast(JITFRAMEPTR, cpu.gc_ll_descr.gcrootmap.stack[0])
            assert getmap(frame).count('1') == 7  #
            copied_stack[0] = cpu.gc_ll_descr.gcrootmap.stack[0]
            cpu.gc_ll_descr.gcrootmap.stack[0] = -42
            l.append("before")

        def after():
            cpu.gc_ll_descr.gcrootmap.stack[0] = copied_stack[0]
            l.append("after")

        invoke_around_extcall(before, after)

        def f(frame, x):
            # all the gc pointers are alive p1 -> p7 (but not p0)
            assert x == 1
            return 2

        FUNC = lltype.FuncType([JITFRAMEPTR, lltype.Signed], lltype.Signed)
        fptr = llhelper(lltype.Ptr(FUNC), f)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        loop = self.parse("""
        [i0, p1, p2, p3, p4, p5, p6, p7]
        p0 = force_token()
        i1 = call_release_gil(ConstClass(fptr), p0, i0, descr=calldescr)
        guard_not_forced(descr=faildescr) [p1, p2, p3, p4, p5, p6, p7]
        finish(i1, descr=finaldescr)
        """,
                          namespace={
                              'fptr': fptr,
                              'calldescr': calldescr,
                              'faildescr': BasicFailDescr(),
                              'finaldescr': BasicFinalDescr()
                          })
        token = JitCellToken()
        cpu.gc_ll_descr.init_nursery(100)
        cpu.setup_once()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        args = [lltype.nullptr(llmemory.GCREF.TO) for i in range(7)]
        frame = cpu.execute_token(token, 1, *args)
        frame = rffi.cast(JITFRAMEPTR, frame)
        assert frame.jf_frame[0] == 2
        assert l == ['before', 'after']
Esempio n. 6
0
    def test_call_release_gil(self):
        py.test.skip("xxx fix this test: the code is now assuming that "
                     "'before' is just rgil.release_gil(), and 'after' is "
                     "only needed if 'rpy_fastgil' was not changed.")
        # note that we can't test floats here because when untranslated
        # people actually wreck xmm registers
        cpu = self.cpu
        l = []
        copied_stack = [None]

        def before():
            # put nonsense on the top of shadowstack
            frame = rffi.cast(JITFRAMEPTR, cpu.gc_ll_descr.gcrootmap.stack[0])
            assert getmap(frame).count('1') == 7 #
            copied_stack[0] = cpu.gc_ll_descr.gcrootmap.stack[0]
            cpu.gc_ll_descr.gcrootmap.stack[0] = -42
            l.append("before")

        def after():
            cpu.gc_ll_descr.gcrootmap.stack[0] = copied_stack[0]
            l.append("after")

        invoke_around_extcall(before, after)

        def f(frame, x):
            # all the gc pointers are alive p1 -> p7 (but not p0)
            assert x == 1
            return 2

        FUNC = lltype.FuncType([JITFRAMEPTR, lltype.Signed], lltype.Signed)
        fptr = llhelper(lltype.Ptr(FUNC), f)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        loop = self.parse("""
        [i0, p1, p2, p3, p4, p5, p6, p7]
        p0 = force_token()
        i1 = call_release_gil(ConstClass(fptr), p0, i0, descr=calldescr)
        guard_not_forced(descr=faildescr) [p1, p2, p3, p4, p5, p6, p7]
        finish(i1, descr=finaldescr)
        """, namespace={'fptr': fptr, 'calldescr':calldescr,
                        'faildescr': BasicFailDescr(),
                        'finaldescr': BasicFinalDescr()})
        token = JitCellToken()
        cpu.gc_ll_descr.init_nursery(100)
        cpu.setup_once()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        args = [lltype.nullptr(llmemory.GCREF.TO) for i in range(7)]
        frame = cpu.execute_token(token, 1, *args)
        frame = rffi.cast(JITFRAMEPTR, frame)
        assert frame.jf_frame[0] == 2
        assert l == ['before', 'after']
Esempio n. 7
0
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if not self.gil_ready:
            self._initialize_gil(space)
            self.gil_ready = True
            result = True
        else:
            result = False  # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        invoke_around_extcall(before_external_call, after_external_call)
        return result
Esempio n. 8
0
File: gil.py Progetto: charred/pypy
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if not self.gil_ready:
            self._initialize_gil(space)
            self.gil_ready = True
            result = True
        else:
            result = False      # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        invoke_around_extcall(before_external_call, after_external_call)
        return result
Esempio n. 9
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     state.deleted = 0
     state.read_end, state.write_end = os.pipe()
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     start_arthreads()
     # force freeing
     gc.collect()
     gc.collect()
     gc.collect()
     # return everything that was written to the pipe so far,
     # followed by the final dot.
     os.write(state.write_end, '.')
     result = os.read(state.read_end, 256)
     os.write(1, "got: %s\n" % result)
     return 0
Esempio n. 10
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     state.deleted = 0
     state.read_end, state.write_end = os.pipe()
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = rthread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     start_arthreads()
     # force freeing
     gc.collect()
     gc.collect()
     gc.collect()
     # return everything that was written to the pipe so far,
     # followed by the final dot.
     os.write(state.write_end, '.')
     result = os.read(state.read_end, 256)
     os.write(1, "got: %s\n" % result)
     return 0
Esempio n. 11
0
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                time.sleep(0.01)

            time.sleep(0.1)

            return len(state.answers)
Esempio n. 12
0
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                time.sleep(0.01)

            time.sleep(0.1)

            return len(state.answers)
Esempio n. 13
0
 def f():
     os.write(write_fd, "-")
     invoke_around_extcall(before, after)
     os.write(write_fd, "E")
Esempio n. 14
0
 def init(self):
     if not self._is_inited:
         self._is_inited = True
         self._lock = rthread.allocate_lock()
         rgil.gil_allocate()
         invoke_around_extcall(before_external_call, after_external_call)
Esempio n. 15
0
 def before(n, x):
     invoke_around_extcall(func, func)
     return (n, None, None, None, None, None,
             None, None, None, None, None, None)
Esempio n. 16
0
 def before(n, x):
     invoke_around_extcall(func, func)
     return (n, None, None, None, None, None,
             None, None, None, None, None, None)
Esempio n. 17
0
 def init(self):
     if not self._is_inited:
         self._is_inited = True
         self._lock = rthread.allocate_lock()
         rgil.gil_allocate()
         invoke_around_extcall(before_external_call, after_external_call)
Esempio n. 18
0
 def f():
     os.write(write_fd, "-")
     invoke_around_extcall(before, after)
     os.write(write_fd, "E")