<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>Was this ever resolved? </div><div><br></div><div>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)</div><div><br></div><div>Thanks</div><div><br><div><div>On Mar 20, 2009, at 7:34 AM, George Giorgidze wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<br><br>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.<br> <br>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:<br><br><span style="font-family: courier new,monospace;">1) I am creating a module</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">2) I am generating an LLVM function and putting it into the module</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">3) creating a module provider for the module</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">4) creating an execution engine for the module provider.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">5) running the function (using JIT)</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">6) freeing machine code for the function</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">7) deleting the function, module, module provider, exectution engine and all other structures created before</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">8) going to step 1 to JIT a new function</span><br style="font-family: courier new,monospace;"><br>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.<br> <br>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.<br> <br>Let us look at HowToUseJIT.cpp example that comes with LLVM source bundle and let us modify the last lines in the following way:<br><br><span style="font-family: courier new,monospace;">  for (;;)</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">  {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    gv = EE->runFunction(FooF, noargs);</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">    // Import result of execution:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    outs() << "Result: " << gv.IntVal << "\n";</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">  }</span><br style="font-family: courier new,monospace;"><br>Everithing works fine. However if we do the following modification:<br><br><span style="font-family: courier new,monospace;">  for (;;)</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">  {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    gv = EE->runFunction(FooF, noargs);</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">    // Import result of execution:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    outs() << "Result: " << gv.IntVal << "\n";</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">    EE->freeMachineCodeForFunction(FooF);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    EE->freeMachineCodeForFunction(Add1F);</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">  }</span><br style="font-family: courier new,monospace;"><br>It works but a memory usage of the application increases continuously.<br><br>So my question is how can I clean up ALL of the memmory created by the JIT engine?<br> <br>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.<br><br>Cheers, George<br><br>-- <br>George Giorgidze<br><a href="http://www.cs.nott.ac.uk/%7Eggg/" target="_blank">http://www.cs.nott.ac.uk/~ggg/</a><br> _______________________________________________<br>LLVM Developers mailing list<br>LLVMdev@cs.uiuc.edu         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br></div></body></html>