Java wrapper for LuaJIT?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Java wrapper for LuaJIT?

Qu0ll

Does anyone know of a Java wrapper for LuaJIT?  I am looking for the absolute fastest way to script my Java apps.

 

Thanks,

 

-JCT

Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

steve donovan
On Mon, Aug 17, 2009 at 7:20 AM, John C. Turnbull
<[hidden email]> wrote:
>
> Does anyone know of a Java wrapper for LuaJIT?  I am looking for the absolute fastest way to script my Java apps.

I haven't tried it, but you should be able to build LuaJava against
LuaJIT, the external API is just the same.

If you're on Windows, I can provide the binary .dll, it's pretty
straightforward on Linux x86 (doesn't do i86_64, sorry) just use the
liblua.a from LuaJIT in the build.

steve d.
Reply | Threaded
Open this post in threaded view
|

RE: Java wrapper for LuaJIT?

Qu0ll
Hi Steve,

Thanks for the info - I'll try to build against the current LuaJIT.  Could
you please send me the Windows DLL you referred to?

Thanks,

John

> -----Original Message-----
> From: [hidden email] [mailto:lua-
> [hidden email]] On Behalf Of steve donovan
> Sent: Monday, 17 August 2009 16:28
> To: Lua list
> Subject: Re: Java wrapper for LuaJIT?
>
> On Mon, Aug 17, 2009 at 7:20 AM, John C. Turnbull
> <[hidden email]> wrote:
> >
> > Does anyone know of a Java wrapper for LuaJIT?  I am looking for the
> absolute fastest way to script my Java apps.
>
> I haven't tried it, but you should be able to build LuaJava against
> LuaJIT, the external API is just the same.
>
> If you're on Windows, I can provide the binary .dll, it's pretty
> straightforward on Linux x86 (doesn't do i86_64, sorry) just use the
> liblua.a from LuaJIT in the build.
>
> steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

steve donovan
On Mon, Aug 17, 2009 at 9:10 AM, John C. Turnbull<[hidden email]> wrote:
> Thanks for the info - I'll try to build against the current LuaJIT.  Could
> you please send me the Windows DLL you referred to?

Assuming you have the JDK and a C compiler, then that's all you need,
plus LuaJIT source.  I mentioned the dll in case you were having
difficulties building LuaJava yourself.

steve d.
Reply | Threaded
Open this post in threaded view
|

RE: Java wrapper for LuaJIT?

Qu0ll
> Assuming you have the JDK and a C compiler, then that's all you need,
> plus LuaJIT source.  I mentioned the dll in case you were having
> difficulties building LuaJava yourself.

Ah, OK thanks - I'll get it a go.

John

Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

Mike Pall-6
In reply to this post by steve donovan
steve donovan wrote:
> John C. Turnbull wrote:
> > Does anyone know of a Java wrapper for LuaJIT?  I am looking for the absolute fastest way to script my Java apps.
>
> I haven't tried it, but you should be able to build LuaJava against
> LuaJIT, the external API is just the same.

Please note that LuaJava uses JNI for calls from Java to Lua or
back from Lua into Java. It's well known that JNI is *slow*. And
LuaJava also has to serialize/unserialize all values passed across
the Lua/Java boundary.

Neither Java's JIT compiler, not LuaJIT will be able to speed this
process up. The more often you cross the language boundary, the
more performance loss this incurs. E.g. repeatedly calling a Lua
method from inside a Java loop (or vice versa) is a bad idea.
Alas, this more or less rules out many good use cases for
scripting a Java application.

You really need to stay in *either* the Java domain *or* the Lua
domain for as long as possible. A long running loop in pure Lua
will definitely benefit from the use of LuaJIT. But if you're just
running a couple of instructions on either side, you're not going
to see much of a difference. So, please don't be disappointed of
the results.

If you have a large Java code base, it may be a better choice to
look for a scripting language which stays inside the Java domain
(i.e. generates Java classes at runtime) and thus doesn't have to
use JNI.

[Note that this is not a critique of either LuaJava or JNI. The
use of JNI is a design decision of LuaJava. And the performance of
JNI simply reflects the inherent impedance mismatch between the
Java and the C side.]

--Mike
Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

steve donovan
On Mon, Aug 17, 2009 at 2:49 PM, Mike Pall<[hidden email]> wrote:
> If you have a large Java code base, it may be a better choice to
> look for a scripting language which stays inside the Java domain
> (i.e. generates Java classes at runtime) and thus doesn't have to
> use JNI.

I did indicate to John privately that calls between Lua and Java are
not going to be fast. For scripting glue, that is acceptable, I
suppose - but he did say _fast_ ;)

There is at least one pure Java implementation of Lua (Kahlua) which
I'm aware of.  Their niche is smart phones.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

Philippe Lhoste
On 17/08/2009 14:58, steve donovan wrote:
> There is at least one pure Java implementation of Lua (Kahlua) which
> I'm aware of.  Their niche is smart phones.

Yes, looks like a viable solution as the JVM isn't too bad and has its own JIT compiler
(HotSpot if I am not mistaken).

I wonder if Kahlua can benefit of new Java 7 JVM improvements for dynamic languages...

Although I don't know/recall if Kahlua is generating Java bytecode out of Lua code or if
it is interpreting Lua bytecode with its own Lua interpreter. In the latter case, it might
not gain as much a performance boost from HotSpot nor latest features.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --

Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

Kristofer Karlsson
Kahlua does not generate bytecode, it's a plain bytecode interpreter.
I also doubt it benefits much from the JIT, it would be very hard for it to optimize for it or do any sort of predictions.

Still, my own benchmarks (possibly not fair or measuring the right thing) show it to be about the same speed as LuaJ, much faster than MiniJoe, Groovy, Cajuscript and Rhino, and about 30 times slower than plain Java.

On Mon, Aug 17, 2009 at 6:06 PM, Philippe Lhoste <[hidden email]> wrote:
On 17/08/2009 14:58, steve donovan wrote:
There is at least one pure Java implementation of Lua (Kahlua) which
I'm aware of.  Their niche is smart phones.

Yes, looks like a viable solution as the JVM isn't too bad and has its own JIT compiler (HotSpot if I am not mistaken).

I wonder if Kahlua can benefit of new Java 7 JVM improvements for dynamic languages...

Although I don't know/recall if Kahlua is generating Java bytecode out of Lua code or if it is interpreting Lua bytecode with its own Lua interpreter. In the latter case, it might not gain as much a performance boost from HotSpot nor latest features.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

Florian Weimer
In reply to this post by Mike Pall-6
* Mike Pall:

> Please note that LuaJava uses JNI for calls from Java to Lua or
> back from Lua into Java. It's well known that JNI is *slow*.

Have you recently benchmarked Hotspot? 8-) It's not that bad anymore.
Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

