[LLVMdev] Possible memory leakage in the LLVM JIT Engine

George Giorgidze giorgidze at gmail.com
Fri Mar 20 07:34:29 PDT 2009


Hi,

In my application I am JITing thousands of functions, though I am doing it
sequantially and running only one at a time. So it is crucial to be able to
properly clean up the memory from an old JITed function when JITing and
running the new one.

I am using Haskell binding of LLVM and my application works OK. However,
memory usage increases and never decreases during the run time of my
application. Here is what I do:

1) I am creating a module
2) I am generating an LLVM function and putting it into the module
3) creating a module provider for the module
4) creating an execution engine for the module provider.
5) running the function (using JIT)
6) freeing machine code for the function
7) deleting the function, module, module provider, exectution engine and all
other structures created before
8) going to step 1 to JIT a new function

I know that the step number 7 is not really necessary. I tried to use the
same execution engine, but memory still leaks. I should note that if
interpreter is used instead of JIT no memmory leakage occurs.

Instead of posting my Haskell code, I though it would be better if I post
short C++ code that (hopefully) demonstrates the possible leakage. My
suspicion is that freeMachineCodeForFunction does not do its job properly.

Let us look at HowToUseJIT.cpp example that comes with LLVM source bundle
and let us modify the last lines in the following way:

  for (;;)
  {
    gv = EE->runFunction(FooF, noargs);
    // Import result of execution:
    outs() << "Result: " << gv.IntVal << "\n";
  }

Everithing works fine. However if we do the following modification:

  for (;;)
  {
    gv = EE->runFunction(FooF, noargs);
    // Import result of execution:
    outs() << "Result: " << gv.IntVal << "\n";
    EE->freeMachineCodeForFunction(FooF);
    EE->freeMachineCodeForFunction(Add1F);
  }

It works but a memory usage of the application increases continuously.

So my question is how can I clean up ALL of the memmory created by the JIT
engine?

Any pointers to a similar application that succesfully acopmlishes what I
want, i.e. does lots of JITing without memory leakage, will be very much
appreciated.

Cheers, George

-- 
George Giorgidze
http://www.cs.nott.ac.uk/~ggg/ <http://www.cs.nott.ac.uk/%7Eggg/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090320/57d88bbd/attachment.html>


More information about the llvm-dev mailing list