Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

First fully functional JIT compiler for AngelScript available


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 15 February 2012 - 04:28 PM

The developers at Blind Mind Studios have implemented the first fully functional JIT compiler for AngelScript.

It is now available to the public as an open source project, with the master repository hosted at github.com.

https://github.com/BlindMindStudios/AngelScript-JIT-Compiler


I haven't had a chance to test it myself, but what Andrew (Thy Reaper) tells me is quite impressive. With the JIT compiler the performance typically improves between 1.5 to 3 times, and in some cases even reaches levels of native C++ code.

This is especially impressive because the JIT compiler itself is implemented in relatively few lines of code, which makes it perfect for embedding.


Currently the JIT compiler only supports x86, but I'm sure it can be quite easily extended to other CPUs as well.



Post your impressions here.

Also, if there are suggestions for further improving AngelScript to make the JIT compiled code even better I'd love to hear them.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6974

Like
0Likes
Like

Posted 15 February 2012 - 04:39 PM

This. is. cool.

One of these days I plan on using AngelScript... I just need to find a need for scripting first... and for that to happen I need to stop doing homework and work on hobby projects, but the homework never ends...

Anyway, I'm excited to use this in the future! Thanks Andreas (for AngleScript) and Blind Mind Studios (for the JIT compiler)!
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#3 InvalidPointer   Members   -  Reputation: 1409

Like
0Likes
Like

Posted 15 February 2012 - 09:17 PM

This. is. cool.

QFE.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#4 _Vicious_   Members   -  Reputation: 240

Like
0Likes
Like

Posted 15 February 2012 - 11:46 PM

wow, that's impressive! the only gripe I have about it is that it depends on C++0x but that's not a critical thing, probably

#5 TheAtom   Members   -  Reputation: 330

Like
0Likes
Like

Posted 16 February 2012 - 11:06 AM

Those tests are not rigorous, but still telling:
Large loop with raw arithmetic: 4 times faster.
Constructing and traversing a large "random" binary tree: 2 times faster (expected more here, no native calls are involved).
Bubblesort of ints array (with stock array addon): around 2.5 times faster.

I haven't had the chance to test it in production yet - first I have to eliminate the reliance on std::function as StlPort does not support it - but it appears very promising.

#6 ThyReaper   Members   -  Reputation: 462

Like
0Likes
Like

Posted 16 February 2012 - 12:04 PM

Hello everyone, I'm the owner of Blind Mind Studios, and responsible for the JIT. If you have any questions or suggestions, let me know.

Those tests are not rigorous, but still telling:
Large loop with raw arithmetic: 4 times faster.
Constructing and traversing a large "random" binary tree: 2 times faster (expected more here, no native calls are involved).
Bubblesort of ints array (with stock array addon): around 2.5 times faster


The binary tree is going slower than you might expect because the JIT doesn't natively handle context switches, for a variety of reasons. Any time a script function is called, the JIT has to return to the AngelScript context for it to allocate stack memory, locate pointers, etc. In the case of native calls, on the other hand, many are completely handled by the JIT.

wow, that's impressive! the only gripe I have about it is that it depends on C++0x but that's not a critical thing, probably


The primary use of C++0x is for lambdas due to so much use of local variables for the psuedo-assembly (each pseudo-register being a stack local variable).

Anyway, I'm excited to use this in the future! Thanks Andreas (for AngleScript) and Blind Mind Studios (for the JIT compiler)!


You're welcome!

#7 ekimr   Members   -  Reputation: 107

Like
0Likes
Like

Posted 16 February 2012 - 12:35 PM

You guys are awesome! Thank you so much for this contribution.
Rantings, ravings, and occasional insight from your typical code-monkey: http://angryprogrammingprimate.blogspot.com/

#8 Tzarls   Members   -  Reputation: 844

Like
0Likes
Like

Posted 08 August 2012 - 09:30 PM

I think I´ve found a potential problem in the way the JIT is implemented in Angelscript. Blind Mind Studios´ web site shows a sample code for use with their JIT:

