Importance of VMKit JIT function cache

VMKit JIT has a function cache to store compiled IR code , so, as soon as method is compiled , it will be stored in to function cache. My question is , who will use this compiled information from function cache. Since we are jitting , the llvm translate source code in to native code and executing them . So, how we relates this function cache with JIT ?



No idea about llvm but in general optimizer make use of them.


Hi Sri,

I think that I don’t understand your question :slight_smile: We have a cache.of compiled functions (native functions) and uses it to execute the Java code in the JIT. And, we do not keep the llvm representation of Java methods because we never reuse it (only in the AOT to generate the llvm bitcode file).

I hope that it helps?

Hi Gael
I am sorry that I couldn’t explain what I was trying to say, anyway I’ve got the answer :slight_smile: . In the parseFunction method returns llvmfunction pointer of compiled method and then it will be stored in to cache. Could you please more elaborate on how those machine instructions ( native functions) executing by llvm. I was trying trace and I couldn’t able to find out which component is taking those native functions and execute them once its compiled.

Thank you for your help.


Hi Sri,

Basically, we use the functions generated in MetaJIT. Basically, we
generate a stub for each Java signature to call a Java method from c++
code. If we call a method from c++ to Java, we directly use MetaJIT.h.
Otherwise, it's a little bit more complicated. For an invokeVirtual,
we use a virtual table to dispatch the call. The entry is initially
filled up with a trampoline (invokeVirtual), and replaced with the
compiled function after its compilation for the next calls. For a
special or static call, we also use an indirection. We use the code
pointer of the Java method descriptor (C++ class JavaMethod). And we
are doing almost the same thing, we initially use a trampoline and
then replace it with the compiled function. And we are using Interface
Method Dispatch for interface calls (which also use trampolines). The
trampolines retrieve the target method by using tricks (by using debug
info), and, if I remember correctly, uses the stubs generated in
MetaJIT for the first calls.

If you want to understand this part of the code, it's maybe a little bit ugly :slight_smile:

Hi Gael
           Thank you for your detailed answer, Hope I will trace out the actual work flow. Currently VMKit stores all the compiled function in the cache and calling func->deleteBody() which is basically drop all the reference and set to an external linkage. Is it possible to use executionEngine->getPointerToFunction(func) and then func->deleteBody(), so, it will drop the machine code from the memory ? How can I effectively remove the machine code which was generated for some specific Java method, for example , in the Java byte code , I want to drop the machine code to method test() { int a =0;} once generated , so that again I can compile with different optimization level and generate native code.