Eclipse OMR - JitBuilder Demo1 (Continued from Simple)

In " Eclipse OMR - JitBuilder Demo1 (Simple) ", we learned how a simple JIT function is implemented.

In this Simple example, a function increment is dynamically implemented and compiled into machine code in memory.

Since the compiled machine code is in memory, can it be saved to a local file to form an obj file? Of course it is possible, and today we will see how it is achieved.

First look at the contents of the Makefile

https:/github.com/eclipse/omr/blob/380ed9131a4251d283962d296907614bf5be65ce/jitbuilder/release/Makefile#L306-L307

increment.o : simple
	TR_Options='enableObjectFileGeneration,objectFile=increment.o' ./simple

Define TR_Options, specify the name of the obj file as increment.o in TR_Options, and then run simple.

When you run simple, you will find that the increment.o file is generated. So how to use this obj file?

or look at the code first

https://github.com/eclipse/omr/blob/380ed9131a4251d283962d296907614bf5be65ce/jitbuilder/release/src/UseIncrement.c#L25

extern int32_t increment(int32_t);

int main(int argc, char *argv[]) {
	int32_t v;
	v = 0; printf("increment(%d) == %d\n", v, increment(v));
	v = 1; printf("increment(%d) == %d\n", v, increment(v));
	v = 10; printf("increment(%d) == %d\n", v, increment(v));
	v = -15; printf("increment(%d) == %d\n", v, increment(v));
	printf("STATIC TEST PASS\n");
	return 0;
}

Use the C language keyword extern to define this function (of course, when compiling, you need to link the increment.o file).

What's the point of fiddling around like that?

As long as you use a little imagination, you will understand: we think of the increment function as a very complex function - a JIT of a dynamic language, such as the JIT of PHP language, and the above routine can be used to compile PHP code into native exe .

If you have learned the principle of compilation, this is actually AOT.

A specific example of AOT: The operation of Java programs usually requires the installation of JRE or JDK first. In the past, people often wanted to implement this function. Can they run Java programs without installing JRE? AOT is required to achieve this function.

Of course, implementing AOT in Java is an extremely complex job, but now it's finally here:

http://mail.openjdk.java.net/pipermail/hotspot-dev/2016-October/025033.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325466065&siteId=291194637