[llvm-commits] [llvm] r69531 - /llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp

Nick Lewycky nicholas at mxc.ca
Sun Apr 19 22:18:05 PDT 2009


This causes a 'make check' failure on x86-64 linux with Ocaml installed. 
The problem seems to me to be that 
test/Bindings/Ocaml/executionengine.ml test_executionengine() never 
calls freeMachineCodeForFunction on @plus.

I tried adding what I thought was the obvious statement and it still 
doesn't work. I don't know ocaml, but it seems that this statement looks 
up @plus and assigns it to "plus" if found:
   match ExecutionEngine.find_function "plus" ee with
   | None -> raise (Failure "find_function 'plus' failed")
   | Some plus ->
and after the call to run_function, I added:
   ExecutionEngine.free_machine_code plus ee;
but the test still fails:
   Failed with signal(SIGABRT) at line 2
   while running: ./executionengine.ml.tmp executionengine.ml.tmp.bc
   While deleting: i32 (i32, i32)* %plus
   An asserting value handle still pointed to this value!

I've spent hours looking at this and haven't been able to figure out 
exactly what the problem is. I've gone from thinking there was something 
wrong in the C or Ocaml bindings to looking at the innards of the JIT 
itself.

If someone else who understands the Ocaml bindings or the JIT could 
please take a look, I'd appreciate that. I'm going to keep on debugging 
and see if I can figure it out.

Nick

Nick Lewycky wrote:
> Author: nicholas
> Date: Sun Apr 19 13:32:03 2009
> New Revision: 69531
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=69531&view=rev
> Log:
> Use an AssertingVH to detect the case where the Function was deleted but
> freeMachineCodeForFunction was never called.
> 
> Modified:
>     llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
> 
> Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=69531&r1=69530&r2=69531&view=diff
> 
> ==============================================================================
> --- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
> +++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Sun Apr 19 13:32:03 2009
> @@ -32,6 +32,7 @@
>  #include "llvm/Target/TargetOptions.h"
>  #include "llvm/Support/Debug.h"
>  #include "llvm/Support/MutexGuard.h"
> +#include "llvm/Support/ValueHandle.h"
>  #include "llvm/System/Disassembler.h"
>  #include "llvm/System/Memory.h"
>  #include "llvm/Target/TargetInstrInfo.h"
> @@ -57,23 +58,23 @@
>    private:
>      /// FunctionToStubMap - Keep track of the stub created for a particular
>      /// function so that we can reuse them if necessary.
> -    std::map<Function*, void*> FunctionToStubMap;
> +    std::map<AssertingVH<Function>, void*> FunctionToStubMap;
>  
>      /// StubToFunctionMap - Keep track of the function that each stub
>      /// corresponds to.
> -    std::map<void*, Function*> StubToFunctionMap;
> +    std::map<void*, AssertingVH<Function> > StubToFunctionMap;
>  
>      /// GlobalToIndirectSymMap - Keep track of the indirect symbol created for a
>      /// particular GlobalVariable so that we can reuse them if necessary.
>      std::map<GlobalValue*, void*> GlobalToIndirectSymMap;
>  
>    public:
> -    std::map<Function*, void*>& getFunctionToStubMap(const MutexGuard& locked) {
> +    std::map<AssertingVH<Function>, void*>& getFunctionToStubMap(const MutexGuard& locked) {
>        assert(locked.holds(TheJIT->lock));
>        return FunctionToStubMap;
>      }
>  
> -    std::map<void*, Function*>& getStubToFunctionMap(const MutexGuard& locked) {
> +    std::map<void*, AssertingVH<Function> >& getStubToFunctionMap(const MutexGuard& locked) {
>        assert(locked.holds(TheJIT->lock));
>        return StubToFunctionMap;
>      }
> @@ -275,11 +276,11 @@
>                                      SmallVectorImpl<void*> &Ptrs) {
>    MutexGuard locked(TheJIT->lock);
>    
> -  std::map<Function*,void*> &FM = state.getFunctionToStubMap(locked);
> +  std::map<AssertingVH<Function>,void*> &FM =state.getFunctionToStubMap(locked);
>    std::map<GlobalValue*,void*> &GM = state.getGlobalToIndirectSymMap(locked);
>    
> -  for (std::map<Function*,void*>::iterator i = FM.begin(), e = FM.end();
> -       i != e; ++i) {
> +  for (std::map<AssertingVH<Function>,void*>::iterator i = FM.begin(),
> +       e = FM.end(); i != e; ++i) {
>      Function *F = i->first;
>      if (F->isDeclaration() && F->hasExternalLinkage()) {
>        GVs.push_back(i->first);
> @@ -296,8 +297,8 @@
>  GlobalValue *JITResolver::invalidateStub(void *Stub) {
>    MutexGuard locked(TheJIT->lock);
>    
> -  std::map<Function*,void*> &FM = state.getFunctionToStubMap(locked);
> -  std::map<void*,Function*> &SM = state.getStubToFunctionMap(locked);
> +  std::map<AssertingVH<Function>,void*> &FM =state.getFunctionToStubMap(locked);
> +  std::map<void*,AssertingVH<Function> > &SM=state.getStubToFunctionMap(locked);
>    std::map<GlobalValue*,void*> &GM = state.getGlobalToIndirectSymMap(locked);
>    
>    // Look up the cheap way first, to see if it's a function stub we are
> @@ -348,7 +349,7 @@
>  
>      // The address given to us for the stub may not be exactly right, it might be
>      // a little bit after the stub.  As such, use upper_bound to find it.
> -    std::map<void*, Function*>::iterator I =
> +    std::map<void*, AssertingVH<Function> >::iterator I =
>        JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
>      assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
>             "This is not a known stub!");
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 




More information about the llvm-commits mailing list