Class ContextLocal<T>

java.lang.Object
com.oracle.truffle.api.ContextLocal<T>

public abstract class ContextLocal<T> extends Object
A context local reference that refers to a value that is created for each polyglot context. Context references can be used to attach data to a polyglot context. That data can be retrieved efficiently for the current context using get() or for other contexts using get(TruffleContext). Context locals can be created for languages and instruments. See links below for usage examples.
Since:
20.3
See Also:
  • Constructor Details

    • ContextLocal

      protected ContextLocal(Object polyglotObject)
      Custom subclasses of context local are not allowed.
      Since:
      20.3
  • Method Details

    • get

      public abstract T get()
      Returns the context local value for the currently entered context. This method is intended to be used on compiled code paths. The return value is never null.
      Throws:
      IllegalStateException - if assertions (-ea) are enabled and no current context is entered on the current thread, context locals have already been cleared for the current context, the corresponding instrument is not initialized, or the corresponding language is not created.
      Since:
      20.3
    • get

      public abstract T get(TruffleContext context)
      Returns the context local value for an explicit context. This method is intended to be used on compiled code paths. The return value is never null.
      Throws:
      IllegalStateException - if assertions (-ea) are enabled and context locals have already been cleared for the specified context, the corresponding instrument is not initialized, or the corresponding language is not created.
      Since:
      20.3