Telling the JIT to remove a stack array
I have an interpreter inner loop that looks something like this: jitdriver = JitDriver(greens=['ip', 'tos', 'bytecodes', 'consts'], reds=['locals', 'stack']) def interpret(code, args): assert isinstance(code, Code) bytecodes = code.bytecodes consts = code.consts vars = code.vars locals = array_of_size(code.locals) ip = 0 stack = array_of_size(code.stacksize) tos = -1 while True: jitdriver.jit_merge_point(ip=ip, tos=tos, bytecodes=bytecodes, consts=consts, locals=locals, stack=stack) op = ord(bytecodes[ip]) if op == POP: stack[tos] = None tos -= 1 ip += 1 continue elif op == PUSH_CONST: arg = ord(bytecodes[ip + 1]) tos += 1 stack[tos] = consts[arg] ip += 2 continue The jit traces from this aren't bad, but it insists on maintaining the stack and locals arrays. Since these arrays are reference arrays, my primitive types (Integers for example) are allocated when math is being performed. What can I do to force the JIT to not maintain a stack/locals array. Or should I construct the stack in a different way? I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet. Timothy
Hi Timothy, On 23 February 2014 01:24, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet.
pypy/interpreter/pyframe.py: self.locals_stack_w. The trick is that it's an attribute of a "frame" class, which is itself turned into a virtualizable with a special declaration about the attribute. See ``PyFrame._virtualizable_ = ['locals_stack_w[*]']'' in pypy/module/pypyjit/interp_jit.py. It's currently the only way to trigger special behavior about the list: you have to make it a special attribute of a virtualizable "frame" class. A bientôt, Armin.
That did the trick. My "count up" program now consists of int_eq, a guard and int_add, that's what I wanted to see. Thanks! Timothy On Sun, Feb 23, 2014 at 1:06 AM, Armin Rigo <arigo@tunes.org> wrote:
Hi Timothy,
On 23 February 2014 01:24, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet.
pypy/interpreter/pyframe.py: self.locals_stack_w. The trick is that it's an attribute of a "frame" class, which is itself turned into a virtualizable with a special declaration about the attribute. See ``PyFrame._virtualizable_ = ['locals_stack_w[*]']'' in pypy/module/pypyjit/interp_jit.py. It's currently the only way to trigger special behavior about the list: you have to make it a special attribute of a virtualizable "frame" class.
A bientôt,
Armin.
-- "One of the main causes of the fall of the Roman Empire was that-lacking zero-they had no way to indicate successful termination of their C programs." (Robert Firth)
since we managed to even write a document, please read it ;-) http://doc.pypy.org/en/latest/jit/virtualizable.html On Mon, Feb 24, 2014 at 9:37 PM, Timothy Baldridge <tbaldridge@gmail.com> wrote:
That did the trick. My "count up" program now consists of int_eq, a guard and int_add, that's what I wanted to see. Thanks!
Timothy
On Sun, Feb 23, 2014 at 1:06 AM, Armin Rigo <arigo@tunes.org> wrote:
Hi Timothy,
On 23 February 2014 01:24, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet.
pypy/interpreter/pyframe.py: self.locals_stack_w. The trick is that it's an attribute of a "frame" class, which is itself turned into a virtualizable with a special declaration about the attribute. See ``PyFrame._virtualizable_ = ['locals_stack_w[*]']'' in pypy/module/pypyjit/interp_jit.py. It's currently the only way to trigger special behavior about the list: you have to make it a special attribute of a virtualizable "frame" class.
A bientôt,
Armin.
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
That doc helped a lot, and the bit on self = hint(self...) solved several more issues. Thanks, Timothy On Mon, Feb 24, 2014 at 1:44 PM, Maciej Fijalkowski <fijall@gmail.com>wrote:
since we managed to even write a document, please read it ;-)
http://doc.pypy.org/en/latest/jit/virtualizable.html
That did the trick. My "count up" program now consists of int_eq, a guard and int_add, that's what I wanted to see. Thanks!
Timothy
On Sun, Feb 23, 2014 at 1:06 AM, Armin Rigo <arigo@tunes.org> wrote:
Hi Timothy,
On 23 February 2014 01:24, Timothy Baldridge <tbaldridge@gmail.com>
wrote:
I tried digging into the PyPy source to find how how this is done
On Mon, Feb 24, 2014 at 9:37 PM, Timothy Baldridge <tbaldridge@gmail.com> wrote: there,
but I haven't been able to find it yet.
pypy/interpreter/pyframe.py: self.locals_stack_w. The trick is that it's an attribute of a "frame" class, which is itself turned into a virtualizable with a special declaration about the attribute. See ``PyFrame._virtualizable_ = ['locals_stack_w[*]']'' in pypy/module/pypyjit/interp_jit.py. It's currently the only way to trigger special behavior about the list: you have to make it a special attribute of a virtualizable "frame" class.
A bientôt,
Armin.
-- "One of the main causes of the fall of the Roman Empire was that-lacking zero-they had no way to indicate successful termination of their C programs." (Robert Firth)
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- "One of the main causes of the fall of the Roman Empire was that-lacking zero-they had no way to indicate successful termination of their C programs." (Robert Firth)
On Mon, Feb 24, 2014 at 9:49 PM, Timothy Baldridge <tbaldridge@gmail.com> wrote:
That doc helped a lot, and the bit on self = hint(self...) solved several more issues.
I'm glad I didn't write just so we know what the semantics are ;-)
Thanks,
Timothy
On Mon, Feb 24, 2014 at 1:44 PM, Maciej Fijalkowski <fijall@gmail.com> wrote:
since we managed to even write a document, please read it ;-)
http://doc.pypy.org/en/latest/jit/virtualizable.html
On Mon, Feb 24, 2014 at 9:37 PM, Timothy Baldridge <tbaldridge@gmail.com> wrote:
That did the trick. My "count up" program now consists of int_eq, a guard and int_add, that's what I wanted to see. Thanks!
Timothy
On Sun, Feb 23, 2014 at 1:06 AM, Armin Rigo <arigo@tunes.org> wrote:
Hi Timothy,
On 23 February 2014 01:24, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I tried digging into the PyPy source to find how how this is done there, but I haven't been able to find it yet.
pypy/interpreter/pyframe.py: self.locals_stack_w. The trick is that it's an attribute of a "frame" class, which is itself turned into a virtualizable with a special declaration about the attribute. See ``PyFrame._virtualizable_ = ['locals_stack_w[*]']'' in pypy/module/pypyjit/interp_jit.py. It's currently the only way to trigger special behavior about the list: you have to make it a special attribute of a virtualizable "frame" class.
A bientôt,
Armin.
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)
participants (3)
-
Armin Rigo
-
Maciej Fijalkowski
-
Timothy Baldridge