[pypy-commit] lang-smalltalk default: add jitdriver, fix translation
lwassermann
noreply at buildbot.pypy.org
Thu Feb 14 15:53:44 CET 2013
Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch:
Changeset: r26:cee7d1098087
Date: 2013-02-14 14:52 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/cee7d1098087/
Log: add jitdriver, fix translation
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -5,6 +5,7 @@
from spyvm import conftest
from spyvm import wrapper
+from rpython.rlib import jit
from rpython.rlib import objectmodel, unroll
class MissingBytecode(Exception):
@@ -16,11 +17,19 @@
class IllegalStoreError(Exception):
"""Illegal Store."""
+def get_printable_location(self, pc, w_method):
+ return '%d: %s' % (pc, w_method.bytes[pc])
+
class Interpreter(object):
_w_last_active_context = None
cnt = 0
_last_indent = ""
+ jit_driver = jit.JitDriver(
+ greens = ['self', 'pc', 'w_method'],
+ reds = ['s_active_context'],
+ get_printable_location = get_printable_location
+ )
def __init__(self, space, image_name=""):
self._w_active_context = None
@@ -81,15 +90,18 @@
bytecodeimpl(s_active_context, self)
def loop(self):
- # we_are_translated returns false on top of CPython and true when
- # translating the interpreter
- if not objectmodel.we_are_translated():
- step = Interpreter.step
- else:
- step = bytecode_step_translated
while True:
s_active_context = self.s_active_context()
- step(self, s_active_context)
+ pc = s_active_context._pc
+ w_method = s_active_context.w_method()
+
+ self.jit_driver.jit_merge_point(
+ self = self,
+ pc = pc,
+ w_method = w_method,
+ s_active_context = s_active_context)
+
+ self.step(s_active_context)
class ReturnFromTopLevel(Exception):
@@ -461,7 +473,6 @@
def bytecodePrimPointY(self, interp):
self._sendSelfSelector("y", 0, interp)
-
BYTECODE_RANGES = [
( 0, 15, "pushReceiverVariableBytecode"),
( 16, 31, "pushTemporaryVariableBytecode"),
@@ -578,3 +589,8 @@
return miniglob["bytecode_step_translated"]
bytecode_step_translated = make_bytecode_dispatch_translated()
+
+# we_are_translated returns false on top of CPython and true when
+# translating the interpreter
+# if objectmodel.we_are_translated():
+Interpreter.step = bytecode_step_translated
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -174,7 +174,8 @@
pass
# XXX is math allowed here?
import math
- bytes_len = max(4, int(math.log(val, 0xff)) + 1)
+ bytes_len = int(math.log(val) / math.log(0xff)) + 1
+ bytes_len = 4 if 4 > bytes_len else bytes_len
w_result = model.W_BytesObject(self.classtable['w_LargePositiveInteger'], bytes_len)
for i in range(bytes_len):
w_result.setchar(i, chr(intmask((val >> i*8) & 255)))
diff --git a/spyvm/targettinybenchsmalltalk.py b/spyvm/targettinybenchsmalltalk.py
--- a/spyvm/targettinybenchsmalltalk.py
+++ b/spyvm/targettinybenchsmalltalk.py
@@ -3,6 +3,8 @@
from spyvm import model, interpreter, primitives, shadow, constants
from spyvm.tool.analyseimage import create_squeakimage
+from rpython.jit.codewriter.policy import JitPolicy
+
# This loads the whole mini.image in advance. At run-time,
# it executes the tinyBenchmark. In this way we get an RPython
# "image" frozen into the executable, mmap'ed by the OS from
@@ -44,7 +46,7 @@
try:
while True:
counter += 1
- interp.step()
+ interp.interpret()
if counter == 100000:
counter = 0
os.write(2, '#')
@@ -60,3 +62,6 @@
def target(*args):
return entry_point, None
+
+def jitpolicy(driver):
+ return JitPolicy()
\ No newline at end of file
More information about the pypy-commit
mailing list