[LLVMdev] Possible memory leakage in the LLVM JIT Engine

Aaron Gray aaronngray.lists at googlemail.com
Mon Mar 23 06:36:41 PDT 2009


Graham,

This patch maybe helpful :-

    http://llvm.org/bugs/show_bug.cgi?id=2608

There's a JITResolver::removeFunction() added to JITEmitter::deallocateMemoryForFunction()

It looks like there is also some other work being done on this area at the moment, check SVN.

Aaron
  ----- Original Message ----- 
  From: Graham Wakefield 
  To: LLVM Developers Mailing List 
  Sent: Sunday, March 22, 2009 11:30 PM
  Subject: Re: [LLVMdev] Possible memory leakage in the LLVM JIT Engine


  Hi,


  Was this ever resolved? 


  I'm curious, I'm also in a situation where there may be many (very many) JITted functions over the history of an application (which may be running for many days)


  Thanks


  On Mar 20, 2009, at 7:34 AM, George Giorgidze wrote:


    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/
    _______________________________________________
    LLVM Developers mailing list
    LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
    http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





------------------------------------------------------------------------------


  _______________________________________________
  LLVM Developers mailing list
  LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
  http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090323/31e218da/attachment.html>


More information about the llvm-dev mailing list