This is an archive of the discontinued LLVM Phabricator instance.

[MCJIT] Remove eventListeners when MCJIT is destructed
AbandonedPublic

Authored by anna on Nov 1 2016, 2:29 PM.

Details

Reviewers
reames
lhames
Summary

We can register any number of listeners when MCJIT instance is created.
However, we do not remove them when destructing (and we never call the
UnregisterJITEventListener method).

This looks like a memory leak, but I'm not very clear about any other purposes
for the eventListeners.

Event Timeline

anna updated this revision to Diff 76633.Nov 1 2016, 2:29 PM
anna retitled this revision from to [MCJIT] Erase eventListeners when MCJIT is destructed.
anna updated this object.
anna retitled this revision from [MCJIT] Erase eventListeners when MCJIT is destructed to [MCJIT] Remove eventListeners when MCJIT is destructed.Nov 1 2016, 2:30 PM
anna added reviewers: lhames, reames.
anna added a subscriber: llvm-commits.
lhames edited edge metadata.Nov 1 2016, 4:49 PM

Hi Anna,

Thanks for looking into this.

The ExecutionEngine::RegisterEventListener documentation specifies that the JIT does not take ownership of the event listener, so freeing the listener is the client's responsibility.

The usual idiom is to allocate the listener as a local variable (if the JIT is used in a single function) or member variable (if the JIT is a class member), then register it. That way the listener is freed with the JIT. If any clients are heap allocating listeners and not freeing them that's definitely a bug.

Cheers,
Lang.

lhames added a comment.Nov 1 2016, 4:51 PM

Looking closer, those two lines (EventListners.clear() and Archives.clear()) are totally redundant in a destructor. We should just remove them. :)

  • Lang.
anna updated this revision to Diff 76693.Nov 2 2016, 5:11 AM
anna edited edge metadata.

Updated based on comments above. We can avoid freeing the Archive in the MCJIT destructor.

anna added a comment.Nov 2 2016, 5:13 AM

thanks Lang for the quick response! It makes sense now. I think there are other parts in the MCJIT code as well, which follow the same idiom (responsibility on the client). I have changed the code to avoid removing the Archives in the destructor.

anna abandoned this revision.Nov 14 2016, 12:44 PM

We dont need the change. The client should handle event listeners. see comment above.