David Manura
In reply to this post by Kristofer Karlsson
On Mon, Aug 17, 2009 at 3:08 PM, Kristofer Karlsson wrote:
> Kahlua does not generate bytecode, it's a plain bytecode interpreter.
> I also doubt it benefits much from the JIT, it would be very hard for it to
> optimize for it or do any sort of predictions.
>
> Still, my own benchmarks (possibly not fair or measuring the right thing)
> show it to be about the same speed as LuaJ, much faster than MiniJoe,
> Groovy, Cajuscript and Rhino, and about 30 times slower than plain Java.

The list of known Lua implementations in Java are in [1].

Perhaps yet another way to go about this is to translate Lua code into
Lua API code (like lua2c) or Lua bytecode (like luac2c) or maybe even
LuaJIT2 bytecode, but instead of binding it to C Lua, bind it to one
of the Java implementations of Lua.  I've heard that Mochalua is
"(slavishly) true to the C API" [2].  If so, it shouldn't be much work
to patch lua2c to work with Mochalua, for example.  However, see
"limitations" (e.g. coroutines).

[1] http://lua-users.org/wiki/LuaImplementations
[2] http://lua-users.org/lists/lua-l/2008-11/msg00319.html
Reply | Threaded
Open this post in threaded view
|

Re: Java wrapper for LuaJIT?

Nodir Temirkhodjaev
In reply to this post by Qu0ll
Another option: https://pnuts.dev.java.net/

Pnuts is a script language for Java environment.

- Simple and clean syntax
- Dynamic/static translation to JVM bytecode
- One of the fastest scripting language implementations on JVM
...