lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Martin Schröder wrote:
> the Google Android thingy includes a VM (call Dalvik), which is not a
> JVM, but they have a tool to convert Java byte code to Dalvik byte
> code.
> 
> Seems like a nice platform for lua... :-)

Well, the source code for the Dalvik VM has not been released
(yet). But peeking into some Java classes and the binary of the
provided DEX disassembler suggests it's a one-to-one translation
of Java bytecode (mixed stack+locals) to DEX bytecode (pure
register machine).

Some shortcuts to reduce dispatch overhead and to avoid storing
little constants are used, too. E.g. Java's iadd translates to
DEX add-int, add-int/2addr, add-int/lit8 or add-int/lit16. Also
multiple classes are merged into a single binary blob with a
compact encoding. Native calls seem to be more efficient, too.

Ok, so the Lua lesson has been learned (register machines being
faster than stack machines). It's pretty sure to run faster than
an interpreter using the classic Java bytecodes (Dalvik doesn't
have a JIT compiler, yet). But otherwise it looks like there's
really nothing spectacularly new in Dalvik.

In other words: Dalvik has the same underlying semantics as the JVM.

I.e. it's designed for languages with static typing, it has no
concept of low-level operations (such as raw memory access), it
has a fixed representation of objects and object references and
so on. It's just as good or as bad as the JVM for implementing
dynamic languages (such as Lua). As I've explained previously,
the impedance mismatch is rather high and other restrictions (no
easy dynamic code generation) would make implementing Lua atop of
Dalvik a tedious and boring exercise.

If, on the other hand, they would add some special bytecodes for
better support of dynamic languages and some leeway with
semantics, it might be a little bit better suited. But I'm not
convinced it would excel as a platform for dynamic languages.
Still, I believe (without trying) that the plain Lua interpreter
would beat a (hypothetical) Lua on top of the current Dalvik VM
easily.

--Mike