/** * Enters this context and returns an object representing the previous context. Calls to enter * must be followed by a call to {@link #leave(Object)} in a finally block and the previous * context must be passed as an argument. It is allowed to enter a context multiple times from * the same thread. If the context is currently not entered by any thread then it is allowed be * entered by an arbitrary thread. Entering the context from two or more different threads at * the same time is possible, unless one of the loaded languages denies access to the thread, in * which case an {@link IllegalStateException} is thrown. The result of the enter function is * unspecified and must only be passed to {@link #leave(Object)}. The result value must not be * stored permanently. * <p> * Entering a language context is designed for compilation and is most efficient if the * {@link TruffleContext context} instance is compilation final. * * <p> * Example usage: {@link TruffleContextSnippets#executeInContext} * * @see #leave(Object) * @since 0.27 */ public Object enter() { Object prev = AccessAPI.engineAccess().enterInternalContext(impl); assert verifyEnter(prev); return prev; }
/** * Enters this context and returns an object representing the previous context. Calls to enter * must be followed by a call to {@link #leave(Object)} in a finally block and the previous * context must be passed as an argument. It is allowed to enter a context multiple times from * the same thread. If the context is currently not entered by any thread then it is allowed be * entered by an arbitrary thread. Entering the context from two or more different threads at * the same time is possible, unless one of the loaded languages denies access to the thread, in * which case an {@link IllegalStateException} is thrown. The result of the enter function is * unspecified and must only be passed to {@link #leave(Object)}. The result value must not be * stored permanently. * <p> * Entering a language context is designed for compilation and is most efficient if the * {@link TruffleContext context} instance is compilation final. * * <p> * Example usage: {@link TruffleContextSnippets#executeInContext} * * @see #leave(Object) * @since 0.27 */ public Object enter() { Object prev = AccessAPI.engineAccess().enterInternalContext(impl); assert verifyEnter(prev); return prev; }