<br><br><div class="gmail_quote">On 12 February 2010 01:48, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@mit.edu">rnk@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On Thu, Feb 11, 2010 at 6:53 PM, James Williams <<a href="mailto:junk@giantblob.com">junk@giantblob.com</a>> wrote:<br>
> Hi,<br>
><br>
> I'm seeing rather high memory usage from LLVM and I'd like to track down<br>
> what I'm doing to cause it. My application is a simple web application<br>
> server that compiles web pages with embedded script to bitcode and compiles<br>
> them with the JIT on demand. I've taken tools/lli.cpp as a starting point<br>
> and extended it to load additional modules.<br>
><br>
> However, if I load successive pages and watch top, my RSS size increases by<br>
> roughly 40 times the on disk size of the loaded bit code for each loaded<br>
> module, which I take to mean I have a massive leak. I'm probably just not<br>
> freeing stuff that I ought to but I don't know what - deleting the<br>
> MemoryBuffer or ModuleProvider results in a SEGV. I've read the doxygen docs<br>
> but I'm not clear what objects have allocated what memory for what purpose,<br>
> what can be freed once all functions in a module have been compiled or how<br>
> to do this.<br>
><br>
> I'd be grateful if anyone could tell me what I'm doing wrong or point me at<br>
> docs or examples covering this topic? The gist of my code is:<br>
><br>
> Module *load_module(char *bitcode_name) {<br>
>   MemoryBuffer *buffer = MemoryBuffer::getFile(bitcode_name,<br>
> &error_message);<br>
>   ModuleProvider *mp = getBitcodeModuleProvider(buffer, getGlobalContext(),<br>
> &error_message);<br>
><br>
>   if( first_time ) {<br>
>       InitializeNativeTarget();<br>
>       builder = new EngineBuilder(mp);<br>
>       builder->setEngineKind(EngineKind::JIT);<br>
>       CodeGenOpt::Level opt_level = CodeGenOpt::Default;<br>
>       builder->setOptLevel(opt_level);<br>
>       execution_engine = builder->create();<br>
>       delete(builder);       // lli doesn't do this - is it safe?<br>
<br>
</div></div>lli allocates the builder on the stack, so it is automatically<br>
destroyed on scope exit.<br></blockquote><div>OK. My C++ is very rusty! <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
>   }<br>
><br>
>   Module *module = mp->materializeModule(&error_message);<br>
>   for (Module::iterator I = module->begin(), E = module->end(); I != E; ++I)<br>
> {<br>
>     Function *f = &*I;<br>
>     if(!f->isDeclaration()) {<br>
>       execution_engine->getPointerToFunction(f);<br>
>     }<br>
>   }<br>
>   // all functions are compiled so I'd like to dispose of the bitcode any<br>
> memory used in the compilation - how can I do this?<br>
<br>
</div>You can call (I think) deleteBody on each compiled function if you're<br>
done with it to delete the IR and leave the machine code.  You can't<br>
delete the functions themselves, because their pointers are used as<br>
keys in a hashtables.<br></blockquote><div>Thanks, I'll give this a try<br><br>-- James <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<font color="#888888"><br>
Reid<br>
<br>
</font></blockquote></div><br>