[LLVMdev] Lifetime of ExecutionEngine?

Amara Emerson amara.emerson at gmail.com
Fri Oct 26 14:08:06 PDT 2012


Yep, depending on your libc implementation it can still be usable (it
doesn't necessarily unmap pages when you free memory), with undefined
behaviour when you attempt to access it of course.

Amara

On 26 October 2012 20:59, Kaylor, Andrew <andrew.kaylor at intel.com> wrote:
> Hi Paul,
>
> I'm surprised to hear that you aren't seeing any adverse effects.  As I understand it, the memory for the function pointer returned by getPointerToFunction is owned by the JITMemoryManager which was used in creating the ExecutionEngine.  In the case of the legacy JIT engine, the JITMemoryManager is owned by the JITEmitter which in turn is owned by the JIT ExecutionEngine.  In the case of the new MCJIT engine, the JITMemoryManager is owned by the MCJITMemoryManager which in turn is owned by the MCJIT ExecutionEngine.
>
> In either case, deleting the ExecutionEngine should result in the JITMemoryManager being deleted and therefore also the memory in which the JITed functions are contained.
>
> I think it's entirely possible that you just aren't seeing a problem because that memory hasn't been recycled yet.  It's a problem waiting to happen.
>
> -Andy
>
>
> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Paul J. Lucas
> Sent: Tuesday, October 23, 2012 11:31 AM
> To: llvmdev at cs.uiuc.edu
> Subject: [LLVMdev] Lifetime of ExecutionEngine?
>
> Given:
>
>         typedef MyClass* (*jit_fn_ptr_type)();
>
>         MyClass* set_fn( llvm::Function *fn ) {
>           // create an ExecutionEngine 'exec' ...
>           jit_fn_ptr_type fn_ptr = (jit_fn_ptr_type)exec->getPointerToFunction( fn );
>           return fn_ptr();
>         }
>
> After I call getPointerToFunction() to obtain the pointer to the JIT'd function and fun the function (that will produce an instance of MyClass on the heap), do I still need 'exec'?
>
> Deleting it immediately after use seems to have no adverse effect.  I just want to double-check that this is OK.
>
> - Paul
>
>
> _______________________________________________
> 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




More information about the llvm-dev mailing list