[pypy-commit] lang-smalltalk storage: Added comments to jit.py.
anton_gulenko
noreply at buildbot.pypy.org
Mon Apr 7 19:34:50 CEST 2014
Author: Anton Gulenko <anton.gulenko at googlemail.com>
Branch: storage
Changeset: r786:426988d32a41
Date: 2014-04-07 19:34 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/426988d32a41/
Log: Added comments to jit.py. Using the methods from the main module to
execute things inside a pre-loaded image.
diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- a/spyvm/test/jit.py
+++ b/spyvm/test/jit.py
@@ -27,11 +27,14 @@
def meta_interp(func):
return jit.meta_interp(func, [], listcomp=True, listops=True, backendopt=True, inline=True)
+def load(imagename):
+ _, interp, _, _ = read_image(imagename)
+ return interp
+
# ==== The following are factories for functions to be passed into meta_interp() ====
-# This will build a small jit just for the specified message-send
-def perform(imagename, receiver, selector, *args):
- _, interp, _, _ = read_image(imagename)
+def preload_perform(imagename, receiver, selector, *args):
+ interp = load(imagename)
def interp_miniloop():
return interp.perform(receiver, selector, *args)
return interp_miniloop
@@ -39,8 +42,9 @@
# This will build a jit executing a synthetic method composed of the given bytecodes and literals,
# and operating on the given stack. The receiver of the 'message' must be at the bottom of the stack.
# The bytecodes can be composed from constants created in this module in above import_bytecodes() call.
-def execute_frame(imagename, bytes, literals, stack):
- space, interp, _, _ = read_image(imagename)
+def preload_execute_frame(imagename, bytes, literals, stack):
+ interp = load(imagename)
+ space = interp.space
w_method = model.W_CompiledMethod(space, header=512)
w_method.literals = literals
w_method.setbytes(bytes)
@@ -51,7 +55,31 @@
return interp.loop(w_frame)
return interp_execute_frame
-# This will build a JIT for the entire VM. Arguments to the VM entry-point must be provided.
+# ==== The following will pre-load images and build a jit based on methods from the entry-point module
+
+def run_benchmark(imagename, benchmark, number=0, arg=""):
+ import targetimageloadingsmalltalk
+ interp = load(imagename)
+ def interp_run_benchmark():
+ return targetimageloadingsmalltalk._run_benchmark(interp, number, benchmark, arg)
+ return interp_run_benchmarks
+
+def run_code(imagename, code, as_benchmark=False):
+ import targetimageloadingsmalltalk
+ interp = load(imagename)
+ def interp_run_code():
+ return targetimageloadingsmalltalk._run_code(interp, code, as_benchmark)
+ return interp_run_code
+
+def run_image(imagename):
+ import targetimageloadingsmalltalk
+ interp = load(imagename)
+ def interp_run_image():
+ return targetimageloadingsmalltalk._run_image(imagename)
+ return interp_run_image
+
+# ==== The following will build a JIT for the real entry-point.
+
def full_vm(args):
import targetimageloadingsmalltalk
module_file = targetimageloadingsmalltalk.__file__[:-1]
@@ -62,21 +90,23 @@
return targetimageloadingsmalltalk.entry_point(full_args)
return interp_full_vm
-def open_image(imagename, additional_args = []):
+def full_vm_image(imagename, additional_args = []):
args = ["images/" + imagename]
args.extend(additional_args)
return full_vm(args)
-def run_vm_code(imagename, code):
- return open_image(imagename, ['-r', code])
+def full_vm_code(imagename, code):
+ return full_vm_image(imagename, ['-r', code])
-def execute_vm_method(imagename, selector, receiver_num=None, string_arg=None):
+def full_vm_method(imagename, selector, receiver_num=None, string_arg=None):
args = ['-m', selector]
if string_arg:
args.extend(['-a', string_arg])
if receiver_num:
args.extend(['-n', receiver_num])
- return open_image(imagename, args)
+ return full_vm_image(imagename, args)
+
+# ==== The Main coordinates above methods
def main():
# ===== First define which image we are going to use.
@@ -84,21 +114,25 @@
# imagename = "minitest.image"
# imagename = "Squeak4.5-noBitBlt.image"
- # ===== These entry-points pre-load the image and execute just a single frame.
- # func = perform(imagename, model.W_SmallInteger(1000), 'loopTest2')
- func = perform(imagename, model.W_SmallInteger(777), 'name')
- # func = execute_frame(imagename, [returnReceiver], [], [model.W_SmallInteger(42)])
+ # ===== These entry-points pre-load the image and directly execute a single frame.
+ # func = preload_perform(imagename, model.W_SmallInteger(1000), 'loopTest2')
+ # func = preload_perform(imagename, model.W_SmallInteger(777), 'name')
+ # func = preload_execute_frame(imagename, [returnReceiver], [], [model.W_SmallInteger(42)])
# ===== These execute the complete interpreter
- # XXX These do not work because loading the image file while meta-interpreting always leads to
- # a 'Bad file descriptor' error.
- # func = execute_vm_method("mini.image", "name", 33)
- # func = run_vm_code(imagename, "^5+6")
- # func = execute_vm_method(imagename, "name", 33)
- # func = open_image(imagename)
+ # ===== XXX These do not work because loading the image file while meta-interpreting always leads to
+ # ===== a 'Bad file descriptor' error.
+ # func = full_vm_code(imagename, "^5+6")
+ # func = full_vm_method(imagename, "name", 33)
+ # func = full_vm_image(imagename)
+
+ # ==== These entry-points pre-load the image and then use methods from the entry-point module.
+ # ==== This is very close to what actually happens in the VM, but with a pre-loaded image.
+ # func = run_benchmark(imagename, "loopTest2", 10000)
+ func = run_code(imagename, "^6+7")
+ # func = run_image(imagename)
# ===== Now we can either simply execute the entry-point, or meta-interpret it (showing all encountered loops).
- # import pdb; pdb.set_trace()
# res = func()
res = meta_interp(func)
print_result(res)
More information about the pypy-commit
mailing list