hi
how can i create a jit (just-in-time) compiler manually with out using any 3rd party library? (in linux and win32)
i can create byte-code (in x86 asm) form my input script language but how can i run it?
creating a jit compiler
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: creating a jit compiler
I would start by reading a book on compiler theory (and perhaps a few others on computer science in general; you should have easily deduced the general idea even without much knowledge of how things work, programmers don't usually need to be told).
Anyway, the CPU is only capable of executing native code. There are two classic types of compilers: AOT (most compilers you know) and interpreters (they work much like emulators). What you want to do is to have your compiler run at runtime (usually, using self-modifying code), a combination of the two techniques. The advantage of JIT compilers is that they can do certain optimizations such as runtime profiling. Because they can be slow until the translation is complete, you will have to choose your algorithms carefully (they need to be able to perform in real-time) and you'll also probably want to cache the results and use them again later.
Anyway, the CPU is only capable of executing native code. There are two classic types of compilers: AOT (most compilers you know) and interpreters (they work much like emulators). What you want to do is to have your compiler run at runtime (usually, using self-modifying code), a combination of the two techniques. The advantage of JIT compilers is that they can do certain optimizations such as runtime profiling. Because they can be slow until the translation is complete, you will have to choose your algorithms carefully (they need to be able to perform in real-time) and you'll also probably want to cache the results and use them again later.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: creating a jit compiler
i know this and compiler theory but how can i execute a code at run time. for example how can i run the following code:Anyway, the CPU is only capable of executing native code...
What I want to do is strip out the VM and execute native machine code on the fly. i read about it (jit compilers) and i found several libraries like as libjit and gnu lightning. but i don't want use this libraries for executing or generating native codepush ebx
mov ebx,12
...
and also i found a thread in stackoverflow.com that says how run this codes in linux but how can i do this linux?
http://stackoverflow.com/questions/5986 ... t-compiler
Re: creating a jit compiler
basically, you allocate a piece of memory, mark it as executable (VirtualProtect on Windows, mmap on Linux)
You then write the generated code into that piece of memory, including any stubs
and call stub_address
You then write the generated code into that piece of memory, including any stubs
and call stub_address