<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16809" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"
bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Graham,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This patch maybe helpful :-</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> </FONT><FONT face=Arial
size=2><A
href="http://llvm.org/bugs/show_bug.cgi?id=2608">http://llvm.org/bugs/show_bug.cgi?id=2608</A></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>There's a JITResolver::removeFunction() added to
JITEmitter::deallocateMemoryForFunction()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>It looks like there is also some other work being
done on this area at the moment, check SVN.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Aaron</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=lists@grahamwakefield.net
href="mailto:lists@grahamwakefield.net">Graham Wakefield</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=llvmdev@cs.uiuc.edu
href="mailto:llvmdev@cs.uiuc.edu">LLVM Developers Mailing List</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, March 22, 2009 11:30
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [LLVMdev] Possible memory
leakage in the LLVM JIT Engine</DIV>
<DIV><BR></DIV>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>
<P>
<HR>
<P></P>_______________________________________________<BR>LLVM Developers
mailing
list<BR>LLVMdev@cs.uiuc.edu
http://llvm.cs.uiuc.edu<BR>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<BR></BLOCKQUOTE></BODY></HTML>