Stack value extractor in Java
Rémi Forax
forax at univ-mlv.fr
Sat Nov 6 11:38:25 PDT 2010
I've wanted to write that several times, so before doing something else,
I want to try to convince all VM hackers that they should stop doing
what they currently do and starts to implement a way to export
values from the VM stack into a Java object.
Here is the problem, a lot of unknown and unused languages like Ruby,
Python,
Javascript (and I think also Groovy [1]) aren't typecheckable, at least
under the
following definition.
To be typeckable, for all operations, the following should be true:
rv = op(v1, v2, ... , vi) with v1 ... vi of type T1 ... Ti and rv of type U
rv2 = op(w1, w2, .... wi) with w1 ... wi of type T1 ... Ti and rv2 of type V
then U == V
This is not true in Ruby because of the way integer overflow are handled.
By example, c = a + b with a and b of type FixNum, c can be a FixNum
or a BigNum depending on the *value* of a and b.
The way to implement that knowing that integer operations rarely overflow
is to generate a bytecode using ints and to escape to the interpreter
if there is an overflow. This trick is by example implemented in nanojit
[2].
But this trick can not be used by JVM languages because there is no
way to get the values stored in the VM stack in order to replay
the operation in the interpreter.
I think we need something like that:
class StackTrace {
public static StackTrace getCurrentStackTrace() { ... }
public int getStackSize() { ... }
public Object getStackValue(int index);
public int getLocalSize() { ... }
public Object getLocalValue(int index);
}
Having this API implemented will really really improve the perf.
Rémi
[1] http://jira.codehaus.org/browse/GROOVY-3991
[2] https://developer.mozilla.org/En/Nanojit
More information about the mlvm-dev
mailing list