[source lang="java"]int main() { asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); //Create the JIT Compiler. The build flags are explained below, //as well as in as_jit.h asCJitCompiler* jit = new asCJITCompiler(0); //Enable JIT helper instructions; without these, //the JIT will not be invoked engine->SetEngineProperty(asEP_INCLUDE_JIT_INSTRUCTIONS, 1); //Bind the JIT compiler to the engine engine->SetJITCompiler(jit);//.............Setup some other stuff, compile and execute your scripts.....//Clean up your engine. Code pages will automatically be cleared //by the JIT when the engine is released. DiscardModules(); engine->Release(); delete jit; return 0;}[/source]

The problem is in the last lines: when we call engine->Release(), we´re not destroying the engine, we´re just telling it that we won´t hold a reference to it anymore. The engine might continue to exist for some undefined time. Then we destroy (delete) jit, which actually destroys the JIT compiler (which is kind of the correct thing to do, otherwise we might be leaking memory). What if after that the engine (which still might be alive) tries to access the now defunct JIT? Crash! I think the JIT should also be a reference counted object.

Edited by Tzarls, 08 August 2012 - 09:32 PM.


#9 quarnster   Members   -  Reputation: 266

Like
0Likes
Like

Posted 09 August 2012 - 12:06 AM

I think I´ve found a potential problem in the way the JIT is implemented in Angelscript. Blind Mind Studios´ web site shows a sample code for use with their JIT:

[source lang="java"]int main() { asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); //Create the JIT Compiler. The build flags are explained below, //as well as in as_jit.h asCJitCompiler* jit = new asCJITCompiler(0); //Enable JIT helper instructions; without these, //the JIT will not be invoked engine->SetEngineProperty(asEP_INCLUDE_JIT_INSTRUCTIONS, 1); //Bind the JIT compiler to the engine engine->SetJITCompiler(jit);//.............Setup some other stuff, compile and execute your scripts.....//Clean up your engine. Code pages will automatically be cleared //by the JIT when the engine is released. DiscardModules(); engine->Release(); delete jit; return 0;}[/source]

The problem is in the last lines: when we call engine->Release(), we´re not destroying the engine, we´re just telling it that we won´t hold a reference to it anymore. The engine might continue to exist for some undefined time. Then we destroy (delete) jit, which actually destroys the JIT compiler (which is kind of the correct thing to do, otherwise we might be leaking memory). What if after that the engine (which still might be alive) tries to access the now defunct JIT? Crash! I think the JIT should also be a reference counted object.


IMO you should just call SetJITCompiler(NULL);

/f

#10 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 09 August 2012 - 09:22 AM

Alternatively you could store the jitcompiler as the script engine's user data, and register a cleanup function with the engine to delete the jitcompiler when the engine is deleted.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#11 Tzarls   Members   -  Reputation: 844

Like
0Likes
Like

Posted 13 August 2012 - 05:00 PM

IMO you should just call SetJITCompiler(NULL);

/f


I don´t know if that´s a good idea - it should work only if Angelscript checks the jitCompiler pointer for NULLness and act accordingly.

#12 Tzarls   Members   -  Reputation: 844

Like
0Likes
Like

Posted 13 August 2012 - 05:05 PM

Alternatively you could store the jitcompiler as the script engine's user data, and register a cleanup function with the engine to delete the jitcompiler when the engine is deleted.


The problem I see with this approach is that since one JIT compiler can serve many engines (Blind Mind Studios´ does) in a multi engine scenario it would be a problem to decide which of the engines has to delete the jitCompiler. So I still think that making the JIT a reference counted object might solve all that issues - the engines themselves would release such references when it is safe to do so. Of course the programmer should remember to release the original reference (the one created when he JIT was first constructed).

#13 Apmyp   Members   -  Reputation: 114

Like
0Likes
Like

Posted 24 August 2012 - 04:53 AM

I tried to add this JIT compiler to my project and got may errors with std::function in MSVC 9 in as_jit.cpp .. Could you say me what I am doing wrong?

#14 saejox   Members   -  Reputation: 714

Like
1Likes
Like

Posted 24 August 2012 - 05:31 AM

JIT needs c++11. lambda, auto, function
vc9 not supported.

#15 Apmyp   Members   -  Reputation: 114

Like
0Likes
Like

Posted 24 August 2012 - 05:33 AM

saejox, thank you! you are opened my eyes, really)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS