On Aug 18, 2010, at 10:24 AM, Reid Kleckner wrote:> You can free the machine code yourself by saying > EE->freeMachineCodeForFunction(F) . If you destroy the EE, it will > also free the machine code.Thanks, but unfortunately, this is exactly the opposite of what I want to do. I need to retain the machine code indefinitely, but I want to free all possible other resources that are not strictly needed simply to jump into the machine code and execute it. In particular, the Modules appear to be the culprit in the memory consumption. If I call ExecutionEngine::removeModule (after JITing a function from the module), does that mean that I can subsequently no longer call the function? Or can I? Can I delete the Module at that point and still use the machine code? -- Larry Gritz lg at larrygritz.com
On Fri, Aug 20, 2010 at 12:39 PM, Larry Gritz <lg at larrygritz.com> wrote:> On Aug 18, 2010, at 10:24 AM, Reid Kleckner wrote: > >> You can free the machine code yourself by saying >> EE->freeMachineCodeForFunction(F) . If you destroy the EE, it will >> also free the machine code. > > Thanks, but unfortunately, this is exactly the opposite of what I want to do. I need to retain the machine code indefinitely, but I want to free all possible other resources that are not strictly needed simply to jump into the machine code and execute it. In particular, the Modules appear to be the culprit in the memory consumption. > > If I call ExecutionEngine::removeModule (after JITing a function from the module), does that mean that I can subsequently no longer call the function? Or can I? Can I delete the Module at that point and still use the machine code?I'm pretty sure you cannot delete the module and still execute the code. The JIT uses pointers to Function objects in its internal data structures, and if you try to free one while it's holding a reference, I believe you'll get an assertion error. The Module owns the Functions, so deleting it will free them. I would imagine that most memory is used in the IR of the functions, which you can delete as I described in my last message. Did that help? Reid
On Aug 20, 2010, at 2:30 PM, Reid Kleckner wrote:> I would imagine that most memory is used in the IR of the functions, > which you can delete as I described in my last message. Did that > help?It helps a little, but it seems that most of the memory consumption is elsewhere. I haven't had the time to spelunk through the Module internals enough to say for sure what's using up the memory. But... On Aug 23, 2010, at 7:25 AM, Nicolas Capens wrote:> I faced the same issue and solved it by writing my own JITMemoryManager. > This is the class that is responsible for allocating memory for the JITed > functions. So your derived implementation can let the application take > ownership of this memory before destructing the entire execution engine. > createJIT takes a JITMemoryManager as parameter, so it's straightforward to > make it use your derived class.Great suggestion, that sounds like what I was shooting for. I'll give that a try. Thanks! -- Larry Gritz lg at larrygritz.com