Interface ThreadsActivationListener


public interface ThreadsActivationListener
Listener that allows to be notified when threads become active and deactivated. This operation may called more frequently than the thread initialization with ThreadsListener, therefore the implementation of the threads activation listener needs to be designed for compilation. Care needs to be taken to not unnecessarily slow down thread activation.

The event notification starts immediately after the listener is registered. It is therefore possible that onLeaveThread(TruffleContext) is called without onEnterThread(TruffleContext) ever being invoked, if the listener is attached in parallel. When any of the listener methods are executed then the ThreadsActivationListener is guaranteed to be a partial evaluation constant. The provided TruffleContext may be a PE constant, but it is not guaranteed.

Common use-cases for threads activation include capturing the time the context is active, changing thread priorities or measuring thread allocated bytes of a context.

Since:
20.3
See Also:
  • Method Details

    • onEnterThread

      void onEnterThread(TruffleContext context)
      Notified when a context is entered on the current thread. Entering a thread indicates that the context is currently active. A context maybe entered multiple times per thread. This method is executed frequently and must be designed for compilation. If this method throws an AbstractTruffleException the exception interop messages may be executed without a context being entered.
      Parameters:
      context - the context being entered on the current thread
      Since:
      20.3
    • onLeaveThread

      void onLeaveThread(TruffleContext context)
      Notified when a context is entered on the current thread. Leaving a thread indicates that the context is no longer active on that thread. A context maybe left multiple times per thread. This method is executed frequently and must be designed for compilation.
      Parameters:
      context - the context being left on the current thread
      Since:
      20.3