From: <zy...@us...> - 2009-02-22 14:40:53
|
Revision: 6041 http://jython.svn.sourceforge.net/jython/?rev=6041&view=rev Author: zyasoft Date: 2009-02-22 14:40:49 +0000 (Sun, 22 Feb 2009) Log Message: ----------- Inlined PyTableCode#interpret into #call(PyFrame,PyClosure) (which restores this method to what it was before the PBC-VM work). This change restores the performance as tested by test/pystone.py. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBaseCode.java branches/pbcvm/src/org/python/core/PyTableCode.java Modified: branches/pbcvm/src/org/python/core/PyBaseCode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBaseCode.java 2009-02-19 20:16:18 UTC (rev 6040) +++ branches/pbcvm/src/org/python/core/PyBaseCode.java 2009-02-22 14:40:49 UTC (rev 6041) @@ -308,9 +308,7 @@ co_name, Py.idstr(this), co_filename, co_firstlineno); } - protected PyObject interpret(PyFrame f) { - throw new UnsupportedOperationException("interpret not supported"); - } + protected abstract PyObject interpret(PyFrame f); protected int getline(PyFrame f) { return f.f_lineno; Modified: branches/pbcvm/src/org/python/core/PyTableCode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyTableCode.java 2009-02-19 20:16:18 UTC (rev 6040) +++ branches/pbcvm/src/org/python/core/PyTableCode.java 2009-02-22 14:40:49 UTC (rev 6041) @@ -6,6 +6,8 @@ * is stored as a PyFunctionTable instance and an integer index. */ +import org.python.modules._systemrestart; + public class PyTableCode extends PyBaseCode { @@ -116,7 +118,92 @@ return super.__findattr_ex__(name); } - protected PyObject interpret(PyFrame frame) { - return funcs.call_function(func_id, frame); + @Override + public PyObject call(PyFrame frame, PyObject closure) { +// System.err.println("tablecode call: "+co_name); + ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; + } + //System.err.println("got ts: "+ts+", "+ts.systemState); + + // Cache previously defined exception + PyException previous_exception = ts.exception; + + // Push frame + frame.f_back = ts.frame; + if (frame.f_builtins == null) { + if (frame.f_back != null) { + frame.f_builtins = frame.f_back.f_builtins; + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); + frame.f_builtins = PySystemState.builtins; + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + + ts.frame = frame; + + // Handle trace function for debugging + if (ts.tracefunc != null) { + frame.f_lineno = co_firstlineno; + frame.tracefunc = ts.tracefunc.traceCall(frame); + } + + // Handle trace function for profiling + if (ts.profilefunc != null) { + ts.profilefunc.traceCall(frame); + } + + PyObject ret; + try { + ret = funcs.call_function(func_id, frame); + } catch (Throwable t) { + // Convert exceptions that occured in Java code to PyExceptions + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + + frame.f_lasti = -1; + + if (frame.tracefunc != null) { + frame.tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); + } + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; + ts.frame = ts.frame.f_back; + throw pye; + } + + if (frame.tracefunc != null) { + frame.tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { + ts.profilefunc.traceReturn(frame, ret); + } + + // Restore previously defined exception + ts.exception = previous_exception; + + ts.frame = ts.frame.f_back; + + // Check for interruption, which is used for restarting the interpreter + // on Jython + if (Thread.currentThread().isInterrupted()) { + throw new PyException(_systemrestart.SystemRestart); + } + return ret; } + + @Override + protected PyObject interpret(PyFrame f) { + throw new UnsupportedOperationException("Inlined interpret to improve call performance (may want to reconsider in the future)."); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |