Lifetime of ExecutionEngine?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Lifetime of ExecutionEngine?

Paul J. Lucas-3
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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime of ExecutionEngine?

Kaylor, Andrew
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: [hidden email] [mailto:[hidden email]] On Behalf Of Paul J. Lucas
Sent: Tuesday, October 23, 2012 11:31 AM
To: [hidden email]
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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime of ExecutionEngine?

Amara Emerson
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 <[hidden email]> 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: [hidden email] [mailto:[hidden email]] On Behalf Of Paul J. Lucas
> Sent: Tuesday, October 23, 2012 11:31 AM
> To: [hidden email]
> 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
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime of ExecutionEngine?

Paul J. Lucas-3
In reply to this post by Kaylor, Andrew
On Oct 26, 2012, at 12:59 PM, "Kaylor, Andrew" <[hidden email]> wrote:

> 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.

I probably should have mentioned that I'm JIT'ing the function, executing it, deleting the ExecutionEngine, and (the part I left out) never executing the JIT'd function again.  It's only ever executed once.  Given that, I would think it would be OK to delete the ExecutionEngine -- yes?

- Paul


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime of ExecutionEngine?

Kaylor, Andrew
Yes, in that case it's probably OK to delete it.  The only other concern that comes to mind is that the ExecutionEngine also takes ownership of the Module object it is compiling, so that will be deleted too.  If that's not a problem for you, then it should be OK to delete the ExecutionEngine.

-Andy

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Paul J. Lucas
Sent: Friday, October 26, 2012 4:56 PM
To: [hidden email] List
Subject: Re: [LLVMdev] Lifetime of ExecutionEngine?

On Oct 26, 2012, at 12:59 PM, "Kaylor, Andrew" <[hidden email]> wrote:

> 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.

I probably should have mentioned that I'm JIT'ing the function, executing it, deleting the ExecutionEngine, and (the part I left out) never executing the JIT'd function again.  It's only ever executed once.  Given that, I would think it would be OK to delete the ExecutionEngine -- yes?

- Paul


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev