[LLVMdev] Lifetime of ExecutionEngine?

Kaylor, Andrew andrew.kaylor at intel.com
Fri Oct 26 12:59:19 PDT 2012


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




More information about the llvm-dev mailing list