Jump to content
  • Advertisement
Sign in to follow this  
WitchLord

First fully functional JIT compiler for AngelScript available

This topic is 2220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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)!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!