OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 7:35 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: creating a jit compiler
PostPosted: Mon Jun 20, 2011 2:00 am 
Offline
Member
Member

Joined: Fri Oct 24, 2008 12:34 pm
Posts: 50
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?


Top
 Profile  
 
 Post subject: Re: creating a jit compiler
PostPosted: Mon Jun 20, 2011 2:36 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
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.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: creating a jit compiler
PostPosted: Mon Jun 20, 2011 4:22 am 
Offline
Member
Member

Joined: Fri Oct 24, 2008 12:34 pm
Posts: 50
Quote:
Anyway, the CPU is only capable of executing native code...


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:

Quote:
push ebx
mov ebx,12
...


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 code

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


Top
 Profile  
 
 Post subject: Re: creating a jit compiler
PostPosted: Mon Jun 20, 2011 4:38 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group