# ⬢ truffle-api 25.6.0-elide.4
Every page: [llms.txt](llms.txt), or all in one file: [llms-full.txt](llms-full.txt)
API reference for truffle-api.
## Packages
- [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md): Do you want to implement your own Truffle based language? In such case start here.
- [`com.oracle.truffle.api.bytecode`](com/oracle/truffle/api/bytecode/index.md): The Bytecode DSL is a DSL and runtime support component of Truffle that makes it easier to implement bytecode interpreters.
- [`com.oracle.truffle.api.bytecode.debug`](com/oracle/truffle/api/bytecode/debug/index.md): Debug utilities for the Bytecode DSL.
- [`com.oracle.truffle.api.bytecode.serialization`](com/oracle/truffle/api/bytecode/serialization/index.md): Serialization-specific classes for the Bytecode DSL.
- [`com.oracle.truffle.api.debug`](com/oracle/truffle/api/debug/index.md): The debug package contains a debugger API that can be used to install breakpoints, step through and control the execution of Truffle guest language applications.
- [`com.oracle.truffle.api.dsl`](com/oracle/truffle/api/dsl/index.md): Domain specific language that allows to specify specializing AST nodes in a declarative way.
- [`com.oracle.truffle.api.exception`](com/oracle/truffle/api/exception/index.md): This package contains a Truffle exception base class.
- [`com.oracle.truffle.api.frame`](com/oracle/truffle/api/frame/index.md): Package containing stack frame representation classes.
- [`com.oracle.truffle.api.instrumentation`](com/oracle/truffle/api/instrumentation/index.md): The instrumentation API provides a way to introspect and inject behavior into interpreters written using the Truffle framework.
- [`com.oracle.truffle.api.instrumentation.provider`](com/oracle/truffle/api/instrumentation/provider/index.md): This package contains a provider to instantiate a Truffle instrument.
- [`com.oracle.truffle.api.interop`](com/oracle/truffle/api/interop/index.md): This package contains classes that specify the contract for inter-operability between Truffle guest languages and tools.
- [`com.oracle.truffle.api.io`](com/oracle/truffle/api/io/index.md): This package contains I/O related classes used by com.oracle.truffle.api.TruffleLanguage implementations.
- [`com.oracle.truffle.api.library`](com/oracle/truffle/api/library/index.md): Truffle Libraries allow language implementations to use polymorphic dispatch for receiver types with support for implementation specific caching/profiling and customization of the dispatch.
- [`com.oracle.truffle.api.library.provider`](com/oracle/truffle/api/library/provider/index.md): This package contains service provider interfaces used by Truffle libraries.
- [`com.oracle.truffle.api.memory`](com/oracle/truffle/api/memory/index.md): This package contains memory related classes used by com.oracle.truffle.api.TruffleLanguage implementations.
- [`com.oracle.truffle.api.nodes`](com/oracle/truffle/api/nodes/index.md): Abstract syntax tree nodes are the basic building block for your com.oracle.truffle.api.TruffleLanguage.
- [`com.oracle.truffle.api.object`](com/oracle/truffle/api/object/index.md): Dynamic object storage model.
- [`com.oracle.truffle.api.profiles`](com/oracle/truffle/api/profiles/index.md): A profile is a Truffle utility class that uses the Truffle compiler directives to guard for and/or forward runtime information to the compiler.
- [`com.oracle.truffle.api.provider`](com/oracle/truffle/api/provider/index.md): This package contains a provider to instantiate a Truffle language.
- [`com.oracle.truffle.api.source`](com/oracle/truffle/api/source/index.md): Represents a source file.
- [`com.oracle.truffle.api.staticobject`](com/oracle/truffle/api/staticobject/index.md): Static Object Model APIs to represent the layout of objects that, once defined, do not change the number and the type of their properties.
- [`com.oracle.truffle.api.strings`](com/oracle/truffle/api/strings/index.md): Truffle String related APIs.
- [`com.oracle.truffle.api.utilities`](com/oracle/truffle/api/utilities/index.md): Various utility classes that aim to make the development of TruffleLanguage guest languages easier.
## Types in `com.oracle.truffle.api`
`ArrayUtils`, `Assumption`, `CallTarget`, `CompilerAsserts`, `CompilerDirectives`, `CompilerDirectives.CompilationFinal`, `CompilerDirectives.EarlyEscapeAnalysis`, `CompilerDirectives.EarlyInline`, `CompilerDirectives.TruffleBoundary`, `CompilerDirectives.ValueType`, `ContextLocal`, `ContextThreadLocal`, `ExactMath`, `HostCompilerDirectives`, `HostCompilerDirectives.BytecodeInterpreterFetchOpcode`, `HostCompilerDirectives.BytecodeInterpreterHandler`, `HostCompilerDirectives.BytecodeInterpreterHandlerConfig`, `HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument`, `HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind`, `HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field`, `HostCompilerDirectives.BytecodeInterpreterSwitch`, `HostCompilerDirectives.InliningCutoff`, `HostCompilerDirectives.InliningRoot`, `InstrumentInfo`, `InternalResource`, `InternalResource.CPUArchitecture`, `InternalResource.Env`, `InternalResource.Id`, `InternalResource.OS`, `OptimizationFailedException`, `Option`, `Option.Group`, `ReplaceObserver`, `RootCallTarget`, `ThreadLocalAction`, `ThreadLocalAction.Access`, `Truffle`, `TruffleContext`, `TruffleContext.Builder`, `TruffleFile`, `TruffleFile.AttributeDescriptor`, `TruffleFile.Attributes`, `TruffleFile.FileStoreInfo`, `TruffleFile.FileTypeDetector`, `TruffleLanguage`, `TruffleLanguage.ContextLocalFactory`, `TruffleLanguage.ContextLocalProvider`, `TruffleLanguage.ContextPolicy`, `TruffleLanguage.ContextReference`, `TruffleLanguage.ContextThreadLocalFactory`, `TruffleLanguage.Env`, `TruffleLanguage.ExitMode`, `TruffleLanguage.InlineParsingRequest`, `TruffleLanguage.LanguageReference`, `TruffleLanguage.ParsingRequest`, `TruffleLanguage.Registration`, `TruffleLogger`, `TruffleOptionDescriptors`, `TruffleOptions`, `TruffleRuntime`, `TruffleRuntimeAccess`, `TruffleSafepoint`, `TruffleSafepoint.CompiledInterruptible`, `TruffleSafepoint.CompiledInterruptibleFunction`, `TruffleSafepoint.Interrupter`, `TruffleSafepoint.Interruptible`, `TruffleSafepoint.InterruptibleFunction`, `TruffleStackTrace`, `TruffleStackTraceElement`, `TruffleThreadBuilder`
## Types in `com.oracle.truffle.api.bytecode`
`BytecodeBuilder`, `BytecodeConfig`, `BytecodeConfig.Builder`, `BytecodeConfigEncoder`, `BytecodeDSLAccess`, `BytecodeDescriptor`, `BytecodeEncodingException`, `BytecodeFrame`, `BytecodeIndexMode`, `BytecodeLabel`, `BytecodeLocal`, `BytecodeLocation`, `BytecodeNode`, `BytecodeParser`, `BytecodeRootNode`, `BytecodeRootNodes`, `BytecodeSupport`, `BytecodeSupport.CloneReferenceList`, `BytecodeSupport.ConstantsBuffer`, `BytecodeTier`, `BytecodeTransition`, `BytecodeVersion`, `ConstantOperand`, `ConstantOperand.Repeat`, `ContinuationResult`, `ContinuationRootNode`, `EpilogExceptional`, `EpilogReturn`, `ExceptionHandler`, `ExceptionHandler.HandlerKind`, `ForceQuickening`, `ForceQuickening.Repeat`, `GenerateBytecode`, `GenerateBytecodeTestVariants`, `GenerateBytecodeTestVariants.Variant`, `Instruction`, `Instruction.Argument`, `Instruction.Argument.BranchProfile`, `Instruction.Argument.Kind`, `InstructionDescriptor`, `InstructionDescriptor.ArgumentDescriptor`, `InstructionTracer`, `InstructionTracer.InstructionAccess`, `Instrumentation`, `LocalAccessor`, `LocalRangeAccessor`, `LocalVariable`, `MaterializedLocalAccessor`, `Operation`, `OperationProxy`, `OperationProxy.Proxyable`, `OperationProxy.Repeat`, `Prolog`, `Return`, `ShortCircuitOperation`, `ShortCircuitOperation.Operator`, `ShortCircuitOperation.Repeat`, `SourceInformation`, `SourceInformationTree`, `StackValue`, `StoreBytecodeIndex`, `TagTree`, `TagTreeNode`, `TagTreeNodeGen`, `TagTreeNodeGen.DynamicDispatchLibraryExports`, `TagTreeNodeGen.DynamicDispatchLibraryExports.Cached`, `TagTreeNodeGen.DynamicDispatchLibraryExports.Uncached`, `Variadic`, `Yield`
## Types in `com.oracle.truffle.api.bytecode.debug`
`BytecodeDebugListener`, `BytecodeDebugTraceListener`, `HistogramInstructionTracer`, `HistogramInstructionTracer.Builder`, `HistogramInstructionTracer.GroupClause`, `HistogramInstructionTracer.Histogram`, `PrintInstructionTracer`, `PrintInstructionTracer.Builder`
## Types in `com.oracle.truffle.api.bytecode.serialization`
`ByteBufferDataInput`, `BytecodeDeserializer`, `BytecodeDeserializer.DeserializerContext`, `BytecodeSerializer`, `BytecodeSerializer.SerializerContext`, `SerializationUtils`
## Types in `com.oracle.truffle.api.debug`
`Breakpoint`, `Breakpoint.Builder`, `Breakpoint.ExceptionBuilder`, `Breakpoint.Kind`, `Breakpoint.ResolveListener`, `DebugContext`, `DebugContextsListener`, `DebugException`, `DebugException.CatchLocation`, `DebugScope`, `DebugStackFrame`, `DebugStackTraceElement`, `DebugThreadsListener`, `DebugValue`, `Debugger`, `DebuggerSession`, `DebuggerTags`, `DebuggerTags.AlwaysHalt`, `SourceElement`, `StepConfig`, `StepConfig.Builder`, `SuspendAnchor`, `SuspendedCallback`, `SuspendedEvent`, `SuspensionFilter`, `SuspensionFilter.Builder`
## Types in `com.oracle.truffle.api.dsl`
`AOTSupport`, `Bind`, `Bind.DefaultExpression`, `Cached`, `Cached.Exclusive`, `Cached.Shared`, `CreateCast`, `DSLSupport`, `DSLSupport.SpecializationDataNode`, `ExecuteTracingSupport`, `Executed`, `Fallback`, `GenerateAOT`, `GenerateAOT.Exclude`, `GenerateAOT.Provider`, `GenerateCached`, `GenerateInline`, `GenerateNodeFactory`, `GeneratePackagePrivate`, `GenerateUncached`, `GeneratedBy`, `Idempotent`, `ImplicitCast`, `ImportStatic`, `InlineSupport`, `InlineSupport.BooleanField`, `InlineSupport.ByteField`, `InlineSupport.CharField`, `InlineSupport.DoubleField`, `InlineSupport.FloatField`, `InlineSupport.InlinableField`, `InlineSupport.InlineTarget`, `InlineSupport.IntField`, `InlineSupport.LongField`, `InlineSupport.ReferenceField`, `InlineSupport.RequiredField`, `InlineSupport.RequiredFields`, `InlineSupport.ShortField`, `InlineSupport.StateField`, `InlineSupport.UnsafeAccessedField`, `Introspectable`, `Introspection`, `Introspection.Provider`, `Introspection.SpecializationInfo`, `NeverDefault`, `NodeChild`, `NodeChildren`, `NodeFactory`, `NodeField`, `NodeFields`, `NonIdempotent`, `ReportPolymorphism`, `ReportPolymorphism.Exclude`, `ReportPolymorphism.Megamorphic`, `Specialization`, `SpecializationStatistics`, `SpecializationStatistics.AlwaysEnabled`, `SpecializationStatistics.NodeStatistics`, `SuppressPackageWarnings`, `TypeCast`, `TypeCheck`, `TypeSystem`, `TypeSystemReference`, `UnsupportedSpecializationException`
## Types in `com.oracle.truffle.api.exception`
`AbstractTruffleException`
## Types in `com.oracle.truffle.api.frame`
`Frame`, `FrameDescriptor`, `FrameDescriptor.Builder`, `FrameExtensions`, `FrameInstance`, `FrameInstance.FrameAccess`, `FrameInstanceVisitor`, `FrameSlotKind`, `FrameSlotTypeException`, `MaterializedFrame`, `VirtualFrame`
## Types in `com.oracle.truffle.api.instrumentation`
`AllocationEvent`, `AllocationEventFilter`, `AllocationEventFilter.Builder`, `AllocationListener`, `AllocationReporter`, `ContextsListener`, `EventBinding`, `EventContext`, `ExecuteSourceEvent`, `ExecuteSourceListener`, `ExecutionEventListener`, `ExecutionEventNode`, `ExecutionEventNodeFactory`, `GenerateWrapper`, `GenerateWrapper.Ignore`, `GenerateWrapper.IncomingConverter`, `GenerateWrapper.OutgoingConverter`, `GenerateWrapper.YieldException`, `InstrumentableNode`, `InstrumentableNode.WrapperNode`, `Instrumenter`, `LoadSourceEvent`, `LoadSourceListener`, `LoadSourceSectionEvent`, `LoadSourceSectionListener`, `NearestSectionFilter`, `NearestSectionFilter.Builder`, `ProbeNode`, `ProvidedTags`, `SourceFilter`, `SourceFilter.Builder`, `SourceSectionFilter`, `SourceSectionFilter.Builder`, `SourceSectionFilter.IndexRange`, `SourceSectionFilter.SourcePredicate`, `StandardTags`, `StandardTags.CallTag`, `StandardTags.ExpressionTag`, `StandardTags.ReadVariableTag`, `StandardTags.RootBodyTag`, `StandardTags.RootTag`, `StandardTags.StatementTag`, `StandardTags.TryBlockTag`, `StandardTags.WriteVariableTag`, `Tag`, `Tag.Identifier`, `ThreadsActivationListener`, `ThreadsListener`, `TruffleInstrument`, `TruffleInstrument.ContextLocalFactory`, `TruffleInstrument.ContextLocalProvider`, `TruffleInstrument.ContextThreadLocalFactory`, `TruffleInstrument.Env`, `TruffleInstrument.Registration`
## Types in `com.oracle.truffle.api.instrumentation.provider`
`TruffleInstrumentProvider`
## Types in `com.oracle.truffle.api.interop`
`ArityException`, `ExceptionType`, `HeapIsolationException`, `InteropException`, `InteropLibrary`, `InvalidArrayIndexException`, `InvalidBufferOffsetException`, `NodeLibrary`, `StopIterationException`, `TruffleObject`, `UnknownIdentifierException`, `UnknownKeyException`, `UnsupportedMessageException`, `UnsupportedTypeException`
## Types in `com.oracle.truffle.api.io`
`TruffleProcessBuilder`
## Types in `com.oracle.truffle.api.library`
`CachedLibrary`, `DynamicDispatchLibrary`, `ExportLibrary`, `ExportLibrary.Repeat`, `ExportMessage`, `ExportMessage.Ignore`, `ExportMessage.Repeat`, `GenerateLibrary`, `GenerateLibrary.Abstract`, `GenerateLibrary.DefaultExport`, `GenerateLibrary.DefaultExport.Repeat`, `Library`, `LibraryExport`, `LibraryExport.DelegateExport`, `LibraryFactory`, `Message`, `ReflectionLibrary`
## Types in `com.oracle.truffle.api.library.provider`
`DefaultExportProvider`, `EagerExportProvider`
## Types in `com.oracle.truffle.api.memory`
`ByteArraySupport`
## Types in `com.oracle.truffle.api.nodes`
`BlockNode`, `BlockNode.ElementExecutor`, `BytecodeOSRNode`, `ControlFlowException`, `DenyReplace`, `DirectCallNode`, `EncapsulatingNodeReference`, `ExecutableNode`, `ExecutionSignature`, `ExplodeLoop`, `ExplodeLoop.LoopExplosionKind`, `IndirectCallNode`, `InvalidAssumptionException`, `LanguageInfo`, `LoopNode`, `Node`, `Node.Child`, `Node.Children`, `NodeClass`, `NodeCloneable`, `NodeCost`, `NodeInfo`, `NodeInterface`, `NodeUtil`, `NodeUtil.NodeCountFilter`, `NodeVisitor`, `RepeatingNode`, `RootNode`, `SlowPathException`, `UnadoptableNode`, `UnexpectedResultException`
## Types in `com.oracle.truffle.api.object`
`DoubleLocation`, `DynamicObject`, `DynamicObject.ContainsKeyNode`, `DynamicObject.CopyPropertiesNode`, `DynamicObject.DynamicField`, `DynamicObject.GetDynamicTypeNode`, `DynamicObject.GetKeyArrayNode`, `DynamicObject.GetNode`, `DynamicObject.GetPropertyArrayNode`, `DynamicObject.GetPropertyFlagsNode`, `DynamicObject.GetPropertyNode`, `DynamicObject.GetShapeFlagsNode`, `DynamicObject.IsSharedNode`, `DynamicObject.MarkSharedNode`, `DynamicObject.PutAllNode`, `DynamicObject.PutConstantNode`, `DynamicObject.PutNode`, `DynamicObject.RemoveKeyNode`, `DynamicObject.ResetShapeNode`, `DynamicObject.SetAllPropertyFlagsNode`, `DynamicObject.SetDynamicTypeNode`, `DynamicObject.SetPropertyFlagsNode`, `DynamicObject.SetShapeFlagsNode`, `DynamicObject.UpdateShapeNode`, `DynamicObjectFactory`, `DynamicObjectLibrary`, `FinalLocationException`, `HiddenKey`, `IncompatibleLocationException`, `IntLocation`, `Location`, `Property`, `PropertyGetter`, `Shape`, `Shape.Builder`, `Shape.DerivedBuilder`
## Types in `com.oracle.truffle.api.profiles`
`BranchProfile`, `ByteValueProfile`, `ConditionProfile`, `CountingConditionProfile`, `DoubleValueProfile`, `FloatValueProfile`, `InlinedBranchProfile`, `InlinedByteValueProfile`, `InlinedConditionProfile`, `InlinedCountingConditionProfile`, `InlinedDoubleValueProfile`, `InlinedExactClassProfile`, `InlinedFloatValueProfile`, `InlinedIntValueProfile`, `InlinedLongValueProfile`, `InlinedLoopConditionProfile`, `InlinedProfile`, `IntValueProfile`, `LongValueProfile`, `LoopConditionProfile`, `PrimitiveValueProfile`, `Profile`, `ValueProfile`
## Types in `com.oracle.truffle.api.provider`
`InternalResourceProvider`, `TruffleLanguageProvider`
## Types in `com.oracle.truffle.api.source`
`Source`, `Source.LiteralBuilder`, `Source.SourceBuilder`, `SourceSection`
## Types in `com.oracle.truffle.api.staticobject`
`DefaultStaticObjectFactory`, `DefaultStaticProperty`, `StaticProperty`, `StaticShape`, `StaticShape.Builder`
## Types in `com.oracle.truffle.api.strings`
`AbstractTruffleString`, `InternalByteArray`, `MutableTruffleString`, `MutableTruffleString.AsManagedNode`, `MutableTruffleString.AsMutableTruffleStringNode`, `MutableTruffleString.ConcatNode`, `MutableTruffleString.ForceEncodingNode`, `MutableTruffleString.FromByteArrayNode`, `MutableTruffleString.FromNativePointerNode`, `MutableTruffleString.SubstringByteIndexNode`, `MutableTruffleString.SubstringNode`, `MutableTruffleString.SwitchEncodingNode`, `MutableTruffleString.WriteByteNode`, `MutableTruffleStringFactory`, `NativeAllocator`, `TranscodingErrorHandler`, `TranscodingErrorHandler.ReplacementString`, `TruffleString`, `TruffleString.AsManagedNode`, `TruffleString.AsNativeNode`, `TruffleString.AsTruffleStringNode`, `TruffleString.ByteIndexOfAnyByteNode`, `TruffleString.ByteIndexOfCodePointNode`, `TruffleString.ByteIndexOfCodePointSetNode`, `TruffleString.ByteIndexOfStringNode`, `TruffleString.ByteIndexOfStringSetNode`, `TruffleString.ByteIndexToCodePointIndexNode`, `TruffleString.ByteLengthOfCodePointNode`, `TruffleString.CharIndexOfAnyCharUTF16Node`, `TruffleString.CodePointAtByteIndexNode`, `TruffleString.CodePointAtIndexNode`, `TruffleString.CodePointAtIndexUTF32Node`, `TruffleString.CodePointIndexToByteIndexNode`, `TruffleString.CodePointLengthNode`, `TruffleString.CodePointSet`, `TruffleString.CodeRange`, `TruffleString.CodeRangeEqualsNode`, `TruffleString.CompactionLevel`, `TruffleString.CompareBytesNode`, `TruffleString.CompareCharsUTF16Node`, `TruffleString.CompareIntsUTF32Node`, `TruffleString.ConcatNode`, `TruffleString.CopyToByteArrayNode`, `TruffleString.CopyToNativeMemoryNode`, `TruffleString.CreateBackwardCodePointIteratorNode`, `TruffleString.CreateCodePointIteratorNode`, `TruffleString.Encoding`, `TruffleString.EqualNode`, `TruffleString.ErrorHandling`, `TruffleString.ForceEncodingNode`, `TruffleString.FromByteArrayNode`, `TruffleString.FromByteArrayWithCompactionUTF32Node`, `TruffleString.FromCharArrayUTF16Node`, `TruffleString.FromCodePointNode`, `TruffleString.FromIntArrayUTF32Node`, `TruffleString.FromJavaStringNode`, `TruffleString.FromLongNode`, `TruffleString.FromNativePointerNode`, `TruffleString.FromNativePointerWithCompactionUTF32Node`, `TruffleString.FromZeroTerminatedNativePointerNode`, `TruffleString.GetByteCodeRangeNode`, `TruffleString.GetCodeRangeImpreciseNode`, `TruffleString.GetCodeRangeNode`, `TruffleString.GetInternalByteArrayNode`, `TruffleString.GetInternalNativePointerNode`, `TruffleString.GetStringCompactionLevelNode`, `TruffleString.HashCodeNode`, `TruffleString.IllegalByteArrayLengthException`, `TruffleString.IndexOfCodePointNode`, `TruffleString.IndexOfStringNode`, `TruffleString.IntIndexOfAnyIntUTF32Node`, `TruffleString.IsValidNode`, `TruffleString.LastByteIndexOfCodePointNode`, `TruffleString.LastByteIndexOfStringNode`, `TruffleString.LastIndexOfCodePointNode`, `TruffleString.LastIndexOfStringNode`, `TruffleString.MaterializeNode`, `TruffleString.MaterializeSubstringNode`, `TruffleString.NumberFormatException`, `TruffleString.ParseDoubleNode`, `TruffleString.ParseIntNode`, `TruffleString.ParseLongNode`, `TruffleString.ReadByteNode`, `TruffleString.ReadCharUTF16Node`, `TruffleString.RegionEqualByteIndexNode`, `TruffleString.RegionEqualNode`, `TruffleString.RepeatNode`, `TruffleString.StringSet`, `TruffleString.SubstringByteIndexNode`, `TruffleString.SubstringNode`, `TruffleString.SwitchEncodingNode`, `TruffleString.ToJavaStringNode`, `TruffleString.ToValidStringNode`, `TruffleString.WithMask`, `TruffleString.WithMask.CreateNode`, `TruffleString.WithMask.CreateUTF16Node`, `TruffleString.WithMask.CreateUTF32Node`, `TruffleStringBuilder`, `TruffleStringBuilder.AppendByteNode`, `TruffleStringBuilder.AppendCharUTF16Node`, `TruffleStringBuilder.AppendCodePointNode`, `TruffleStringBuilder.AppendIntNumberNode`, `TruffleStringBuilder.AppendJavaStringUTF16Node`, `TruffleStringBuilder.AppendLongNumberNode`, `TruffleStringBuilder.AppendStringNode`, `TruffleStringBuilder.AppendSubstringByteIndexNode`, `TruffleStringBuilder.ToStringNode`, `TruffleStringBuilderFactory`, `TruffleStringBuilderUTF16`, `TruffleStringBuilderUTF32`, `TruffleStringBuilderUTF8`, `TruffleStringFactory`, `TruffleStringFactory.WithMaskFactory`, `TruffleStringIterator`, `TruffleStringIterator.NextNode`, `TruffleStringIterator.PreviousNode`, `TruffleStringIteratorFactory`
## Types in `com.oracle.truffle.api.utilities`
`AssumedValue`, `CyclicAssumption`, `FinalBitSet`, `JSONHelper`, `JSONHelper.JSONArrayBuilder`, `JSONHelper.JSONObjectBuilder`, `JSONHelper.JSONStringBuilder`, `MathUtils`, `TriState`, `TruffleWeakReference`
# ▣ com.oracle.truffle.api
[truffle-api](index.md) · Every page: [llms.txt](llms.txt)
Package in truffle-api. Since 0.8 or older.
Do you want to implement your own [`Truffle based language`](com/oracle/truffle/api/TruffleLanguage.md)? In such case start [`here`](com/oracle/truffle/api/TruffleLanguage.md).
## Interfaces
- [`Assumption`](com/oracle/truffle/api/Assumption.md): An assumption is a global boolean flag that starts with the value true (i.e., the assumption is valid) and can subsequently be invalidated (using Assumption.invalidate()).
- [`CallTarget`](com/oracle/truffle/api/CallTarget.md): Represents the target of a call.
- [`InternalResource`](com/oracle/truffle/api/InternalResource.md): Represents an internal resource of a language that can be lazily unpacked to a cache user directory.
- [`ReplaceObserver`](com/oracle/truffle/api/ReplaceObserver.md): An observer that is notified whenever a child node is replaced.
- [`RootCallTarget`](com/oracle/truffle/api/RootCallTarget.md): Represents the target of a call to a RootNode, i.e., to another tree of nodes.
- [`TruffleOptionDescriptors`](com/oracle/truffle/api/TruffleOptionDescriptors.md): An OptionDescriptors enhanced to provide a sandbox policy for options.
- [`TruffleRuntime`](com/oracle/truffle/api/TruffleRuntime.md): Interface representing a Truffle runtime object.
- [`TruffleRuntimeAccess`](com/oracle/truffle/api/TruffleRuntimeAccess.md): A service that provides access to a TruffleRuntime implementation.
## Classes
- [`ArrayUtils`](com/oracle/truffle/api/ArrayUtils.md): This class provides additional operations for String as well as character and byte arrays, which may be intrinsified by a compiler.
- [`CompilerAsserts`](com/oracle/truffle/api/CompilerAsserts.md): Assertions about the code produced by the Truffle compiler.
- [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md): Directives that influence the optimizations of the Truffle compiler.
- [`ContextLocal`](com/oracle/truffle/api/ContextLocal.md): A context local reference that refers to a value that is created for each polyglot context.
- [`ContextThreadLocal`](com/oracle/truffle/api/ContextThreadLocal.md): A context thread local reference that refers to a value that is created for each polyglot context and thread.
- [`ExactMath`](com/oracle/truffle/api/ExactMath.md): This class contains exact math related methods that are generally useful for dynamic language implementations.
- [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md): Directives that influence the optimizations of the host compiler.
- [`InstrumentInfo`](com/oracle/truffle/api/InstrumentInfo.md): Represents public information about an instrument.
- [`ThreadLocalAction`](com/oracle/truffle/api/ThreadLocalAction.md): Represents an action that is executed at a safepoint location of the guest language execution.
- [`Truffle`](com/oracle/truffle/api/Truffle.md): Class for obtaining the Truffle runtime singleton object of this virtual machine.
- [`TruffleContext`](com/oracle/truffle/api/TruffleContext.md): A handle on a context of a set of Truffle languages.
- [`TruffleFile`](com/oracle/truffle/api/TruffleFile.md): An abstract representation of a file used by Truffle languages.
- [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md): A Truffle language implementation contains all the services a language should provide to make it composable with other languages.
- [`TruffleLogger`](com/oracle/truffle/api/TruffleLogger.md): Support for logging in Truffle languages and instruments.
- [`TruffleOptions`](com/oracle/truffle/api/TruffleOptions.md): Class containing general Truffle options.
- [`TruffleSafepoint`](com/oracle/truffle/api/TruffleSafepoint.md): Truffle safepoints allow interrupting the guest language execution to execute thread-local actions submitted by a language or tool.
- [`TruffleStackTraceElement`](com/oracle/truffle/api/TruffleStackTraceElement.md): Represents a guest stack trace element.
- [`TruffleThreadBuilder`](com/oracle/truffle/api/TruffleThreadBuilder.md): A builder for threads that have access to the appropriate TruffleContext.
## Exceptions
- [`OptimizationFailedException`](com/oracle/truffle/api/OptimizationFailedException.md): No description.
- [`TruffleStackTrace`](com/oracle/truffle/api/TruffleStackTrace.md): Represents a guest language stack trace.
## Annotations
- [`Option`](com/oracle/truffle/api/Option.md): Describes the attributes of an option whose value is in a static field annotated by this annotation.
# ◆ ArrayUtils
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0.
```java
public final class ArrayUtils
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ArrayUtils`
This class provides additional operations for [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) as well as character and byte arrays, which may be intrinsified by a compiler.
## Methods
### indexOf(String, int, …)
`public static int indexOf(String string, int fromIndex, int maxIndex, char... values)`. Since 19.0. Returns the index of the first occurrence of any character contained in `values` in `string`, bounded by `fromIndex` (inclusive) and `maxIndex` (exclusive). Returns `int`: the index of the first occurrence of any character contained in `values` in `string` that is greater than or equal to `fromIndex` and less than `maxIndex`, or `-1` if none of the characters occur. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOf(java.lang.String,int,int,char...)`
### indexOf(char[], int, …)
`public static int indexOf(char[] array, int fromIndex, int maxIndex, char... values)`. Since 19.0. Returns the index of the first occurrence of any character contained in `values` in `array`, bounded by `fromIndex` (inclusive) and `maxIndex` (exclusive). Returns `int`: the index of the first occurrence of any character contained in `values` in `array` that is greater than or equal to `fromIndex` and less than `maxIndex`, or `-1` if none of the characters occur. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOf(char[],int,int,char...)`
### indexOf(byte[], int, …)
`public static int indexOf(byte[] array, int fromIndex, int maxIndex, byte... values)`. Since 19.0. Returns the index of the first occurrence of any byte contained in `values` in `array`, bounded by `fromIndex` (inclusive) and `maxIndex` (exclusive). Returns `int`: the index of the first occurrence of any byte contained in `values` in `array` that is greater than or equal to `fromIndex` and less than `maxIndex`, or `-1` if none of the values occur. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOf(byte[],int,int,byte...)`
### indexOfWithOrMask(byte[], int, …)
`public static int indexOfWithOrMask(byte[] haystack, int fromIndex, int length, byte[] needle, byte[] mask)`. Since 19.3. Returns the index of the first region of `haystack` that equals `needle` after being OR'ed with `mask`, bounded by `fromIndex` (inclusive) and `length`. Performs best if `needle` and `mask` are `CompilationFinal` with `dimensions = 1`. Returns `int`: the index of the first region of `haystack` where for all indices `i` of `needle` `(haystack[index + i] | mask[i]) == needle[i]` holds, and `fromIndex <= index && index + needle.length <= fromIndex + length` holds, or `-1` if no such region is found. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOfWithOrMask(byte[],int,int,byte[],byte[])`
### indexOfWithOrMask(char[], int, …)
`public static int indexOfWithOrMask(char[] haystack, int fromIndex, int length, char[] needle, char[] mask)`. Since 19.3. Returns the index of the first region of `haystack` that equals `needle` after being OR'ed with `mask`, bounded by `fromIndex` (inclusive) and `length`. Performs best if `needle` and `mask` are `CompilationFinal` with `dimensions = 1`. Returns `int`: the index of the first region of `haystack` where for all indices `i` of `needle` `(haystack[index + i] | mask[i]) == needle[i]` holds, and `fromIndex <= index && index + needle.length <= fromIndex + length` holds, or `-1` if no such region is found. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOfWithOrMask(char[],int,int,char[],char[])`
### indexOfWithOrMask(String, int, …)
`public static int indexOfWithOrMask(String haystack, int fromIndex, int length, String needle, String mask)`. Since 19.3. Returns the index of the first region of `haystack` that equals `needle` after being OR'ed with `mask`, bounded by `fromIndex` (inclusive) and `length`. Performs best if `needle` and `mask` are `CompilationFinal`. Returns `int`: the index of the first region of `haystack` where for all indices `i` of `needle` `(haystack.charAt(index + i) | mask.charAt(i)) == needle.charAt(i)` holds, and `fromIndex <= index && index + needle.length() <= fromIndex + length` holds, or `-1` if no such region is found. Cite: `com/oracle/truffle/api/ArrayUtils.html#indexOfWithOrMask(java.lang.String,int,int,java.lang.String,java.lang.String)`
### regionEqualsWithOrMask(byte[], int, …)
`public static boolean regionEqualsWithOrMask(byte[] a, int offsetA, byte[] b, int offsetB, int length, byte[] mask)`. Since 19.3. Returns `true` iff for all indices `i` from `0` (inclusive) to `length` (exclusive), `(a[offsetA + i] | mask[i]) == b[offsetB + i]` holds. Performs best if `length` and `mask` are `CompilationFinal` with `dimensions = 1`. If `mask` is `null`, it is treated as if it was filled with zeroes. Cite: `com/oracle/truffle/api/ArrayUtils.html#regionEqualsWithOrMask(byte[],int,byte[],int,int,byte[])`
### regionEqualsWithOrMask(char[], int, …)
`public static boolean regionEqualsWithOrMask(char[] a, int offsetA, char[] b, int offsetB, int length, char[] mask)`. Since 19.3. Returns `true` iff for all indices `i` from `0` (inclusive) to `length` (exclusive), `(a[offsetA + i] | mask[i]) == b[offsetB + i]` holds. Performs best if `length` and `mask` are `CompilationFinal` with `dimensions = 1`. If `mask` is `null`, it is treated as if it was filled with zeroes. Cite: `com/oracle/truffle/api/ArrayUtils.html#regionEqualsWithOrMask(char[],int,char[],int,int,char[])`
### regionEqualsWithOrMask(String, int, …)
`public static boolean regionEqualsWithOrMask(String a, int offsetA, String b, int offsetB, int length, String mask)`. Since 19.3. Returns `true` iff for all indices `i` from `0` (inclusive) to `length` (exclusive), `(a.charAt(offsetA + i) | mask.charAt(i)) == b.charAt(offsetB + i)` holds. Performs best if `length` and `mask` are `CompilationFinal` with `dimensions = 1`. If `mask` is `null`, it is treated as if it was filled with zeroes. Cite: `com/oracle/truffle/api/ArrayUtils.html#regionEqualsWithOrMask(java.lang.String,int,java.lang.String,int,int,java.lang.String)`
### arraycopy(int[], int, …)
`public static void arraycopy(int[] source, int sourceIndex, int[] destination, int destinationIndex, int length)`. Since 25.1. Copies `length` elements from `source`, starting at `sourceIndex`, to `destination`, starting at `destinationIndex`. This method is intended for performance-sensitive Truffle code that copies non-overlapping `int[]` regions and can benefit from compiler intrinsification, in particular for small constant-length copies. It is not a general replacement for [`System.arraycopy`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/System.html#arraycopy%28java.lang.Object,int,java.lang.Object,int,int%29): use [`System.arraycopy`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/System.html#arraycopy%28java.lang.Object,int,java.lang.Object,int,int%29) unless the stricter contract below is acceptable. Unlike [`System.arraycopy`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/System.html#arraycopy%28java.lang.Object,int,java.lang.Object,int,int%29), this method is intrinsified in a manner that doesn't behave exactly as the scalar loop would: overlapping source and destination regions are not supported, and individual elements may be copied twice, which may be observable in multi-threading contexts. Cite: `com/oracle/truffle/api/ArrayUtils.html#arraycopy(int[],int,int[],int,int)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ Assumption
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface Assumption
```
An assumption is a global boolean flag that starts with the value true (i.e., the assumption is valid) and can subsequently be invalidated (using [`Assumption.invalidate()`](com/oracle/truffle/api/Assumption.md#invalidate%28%29)). Once invalidated, an assumption can never get valid again. Assumptions can be created using the [`TruffleRuntime.createAssumption()`](com/oracle/truffle/api/TruffleRuntime.md#createAssumption%28%29) or the [`TruffleRuntime.createAssumption(String)`](com/oracle/truffle/api/TruffleRuntime.md#createAssumption%28java.lang.String%29) method. The Truffle compiler has special knowledge of this class in order to produce efficient machine code for checking an assumption in case the assumption object is a compile time constant. Therefore, assumptions should be stored in final fields in Truffle nodes. All instances of classes implementing `Assumption` must be held in `final` fields for compiler optimizations to take effect.
Do not manually subclass the [`Assumption`](com/oracle/truffle/api/Assumption.md) interface. This class is only intended to be subclassed by Truffle runtime implementations to avoid polymorphism in performance sensitive methods.
## Fields
### ALWAYS_VALID
`Assumption ALWAYS_VALID`. Since 22.1. An assumption that is always valid and fails with an [`UnsupportedOperationException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/UnsupportedOperationException.html) if invalidated. Cite: `com/oracle/truffle/api/Assumption.html#ALWAYS_VALID`
### NEVER_VALID
`Assumption NEVER_VALID`. Since 22.1. An assumption that is never valid. Cite: `com/oracle/truffle/api/Assumption.html#NEVER_VALID`
## Methods
### check()
`void check() throws InvalidAssumptionException`. Since 0.8 or earlier. Checks that this assumption is still valid. The method throws an exception, if this is no longer the case. This method is preferred over the `isValid()` method when writing guest language interpreter code. The catch block should perform a node rewrite (see `Node.replace(Node)`) with a node that no longer relies on the assumption. Throws: `InvalidAssumptionException`: If the assumption is no longer valid. Cite: `com/oracle/truffle/api/Assumption.html#check()`
### isValid()
`boolean isValid()`. Since 0.8 or earlier. Checks whether the assumption is still valid. Returns `boolean`: a boolean value indicating the validity of the assumption. Cite: `com/oracle/truffle/api/Assumption.html#isValid()`
### invalidate()
`void invalidate()`. Since 0.8 or earlier. Invalidates this assumption. Performs no operation, if the assumption is already invalid. Cite: `com/oracle/truffle/api/Assumption.html#invalidate()`
### invalidate(String)
`default void invalidate(String message)`. Since 0.33. Invalidates this assumption. Performs no operation, if the assumption is already invalid. Parameters: `message` `String`: a message stating the reason of the invalidation. Cite: `com/oracle/truffle/api/Assumption.html#invalidate(java.lang.String)`
### getName()
`String getName()`. Since 0.8 or earlier. A name for the assumption that is used for debug output. Returns `String`: the name of the assumption. Cite: `com/oracle/truffle/api/Assumption.html#getName()`
### isValidAssumption(Assumption)
`static boolean isValidAssumption(Assumption assumption)`. Since 19.0. Checks whether an assumption is not `null` and valid. Cite: `com/oracle/truffle/api/Assumption.html#isValidAssumption(com.oracle.truffle.api.Assumption)`
### isValidAssumption(Assumption[])
`static boolean isValidAssumption(Assumption[] assumptions)`. Since 19.0. Checks whether all assumptions in an array are not `null` and valid. Returns `false` if the assumptions array itself is `null`. This method is designed for compilation. Note that the provided assumptions array must be a compilation final array with `dimensions` set to one. Cite: `com/oracle/truffle/api/Assumption.html#isValidAssumption(com.oracle.truffle.api.Assumption[])`
### create()
`static Assumption create()`. Since 22.1. Creates a new assumption with a name. Shortcut for `TruffleRuntime.createAssumption()`. Cite: `com/oracle/truffle/api/Assumption.html#create()`
### create(String)
`static Assumption create(String name)`. Since 22.1. Creates a new assumption with a name. Shortcut for `TruffleRuntime.createAssumption(String)`. Cite: `com/oracle/truffle/api/Assumption.html#create(java.lang.String)`
# ◇ CallTarget
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface CallTarget
```
Represents the target of a call. Call targets are created automatically from a [`RootNode`](com/oracle/truffle/api/nodes/RootNode.md) by calling [`RootNode.getCallTarget()`](com/oracle/truffle/api/nodes/RootNode.md#getCallTarget%28%29).
A call target allows the runtime to employ a compilation heuristic to trigger partial evaluation of the underlying [`RootNode`](com/oracle/truffle/api/nodes/RootNode.md), typically in the background. Additionally, calling a call target builds a guest language level [`stack trace`](com/oracle/truffle/api/TruffleStackTrace.md) which can be inspected using [`TruffleRuntime.iterateFrames(com.oracle.truffle.api.frame.FrameInstanceVisitor)`](com/oracle/truffle/api/TruffleRuntime.md#iterateFrames%28com.oracle.truffle.api.frame.FrameInstanceVisitor%29) or [`TruffleStackTrace.getStackTrace(Throwable)`](com/oracle/truffle/api/TruffleStackTrace.md#getStackTrace%28java.lang.Throwable%29).
Do not subclass [`CallTarget`](com/oracle/truffle/api/CallTarget.md) directly, as this interface is likely to become sealed in the future.
**See also**
- [`RootNode`](com/oracle/truffle/api/nodes/RootNode.md)
- [`DirectCallNode`](com/oracle/truffle/api/nodes/DirectCallNode.md)
- [`IndirectCallNode`](com/oracle/truffle/api/nodes/IndirectCallNode.md)
## Methods
### call(Object...)
`Object call(Object... arguments)`. Since 0.8 or earlier. Calls the encapsulated root node with the given arguments and returns the result. By calling this method, the call location is looked up using `EncapsulatingNodeReference`. Use `call(Node, Object...)` if the call location is already known. Calling this method in partially evaluated code will allow it to get inlined if the receiver (this) is a `pe-constant`. Call site `cloning` is only supported if a `DirectCallNode` is used instead. Parameters: `arguments` `Object...`: The arguments passed to the call, as an object array. Returns `Object`: The result of the call. See also: `call(Node, Object...)`. Cite: `com/oracle/truffle/api/CallTarget.html#call(java.lang.Object...)`
### call(Node, Object...)
`default Object call(Node location, Object... arguments)`. Since 24.1. Calls the encapsulated root node with an explicit call location and arguments, and returns the result. This method should be preferred over `call(Object...)` if the current location is known, as it avoids looking up the current location from a thread-local. Parameters: `location` `Node`: A `Node` that identifies the location of this call. The location may be `null` if no location is available. `arguments` `Object...`: The arguments passed to the call, as an object array. Returns `Object`: The result of the call. See also: `call(Object...)`. Cite: `com/oracle/truffle/api/CallTarget.html#call(com.oracle.truffle.api.nodes.Node,java.lang.Object...)`
### call(Node, int, Object[])
`default Object call(Node location, int bytecodeIndex, Object[] arguments)`. Since 25.6. Calls the root node, preserving the explicit location and BCI for stack walking. Callers that do not have an explicit bytecode index should pass `-1`. Parameters: `location` `Node`: a `Node` that identifies the location of this call. The location may be `null` if no location is available. `bytecodeIndex` `int`: the bytecode index associated with this call, or `-1` if no explicit bytecode index is available. `arguments` `Object[]`: the arguments passed to the call, as an object array. Returns `Object`: the result of the call. See also: `call(Node, Object...)`. Cite: `com/oracle/truffle/api/CallTarget.html#call(com.oracle.truffle.api.nodes.Node,int,java.lang.Object[])`
# ◆ CompilerAsserts
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public final class CompilerAsserts
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `CompilerAsserts`
Assertions about the code produced by the Truffle compiler. All operations have no effect when either executed in the interpreter or in the compiled code. The assertions are checked during code generation and the Truffle compiler produces for failing assertions a stack trace that identifies the code position of the assertion in the context of the current compilation.
## Methods
### neverPartOfCompilation()
`public static void neverPartOfCompilation()`. Since 0.8 or earlier. Assertion that this code position should never be reached during compilation. It can be used for exceptional code paths or rare code paths that should never be included in a compilation unit. See `CompilerDirectives.transferToInterpreter()` for the corresponding compiler directive. `CompilerDirectives.bailout(String)` should be used if failing compilation is desired, e.g., for testing. `neverPartOfCompilation()` must not be reachable for runtime compilation, see the TruffleCheckNeverPartOfCompilation option. Cite: `com/oracle/truffle/api/CompilerAsserts.html#neverPartOfCompilation()`
### neverPartOfCompilation(String)
`public static void neverPartOfCompilation(String message)`. Since 0.8 or earlier. Assertion that this code position should never be reached during compilation. It can be used for exceptional code paths or rare code paths that should never be included in a compilation unit. See `CompilerDirectives.transferToInterpreter()` for the corresponding compiler directive. `CompilerDirectives.bailout(String)` should be used if failing compilation is desired, e.g., for testing. `neverPartOfCompilation()` must not be reachable for runtime compilation, see the TruffleCheckNeverPartOfCompilation option. Parameters: `message` `String`: text associated with the bailout exception. Cite: `com/oracle/truffle/api/CompilerAsserts.html#neverPartOfCompilation(java.lang.String)`
### compilationConstant(Object)
`public static void compilationConstant(Object value)`. Since 0.8 or earlier. Assertion that the corresponding value is reduced to a constant during compilation. This is, for example, useful to assert that an array has always the same size, although the actual value is only known at run-time. In most cases, it is preferred to use `CompilerAsserts.partialEvaluationConstant(Object)` and its specialized variants. Parameters: `value` `Object`: the value that must be constant during compilation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#compilationConstant(java.lang.Object)`
### partialEvaluationConstant(Object)
`public static void partialEvaluationConstant(Object value)`. Since 0.8 or earlier. Assertion that the corresponding value is reduced to a constant during the initial partial evaluation phase. Compared with `CompilerAsserts.compilationConstant(Object)`, the constantness of the value is checked much earlier in the compilation pipeline. It should therefore be preferred, also because its specialized variants avoid boxing. Parameters: `value` `Object`: the value that must be constant during compilation. See also: `CompilerAsserts.compilationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(java.lang.Object)`
### partialEvaluationConstant(boolean)
`public static void partialEvaluationConstant(boolean value)`. Since 19.3. Specialized version of `CompilerAsserts.compilationConstant(Object)` for `boolean` values. Parameters: `value` `boolean`: the value that must be constant during partial evaluation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(boolean)`
### partialEvaluationConstant(int)
`public static void partialEvaluationConstant(int value)`. Since 19.3. Specialized version of `CompilerAsserts.compilationConstant(Object)` for `int` values. Parameters: `value` `int`: the value that must be constant during partial evaluation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(int)`
### partialEvaluationConstant(float)
`public static void partialEvaluationConstant(float value)`. Since 19.3. Specialized version of `CompilerAsserts.compilationConstant(Object)` for `float` values. Parameters: `value` `float`: the value that must be constant during partial evaluation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(float)`
### partialEvaluationConstant(long)
`public static void partialEvaluationConstant(long value)`. Since 19.3. Specialized version of `CompilerAsserts.compilationConstant(Object)` for `long` values. Parameters: `value` `long`: the value that must be constant during partial evaluation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(long)`
### partialEvaluationConstant(double)
`public static void partialEvaluationConstant(double value)`. Since 19.3. Specialized version of `CompilerAsserts.compilationConstant(Object)` for `double` values. Parameters: `value` `double`: the value that must be constant during partial evaluation. See also: `CompilerAsserts.partialEvaluationConstant(Object)`. Cite: `com/oracle/truffle/api/CompilerAsserts.html#partialEvaluationConstant(double)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ CompilerDirectives
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public final class CompilerDirectives
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `CompilerDirectives`
Directives that influence the optimizations of the Truffle compiler. All of the operations have no effect when executed in the Truffle interpreter.
## Nested types
- [`CompilerDirectives.CompilationFinal`](com/oracle/truffle/api/CompilerDirectives.CompilationFinal.md) (annotation interface): Marks fields that should be considered final for a Truffle compilation although they are not final while executing in the interpreter.
- [`CompilerDirectives.EarlyEscapeAnalysis`](com/oracle/truffle/api/CompilerDirectives.EarlyEscapeAnalysis.md) (annotation interface): Requests the Truffle compiler to run escape analysis on this method before partial evaluation.
- [`CompilerDirectives.EarlyInline`](com/oracle/truffle/api/CompilerDirectives.EarlyInline.md) (annotation interface): Marks a method or constructor as a candidate for early inlining during Truffle compilation.
- [`CompilerDirectives.TruffleBoundary`](com/oracle/truffle/api/CompilerDirectives.TruffleBoundary.md) (annotation interface): Marks a method that it is considered as a boundary for Truffle partial evaluation.
- [`CompilerDirectives.ValueType`](com/oracle/truffle/api/CompilerDirectives.ValueType.md) (annotation interface): Marks classes as value types.
## Fields
### LIKELY_PROBABILITY
`public static final double LIKELY_PROBABILITY`. Since 0.8 or earlier. Constant value: `0.75`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#LIKELY_PROBABILITY`
### UNLIKELY_PROBABILITY
`public static final double UNLIKELY_PROBABILITY`. Since 0.8 or earlier. Constant value: `0.25`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#UNLIKELY_PROBABILITY`
### SLOWPATH_PROBABILITY
`public static final double SLOWPATH_PROBABILITY`. Since 0.8 or earlier. Constant value: `1.0E-4`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#SLOWPATH_PROBABILITY`
### FASTPATH_PROBABILITY
`public static final double FASTPATH_PROBABILITY`. Since 0.8 or earlier. Constant value: `0.9999`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#FASTPATH_PROBABILITY`
## Methods
### transferToInterpreter()
`public static void transferToInterpreter()`. Since 0.8 or earlier. Directive for the compiler to discontinue compilation at this code position and instead insert a transfer to the interpreter. Cite: `com/oracle/truffle/api/CompilerDirectives.html#transferToInterpreter()`
### transferToInterpreterAndInvalidate()
`public static void transferToInterpreterAndInvalidate()`. Since 0.8 or earlier. Directive for the compiler to discontinue compilation at this code position and instead insert a transfer to the interpreter, invalidating the currently executing machine code. Cite: `com/oracle/truffle/api/CompilerDirectives.html#transferToInterpreterAndInvalidate()`
### inInterpreter()
`public static boolean inInterpreter()`. Since 0.8 or earlier. Returns a boolean value indicating whether the method is executed in the interpreter. Returns `boolean`: `true` when executed in the interpreter, `false` in compiled code. Cite: `com/oracle/truffle/api/CompilerDirectives.html#inInterpreter()`
### hasNextTier()
`public static boolean hasNextTier()`. Since 22.0.0. Returns a boolean value indicating whether the method is executed in a compilation tier which can be replaced with a higher tier (e.g. interpretation tier can be replaced by a first tier, a first tier by a second tier compilation). Returns `boolean`: `true` when executed in the first tier Truffle compilation, `false` otherwise. Cite: `com/oracle/truffle/api/CompilerDirectives.html#hasNextTier()`
### inCompiledCode()
`public static boolean inCompiledCode()`. Since 0.8 or earlier. Returns a boolean value indicating whether the method is executed in the compiled code. Returns `boolean`: `false` when executed in the interpreter, `true` in compiled code. Cite: `com/oracle/truffle/api/CompilerDirectives.html#inCompiledCode()`
### preserveFrameStateHere()
`public static void preserveFrameStateHere()`. Since 25.1. Inserts a state-split marker at this program point so deoptimization restores frame state for the current bytecode location. This is intended for bytecode interpreters that need reliable transfer-to-interpreter transition reporting at specific program points. Cite: `com/oracle/truffle/api/CompilerDirectives.html#preserveFrameStateHere()`
### inCompilationRoot()
`public static boolean inCompilationRoot()`. Since 0.28 or earlier. Returns a boolean value indicating whether the method is executed in the root of a Truffle compilation. Returns `boolean`: `false` when executed in the interpreter or in an inlined `CallTarget`, `true` when in non-inlined compiled code. Cite: `com/oracle/truffle/api/CompilerDirectives.html#inCompilationRoot()`
### isCompilationConstant(Object)
`public static boolean isCompilationConstant(Object value)`. Since 0.8 or earlier. Returns a boolean indicating whether or not a given value is seen as constant in optimized code. If this method is called in the interpreter this method will always return `true`. Note that optimizations that a compiler will apply to code that is conditional on `isCompilationConstant` may be limited. For this reason `isCompilationConstant` is not recommended for use to select between alternate implementations of functionality depending on whether a value is constant. Instead, it is intended for use as a diagnostic mechanism. Returns `boolean`: `true` when given value is seen as compilation constant, `false` if not compilation constant. Cite: `com/oracle/truffle/api/CompilerDirectives.html#isCompilationConstant(java.lang.Object)`
### isPartialEvaluationConstant(Object)
`public static boolean isPartialEvaluationConstant(Object value)`. Since 0.8 or earlier. Returns a boolean indicating whether a given value is seen as constant during the initial partial evaluation phase. If this method is called in the interpreter this method will always return `true`. Because of that one should consider if the code guarded by this check should be run in interpreter or not. If it's faster to not run the guarded code in interpreter one can use: but beware that code is never run in interpreter and so might lead to subtle bugs and is harder to debug. If it does not matter much whether the code runs in interpreter it's best to just: Returns `boolean`: `true` when given value is seen as compilation constant or in interpreter, `false` otherwise. Cite: `com/oracle/truffle/api/CompilerDirectives.html#isPartialEvaluationConstant(java.lang.Object)`
```java
if (CompilerDirectives.inCompiledCode() && CompilerDirectives.isPartialEvaluationConstant(value)) {
// logic only run in compiled code if value is a PE constant
}
```
```java
if (CompilerDirectives.isPartialEvaluationConstant(value)) {
// logic run in interpreter and in compiled code if value is a PE constant
}
```
### interpreterOnly(Runnable)
`public static void interpreterOnly(Runnable runnable)`. Since 0.8 or earlier. Directive for the compiler that the given runnable should only be executed in the interpreter and ignored in the compiled code. Parameters: `runnable` `Runnable`: the closure that should only be executed in the interpreter. Cite: `com/oracle/truffle/api/CompilerDirectives.html#interpreterOnly(java.lang.Runnable)`
### interpreterOnly(Callable)
`public static T interpreterOnly(Callable callable) throws Exception`. Since 0.8 or earlier. Directive for the compiler that the given callable should only be executed in the interpreter. Parameters: `callable` `Callable`: the closure that should only be executed in the interpreter. Returns `T`: the result of executing the closure in the interpreter and null in the compiled code. Throws: `Exception`: If the closure throws an exception when executed in the interpreter. Cite: `com/oracle/truffle/api/CompilerDirectives.html#interpreterOnly(java.util.concurrent.Callable)`
### injectBranchProbability(double, boolean)
`public static boolean injectBranchProbability(double probability, boolean condition)`. Since 0.8 or earlier. Injects a probability for the given condition into the probability information of the immediately succeeding branch instruction for the condition. The probability must be a value between 0.0 and 1.0 (inclusive). The condition should not be a combined condition. Example usage immediately before an if statement (it specifies that the likelihood for a to be greater than b is 90%): ` if (injectBranchProbability(0.9, a > b)) { // ... } ` Example usage for a combined condition (it specifies that the likelihood for a to be greater than b is 90% and under the assumption that this is true, the likelihood for a being 0 is 10%): ` if (injectBranchProbability(0.9, a > b) && injectBranchProbability(0.1, a == 0)) { // ... } ` There are predefined constants for commonly used probabilities (see `LIKELY_PROBABILITY` , `UNLIKELY_PROBABILITY`, `SLOWPATH_PROBABILITY`, `FASTPATH_PROBABILITY` ). Parameters: `probability` `double`: the probability value between 0.0 and 1.0 that should be injected. Cite: `com/oracle/truffle/api/CompilerDirectives.html#injectBranchProbability(double,boolean)`
### bailout(String)
`public static void bailout(String reason)`. Since 0.8 or earlier. Bails out of a compilation (e.g., for guest language features that should never be compiled). Parameters: `reason` `String`: the reason for the bailout. Cite: `com/oracle/truffle/api/CompilerDirectives.html#bailout(java.lang.String)`
### materialize(Object)
`public static void materialize(Object obj)`. Since 0.8 or earlier. Ensures that the given object is not virtual, i.e., not removed by Escape Analysis at the point of this call. Parameters: `obj` `Object`: the object to exclude from Escape Analysis. Cite: `com/oracle/truffle/api/CompilerDirectives.html#materialize(java.lang.Object)`
### ensureAllocatedHere(T)
`public static T ensureAllocatedHere(T object)`. Since 24.1.0. Prevents the compiler from moving an allocation, enabling precise [`OutOfMemoryError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/OutOfMemoryError.html) exception locations. This intrinsic ensures the allocation's immobility and guarantees that the compiler's optimizations do not eliminate the allocation. Imposing such a restriction can hinder certain compiler optimizations, potentially degrading performance. If the intrinsic does not find an allocation as its argument, it causes a runtime compilation failure, invoking `CompilerDirectives.bailout(String)`. **Example usage:**. Cite: `com/oracle/truffle/api/CompilerDirectives.html#ensureAllocatedHere(T)`
```java
int[] tryAllocateArray() {
int[] array;
try {
array = CompilerDirectives.ensureAllocatedHere(new int[42]);
} catch (OutOfMemoryError e) {
// handle out of memory errors to maintain consistency
array = null;
}
return array;
}
```
### ensureVirtualized(Object)
`public static void ensureVirtualized(Object object)`. Since 0.8 or earlier. Ensures that the given object will be virtual (escape analyzed) at all points that are dominated by the current position. Cite: `com/oracle/truffle/api/CompilerDirectives.html#ensureVirtualized(java.lang.Object)`
### ensureVirtualizedHere(Object)
`public static void ensureVirtualizedHere(Object object)`. Since 0.8 or earlier. Ensures that the given object will be virtual at the current position. Cite: `com/oracle/truffle/api/CompilerDirectives.html#ensureVirtualizedHere(java.lang.Object)`
### blackhole(boolean)
`public static void blackhole(boolean value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(boolean)`
### blackhole(byte)
`public static void blackhole(byte value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(byte)`
### blackhole(short)
`public static void blackhole(short value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(short)`
### blackhole(char)
`public static void blackhole(char value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(char)`
### blackhole(int)
`public static void blackhole(int value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(int)`
### blackhole(long)
`public static void blackhole(long value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(long)`
### blackhole(float)
`public static void blackhole(float value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(float)`
### blackhole(double)
`public static void blackhole(double value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(double)`
### blackhole(Object)
`public static void blackhole(Object value)`. Since 21.2. Consume a value, making sure the compiler doesn't optimize away the computation of this value, even if it is otherwise unused. This should only be used for benchmarking purposes. Cite: `com/oracle/truffle/api/CompilerDirectives.html#blackhole(java.lang.Object)`
### castExact(Object, Class)
`public static T castExact(Object object, Class clazz)`. Since 0.33. Casts the given object to the exact class represented by `clazz`. The cast succeeds only if `object == null || object.getClass() == clazz` and thus fails for any subclass. Parameters: `object` `Object`: the object to be cast. `clazz` `Class`: the class to check against, must not be null. Returns `T`: the object after casting. Throws: `ClassCastException` (unchecked): if the object is non-null and not exactly of the given class. `NullPointerException` (unchecked): if the class argument is null. See also: [`Class.cast(Object)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Class.html#cast%28java.lang.Object%29). Cite: `com/oracle/truffle/api/CompilerDirectives.html#castExact(java.lang.Object,java.lang.Class)`
### isExact(Object, Class)
`public static boolean isExact(Object object, Class> clazz)`. Since 21.1. Checks the given object to the exact class represented by `clazz`. The method returns `true` only if `object != null && object.getClass() == clazz` and thus fails for any subclass. Parameters: `object` `Object`: the object to be cast. `clazz` `Class>`: the class to check against, must not be null. Throws: `NullPointerException` (unchecked): if the class argument is null. Cite: `com/oracle/truffle/api/CompilerDirectives.html#isExact(java.lang.Object,java.lang.Class)`
### shouldNotReachHere()
`public static RuntimeException shouldNotReachHere()`. Since 20.2. Indicates a code path that is not supposed to be reached during compilation or interpretation. Reaching this method is considered a fatal internal error and execution should not continue. Transfers to interpreter and `invalidates` the compiled code and always throws an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) when invoked. This method returns a runtime exception to be conveniently used in combination with Java throw statements, for example: Cite: `com/oracle/truffle/api/CompilerDirectives.html#shouldNotReachHere()`
```java
if (expectedCondition) {
return 42;
} else {
throw shouldNotReachHere();
}
```
### shouldNotReachHere(String)
`public static RuntimeException shouldNotReachHere(String message)`. Since 20.2. Indicates a code path that is not supposed to be reached during compilation or interpretation. Reaching this method is considered a fatal internal error and execution should not continue. Transfers to interpreter and `invalidates` the compiled code and always throws an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) when invoked. This method returns a runtime exception to be conveniently used in combination with Java throw statements, for example: Parameters: `message` `String`: an additional message for the exception thrown. Cite: `com/oracle/truffle/api/CompilerDirectives.html#shouldNotReachHere(java.lang.String)`
```java
if (expectedCondition) {
return 42;
} else {
throw shouldNotReachHere("Additional message");
}
```
### shouldNotReachHere(Throwable)
`public static RuntimeException shouldNotReachHere(Throwable cause)`. Since 20.2. Indicates a code path that is not supposed to be reached during compilation or interpretation. Reaching this method is considered a fatal internal error and execution should not continue. Transfers to interpreter and `invalidates` the compiled code and always throws an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) when invoked. This method returns a runtime exception to be conveniently used in combination with Java throw statements, for example: Parameters: `cause` `Throwable`: the cause if an exception was responsible for the unexpected case. Cite: `com/oracle/truffle/api/CompilerDirectives.html#shouldNotReachHere(java.lang.Throwable)`
```java
if (expectedCondition) {
return 42;
} else {
throw shouldNotReachHere("Additional message");
}
```
### shouldNotReachHere(String, Throwable)
`public static RuntimeException shouldNotReachHere(String message, Throwable cause)`. Since 20.2. Indicates a code path that is not supposed to be reached during compilation or interpretation. Reaching this method is considered a fatal internal error and execution should not continue. Transfers to interpreter and `invalidates` the compiled code and always throws an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) when invoked. This method returns a runtime exception to be conveniently used in combination with Java throw statements, for example: Parameters: `message` `String`: an additional message for the exception thrown. `cause` `Throwable`: the cause if an exception was responsible for the unexpected case. Cite: `com/oracle/truffle/api/CompilerDirectives.html#shouldNotReachHere(java.lang.String,java.lang.Throwable)`
```java
if (expectedCondition) {
return 42;
} else {
throw shouldNotReachHere("Additional message");
}
```
### mergeExplodeKey(int)
`public static int mergeExplodeKey(int i)`. Since 25.5. Marks a local variable as the key used for merging loop iterations in methods annotated with `LoopExplosionKind.MERGE_EXPLODE`. Using this outside of merge exploded methods will lead to a compilation failure. Call this method once before the loop, preferably immediately before it, and assign the return value back to the variable: Direct adjacency is not required, but the marked value must reach the first loop header unchanged and must not be consumed by an intervening merge-exploded loop. Key discovery happens only at initial entry; calling this method inside the loop is too late. Later iterations track the current value at the discovered location. A nested `int` or `long` value stored in objects virtualized by `EarlyEscapeAnalysis` can also be marked, for example `state.inner.key = CompilerDirectives.mergeExplodeKey(state.inner.key);`. This is only supported while every object on that access path remains virtual and never escapes. Only a single variable can currently be marked with this method; marking multiple variables causes a compilation failure. This restriction will be lifted in a future release. At every iteration, the key value must be a compile-time constant `int` or `long` so the compiler can create a distinct merge point for each key value and correctly handle irreducibly exploded structures. If this is not upheld, a compilation failure occurs. Other variables must have the same value at every iteration where the key matches (e.g., partial evaluate to the same constant or remain unchanged). If a non-key variable changes while the key stays the same, a compilation failure occurs because the states cannot be merged. A way to explicitly mark a variable as exempt from the same-value requirement is planned. Parameters: `i` `int`: the variable that should be used as the merge key. Returns `int`: the unchanged value. See also: `mergeExplodeKey(long)`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#mergeExplodeKey(int)`
```java
int bci = 0;
// ...
bci = CompilerDirectives.mergeExplodeKey(bci);
while (bci != END_BCI) {
// ...
}
```
### mergeExplodeKey(long)
`public static long mergeExplodeKey(long i)`. Since 25.5. Marks a `long` variable as the key used for merging loop iterations in methods annotated with `LoopExplosionKind.MERGE_EXPLODE`. Using this outside of merge exploded methods will lead to a compilation failure. The usage and restrictions are the same as for `mergeExplodeKey(int)`, including the requirement that the key be a compile-time constant at every loop header. For irreducible loops, `long` key values must also fit in the signed 32-bit `int` range. Values outside of this range will cause a compilation failure. Parameters: `i` `long`: the variable that should be used as the merge key. Returns `long`: the unchanged value. See also: `mergeExplodeKey(int)`. Cite: `com/oracle/truffle/api/CompilerDirectives.html#mergeExplodeKey(long)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ CompilerDirectives.CompilationFinal
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier. Nested in [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({FIELD})
public @interface CompilerDirectives.CompilationFinal
```
Marks fields that should be considered final for a Truffle compilation although they are not final while executing in the interpreter. If the field type is an array type, the compiler considers reads with a constant index as constants.
## Elements
### dimensions()
`int dimensions() default -1`. Since 0.14. Specifies the number of array dimensions to be marked as compilation final. This value should be specified for all array-typed compilation-final fields and should be left unspecified for other field types for which it has no meaning. The allowed range is from 0 to the number of declared array dimensions (inclusive). Specifically, a `dimensions` value of 0 marks only the reference to the (outermost) array as final but not its elements, a value of 1 marks the outermost array and all its elements as final but not the elements of any nested arrays. For compatibility reasons, array-typed fields without an explicit `dimensions` parameter default to the number of array dimensions declared in the field type. Default: `-1`. Cite: `com/oracle/truffle/api/CompilerDirectives.CompilationFinal.html#dimensions()`
# @ CompilerDirectives.EarlyEscapeAnalysis
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface CompilerDirectives.EarlyEscapeAnalysis
```
Requests the Truffle compiler to run escape analysis on this method before partial evaluation.
When a method or constructor is annotated with `@EarlyEscapeAnalysis`, a dedicated partial escape analysis phase is executed for that method before partial evaluation. This allows allocations that do not escape the method to be virtualized or eliminated, and their fields to be treated as partial-evaluation-time constants where possible.
### Typical use cases
- Methods that allocate temporary objects whose fields are used only locally and are expected to become constants after partial evaluation.
- Interpreters that keep loop state in a small object (for example a bytecode index), in combination with [`ExplodeLoop`](com/oracle/truffle/api/nodes/ExplodeLoop.md) and [`EarlyInline`](com/oracle/truffle/api/CompilerDirectives.EarlyInline.md), so that the state object can be fully scalar replaced.
### Example: non-escaping temporary object
```java
@EarlyEscapeAnalysis
private static int computeConstant() {
TestEscape v = new TestEscape(42);
CompilerAsserts.partialEvaluationConstant(v.value);
// After early escape analysis and partial evaluation this method reduces to "return 42".
return v.value;
}
static final class TestEscape {
int value;
TestEscape(int value) {
this.value = value;
}
}
```
### Example: loop state object in a merge-exploded interpreter
```java
static final class BytecodeIndex {
int bci;
}
@CompilationFinal(dimensions = 1) private final byte[] bytecodes = new byte[]{0, 1, 4, 2, 3};
@ExplodeLoop(kind = LoopExplosionKind.MERGE_EXPLODE)
@EarlyEscapeAnalysis
int execute(Boolean v) {
byte[] bc = this.bytecodes;
BytecodeIndex index = new BytecodeIndex();
while (true) {
CompilerAsserts.partialEvaluationConstant(index.bci);
switch (bc[index.bci]) {
case 0:
index.bci++;
break;
case 1:
// {@code branchTrue} is early inlined and sees the virtual {@code index}
// object.
branchTrue(bc, index, v);
break;
case 2:
return 41;
case 3:
return 42;
case 4:
throw CompilerDirectives.shouldNotReachHere();
}
}
}
@EarlyInline
private static void branchTrue(byte[] bc, BytecodeIndex index, Boolean v) {
if (v) {
index.bci = bc[index.bci + 1];
} else {
index.bci = index.bci + 2;
}
}
```
# @ CompilerDirectives.EarlyInline
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface CompilerDirectives.EarlyInline
```
Marks a method or constructor as a candidate for early inlining during Truffle compilation.
Methods annotated with `@EarlyInline` are considered by a dedicated early inlining phase before partial evaluation. This exposes the helper's control flow and state updates directly in the caller so that other Truffle directives such as [`ExplodeLoop`](com/oracle/truffle/api/nodes/ExplodeLoop.md) and [`EarlyEscapeAnalysis`](com/oracle/truffle/api/CompilerDirectives.EarlyEscapeAnalysis.md) can see and optimize them.
Only direct calls whose target method is annotated are considered, and normal inlining preconditions still apply. Indirect calls, native methods, and methods that cannot be inlined are ignored.
### Typical use cases
- Inlining small branch or bytecode handlers into a [`merge-exploded`](com/oracle/truffle/api/nodes/ExplodeLoop.LoopExplosionKind.md#MERGE_EXPLODE) interpreter loop so that loop explosion can merge state across the helper call.
- Inlining helpers that update non-escaping state objects in methods annotated with [`EarlyEscapeAnalysis`](com/oracle/truffle/api/CompilerDirectives.EarlyEscapeAnalysis.md), improving escape analysis and scalar replacement.
### Example: early inlining of a branch handler
```java
@CompilationFinal(dimensions = 1) private final byte[] bytecodes = new byte[]{0, 1, 4, 2, 3};
@ExplodeLoop(kind = LoopExplosionKind.MERGE_EXPLODE)
int execute(Boolean v) {
byte[] bc = this.bytecodes;
int bci = 0;
while (true) {
CompilerAsserts.partialEvaluationConstant(bci);
switch (bc[bci]) {
case 0:
bci++;
break;
case 1:
// {@code branchTrue} is inlined before partial evaluation.
bci = branchTrue(bc, bci, v);
break;
case 2:
return 41;
case 3:
return 42;
default:
throw CompilerDirectives.shouldNotReachHere();
}
}
}
@EarlyInline
private static int branchTrue(byte[] bc, int bci, Boolean v) {
if (v) {
return bc[bci + 1];
} else {
return bci + 2;
}
}
```
# @ CompilerDirectives.TruffleBoundary
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier. Nested in [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface CompilerDirectives.TruffleBoundary
```
Marks a method that it is considered as a boundary for Truffle partial evaluation.
## Elements
### transferToInterpreterOnException()
`boolean transferToInterpreterOnException() default true`. Since 0.28. Determines whether execution should be transferred to the interpreter if an exception is thrown across this boundary, in which case the caller's compiled code is invalidated and will not transfer to the interpreter on exceptions for this method again. Default: `true`. Cite: `com/oracle/truffle/api/CompilerDirectives.TruffleBoundary.html#transferToInterpreterOnException()`
### allowInlining()
`boolean allowInlining() default false`. Since 0.27. Considers this Truffle boundary invoke as an inlining candidate. Partial evaluation cannot inline a boundary, but a later inlining pass can. Default: `false`. Cite: `com/oracle/truffle/api/CompilerDirectives.TruffleBoundary.html#allowInlining()`
# @ CompilerDirectives.ValueType
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier. Nested in [`CompilerDirectives`](com/oracle/truffle/api/CompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({TYPE})
public @interface CompilerDirectives.ValueType
```
Marks classes as value types. Reference comparisons (==) between instances of those classes have undefined semantics and can either return true or false.
# ◆ ContextLocal
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 20.3.
```java
public abstract class ContextLocal
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ContextLocal`
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()`](com/oracle/truffle/api/ContextLocal.md#get%28%29) or for other contexts using [`get(TruffleContext)`](com/oracle/truffle/api/ContextLocal.md#get%28com.oracle.truffle.api.TruffleContext%29). Context locals can be created for languages and instruments. See links below for usage examples.
**See also**
- [`Usage with languages.`](com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.md#createContextLocal%28com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory%29)
- [`Usage with instruments.`](com/oracle/truffle/api/instrumentation/TruffleInstrument.ContextLocalProvider.md#createContextLocal%28com.oracle.truffle.api.instrumentation.TruffleInstrument.ContextLocalFactory%29)
## Constructors
### ContextLocal(Object)
`protected ContextLocal(Object polyglotObject)`. Since 20.3. Custom subclasses of context local are not allowed. Cite: `com/oracle/truffle/api/ContextLocal.html#(java.lang.Object)`
## Methods
### get()
`public abstract T get()`. Since 20.3. 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` (unchecked): 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. Cite: `com/oracle/truffle/api/ContextLocal.html#get()`
### get(TruffleContext)
`public abstract T get(TruffleContext context)`. Since 20.3. 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` (unchecked): 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. Cite: `com/oracle/truffle/api/ContextLocal.html#get(com.oracle.truffle.api.TruffleContext)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ ContextThreadLocal
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 20.3.
```java
public abstract class ContextThreadLocal
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ContextThreadLocal`
A context thread local reference that refers to a value that is created for each polyglot context and thread. Context thread references can be used to attach data to a polyglot context for a thread. That data can be retrieved efficiently for the current context and thread using [`get()`](com/oracle/truffle/api/ContextThreadLocal.md#get%28%29) or less efficiently for other contexts and other threads using [`get(TruffleContext, Thread)`](com/oracle/truffle/api/ContextThreadLocal.md#get%28com.oracle.truffle.api.TruffleContext,java.lang.Thread%29). Context thread locals can be created for languages and instruments. See links below for usage examples.
**See also**
- [`Usage with languages.`](com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.md#createContextThreadLocal%28com.oracle.truffle.api.TruffleLanguage.ContextThreadLocalFactory%29)
- [`Usage with instruments.`](com/oracle/truffle/api/instrumentation/TruffleInstrument.ContextLocalProvider.md#createContextThreadLocal%28com.oracle.truffle.api.instrumentation.TruffleInstrument.ContextThreadLocalFactory%29)
## Constructors
### ContextThreadLocal(Object)
`protected ContextThreadLocal(Object polyglotObject)`. Since 20.3. Custom subclasses of context local are not allowed. Cite: `com/oracle/truffle/api/ContextThreadLocal.html#(java.lang.Object)`
## Methods
### get()
`public abstract T get()`. Since 20.3. Returns the context thread local value for the currently entered context and thread. This method is intended to be used on compiled code paths. The return value is never `null`. Throws [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if no current context is entered on the current thread. Cite: `com/oracle/truffle/api/ContextThreadLocal.html#get()`
### get(Thread)
`public abstract T get(Thread t)`. Since 20.3. Returns the context thread local value for the currently entered context and the given thread. This method is less efficient than `get()` or `get(TruffleContext)` as it requires synchronization between the threads. The return value is never `null`. Throws [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if no current context is entered on the current thread. Cite: `com/oracle/truffle/api/ContextThreadLocal.html#get(java.lang.Thread)`
### get(TruffleContext)
`public abstract T get(TruffleContext t)`. Since 20.3. Returns the context thread local value for the given context and the current thread.his method is intended to be used on compiled code paths. The return value is never `null`. Throws [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if no current context is entered on the current thread. Cite: `com/oracle/truffle/api/ContextThreadLocal.html#get(com.oracle.truffle.api.TruffleContext)`
### get(TruffleContext, Thread)
`public abstract T get(TruffleContext context, Thread t)`. Since 20.3. Returns the context thread local value for the given context and the given thread. The context does not need to, but may be entered when retrieving the current context local. This method is less efficient than `get()` or `get(TruffleContext)` as it requires synchronization between the threads. The return value is never `null`. Throws [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) if no current context is entered on the current thread. Cite: `com/oracle/truffle/api/ContextThreadLocal.html#get(com.oracle.truffle.api.TruffleContext,java.lang.Thread)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ ExactMath
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public final class ExactMath
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ExactMath`
This class contains exact math related methods that are generally useful for dynamic language implementations.
## Methods
### multiplyHigh(int, int)
`public static int multiplyHigh(int x, int y)`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/ExactMath.html#multiplyHigh(int,int)`
### multiplyHigh(long, long)
`public static long multiplyHigh(long x, long y)`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/ExactMath.html#multiplyHigh(long,long)`
### multiplyHighUnsigned(int, int)
`public static int multiplyHighUnsigned(int x, int y)`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/ExactMath.html#multiplyHighUnsigned(int,int)`
### multiplyHighUnsigned(long, long)
`public static long multiplyHighUnsigned(long x, long y)`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/ExactMath.html#multiplyHighUnsigned(long,long)`
### truncate(float)
`public static float truncate(float x)`. Since 21.1. Removes the decimal part (aka truncation or rounds towards zero) of the given float. This corresponds to the IEEE 754 `roundToIntegralTowardZero` operation (IEEE Std 754-2008, section 5.9, page 41). Cite: `com/oracle/truffle/api/ExactMath.html#truncate(float)`
### truncate(double)
`public static double truncate(double x)`. Since 21.1. Removes the decimal part (aka truncation or rounds towards zero) of the given double. This corresponds to the IEEE 754 `roundToIntegralTowardZero` operation (IEEE Std 754-2008, section 5.9, page 41). Cite: `com/oracle/truffle/api/ExactMath.html#truncate(double)`
### truncateToUnsignedLong(double)
`public static long truncateToUnsignedLong(double x)`. Since 25.0. Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation of `NaN` and `x <= -1` to `0`, and `x >= 2`64 to `2`63`-1` (`-1`). Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (`x <= -1`) and overflow (`x >= 0x1p64`) first. Parameters: `x` `double`: input value. Returns `long`: the unsigned integer result, wrapped in a signed integer. Cite: `com/oracle/truffle/api/ExactMath.html#truncateToUnsignedLong(double)`
### truncateToUnsignedLong(float)
`public static long truncateToUnsignedLong(float x)`. Since 25.0. Converts the float value to unsigned long with truncation (i.e. rounding towards zero) and saturation of `NaN` and `x <= -1` to `0`, and `x >= 2`64 to `2`63`-1` (`-1`). Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (`x <= -1f`) and overflow (`x >= 0x1p64f`) first. Parameters: `x` `float`: input value. Returns `long`: the unsigned integer result, wrapped in a signed integer. Cite: `com/oracle/truffle/api/ExactMath.html#truncateToUnsignedLong(float)`
### truncateToUnsignedInt(double)
`public static int truncateToUnsignedInt(double x)`. Since 25.0. Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation of `NaN` and `x <= -1` to `0`, and `x >= 2`32 to `2`31`-1` (`-1`). Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (`x <= -1`) and overflow (`x >= 0x1p32`) first. Parameters: `x` `double`: input value. Returns `int`: the unsigned integer result, wrapped in a signed integer. Cite: `com/oracle/truffle/api/ExactMath.html#truncateToUnsignedInt(double)`
### truncateToUnsignedInt(float)
`public static int truncateToUnsignedInt(float x)`. Since 25.0. Converts the float value to unsigned int with truncation (i.e. rounding towards zero) and saturation of `NaN` and `x <= -1` to `0`, and `x >= 2`32 to `2`31`-1` (`-1`). Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (`x <= -1`) and overflow (`x >= 0x1p64`) first. Parameters: `x` `float`: input value. Returns `int`: the unsigned integer result, wrapped in a signed integer. Cite: `com/oracle/truffle/api/ExactMath.html#truncateToUnsignedInt(float)`
### unsignedToDouble(long)
`public static double unsignedToDouble(long x)`. Since 25.0. Converts the given unsigned `long` to the closest `double` value. Parameters: `x` `long`: unsigned integer input, wrapped in a signed integer. Returns `double`: the `double` result. Cite: `com/oracle/truffle/api/ExactMath.html#unsignedToDouble(long)`
### unsignedToFloat(long)
`public static float unsignedToFloat(long x)`. Since 25.0. Converts the given unsigned `long` to the closest `float` value. Parameters: `x` `long`: unsigned integer input, wrapped in a signed integer. Returns `float`: the `float` result. Cite: `com/oracle/truffle/api/ExactMath.html#unsignedToFloat(long)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ HostCompilerDirectives
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 21.0.
```java
public final class HostCompilerDirectives
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `HostCompilerDirectives`
Directives that influence the optimizations of the host compiler. These operations affect how the Truffle interpreter is itself compiled.
## Nested types
- [`HostCompilerDirectives.BytecodeInterpreterFetchOpcode`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterFetchOpcode.md) (annotation interface): Annotates a method that fetches the next opcode.
- [`HostCompilerDirectives.BytecodeInterpreterHandler`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.md) (annotation interface): Annotates a method that serves as a Truffle interpreter bytecode handler, that is, a method implements the complete semantics of a single bytecode instruction.
- [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.md) (annotation interface): Configuration for all bytecode interpreter handler arguments, including the receiver.
- [`HostCompilerDirectives.BytecodeInterpreterSwitch`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterSwitch.md) (annotation interface): Marks a method that is an implementation of a Truffle interpreter, and which should receive additional optimization budget.
- [`HostCompilerDirectives.InliningCutoff`](com/oracle/truffle/api/HostCompilerDirectives.InliningCutoff.md) (annotation interface): Hints to Truffle host inlining that a particular method is partial evaluatable, but it would be a good place for a cutoff when performing host inlining.
- [`HostCompilerDirectives.InliningRoot`](com/oracle/truffle/api/HostCompilerDirectives.InliningRoot.md) (annotation interface): Marks a method as a candidate for Truffle host inlining.
## Methods
### inInterpreterFastPath()
`public static boolean inInterpreterFastPath()`. Since 23.0. Indicates whether a branch is executed only in the interpreter. In addition to `CompilerDirectives.inInterpreter()`, this method instructs the host compiler to treat the positive branch as frequently executed code of high importance. Branches protected by this method should be treated as if they were runtime compiled code paths, even if they may never actually be compiled. This means that slow-paths must be protected using either `CompilerDirectives.transferToInterpreterAndInvalidate()` or `TruffleBoundary`. A common use case for this directive is in counting condition profiles, where counters must be protected by `CompilerDirectives.inInterpreter()` but also need to be optimized as fast-path by the host compiler. Without this directive, the host compiler may treat the branch as a slow-path branch. Returns `boolean`: `true` if executed in the interpreter, `false` in compiled code. Cite: `com/oracle/truffle/api/HostCompilerDirectives.html#inInterpreterFastPath()`
### markThreadedSwitch(int)
`public static int markThreadedSwitch(int input)`. Since 25.1. Marks a switch statement within a loop as a candidate for threaded switch optimization. Threaded switch replicates the switch statement at the end of each case, improving branch prediction at the processor level. Usage example: The compiler recognizes the code blocks from the loop header up to the switch and duplicates them into each case that continues the while loop. This effectively transforms the structure as follows: When additional statements follow the switch block within a loop, the compiler may trigger an optimization to duplicate these statements into each case block. If this duplication does not occur, the compiler can still identify the loop as a candidate for threaded switch optimization and apply relevant optimizations to minimize overhead in the loop header, such as postponing register spilling from the loop header to cases with actual register pressure, even at the cost of code bloat. However, due to the presence of these tail statements, the loop has only one back edge, which effectively disables threading. The compiler may also reject candidates for threaded switch optimization if the identified code blocks, after inlining, contain complex control flow or operations beyond memory reads. To log decisions related to threaded switch optimization, use the Graal option `TraceThreadedSwitchOptimization`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.html#markThreadedSwitch(int)`
```java
while (cond) {
input = inlinedNextOpcode();
switch (markThreadedSwitch(input)) {
case op1: { body1; }
case op2: { body2; }
}
}
```
```java
if (cond) {
input = inlinedNextOpcode();
switch (markThreadedSwitch(input)) {
case op1: {
body1;
if (cond) {
input = inlinedNextOpcode();
switch (markThreadedSwitch(input)) // go to matching case of outer switch
}
}
case op2: {
body2;
if (cond) {
input = inlinedNextOpcode();
switch (markThreadedSwitch(input)) // go to matching case of outer switch
}
}
}
}
```
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ HostCompilerDirectives.BytecodeInterpreterFetchOpcode
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD})
public @interface HostCompilerDirectives.BytecodeInterpreterFetchOpcode
```
Annotates a method that fetches the next opcode. The annotated method must be side-effect free, must not throw for valid interpreter state, and share the same signature with [`BytecodeInterpreterHandler`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.md)-annotated methods in the same enclosing class. It will be inlined into Truffle interpreter bytecode handler stubs to enable tail call threading.
# @ HostCompilerDirectives.BytecodeInterpreterHandler
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD})
public @interface HostCompilerDirectives.BytecodeInterpreterHandler
```
Annotates a method that serves as a Truffle interpreter bytecode handler, that is, a method implements the complete semantics of a single bytecode instruction.
For more details, see the [ One Compilation per Bytecode Handler documentation](https://github.com/oracle/graal/blob/master/truffle/docs/OneCompilationPerBytecodeHandler.md).
## Elements
### value()
`int[] value()`. The handled bytecode's opcodes. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.html#value()`
### threading()
`boolean threading() default true`. Indicates whether to enable tail call threading at the end of this handler. If `false`, the threading will terminate, and control will return to the switch-loop after this handler is executed. Alternatively, omitting the `BytecodeInterpreterHandler` annotation will cause control to return to the switch-loop before this handler is executed. Default: `true`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.html#threading()`
### safepoint()
`boolean safepoint() default true`. Indicates whether host safepoint should be inserted in the stub correspond to this handler. Default: `true`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.html#safepoint()`
# @ HostCompilerDirectives.BytecodeInterpreterHandlerConfig
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD})
public @interface HostCompilerDirectives.BytecodeInterpreterHandlerConfig
```
Configuration for all bytecode interpreter handler arguments, including the receiver. Must be used in conjunction with [`BytecodeInterpreterSwitch`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterSwitch.md).
**See also**
- [`BytecodeInterpreterHandler`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.md)
## Nested types
- [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.md) (annotation interface): Configuration for a bytecode interpreter handler argument.
## Elements
### maximumOperationCode()
`int maximumOperationCode()`. The maximum unsigned value of the opcode. This is relevant for `BytecodeInterpreterHandler` when tail call threading is enabled, and is used to construct a handler table. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.html#maximumOperationCode()`
### arguments()
`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument[] arguments()`. Configuration for each method argument. For non-static methods, the first element corresponds to the receiver. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.html#arguments()`
### secondarySwitch()
`boolean secondarySwitch() default false`. Indicates that the annotated method implements a secondary partition of a bytecode interpreter switch. A secondary switch is expected to be inlined into a primary `BytecodeInterpreterSwitch` method during host compilation. Its handler configuration is retained so that handler calls originating from the inlined secondary switch can be mapped to the primary switch's handler stubs. When compiled as a separate method, however, handler calls in a secondary switch are not outlined. In particular, a deoptimization target may invoke the separately compiled secondary switch without first passing through host inlining. Keeping its handler calls ordinary prevents such execution from entering threaded handler stubs without the primary switch's exception and state-management paths. Returns `boolean`: `true` if the annotated method is a secondary switch partition whose handler calls must not be outlined when the method is compiled separately. Default: `false`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.html#secondarySwitch()`
### enableTailDuplication()
`boolean enableTailDuplication() default false`. Since 25.5. Enables tail duplication for this interpreter's threaded bytecode handler stubs. When enabled, the compiler removes the control-flow anchor at the handler return and encourages duplication of the dispatch tail, allowing different handler paths to have separate indirect tail-call sites. Duplication remains subject to compiler safety checks and code size budgets; enabling this option does not guarantee that a tail will be duplicated. Separate dispatch sites can improve branch prediction, but the additional code can also reduce performance. This option is disabled by default and should only be enabled after measuring the effect on the interpreter's workloads. When disabled, the return anchor is retained and no tail-duplication hint is emitted. This option has no effect on non-threaded stubs, which always retain their return anchor. Default: `false`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.html#enableTailDuplication()`
# @ HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.md).
```java
@Retention(RUNTIME)
@Target({METHOD})
public @interface HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument
```
Configuration for a bytecode interpreter handler argument.
**See also**
- [`BytecodeInterpreterHandler`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandler.md)
## Nested types
- [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.md) (enum class): No description.
- [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.md) (annotation interface): Configuration for an expanded field.
## Elements
### returnValue()
`boolean returnValue() default false`. Indicates that this argument will be updated with the return value of the handler. The interpreter must store the handler result directly back to the logical local represented by this argument. Threaded handler stubs rely on that direct store shape to keep the local consistent when an exception unwinds before the normal return-value update path runs. Default: `false`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.html#returnValue()`
### expand()
`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind expand() default NONE`. Indicates that this argument will be expanded in a Truffle interpreter bytecode handler stub if its expansion kind is not `ExpansionKind.NONE`. Default: `NONE`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.html#expand()`
### expandedType()
`Class> expandedType() default void.class`. Since 25.5. Exact concrete type reconstructed for a `ExpansionKind.VIRTUAL` argument. `void.class` uses the declared parameter type. An explicit type must be a concrete instance class assignable to the parameter type. It may be defined by a different class loader from the handler's declaring class. At each outlined call, the compiler must prove that the argument is non-null and has this exact type. All instance fields, including inherited fields, are expanded. The expansion type must have at least one instance field. This property is ignored on HotSpot, which uses the declared parameter type. Default: `void.class`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.html#expandedType()`
### fields()
`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field[] fields() default {}`. Indicates the fields to be expanded of this argument if its expansion kind is `ExpansionKind.MATERIALIZED`. Default: `{}`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.html#fields()`
### nonNull()
`boolean nonNull() default true`. Indicates that this argument is always non-null. A null check will be placed before the call site and before threading dispatch. This property is irrelevant for primitive arguments. Default: `true`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.html#nonNull()`
# ≡ HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Enum class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Nested in [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.md).
```java
public enum HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html) > `ExpansionKind`
## Enum constants
### NONE
`NONE`. No expansion. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.html#NONE`
### MATERIALIZED
`MATERIALIZED`. The argument is expanded into its subfields in addition to the original argument. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.html#MATERIALIZED`
### VIRTUAL
`VIRTUAL`. The argument is expanded into its subfields without the original argument. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.html#VIRTUAL`
## Methods
### values()
`public static HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind[] values()`. Returns the enum constants in declaration order. Returns `HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind[]`: Returns the enum constants in declaration order. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.html#values()`
### valueOf(String)
`public static HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind valueOf(String name)`. Returns the enum constant with the given name. Parameters: `name` `String`: The exact name of the enum constant. Returns `HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind`: Returns the enum constant with the given name. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.ExpansionKind.html#valueOf(java.lang.String)`
## Inherited members
- From class [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#clone%28%29), [`compareTo`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#compareTo%28E%29), [`describeConstable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#describeConstable%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#finalize%28%29), [`getDeclaringClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#getDeclaringClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#hashCode%28%29), [`name`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#name%28%29), [`ordinal`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#ordinal%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#toString%28%29), [`valueOf`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument`](com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.md).
```java
@Retention(RUNTIME)
@Target({METHOD})
public @interface HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field
```
Configuration for an expanded field.
## Elements
### name()
`String name()`. Name of the field. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.html#name()`
### nonNull()
`boolean nonNull() default true`. Indicates that this field is always non-null. A null check will be placed before the call site and before threading dispatch. This property is irrelevant for primitive fields. Default: `true`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.html#nonNull()`
### templateVariable()
`int templateVariable() default 0`. Since 25.5. Marks this field as template state for threaded bytecode handlers. A value of `N >= 2` creates one handler variant for each field value in the range `[0, N)`. A value of `0` disables template specialization for this field, and `1` is invalid. Each variant starts with the corresponding field value. Before control transfers to the next threaded handler, every control-flow path must assign a known valid value or retain the current value. If multiple template fields are updated, their values must be resolved through the same control-flow merge. When threading ends, the current field value is written back to the original argument. When template mode is disabled, the field behaves like an ordinary expanded field. The field must be an `int` field of a `ExpansionKind.VIRTUAL` argument. See the [ template handler documentation](https://github.com/oracle/graal/blob/master/truffle/docs/OneCompilationPerBytecodeHandler.md#template) for examples and additional restrictions. Default: `0`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.html#templateVariable()`
### validWhen()
`String validWhen() default ""`. Since 25.5. Names the template-variable field on the same virtual-expanded argument that controls whether this field's incoming value is valid. An empty name disables conditional validity and requires `valid()` to be empty. Only non-final, non-template `long` or `double` fields of `ExpansionKind.VIRTUAL` arguments support conditional validity. This metadata is ignored on HotSpot and whenever template mode is disabled. Default: `""`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.html#validWhen()`
### valid()
`int[] valid() default {}`. Since 25.5. Values of `validWhen()` for which the incoming field value is valid. Otherwise, the generated handler starts with an arbitrary field value that must not be observed, including through exception-state materialization. The handler may overwrite the field before reading it. This contract applies at handler entry, not to subsequent changes of the template-variable field. This metadata is ignored on HotSpot and whenever template mode is disabled. Default: `{}`. Cite: `com/oracle/truffle/api/HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field.html#valid()`
# @ HostCompilerDirectives.BytecodeInterpreterSwitch
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 21.0. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface HostCompilerDirectives.BytecodeInterpreterSwitch
```
Marks a method that is an implementation of a Truffle interpreter, and which should receive additional optimization budget.
This annotation is used to annotate the root method of a bytecode interpreter, and it hints the compiler to invest extra effort into optimizing such methods. Language implementers are advised to inspect the IR of the interpreter when using this.
# @ HostCompilerDirectives.InliningCutoff
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 22.3. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface HostCompilerDirectives.InliningCutoff
```
Hints to Truffle host inlining that a particular method is partial evaluatable, but it would be a good place for a cutoff when performing host inlining. A host compiler may use this information as a hint to take trade-offs optimizing the code. Good examples of cutoffs are:
- Methods related to instrumentation or tracing. Instrumentation and tracing are typically not critical for interpreter performance.
- Methods raising guest language exceptions. Such paths must often partially evaluate for good peak performance, but are not a priority to optimize during interpreter execution.
- Methods related to Truffle interoperability behavior. Such paths are typically only used exceptionally, as the vast majority of code is likely non-interop code.
- Methods that are very complex and would only deny other more important methods to be inlined.
If a method is already annotated with [`TruffleBoundary`](com/oracle/truffle/api/CompilerDirectives.TruffleBoundary.md) or is dominated by a call to [`transferToInterpreter()`](com/oracle/truffle/api/CompilerDirectives.md#transferToInterpreterAndInvalidate%28%29) then this method has no effect, as any path that is not designed for partial evaluation is already considered a slow-path in hosted inlining.
This annotation may be used to tune Truffle hosted inlining decisions. It is useful in cases where the host inliner did not have enough budget to exhaustively inline the entire partial evaluatable fast-path. In such a case it might be worthwhile to annotate rarely executed methods with [`InliningCutoff`](com/oracle/truffle/api/HostCompilerDirectives.InliningCutoff.md) to reduce their priority to make room for more important methods.
For more details on host inlining see the [documentation](https://github.com/oracle/graal/blob/master/truffle/docs/HostCompilation.md)
# @ HostCompilerDirectives.InliningRoot
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.1. Nested in [`HostCompilerDirectives`](com/oracle/truffle/api/HostCompilerDirectives.md).
```java
@Retention(RUNTIME)
@Target({METHOD, CONSTRUCTOR})
public @interface HostCompilerDirectives.InliningRoot
```
Marks a method as a candidate for Truffle host inlining. The host compiler may use this information to guide inlining and optimization decisions.
Annotated methods must be designed for partial evaluation. This annotation should not be applied to arbitrary Java code or third-party libraries, as doing so may cause severe performance degradation.
Typical examples include `execute` methods of cached nodes. The Truffle DSL automatically applies this annotation to every generated execute method. It is recommended to be used for manually written `execute` methods as well.
For more details, see the [ Truffle host compilation documentation](https://github.com/oracle/graal/blob/master/truffle/docs/HostCompilation.md).
# ◆ InstrumentInfo
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.26.
```java
public final class InstrumentInfo
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `InstrumentInfo`
Represents public information about an instrument.
## Methods
### getId()
`public String getId()`. Since 0.26. Gets the id clients can use to acquire this instrument. Returns `String`: this instrument's unique id. Cite: `com/oracle/truffle/api/InstrumentInfo.html#getId()`
### getName()
`public String getName()`. Since 0.26. Gets a human readable name of this instrument. Returns `String`: this instrument's user-friendly name. Cite: `com/oracle/truffle/api/InstrumentInfo.html#getName()`
### getVersion()
`public String getVersion()`. Since 0.26. Gets the version of this instrument. Returns `String`: this instrument's version. Cite: `com/oracle/truffle/api/InstrumentInfo.html#getVersion()`
### toString()
`public String toString()`. Since 0.26. Overrides `toString()`. Cite: `com/oracle/truffle/api/InstrumentInfo.html#toString()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ InternalResource
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1.
```java
public interface InternalResource
```
Represents an internal resource of a language that can be lazily unpacked to a cache user directory.
A typical implementation of an `InternalResource` for a platform-specific library stored in the `META-INF/resources////` looks like this:
```java
@InternalResource.Id("resource-id")
final class NativeLibResource implements InternalResource {
@Override
public void unpackFiles(Env env, Path targetDirectory) throws IOException {
Path base = Path.of("META-INF", "resources", "mylanguage", "resource-id",
env.getOS().toString(), env.getCPUArchitecture().toString());
env.unpackResourceFiles(base.resolve("file-list"), targetDirectory, base);
}
@Override
public String versionHash(Env env) {
try {
Path hashResource = Path.of("META-INF", "resources", "mylanguage", "resource-id",
env.getOS().toString(), env.getCPUArchitecture().toString(), "sha256");
return env.readResourceLines(hashResource).get(0);
} catch (IOException ioe) {
throw CompilerDirectives.shouldNotReachHere(ioe);
}
}
}
```
The resource files are listed in the `META-INF/resources/////file-list` file. For the file list format, refer to [`InternalResource.unpackFiles(Env, Path)`](com/oracle/truffle/api/InternalResource.md#unpackFiles%28com.oracle.truffle.api.InternalResource.Env,java.nio.file.Path%29). Additionally, the `META-INF/resources/////sha256` file contains an SHA-256 hash of the resource files. It is recommended to use non-encapsulated resource paths that include the component ID and resource ID, as this helps prevent ambiguity when the language or instrument is used in an unnamed module.
## Nested types
- [`InternalResource.CPUArchitecture`](com/oracle/truffle/api/InternalResource.CPUArchitecture.md) (enum class): Represents a supported CPU architecture.
- [`InternalResource.Env`](com/oracle/truffle/api/InternalResource.Env.md) (class): Access to common utilities for unpacking resource files.
- [`InternalResource.Id`](com/oracle/truffle/api/InternalResource.Id.md) (annotation interface): The annotation used to lookup InternalResource by an id.
- [`InternalResource.OS`](com/oracle/truffle/api/InternalResource.OS.md) (enum class): Represents a supported operating system.
## Methods
### unpackFiles(InternalResource.Env, Path)
`void unpackFiles(InternalResource.Env env, Path targetDirectory) throws IOException`. Since 23.1. Unpacks all resources to a given target directory. The target directory is guaranteed to be writable and the unpacking is synchronized by a file system lock. If a resource was previously cached then `versionHash(Env)` is invoked and the version string is compared. If it matches then `unpackFiles(Env, Path)` will not be invoked and the directory will be used as previously unpacked. The target directory is guaranteed to exist and guaranteed to be empty. Ideally the result of this method should be idempotent in order to be safely cacheable. Care should be taken, if system properties are used that change the result of this method. It is safe to use `OS` and `CPUArchitecture` enums as internal resources are never cached or moved across operating system architectures. No guest language code must run as part of this method. Parameters: `targetDirectory` `Path`: the target directory to extract files to. Cite: `com/oracle/truffle/api/InternalResource.html#unpackFiles(com.oracle.truffle.api.InternalResource.Env,java.nio.file.Path)`
### versionHash(InternalResource.Env)
`String versionHash(InternalResource.Env env) throws IOException`. Since 23.1. Returns the version hash to be used for this resource. It is the responsibility of the implementer to ensure that this version hash is unique. For example, an SHA-256 could be a good version identifier for file based resources. Since the version hash serves as a path component on the host filesystem, its length is restricted to a maximum of 128 bytes. If the version hash length exceeds this limit, an `IOException` will be thrown during unpacking. Cite: `com/oracle/truffle/api/InternalResource.html#versionHash(com.oracle.truffle.api.InternalResource.Env)`
# ≡ InternalResource.CPUArchitecture
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Enum class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1. Nested in [`InternalResource`](com/oracle/truffle/api/InternalResource.md).
```java
public enum InternalResource.CPUArchitecture
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html) > `CPUArchitecture`
Represents a supported CPU architecture.
## Enum constants
### AARCH64
`AARCH64`. Since 23.1. The ARMv8 64-bit architecture. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#AARCH64`
### AMD64
`AMD64`. Since 23.1. The x86 64-bit architecture. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#AMD64`
### UNSUPPORTED
`UNSUPPORTED`. Since 25.1. Represents an unsupported architecture. To enable execution on unsupported platforms, the system property `-Dpolyglot.engine.allowUnsupportedPlatform=true` must be explicitly set. If this property is not set and the platform is unsupported, the `getCurrent()` method will throw an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html). Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#UNSUPPORTED`
## Methods
### values()
`public static InternalResource.CPUArchitecture[] values()`. Returns the enum constants in declaration order. Returns `InternalResource.CPUArchitecture[]`: Returns the enum constants in declaration order. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#values()`
### valueOf(String)
`public static InternalResource.CPUArchitecture valueOf(String name)`. Returns the enum constant with the given name. Parameters: `name` `String`: The exact name of the enum constant. Returns `InternalResource.CPUArchitecture`: Returns the enum constant with the given name. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#valueOf(java.lang.String)`
### toString()
`public String toString()`. Since 23.1. Returns the string representing CPU architecture name. Overrides `toString()`. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#toString()`
### getCurrent()
`public static InternalResource.CPUArchitecture getCurrent()`. Since 23.1. Returns the current CPU architecture. Cite: `com/oracle/truffle/api/InternalResource.CPUArchitecture.html#getCurrent()`
## Inherited members
- From class [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#clone%28%29), [`compareTo`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#compareTo%28E%29), [`describeConstable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#describeConstable%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#finalize%28%29), [`getDeclaringClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#getDeclaringClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#hashCode%28%29), [`name`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#name%28%29), [`ordinal`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#ordinal%28%29), [`valueOf`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ InternalResource.Env
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1. Nested in [`InternalResource`](com/oracle/truffle/api/InternalResource.md).
```java
public final class InternalResource.Env
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Env`
Access to common utilities for unpacking resource files.
## Methods
### inContextPreinitialization()
`public boolean inContextPreinitialization()`. Since 23.1. Returns `true` if the engine causing the resource unpacking is being pre-initialized. Cite: `com/oracle/truffle/api/InternalResource.Env.html#inContextPreinitialization()`
### inNativeImageBuild()
`public boolean inNativeImageBuild()`. Since 23.1. Returns `true` if resource unpacking happens during the native image build. Cite: `com/oracle/truffle/api/InternalResource.Env.html#inNativeImageBuild()`
### getCPUArchitecture()
`public InternalResource.CPUArchitecture getCPUArchitecture()`. Since 23.1. Returns the current processor architecture. The value can be used to resolve an architecture specific files during resource unpacking. Cite: `com/oracle/truffle/api/InternalResource.Env.html#getCPUArchitecture()`
### getOS()
`public InternalResource.OS getOS()`. Since 23.1. Returns the current operating system. The value can be used to resolve an OS specific files during resource unpacking. Cite: `com/oracle/truffle/api/InternalResource.Env.html#getOS()`
### readResourceLines(Path)
`public List readResourceLines(Path location) throws IOException`. Since 23.1. Reads a resource from the module, which owns the `InternalResource` implementation class. If the resource is encapsulated in the module, see [`Module.getResourceAsStream(String)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Module.html#getResourceAsStream%28java.lang.String%29), the module needs to open the `location` enclosing package to the `org.graalvm.truffle` module. It is recommended to use non-encapsulated resource paths. Parameters: `location` `Path`: relative path that identifies the resource in the module. The relative path gets resolved into an absolute path using the archive root. Returns `List`: the lines from the resource as a [`List`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/List.html). Throws: `IOException`: in case of IO error. Cite: `com/oracle/truffle/api/InternalResource.Env.html#readResourceLines(java.nio.file.Path)`
### unpackResourceFiles(Path, Path, …)
`public void unpackResourceFiles(Path source, Path target, Path relativizeTo, Predicate filter) throws IOException`. Since 24.2. Extracts files from the module, which owns the `InternalResource` implementation class, listed in the `source` file list and places them into the `target` folder. If resources are encapsulated within the module, see [`Module.getResourceAsStream(String)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Module.html#getResourceAsStream%28java.lang.String%29), the module needs to open the enclosing package of the resources to the `org.graalvm.truffle` module. It is recommended to use non-encapsulated resource paths. The file list is a [`Java properties`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Properties.html) file where resource files serve as keys, and the corresponding values consist of serialized attributes separated by `','`. Currently, only the POSIX file permissions attribute is supported. The format of this attribute follows the same convention used by the [`PosixFilePermissions.fromString(String)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/attribute/PosixFilePermissions.html#fromString%28java.lang.String%29). Example of a file list content: Parameters: `source` `Path`: the relative path that identifies the file list resource in the module. The relative path gets resolved into an absolute path using the archive root. `target` `Path`: the folder to extract resources to. `relativizeTo` `Path`: the path used to relativize the file list entries in the `target` folder. In other words, the file list entries are resolved using the `target` directory after removing the `relativizeTo` path. `filter` `Predicate`: resource path filter. Only resources at resource paths for which the filter predicate returns `true` are unpacked. Throws: `IllegalArgumentException` (unchecked): if `relativizeTo` is an absolute path or file list contains an absolute path. `IOException`: in case of IO error. Cite: `com/oracle/truffle/api/InternalResource.Env.html#unpackResourceFiles(java.nio.file.Path,java.nio.file.Path,java.nio.file.Path,java.util.function.Predicate)`
```java
META-INF/resources/darwin/amd64/bin/libtrufflenfi.dylib = rwxr-xr-x
META-INF/resources/common/include/trufflenfi.h = rw-r--r--
```
### unpackResourceFiles(Path, Path, Path)
`public void unpackResourceFiles(Path source, Path target, Path relativizeTo) throws IOException`. Since 23.1. Extracts files from the module, which owns the `InternalResource` implementation class, listed in the `source` file list and places them into the `target` folder. Same as `unpackResourceFiles(Path, Path, Path, Predicate)` with `filter = p -> true`. See also: `unpackResourceFiles(Path, Path, Path, Predicate)`. Cite: `com/oracle/truffle/api/InternalResource.Env.html#unpackResourceFiles(java.nio.file.Path,java.nio.file.Path,java.nio.file.Path)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ InternalResource.Id
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1. Nested in [`InternalResource`](com/oracle/truffle/api/InternalResource.md).
```java
@Retention(RUNTIME)
@Target({TYPE})
public @interface InternalResource.Id
```
The annotation used to lookup [`InternalResource`](com/oracle/truffle/api/InternalResource.md) by an id. The internal resource can be designated as either required or optional. For required internal resources, their availability is imperative. In addition to being annotated with this annotation, they also need to be registered using the [`TruffleLanguage.Registration.internalResources()`](com/oracle/truffle/api/TruffleLanguage.Registration.md#internalResources%28%29) method to be associated with a specific language or instrument. On the other hand, optional internal resources are not mandatory in the runtime. Instead of being registered using the [`TruffleLanguage.Registration.internalResources()`](com/oracle/truffle/api/TruffleLanguage.Registration.md#internalResources%28%29) annotation, they should supply the relevant language or instrument id through [`Id.componentId()`](com/oracle/truffle/api/InternalResource.Id.md#componentId%28%29).
## Elements
### value()
`String value()`. Since 23.1. An internal resource identifier that is a valid path component and unique per language. Cite: `com/oracle/truffle/api/InternalResource.Id.html#value()`
### componentId()
`String componentId() default ""`. Since 23.1. A Truffle language or instrument identifier for which the resource is registered. The `componentId` is necessary only for optional internal resources to associate them with the appropriate language or instrument. For required internal resources, the `componentId` can be left unset. Default: `""`. Cite: `com/oracle/truffle/api/InternalResource.Id.html#componentId()`
### optional()
`boolean optional() default false`. Since 23.1. Marks the annotated resource as optional. By default, internal resources are considered required and must be registered using `TruffleLanguage.Registration` or `TruffleInstrument.Registration`. Optional internal resources are retrieved using the [`java.util.ServiceLoader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/ServiceLoader.html) mechanism. The service implementation is generated by an annotation processor. Therefore, for proper functionality, the Truffle DSL processor must be included in the processor path. Default: `false`. Cite: `com/oracle/truffle/api/InternalResource.Id.html#optional()`
# ≡ InternalResource.OS
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Enum class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1. Nested in [`InternalResource`](com/oracle/truffle/api/InternalResource.md).
```java
public enum InternalResource.OS
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html) > `OS`
Represents a supported operating system.
## Enum constants
### DARWIN
`DARWIN`. Since 23.1. The macOS operating system. Cite: `com/oracle/truffle/api/InternalResource.OS.html#DARWIN`
### LINUX
`LINUX`. Since 23.1. The Linux operating system. Cite: `com/oracle/truffle/api/InternalResource.OS.html#LINUX`
### WINDOWS
`WINDOWS`. Since 23.1. The Windows operating system. Cite: `com/oracle/truffle/api/InternalResource.OS.html#WINDOWS`
### UNSUPPORTED
`UNSUPPORTED`. Since 25.1. Represents an unsupported operating system. To enable execution on unsupported platforms, the system property `-Dpolyglot.engine.allowUnsupportedPlatform=true` must be explicitly set. If this property is not set and the platform is unsupported, the `getCurrent()` method will throw an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html). Cite: `com/oracle/truffle/api/InternalResource.OS.html#UNSUPPORTED`
## Methods
### values()
`public static InternalResource.OS[] values()`. Returns the enum constants in declaration order. Returns `InternalResource.OS[]`: Returns the enum constants in declaration order. Cite: `com/oracle/truffle/api/InternalResource.OS.html#values()`
### valueOf(String)
`public static InternalResource.OS valueOf(String name)`. Returns the enum constant with the given name. Parameters: `name` `String`: The exact name of the enum constant. Returns `InternalResource.OS`: Returns the enum constant with the given name. Cite: `com/oracle/truffle/api/InternalResource.OS.html#valueOf(java.lang.String)`
### toString()
`public String toString()`. Since 23.1. Returns the string representing operating system name. Overrides `toString()`. Cite: `com/oracle/truffle/api/InternalResource.OS.html#toString()`
### getCurrent()
`public static InternalResource.OS getCurrent()`. Since 23.1. Returns the current operating system. Cite: `com/oracle/truffle/api/InternalResource.OS.html#getCurrent()`
## Inherited members
- From class [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#clone%28%29), [`compareTo`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#compareTo%28E%29), [`describeConstable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#describeConstable%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#finalize%28%29), [`getDeclaringClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#getDeclaringClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#hashCode%28%29), [`name`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#name%28%29), [`ordinal`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#ordinal%28%29), [`valueOf`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ⚡︎ OptimizationFailedException
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Exception in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public class OptimizationFailedException extends RuntimeException
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Throwable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html) > [`Exception`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Exception.html) > [`RuntimeException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/RuntimeException.html) > `OptimizationFailedException`
## Constructors
### OptimizationFailedException(Throwable, RootCallTarget)
`public OptimizationFailedException(Throwable cause, RootCallTarget callTarget)`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/OptimizationFailedException.html#(java.lang.Throwable,com.oracle.truffle.api.RootCallTarget)`
## Methods
### getCallTarget()
`public RootCallTarget getCallTarget()`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/OptimizationFailedException.html#getCallTarget()`
## Inherited members
- From class [`Throwable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html): [`addSuppressed`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#addSuppressed%28java.lang.Throwable%29), [`fillInStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#fillInStackTrace%28%29), [`getCause`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#getCause%28%29), [`getLocalizedMessage`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#getLocalizedMessage%28%29), [`getMessage`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#getMessage%28%29), [`getStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#getStackTrace%28%29), [`getSuppressed`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#getSuppressed%28%29), [`initCause`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#initCause%28java.lang.Throwable%29), [`printStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#printStackTrace%28%29), [`printStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#printStackTrace%28java.io.PrintStream%29), [`printStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#printStackTrace%28java.io.PrintWriter%29), [`setStackTrace`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#setStackTrace%28java.lang.StackTraceElement[]%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html#toString%28%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ Option
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.27.
```java
@Retention(CLASS)
@Target({FIELD})
public @interface Option
```
Describes the attributes of an option whose [`value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionKey.html) is in a static field annotated by this annotation. If used in a class then a package-protected class following the name pattern `$classNameOptionDescriptors` is generated. The generated class implements [`OptionDescriptors`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html) and contains all options specified by the declaring class.
If the [`Option`](com/oracle/truffle/api/Option.md) annotation is used in a subclass of [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) or [`com.oracle.truffle.api.instrumentation.TruffleInstrument`](com/oracle/truffle/api/instrumentation/TruffleInstrument.md) then the option descriptor prefix is automatically inherited from the [`language id`](com/oracle/truffle/api/TruffleLanguage.Registration.md#id%28%29) or the [`instrument id`](com/oracle/truffle/api/instrumentation/TruffleInstrument.Registration.md#id%28%29). If the class is not a language or an instrument then the [`Option.Group`](com/oracle/truffle/api/Option.Group.md) annotation can be used on the class to specify a option group name prefix.
The [`option descriptor name`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getName%28%29) is generated from the [`group name`](com/oracle/truffle/api/Option.Group.md#value%28%29) and the [`option name`](com/oracle/truffle/api/Option.md#name%28%29) separated by `'.'`. If the option name is an empty [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) then the trailing `'.'` will be removed from the descriptor name such that it exactly matches the group name. If, for example, the option group is `'js'` and the option name is inherited from the field name `'ECMACompatibility'` then the full descriptor name is `'js.ECMACompatibility'`.
**Example usage:**
```java
@TruffleLanguage.Registration(id = "mylang", name = "My Language",
version = "1.0")
abstract static class MyLanguage extends TruffleLanguage {
// the descriptor name for MyOption1 is 'mylang.MyOption1'
@Option(help = "Help Text.", category = OptionCategory.USER,
stability = OptionStability.STABLE)
static final OptionKey MyOption1 = new OptionKey<>("");
// the descriptor name for SecondOption is 'mylang.secondOption'
@Option(help = "Help Text.", name = "secondOption",
category = OptionCategory.EXPERT,
stability = OptionStability.EXPERIMENTAL)
static final OptionKey SecondOption = new OptionKey<>(false);
@Override
protected Context createContext(TruffleLanguage.Env env) {
if (env.getOptions().get(SecondOption)) {
// options are available via environment
}
return null;
}
@Override
protected OptionDescriptors getOptionDescriptors() {
// this class is generated by the annotation processor
return new MyLanguageOptionDescriptors();
}
}
```
.
**See also**
- [`OptionDescriptor`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html)
- [`Option.Group`](com/oracle/truffle/api/Option.Group.md)
## Nested types
- [`Option.Group`](com/oracle/truffle/api/Option.Group.md) (annotation interface): Must be applied on classes containing option fields to specify a name prefix if the prefix cannot be inferred by language or instrument.
## Elements
### name()
`String name() default ""`. Since 0.27. Returns a custom name for the option. If not specified then the name of the annotated field is used. The [`option descriptor name`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getName%28%29) is generated from the `group name` and the `option name` separated by `'.'`. If the option name is an empty [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) then the trailing `'.'` will be removed from the descriptor name such that it exactly matches the group name. If, for example, the option group is `'js'` and the option name is inherited from the field name `'ECMACompatibility'` then the full descriptor name is `'js.ECMACompatibility'`. Default: `""`. Cite: `com/oracle/truffle/api/Option.html#name()`
### help()
`String help()`. Since 0.27. Returns a help message for the option. New lines can be embedded in the message with `"%n"`. The generated an option descriptor returns this value as result of [`OptionDescriptor.getHelp()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getHelp%28%29). Recommendation: Include the default value for the option and the end of the text, e.g. `"Enable or disable the option (default: true)."`. Cite: `com/oracle/truffle/api/Option.html#help()`
### deprecated()
`boolean deprecated() default false`. Since 0.27. Returns `true` if this option is deprecated. The generated option descriptor returns this value as result of [`OptionDescriptor.isDeprecated()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#isDeprecated%28%29). Default: `false`. Cite: `com/oracle/truffle/api/Option.html#deprecated()`
### deprecationMessage()
`String deprecationMessage() default ""`. Since 20.1.0. Returns the deprecation reason and the recommended fix. The generated option descriptor returns this value as result of [`OptionDescriptor.getDeprecationMessage()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getDeprecationMessage%28%29). Default: `""`. Cite: `com/oracle/truffle/api/Option.html#deprecationMessage()`
### category()
`OptionCategory category()`. Since 0.27. Specifies the category of the option. The generated option descriptor returns this value as result of [`OptionDescriptor.getCategory()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getCategory%28%29). Cite: `com/oracle/truffle/api/Option.html#category()`
### stability()
`OptionStability stability() default EXPERIMENTAL`. Since 19.0. Defines the stability of this option. The default value is [`OptionStability.EXPERIMENTAL`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionStability.html#EXPERIMENTAL). Default: `EXPERIMENTAL`. Cite: `com/oracle/truffle/api/Option.html#stability()`
### usageSyntax()
`String usageSyntax() default ""`. Since 22.1. Describes in short the syntax of accepted values for this option. This value is used when generating help messages to better explain how to use the option. Combine with the help message to illustrate to users how to correctly use the option. For example: Recommendations: if the option accepts a discrete number of values (e.g. boolean, enum) list the values separated by a '\|' character. The default value for enums should be placed as the first in the list. e.g. `"true|false"`, `"none|red|green|blue|white"`; if the options accepts a value representing a well-known concept or a number representing particular units, place that concept/unit between \< and \> e.g. `""`, `""`, `""`, `"<>"`; if the options accepts a range of numbers use the range syntax: \[a,b\] for inclusive range from a to b, (a, b) for exclusive range from a to b, \[a, b) for range from a to b including a and (a, b\] for range from a to b including b. If the range is infinite use inf and -inf. For example: `"[0, 100]"`, `"(0.0, 1.0)"`, `"[0, inf)`.; if the options accepts a comma-separated list, use two comma-separated values and a `...`. Apply these same recommendations to individual values, e.g. `",,..."`.; if the options accepts a custom format, describe the format in a generic manner e.g. ip address - `"*.*.*.*"`, CSV Person - `",,"`. Default: `""`. Cite: `com/oracle/truffle/api/Option.html#usageSyntax()`
```java
@Option(name = "Enabled", help = "Enable/Disable the option.", usageSyntax = "true|false")
```
### sandbox()
`SandboxPolicy sandbox() default TRUSTED`. Since 23.0. Specifies the most strict sandbox policy in which the option can be used. The option can be used for an engine/context with the specified sandbox policy or a weaker one. For example, if an option specifies `ISOLATED` policy, it can be used for an engine/context configured with sandbox policy `TRUSTED`, `CONSTRAINED` or `ISOLATED`. But it cannot be used for an engine/context configured with the `UNTRUSTED` sandbox policy. Default: `TRUSTED`. See also: [`SandboxPolicy`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html). Cite: `com/oracle/truffle/api/Option.html#sandbox()`
### constant()
`boolean constant() default false`. Since 25.1. Declares this option as immutable after polyglot runtime initialization, enabling constant propagation and dead-code elimination when read through [`org.graalvm.options.ConstantOptionKey.getConstantValue()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/ConstantOptionKey.html#getConstantValue%28%29). Constant options must use [`org.graalvm.options.ConstantOptionKey`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/ConstantOptionKey.html) as their field type. Their value is fixed before the polyglot runtime is initialized and cannot be changed at runtime. The value is read from the system property `-Dpolyglot.=` during class initialization; if absent, the [`default value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionKey.html#getDefaultValue%28%29) is used. Once set, calls to [`org.graalvm.options.ConstantOptionKey.getConstantValue()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/ConstantOptionKey.html#getConstantValue%28%29) on a `static final` field are eligible for constant folding by the GraalVM compiler, allowing dead branches to be eliminated. The default value is `false`. Default: `false`. See also: [`org.graalvm.options.ConstantOptionKey`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/ConstantOptionKey.html). Cite: `com/oracle/truffle/api/Option.html#constant()`
# @ Option.Group
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.27. Nested in [`Option`](com/oracle/truffle/api/Option.md).
```java
@Retention(CLASS)
@Target({TYPE})
public @interface Option.Group
```
Must be applied on classes containing [`option`](com/oracle/truffle/api/Option.md) fields to specify a name prefix if the prefix cannot be inferred by language or instrument.
The [`option descriptor name`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getName%28%29) is generated from the [`option name prefix`](com/oracle/truffle/api/Option.Group.md#value%28%29) and the [`option name`](com/oracle/truffle/api/Option.md#name%28%29) separated by `'.'`. If the option name is an empty [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) then the trailing `'.'` will be removed from the descriptor name.
## Elements
### value()
`String[] value()`. Since 0.27. A set of group names that are used as prefix for all options of the annotated class. If multiple group names are specified then descriptors for each combination of group and option name is generated. The [`option descriptor name`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptor.html#getName%28%29) is generated from the `group name` and the `option name` separated by `'.'`. If the option name is an empty [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) then the trailing `'.'` will be removed from the descriptor name such that it exactly matches the group name. If, for example, the option group is `'js'` and the option name is inherited from the field name `'ECMACompatibility'` then the full descriptor name is `'js.ECMACompatibility'`. Cite: `com/oracle/truffle/api/Option.Group.html#value()`
# ◇ ReplaceObserver
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface ReplaceObserver
```
An observer that is notified whenever a child node is replaced. Note this is **not** called if the RootNode does not have a CallTarget yet.
## Methods
### nodeReplaced(Node, Node, CharSequence)
`boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason)`. Since 0.8 or earlier. Returns `true` if the event is consumed and no parent nodes should be notified by for replaces. Returns `false` if the parent `Node` or `CallTarget` should get notified. Cite: `com/oracle/truffle/api/ReplaceObserver.html#nodeReplaced(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.nodes.Node,java.lang.CharSequence)`
# ◇ RootCallTarget
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface RootCallTarget extends CallTarget
```
Extends: [`CallTarget`](com/oracle/truffle/api/CallTarget.md)
Represents the target of a call to a [`RootNode`](com/oracle/truffle/api/nodes/RootNode.md), i.e., to another tree of nodes. Instances of this class are created lazily and can be accessed via [`RootNode.getCallTarget()`](com/oracle/truffle/api/nodes/RootNode.md#getCallTarget%28%29).
## Methods
### getRootNode()
`RootNode getRootNode()`. Since 0.8 or earlier. Cite: `com/oracle/truffle/api/RootCallTarget.html#getRootNode()`
## Inherited members
- From interface [`CallTarget`](com/oracle/truffle/api/CallTarget.md): [`call`](com/oracle/truffle/api/CallTarget.md#call%28com.oracle.truffle.api.nodes.Node,int,java.lang.Object[]%29), [`call`](com/oracle/truffle/api/CallTarget.md#call%28com.oracle.truffle.api.nodes.Node,java.lang.Object...%29), [`call`](com/oracle/truffle/api/CallTarget.md#call%28java.lang.Object...%29)
# ◆ ThreadLocalAction
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 21.1.
```java
public abstract class ThreadLocalAction
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ThreadLocalAction`
Represents an action that is executed at a [`safepoint`](com/oracle/truffle/api/TruffleSafepoint.md) location of the guest language execution. Thread local actions can be submitted by [`languages`](com/oracle/truffle/api/TruffleLanguage.Env.md#submitThreadLocal%28java.lang.Thread[],com.oracle.truffle.api.ThreadLocalAction%29) or [`instruments`](com/oracle/truffle/api/instrumentation/TruffleInstrument.Env.md#submitThreadLocal%28com.oracle.truffle.api.TruffleContext,java.lang.Thread[],com.oracle.truffle.api.ThreadLocalAction%29). When an action is submitted it will be [`performed`](com/oracle/truffle/api/ThreadLocalAction.md#perform%28com.oracle.truffle.api.ThreadLocalAction.Access%29) locally on the threads they are submitted to. After submitting a thread local action a [`Future`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html) is returned that allows to wait for and cancel the submitted action.
Thread local actions can be configured to allow side-effects using the constructor of the action. If side-effects are allowed (`true`), then the thread-local action is allowed to throw non-internal guest language exceptions from the action and modify the observable guest application state. Otherwise, the action is not allowed to modify the observable state, and any non-internal guest language exception will be transformed to an internal error of type [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html). Side-effects may be temporarily [`disabled`](com/oracle/truffle/api/TruffleSafepoint.md#setAllowSideEffects%28boolean%29) by the guest language.
Thread local actions can also be set to be executed in a synchronous or asynchronous way. A submitted synchronous thread-local action waits until it is started on all threads that it was submitted on. Then the action is [`performed`](com/oracle/truffle/api/ThreadLocalAction.md#perform%28com.oracle.truffle.api.ThreadLocalAction.Access%29) on all threads. After they were performed on a thread, the action waits for all threads to complete. No synchronous thread-local actions can be submitted while performing synchronous actions, as this may lead to deadlocks. If a synchronous event is submitted during a synchronous event, then a [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown when the action is submitted. Asynchronous thread-local actions might start and complete to perform independently of each other. There is no restriction on how they may be submitted.
Thread local actions are guaranteed to be executed in the same order as they were submitted for a context. If a context has pending thread-local actions, the actions may be canceled when the context is canceled or closed invalid. Exceptions thrown by the action will be forwarded handled by the guest language implementation. The only exception is for truffle exceptions that are thrown for non-side-effecting events.
Notifications of blocking:
[`notifyBlocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyBlocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) and [`notifyUnblocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyUnblocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) notify thread local actions that their processing has been blocked/unblocked due to [`a blocked call`](com/oracle/truffle/api/TruffleSafepoint.md#setBlockedFunction%28com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.TruffleSafepoint.Interrupter,com.oracle.truffle.api.TruffleSafepoint.InterruptibleFunction,T,java.lang.Runnable,java.util.function.Consumer%29). [`notifyBlocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyBlocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) is called for each pending action at the beginning of a blocked call and for each of the continuations of the blocked call after it is interrupted and thread local actions are processed. [`ThreadLocalAction.notifyUnblocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyUnblocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) is called for each pending action at the end of a blocked call and also right after each of its interruptions, before thread local actions are processed and the blocked call continues.
In case a thread local action is submitted during a blocked call, the call is interrupted and [`notifyUnblocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyUnblocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) is called without a previous call to [`notifyBlocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyBlocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29). Recurring thread local actions do not repeatedly interrupt a blocked call - a blocked call is not interrupted if all pending actions are recurring actions submitted before the blocked call. New submissions of thread local actions still interrupt blocked calls, no matter if the new thread local actions are recurring or not. When a blocked call is interrupted, all pending actions are processed no matter if they are recurring or not.
The notifications of blocking are especially useful for recurring thread local actions as those actions don't interrupt blocked calls and the notifications inform them about the potentially long time intervals when those actions are not executed due to the blocked calls. Non-recurring thread local actions mainly benefit from the [`ThreadLocalAction.notifyUnblocked(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#notifyUnblocked%28com.oracle.truffle.api.ThreadLocalAction.Access%29) notification telling them that they interrupted a blocked call. For example, a safepoint sampler might want to exclude the samples from blocked calls.
Example Usage:
```java
Env env; // language or instrument environment
env.submitThreadLocal(null, new ThreadLocalAction(true, true) {
@Override
protected void perform(Access access) {
assert access.getThread() == Thread.currentThread();
}
@Override
protected void notifyBlocked(Access access) {
assert access.getThread() == Thread.currentThread();
}
@Override
protected void notifyUnblocked(Access access) {
assert access.getThread() == Thread.currentThread();
}
@Override
protected String name() {
return "MyAction"
}
});
```
Further information can be found in the [safepoint tutorial](http://github.com/oracle/graal/blob/master/truffle/docs/Safepoints.md).
**See also**
- [`TruffleSafepoint`](com/oracle/truffle/api/TruffleSafepoint.md)
- [`TruffleLanguage.Env.submitThreadLocal`](com/oracle/truffle/api/TruffleLanguage.Env.md#submitThreadLocal%28java.lang.Thread[],com.oracle.truffle.api.ThreadLocalAction%29)
- [`com.oracle.truffle.api.instrumentation.TruffleInstrument.Env.submitThreadLocal`](com/oracle/truffle/api/instrumentation/TruffleInstrument.Env.md#submitThreadLocal%28com.oracle.truffle.api.TruffleContext,java.lang.Thread[],com.oracle.truffle.api.ThreadLocalAction%29)
## Nested types
- [`ThreadLocalAction.Access`](com/oracle/truffle/api/ThreadLocalAction.Access.md) (abstract class): Argument class for ThreadLocalAction.perform(Access).
## Constructors
### ThreadLocalAction(boolean, boolean)
`protected ThreadLocalAction(boolean hasSideEffects, boolean synchronous)`. Since 21.1. Creates a new thread local action. Parameters: `hasSideEffects` `boolean`: true if the event may have side-effects else false. `synchronous` `boolean`: true if the event should run synchronous else the event will run asynchronous. See also: `ThreadLocalAction`. Cite: `com/oracle/truffle/api/ThreadLocalAction.html#(boolean,boolean)`
### ThreadLocalAction(boolean, boolean, boolean)
`protected ThreadLocalAction(boolean hasSideEffects, boolean synchronous, boolean recurring)`. Since 21.1. Creates a new thread local action. Parameters: `hasSideEffects` `boolean`: true if the event may have side-effects else false. `synchronous` `boolean`: true if the event should run synchronous else the event will run asynchronous. `recurring` `boolean`: true if the event should be rescheduled until cancelled, else false. See also: `ThreadLocalAction`. Cite: `com/oracle/truffle/api/ThreadLocalAction.html#(boolean,boolean,boolean)`
## Methods
### perform(ThreadLocalAction.Access)
`protected abstract void perform(ThreadLocalAction.Access access)`. Since 21.1. Performs the thread local action on a given thread. Parameters: `access` `ThreadLocalAction.Access`: allows access to the current thread and the current code location. See also: `ThreadLocalAction`. Cite: `com/oracle/truffle/api/ThreadLocalAction.html#perform(com.oracle.truffle.api.ThreadLocalAction.Access)`
### notifyBlocked(ThreadLocalAction.Access)
`protected void notifyBlocked(ThreadLocalAction.Access access)`. Since 24.2. Callback for notifying the thread local action that its processing has been blocked due to `a blocked call`. Parameters: `access` `ThreadLocalAction.Access`: allows access to the current thread and the current code location. See also: `ThreadLocalAction`. Cite: `com/oracle/truffle/api/ThreadLocalAction.html#notifyBlocked(com.oracle.truffle.api.ThreadLocalAction.Access)`
### notifyUnblocked(ThreadLocalAction.Access)
`protected void notifyUnblocked(ThreadLocalAction.Access access)`. Since 24.2. Callback for notifying the thread local action that its processing has been unblocked during or while leaving `a blocked call`. Parameters: `access` `ThreadLocalAction.Access`: allows access to the current thread and the current code location. See also: `ThreadLocalAction`. Cite: `com/oracle/truffle/api/ThreadLocalAction.html#notifyUnblocked(com.oracle.truffle.api.ThreadLocalAction.Access)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ ThreadLocalAction.Access
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 21.1. Nested in [`ThreadLocalAction`](com/oracle/truffle/api/ThreadLocalAction.md).
```java
public abstract static class ThreadLocalAction.Access
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Access`
Argument class for [`ThreadLocalAction.perform(Access)`](com/oracle/truffle/api/ThreadLocalAction.md#perform%28com.oracle.truffle.api.ThreadLocalAction.Access%29).
## Constructors
### Access(Object)
`protected Access(Object secret)`. Since 23.1. Constructor for framework use only. Cite: `com/oracle/truffle/api/ThreadLocalAction.Access.html#(java.lang.Object)`
### Access(AbstractPolyglotImpl)
`protected Access(AbstractPolyglotImpl secret)`. Since 21.1. Constructor for framework use only. Cite: `com/oracle/truffle/api/ThreadLocalAction.Access.html#(org.graalvm.polyglot.impl.AbstractPolyglotImpl)`
## Methods
### getLocation()
`public abstract Node getLocation()`. Since 21.1. Returns the current node location executing on this thread. The return value is guaranteed to be non-null. Cite: `com/oracle/truffle/api/ThreadLocalAction.Access.html#getLocation()`
### getThread()
`public abstract Thread getThread()`. Since 21.1. Returns the thread where this thread local action is running on. Currently this always returns [`Thread.currentThread()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#currentThread%28%29). See the [safepoint tutorial](http://github.com/oracle/graal/blob/master/truffle/docs/Safepoints.md) for further details on our plans. Cite: `com/oracle/truffle/api/ThreadLocalAction.Access.html#getThread()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ Truffle
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public final class Truffle
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Truffle`
Class for obtaining the Truffle runtime singleton object of this virtual machine.
## Methods
### getRuntime()
`public static TruffleRuntime getRuntime()`. Since 0.8 or earlier. Gets the singleton `TruffleRuntime` object. Cite: `com/oracle/truffle/api/Truffle.html#getRuntime()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleContext
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.27.
```java
public final class TruffleContext implements AutoCloseable
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleContext`
Implements: [`AutoCloseable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AutoCloseable.html)
A handle on a context of a set of Truffle languages. This context handle is designed to be used by Truffle guest language implementations. The Truffle context can be used to create inner contexts for isolated execution of guest language code.
A [`context`](com/oracle/truffle/api/TruffleContext.md) consists of a [`language context`](com/oracle/truffle/api/TruffleLanguage.md#createContext%28com.oracle.truffle.api.TruffleLanguage.Env%29) instance for each [`installed language`](com/oracle/truffle/api/TruffleLanguage.Env.md#getInternalLanguages%28%29). The current language context is [`created`](com/oracle/truffle/api/TruffleLanguage.md#createContext%28com.oracle.truffle.api.TruffleLanguage.Env%29) eagerly and can be accessed using a [`context reference`](com/oracle/truffle/api/TruffleLanguage.ContextReference.md) after the context was [`entered`](com/oracle/truffle/api/TruffleContext.md#enter%28com.oracle.truffle.api.nodes.Node%29).
The configuration for each language context is inherited from its parent/creator context. In addition to that [`config`](com/oracle/truffle/api/TruffleContext.Builder.md#config%28java.lang.String,java.lang.Object%29) parameters can be passed to new language context instance of the current language. The configuration of other installed languages cannot be modified. To run guest language code in a context, the context needs to be first [`entered`](com/oracle/truffle/api/TruffleContext.md#enter%28com.oracle.truffle.api.nodes.Node%29) and then [`left`](com/oracle/truffle/api/TruffleContext.md#leave%28com.oracle.truffle.api.nodes.Node,java.lang.Object%29). The context should be [`closed`](com/oracle/truffle/api/TruffleContext.md#close%28%29) when it is no longer needed. If the context is not closed explicitly, then it is automatically closed together with the parent context.
Example usage:
```java
final class MyNode extends Node {
void executeInContext(Env env) {
MyContext outerLangContext = getContext(this);
TruffleContext innerContext = env.newInnerContextBuilder().
initializeCreatorContext(true).build();
Object p = innerContext.enter(this);
try {
/*
* Here the this node cannot be passed otherwise an
* invalid sharing error would occur.
*/
MyContext innerLangContext = getContext(null);
assert outerLangContext != innerLangContext;
} finally {
innerContext.leave(this, p);
}
assert outerLangContext == getContext(this);
innerContext.close();
}
}
private static ContextReference REFERENCE
= ContextReference.create(MyLanguage.class);
private static MyContext getContext(Node node) {
return REFERENCE.get(node);
}
```
## Nested types
- [`TruffleContext.Builder`](com/oracle/truffle/api/TruffleContext.Builder.md) (class): Builder class to create new TruffleContext instances.
## Methods
### equals(Object)
`public boolean equals(Object obj)`. Since 20.3. Overrides `equals(java.lang.Object)`. Cite: `com/oracle/truffle/api/TruffleContext.html#equals(java.lang.Object)`
### hashCode()
`public int hashCode()`. Since 20.3. Overrides `hashCode()`. Cite: `com/oracle/truffle/api/TruffleContext.html#hashCode()`
### getParent()
`public TruffleContext getParent()`. Since 0.30. Get a parent context of this context, if any. This provides the hierarchy of inner contexts. Returns `TruffleContext`: a parent context, or `null` if there is no parent. Cite: `com/oracle/truffle/api/TruffleContext.html#getParent()`
### enter(Node)
`public Object enter(Node node)`. Since 20.3. Enters this context and returns an object representing the previous context. Calls to enter must be followed by a call to `leave(Node, 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 [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. If the current thread was not previously entered in any context, the enter function returns `null`. If the return value is not `null`, the result of the enter function is unspecified and must only be passed to `leave(Node, Object)`. The result value must not be stored permanently. An adopted node may be passed to allow perform optimizations on the fast-path. If a `null` node is passed then entering a context will result in a `boundary` call in compiled code. If the provided node is not adopted an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) is thrown. Entering a language context is designed for compilation and is most efficient if the `context` instance is compilation final. Example usage: `TruffleContextSnippets.MyNode.executeInContext`. See also: `leave(Node, Object)`. Cite: `com/oracle/truffle/api/TruffleContext.html#enter(com.oracle.truffle.api.nodes.Node)`
### initializeInternal(Node, String)
`public boolean initializeInternal(Node node, String languageId)`. Since 22.3. Forces initialization of an internal or public language. If the context is not an inner context and e.g. accessed using `Env.getContext()` an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. In such a case `Env.initializeLanguage(LanguageInfo)` should be used instead to initialize contexts. No context or the parent creator context must be entered to initialize languages in a `TruffleContext` otherwise an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) will be thrown. Parameters: `node` `Node`: a partial evaluation constant node context used to optimize this operation. Can be `null` if not available. `languageId` `String`: the id of the language to initialize. Returns `boolean`: `true` if the language was initialized, else `false`, e.g. if the language as already initialized. Throws: `IllegalStateException` (unchecked): if an invalid context is entered or the context is already closed. `IllegalArgumentException` (unchecked): if the given language of the source cannot be accessed. Cite: `com/oracle/truffle/api/TruffleContext.html#initializeInternal(com.oracle.truffle.api.nodes.Node,java.lang.String)`
### initializePublic(Node, String)
`public boolean initializePublic(Node node, String languageId)`. Since 22.3. The same as `initializeInternal(Node, String)`, but only public languages are accessible. Parameters: `node` `Node`: a partial evaluation constant node context used to optimize this operation. Can be `null` if not available. `languageId` `String`: the id of the language to initialize. Returns `boolean`: `true` if the language was initialized, else `false`, e.g. if the language as already initialized. Throws: `IllegalStateException` (unchecked): if an invalid context is entered or the context is already closed. `IllegalArgumentException` (unchecked): if the given language of the source cannot be accessed. Cite: `com/oracle/truffle/api/TruffleContext.html#initializePublic(com.oracle.truffle.api.nodes.Node,java.lang.String)`
### evalInternal(Node, Source)
`public Object evalInternal(Node node, Source source)`. Since 21.3. Evaluates a source in an inner context and returns the result. If the context is not an inner context and e.g. accessed using `Env.getContext()` an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. In such a case `Env.parseInternal(Source, String...)` should be used instead to evaluate sources. No context or the parent creator context must be entered to evaluate sources in a `TruffleContext` otherwise an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) will be thrown. In order to ensure that all values are accessed from their respective contexts only, any non-primitive value returned by the evaluation will be wrapped and enter this context for each interop message sent. Parameters to interop messages will enter and leave the parent context when they are accessed. If the result is a primitive value, then the value is directly returned. This method has access to all public and internal languages the creator context has access to. This corresponds to the set of languages returned by `Env.getInternalLanguages()`. If a language cannot be accessed then an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) is thrown. If a language is not yet initialized in the inner context, it will get automatically initialized. This method is designed to be used in compiled code paths. This method may be used from multiple threads at the same time. The result of this method must not be cached, instead the `Source` object should be cached. Parameters: `node` `Node`: a partial evaluation constant node context used to optimize this operation. Can be `null` if not available. `source` `Source`: the source to evaluate. Throws: `IllegalArgumentException` (unchecked): if the given language of the source cannot be accessed. `IllegalStateException` (unchecked): if an invalid context is entered or the context is already closed. Cite: `com/oracle/truffle/api/TruffleContext.html#evalInternal(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.source.Source)`
### evalPublic(Node, Source)
`public Object evalPublic(Node node, Source source)`. Since 21.3. The same as `evalInternal(Node, Source)`, but only public languages are accessible. Parameters: `node` `Node`: a partial evaluation constant node context used to optimize this operation. Can be `null` if not available. `source` `Source`: the source to evaluate. Throws: `IllegalArgumentException` (unchecked): if the given language of the source cannot be accessed. `IllegalStateException` (unchecked): if an invalid context is entered or the context is already closed. Cite: `com/oracle/truffle/api/TruffleContext.html#evalPublic(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.source.Source)`
### isEntered()
`public boolean isEntered()`. Since 20.0. Checks whether the context is entered on the current thread and the context is the currently active context on this thread. There can be multiple contexts `active` on a single thread, but this method only returns `true` if it is the top-most context. This method is thread-safe and may be used from multiple threads. Returns `boolean`: `true` if the context is active, `false` otherwise. Cite: `com/oracle/truffle/api/TruffleContext.html#isEntered()`
### isActive()
`public boolean isActive()`. Since 20.3. Returns `true` if the context is currently active on the current thread, else `false`. Checks whether the context has been previously entered by this thread with `enter(Node)` and hasn't been left yet with `leave(Node, java.lang.Object)` methods. Multiple contexts can be active on a single thread. See `isEntered()` for checking whether it is the top-most entered context. This method is thread-safe and may be used from multiple threads. Cite: `com/oracle/truffle/api/TruffleContext.html#isActive()`
### isClosed()
`public boolean isClosed()`. Since 20.3. Returns `true` if the context was closed else `false`. A context may be closed if `close()`, `closeCancelled(Node, String)`, or `closeExited(Node, int)` was called previously. Cite: `com/oracle/truffle/api/TruffleContext.html#isClosed()`
### isCancelling()
`public boolean isCancelling()`. Since 21.1. Returns `true` if the context is being cancelled else `false`. A context may be in the process of cancelling if `closeCancelled(Node, String)` was called previously. Cite: `com/oracle/truffle/api/TruffleContext.html#isCancelling()`
### isExiting()
`public boolean isExiting()`. Since 22.0. Returns `true` if the context is being hard-exited else `false`. A context may be in the process of exit if `closeExited(Node, int)` was called previously. Cite: `com/oracle/truffle/api/TruffleContext.html#isExiting()`
### pause()
`public Future pause()`. Since 21.2. Pause execution on all threads for this context. This call does not wait for the threads to be actually paused. Instead, a future is returned that can be used to wait for the execution to be paused. The future is completed when all active threads are paused. New threads entered after this point are paused immediately after entering until `TruffleContext.resume(Future)` is called. Returns `Future`: a future that can be used to wait for the execution to be paused. Also, the future is used to resume execution by passing it to the `TruffleContext.resume(Future)` method. Cite: `com/oracle/truffle/api/TruffleContext.html#pause()`
### resume(Future)
`public void resume(Future pauseFuture)`. Since 21.2. Resume previously paused execution on all threads for this context. The execution will not resume if `TruffleContext.pause()` was called multiple times and for some of the other calls resume was not called yet. Parameters: `pauseFuture` `Future`: pause future returned by a previous call to `TruffleContext.pause()`. Throws: `IllegalArgumentException` (unchecked): in case the passed pause future was not obtained by a previous call to `TruffleContext.pause()` on this context. Cite: `com/oracle/truffle/api/TruffleContext.html#resume(java.util.concurrent.Future)`
### leave(Node, Object)
`public void leave(Node node, Object prev)`. Since 20.3. Leaves this context and sets the previous context as the new current context. An adopted node may be passed to allow perform optimizations on the fast-path. If a `null` node is passed then entering a context will result in a `boundary` call in compiled code. If the node is not adopted an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) is thrown. Leaving a language context is designed for compilation and is most efficient if the `context` instance is compilation final. Parameters: `prev` `Object`: the previous context returned by `enter(Node)`. See also: `enter(Node)`. Cite: `com/oracle/truffle/api/TruffleContext.html#leave(com.oracle.truffle.api.nodes.Node,java.lang.Object)`
### leaveAndEnter(Node, Supplier)
`@Deprecated public T leaveAndEnter(Node node, Supplier runWhileOutsideContext)`. Since 21.1. Deprecated. Use `leaveAndEnter(Node, Interrupter, InterruptibleFunction, Object)` instead. Leaves this context, runs the passed supplier and reenters the context. This is useful when the current thread must wait for another thread (and does not need to access the context to do so) and triggering multithreading is not desired, for instance when implementing coroutines with threads. The supplier cannot access the context and must not run any guest language code or invoke interoperability messages. The supplier will typically notify another thread that it can now enter the context without triggering multithreading and then wait for some thread to leave the context before exiting the supplier and reentering the context (again to avoid triggering multithreading). An adopted node may be passed to allow perform optimizations on the fast-path. If a `null` node is passed then entering a context will result in a `boundary` call in compiled code. If the provided node is not adopted an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) is thrown. Entering a language context is designed for compilation and is most efficient if the `context` instance is compilation final. Parameters: `node` `Node`: an adopted node or `null`. `runWhileOutsideContext` `Supplier`: the supplier to run while having left this context. Cite: `com/oracle/truffle/api/TruffleContext.html#leaveAndEnter(com.oracle.truffle.api.nodes.Node,java.util.function.Supplier)`
### leaveAndEnter(Node, TruffleSafepoint.Interrupter, …)
`public R leaveAndEnter(Node node, TruffleSafepoint.Interrupter interrupter, TruffleSafepoint.InterruptibleFunction interruptible, T object)`. Since 23.1. Leaves this context, runs the passed interruptible function and reenters the context. This is useful when the current thread must wait for another thread (and does not need to access the context to do so) and triggering multithreading is not desired, for instance when implementing coroutines with threads. The function cannot access the context and must not run any guest language code or invoke interoperability messages. The function will typically notify another thread that it can now enter the context without triggering multithreading and then wait for some thread to leave the context before exiting the function and reentering the context (again to avoid triggering multithreading). An adopted node may be passed to allow performing optimizations on the fast-path. Parameters: `node` `Node`: an adopted node or `null`. `interrupter` `TruffleSafepoint.Interrupter`: an interrupter used to interrupt the interruptible function when, e.g., the context is cancelled. The interrupter is also used to `reset` the interrupted state when the context is reentered. `interruptible` `TruffleSafepoint.InterruptibleFunction`: the interruptible function to run while having left this context. This function is run at most once. Returns `R`: return value of the interruptible, or `null` if the interruptibe throws an [`InterruptedException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/InterruptedException.html) without the context being cancelled or exited. Cite: `com/oracle/truffle/api/TruffleContext.html#leaveAndEnter(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.TruffleSafepoint.Interrupter,com.oracle.truffle.api.TruffleSafepoint.InterruptibleFunction,T)`
### close()
`public void close()`. Since 0.27. Closes this context and disposes its resources. Closes this context and disposes its resources. A context cannot be closed if it is currently `entered` or active by any thread. If a closed context is attempted to be accessed or entered, then an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. If the context is not closed explicitly, then it is automatically closed together with the parent context. If an attempt to close a context was successful then consecutive calls to close have no effect. Throws: `UnsupportedOperationException` (unchecked): if the close operation is not supported on this context. `IllegalStateException` (unchecked): if the context is `active`. Overrides `close()`. See also: `closeCancelled(Node, String)`, `closeResourceExhausted(Node, String)`. Cite: `com/oracle/truffle/api/TruffleContext.html#close()`
### closeCancelled(Node, String)
`public void closeCancelled(Node closeLocation, String message)`. Since 20.3. Force closes the context as cancelled and stops all the execution on all active threads using a special [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel exception. If this context is not currently `entered` on the current thread then this method waits until the close operation is complete and `isClosed()` returns `true`, else it throws the cancelled exception upon its completion of this method. If an attempt to close a context was successful then consecutive calls to close have no effect. The throwing of the special [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel exception also applies to any guest code run during `TruffleLanguage.finalizeContext(Object)` which means that `TruffleLanguage.finalizeContext(Object)` cannot run guest code during the cancel operation. If forced and this context currently `entered` on the current thread and no other context is entered on the current thread then this method directly throws a [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) error instead of completing to indicate that the current thread should be stopped. The thrown [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) must not be caught by the guest language and freely propagated to the guest application to cancel the execution on the current thread. Please note that this means that the guest language's finally blocks must not be executed. If a context is `active` on the current thread, but not `entered`, then an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown, as parent contexts that are active on the current thread cannot be cancelled. Parameters: `closeLocation` `Node`: the node where the close occurred. If the context is currently entered on the thread, then this node will be used as location, for the exception thrown. If the context is not entered, then the closeLocation parameter will be ignored. `message` `String`: exception text for humans provided to the embedder and tools that observe the cancellation. Throws: `UnsupportedOperationException` (unchecked): if the close operation is not supported on this context. `IllegalStateException` (unchecked): if the context is `active` but not `entered` on the current thread. See also: `close()`, `closeResourceExhausted(Node, String)`. Cite: `com/oracle/truffle/api/TruffleContext.html#closeCancelled(com.oracle.truffle.api.nodes.Node,java.lang.String)`
### closeExited(Node, int)
`public void closeExited(Node exitLocation, int exitCode)`. Since 22.0. Initiates force close of the context as exited - `hard exit`. Requires the context to be entered on the current thread. Languages are first notified by calling `TruffleLanguage.exitContext(Object, TruffleLanguage.ExitMode, int)` and then the closing of the context is initiated. Execution on all active threads including the current thread is stopped by throwing a special [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exit exception. This method does not wait for the execution on other threads to be stopped, it throws the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exception as soon as possible. To exit threads reliably, guest languages need to ensure that the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) is always immediately rethrown and guest language exception handlers and finally blocks are not run. The throwing of the special [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exit exception also applies to any guest code run during `TruffleLanguage.finalizeContext(Object)` which means that `TruffleLanguage.finalizeContext(Object)` cannot run guest code during hard exit. The exit code can be specified only once and the first call to this method also executes the `exit notifications` on the same thread. Further calls to this method will ensure that the following guest code on the calling thread is not executed by throwing the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exit exception, and the exit location is used as the stopping point of the thread, but the passed exit code is ignored and exit notifications are not run. In case the context is in one of the following states the context is being closed and the finalization stage has already begun (`TruffleLanguage.finalizeContext(Object)` is being executed for all language contexts).; the context is already closed; the context threads are being unwound as a part of the cancelling process; the context threads are being unwound as a part of the hard exit process that comes after exit notifications then calling this method has no effect. Parameters: `exitLocation` `Node`: the node where the exit occurred. `exitCode` `int`: exitCode provided to the embedder and tools that observe the exit. Throws: `IllegalStateException` (unchecked): if the context is not `entered` on the current thread. See also: [Context Exit](https://github.com/oracle/graal/blob/master/truffle/docs/Exit.md). Cite: `com/oracle/truffle/api/TruffleContext.html#closeExited(com.oracle.truffle.api.nodes.Node,int)`
### closeResourceExhausted(Node, String)
`public void closeResourceExhausted(Node location, String message)`. Since 20.3. Force closes the context due to resource exhaustion. This method is equivalent to calling `closeCancelled(location, message)` except in addition the thrown [`PolyglotException`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/PolyglotException.html) returns `true` for [`PolyglotException.isResourceExhausted()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/PolyglotException.html#isResourceExhausted%28%29). See also: [`PolyglotException.isResourceExhausted()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/PolyglotException.html#isResourceExhausted%28%29), `close()`, `closeCancelled(Node, String)`. Cite: `com/oracle/truffle/api/TruffleContext.html#closeResourceExhausted(com.oracle.truffle.api.nodes.Node,java.lang.String)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleContext.Builder
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.27. Nested in [`TruffleContext`](com/oracle/truffle/api/TruffleContext.md).
```java
public final class TruffleContext.Builder
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Builder`
Builder class to create new [`TruffleContext`](com/oracle/truffle/api/TruffleContext.md) instances.
## Methods
### config(String, Object)
`public TruffleContext.Builder config(String key, Object value)`. Since 0.27. Sets a config parameter that the child context of this language can access using `Env.getConfig()`. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#config(java.lang.String,java.lang.Object)`
### initializeCreatorContext(boolean)
`public TruffleContext.Builder initializeCreatorContext(boolean enabled)`. Since 21.3. Specifies whether the creating language context should be initialized in the new context. By default the creating language won't get initialized. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#initializeCreatorContext(boolean)`
### out(OutputStream)
`public TruffleContext.Builder out(OutputStream out)`. Since 22.3. Sets the standard output stream to be used for the context. If not set or set to `null`, then the standard output stream is inherited from the outer context. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#out(java.io.OutputStream)`
### err(OutputStream)
`public TruffleContext.Builder err(OutputStream err)`. Since 22.3. Sets the error output stream to be used for the context. If not set or set to `null`, then the standard error stream is inherited from the outer context. is used. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#err(java.io.OutputStream)`
### in(InputStream)
`public TruffleContext.Builder in(InputStream in)`. Since 22.3. Sets the input stream to be used for the context. If not set or set to `null`, then the standard input stream is inherited from the outer context. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#in(java.io.InputStream)`
### forceSharing(Boolean)
`public TruffleContext.Builder forceSharing(Boolean enabled)`. Since 22.3. Force enables or disables code sharing for this inner context. By default this option is set to `null` which instructs this context to inherit sharing configuration from the outer context. If sharing is explicitly set to `true` then code may be shared with all contexts compatible with the configuration of this inner context. Code may also be shared with the outer context if the outer context supports code sharing and its sharing layer is compatible. This may be useful to force sharing for multiple created inner contexts if the outer context configuration disabled sharing. If sharing is explicitly set to `false` then no code will be shared even if the outer context has code sharing enabled and supported by the language. This may be useful to avoid runtime profile pollution through code run in an inner context. If multiple languages are potentially used it is recommended but not required to use `permitted languages` to specify all used languages ahead of time. This allows to validate sharing layer compatibility eagerly and avoids late failures when a language is initialized lazily and is not compatible with the sharing layer. Use `--engine.TraceSharing` for details on whether the sharing configuration is compatible. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#forceSharing(java.lang.Boolean)`
### option(String, String)
`public TruffleContext.Builder option(String key, String value)`. Since 22.3. Overrides an option of the inner context. Only language options may be changed. Engine or instrument options cannot be modified after their initial configuration in the outer context. All options for inner contexts are inherited from the outer context, but options set for the inner context have precedence over options set in the outer context. This method is currently only supported if the outer context is configured with [`org.graalvm.polyglot.Context.Builder.allowInnerContextOptions(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowInnerContextOptions%28boolean%29). If all privileges are denied then an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) will be thrown when building the inner context. To find out whether the inner context option privilege has been granted languages may use `TruffleLanguage.Env.isInnerContextOptionsAllowed()`. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#option(java.lang.String,java.lang.String)`
### inheritAllAccess(boolean)
`public TruffleContext.Builder inheritAllAccess(boolean b)`. Since 22.3. If set to `true` allows all access privileges that were also granted to the outer context. If set to `false` then all privileges are denied in the created context independent of the outer context. By default all privileges are denied and not inherited. This privilege enables inheritance for the following privileges: `allowCreateThread(boolean)`; `allowNativeAccess(boolean)`; `allowIO(boolean)`; `allowHostClassLookup(boolean)`; `allowHostClassLoading(boolean)`; `allowCreateProcess(boolean)`; `allowPolyglotAccess(boolean)`; `allowInheritEnvironmentAccess(boolean)`; `allowInnerContextOptions(boolean)` If an individual privilege was set explicitly then the value of `inheritAllAccess(boolean)` is ignored for that privilege. For example it is possible to set `inheritAllAccess(boolean)` to `true` but set `allowNativeAccess(boolean)` to `false` to allow inheritance of all but native access rights from the outer to the inner context. In case new privileges are added in the future, then this method will allow or disallow inheritance for the new privileges as well. For security sensitive use-cases it is recommended to keep the default value of `inheritAllAccess(boolean)` and individually specify allowed privileges for this context. For non security sensitive use-cases it is recommended to set this flag to `true`. Following this recommendation is important in case new privileges are added to the platform. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#inheritAllAccess(boolean)`
### allowCreateThread(boolean)
`public TruffleContext.Builder allowCreateThread(boolean b)`. Since 22.3. Allows or denies creating threads for this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowCreateThread(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowCreateThread%28boolean%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowCreateThread(boolean)`
### allowNativeAccess(boolean)
`public TruffleContext.Builder allowNativeAccess(boolean b)`. Since 22.3. Allows or denies using native access in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowNativeAccess(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowNativeAccess%28boolean%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowNativeAccess(boolean)`
### allowIO(boolean)
`public TruffleContext.Builder allowIO(boolean b)`. Since 22.3. Allows or denies using IO in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowIO(org.graalvm.polyglot.io.IOAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowIO%28org.graalvm.polyglot.io.IOAccess%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowIO(boolean)`
### allowHostClassLoading(boolean)
`public TruffleContext.Builder allowHostClassLoading(boolean b)`. Since 22.3. Allows or denies loading new host classes in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowHostAccess(org.graalvm.polyglot.HostAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowHostAccess%28org.graalvm.polyglot.HostAccess%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowHostClassLoading(boolean)`
### allowHostClassLookup(boolean)
`public TruffleContext.Builder allowHostClassLookup(boolean b)`. Since 22.3. Allows or denies loading new host classes in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowHostAccess(org.graalvm.polyglot.HostAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowHostAccess%28org.graalvm.polyglot.HostAccess%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowHostClassLookup(boolean)`
### allowCreateProcess(boolean)
`public TruffleContext.Builder allowCreateProcess(boolean b)`. Since 22.3. Allows or denies creating processes in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowCreateProcess(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowCreateProcess%28boolean%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowCreateProcess(boolean)`
### allowInnerContextOptions(boolean)
`public TruffleContext.Builder allowInnerContextOptions(boolean b)`. Since 22.3. Allows or denies options for inner contexts created by this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowCreateProcess(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowCreateProcess%28boolean%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowInnerContextOptions(boolean)`
### allowPolyglotAccess(boolean)
`public TruffleContext.Builder allowPolyglotAccess(boolean b)`. Since 22.3. Allows or denies access to polyglot languages in this context. Set to `true` to inherit access privilege from the outer context or `false` to deny access for this context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowPolyglotAccess(org.graalvm.polyglot.PolyglotAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowPolyglotAccess%28org.graalvm.polyglot.PolyglotAccess%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowPolyglotAccess(boolean)`
### threadAccessDeniedHandler(Consumer)
`public TruffleContext.Builder threadAccessDeniedHandler(Consumer handler)`. Since 24.2. Installs handler to control what happens on multiple thread access. When multiple threads are accessing a context which isn't ready for multithreaded access an exception is yielded by default. By installing this `handler` one can control what shall happen. Either to throw exception (with the provided reason) or to resolve the multithreaded situation somehow and return to retry the thread access again. Parameters: `handler` `Consumer`: callback (that gets a reason as an input) that either throws an exception or returns to signal a **request for retry**. Returns `TruffleContext.Builder`: this builder. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#threadAccessDeniedHandler(java.util.function.Consumer)`
### allowInheritEnvironmentAccess(boolean)
`public TruffleContext.Builder allowInheritEnvironmentAccess(boolean b)`. Since 22.3. Allows or denies access to the parent context's environment in this context. Set to `true` to inherit variables from the outer context or `false` to deny inheritance for this context. Environment variables can be set for the inner context with `environment(String, String)` even if inheritance is disabled. If inheritance is enabled, environment variables specified for the inner context override environment variables of the outer context. See also: `inheritAllAccess(boolean)`, [`org.graalvm.polyglot.Context.Builder.allowEnvironmentAccess(org.graalvm.polyglot.EnvironmentAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowEnvironmentAccess%28org.graalvm.polyglot.EnvironmentAccess%29). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#allowInheritEnvironmentAccess(boolean)`
### environment(String, String)
`public TruffleContext.Builder environment(String name, String value)`. Since 22.3. Sets an environment variable. Parameters: `name` `String`: the environment variable name. `value` `String`: the environment variable value. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#environment(java.lang.String,java.lang.String)`
### environment(Map)
`public TruffleContext.Builder environment(Map env)`. Since 22.3. Shortcut for setting multiple `environment variables` using a map. All values of the provided map must be non-null. Parameters: `env` `Map`: environment variables. See also: `To set a single environment variable.`. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#environment(java.util.Map)`
### timeZone(ZoneId)
`public TruffleContext.Builder timeZone(ZoneId zone)`. Since 22.3. Sets the default time zone to be used for this context. If not set, or explicitly set to `null` then the time zone of the outer context will be used. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#timeZone(java.time.ZoneId)`
### arguments(String, String[])
`public TruffleContext.Builder arguments(String language, String[] args)`. Since 22.3. Sets the guest language application arguments for a language context. Application arguments are typically made available to guest language implementations. Passing no arguments to a language is equivalent to providing an empty arguments array. Parameters: `language` `String`: the language id of the primary language. `args` `String[]`: an array of arguments passed to the guest language program. Throws: `IllegalArgumentException` (unchecked): if an invalid language id was specified. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#arguments(java.lang.String,java.lang.String[])`
### options(Map)
`public TruffleContext.Builder options(Map options)`. Since 22.3. Sets multiple options using a map. See `option(String, String)` for details. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#options(java.util.Map)`
### onCancelled(Runnable)
`public TruffleContext.Builder onCancelled(Runnable r)`. Since 22.1. Specifies a [`Runnable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runnable.html) that will be executed when the new context is `cancelled` and the cancel exception is about to reach the outer context, or when some operation on the new context is attempted while the context is already cancelled. However, the runnable will only be executed if the outer context is not cancelled. The purpose of the runnable is to allow throwing a custom guest exception before the cancel exception reaches the outer context, so that the outer context can properly handle the exception. In case the runnable does not throw any exception, an internal error is thrown (should not be caught). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#onCancelled(java.lang.Runnable)`
### onExited(Consumer)
`public TruffleContext.Builder onExited(Consumer r)`. Since 22.1. Specifies a [`Consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html) that will be executed when the new context is `hard-exited` and the exit exception is about to reach the outer context, or when some operation on the new context is attempted while the context is already hard-exited. However, the consumer will only be executed if the outer context is not hard-exited. The purpose of the consumer is to allow throwing a custom guest exception before the exit exception reaches the outer context, so that the outer context can properly handle the exception. In case the consumer does not throw any exception, an internal error is thrown (should not be caught). The single input argument to the [`Consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html) is the exit code. See also: [Context Exit](https://github.com/oracle/graal/blob/master/truffle/docs/Exit.md). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#onExited(java.util.function.Consumer)`
### onClosed(Runnable)
`public TruffleContext.Builder onClosed(Runnable r)`. Since 22.1. Specifies a [`Runnable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runnable.html) that will be executed when some operation on the new context attempted while the context is already `closed`. However, the runnable will only be executed if the outer context is not closed. The purpose of the runnable is to allow throwing a custom guest exception before the close exception reaches the outer context, so that the outer context can properly handle the exception. In case the runnable does not throw any exception, an internal error is thrown (should not be caught). Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#onClosed(java.lang.Runnable)`
### build()
`public TruffleContext build()`. Since 0.27. Builds the new context instance. Cite: `com/oracle/truffle/api/TruffleContext.Builder.html#build()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleFile
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0.
```java
public final class TruffleFile extends TruffleFileLegacy
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleFileLegacy` > `TruffleFile`
An abstract representation of a file used by Truffle languages.
## Nested types
- [`TruffleFile.AttributeDescriptor`](com/oracle/truffle/api/TruffleFile.AttributeDescriptor.md) (class): Represents a file's attribute.
- [`TruffleFile.Attributes`](com/oracle/truffle/api/TruffleFile.Attributes.md) (class): A view over file's attributes values obtained by getAttributes.
- [`TruffleFile.FileStoreInfo`](com/oracle/truffle/api/TruffleFile.FileStoreInfo.md) (class): Provides information about the file store.
- [`TruffleFile.FileTypeDetector`](com/oracle/truffle/api/TruffleFile.FileTypeDetector.md) (interface): A detector for finding file's MIME type and encoding.
## Fields
### LAST_MODIFIED_TIME
`public static final TruffleFile.AttributeDescriptor LAST_MODIFIED_TIME`. Since 19.0. The file's last modified time. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#LAST_MODIFIED_TIME`
### LAST_ACCESS_TIME
`public static final TruffleFile.AttributeDescriptor LAST_ACCESS_TIME`. Since 19.0. The file's last access time. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#LAST_ACCESS_TIME`
### CREATION_TIME
`public static final TruffleFile.AttributeDescriptor CREATION_TIME`. Since 19.0. The file's creation time. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#CREATION_TIME`
### IS_REGULAR_FILE
`public static final TruffleFile.AttributeDescriptor IS_REGULAR_FILE`. Since 19.0. Represents the file a regular file. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#IS_REGULAR_FILE`
### IS_DIRECTORY
`public static final TruffleFile.AttributeDescriptor IS_DIRECTORY`. Since 19.0. Represents the file a directory. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#IS_DIRECTORY`
### IS_SYMBOLIC_LINK
`public static final TruffleFile.AttributeDescriptor IS_SYMBOLIC_LINK`. Since 19.0. Represents the file a symbolic link. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#IS_SYMBOLIC_LINK`
### IS_OTHER
`public static final TruffleFile.AttributeDescriptor IS_OTHER`. Since 19.0. Represents the file a special file (device, named pipe). Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#IS_OTHER`
### SIZE
`public static final TruffleFile.AttributeDescriptor SIZE`. Since 19.0. The file's size in bytes. Supported by all filesystems. Cite: `com/oracle/truffle/api/TruffleFile.html#SIZE`
### UNIX_OWNER
`public static final TruffleFile.AttributeDescriptor UNIX_OWNER`. Since 19.0. The owner of the file. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_OWNER`
### UNIX_GROUP
`public static final TruffleFile.AttributeDescriptor UNIX_GROUP`. Since 19.0. The group owner of the file. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_GROUP`
### UNIX_PERMISSIONS
`public static final TruffleFile.AttributeDescriptor> UNIX_PERMISSIONS`. Since 19.0. The file's Posix permissions. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_PERMISSIONS`
### UNIX_MODE
`public static final TruffleFile.AttributeDescriptor UNIX_MODE`. Since 19.0. The file's mode containing the protection and file type bits. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_MODE`
### UNIX_INODE
`public static final TruffleFile.AttributeDescriptor UNIX_INODE`. Since 19.0. The file's inode number. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_INODE`
### UNIX_DEV
`public static final TruffleFile.AttributeDescriptor UNIX_DEV`. Since 19.0. The id of a device containing the file. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_DEV`
### UNIX_RDEV
`public static final TruffleFile.AttributeDescriptor UNIX_RDEV`. Since 19.0. The id of a device represented by the file. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_RDEV`
### UNIX_NLINK
`public static final TruffleFile.AttributeDescriptor UNIX_NLINK`. Since 19.0. The number of hard links. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_NLINK`
### UNIX_UID
`public static final TruffleFile.AttributeDescriptor UNIX_UID`. Since 19.0. The user id of file owner. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_UID`
### UNIX_GID
`public static final TruffleFile.AttributeDescriptor UNIX_GID`. Since 19.0. The group id of file owner. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_GID`
### UNIX_CTIME
`public static final TruffleFile.AttributeDescriptor UNIX_CTIME`. Since 19.0. The file's last status change time. Supported only by UNIX native filesystem. Cite: `com/oracle/truffle/api/TruffleFile.html#UNIX_CTIME`
## Methods
### exists(LinkOption...)
`public boolean exists(LinkOption... options)`. Since 19.0. Tests existence of a file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `boolean`: `true` if the file exists. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#exists(java.nio.file.LinkOption...)`
### isReadable()
`public boolean isReadable()`. Since 19.0. Tests if a file is readable. Checks if the file exists and this Java virtual machine has enough privileges to read the file. Returns `boolean`: `true` if the file exists and is readable. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isReadable()`
### isWritable()
`public boolean isWritable()`. Since 19.0. Tests if a file is writable. Checks if the file exists and this Java virtual machine has enough privileges to write to the file. Returns `boolean`: `true` if the file exists and is writable. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isWritable()`
### isExecutable()
`public boolean isExecutable()`. Since 19.0. Tests if a file is executable. Checks if the file exists and this Java virtual machine has enough privileges to execute the file. Returns `boolean`: `true` if the file exists and is executable. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isExecutable()`
### isDirectory(LinkOption...)
`public boolean isDirectory(LinkOption... options)`. Since 19.0. Tests if a file is a directory. Checks if the file exists and is a directory. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled, by default the symbolic links are followed. Returns `boolean`: `true` if the file exists and is a directory. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isDirectory(java.nio.file.LinkOption...)`
### isRegularFile(LinkOption...)
`public boolean isRegularFile(LinkOption... options)`. Since 19.0. Tests if a file is a regular file. Checks if the file exists and is a regular file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled, by default the symbolic links are followed. Returns `boolean`: `true` if the file exists and is a regular file. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isRegularFile(java.nio.file.LinkOption...)`
### isSymbolicLink()
`public boolean isSymbolicLink()`. Since 19.0. Tests if a file is a symbolic link. Checks if the file exists and is a symbolic link. Returns `boolean`: `true` if the file exists and is a symbolic link. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isSymbolicLink()`
### isAbsolute()
`public boolean isAbsolute()`. Since 19.0. Tests if this `TruffleFile`'s path is absolute. Returns `boolean`: `true` if the file path is absolute. Cite: `com/oracle/truffle/api/TruffleFile.html#isAbsolute()`
### getName()
`public String getName()`. Since 19.0. Returns the name of this `TruffleFile`. Returns `String`: the name of file or directory denoted by this `TruffleFile`, or `null` if the file is a root directory. Cite: `com/oracle/truffle/api/TruffleFile.html#getName()`
### getPath()
`public String getPath()`. Since 19.0. Returns the string representation of this `TruffleFile`. Returns `String`: the path of this `TruffleFile`. Cite: `com/oracle/truffle/api/TruffleFile.html#getPath()`
### toUri()
`public URI toUri()`. Since 19.0. Returns the absolute [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) representation of this `TruffleFile`. Returns `URI`: the absolute [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) representing the `TruffleFile`. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied a resolution of an absolute path. Cite: `com/oracle/truffle/api/TruffleFile.html#toUri()`
### toRelativeUri()
`public URI toRelativeUri()`. Since 19.0. Returns a relative [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) representation of non absolute `TruffleFile`. If this `TruffleFile` is relative it returns a relative [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). For an `absolute` `TruffleFile` it returns an absolute [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). Returns `URI`: the [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) representing the `TruffleFile`. Cite: `com/oracle/truffle/api/TruffleFile.html#toRelativeUri()`
### getAbsoluteFile()
`public TruffleFile getAbsoluteFile()`. Since 19.0. Resolves this `TruffleFile` to absolute `TruffleFile`. If this `TruffleFile` is already absolute this method returns this `TruffleFile` without any resolution. Returns `TruffleFile`: the absolute `TruffleFile`. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied a resolution of an absolute path. Cite: `com/oracle/truffle/api/TruffleFile.html#getAbsoluteFile()`
### getCanonicalFile(LinkOption...)
`public TruffleFile getCanonicalFile(LinkOption... options) throws IOException`. Since 19.0. Returns a `TruffleFile` representing the real (canonical) path of an existing file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `TruffleFile`: a `TruffleFile` representing the absolute canonical path. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getCanonicalFile(java.nio.file.LinkOption...)`
### getParent()
`public TruffleFile getParent()`. Since 19.0. Returns a parent `TruffleFile` or null when the file does not have a parent. Returns `TruffleFile`: the parent `TruffleFile`. Cite: `com/oracle/truffle/api/TruffleFile.html#getParent()`
### resolve(String)
`public TruffleFile resolve(String name)`. Since 19.0. Resolves given string path representation against this `TruffleFile`. Parameters: `name` `String`: the path to resolve. Returns `TruffleFile`: the resolved `TruffleFile`. Throws: `InvalidPathException` (unchecked): if the path string contains non valid characters. Cite: `com/oracle/truffle/api/TruffleFile.html#resolve(java.lang.String)`
### resolveSibling(String)
`public TruffleFile resolveSibling(String name)`. Since 19.0. Resolves given string path representation against the parent of this `TruffleFile`. Parameters: `name` `String`: the path to resolve. Returns `TruffleFile`: the resolved `TruffleFile`. Throws: `InvalidPathException` (unchecked): if the path string contains non valid characters. Cite: `com/oracle/truffle/api/TruffleFile.html#resolveSibling(java.lang.String)`
### size(LinkOption...)
`public long size(LinkOption... options) throws IOException`. Since 19.0. Returns the size of a file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `long`: the file size in bytes. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#size(java.nio.file.LinkOption...)`
### getLastModifiedTime(LinkOption...)
`public FileTime getLastModifiedTime(LinkOption... options) throws IOException`. Since 19.0. Returns the last modified time. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `FileTime`: the [`FileTime`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/attribute/FileTime.html) representing the time this `TruffleFile` was last modified. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getLastModifiedTime(java.nio.file.LinkOption...)`
### setLastModifiedTime(FileTime, LinkOption...)
`public void setLastModifiedTime(FileTime time, LinkOption... options) throws IOException`. Since 19.0. Sets the file's last modified time. Parameters: `time` `FileTime`: the new value of the last modified time. `options` `LinkOption...`: the options determining how the symbolic links should be handled. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#setLastModifiedTime(java.nio.file.attribute.FileTime,java.nio.file.LinkOption...)`
### getLastAccessTime(LinkOption...)
`public FileTime getLastAccessTime(LinkOption... options) throws IOException`. Since 19.0. Returns the last access time. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `FileTime`: the [`FileTime`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/attribute/FileTime.html) representing the time this `TruffleFile` was last accessed. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getLastAccessTime(java.nio.file.LinkOption...)`
### setLastAccessTime(FileTime, LinkOption...)
`public void setLastAccessTime(FileTime time, LinkOption... options) throws IOException`. Since 19.0. Sets the file's last access time. Parameters: `time` `FileTime`: the new value of the last access time. `options` `LinkOption...`: the options determining how the symbolic links should be handled. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#setLastAccessTime(java.nio.file.attribute.FileTime,java.nio.file.LinkOption...)`
### getCreationTime(LinkOption...)
`public FileTime getCreationTime(LinkOption... options) throws IOException`. Since 19.0. Returns the creation time. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `FileTime`: the [`FileTime`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/attribute/FileTime.html) representing the time this `TruffleFile` was created. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getCreationTime(java.nio.file.LinkOption...)`
### setCreationTime(FileTime, LinkOption...)
`public void setCreationTime(FileTime time, LinkOption... options) throws IOException`. Since 19.0. Sets the file's creation time. Parameters: `time` `FileTime`: the new value of the creation time. `options` `LinkOption...`: the options determining how the symbolic links should be handled. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#setCreationTime(java.nio.file.attribute.FileTime,java.nio.file.LinkOption...)`
### list()
`public Collection list() throws IOException`. Since 19.0. Returns a collection of `TruffleFile`s in the directory denoted by this `TruffleFile`. Returns `Collection`: a collection of `TruffleFile`s located in the directory denoted by this `TruffleFile`. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#list()`
### newByteChannel(Set, FileAttribute...)
`public FileChannel newByteChannel(Set extends OpenOption> options, FileAttribute>... attributes) throws IOException`. Since 19.0. Opens or creates a file returning a [`FileChannel`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileChannel.html) to access the file content. In most cases, the returned channel should be closed using a try-with-resources construct. When the channel must remain open for the lifetime of a context, it should be `registered` for automatic close on context disposal. The returned channel supports file locking when locking is supported by the underlying file system. On JDK 22 and later, it also supports mapping file regions when memory mapping is supported by the underlying file system. Parameters: `options` `Set extends OpenOption>`: the options specifying how the file should be opened. `attributes` `FileAttribute>...`: the optional attributes to set atomically when creating the new file. Returns `FileChannel`: the created [`FileChannel`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileChannel.html). Throws: `FileAlreadyExistsException` (unchecked): if [`StandardOpenOption.CREATE_NEW`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardOpenOption.html#CREATE_NEW) option is set and a file already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically. `IllegalArgumentException` (unchecked): in case of invalid options combination. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Overrides `newByteChannel(java.util.Set,java.nio.file.attribute.FileAttribute...)`. Cite: `com/oracle/truffle/api/TruffleFile.html#newByteChannel(java.util.Set,java.nio.file.attribute.FileAttribute...)`
### newInputStream(OpenOption...)
`public InputStream newInputStream(OpenOption... options) throws IOException`. Since 19.0. Opens a file for reading returning an [`InputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InputStream.html) to access the file content. In most cases, the returned [`InputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InputStream.html) should be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should be `registered` for automatic close on context dispose. Parameters: `options` `OpenOption...`: the options specifying how the file should be opened. Returns `InputStream`: the created [`InputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InputStream.html). Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): in case of invalid options combination. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newInputStream(java.nio.file.OpenOption...)`
### newBufferedReader(Charset)
`public BufferedReader newBufferedReader(Charset charset) throws IOException`. Since 19.0. Opens a file for reading returning a [`BufferedReader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedReader.html) to access the file content. In most cases, the returned [`BufferedReader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedReader.html) should be closed using try-with-resources construct. When the reader must keep being opened for the lifetime of a context it should be `registered` for automatic close on context dispose. Parameters: `charset` `Charset`: the file encoding. Returns `BufferedReader`: the created [`BufferedReader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedReader.html). Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newBufferedReader(java.nio.charset.Charset)`
### newBufferedReader()
`public BufferedReader newBufferedReader() throws IOException`. Since 19.0. Opens a file for reading returning a [`BufferedReader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedReader.html) to access the file content. See `newBufferedReader(Charset)`. Returns `BufferedReader`: the created [`BufferedReader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedReader.html). Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newBufferedReader()`
### readAllBytes()
`public byte[] readAllBytes() throws IOException`. Since 19.0. Reads a file content as bytes. Returns `byte[]`: the created `byte[]`. Throws: `IOException`: in case of IO error. `OutOfMemoryError` (unchecked): if an array of a file size cannot be allocated. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#readAllBytes()`
### newOutputStream(OpenOption...)
`public OutputStream newOutputStream(OpenOption... options) throws IOException`. Since 19.0. Opens a file for writing returning an [`OutputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/OutputStream.html). In most cases, the returned [`OutputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/OutputStream.html) should be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should be `registered` for automatic close on context dispose. Parameters: `options` `OpenOption...`: the options specifying how the file should be opened. Returns `OutputStream`: the created [`OutputStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/OutputStream.html). Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): in case of invalid options combination. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newOutputStream(java.nio.file.OpenOption...)`
### newBufferedWriter(Charset, OpenOption...)
`public BufferedWriter newBufferedWriter(Charset charset, OpenOption... options) throws IOException`. Since 19.0. Opens a file for writing returning an [`BufferedWriter`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedWriter.html). In most cases, the returned [`BufferedWriter`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedWriter.html) should be closed using try-with-resources construct. When the writer must keep being opened for the lifetime of a context it should be `registered` for automatic close on context dispose. Parameters: `charset` `Charset`: the file encoding. `options` `OpenOption...`: the options specifying how the file should be opened. Returns `BufferedWriter`: the created [`BufferedWriter`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedWriter.html). Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): in case of invalid options combination. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newBufferedWriter(java.nio.charset.Charset,java.nio.file.OpenOption...)`
### newBufferedWriter(OpenOption...)
`public BufferedWriter newBufferedWriter(OpenOption... options) throws IOException`. Since 19.0. Opens a file for writing returning an [`BufferedWriter`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedWriter.html). See `newBufferedWriter(Charset, OpenOption...)`. Parameters: `options` `OpenOption...`: the options specifying how the file should be opened. Returns `BufferedWriter`: the created [`BufferedWriter`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/BufferedWriter.html). Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): in case of invalid options combination. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newBufferedWriter(java.nio.file.OpenOption...)`
### createFile(FileAttribute...)
`public void createFile(FileAttribute>... attributes) throws IOException`. Since 19.0. Creates a new empty file. Parameters: `attributes` `FileAttribute>...`: the optional attributes to set atomically when creating the new file. Throws: `FileAlreadyExistsException` (unchecked): if the file already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#createFile(java.nio.file.attribute.FileAttribute...)`
### createDirectory(FileAttribute...)
`public void createDirectory(FileAttribute>... attributes) throws IOException`. Since 19.0. Creates a new directory. Parameters: `attributes` `FileAttribute>...`: the optional attributes to set atomically when creating the new file. Throws: `FileAlreadyExistsException` (unchecked): if the file or directory already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#createDirectory(java.nio.file.attribute.FileAttribute...)`
### createDirectories(FileAttribute...)
`public void createDirectories(FileAttribute>... attributes) throws IOException`. Since 19.0. Creates a directory and all nonexistent parent directories. Unlike the `createDirectory` the [`FileAlreadyExistsException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileAlreadyExistsException.html) is not thrown if the directory already exists. Parameters: `attributes` `FileAttribute>...`: the optional attributes to set atomically when creating the new file. Throws: `FileAlreadyExistsException` (unchecked): if a file (not a directory) already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#createDirectories(java.nio.file.attribute.FileAttribute...)`
### delete()
`public void delete() throws IOException`. Since 19.0. Deletes the file. If the `TruffleFile` denotes a directory, the directory must be empty before deleting. If the `TruffleFile` denotes a symbolic link the symbolic link itself is deleted not its target. Throws: `NoSuchFileException` (unchecked): if the file does not exist. `DirectoryNotEmptyException` (unchecked): if the `TruffleFile` denotes a non empty directory. `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#delete()`
### move(TruffleFile, CopyOption...)
`public void move(TruffleFile target, CopyOption... options) throws IOException`. Since 19.0. Moves or renames the file. Parameters: `target` `TruffleFile`: the path of a target file. `options` `CopyOption...`: the options specifying how the move should be performed, see [`StandardCopyOption`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html). Throws: `UnsupportedOperationException` (unchecked): if `options` contains unsupported option. `FileAlreadyExistsException` (unchecked): if the target path already exists and the `options` don't contain [`StandardCopyOption.REPLACE_EXISTING`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html#REPLACE_EXISTING) option. `DirectoryNotEmptyException` (unchecked): if the `options` contain [`StandardCopyOption.REPLACE_EXISTING`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html#REPLACE_EXISTING) but the `target` is a non empty directory. `AtomicMoveNotSupportedException` (unchecked): if the `options` contain [`StandardCopyOption.ATOMIC_MOVE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html#ATOMIC_MOVE) but file cannot be moved atomically. `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#move(com.oracle.truffle.api.TruffleFile,java.nio.file.CopyOption...)`
### getPosixPermissions(LinkOption...)
`public Set getPosixPermissions(LinkOption... linkOptions) throws IOException`. Since 19.0. Returns the file's Posix permissions. Parameters: `linkOptions` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `Set`: the file's Posix permissions. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): when the Posix permissions are not supported by filesystem. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getPosixPermissions(java.nio.file.LinkOption...)`
### setPosixPermissions(Set, LinkOption...)
`public void setPosixPermissions(Set extends PosixFilePermission> permissions, LinkOption... linkOptions) throws IOException`. Since 19.0. Sets the file's Posix permissions. Parameters: `permissions` `Set extends PosixFilePermission>`: the Posix permissions to set. `linkOptions` `LinkOption...`: the options determining how the symbolic links should be handled. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): when the Posix permissions are not supported by filesystem. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#setPosixPermissions(java.util.Set,java.nio.file.LinkOption...)`
### toString()
`public String toString()`. Since 19.0. Overrides `toString()`. Cite: `com/oracle/truffle/api/TruffleFile.html#toString()`
### hashCode()
`public int hashCode()`. Since 19.0. Overrides `hashCode()`. Cite: `com/oracle/truffle/api/TruffleFile.html#hashCode()`
### equals(Object)
`public boolean equals(Object other)`. Since 19.0. Overrides `equals(java.lang.Object)`. Cite: `com/oracle/truffle/api/TruffleFile.html#equals(java.lang.Object)`
### normalize()
`public TruffleFile normalize()`. Since 19.0. Returns a `TruffleFile` with removed redundant name elements in it's path. Returns `TruffleFile`: the normalized `TruffleFile`. Cite: `com/oracle/truffle/api/TruffleFile.html#normalize()`
### relativize(TruffleFile)
`public TruffleFile relativize(TruffleFile other)`. Since 19.0. Creates a `TruffleFile` with a relative path between this `TruffleFile` and a given `TruffleFile`. Relativization is the inverse of `resolution`. Relativization constructs a `TruffleFile` with relative path that when `resolved` against this `TruffleFile` yields a `TruffleFile` locating the same file as given `TruffleFile`. A relative path cannot be constructed if only one of the `TruffleFile`s is `absolute`. Parameters: `other` `TruffleFile`: the `TruffleFile` to relativize against this `TruffleFile`. Returns `TruffleFile`: the `TruffleFile` with relative path between this and `other` `TruffleFile`s. Throws: `IllegalArgumentException` (unchecked): when `other` cannot be relativized against this `TruffleFile`. Cite: `com/oracle/truffle/api/TruffleFile.html#relativize(com.oracle.truffle.api.TruffleFile)`
### startsWith(String)
`public boolean startsWith(String other)`. Since 19.0. Tests if this `TruffleFile` path starts with the given path. The path `foo/bar` starts with `foo` and `foo/bar` but does not start with `f`. Parameters: `other` `String`: the path. Returns `boolean`: `true` if this `TruffleFile` path starts with given path. Throws: `IllegalArgumentException` (unchecked): if the path cannot be parsed. Cite: `com/oracle/truffle/api/TruffleFile.html#startsWith(java.lang.String)`
### startsWith(TruffleFile)
`public boolean startsWith(TruffleFile other)`. Since 19.0. Tests if this `TruffleFile` path starts with the given `TruffleFile` path. The path `foo/bar` starts with `foo` and `foo/bar` but does not start with `f`. Parameters: `other` `TruffleFile`: the `TruffleFile`. Returns `boolean`: `true` if this `TruffleFile` path starts with given `TruffleFile` path. Cite: `com/oracle/truffle/api/TruffleFile.html#startsWith(com.oracle.truffle.api.TruffleFile)`
### endsWith(String)
`public boolean endsWith(String other)`. Since 19.0. Tests if this `TruffleFile` path ends with the given path. The path `foo/bar` ends with `bar` and `foo/bar` but does not end with `r`. Parameters: `other` `String`: the path. Returns `boolean`: `true` if this `TruffleFile` path ends with given path. Throws: `IllegalArgumentException` (unchecked): if the path cannot be parsed. Cite: `com/oracle/truffle/api/TruffleFile.html#endsWith(java.lang.String)`
### endsWith(TruffleFile)
`public boolean endsWith(TruffleFile other)`. Since 19.0. Tests if this `TruffleFile` path ends with the given `TruffleFile` path. The path `foo/bar` ends with `bar` and `foo/bar` but does not end with `r`. Parameters: `other` `TruffleFile`: the `TruffleFile`. Returns `boolean`: `true` if this `TruffleFile` path ends with given `TruffleFile` path. Cite: `com/oracle/truffle/api/TruffleFile.html#endsWith(com.oracle.truffle.api.TruffleFile)`
### createLink(TruffleFile)
`public void createLink(TruffleFile target) throws IOException`. Since 19.0. Creates a new link to an existing target *(optional operation)*. Parameters: `target` `TruffleFile`: the existing file to link. Throws: `FileAlreadyExistsException` (unchecked): if the file or directory already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation does not support links. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#createLink(com.oracle.truffle.api.TruffleFile)`
### createSymbolicLink(TruffleFile, FileAttribute...)
`public void createSymbolicLink(TruffleFile target, FileAttribute>... attrs) throws IOException`. Since 19.0. Creates a symbolic link to a target *(optional operation)*. Parameters: `target` `TruffleFile`: the target of the symbolic link. `attrs` `FileAttribute>...`: the optional attributes to set atomically when creating the symbolic link. Throws: `FileAlreadyExistsException` (unchecked): if the file or directory already exists on given path. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation does not support symbolic links or the attributes contain an attribute which cannot be set atomically. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#createSymbolicLink(com.oracle.truffle.api.TruffleFile,java.nio.file.attribute.FileAttribute...)`
### readSymbolicLink()
`public TruffleFile readSymbolicLink() throws IOException`. Since 20.3. Reads the target of a symbolic link. Returns `TruffleFile`: the `TruffleFile` representing the target of the symbolic link. Throws: `NotLinkException` (unchecked): if the `TruffleFile` is not a symbolic link. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation does not support symbolic links. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#readSymbolicLink()`
### getOwner(LinkOption...)
`public UserPrincipal getOwner(LinkOption... options) throws IOException`. Since 19.0. Returns the owner of the file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `UserPrincipal`: the file owner. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation does not support owner attribute. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getOwner(java.nio.file.LinkOption...)`
### getGroup(LinkOption...)
`public GroupPrincipal getGroup(LinkOption... options) throws IOException`. Since 19.0. Returns the group owner of the file. Parameters: `options` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `GroupPrincipal`: the file owner. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation does not support group owner attribute. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getGroup(java.nio.file.LinkOption...)`
### newDirectoryStream()
`public DirectoryStream newDirectoryStream() throws IOException`. Since 19.0. Opens a directory, returning a [`DirectoryStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/DirectoryStream.html) to iterate over all entries in the directory. The `TruffleFile`s returned by the directory stream's [`iterator`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/DirectoryStream.html#iterator%28%29) are created as if by `resolving` the name of the directory entry against this `TruffleFile`. In most cases, the returned [`DirectoryStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/DirectoryStream.html) should be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should be `registered` for automatic close on context dispose. When not using the try-with-resources construct, then the directory stream's [`close`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/Closeable.html#close%28%29) method should be called after iteration is completed. The code which iterates over all files can use simpler `list()` method. Returns `DirectoryStream`: a new opened [`DirectoryStream`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/DirectoryStream.html) object. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#newDirectoryStream()`
### visit(FileVisitor, int, FileVisitOption...)
`public void visit(FileVisitor visitor, int maxDepth, FileVisitOption... options) throws IOException`. Since 19.0. Visits this `TruffleFile` file tree. This method walks a file tree rooted at this `TruffleFile`. The file tree traversal is *depth-first*. The appropriate method on give [`FileVisitor`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html) is invoked for each met file. File tree traversal completes when all accessible files in the tree have been visited, a [`FileVisitor`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html) visit method returns a [`FileVisitResult.TERMINATE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitResult.html#TERMINATE) or a [`FileVisitor`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html) method terminates due to an uncaught exception. For each file encountered this method attempts to read its [`java.nio.file.attribute.BasicFileAttributes`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/attribute/BasicFileAttributes.html). If the file is not a directory then the [`visitFile`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html#visitFile%28T,java.nio.file.attribute.BasicFileAttributes%29) method is invoked with the file attributes. If the file attributes cannot be read, due to an I/O exception, then the [`visitFileFailed`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html#visitFileFailed%28T,java.io.IOException%29) method is invoked with the I/O exception. Where the file is a directory, and the directory could not be opened, then the `visitFileFailed` method is invoked with the I/O exception, after which, the file tree walk continues, by default, at the next *sibling* of the directory. Where the directory is opened successfully, then the entries in the directory, and their *descendants* are visited. When all entries have been visited, or an I/O error occurs during iteration of the directory, then the directory is closed and the visitor's [`postVisitDirectory`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html#postVisitDirectory%28T,java.io.IOException%29) method is invoked. The file tree walk then continues, by default, at the next *sibling* of the directory. By default, symbolic links are not automatically followed by this method. If the `options` parameter contains the [`FOLLOW_LINKS`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitOption.html#FOLLOW_LINKS) option then symbolic links are followed. The `maxDepth` parameter is the maximum number of levels of directories to visit. A value of `0` means that only the starting file is visited. The `visitFile` method is invoked for all files, including directories, encountered at `maxDepth`, unless the basic file attributes cannot be read, in which case the ` visitFileFailed` method is invoked. Parameters: `visitor` `FileVisitor`: the [`FileVisitor`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/FileVisitor.html) to invoke for each file. `maxDepth` `int`: the maximum number of directory levels to visit, [`MAX_VALUE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Integer.html#MAX_VALUE) may be used to indicate that all levels should be visited. `options` `FileVisitOption...`: the options configuring the file tree traversal. Throws: `IllegalArgumentException` (unchecked): if the `maxDepth` parameter is negative. `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#visit(java.nio.file.FileVisitor,int,java.nio.file.FileVisitOption...)`
### copy(TruffleFile, CopyOption...)
`public void copy(TruffleFile target, CopyOption... options) throws IOException`. Since 19.0. Copies the file. When the file is a directory the copy creates an empty directory in the target location, the directory entries are not copied. This method can be used with the `visit` method to copy the whole sub-tree. Parameters: `target` `TruffleFile`: the path of a target file. `options` `CopyOption...`: the options specifying how the copy should be performed, see [`StandardCopyOption`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html). Throws: `UnsupportedOperationException` (unchecked): if `options` contains unsupported option. `FileAlreadyExistsException` (unchecked): if the target path already exists and the `options` don't contain [`StandardCopyOption.REPLACE_EXISTING`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html#REPLACE_EXISTING) option. `DirectoryNotEmptyException` (unchecked): if the `options` contain [`StandardCopyOption.REPLACE_EXISTING`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardCopyOption.html#REPLACE_EXISTING) but the `target` is a non empty directory. `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#copy(com.oracle.truffle.api.TruffleFile,java.nio.file.CopyOption...)`
### detectMimeType()
`public String detectMimeType()`. Since 22.2. Detects the `file` MIME type. Returns `String`: the MIME type or `null` if the MIME type is not recognized. Throws: `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#detectMimeType()`
### isSameFile(TruffleFile, LinkOption...)
`public boolean isSameFile(TruffleFile other, LinkOption... options) throws IOException`. Since 20.2.0. Tests if this and the given `TruffleFile` refer to the same physical file. If both `TruffleFile` objects are `equal` then this method returns `true` without any checks. If the `TruffleFile`s have different filesystems then this method returns `false`. Otherwise, this method checks if both `TruffleFile`s refer to the same physical file. Depending on the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation it may require to read the files attributes. This implies: Public and Internal files with disabled IO are never the same.; Public and Internal files with allowed IO are potentially the same.; Files created by different languages are potentially the same.; Files created during the Context pre-initialization and files created during Context execution are potentially the same. Parameters: `other` `TruffleFile`: the other `TruffleFile`. Returns `boolean`: `true` if this and the given `TruffleFile` refer to the same physical file. Throws: `IOException`: in case of IO error. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#isSameFile(com.oracle.truffle.api.TruffleFile,java.nio.file.LinkOption...)`
### getAttribute(TruffleFile.AttributeDescriptor, LinkOption...)
`public T getAttribute(TruffleFile.AttributeDescriptor attribute, LinkOption... linkOptions) throws IOException`. Since 19.0. Reads a single file's attribute. Parameters: `attribute` `TruffleFile.AttributeDescriptor`: the attribute to read. `linkOptions` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `T`: the attribute value. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): when the filesystem does not support required attribute. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getAttribute(com.oracle.truffle.api.TruffleFile.AttributeDescriptor,java.nio.file.LinkOption...)`
### setAttribute(TruffleFile.AttributeDescriptor, T, LinkOption...)
`public void setAttribute(TruffleFile.AttributeDescriptor attribute, T value, LinkOption... linkOptions) throws IOException`. Since 19.1.0. Sets a single file's attribute. Parameters: `attribute` `TruffleFile.AttributeDescriptor`: the attribute to set. `value` `T`: the attribute value. `linkOptions` `LinkOption...`: the options determining how the symbolic links should be handled. Throws: `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): when the filesystem does not support given attribute. `IllegalArgumentException` (unchecked): when the attribute value has an inappropriate value. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#setAttribute(com.oracle.truffle.api.TruffleFile.AttributeDescriptor,T,java.nio.file.LinkOption...)`
### getAttributes(Collection, LinkOption...)
`public TruffleFile.Attributes getAttributes(Collection extends TruffleFile.AttributeDescriptor>> attributes, LinkOption... linkOptions) throws IOException`. Since 19.0. Reads file's attributes as a bulk operation. Parameters: `attributes` `Collection extends TruffleFile.AttributeDescriptor>>`: the attributes to read. `linkOptions` `LinkOption...`: the options determining how the symbolic links should be handled. Returns `TruffleFile.Attributes`: the `attributes view`. Throws: `IllegalArgumentException` (unchecked): when no attributes are given. `IOException`: in case of IO error. `UnsupportedOperationException` (unchecked): when the filesystem does not support some of the required attributes. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.html#getAttributes(java.util.Collection,java.nio.file.LinkOption...)`
### getFileStoreInfo()
`public TruffleFile.FileStoreInfo getFileStoreInfo()`. Since 25.0.0. Returns information about the file store that contains this file. The returned `FileStoreInfo` object provides access to disk-related metadata such as total size, usable space, and unallocated space. See also: `FileStoreInfo`. Cite: `com/oracle/truffle/api/TruffleFile.html#getFileStoreInfo()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleFile.AttributeDescriptor
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0. Nested in [`TruffleFile`](com/oracle/truffle/api/TruffleFile.md).
```java
public static final class TruffleFile.AttributeDescriptor
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `AttributeDescriptor`
Represents a file's attribute.
Not all attributes are supported by all filesystems. When the filesystem does not support the attribute the attribute read fails with [`UnsupportedOperationException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/UnsupportedOperationException.html).
Attributes can be read one by one by the [`getAttribute`](com/oracle/truffle/api/TruffleFile.md#getAttribute%28com.oracle.truffle.api.TruffleFile.AttributeDescriptor,java.nio.file.LinkOption...%29) method or as a bulk read operation by [`getAttributes`](com/oracle/truffle/api/TruffleFile.md#getAttributes%28java.util.Collection,java.nio.file.LinkOption...%29) method. When more attributes are needed the bulk read provides better performance.
## Methods
### toString()
`public String toString()`. Since 19.0. Overrides `toString()`. Cite: `com/oracle/truffle/api/TruffleFile.AttributeDescriptor.html#toString()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleFile.Attributes
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0. Nested in [`TruffleFile`](com/oracle/truffle/api/TruffleFile.md).
```java
public static final class TruffleFile.Attributes
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Attributes`
A view over file's attributes values obtained by [`getAttributes`](com/oracle/truffle/api/TruffleFile.md#getAttributes%28java.util.Collection,java.nio.file.LinkOption...%29).
## Methods
### get(TruffleFile.AttributeDescriptor)
`public T get(TruffleFile.AttributeDescriptor descriptor)`. Since 19.0. Returns the attribute value. Parameters: `descriptor` `TruffleFile.AttributeDescriptor`: the attribute to obtain value for. Returns `T`: the attribute value, may return `null` if the filesystem doesn't support the attribute. Throws: `IllegalArgumentException` (unchecked): if the view was not created for the given attribute. Cite: `com/oracle/truffle/api/TruffleFile.Attributes.html#get(com.oracle.truffle.api.TruffleFile.AttributeDescriptor)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleFile.FileStoreInfo
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 25.0.0. Nested in [`TruffleFile`](com/oracle/truffle/api/TruffleFile.md).
```java
public final class TruffleFile.FileStoreInfo
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `FileStoreInfo`
Provides information about the file store. This class offers access to storage-related metrics, such as the total size of the file store, unallocated space, and the usable space available to the current Java virtual machine.
**See also**
- [`TruffleFile.getFileStoreInfo()`](com/oracle/truffle/api/TruffleFile.md#getFileStoreInfo%28%29)
## Methods
### getTotalSpace()
`public long getTotalSpace() throws IOException`. Since 25.0.0. Returns the size, in bytes, of the file store. If the file store's size exceeds [`Long.MAX_VALUE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Long.html#MAX_VALUE), `Long.MAX_VALUE` is returned. Returns `long`: the size of the file store in bytes. Throws: `UnsupportedOperationException` (unchecked): if the file system does not support retrieving file store information. `IOException`: if an I/O error occurs while accessing the file store. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileStoreInfo.html#getTotalSpace()`
### getUnallocatedSpace()
`public long getUnallocatedSpace() throws IOException`. Since 25.0.0. Returns the number of unallocated bytes in the file store. The returned value represents the raw free space on the storage device, regardless of access permissions or user quotas. If the number of unallocated bytes exceeds [`Long.MAX_VALUE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Long.html#MAX_VALUE), `Long.MAX_VALUE` is returned. Note that the value may be imprecise, as it can change at any time due to external I/O operations, including those performed outside this virtual machine. Returns `long`: the number of unallocated bytes. Throws: `UnsupportedOperationException` (unchecked): if the file system does not support retrieving file store information. `IOException`: if an I/O error occurs while accessing the file store. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileStoreInfo.html#getUnallocatedSpace()`
### getUsableSpace()
`public long getUsableSpace() throws IOException`. Since 25.0.0. Returns the number of bytes available to this Java virtual machine on the file store. Unlike `getUnallocatedSpace()`, this method accounts for operating system-level restrictions, user quotas, and file system permissions, and therefore may return a smaller value. If the available space exceeds [`Long.MAX_VALUE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Long.html#MAX_VALUE), `Long.MAX_VALUE` is returned. Note that the returned value may be imprecise, as it can change at any time due to external I/O activity, including operations performed outside this virtual machine. Returns `long`: the number of usable bytes available to this Java virtual machine. Throws: `UnsupportedOperationException` (unchecked): if the file system does not support retrieving file store information. `IOException`: if an I/O error occurs while accessing the file store. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileStoreInfo.html#getUsableSpace()`
### getBlockSize()
`public long getBlockSize() throws IOException`. Since 25.0.0. Returns the number of bytes per block in the file store. Returns `long`: the block size. Throws: `UnsupportedOperationException` (unchecked): if the file system does not support retrieving file store information. `IOException`: if an I/O error occurs while accessing the file store. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileStoreInfo.html#getBlockSize()`
### isReadOnly()
`public boolean isReadOnly() throws IOException`. Since 25.0.0. Determines whether the file store is read-only. Note that even if the file store is not read-only, individual write operations may still be denied due to restrictions imposed by the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation, operating system level policies, user quotas, or file system permissions. Throws: `UnsupportedOperationException` (unchecked): if the file system does not support retrieving file store information. `IOException`: if an I/O error occurs while accessing the file store. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) implementation denied the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileStoreInfo.html#isReadOnly()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ TruffleFile.FileTypeDetector
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0. Nested in [`TruffleFile`](com/oracle/truffle/api/TruffleFile.md).
```java
public interface TruffleFile.FileTypeDetector
```
A detector for finding [`file`](com/oracle/truffle/api/TruffleFile.md)'s MIME type and encoding.
The means by which the detector determines the MIME is highly implementation specific. A simple implementation might detect the MIME type using [`file`](com/oracle/truffle/api/TruffleFile.md) extension. In other cases, the content of [`file`](com/oracle/truffle/api/TruffleFile.md) needs to be examined to guess its file type.
The implementations are registered using [`TruffleLanguage registration`](com/oracle/truffle/api/TruffleLanguage.Registration.md#fileTypeDetectors%28%29).
**See also**
- [`TruffleFile.detectMimeType()`](com/oracle/truffle/api/TruffleFile.md#detectMimeType%28%29)
- [`TruffleLanguage.Registration.fileTypeDetectors()`](com/oracle/truffle/api/TruffleLanguage.Registration.md#fileTypeDetectors%28%29)
## Methods
### findMimeType(TruffleFile)
`String findMimeType(TruffleFile file) throws IOException`. Since 19.0. Finds a MIME type for given `TruffleFile`. Parameters: `file` `TruffleFile`: the `file` to find a MIME type for. Returns `String`: the MIME type or `null` if the MIME type is not recognized. Throws: `IOException`: of an I/O error occurs. `SecurityException` (unchecked): if the implementation requires an access the file and the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denies the operation. Cite: `com/oracle/truffle/api/TruffleFile.FileTypeDetector.html#findMimeType(com.oracle.truffle.api.TruffleFile)`
### findEncoding(TruffleFile)
`Charset findEncoding(TruffleFile file) throws IOException`. Since 19.0. For a file containing an encoding information returns the encoding. Parameters: `file` `TruffleFile`: the `file` to find an encoding for. It's guaranteed that the `file` has a MIME type supported by the language registering this `FileTypeDetector`. Returns `Charset`: the file encoding or `null` if the file does not provide encoding. Throws: `IOException`: of an I/O error occurs. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denies the file access. Cite: `com/oracle/truffle/api/TruffleFile.FileTypeDetector.html#findEncoding(com.oracle.truffle.api.TruffleFile)`
# ◆ TruffleLanguage
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public abstract class TruffleLanguage
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleLanguage`
A Truffle language implementation contains all the services a language should provide to make it composable with other languages. Implementation classes must be annotated with [`Registration`](com/oracle/truffle/api/TruffleLanguage.Registration.md) in order to be discoverable by the [Polyglot API](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/package-summary.html). [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) subclasses must provide a public default constructor.
#### Lifecycle
A language implementation becomes available for use by an engine when metadata is added using the [`Registration`](com/oracle/truffle/api/TruffleLanguage.Registration.md) annotation and the implementation's JAR file placed on the host Java Virtual Machine's class path.
A newly created engine locates all available language implementations and creates a [descriptor](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Language.html) for each. The descriptor holds the language's registered metadata, but its execution environment is not initialized until the language is needed for code execution. That execution environment remains initialized for the lifetime of the engine and is isolated from the environment in any other engine instance.
Language global state can be shared between multiple context instances by saving them in a custom field of the [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) subclass. Languages may control sharing between multiple contexts using its [`context policy`](com/oracle/truffle/api/TruffleLanguage.Registration.md#contextPolicy%28%29). By default the context policy is [`exclusive`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#EXCLUSIVE): each context has its own separate TruffleLanguage instance.
If the context policy is more permissive then the implementation needs to manually ensure data isolation between the contexts. This means that state associated with a context must not be stored in a TruffleLanguage subclass. ASTs and assumptions can be shared across multiple contexts if modifying them does not affect language semantics. Languages are strongly discouraged from using static mutable state in their languages. Instead [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) instances should be used instead to store global state and their sharing should be configured using [`context policy`](com/oracle/truffle/api/TruffleLanguage.Registration.md#contextPolicy%28%29).
Whenever an engine is disposed then each initialized language context will be [`disposed`](com/oracle/truffle/api/TruffleLanguage.md#disposeContext%28C%29).
#### Context Policy and Sharing
The number of [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) instances per polyglot [`context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) is configured by the [`context policy`](com/oracle/truffle/api/TruffleLanguage.Registration.md#contextPolicy%28%29). By default an [`exclusive`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#EXCLUSIVE) [`language`](com/oracle/truffle/api/TruffleLanguage.md) instance is created for every [`polyglot context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) or [`inner context`](com/oracle/truffle/api/TruffleLanguage.Env.md#newInnerContextBuilder%28java.lang.String...%29). With policy [`reuse`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#REUSE), language instances will be reused after a language context was [`disposed`](com/oracle/truffle/api/TruffleLanguage.md#disposeContext%28C%29). With policy [`shared`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#SHARED), a language will also be reused if active contexts are not yet disposed. Language instances will only be shared or reused if they are [`compatible`](com/oracle/truffle/api/TruffleLanguage.md#areOptionsCompatible%28org.graalvm.options.OptionValues,org.graalvm.options.OptionValues%29). Language implementations are encouraged to support the most permissive context policy possible. Please see the individual [`policies`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md) for details on the implications on the language implementation.
The following illustration shows the cardinalities of the individual components:
```java
N: unbounded
P: N for exclusive, 1 for shared context policy
L: number of installed languages
I: number of installed instruments
- 1 : Host VM Processs
- N : Engine
- N : Context
- L : Language Context
- P * L : TruffleLanguage
- I : Instrument
- 1 : TruffleInstrument
```
For more information on sharing between multiple contexts please see [`ContextPolicy`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md).
#### Parse Caching
The result of the [`parsing request`](com/oracle/truffle/api/TruffleLanguage.md#parse%28com.oracle.truffle.api.TruffleLanguage.ParsingRequest%29) is cached per language instance, [`source`](com/oracle/truffle/api/TruffleLanguage.ParsingRequest.md#getSource%28%29), [`argument names`](com/oracle/truffle/api/TruffleLanguage.ParsingRequest.md#getArgumentNames%28%29) and environment [`options`](com/oracle/truffle/api/TruffleLanguage.Env.md#getOptions%28%29). The scope of the caching is influenced by the [`context policy`](com/oracle/truffle/api/TruffleLanguage.Registration.md#contextPolicy%28%29). Caching may be [`disabled`](com/oracle/truffle/api/source/Source.md#isCached%28%29) for certain sources. It is enabled for new sources by default.
#### Language Configuration
On [`context creation`](com/oracle/truffle/api/TruffleLanguage.md#createContext%28com.oracle.truffle.api.TruffleLanguage.Env%29) each language context is provided with information about the environment [`environment`](com/oracle/truffle/api/TruffleLanguage.Env.md). Language can optionally declare [`configurable`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#option%28java.lang.String,java.lang.String%29) options in [`getOptionDescriptors()`](com/oracle/truffle/api/TruffleLanguage.md#getOptionDescriptors%28%29).
#### Polyglot Bindings
Language implementations communicate with one another (and with instrumentation-based tools such as debuggers) by reading/writing named values into the [`polyglot bindings`](com/oracle/truffle/api/TruffleLanguage.Env.md#getPolyglotBindings%28%29). This bindings object is used to implement guest language export/import statements used for *language interoperation*.
A language implementation can also [import](com/oracle/truffle/api/TruffleLanguage.Env.md#importSymbol%28java.lang.String%29) or [export](com/oracle/truffle/api/TruffleLanguage.Env.md#exportSymbol%28java.lang.String,java.lang.Object%29) a global symbol by name. The scope may be accessed from multiple threads at the same time. Existing keys are overwritten.
#### Configuration vs. Initialization
To ensure that a Truffle language can be used in a language-agnostic way, the implementation should be designed to decouple its configuration and initialization from language specifics as much as possible. One aspect of this is the initialization and start of execution via the [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html), which should be designed in a generic way. Language-specific entry points, for instance to emulate the command-line interface of an existing implementation, should be handled externally.
#### Multi-threading
There are two kinds of threads that access contexts of Truffle guest languages:
- Internal threads are [`created`](com/oracle/truffle/api/TruffleLanguage.Env.md#newTruffleThreadBuilder%28java.lang.Runnable%29) and managed by a language for a context. All internally created threads need to be stopped when the context is [`disposed`](com/oracle/truffle/api/TruffleLanguage.md#disposeContext%28C%29).
- External threads are created and managed by the host application / language launcher. The host application is allowed to use language contexts from changing threads, sequentially or at the same time if the language [`allows`](com/oracle/truffle/api/TruffleLanguage.md#isThreadAccessAllowed%28java.lang.Thread,boolean%29) it.
By default every [`context`](com/oracle/truffle/api/TruffleLanguage.md#createContext%28com.oracle.truffle.api.TruffleLanguage.Env%29) only allows access from one thread at the same time. Therefore if the context is tried to be accessed from multiple threads at the same time the access will fail. Languages that want to allow multi-threaded access to a context may override [`isThreadAccessAllowed(Thread, boolean)`](com/oracle/truffle/api/TruffleLanguage.md#isThreadAccessAllowed%28java.lang.Thread,boolean%29) and return `true` also for multi-threaded accesses. Initialization actions for multi-threaded access can be performed by overriding [`initializeMultiThreading(Object)`](com/oracle/truffle/api/TruffleLanguage.md#initializeMultiThreading%28C%29). Threads are [`initialized`](com/oracle/truffle/api/TruffleLanguage.md#initializeThread%28C,java.lang.Thread%29) and [`disposed`](com/oracle/truffle/api/TruffleLanguage.md#disposeContext%28C%29) before and after use with a context. Languages may [`create`](com/oracle/truffle/api/TruffleLanguage.Env.md#newTruffleThreadBuilder%28java.lang.Runnable%29) new threads if the environment [`allows`](com/oracle/truffle/api/TruffleLanguage.Env.md#isCreateThreadAllowed%28%29) it.
In addition to the two kinds of threads described above, there are [`system threads`](com/oracle/truffle/api/TruffleLanguage.Env.md#createSystemThread%28java.lang.Runnable,java.lang.ThreadGroup%29) designed to process language internal tasks in the background. They do not require the [`creation permit`](com/oracle/truffle/api/TruffleLanguage.Env.md#isCreateThreadAllowed%28%29), but they must not enter any language context.
**Type parameters**
- ``: internal state of the language associated with every thread that is executing program [`parsed`](com/oracle/truffle/api/TruffleLanguage.md#parse%28com.oracle.truffle.api.TruffleLanguage.ParsingRequest%29) by the language
**See also**
- [`for embedding of Truffle languages in Java host applications.`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html)
## Nested types
- [`TruffleLanguage.ContextLocalFactory`](com/oracle/truffle/api/TruffleLanguage.ContextLocalFactory.md) (interface): Context local factory for Truffle languages.
- [`TruffleLanguage.ContextLocalProvider`](com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.md) (class): Provider for creating context local and context thread local references.
- [`TruffleLanguage.ContextPolicy`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md) (enum class): Defines the supported policy for reusing languages per context.
- [`TruffleLanguage.ContextReference`](com/oracle/truffle/api/TruffleLanguage.ContextReference.md) (abstract class): Represents a reference to the current context.
- [`TruffleLanguage.ContextThreadLocalFactory`](com/oracle/truffle/api/TruffleLanguage.ContextThreadLocalFactory.md) (interface): Context thread local factory for Truffle languages.
- [`TruffleLanguage.Env`](com/oracle/truffle/api/TruffleLanguage.Env.md) (class): Represents execution environment of the TruffleLanguage.
- [`TruffleLanguage.ExitMode`](com/oracle/truffle/api/TruffleLanguage.ExitMode.md) (enum class): Mode of exit operation.
- [`TruffleLanguage.InlineParsingRequest`](com/oracle/truffle/api/TruffleLanguage.InlineParsingRequest.md) (class): Request for inline parsing.
- [`TruffleLanguage.LanguageReference`](com/oracle/truffle/api/TruffleLanguage.LanguageReference.md) (abstract class): Represents a reference to the current language instance.
- [`TruffleLanguage.ParsingRequest`](com/oracle/truffle/api/TruffleLanguage.ParsingRequest.md) (class): Request for parsing.
- [`TruffleLanguage.Registration`](com/oracle/truffle/api/TruffleLanguage.Registration.md) (annotation interface): The annotation to use to register your language to the Polyglot API.
## Fields
### locals
`protected final TruffleLanguage.ContextLocalProvider locals`. Since 23.1. Provider for creating context local and context thread local references. See also: `TruffleLanguage.ContextLocalProvider.createContextLocal(TruffleLanguage.ContextLocalFactory)`, `TruffleLanguage.ContextLocalProvider.createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#locals`
## Constructors
### TruffleLanguage()
`protected TruffleLanguage()`. Since 0.8 or earlier. Constructor to be called by subclasses. Language should not create any `RootNode`s in its constructor. The RootNodes created in the language constructor are not associated with a Context and they don't respect Context's engine options. The needed RootNodes can be created in the `createContext(Env)`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#()`
## Methods
### areOptionsCompatible(OptionValues, OptionValues)
`protected boolean areOptionsCompatible(OptionValues firstOptions, OptionValues newOptions)`. Since 19.0. Returns `true` if the combination of two sets of options allow to `share` or `reuse` the same language instance, else `false`. If options are incompatible then a new language instance will be created for a new context. The default implementation returns `true`. If the context policy of a language is set to `exclusive` (default behavior) then `areOptionsCompatible(OptionValues, OptionValues)` will never be invoked as `TruffleLanguage` instances will not be shared for multiple contexts. For the other context policies `reuse` and `shared` this method can be used to further restrict the reuse of language instances. Compatibility influences `parse caching` because it uses the `language` instance as a key. Example usage of areOptionsCompatible if sharing of the language instances and parse caching should be restricted by the script version option: Parameters: `firstOptions` `OptionValues`: the options used to create the first context, never `null`. `newOptions` `OptionValues`: the options that will be used for the new context, never `null`. See also: `ContextPolicy`, `parse(ParsingRequest)`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#areOptionsCompatible(org.graalvm.options.OptionValues,org.graalvm.options.OptionValues)`
```java
class CompatibleLanguage extends TruffleLanguage {
@Option(help = "", category = OptionCategory.USER)
static final OptionKey ScriptVersion
= new OptionKey<>("ECMA2017");
@Override
protected boolean areOptionsCompatible(OptionValues firstOptions,
OptionValues newOptions) {
return firstOptions.get(ScriptVersion).
equals(newOptions.get(ScriptVersion));
}
@Override
protected OptionDescriptors getOptionDescriptors() {
return new CompatibleLanguageOptionDescriptors();
}
}
```
### createContext(TruffleLanguage.Env)
`protected abstract C createContext(TruffleLanguage.Env env)`. Since 0.8 or earlier. Creates internal representation of the executing context suitable for given environment. Each time the `language` is used by a new [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html), the system calls this method to let the `language` prepare for *execution*. The returned execution context is completely language specific; it is however expected it will contain reference to here-in provided `env` and adjust itself according to parameters provided by the `env` object. The context created by this method is accessible using `context references`. An [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown if the context is tried to be accessed while the createContext method is executed. This method shouldn't perform any complex operations. The runtime system is just being initialized and for example making `calls into other languages` and assuming your language is already initialized and others can see it would be wrong - until you return from this method, the initialization isn't over. The same is true for instrumentation, the instruments cannot receive any meta data about code executed during context creation. Should there be a need to perform complex initialization, do it by overriding the `initializeContext(java.lang.Object)` method. Additional services provided by the language must be `registered` by this method otherwise [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. May return `null` if the language does not need any per-[context](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) state. Otherwise it should return a new object instance every time it is called. Parameters: `env` `TruffleLanguage.Env`: the environment the language is supposed to operate in. Returns `C`: internal data of the language in given environment or `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#createContext(com.oracle.truffle.api.TruffleLanguage.Env)`
### initializeContext(C)
`protected void initializeContext(C context) throws Exception`. Since 0.17. Perform any complex initialization. The `createContext(com.oracle.truffle.api.TruffleLanguage.Env)` factory method shouldn't do any complex operations. Just create the instance of the context, let the runtime system register it properly. Should there be a need to perform complex initialization, override this method and let the runtime call it *later* to finish any *post initialization* actions. Example: Parameters: `context` `C`: the context created by `createContext(com.oracle.truffle.api.TruffleLanguage.Env)`. Throws: `Exception`: if something goes wrong. Cite: `com/oracle/truffle/api/TruffleLanguage.html#initializeContext(C)`
```java
class PostInitLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
// "quickly" create the context
return new Context(env);
}
@Override
protected void initializeContext(Context context) throws IOException {
// called "later" to finish the initialization
// for example call into another language
Source source = Source.newBuilder("js",
"function(x, y) x * y",
"mul.js").build();
context.mul = context.env.parsePublic(source);
}
}
```
### finalizeContext(C)
`protected void finalizeContext(C context)`. Since 0.30. Performs language context finalization actions that are necessary before language contexts are `disposed`. However, in case the underlying polyglot context is being cancelled or hard-exited, `disposeContext(Object)` is called even if `finalizeContext(Object)` throws an `com.oracle.truffle.api.exception.AbstractTruffleException` or a [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel or exit exception. For the hard exit a language is supposed to run its finalization actions that require running guest code in `exitContext(Object, ExitMode, int)`, but please note that after `exitContext(Object, ExitMode, int)` runs for a language, the language can still be invoked from `exitContext(Object, ExitMode, int)` for a different language. Therefore, for instance, finalization for standard streams should both flush and set them to unbuffered mode at the end of exitContext, so that running guest code is not required to dispose the streams after that point. Context finalization is invoked even if a context was cancelled. In such a case, if guest code would run as part of the finalization, it would be cancelled at the next polled `safepoint`. If there is guest code that always needs to run even if cancelled, e.g. to prevent resource leakage, use `TruffleSafepoint.setAllowActions(boolean)` to temporarily disable safepoints while executing that code. All installed languages must remain usable after finalization. The finalization order can be influenced by specifying `language dependencies`. By default internal languages are finalized last, otherwise, the default order is unspecified but deterministic. While the finalization code is run, other language contexts may become initialized. In such a case, the finalization order may be non-deterministic and/or not respect the order specified by language dependencies. All threads `created` by the language must be stopped and joined during finalizeContext. The languages are responsible for fulfilling that contract, otherwise, an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) is thrown. It's not safe to use the [`ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/ExecutorService.html#awaitTermination%28long,java.util.concurrent.TimeUnit%29) to detect Thread termination as the polyglot thread may be cancelled before executing the executor worker. During finalizeContext, all unclosed inner contexts `created` by the language must be left on all threads where the contexts are still active. No active inner context is allowed after `finalizeContext(Object)` returns, otherwise it is an internal error. Non-active inner contexts `created` by the language that are still unclosed after `finalizeContext(Object)` returns are automatically closed by Truffle. Typical implementation looks like: Parameters: `context` `C`: the context created by `createContext(com.oracle.truffle.api.TruffleLanguage.Env)`. See also: `for specifying language dependencies.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#finalizeContext(C)`
```java
class AsyncThreadLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected boolean isThreadAccessAllowed(Thread thread,
boolean singleThreaded) {
// allow access from any thread instead of just one
return true;
}
@Override
protected void initializeContext(Context context) throws Exception {
// create and start a Thread for the asynchronous task
// remeber the Thread reference to stop and join it in
// the finalizeContext
Thread t = context.env.newTruffleThreadBuilder(new Runnable() {
@Override
public void run() {
// asynchronous task
}
}).build();
context.startedThreads.add(t);
t.start();
}
@Override
protected void finalizeContext(Context context) {
// stop and join all the created Threads
boolean interrupted = false;
for (int i = 0; i < context.startedThreads.size();) {
Thread threadToJoin = context.startedThreads.get(i);
try {
if (threadToJoin != Thread.currentThread()) {
threadToJoin.interrupt();
threadToJoin.join();
}
i++;
} catch (InterruptedException ie) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
```
### exitContext(C, TruffleLanguage.ExitMode, int)
`protected void exitContext(C context, TruffleLanguage.ExitMode exitMode, int exitCode)`. Since 22.0. Performs language exit event actions that are necessary before language contexts are `finalized`. However, in case the underlying polyglot context is being cancelled, `exit notifications` are not executed. Also, for `hard exit`, `finalizeContext(Object)` is called even if `exitContext(Object, ExitMode, int)` throws an `com.oracle.truffle.api.exception.AbstractTruffleException` or a [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel or exit exception. All initialized language contexts must remain usable after exit notifications. In case a `com.oracle.truffle.api.exception.AbstractTruffleException` or the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exit exception is thrown during an `hard exit notification`, it is just logged and otherwise ignored and the notification process continues with the next language in order. In case the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel exception is thrown, it means the context is being cancelled in which case the exit notification process immediately stops. The exit notification order can be influenced by specifying `language dependencies` - The exit notification for language A that depends on language B is executed before the exit notification for language B. By default, notifications for internal languages are executed last, otherwise, the default order is unspecified but deterministic. During `hard exit` notification, a language is supposed to run its finalization actions that require running guest code instead of running them in `finalizeContext(Object)`. While the exit notification code is run, all languages remain fully functional. Also, other language contexts may become initialized. In such a case, the notification order may be non-deterministic and/or not respect the order specified by language dependencies. In case `TruffleContext.closeExited(Node, int)` is called during a `natural exit` notification, natural exit notifications for remaining language contexts are not executed and the `hard exit` process starts by executing `hard exit` notifications. In case `TruffleContext.closeExited(Node, int)` is called during a `hard exit` notification, it just throws the special [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exit exception, which is then just logged as described above. In case the underlying polyglot context is cancelled by e.g. `TruffleContext.closeCancelled(Node, String)` during exit notifications, guest code executed during exit notification is regularly cancelled, i.e., throws the [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) cancel exception, and the notification process does not continue as described above. In the case of `hard exit`, if the current context has inner contexts that are still active, the execution for them will be stopped as well after all language exit notifications are executed for the outer context, but the exit notifications for the inner contexts are not automatically executed. The language needs to take appropriate action to make sure inner contexts are exited properly. Parameters: `context` `C`: language context. `exitMode` `TruffleLanguage.ExitMode`: mode of exit. `exitCode` `int`: exit code that was specified for exit. See also: [Context Exit](https://github.com/oracle/graal/blob/master/truffle/docs/Exit.md). Cite: `com/oracle/truffle/api/TruffleLanguage.html#exitContext(C,com.oracle.truffle.api.TruffleLanguage.ExitMode,int)`
### initializeMultipleContexts()
`protected void initializeMultipleContexts()`. Since 19.0. Initializes this language instance for use with multiple contexts. Whether a language instance supports being used for multiple contexts depends on its `context policy`. For any sharing of a language instance for multiple language contexts to take place a context must be created with sharing enabled. By default sharing is disabled for polyglot contexts. Sharing can be enabled by specifying an [`explicit engine`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#engine%28org.graalvm.polyglot.Engine%29) or using an option. Before any language is used for sharing `initializeMultipleContexts()` is invoked. It is guaranteed that sharing between multiple contexts is `initialized` before any language context is `created`. A language may use this method to configure itself to use context independent speculations only. Since Truffle nodes are never shared between multiple language instances it is sufficient to keep track of whether sharing is enabled using a non-volatile boolean field instead of an assumption. They field may also be annotated with `CompilationFinal` as it is guaranteed that this method is called prior to any compilation. The following criteria should be satisfied when supporting context independent code: All speculation on runtime value identity must be disabled with multiple contexts initialized, as they will lead to a guaranteed deoptimization when used with a second context.; Function inline caches should be modified and implemented as a two-level inline cache. The first level speculates on the function instance's identity and the second level on the underlying CallTarget instance. The first level cache must be disabled if multiple contexts are initialized, as this would unnecessarily cause deoptimization.; The DynamicObject root Shape instance should be stored in the language instance instead of the language context. Otherwise, any inline cache on shapes will not stabilize and ultimately end up in the generic state.; All Node implementations must not store context-dependent data structures or context-dependent runtime values.; All assumption instances should be stored in the language instance instead of the context. With multiple contexts initialized, the context instance read using context references may no longer be a constant. In this case any assumption read from the context would not be folded and they would cause significant runtime performance overhead. Assumptions from the language can always be folded by the compiler in both single and multiple context mode. See also: `More information on sharing language instances for multiple contexts.`, `Specify option configurations that make sharing incompatible.`, `ContextPolicy`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#initializeMultipleContexts()`
### disposeContext(C)
`protected void disposeContext(C context)`. Since 0.8 or earlier. Disposes the context created by `createContext(com.oracle.truffle.api.TruffleLanguage.Env)`. A dispose cleans up all resources associated with a context. The context may become unusable after it was disposed. It is not allowed to run guest language code while disposing a context. Finalization code should be run in `finalizeContext(Object)` instead. Finalization will be performed prior to context `disposal`. However, in case the underlying polyglot context is being cancelled, `disposeContext(Object)` is called even if `finalizeContext(Object)` throws `com.oracle.truffle.api.exception.AbstractTruffleException` or [`ThreadDeath`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exception.. The disposal order can be influenced by specifying `language dependencies`. By default internal languages are disposed last, otherwise the default order is unspecified but deterministic. During disposal no other language must be accessed using the `language environment`. Parameters: `context` `C`: the context created by `createContext(com.oracle.truffle.api.TruffleLanguage.Env)`. See also: `to run finalization code for a context.`, `to perform disposal actions when a thread is no longer used.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#disposeContext(C)`
### parse(TruffleLanguage.ParsingRequest)
`protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception`. Since 0.22. Parses the `provided source` and generates its appropriate AST representation. The parsing should execute no user code, it should only create the `Node` tree to represent the source. If the `provided source` does not correspond naturally to a `call target`, the returned call target should create and if necessary initialize the corresponding language entity and return it. The result of the parsing request is cached per language instance, `source` and `argument names`. It is safe to assume that current `language` instance and `argument names` will remain unchanged for a parsed `CallTarget`. The scope of the caching is influenced by the `context policy` and option `compatibility`. Caching may be `disabled` for sources. It is enabled for new sources by default. The `argumentNames` may contain symbolic names for actual parameters of the call to the returned value. The result should be a call target with method `CallTarget.call(java.lang.Object...)` that accepts as many arguments as were provided via the `ParsingRequest.getArgumentNames()` method. Implement `parse(com.oracle.truffle.api.TruffleLanguage.InlineParsingRequest)` to parse source in a specific context location. Parameters: `request` `TruffleLanguage.ParsingRequest`: request for parsing. Returns `CallTarget`: a call target to invoke which also keeps in memory the `Node` tree representing just parsed `code`. Throws: `Exception`: exception can be thrown when parsing goes wrong. Here-in thrown exception is propagated to the user who called one of `eval` methods of [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). See also: `TruffleLanguage.Registration.contextPolicy()`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)`
### parse(TruffleLanguage.InlineParsingRequest)
`protected ExecutableNode parse(TruffleLanguage.InlineParsingRequest request) throws Exception`. Since 0.31. Parses the `provided source snippet` at the `provided location` and generates its appropriate AST representation. The parsing should execute no user code, it should only create the `Node` tree to represent the source. The parsing should be performed in a context (specified by `InlineParsingRequest.getLocation()`). The result should be an AST fragment with method `ExecutableNode.execute(com.oracle.truffle.api.frame.VirtualFrame)` that accepts frames valid at the `provided location`. When not implemented, `null` is returned by default. Parameters: `request` `TruffleLanguage.InlineParsingRequest`: request for parsing. Returns `ExecutableNode`: a fragment to invoke which also keeps in memory the `Node` tree representing just parsed `code`, or `null` when inline parsing of code snippets is not implemented. Throws: `Exception`: exception can be thrown when parsing goes wrong. Cite: `com/oracle/truffle/api/TruffleLanguage.html#parse(com.oracle.truffle.api.TruffleLanguage.InlineParsingRequest)`
### getOptionDescriptors()
`protected OptionDescriptors getOptionDescriptors()`. Since 0.27. Returns a set of option descriptors that are supported by this language. Option values are accessible using the `environment` when the context is `created`. To construct option descriptors from a list then [`OptionDescriptors.create(List)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html#create%28java.util.List%29) can be used. Languages must always return the same option descriptors independent of the language instance or side-effects. See also: `For an example of declaring the option descriptor using an annotation.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getOptionDescriptors()`
### getSourceOptionDescriptors()
`protected OptionDescriptors getSourceOptionDescriptors()`. Since 25.0. Returns a set of source option descriptors that are supported by this language. Option values are accessible using the `environment` or using a `parsing request` when the source is parsed. Languages must always return the same option descriptors independent of the language instance or side-effects. See also: `For an example of declaring the option descriptor using an annotation.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getSourceOptionDescriptors()`
### patchContext(C, TruffleLanguage.Env)
`protected boolean patchContext(C context, TruffleLanguage.Env newEnv)`. Since 0.31. Notifies the language with pre-initialized context about `Env` change. See [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) for information how to enable the Context pre-initialization. During the pre-initialization (in the native compilation time) the `createContext(com.oracle.truffle.api.TruffleLanguage.Env)` and `initializeContext(java.lang.Object)` methods are called. In the image execution time, the `patchContext(java.lang.Object, com.oracle.truffle.api.TruffleLanguage.Env)` is called on all languages whose contexts were created during the pre-initialization a consequence of [`org.graalvm.polyglot.Context.create(java.lang.String...)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#create%28java.lang.String...%29) invocation. The contexts are patched in a topological order starting from dependent languages. If the `patchContext(java.lang.Object, com.oracle.truffle.api.TruffleLanguage.Env)` is successful for all pre-initialized languages the pre-initialized context is used, otherwise a new context is created. Typical implementation looks like: Parameters: `context` `C`: the context created by `createContext(com.oracle.truffle.api.TruffleLanguage.Env)` during pre-initialization. `newEnv` `TruffleLanguage.Env`: the new environment replacing the environment used in pre-initialization phase. Returns `boolean`: true in case of successful environment update. When the context cannot be updated to a new environment return false to create a new context. By default it returns `false` to prevent an usage of pre-initialized context by a language which is not aware of context pre-initialization. Cite: `com/oracle/truffle/api/TruffleLanguage.html#patchContext(C,com.oracle.truffle.api.TruffleLanguage.Env)`
```java
@Override
protected boolean patchContext(Context context, Env newEnv) {
if (!optionsAllowPreInitializedContext(context, newEnv)) {
// Incompatible options - cannot use pre-initialized context
return false;
}
context.env = newEnv;
context.args = newEnv.getApplicationArguments();
context.in = newEnv.in();
context.out = newEnv.out();
context.err = newEnv.err();
return true;
}
private boolean optionsAllowPreInitializedContext(Context context, Env newEnv) {
// Verify that values of important options in the new Env do not differ
// from values in the pre-initialized context
final String newVersionValue = newEnv.getOptions().get(version);
return Objects.equals(context.languageVersion, newVersionValue);
}
```
### isThreadAccessAllowed(Thread, boolean)
`protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded)`. Since 0.28. Returns `true` if code of this language is allowed to be executed on this thread. The method returns `false` to deny execution on this thread. The default implementation denies access to more than one thread at the same time. The [`current thread`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#currentThread%28%29) may differ from the passed thread. If this method throws an `com.oracle.truffle.api.exception.AbstractTruffleException` the exception interop messages may be executed without a context being entered. **Example multi-threaded language implementation:**. Parameters: `thread` `Thread`: the thread that accesses the context for the first time. `singleThreaded` `boolean`: `true` if the access is considered single-threaded, `false` if more than one thread is active at the same time. Cite: `com/oracle/truffle/api/TruffleLanguage.html#isThreadAccessAllowed(java.lang.Thread,boolean)`
```java
class MultiThreadedLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected boolean isThreadAccessAllowed(Thread thread,
boolean singleThreaded) {
// allow access from any thread instead of just one
return true;
}
@Override
protected void initializeMultiThreading(Context context) {
// perform actions when the context is switched to multi-threading
context.singleThreaded.invalidate();
}
@Override
protected void initializeThread(Context context, Thread thread) {
// perform initialization actions for threads
}
@Override
protected void disposeThread(Context context, Thread thread) {
// perform disposal actions for threads
}
}
```
### initializeMultiThreading(C)
`protected void initializeMultiThreading(C context)`. Since 0.28. Invoked before the context is accessed from multiple threads at the same time. This allows languages to perform actions that are required to support multi-threading. It will never be invoked if `isThreadAccessAllowed(Thread, boolean)` is implemented to deny access from multiple threads at the same time. All initialized languages must allow multi-threading for this method to be invoked. If this method throws an `com.oracle.truffle.api.exception.AbstractTruffleException` the exception interop messages may be executed without a context being entered. **Example multi-threaded language implementation:**. Parameters: `context` `C`: the context that should be prepared for multi-threading. Cite: `com/oracle/truffle/api/TruffleLanguage.html#initializeMultiThreading(C)`
```java
class MultiThreadedLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected boolean isThreadAccessAllowed(Thread thread,
boolean singleThreaded) {
// allow access from any thread instead of just one
return true;
}
@Override
protected void initializeMultiThreading(Context context) {
// perform actions when the context is switched to multi-threading
context.singleThreaded.invalidate();
}
@Override
protected void initializeThread(Context context, Thread thread) {
// perform initialization actions for threads
}
@Override
protected void disposeThread(Context context, Thread thread) {
// perform disposal actions for threads
}
}
```
### initializeThread(C, Thread)
`protected void initializeThread(C context, Thread thread)`. Since 0.28. Invoked before a context is accessed from a new thread. This allows the language to perform initialization actions for each thread before guest language code is executed. Also for languages that deny access from multiple threads at the same time, multiple threads may be initialized if they are used sequentially. This method will be invoked before the context is `initialized` for the thread the context will be initialized with. If the thread is stored in the context it must be referenced using [`WeakReference`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ref/WeakReference.html) to avoid leaking thread objects. The [`current thread`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#currentThread%28%29) is equal to the initialized thread. If this method throws an `com.oracle.truffle.api.exception.AbstractTruffleException` the exception interop messages may be executed without a context being entered. **Example multi-threaded language implementation:**. Parameters: `context` `C`: the context that is entered. `thread` `Thread`: the thread that accesses the context for the first time. Cite: `com/oracle/truffle/api/TruffleLanguage.html#initializeThread(C,java.lang.Thread)`
```java
class MultiThreadedLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected boolean isThreadAccessAllowed(Thread thread,
boolean singleThreaded) {
// allow access from any thread instead of just one
return true;
}
@Override
protected void initializeMultiThreading(Context context) {
// perform actions when the context is switched to multi-threading
context.singleThreaded.invalidate();
}
@Override
protected void initializeThread(Context context, Thread thread) {
// perform initialization actions for threads
}
@Override
protected void disposeThread(Context context, Thread thread) {
// perform disposal actions for threads
}
}
```
### finalizeThread(C, Thread)
`protected void finalizeThread(C context, Thread thread)`. Since 23.1. The behavior of this notification is different for `polyglot threads` and embedder threads. For `polyglot threads` the `finalizeThread` notification is invoked just before the context is left for the last time in the thread, and it is still safe to run guest code unless the context is cancelled or hard-exited. This allows the language to perform finalization actions for each thread and context. Polyglot threads are finalized before or while the context is finalized and it always holds that `thread == Thread.currentThread()`. Embedder threads are finalized after the context is finalized, but before it is disposed. `thread == Thread.currentThread()` holds only for the embedder thread that performed the context finalization. Finalization of other embedder threads is invoked in the context finalization thread as well, and so `thread != Thread.currentThread()`. It is still safe to run guest code in `finalizeThread` for an embedder thread unless the context is cancelled or hard-exited, but it is not allowed to initialize new language contexts or create polyglot threads. A language context initialization or creation of a polyglot thread in `finalizeThread` for an embedder thread results in [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html). Please note that embedder threads may be collected by the garbage collector before they can be finalized and may therefore not be finalized. Thread finalization is invoked before `thread disposal`. See also: `For usage details.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#finalizeThread(C,java.lang.Thread)`
### disposeThread(C, Thread)
`protected void disposeThread(C context, Thread thread)`. Since 0.28. Invoked the last time code will be executed for this thread and context. This allows the language to perform cleanup actions for each thread and context. Threads might be disposed before after or while a context is disposed. The [`current thread`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#currentThread%28%29) may differ from the disposed thread. Disposal of threads is only guaranteed for threads that were created by guest languages, so called `polyglot threads`. Other threads, created by the embedder, may be collected by the garbage collector before they can be disposed and may therefore not be disposed. See also: `For usage details.`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#disposeThread(C,java.lang.Thread)`
### getScope(C)
`protected Object getScope(C context)`. Since 20.3. Get a top scope of the language, if any. The returned object must be an `interop scope object` and may have `parent scopes`. The scope object exposes all top scopes variables as flattened `members`. Top scopes are independent of a `Frame`. See `com.oracle.truffle.api.interop.InteropLibrary.isScope(Object)` for details. The returned scope objects may be cached by the caller per language context. Therefore the method should always return equivalent top-scopes and variables objects for a given language context. Changes to the top scope by executing guest language code should be reflected by cached scope instances. It is recommended to store the top-scope directly in the language context for efficient access. Interpretation In most languages, just evaluating an expression like `Math` is equivalent of a lookup with the identifier 'Math' in the top-most scopes of the language. Looking up the identifier 'Math' should have equivalent semantics as reading with the key 'Math' from the variables object of one of the top-most scopes of the language. In addition languages may optionally allow modification and insertion with the variables object of the returned top-scopes. Languages may want to specify multiple parent top-scopes. It is recommended to stay as close as possible to the set of top-scopes that as is described in the guest language specification, if available. For example, in JavaScript, there is a 'global environment' and a 'global object' scope. While the global environment scope contains class declarations and is not insertable, the global object scope is used to insert new global variable values and is therefore insertable. Use Cases Top scopes are accessible to instruments with `com.oracle.truffle.api.instrumentation.TruffleInstrument.Env.getScope(LanguageInfo)`. They are used by debuggers to access the top-most scopes of the language.; Top scopes available in the [`polyglot API`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/package-summary.html) as context [`bindings`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#getBindings%28java.lang.String%29) object. Access to members of the bindings object is applied to the returned scope object via interop.; Languages may expose other language scopes using a polyglot bindings builtin. E.g with `com.oracle.truffle.api.TruffleLanguage.Env.getScopePublic(LanguageInfo)`. Parameters: `context` `C`: the context to find the language top scope in. Returns `Object`: the scope object or `null` if the language does not support such concept. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getScope(C)`
### isVisible(C, Object)
`protected boolean isVisible(C context, Object value)`. Since 0.22. Decides whether the result of evaluating an interactive source should be printed to stdout. By default this methods returns `true` claiming all values are visible. This method affects behavior of [`org.graalvm.polyglot.Context.eval(org.graalvm.polyglot.Source)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#eval%28org.graalvm.polyglot.Source%29) - when evaluating an `interactive source` the result of the evaluation is tested for `visibility` and if the value is found visible, it gets converted to string and printed to [`standard output`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#out%28java.io.OutputStream%29). A language can control whether a value is or isn't printed by overriding this method and returning `false` for some or all values. In such case it is up to the language itself to use the `Env.out()`, `Env.err()` and `Env.in()` streams of the environment. When evaluation is called with an `interactive source` of a language that controls its interactive behavior, it is the responsibility of the language itself to print the result to use the `Env.out()`, `Env.err()` and `Env.in()` streams of the environment. Parameters: `context` `C`: the execution context for doing the conversion. `value` `Object`: the value to check. Either primitive type or `com.oracle.truffle.api.interop.TruffleObject`. Returns `boolean`: `true` if the language implements an interactive response to evaluation of interactive sources. Cite: `com/oracle/truffle/api/TruffleLanguage.html#isVisible(C,java.lang.Object)`
### getLanguageView(C, Object)
`protected Object getLanguageView(C context, Object value)`. Since 20.1. Wraps the value to provide language-specific information for primitive and foreign values. Foreign values should be enhanced to look like the most generic object type of the language. The wrapper needs to introduce any "virtual" methods and properties that are commonly used in language constructs and in algorithms that are written to work on this generic object type. The wrapper may add or remove existing interop traits, but it is not allowed to change the `interop type`. For example, it is not allowed to change the type from number to string. If the behavior of an existing trait is modified then all writes on the mapper need to be forwarded to the underlying object, apart from the virtual members. Writes to the virtual members should be persisted in the wrapper if this is the behavior of the object type that is being mapped to. Every language view wrapper must return the current language as their associated `language`. An [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) is thrown when a language view is requested if this contract is violated. Example modifications language view wrappers may perform: Provide a language specific `display string` for primitive and foreign values.; Return a language specific `metaobject` for primitive or foreign values.; Add virtual members to the object for the view. For example, any JavaScript object is expected to have an implicit \_\_proto\_\_ member. Foreign objects, even if they do not have such a member, are interpreted as if they have.; There are languages where all scalar values are also vectors. In such a case the array element trait may be added using the language wrapper to such values. The default implementation returns `null`. If `null` is returned then the default language view will be used. The default language view wraps the value and returns the current language as their associated language. With the default view wrapper all interop library messages will be forwarded to the delegate value. This following example shows a simplified language view. For a full implementation including an example of metaobjects can be found in the Truffle examples language "SimpleLanguage". Parameters: `context` `C`: the current context. `value` `Object`: the value. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getLanguageView(C,java.lang.Object)`
```java
@ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate")
final class ExampleLanguageView implements TruffleObject {
protected final Object delegate;
ExampleLanguageView(Object delegate) {
this.delegate = delegate;
}
@ExportMessage
boolean hasLanguageId() {
return true;
}
@ExportMessage
String getLanguageId() {
return MyLanguage.ID;
}
@ExportMessage
Object toDisplayString(boolean allowSideEffects,
@CachedLibrary("this.delegate") InteropLibrary dLib) {
try {
if (dLib.isString(this.delegate)) {
return dLib.asString(this.delegate);
} else if (dLib.isBoolean(this.delegate)) {
return dLib.asBoolean(this.delegate) ? "TRUE" : "FALSE";
} else if (dLib.fitsInLong(this.delegate)) {
return longToString(dLib.asLong(this.delegate));
} else {
// full list truncated for this language
return "Unsupported value";
}
} catch (UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
throw new AssertionError(e);
}
}
@TruffleBoundary
private static String longToString(long value) {
return String.valueOf(value);
}
@ExportMessage
boolean hasMetaObject(@CachedLibrary("this.delegate") InteropLibrary dLib) {
return dLib.isString(this.delegate)//
|| dLib.fitsInLong(this.delegate)//
|| dLib.isBoolean(this.delegate);
}
@ExportMessage
Object getMetaObject(@CachedLibrary("this.delegate") InteropLibrary dLib)
throws UnsupportedMessageException {
if (dLib.isString(this.delegate)) {
return MyMetaObject.PRIMITIVE_STRING;
} else if (dLib.isBoolean(this.delegate)) {
return MyMetaObject.PRIMITIVE_LONG;
} else if (dLib.fitsInLong(this.delegate)) {
return MyMetaObject.PRIMITIVE_BOOLEAN;
} else {
// no associable metaobject
throw UnsupportedMessageException.create();
}
}
}
```
### createContextLocal(TruffleLanguage.ContextLocalFactory)
`@Deprecated protected final ContextLocal createContextLocal(TruffleLanguage.ContextLocalFactory factory)`. Since 20.3. Deprecated. in 23.1, use `TruffleLanguage.ContextLocalProvider.createContextLocal(TruffleLanguage.ContextLocalFactory)` instead. Creates a new context local reference for this Truffle language. Starting with JDK 21, using this method leads to a this-escape warning. Use `TruffleLanguage.ContextLocalProvider.createContextLocal(TruffleLanguage.ContextLocalFactory)` instead. Cite: `com/oracle/truffle/api/TruffleLanguage.html#createContextLocal(com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory)`
### createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)
`@Deprecated protected final ContextThreadLocal createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory factory)`. Since 20.3. Deprecated. in 23.1, use `TruffleLanguage.ContextLocalProvider.createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)` instead. Creates a new context thread local reference for this Truffle language. Starting with JDK 21, using this method leads to a this-escape warning. Use `TruffleLanguage.ContextLocalProvider.createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)` instead. Cite: `com/oracle/truffle/api/TruffleLanguage.html#createContextThreadLocal(com.oracle.truffle.api.TruffleLanguage.ContextThreadLocalFactory)`
### getLanguageHome()
`protected final String getLanguageHome()`. Since 19.0. Returns the home location for this language or `null` if the language home is not set. Languages consumed from the Maven repository typically don't have a language home. For legacy graalvm or standalone builds the language home corresponds to the directory in which the Jar file is located, if run from a Jar file. For an AOT compiled binary, this corresponds to the location of the language files in the default GraalVM distribution layout. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getLanguageHome()`
### getAsynchronousStackDepth()
`protected final int getAsynchronousStackDepth()`. Since 20.1.0. Get the depth of asynchronous stack. When zero, the language should not sacrifice performance to be able to provide asynchronous stack. When the depth is non-zero, the language should provide asynchronous stack up to that depth. The language may provide more asynchronous frames than this depth if it's of no performance penalty, or if requested by other (e.g. language-specific) options. The returned depth may change at any time. Override `RootNode.findAsynchronousFrames(Frame)` to provide the asynchronous stack frames. See also: `RootNode.findAsynchronousFrames(Frame)`. Cite: `com/oracle/truffle/api/TruffleLanguage.html#getAsynchronousStackDepth()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ TruffleLanguage.ContextLocalFactory
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 20.3. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
@FunctionalInterface
protected interface TruffleLanguage.ContextLocalFactory
```
Context local factory for Truffle languages. Creates a new value per context.
## Methods
### create(C)
`T create(C context)`. Since 20.3. Returns a new value for a context local of a language. The returned value must not be `null` and must return a stable and exact type per registered language. A thread local must always return the same [`class`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), even for multiple instances of the same `TruffleLanguage`. If this method throws an `com.oracle.truffle.api.exception.AbstractTruffleException` the exception interop messages may be executed without a context being entered. See also: `TruffleLanguage.ContextLocalProvider.createContextLocal(TruffleLanguage.ContextLocalFactory)`. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextLocalFactory.html#create(C)`
# ◆ TruffleLanguage.ContextLocalProvider
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.1. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
protected static final class TruffleLanguage.ContextLocalProvider
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ContextLocalProvider`
Provider for creating context local and context thread local references.
**See also**
- [`TruffleLanguage.locals`](com/oracle/truffle/api/TruffleLanguage.md#locals)
- [`TruffleLanguage.ContextLocalProvider.createContextLocal(TruffleLanguage.ContextLocalFactory)`](com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.md#createContextLocal%28com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory%29)
- [`TruffleLanguage.ContextLocalProvider.createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)`](com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.md#createContextThreadLocal%28com.oracle.truffle.api.TruffleLanguage.ContextThreadLocalFactory%29)
## Methods
### createContextLocal(TruffleLanguage.ContextLocalFactory)
`public ContextLocal createContextLocal(TruffleLanguage.ContextLocalFactory factory)`. Since 23.1. Creates a new context local reference for this Truffle language. Context locals for languages allow to store additional top-level values for each context besides the language context. The advantage of context locals compared to storing the value in a field of the language context is that reading a context local requires one indirection less. It is recommended to use context locals for languages only if the read is critical for performance. Context local references must be created during the invocation in the `TruffleLanguage` constructor. Calling this method at a later point in time will throw an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html). For each registered `TruffleLanguage` subclass it is required to always produce the same number of context local references. The values produced by the factory must not be `null` and use a stable exact value type for each instance of a registered language class. If the return value of the factory is not stable or `null` then an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. These restrictions allow the Truffle runtime to read the value more efficiently. Usage example: Cite: `com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.html#createContextLocal(com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory)`
```java
@TruffleLanguage.Registration(id = "example", name = "ExampleLanguage")
public final class ExampleLanguage extends TruffleLanguage {
final ContextLocal contextLocal = locals.createContextLocal(ExampleLocal::new);
@Override
protected Env createContext(Env env) {
return env;
}
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return new RootNode(this) {
@Override
public Object execute(VirtualFrame frame) {
// fast read
ExampleLocal local = contextLocal.get();
// access local
return "";
}
}.getCallTarget();
}
static final class ExampleLocal {
final Env env;
ExampleLocal(Env env) {
this.env = env;
}
}
}
```
### createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)
`public ContextThreadLocal createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory factory)`. Since 23.1. Creates a new context thread local reference for this Truffle language. Context threadlocals for languages allow storing additional top-level values for each context and thread. The factory may be invoked on any thread other than the thread of the context thread local value. Context thread local references must be created during the invocation in the `TruffleLanguage` constructor. Calling this method at a later point in time will throw an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html). For each registered `TruffleLanguage` subclass it is required to always produce the same number of context thread local references. The values produced by the factory must not be `null` and use a stable exact value type for each instance of a registered language class. If the return value of the factory is not stable or `null` then an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. These restrictions allow the Truffle runtime to read the value more efficiently. Context thread locals should not contain a strong reference to the provided thread. Use a weak reference instance for that purpose. Usage example: Cite: `com/oracle/truffle/api/TruffleLanguage.ContextLocalProvider.html#createContextThreadLocal(com.oracle.truffle.api.TruffleLanguage.ContextThreadLocalFactory)`
```java
@TruffleLanguage.Registration(id = "example", name = "ExampleLanguage")
public static class ExampleLanguage extends TruffleLanguage {
final ContextThreadLocal threadLocal = locals.createContextThreadLocal(ExampleLocal::new);
@Override
protected Env createContext(Env env) {
return env;
}
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return new RootNode(this) {
@Override
public Object execute(VirtualFrame frame) {
// fast read
ExampleLocal local = threadLocal.get();
// access local
return "";
}
}.getCallTarget();
}
static final class ExampleLocal {
final Env env;
final WeakReference thread;
ExampleLocal(Env env, Thread thread) {
this.env = env;
this.thread = new WeakReference<>(thread);
}
}
}
```
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ≡ TruffleLanguage.ContextPolicy
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Enum class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public enum TruffleLanguage.ContextPolicy
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html) > `ContextPolicy`
Defines the supported policy for reusing [`languages`](com/oracle/truffle/api/TruffleLanguage.md) per context. I.e. the policy specifies the degree of sharing that is allowed between multiple language contexts. The default policy is [`exclusive`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#EXCLUSIVE). Every language is encouraged to try to support a context policy that is as permissive as possible, where [`exclusive`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#EXCLUSIVE) is the least and [`shared`](com/oracle/truffle/api/TruffleLanguage.ContextPolicy.md#SHARED) is the most permissive policy. [`Parse caching`](com/oracle/truffle/api/TruffleLanguage.md#parse%28com.oracle.truffle.api.TruffleLanguage.ParsingRequest%29) is scoped per [`language`](com/oracle/truffle/api/TruffleLanguage.md) instance, therefore the context policy influences its behavior.
If multiple sharable languages are used at the same time, nodes of sharable languages may adopt nodes of a non-sharable languages indirectly, e.g. through Truffle interoperability. This would complicate language implementations as they would always need to support sharing for their nodes. To avoid this problem, Truffle uses sharing layers. Sharing layers ensure that every node created by a language instance can only be observed by a single language instance at a time. Sharing layers operate on the principle that all languages share the code with the same language instance or no language shares. As a convenient consequence any call to [`LanguageReference.get(Node)`](com/oracle/truffle/api/TruffleLanguage.LanguageReference.md#get%28com.oracle.truffle.api.nodes.Node%29) with an adopted [`Node`](com/oracle/truffle/api/nodes/Node.md) can fold to a constant during partial evaluation.
For any sharing to take place a context must be created with sharing enabled. By default sharing is disabled for polyglot contexts. Sharing can be enabled by specifying an [`explicit engine`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#engine%28org.graalvm.polyglot.Engine%29) or using an option. Before any language is used for sharing [`TruffleLanguage.initializeMultipleContexts()`](com/oracle/truffle/api/TruffleLanguage.md#initializeMultipleContexts%28%29) is invoked. It is guaranteed that sharing between multiple contexts is [`initialized`](com/oracle/truffle/api/TruffleLanguage.md#initializeMultipleContexts%28%29) before any language context is [`created`](com/oracle/truffle/api/TruffleLanguage.md#createContext%28com.oracle.truffle.api.TruffleLanguage.Env%29).
**See also**
- [`To configure context policy for a language.`](com/oracle/truffle/api/TruffleLanguage.Registration.md#contextPolicy%28%29)
- [`TruffleLanguage.parse(ParsingRequest)`](com/oracle/truffle/api/TruffleLanguage.md#parse%28com.oracle.truffle.api.TruffleLanguage.ParsingRequest%29)
- [`TruffleLanguage.initializeMultipleContexts()`](com/oracle/truffle/api/TruffleLanguage.md#initializeMultipleContexts%28%29)
## Enum constants
### EXCLUSIVE
`EXCLUSIVE`. Since 19.0. Use one exclusive `TruffleLanguage` instance per language context instance. Using this policy has the following implications: `Parse caching` is scoped per `language` instance. This means the language context instance may be directly stored in instance fields of AST nodes without the use of `ContextReference`. The use of `ContextReference` is still recommended to simplify migration to more permissive policies.; If the language does not allow `multi-threading` (default behavior) then the language instance is guaranteed to be used from one thread at a time only. Cached ASTs will not be used from multiple threads at the same time.; `TruffleLanguage.initializeMultipleContexts()` is guaranteed to never be invoked. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextPolicy.html#EXCLUSIVE`
### REUSE
`REUSE`. Since 19.0. Use a single `TruffleLanguage` instance per context instance, but allow the reuse of a language instance when a context was `disposed`. This policy is useful when parsed ASTs should be shared, but multiple thread execution of the AST is not yet supported by the language. Using this policy has the following implications: `Parse caching` is scoped per `language` instance. This means language context instances must NOT be directly stored in instance fields of AST nodes and the `ContextReference` must be used instead.; If the language does not `allow` access from multiple threads (default behavior) then the language instance is guaranteed to be used from one thread at a time only. In this case also cached ASTs will not be used from multiple threads at the same time. If the language allows access from multiple threads then also ASTs may be used from multiple threads at the same time.; `TruffleLanguage.initializeMultipleContexts()` will be invoked to notify the language that multiple contexts will be used with one language instance.; `Language` instance fields must only be used for data that can be shared across multiple contexts. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextPolicy.html#REUSE`
### SHARED
`SHARED`. Since 19.0. Use one `TruffleLanguage` instance for many language context instances. Using this policy has the following implications: `Parse caching` is scoped per `language` instance. With multiple language instances per context, context instances must *not* be directly stored in instance fields of AST nodes and the `ContextReference` must be used instead.; All methods of the `language` instance and parsed ASTs may be called from multiple threads at the same time independent of whether multiple thread access is `allowed` for the language.; `TruffleLanguage.initializeMultipleContexts()` will be invoked to notify the language that multiple contexts will be used with one language instance.; `Language` instance fields must only be used for data that can be shared across multiple contexts and mutable data held by the language instance must be synchronized to support concurrent access. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextPolicy.html#SHARED`
## Methods
### values()
`public static TruffleLanguage.ContextPolicy[] values()`. Returns the enum constants in declaration order. Returns `TruffleLanguage.ContextPolicy[]`: Returns the enum constants in declaration order. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextPolicy.html#values()`
### valueOf(String)
`public static TruffleLanguage.ContextPolicy valueOf(String name)`. Returns the enum constant with the given name. Parameters: `name` `String`: The exact name of the enum constant. Returns `TruffleLanguage.ContextPolicy`: Returns the enum constant with the given name. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextPolicy.html#valueOf(java.lang.String)`
## Inherited members
- From class [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#clone%28%29), [`compareTo`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#compareTo%28E%29), [`describeConstable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#describeConstable%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#finalize%28%29), [`getDeclaringClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#getDeclaringClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#hashCode%28%29), [`name`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#name%28%29), [`ordinal`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#ordinal%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#toString%28%29), [`valueOf`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleLanguage.ContextReference
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.25 revised in 21.3. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public abstract static class TruffleLanguage.ContextReference
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ContextReference`
Represents a reference to the current context. The current context is a thread local value that changes when polyglot context is entered or left. Context references are created using [`create(Class)`](com/oracle/truffle/api/TruffleLanguage.ContextReference.md#create%28java.lang.Class%29) and are intended to be stored in static final fields and accessed at runtime using [`ContextReference.get(Node)`](com/oracle/truffle/api/TruffleLanguage.ContextReference.md#get%28com.oracle.truffle.api.nodes.Node%29) with the current [`Node`](com/oracle/truffle/api/nodes/Node.md), if available, as parameter.
Example intended usage:
```java
public final class MyContext {
private static final ContextReference REFERENCE =
ContextReference.create(MyLanguage.class);
public static MyContext get(Node node) {
return REFERENCE.get(node);
}
}
@Registration(...)
public final class MyLanguage extends TruffleLanguage {
// ...
private static final LanguageReference REFERENCE =
LanguageReference.create(MyLanguage.class);
public static MyLanguage get(Node node) {
return REFERENCE.get(node);
}
}
public final class MyLanguageNode extends Node {
// ...
public Object execute(VirtualFrame frame) {
MyContext currentContext = getContext();
MyLanguage currentLanguage = getLanguage();
// use context or language on the fast-path
// references can also be used behind the boundary
exampleBoundary();
}
@TruffleBoundary
public void exampleBoundary() {
MyLanguage currentLanguage = MyLanguage.get(null);
MyContext currentContext = MyContext.get(null);
// use context or language on the slow-path
}
public final MyLanguage getLanguage() {
return MyLanguage.get(this);
}
public final MyContext getContext() {
return MyContext.get(this);
}
}
```
## Constructors
### ContextReference()
`protected ContextReference()`. Since 19.0. Constructors for subclasses. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextReference.html#()`
## Methods
### get(Node)
`public abstract C get(Node node)`. Since 21.3. Returns the current language context associated with the current thread. An enclosing node should be provided as parameter if available, otherwise `null` may be provided. This method is designed to be called safely from compiled code paths. In order to maximize efficiency in compiled code paths, a partial evaluation constant and adopted node should be passed as parameter. If this is the case then the return context will get constant folded in compiled code paths if there is only a single context instance for the enclosing engine or lookup location/node. The current context might vary between `executions` if resources or code is `shared` between multiple contexts or when used as part of an InteropLibrary export. It is recommended to \*not\* cache values of the context in the AST to reduce footprint. Getting it through a context reference will either constant fold or be very efficient in compiled code paths. If a context is accessed during `context creation`, on an unknown Thread, or in the language class constructor an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. See also: `for a full usage example`. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextReference.html#get(com.oracle.truffle.api.nodes.Node)`
### create(Class)
`public static , C> TruffleLanguage.ContextReference create(Class languageClass)`. Since 21.3. Creates a new instance of a context reference for an registered language. Throws [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) if the provided language class is not `registered`. Guaranteed to always return the same context reference for a given language class. See `ContextReference` for a usage example. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextReference.html#create(java.lang.Class)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ TruffleLanguage.ContextThreadLocalFactory
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 20.3. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
@FunctionalInterface
protected interface TruffleLanguage.ContextThreadLocalFactory
```
Context thread local factory for Truffle languages. Creates a new value per context and thread.
## Methods
### create(C, Thread)
`T create(C context, Thread thread)`. Since 20.3. Returns a new value for a context thread local for a language context and thread. The returned value must not be `null` and must return a stable and exact type per TruffleLanguage subclass. A thread local must always return the same [`class`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), even for multiple instances of the same `TruffleLanguage`. If this method throws an `com.oracle.truffle.api.exception.AbstractTruffleException` the exception interop messages may be executed without a context being entered. See also: `TruffleLanguage.ContextLocalProvider.createContextThreadLocal(TruffleLanguage.ContextThreadLocalFactory)`. Cite: `com/oracle/truffle/api/TruffleLanguage.ContextThreadLocalFactory.html#create(C,java.lang.Thread)`
# ◆ TruffleLanguage.Env
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public static final class TruffleLanguage.Env
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Env`
Represents execution environment of the [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md). Each active [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) receives instance of the environment before any code is executed upon it. The environment has knowledge of all active languages and can exchange symbols between them.
## Methods
### getOptions()
`public OptionValues getOptions()`. Since 0.27. Returns option values for the options described in `TruffleLanguage.getOptionDescriptors()`. The returned options are never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getOptions()`
### getApplicationArguments()
`public String[] getApplicationArguments()`. Since 0.27. Returns the application arguments that were provided for this context. The arguments array and its elements are never `null`. It is up to the language implementation whether and how they are accessible within the guest language scripts. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getApplicationArguments()`
### isCreateThreadAllowed()
`public boolean isCreateThreadAllowed()`. Since 0.28. Returns `true` if the creation of new threads is allowed in the current environment. See also: `newTruffleThreadBuilder(Runnable)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isCreateThreadAllowed()`
### createThread(Runnable)
`@Deprecated public Thread createThread(Runnable runnable)`. Since 0.28. Deprecated. Use `newTruffleThreadBuilder(Runnable)` instead. Creates a new thread that has access to the current language context. See `createThread(Runnable, TruffleContext, ThreadGroup, long)` for a detailed description of the parameters. The `group` is null and `stackSize` set to 0. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createThread(java.lang.Runnable)`
### createThread(Runnable, TruffleContext)
`@Deprecated public Thread createThread(Runnable runnable, TruffleContext context)`. Since 0.28. Deprecated. Use `newTruffleThreadBuilder(Runnable)` instead. Creates a new thread that has access to the given context. See `createThread(Runnable, TruffleContext, ThreadGroup, long)` for a detailed description of the parameters. The `group` is null and `stackSize` set to 0. See also: `getContext()`, `newInnerContextBuilder(String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createThread(java.lang.Runnable,com.oracle.truffle.api.TruffleContext)`
### createThread(Runnable, TruffleContext, ThreadGroup)
`@Deprecated public Thread createThread(Runnable runnable, TruffleContext context, ThreadGroup group)`. Since 0.28. Deprecated. Use `newTruffleThreadBuilder(Runnable)` instead. Creates a new thread that has access to the given context. See `createThread(Runnable, TruffleContext, ThreadGroup, long)` for a detailed description of the parameters. The `stackSize` set to 0. See also: `getContext()`, `newInnerContextBuilder(String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createThread(java.lang.Runnable,com.oracle.truffle.api.TruffleContext,java.lang.ThreadGroup)`
### createThread(Runnable, TruffleContext, …)
`@Deprecated public Thread createThread(Runnable runnable, TruffleContext context, ThreadGroup group, long stackSize)`. Since 0.28. Deprecated. Use `newTruffleThreadBuilder(Runnable)` instead. Creates a new thread that has access to the given context. A thread is `initialized` when it is [`started`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#start%28%29) and `disposed` as soon as the thread finished the execution. It is recommended to set an [`uncaught exception handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#setUncaughtExceptionHandler%28java.lang.Thread.UncaughtExceptionHandler%29) for the created thread. For example the thread can throw an uncaught exception if one of the initialized language contexts don't support execution on this thread. The language that created and started the thread is responsible to stop and join it during the `finalizeContext`, otherwise an [`AssertionError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AssertionError.html) is thrown. It's not safe to use the [`ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/ExecutorService.html#awaitTermination%28long,java.util.concurrent.TimeUnit%29) to detect Thread termination as the polyglot thread may be cancelled before executing the executor worker. A typical implementation looks like: The `TruffleContext` can be either an inner context created by `newInnerContextBuilder(String...)`.`build()`, or the context associated with this environment obtained from `getContext()`. Parameters: `runnable` `Runnable`: the runnable to run on this thread. `context` `TruffleContext`: the context to enter and leave when the thread is started. `group` `ThreadGroup`: the thread group, passed on to the underlying [`Thread`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html). `stackSize` `long`: the desired stack size for the new thread, or zero if this parameter is to be ignored. Throws: `IllegalStateException` (unchecked): if thread creation is not `allowed`. See also: `getContext()`, `newInnerContextBuilder(String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createThread(java.lang.Runnable,com.oracle.truffle.api.TruffleContext,java.lang.ThreadGroup,long)`
```java
class AsyncThreadLanguage extends TruffleLanguage {
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected boolean isThreadAccessAllowed(Thread thread,
boolean singleThreaded) {
// allow access from any thread instead of just one
return true;
}
@Override
protected void initializeContext(Context context) throws Exception {
// create and start a Thread for the asynchronous task
// remeber the Thread reference to stop and join it in
// the finalizeContext
Thread t = context.env.newTruffleThreadBuilder(new Runnable() {
@Override
public void run() {
// asynchronous task
}
}).build();
context.startedThreads.add(t);
t.start();
}
@Override
protected void finalizeContext(Context context) {
// stop and join all the created Threads
boolean interrupted = false;
for (int i = 0; i < context.startedThreads.size();) {
Thread threadToJoin = context.startedThreads.get(i);
try {
if (threadToJoin != Thread.currentThread()) {
threadToJoin.interrupt();
threadToJoin.join();
}
i++;
} catch (InterruptedException ie) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
```
### newTruffleThreadBuilder(Runnable)
`public TruffleThreadBuilder newTruffleThreadBuilder(Runnable runnable)`. Since 23.0. Creates a builder for threads that have access to the given context. Parameters: `runnable` `Runnable`: the runnable to run on the threads created by the builder. Returns `TruffleThreadBuilder`: the builder for threads that have access to the given context. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#newTruffleThreadBuilder(java.lang.Runnable)`
### createSystemThread(Runnable)
`public Thread createSystemThread(Runnable runnable)`. Since 22.3. Creates a new thread designed to process language internal tasks in the background. See `createSystemThread(Runnable, ThreadGroup)` for a detailed description of the parameters. See also: `createSystemThread(Runnable, ThreadGroup)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createSystemThread(java.lang.Runnable)`
### createSystemThread(Runnable, ThreadGroup)
`public Thread createSystemThread(Runnable runnable, ThreadGroup threadGroup)`. Since 22.3. Creates a new thread designed to process language internal tasks in the background. The created thread cannot enter the context, if it tries an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. Creating or terminating a system thread does not notify `languages` or instruments' thread-listeners. Creating a system thread does not cause a transition to multi-threaded access. The `creation permit` is not required to create a system thread. The caller must be either entered in a context, or in another system thread to create a new system thread. If not an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. It is recommended to set an [`uncaught exception handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html#setUncaughtExceptionHandler%28java.lang.Thread.UncaughtExceptionHandler%29) for the created thread. For example the thread can throw an uncaught exception if the context is closed before the thread is started. The language that created and started the thread is responsible to stop and join it during the `TruffleLanguage.disposeContext(Object)` disposeContext}, otherwise an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. It's not safe to use the [`ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/ExecutorService.html#awaitTermination%28long,java.util.concurrent.TimeUnit%29) to detect Thread termination as the system thread may be cancelled before executing the executor worker. A typical implementation looks like: Parameters: `runnable` `Runnable`: the runnable to run on this thread. `threadGroup` `ThreadGroup`: the thread group, passed on to the underlying [`Thread`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Thread.html). Throws: `IllegalStateException` (unchecked): if the context is already closed. See also: `createSystemThread(Runnable)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createSystemThread(java.lang.Runnable,java.lang.ThreadGroup)`
```java
class SystemThreadLanguage extends
TruffleLanguage {
static class Context {
private final BlockingQueue tasks;
private final Env env;
private volatile Thread systemThread;
private volatile boolean cancelled;
Context(Env env) {
this.tasks = new LinkedBlockingQueue<>();
this.env = env;
}
}
@Override
protected Context createContext(Env env) {
return new Context(env);
}
@Override
protected void initializeContext(Context context) {
// Create and start a Thread for the asynchronous internal task.
// Remember the Thread to stop and join it in the disposeContext.
context.systemThread = context.env.createSystemThread(() -> {
while (!context.cancelled) {
try {
Runnable task = context.tasks.
poll(Integer.MAX_VALUE, SECONDS);
if (task != null) {
task.run();
}
} catch (InterruptedException ie) {
// pass to cancelled check
}
}
});
context.systemThread.start();
}
@Override
protected void disposeContext(Context context) {
// Stop and join system thread.
context.cancelled = true;
Thread threadToJoin = context.systemThread;
if (threadToJoin != null) {
threadToJoin.interrupt();
boolean interrupted = false;
boolean terminated = false;
while (!terminated) {
try {
threadToJoin.join();
terminated = true;
} catch (InterruptedException ie) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
}
```
### newInnerContextBuilder(String...)
`public TruffleContext.Builder newInnerContextBuilder(String... permittedLanguages)`. Since 22.3. Returns a new context builder useful to create inner context instances. By default the inner context inherits none of the access privileges. To inherit access set `TruffleContext.Builder.inheritAllAccess(boolean)` to `true`. No language context will be initialized by default in the inner context. In order to initialize the creator context use `TruffleContext.Builder.initializeCreatorContext(boolean)`, initialize the language after context creation using `TruffleContext.initializePublic(Node, String)` or evaluate a source using `TruffleContext.evalPublic(Node, Source)`. Parameters: `permittedLanguages` `String...`: ids of languages permitted in the context. If no languages are provided, then all languages permitted to the outer context will be permitted. Languages are validated when the context is [`built`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#build%28%29). An [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) will be thrown if an unknown or a language denied by the engine was used. See also: `for details on language inner contexts.`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#newInnerContextBuilder(java.lang.String...)`
### getPolyglotBindings()
`public Object getPolyglotBindings()`. Since 0.32. Returns a TruffleObject that represents the polyglot bindings. The polyglot bindings consists of a set of symbols that have been exported explicitly by the languages or the embedder. This set of symbols allows for data exchange between polyglot languages. The polyglot bindings is separate from language bindings. The symbols can by read using string identifiers, a list of symbols may be requested with the keys message. Existing identifiers are removable, modifiable, readable and any new identifiers are insertable. Throws: `SecurityException` (unchecked): if polyglot access is not enabled. See also: `isPolyglotBindingsAccessAllowed()`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getPolyglotBindings()`
### importSymbol(String)
`public Object importSymbol(String symbolName)`. Since 0.8 or earlier. Explicitly imports a symbol from the polyglot bindings. The behavior of this method is equivalent to sending a READ message to the `polyglot bindings` object. Reading a symbol that does not exist will return `null`. The returned symbol value can either be a `TruffleObject` (e.g. a native object from the other language) to support interoperability between languages, [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) or one of the Java primitive wrappers ( [`Integer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Integer.html), [`Double`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Double.html), [`Byte`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Byte.html), [`Boolean`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Boolean.html), etc.). Polyglot symbols can only be imported if the `polyglot bindings access` is allowed. Parameters: `symbolName` `String`: the name of the symbol to search for. Returns `Object`: object representing the symbol or `null` if it does not exist. Throws: `SecurityException` (unchecked): if importing polyglot symbols is not allowed. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#importSymbol(java.lang.String)`
### exportSymbol(String, Object)
`public void exportSymbol(String symbolName, Object value)`. Since 0.27. Explicitly exports a symbol to the polyglot bindings object. The behavior of this method is equivalent to sending a WRITE message to the `polyglot bindings` object. Exporting a symbol with a `null` value will remove the symbol from the polyglot object. The exported symbol value can either be a `TruffleObject` (e.g. a native object from the other language) to support interoperability between languages, [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) or one of the Java primitive wrappers ( [`Integer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Integer.html), [`Double`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Double.html), [`Byte`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Byte.html), [`Boolean`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Boolean.html), etc.). Polyglot symbols can only be export if the `polyglot bindings access` is allowed. Parameters: `symbolName` `String`: the name with which the symbol should be exported into the polyglot scope. `value` `Object`: the value to export for. Throws: `SecurityException` (unchecked): if exporting polyglot symbols is not allowed. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#exportSymbol(java.lang.String,java.lang.Object)`
### isHostLookupAllowed()
`public boolean isHostLookupAllowed()`. Since 0.27. Returns `true` if host access is generally allowed. If this method returns `false` then `lookupHostSymbol(String)` will always fail. Host lookup is generally disallowed if the embedder provided a null [`host class filter`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowHostClassLookup%28java.util.function.Predicate%29). Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isHostLookupAllowed()`
### addToHostClassPath(TruffleFile)
`public void addToHostClassPath(TruffleFile entry)`. Since 19.0. Adds an entry to the Java host class loader. All classes looked up with `lookupHostSymbol(String)` will lookup classes with this new entry. If the entry was already added then calling this method again for the same entry has no effect. Given entry must not be `null`. Note that classes added by this method are in the unnamed module. Throws: `SecurityException` (unchecked): if the file is not `readable`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#addToHostClassPath(com.oracle.truffle.api.TruffleFile)`
### lookupHostSymbol(String)
`public Object lookupHostSymbol(String symbolName)`. Since 0.27. Looks up a Java class in the top-most scope the host environment. Throws an error if no symbol was found or the symbol was not accessible. Symbols might not be accessible if a [`host class filter`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowHostClassLookup%28java.util.function.Predicate%29) prevents access. The returned object is always a `TruffleObject` that represents the class symbol. Parameters: `symbolName` `String`: the qualified class name in the host language. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#lookupHostSymbol(java.lang.String)`
### isHostObject(Object)
`@Deprecated(since = "25.1") public boolean isHostObject(Object value)`. Since 19.0. Deprecated since 25.1. Use isHostObject. Returns `true` if the argument is Java host language object wrapped using Truffle interop. See also: `asHostObject(Object)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isHostObject(java.lang.Object)`
### asHostObject(Object)
`@Deprecated(since = "25.1") public Object asHostObject(Object value)`. Since 19.0. Deprecated since 25.1. Use asHostObject. Returns the java host representation of a Truffle guest object if it represents a Java host language object. Throws [`ClassCastException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ClassCastException.html) if the provided argument is not a `host object`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#asHostObject(java.lang.Object)`
### asGuestValue(Object)
`public Object asGuestValue(Object hostObject)`. Since 19.0. Converts an existing Java host object to a guest language value. If the value is already an interop value, then no conversion will be performed. Otherwise, the returned wraps the host object and provides support for the interop contract to access the java members. The interpretation of converted objects is described in [`Context.asValue(Object)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#asValue%28java.lang.Object%29). This method should be used exclusively to convert already allocated Java objects to a guest language representation. To allocate new host objects users should use `lookupHostSymbol(String)` to lookup the class and then send a NEW interop message to that object to instantiate it. This method does not respect configured [`class filters`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowHostClassLookup%28java.util.function.Predicate%29). Parameters: `hostObject` `Object`: the host object to convert. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#asGuestValue(java.lang.Object)`
### asBoxedGuestValue(Object)
`public Object asBoxedGuestValue(Object guestObject)`. Since 19.0. Wraps primitive interop values in a TruffleObject exposing their methods as members. By default, primitive host values are not wrapped in TruffleObjects to expose their members. This method is intended for compatibility with existing Java interop APIs that expect such behavior. This method boxes the following primitive interop values: [`Boolean`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Boolean.html), [`Byte`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Byte.html), [`Short`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Short.html), [`Integer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Integer.html), [`Long`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Long.html), [`Float`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Float.html), [`Double`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Double.html) , [`Character`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Character.html), [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html). If the provided value is already boxed then the current value will be returned. If the provided value is not an interop value then an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) will be thrown. Parameters: `guestObject` `Object`: the primitive guest value to box. Throws: `IllegalArgumentException` (unchecked): if value is an invalid interop value. See also: `asGuestValue(Object)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#asBoxedGuestValue(java.lang.Object)`
### isHostFunction(Object)
`@Deprecated(since = "25.1") public boolean isHostFunction(Object value)`. Since 19.0. Deprecated since 25.1. Use `interopLibrary.isHostObject(obj) && interopLibrary.isExecutable(obj) && !interopLibrary.hasMembers(obj)`. Returns `true` if the argument is a Java host language function wrapped using Truffle interop. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isHostFunction(java.lang.Object)`
### findMetaObject(Object)
`public Object findMetaObject(Object value)`. Since 19.0. Find a metaobject of a value, if any. The metaobject represents a description of the object, reveals it's kind and it's features. Some information that a metaobject might define includes the base object's type, interface, class, methods, attributes, etc. When no metaobject is known, returns `null`. The metaobject is an interop value. An interop value can be either a `TruffleObject` (e.g. a native object from the other language) to support interoperability between languages or a [`String`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html). Parameters: `value` `Object`: the value to find the meta object for. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#findMetaObject(java.lang.Object)`
### isHostException(Throwable)
`@Deprecated(since = "25.1") public boolean isHostException(Throwable exception)`. Since 19.0. Deprecated since 25.1. Use `interopLibrary.isHostObject(obj) && interopLibrary.isException(obj)`. Tests whether an exception is a host exception thrown by a Java Interop method invocation. Host exceptions may be thrown by interoperability messages. The host exception may be unwrapped using `asHostException(Throwable)`. Parameters: `exception` `Throwable`: the [`Throwable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Throwable.html) to test. Returns `boolean`: `true` if the `exception` is a host exception, `false` otherwise. See also: `asHostException(Throwable)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isHostException(java.lang.Throwable)`
### asHostException(Throwable)
`@Deprecated(since = "25.1") public Throwable asHostException(Throwable exception)`. Since 19.0. Deprecated since 25.1. Use asHostObject. Unwraps a host exception thrown by a Java method invocation. Host exceptions may be thrown by interoperability messages. The host exception may be unwrapped using `asHostException(Throwable)`. Parameters: `exception` `Throwable`: the host exception to unwrap. Returns `Throwable`: the original Java exception. Throws: `IllegalArgumentException` (unchecked): if the `exception` is not a host exception. See also: `isHostException(Throwable)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#asHostException(java.lang.Throwable)`
### isHostSymbol(Object)
`@Deprecated(since = "25.1") public boolean isHostSymbol(Object guestObject)`. Since 19.0. Deprecated since 25.1. Use `interopLibrary.isHostObject(obj) && interopLibrary.isScope(obj)`. Returns `true` if the argument is a host symbol, representing the constructor and static members of a Java class, as obtained by e.g. `lookupHostSymbol`. See also: `lookupHostSymbol(String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isHostSymbol(java.lang.Object)`
### asHostSymbol(Class)
`public Object asHostSymbol(Class> symbolClass)`. Since 19.0. Converts a Java class to a host symbol as if by `lookupHostSymbol(symbolClass.getName())` but without an actual lookup. Must not be used with Truffle or guest language classes. See also: `lookupHostSymbol(String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#asHostSymbol(java.lang.Class)`
### isInnerContextOptionsAllowed()
`public boolean isInnerContextOptionsAllowed()`. Since 22.3. Returns `true` if context options are allowed to be modified for inner contexts, or `false` if not. This method only indicates whether the embedder granted wildcard all access for new privileges using [`org.graalvm.polyglot.Context.Builder.allowInnerContextOptions(boolean)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowInnerContextOptions%28boolean%29). This method is useful to find out whether it is possible to specify options for inner contexts using `TruffleContext.Builder.option(String, String)`, as options can only be specified with all access enabled. See also: `TruffleContext.Builder.option(String, String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isInnerContextOptionsAllowed()`
### isFileIOAllowed()
`public boolean isFileIOAllowed()`. Since 23.0. Returns `true` if access to files is allowed, else `false`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isFileIOAllowed()`
### isSocketIOAllowed()
`public boolean isSocketIOAllowed()`. Since 23.0. Returns `true` if access to network sockets is allowed, else `false`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isSocketIOAllowed()`
### isNativeAccessAllowed()
`public boolean isNativeAccessAllowed()`. Since 19.0. Returns `true` if access to native code is generally allowed. If this method returns `false` then loading native libraries with the Truffle NFI will fail. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isNativeAccessAllowed()`
### isPolyglotEvalAllowed()
`@Deprecated public boolean isPolyglotEvalAllowed()`. Since 19.2. Deprecated. in 24.1 use `isPolyglotEvalAllowed(null) instead`. Note that language implementations should now check whether polyglot eval is allowed also for individual languages, as access could be denied only for an individual language. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isPolyglotEvalAllowed()`
### isPolyglotEvalAllowed(LanguageInfo)
`public boolean isPolyglotEvalAllowed(LanguageInfo targetLanguage)`. Since 24.1. Returns `true` if the current language is allowed to evaluate guest application provided code of the given language, else `false`. If this method returns `true` then the current language has permission to use `parsePublic(Source, String...)` and `getScopePublic(LanguageInfo)` for the given language. If the given language is `null` then this method will return `true` if polyglot access is allowed in principle, else `false`. Languages may want to call this method twice. Once with `null` to determine whether polyglot eval and scope based builtins should be available to the application at all and once with the concrete language just before the access. The result of this method is safe to be cached per language context, it is guaranteed to not change for a context and target language combination. See also: [`Embedders can restrict polyglot eval access between certain languages.`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/PolyglotAccess.Builder.html#allowEval%28java.lang.String,java.lang.String%29), `parsePublic(Source, String...)`, `getScopePublic(LanguageInfo)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isPolyglotEvalAllowed(com.oracle.truffle.api.nodes.LanguageInfo)`
### isPolyglotBindingsAccessAllowed()
`public boolean isPolyglotBindingsAccessAllowed()`. Since 19.2. Returns `true` if polyglot bindings access is allowed, else `false` . Guest languages should hide or disable all polyglot bindings builtins if this flag is set to `false`. If polyglot bindings access is disabled then `getPolyglotBindings()`, `importSymbol(String)` or `exportSymbol(String, Object)` fails with a SecurityException. See also: [`org.graalvm.polyglot.Context.Builder.allowPolyglotAccess(org.graalvm.polyglot.PolyglotAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowPolyglotAccess%28org.graalvm.polyglot.PolyglotAccess%29). Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isPolyglotBindingsAccessAllowed()`
### isMimeTypeSupported(String)
`public boolean isMimeTypeSupported(String mimeType)`. Since 0.11. Allows it to be determined if this [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) can execute code written in a language with a given MIME type. Returns `boolean`: a boolean that indicates if the MIME type is supported. See also: `Source.getMimeType()`, `parsePublic(Source, String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isMimeTypeSupported(java.lang.String)`
### parseInternal(Source, String...)
`public CallTarget parseInternal(Source source, String... argumentNames)`. Since 19.2. Parses the source of a public or internal language and returns the parse result as `CallTarget`. The `language id` is used to identify the `TruffleLanguage` to use to perform the `parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)`. The names of arguments are parameters for the resulting {#link CallTarget} that allow the `source` to reference the actual parameters passed to `CallTarget.call(java.lang.Object...)`. The suffix `internal` in the method name indicates that the result of this method is **not** safe to exposed to arbitrary guest code, by default. Use `parsePublic(Source, String...)` for that purpose instead. Compared to `parsePublic(Source, String...)` this method provides also access to `internal` and dependent languages in addition to public languages. For example, in JavaScript, a call to the eval builtin should forward to `parsePublic(Source, String...)` as it contains code provided by the guest language user. Parsing regular expressions with the internal regular expression engine should call `parseInternal(Source, String...)` instead, as this is considered an implementation detail of the language. It is recommended that the language uses `Env.parsePublic(Source, String...)` or `Env.parseInternal(Source, String...)` instead of directly passing the Source to the parser, in order to support code caching with `ContextPolicy.SHARED` and `ContextPolicy.REUSE`. Parameters: `source` `Source`: the source to evaluate. `argumentNames` `String...`: the names of `CallTarget.call(java.lang.Object...)` arguments that can be referenced from the source. Returns `CallTarget`: the call target representing the parsed result. Throws: `IllegalStateException` (unchecked): if polyglot context associated with this environment is not entered, or if the language is neither a `public language` nor an `internal language`. `IllegalArgumentException` (unchecked): if the language is not allowed to evaluate code by the current language. See also: `parsePublic(Source, String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#parseInternal(com.oracle.truffle.api.source.Source,java.lang.String...)`
### parsePublic(Source, String...)
`public CallTarget parsePublic(Source source, String... argumentNames)`. Since 19.2. Parses the source of a public language and returns the parse result as `CallTarget` . The `language id` is used to identify the `TruffleLanguage` to use to perform the `parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)`. The names of arguments are parameters for the resulting {#link CallTarget} that allow the `source` to reference the actual parameters passed to `CallTarget.call(java.lang.Object...)`. The suffix `public` in the method name indicates that the result of this method is safe to be exposed by default to guest applications. Public languages are configured by the embedder to be accessible to the guest language program. For example, in JavaScript, a call to the eval builtin should forward to `parsePublic(Source, String...)` as it contains code provided by the guest language user. Parsing regular expressions with the internal regular expression engine should call `parseInternal(Source, String...)` instead, as this is considered an implementation detail of the language. It is recommended that the language uses `Env.parsePublic(Source, String...)` or `Env.parseInternal(Source, String...)` instead of directly passing the Source to the parser, in order to support code caching with `ContextPolicy.SHARED` and `ContextPolicy.REUSE`. Languages should check for `eval permissions` for each `public language` prior to calling this method, otherwise [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) is thrown if not sufficient privileges are available. Parameters: `source` `Source`: the source to evaluate. `argumentNames` `String...`: the names of `CallTarget.call(java.lang.Object...)` arguments that can be referenced from the source. Returns `CallTarget`: the call target representing the parsed result. Throws: `IllegalStateException` (unchecked): if polyglot context associated with this environment is not entered, or if the language is not a `public language`. `IllegalArgumentException` (unchecked): if the language is not allowed to evaluate code by the current language. See also: `parseInternal(Source, String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#parsePublic(com.oracle.truffle.api.source.Source,java.lang.String...)`
### in()
`public InputStream in()`. Since 0.8 or earlier. Input stream provided by [`org.graalvm.polyglot.Context.Builder.in(InputStream)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#in%28java.io.InputStream%29) this language is being executed in. Returns `InputStream`: reader, never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#in()`
### out()
`public OutputStream out()`. Since 0.8 or earlier. Standard output writer provided by [`org.graalvm.polyglot.Context.Builder.out(OutputStream)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#out%28java.io.OutputStream%29) this language is being executed in. Returns `OutputStream`: writer, never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#out()`
### err()
`public OutputStream err()`. Since 0.8 or earlier. Standard error writer provided by [`org.graalvm.polyglot.Context.Builder.err(OutputStream)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#err%28java.io.OutputStream%29) this language is being executed in. Returns `OutputStream`: writer, never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#err()`
### lookup(Class)
`public T lookup(Class type)`. Since 0.12. Looks additional service up. An environment for a particular `language` may also be associated with additional services. One can request implementations of such services by calling this method with the type identifying the requested service and its API. Services that can be obtained via this method include `com.oracle.truffle.api.instrumentation.Instrumenter` and others. Type parameters: ``: type of requested service. Parameters: `type` `Class`: class of requested service. Returns `T`: instance of T or `null` if there is no such service available. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#lookup(java.lang.Class)`
### lookup(InstrumentInfo, Class)
`public S lookup(InstrumentInfo instrument, Class type)`. Since 0.26. Returns an additional service provided by this instrument, specified by type. If an instrument is not enabled, it will be enabled automatically by requesting a supported service. If the instrument does not provide a service for a given type it will not be enabled automatically. Type parameters: ``: the requested type. Parameters: `instrument` `InstrumentInfo`: identification of the instrument to query. `type` `Class`: the class of the requested type. Returns `S`: the registered service or `null` if none is found. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#lookup(com.oracle.truffle.api.InstrumentInfo,java.lang.Class)`
### lookup(LanguageInfo, Class)
`public S lookup(LanguageInfo language, Class type)`. Since 19.0 supports services registered by registerService. Returns an additional service provided by the given language, specified by type. For services registered by `Registration.services()` the service lookup will ensure that the language is loaded and services are registered. The provided langauge and type must not be `null`. Type parameters: ``: the requested type. Parameters: `language` `LanguageInfo`: the language to query. `type` `Class`: the class of the requested type. Returns `S`: the registered service or `null` if none is found. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#lookup(com.oracle.truffle.api.nodes.LanguageInfo,java.lang.Class)`
### initializeLanguage(LanguageInfo)
`public boolean initializeLanguage(LanguageInfo targetLanguage)`. Since 20.1.0. Ensures that the target language is initialized. This method firstly verifies that the target language is accessible from this language. If not the [`SecurityException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/SecurityException.html) is thrown. Then the target language initialization is performed if not already done. Parameters: `targetLanguage` `LanguageInfo`: the language to initialize. Throws: `SecurityException` (unchecked): if an access to `targetLanguage` is not permitted. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#initializeLanguage(com.oracle.truffle.api.nodes.LanguageInfo)`
### getInternalLanguages()
`public Map getInternalLanguages()`. Since 19.2. Returns all languages that are installed and internally accessible in the environment. Using the language instance additional services can be `looked up`. `parseInternal(Source, String...)` is allowed for all languages returned by this method. This list of languages should not be exposed to guest language programs, as it lists internal languages. See also: `lookup(LanguageInfo, Class)`, `parseInternal(Source, String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInternalLanguages()`
### getHostLanguage()
`public LanguageInfo getHostLanguage()`. Since 24.2. Retrieves the host language used in this environment. The returned language can be used to obtain the host language top scope object using `getScopeInternal(LanguageInfo)` method. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getHostLanguage()`
### getPublicLanguages()
`public Map getPublicLanguages()`. Since 19.2. Returns all languages that are installed and publicly accessible in the environment. Using the language instance additional services can be `looked up`. `parsePublic(Source, String...)` is allowed for all languages returned by this method. This list of languages may be exposed ot the guest language program. See also: `parsePublic(Source, String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getPublicLanguages()`
### getLanguageInfo(Class)
`public LanguageInfo getLanguageInfo(Class extends TruffleLanguage>> languageClass)`. Since 24.2. Returns the `language info` for a given language class if available. The class may be obtained with `InteropLibrary.getLanguage(Object)`. Throws an [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) if the provided language is not registered. Parameters: `languageClass` `Class extends TruffleLanguage>>`: the language class to convert. Returns `LanguageInfo`: the associated language info. Throws: `IllegalArgumentException` (unchecked): if the language class is not valid. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getLanguageInfo(java.lang.Class)`
### getInstruments()
`public Map getInstruments()`. Since 0.26. Returns a map instrument-id to instrument instance of all instruments that are installed in the environment. Using the instrument instance additional services can be `looked up` . Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInstruments()`
### getTimeZone()
`public ZoneId getTimeZone()`. Since 19.2. Returns the default time zone of this environment. If the time-zone was not explicitly set by the embedder, UTC is returned with [`SandboxPolicy.CONSTRAINED`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html#CONSTRAINED) or stricter sandbox policies, and the [`system default`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/time/ZoneId.html#systemDefault%28%29) time-zone is returned otherwise. See also: [`ZoneId.systemDefault()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/time/ZoneId.html#systemDefault%28%29). Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getTimeZone()`
### getConfig()
`public Map getConfig()`. Since 0.11. Configuration arguments passed from an outer language context to an inner language context. Inner language contexts can be created using `newInnerContextBuilder(String...)`. See also: `to create inner contexts.`, `to pass configuration objects to the inner context.`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getConfig()`
### getContext()
`public TruffleContext getContext()`. Since 0.30. Returns the polyglot context associated with this environment. Returns `TruffleContext`: the polyglot context. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getContext()`
### isPreInitialization()
`public boolean isPreInitialization()`. Since 19.0. Returns `true` if this [`org.graalvm.polyglot.Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) is being pre-initialized. For a given `environment`, the return value of this method never changes. See also: `initializeContext(Object)`, `patchContext(Object, Env)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isPreInitialization()`
### getPublicTruffleFile(String)
`public TruffleFile getPublicTruffleFile(String path)`. Since 19.3.0. Returns a `TruffleFile` for given path. The returned `TruffleFile` access depends on the file system used by the context and can vary from all access in case of [`allowed IO`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/IOAccess.html#ALL) to no access in case of [`denied IO`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/IOAccess.html#NONE). When IO is not enabled by the `Context` the `TruffleFile` operations throw [`SecurityException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/SecurityException.html). The `getPublicTruffleFile` method should be used to access user files or to implement language IO builtins. Parameters: `path` `String`: the absolute or relative path to create `TruffleFile` for. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) supports only [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). `IllegalArgumentException` (unchecked): if the `path` string cannot be converted to a [`Path`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/Path.html). See also: [`IOAccess`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/IOAccess.html), [`Builder.allowIO(IOAccess)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#allowIO%28org.graalvm.polyglot.io.IOAccess%29). Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getPublicTruffleFile(java.lang.String)`
### getPublicTruffleFile(URI)
`public TruffleFile getPublicTruffleFile(URI uri)`. Since 19.3.0. Returns a `TruffleFile` for given path. See `getPublicTruffleFile(String)` for detailed information. Parameters: `uri` `URI`: the [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) to create `TruffleFile` for. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) scheme is not supported. `IllegalArgumentException` (unchecked): if preconditions on the `uri` do not hold. `FileSystemNotFoundException` (unchecked): is the file system, identified by the `uri`, does not exist and cannot be created automatically. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getPublicTruffleFile(java.net.URI)`
### getInternalTruffleFile(String)
`public TruffleFile getInternalTruffleFile(String path)`. Since 19.3.0. Returns a `TruffleFile` for the given path. This method allows access to a language's internal resources even if file system privileges might be limited or denied. If the path locates a file under an internal resource root or under a guest language home, it is guaranteed that the returned `TruffleFile` has at least read access. Otherwise, the returned `TruffleFile` access depends on the file system used by the context and can vary from all access in case of allowed IO to no access in case of denied IO. This method should be used to read language-provided files, such as language standard libraries. This method is equivalent to `getTruffleFileInternal(path, p -> true)`. If a language should only use a subset of the language's internal resources, consider using `getTruffleFileInternal(String, Predicate)` and perform that language-specific restriction using a predicate. Parameters: `path` `String`: the absolute or relative path to create `TruffleFile` for. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) supports only [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). `IllegalArgumentException` (unchecked): if the `path` string cannot be converted to a [`Path`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/Path.html). See also: `getTruffleFileInternal(String, Predicate)`, `getPublicTruffleFile(java.lang.String)`, `getInternalResource(String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInternalTruffleFile(java.lang.String)`
### getInternalTruffleFile(URI)
`public TruffleFile getInternalTruffleFile(URI uri)`. Since 19.3.0. Returns `TruffleFile` for given [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). See `getInternalTruffleFile(String)` for detailed information. Parameters: `uri` `URI`: the [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) to create `TruffleFile` for. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) scheme is not supported. `IllegalArgumentException` (unchecked): if preconditions on the `uri` do not hold. `FileSystemNotFoundException` (unchecked): is the file system, identified by the `uri`, does not exist and cannot be created automatically. See also: `getTruffleFileInternal(URI, Predicate)`, `getPublicTruffleFile(java.net.URI)`, `getInternalResource(String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInternalTruffleFile(java.net.URI)`
### getTruffleFileInternal(String, Predicate)
`public TruffleFile getTruffleFileInternal(String path, Predicate filter)`. Since 21.1.0. Returns a `TruffleFile` for the given path. This method allows access to a language's internal resources even if file system privileges might be limited or denied. If the path locates a file under an internal resource root or under a guest language home, and the file satisfies the given `filter`, it is guaranteed that the returned `TruffleFile` has at least read access. Otherwise, the returned `TruffleFile` access depends on the file system used by the context and can vary from all access in case of allowed IO to no access in case of denied IO. A common use case for this method is a filter granting read access to the language standard libraries. The method performs the following checks: If the IO is enabled by the [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) an accessible `TruffleFile` is returned without any other checks.; If the given path does not locate a file in an internal resource root or a guest language home, a `TruffleFile` with no access is returned.; If the given filter accepts the file a readable `TruffleFile` is returned. Otherwise, a `TruffleFile` with no access is returned. The relation to `getPublicTruffleFile(String)` and `getInternalTruffleFile(String)` is: The `getPublicTruffleFile(String)` is equivalent to `getTruffleFileInternal(path, p -> false)`.; The `getInternalTruffleFile(String)` is equivalent to `getTruffleFileInternal(path, p -> true)`. Parameters: `path` `String`: the absolute or relative path to create `TruffleFile` for. `filter` `Predicate`: to enable read access to `TruffleFile`. Multiple invocations of `filter.test(file)` must consistently return `true` or consistently return `false` for a given path. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) supports only [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). `IllegalArgumentException` (unchecked): if the `path` string cannot be converted to a [`Path`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/Path.html). See also: `getTruffleFileInternal(URI, Predicate)`, `getPublicTruffleFile(String)`, `getInternalTruffleFile(String)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getTruffleFileInternal(java.lang.String,java.util.function.Predicate)`
### getTruffleFileInternal(URI, Predicate)
`public TruffleFile getTruffleFileInternal(URI uri, Predicate filter)`. Since 21.1.0. Returns a `TruffleFile` for given URI. See `getTruffleFileInternal(String, Predicate)` for detailed information. Parameters: `uri` `URI`: the [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html) to create `TruffleFile` for. `filter` `Predicate`: to enable read access to `TruffleFile`. Multiple invocations of `filter.test(file)` must consistently return `true` or consistently return `false` for a given path. Returns `TruffleFile`: `TruffleFile`. Throws: `UnsupportedOperationException` (unchecked): when the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) supports only [`URI`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html). `IllegalArgumentException` (unchecked): if preconditions on the `uri` do not hold. `FileSystemNotFoundException` (unchecked): is the file system, identified by the `uri`, does not exist and cannot be created automatically. See also: `getTruffleFileInternal(String, Predicate)`, `getPublicTruffleFile(URI)`, `getInternalTruffleFile(URI)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getTruffleFileInternal(java.net.URI,java.util.function.Predicate)`
### getCurrentWorkingDirectory()
`public TruffleFile getCurrentWorkingDirectory()`. Since 19.0. Gets the current working directory. The current working directory is used to resolve non absolute paths in `TruffleFile` methods. Returns `TruffleFile`: the current working directory. Throws: `SecurityException` (unchecked): if the [`filesystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denies reading of the current working directory. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getCurrentWorkingDirectory()`
### setCurrentWorkingDirectory(TruffleFile)
`public void setCurrentWorkingDirectory(TruffleFile currentWorkingDirectory)`. Since 19.0. Sets the current working directory. The current working directory is used to resolve non absolute paths in `TruffleFile` methods. Parameters: `currentWorkingDirectory` `TruffleFile`: the new current working directory. Throws: `UnsupportedOperationException` (unchecked): if setting of the current working directory is not supported. `IllegalArgumentException` (unchecked): if the `currentWorkingDirectory` is not a valid current working directory. `SecurityException` (unchecked): if `currentWorkingDirectory` is not readable. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#setCurrentWorkingDirectory(com.oracle.truffle.api.TruffleFile)`
### getFileNameSeparator()
`public String getFileNameSeparator()`. Since 19.0. Returns the name separator used to separate names in `TruffleFile`'s path string. Returns `String`: the name separator. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getFileNameSeparator()`
### getPathSeparator()
`public String getPathSeparator()`. Since 19.1.0. Returns the path separator used to separate filenames in a path list. On UNIX the path separator is `':'`. On Windows it's `';'`. Returns `String`: the path separator. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getPathSeparator()`
### registerService(Object)
`public void registerService(Object service)`. Since 19.0. Registers additional services provided by the language. The registered services are made available to users via `lookup(com.oracle.truffle.api.nodes.LanguageInfo, java.lang.Class)` query method. For each service interface enumerated in `language registration` the language has to register a single service implementation. This method can be called only during the execution of the `createContext method`, then the services are collected and cannot be changed anymore. Parameters: `service` `Object`: a service to be returned from associated `lookup method`. Throws: `IllegalStateException` (unchecked): if the method is called outside of `createContext(com.oracle.truffle.api.TruffleLanguage.Env)` method. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#registerService(java.lang.Object)`
### isCreateProcessAllowed()
`public boolean isCreateProcessAllowed()`. Since 19.1.0. Returns `true` if the creation of a sub-process is allowed in the current environment. See also: `newProcessBuilder(java.lang.String...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#isCreateProcessAllowed()`
### newProcessBuilder(String...)
`public TruffleProcessBuilder newProcessBuilder(String... command)`. Since 19.1.0. Creates a new process builder with the specified operating program and arguments. Parameters: `command` `String...`: the executable and its arguments. Throws: `SecurityException` (unchecked): when process creation is not allowed. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#newProcessBuilder(java.lang.String...)`
### getEnvironment()
`public Map getEnvironment()`. Since 19.1.0. Returns an unmodifiable map of the process environment. When the `Context` is configured with [`EnvironmentAccess.INHERIT`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/EnvironmentAccess.html#INHERIT) it returns the [`System.getenv()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/System.html#getenv%28%29) and the environment variables configured on the `Context`. For the [`EnvironmentAccess.NONE`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/EnvironmentAccess.html#NONE) only the environment variables configured on the `Context` are returned. Returns `Map`: the process environment as a map of variable names to values. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getEnvironment()`
### createTempFile(TruffleFile, String, …)
`public TruffleFile createTempFile(TruffleFile dir, String prefix, String suffix, FileAttribute>... attrs) throws IOException`. Since 19.3.0. Creates a new empty file in the specified or default temporary directory, using the given prefix and suffix to generate its name. This method provides only part of a temporary file facility. To arrange for a file created by this method to be deleted automatically the resulting file must be opened using the [`DELETE_ON_CLOSE`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/StandardOpenOption.html#DELETE_ON_CLOSE) option. In this case the file is deleted when the appropriate `close` method is invoked. Alternatively, a [`shutdown hook`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29) may be used to delete the file automatically. Parameters: `dir` `TruffleFile`: the directory in which the file should be created or `null` for a default temporary directory. `prefix` `String`: the prefix to generate the file's name or `null`. `suffix` `String`: the suffix to generate the file's name or `null` in which case "`.tmp`" is used. `attrs` `FileAttribute>...`: the optional attributes to set atomically when creating the file. Returns `TruffleFile`: the `TruffleFile` representing the newly created file that did not exist before this method was invoked. Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): if the prefix or suffix cannot be used to generate a valid file name. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically or [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) does not support default temporary directory. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createTempFile(com.oracle.truffle.api.TruffleFile,java.lang.String,java.lang.String,java.nio.file.attribute.FileAttribute...)`
### createTempDirectory(TruffleFile, String, FileAttribute...)
`public TruffleFile createTempDirectory(TruffleFile dir, String prefix, FileAttribute>... attrs) throws IOException`. Since 19.3.0. Creates a new directory in the specified or default temporary directory, using the given prefix to generate its name. This method provides only part of a temporary file facility. A [`shutdown hook`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29) may be used to delete the directory automatically. Parameters: `dir` `TruffleFile`: the directory in which the directory should be created or `null` for a default temporary directory. `prefix` `String`: the prefix to generate the directory's name or `null`. `attrs` `FileAttribute>...`: the optional attributes to set atomically when creating the directory. Returns `TruffleFile`: the `TruffleFile` representing the newly created directory that did not exist before this method was invoked. Throws: `IOException`: in case of IO error. `IllegalArgumentException` (unchecked): if the prefix cannot be used to generate a valid file name. `UnsupportedOperationException` (unchecked): if the attributes contain an attribute which cannot be set atomically or [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) does not support default temporary directory. `SecurityException` (unchecked): if the [`FileSystem`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/io/FileSystem.html) denied the operation. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createTempDirectory(com.oracle.truffle.api.TruffleFile,java.lang.String,java.nio.file.attribute.FileAttribute...)`
### createHostAdapter(Object[])
`public Object createHostAdapter(Object[] types)`. Since 22.1. Creates a Java host adapter class that can be instantiated with a guest object (as the last argument) in order to create adapter instances of the provided host types, (non-final) methods of which delegate to the guest object's invocable members. Implementations must be [allowed](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/HostAccess.Builder.html#allowImplementations%28java.lang.Class%29) for these types. The returned host adapter class is an instantiable host object that is also a meta object, so `isMetaInstance` can be used to check if an object is an instance of this adapter class. See usage example below. Please note that only classes from the unnamed module or classes exported to the unnamed module can be used in `types`. The generated host adapter class is also in the unnamed module. A host class is generated as follows: For every protected or public constructor in the extended class, the adapter class will have one public constructor (visibility of protected constructors in the extended class is promoted to public). For every super constructor, a constructor taking a trailing [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html) argument preceded by original constructor's arguments is generated. When such a constructor is invoked, the passed [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html)'s member functions are used to implement and/or override methods on the original class, dispatched by name. A single invocable member will act as the implementation for all overloaded methods of the same name. When methods on an adapter instance are invoked, the functions are invoked having the [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html) passed in the instance constructor as their receiver. Subsequent changes to the members of that [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html) (reassignment or removal of its functions) are reflected in the adapter instance; the method implementations are not bound to functions at constructor invocation time. The generated host class extends all non-final public or protected methods, and forwards their invocations to the guest object provided to the constructor. If the guest object does not contain an invocable member with that name, the super/default method is invoked instead. If the super method is abstract, an [`AbstractMethodError`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/AbstractMethodError.html) is thrown. If the original types collectively have only one abstract method, or have several of them, but all share the same name, the constructor(s) will check if the [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html) is executable, and if so, will use the passed function as the implementation for all abstract methods. For consistency, any concrete methods sharing the single abstract method name will also be overridden by the function. For non-void methods, all the conversions supported by [`Value.as`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html#as%28java.lang.Class%29) will be in effect to coerce the guest methods' return value to the expected Java return type. Instances of the host class have the following additional special members: `super`: provides access to the super methods of the host class via a wrapper object. Can be used to call super methods from guest method overrides.; `this`: returns the original guest object. Direct member operations on an adapter instance for members not provided by the generated host class are delegated to the original guest object. Java host fields and methods, and the special `super` and `this` members, take precedence over same-named guest object members. Example: Parameters: `types` `Object[]`: the types to extend. Must be non-null and contain at least one extensible superclass or interface, and at most one superclass. All types must be public, accessible, and allow implementation. Returns `Object`: a host class that can be instantiated to create instances of a host class that extends all the provided host types. The host class may be cached. Throws: `IllegalArgumentException` (unchecked): if the types are not extensible or more than one superclass is given. `SecurityException` (unchecked): if host access does not allow creating adapter classes for these types. `UnsupportedOperationException` (unchecked): if creating adapter classes is not supported on this runtime at all, which is currently the case for native images. `NullPointerException` (unchecked): if `types` is null. See also: `createHostAdapterWithClassOverrides(Object[], Object)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createHostAdapter(java.lang.Object[])`
```java
Object hostClass = env.createHostAdapter(new Object[]{
env.asHostSymbol(Superclass.class),
env.asHostSymbol(Interface.class)});
// generates a class along the lines of:
public class Adapter extends Superclass implements Interface {
private Value delegate;
public Adapter(Value delegate) { this.delegate = delegate; }
public method(Object... args) {
if (delegate.canInvokeMember("method") {
return delegate.invokeMember("method", args);
} else {
return super.method(args);
}
}
}
// and can be instantiated as follows:
Object instance = InteropLibrary.getUncached().instantiate(hostClass, guestObject);
assert InteropLibrary.getUncached().isMetaInstance(hostClass, instance);
```
### createHostAdapterWithClassOverrides(Object[], Object)
`public Object createHostAdapterWithClassOverrides(Object[] types, Object classOverrides)`. Since 22.1. Like `createHostAdapter(Object[])` but creates a Java host adapter class with class-level overrides, i.e., the guest object provided as `classOverrides` is statically bound to the class rather than instances of the class. Returns a host class that can be instantiated to create instances of the provided host `types`, (non-final) methods of which delegate to the guest object provided as `classOverrides`. Allows creating host adapter class hierarchies, i.e., the returned class can be used as a superclass of other host adapter classes. Note that classes created with method cannot be cached. Therefore, this feature should be used sparingly. See `createHostAdapter(Object[])` for more details. Parameters: `types` `Object[]`: the types to extend. Must be non-null and contain at least one extensible superclass or interface, and at most one superclass. All types must be public, accessible, and allow implementation. `classOverrides` `Object`: a guest object with class-level overrides. If not null, the object is bound to the class, not to any instance. Consequently, the generated constructors are changed to not take an object; all instances will share the same overrides object. Note that since a new class has to be generated for every overrides object instance and cannot be shared, use of this feature is discouraged; it is provided only for compatibility reasons. Returns `Object`: a host class symbol that can be instantiated to create instances of a host class that extends all the provided host types. Throws: `IllegalArgumentException` (unchecked): if the types are not extensible or more than one superclass is given. `SecurityException` (unchecked): if host access does not allow creating adapter classes for these types. `UnsupportedOperationException` (unchecked): if creating adapter classes is not supported on this runtime at all, which is currently the case for native images. `NullPointerException` (unchecked): if either `types` or `classOverrides` is null. See also: `createHostAdapter(Object[])`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#createHostAdapterWithClassOverrides(java.lang.Object[],java.lang.Object)`
### getInternalResource(Class)
`public TruffleFile getInternalResource(Class extends InternalResource> resource) throws IOException`. Since 23.1. Returns the `TruffleFile` representing the target directory of an internal resource. The internal resource is guaranteed to be fully `InternalResource.unpackFiles(InternalResource.Env, Path)` s unpacked} before this method returns. When this method is called for the first time and the resource is not cached than the resource will be unpacked. Unpacking an internal resource can be an expensive operation, but the implementation makes sure that unpacked internal resources are cached. The returned `TruffleFile` will only grant read-only access to the target directory, but access is provided even if IO access is disabled. On a HotSpot VM the internal resource is typically cached in the user directory, so unpacking would be repeated once per operating system user. When the language was compiled using native-image internal resources are unpacked at native-image compile time and stored relative to the native-image. Parameters: `resource` `Class extends InternalResource>`: the resource class to load. Throws: `IllegalArgumentException` (unchecked): if `resource` is not associated with this language. `IOException`: in case of IO error. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInternalResource(java.lang.Class)`
### getInternalResource(String)
`public TruffleFile getInternalResource(String resourceId) throws IOException`. Since 23.1. Returns the `TruffleFile` representing the target directory of an internal resource. Unlike the `getInternalResource(Class)`, this method can be used for optional resources whose classes may not exist at runtime. In this case the optional resource must be unpacked at build time, see [`Engine.copyResources(Path, String...)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Engine.html#copyResources%28java.nio.file.Path,java.lang.String...%29). If the resource with the specified `resourceId` is not associated to this language, the function returns `null`. Parameters: `resourceId` `String`: unique id of the resource to be loaded. Returns `TruffleFile`: internal resource directory or `null` if resource with the `resourceId` is not associated with this language. Throws: `IOException`: in case of IO error. See also: `getInternalResource(Class)`, [`Engine.copyResources(Path, String...)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Engine.html#copyResources%28java.nio.file.Path,java.lang.String...%29). Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getInternalResource(java.lang.String)`
### getLogger(String)
`public TruffleLogger getLogger(String loggerName)`. Since 21.1. Find or create a context-bound logger. The returned `TruffleLogger` always uses a logging handler and options from this execution environment context and does not depend on being entered on any thread. If a logger with a given name already exists it's returned. Otherwise, a new logger is created. Unlike loggers created by `TruffleLogger.getLogger` loggers created by this method are bound to a single context. There may be more logger instances having the same name but each bound to a different context. Languages should never store the returned logger into a static field. If the context policy is more permissive than `ContextPolicy.EXCLUSIVE` the returned logger must not be stored in a TruffleLanguage subclass. It is recommended to create all language loggers in `TruffleLanguage.createContext(Env)`. Parameters: `loggerName` `String`: the name of a `TruffleLogger`, if a `loggerName` is null or empty a root logger for language or instrument is returned. Returns `TruffleLogger`: a `TruffleLogger`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getLogger(java.lang.String)`
### getLogger(Class)
`public TruffleLogger getLogger(Class> forClass)`. Since 21.1. Find or create a context-bound logger. The returned `TruffleLogger` always uses a logging handler and options from this execution environment context and does not depend on being entered on any thread. If a logger with a given name already exists it's returned. Otherwise, a new logger is created. Unlike loggers created by `TruffleLogger.getLogger` loggers created by this method are bound to a single context. There may be more logger instances having the same name but each bound to a different context. Languages should never store the returned logger into a static field. If the context policy is more permissive than `ContextPolicy.EXCLUSIVE` the returned logger must not be stored in a TruffleLanguage subclass. It is recommended to create all language loggers in `TruffleLanguage.createContext(Env)`. Parameters: `forClass` `Class>`: the [`Class`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Class.html) to create a logger for. Returns `TruffleLogger`: a `TruffleLogger`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getLogger(java.lang.Class)`
### submitThreadLocal(Thread[], ThreadLocalAction)
`public Future submitThreadLocal(Thread[] threads, ThreadLocalAction action)`. Since 21.1. Submits a thread local action to be performed at the next guest language safepoint on a provided set of threads, once for each thread. If the threads array is `null` then the thread local action will be performed on all alive threads. The submitted actions are processed in the same order as they are submitted in. The action can be synchronous or asynchronous, side-effecting or non-side-effecting. Please see `ThreadLocalAction` for details. It is ensured that a thread local action will get processed as long as the thread stays active for this context. If a thread becomes inactive before the action can get processed then the action will not be performed for this thread. If a thread becomes active while the action is being processed then the action will be performed for that thread as long as the thread filter includes the thread or `null` was passed. Already started synchronous actions will block on activation of a new thread. If the synchronous action was not yet started on any thread, then the synchronous action will also be performed for the newly activated thread. The method returns a [`Future`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html) instance that allows to wait for the thread local action to complete or to cancel a currently performed event. Example Usage: By default thread-local actions are executed once per configured thread and do not repeat themselves. If a ThreadLocalAction is configured to be `recurring` then the action will automatically be rescheduled in the same configuration until it is [`cancelled`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html#cancel%28boolean%29). For recurring actions, an invocation of [`Future.get()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html#get%28%29) will only wait for the first action to be performed. [`Future.isDone()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html#isDone%28%29) will return `true` only if the action was canceled. Canceling a recurring action will result in the current event being canceled and no further events being submitted. Using recurring events should be preferred over submitting the event again for the current thread while performing the thread-local action as recurring events are also resubmitted in case all threads leave and later reenter. If the thread local action future needs to be waited on and this might be prone to deadlocks the `blocking API` can be used to allow other thread local actions to be processed while the current thread is waiting. The returned [`Future.get()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html#get%28%29) method can be used as `Interruptible`. If the underlying polyglot context is already closed, the method returns a completed [`Future`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Future.html). Parameters: `threads` `Thread[]`: the threads to execute the action on. `null` for all threads. `action` `ThreadLocalAction`: the action to perform on that thread. See also: `ThreadLocalAction`, `TruffleSafepoint`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#submitThreadLocal(java.lang.Thread[],com.oracle.truffle.api.ThreadLocalAction)`
```java
Env env; // supplied
env.submitThreadLocal(null, new ThreadLocalAction(true, true) {
@Override
protected void perform(Access access) {
// perform action
}
});
```
### registerOnDispose(Closeable)
`public void registerOnDispose(Closeable closeable)`. Since 21.2. Registers [`Closeable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/Closeable.html) for automatic close on context dispose. In most cases, closeable should be closed using try-with-resources construct. When a closeable must keep being opened for the lifetime of a context it should be registered using this method for automatic close on context dispose. The registered [`Closeable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/Closeable.html) is weakly referenced. The guest language must strongly reference it otherwise, it may be garbage collected before it's closed. If the registered closeable throws an [`IOException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/IOException.html) during close, the thrown exception does not prevent successful context dispose. The IOException is logged to the engine logger with a [`Level.WARNING`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING) level. Other exceptions are rethrown as internal [`PolyglotException`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/PolyglotException.html). Parameters: `closeable` `Closeable`: to be closed on context dispose. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#registerOnDispose(java.io.Closeable)`
### getSandboxPolicy()
`public SandboxPolicy getSandboxPolicy()`. Since 23.0. Returns the context's [`SandboxPolicy`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html). A language can use the returned sandbox policy to make language-specific verifications that the sandbox requirements are met. These verifications should be made as early as possible in the `TruffleLanguage.createContext(Env)` method. See also: [`SandboxPolicy`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html), `TruffleLanguage.createContext(Env)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getSandboxPolicy()`
### getScopePublic(LanguageInfo)
`public Object getScopePublic(LanguageInfo language) throws IllegalArgumentException`. Since 24.1. Returns the scope object of a non-null `public language`. The returned value follows the contract of `TruffleLanguage.getScope(Object)` of the other language, therefore it must be an `interop scope object` and may have `parent scopes`. The bindings object exposes all top scopes variables as flattened `members`. In addition to being a scope the returned object may implement any number of the `interop traits`. The interop members of the returned object are typically writable, but that is not guaranteed. The suffix `public` in the method name indicates that the result of this method is safe to be exposed by default to guest applications. For example, languages should use this method to implement the semantics of their polyglot bindings builtin, but is not limited to that. All `public` languages with `eval permissions` are accessible. If a language is not accessible then an [`SecurityException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/SecurityException.html) is thrown. The scope of the current language is always accessible, but it is recommended to use a language specific way to access symbols of the current language. Languages should check for `eval permissions` for each `public language` prior to calling this method, otherwise it might cause [`SecurityException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/SecurityException.html) if not sufficient privileges are available. Returns `Object`: the scope, or `null` if the requested language does not support such a concept. Throws: `IllegalStateException` (unchecked): if polyglot context associated with this environment is not entered. `SecurityException` (unchecked): if polyglot scope access is not enabled for this language. See also: `getScopeInternal(LanguageInfo)`, `isPolyglotEvalAllowed(LanguageInfo)`, `getPolyglotBindings()`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getScopePublic(com.oracle.truffle.api.nodes.LanguageInfo)`
### getScopeInternal(LanguageInfo)
`public Object getScopeInternal(LanguageInfo language)`. Since 24.1. Returns the scope object of a non-null `internal language`. Works the same as `getScopePublic(LanguageInfo)` but it also returns scopes of internal and dependent languages. The suffix `internal` in the method name indicates that the result of this method is **not** safe to be exposed to arbitrary guest code, by default. Use `getScopePublic(LanguageInfo)` for that purpose instead. For example, this method could be used to access a fixed set of symbols from the Truffle Native Interface, e.g. to load native language extensions. Languages may decide to expose scopes of internal languages to arbitrary guest code for testing purposes. Make sure this option is disabled by default and enabled using an [`internal`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionCategory.html#INTERNAL) option only. The scope of the current language is always accessible, but it is recommended to use a language specific way to access symbols of the current language. It is recommended to only use this method for `internal` or `dependent languages`. For convenience, this method will also succeed for all accessible `public languages` with `eval permissions`. Returns `Object`: the scope, or `null` if the requested language does not support such a concept. Throws: `IllegalStateException` (unchecked): if polyglot context associated with this environment is not entered. `SecurityException` (unchecked): if polyglot scope access is not enabled for this language. See also: `getScopePublic(LanguageInfo)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Env.html#getScopeInternal(com.oracle.truffle.api.nodes.LanguageInfo)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ≡ TruffleLanguage.ExitMode
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Enum class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 22.0. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public enum TruffleLanguage.ExitMode
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html) > `ExitMode`
Mode of exit operation.
**See also**
- [`exitContext(Object, ExitMode, int)`](com/oracle/truffle/api/TruffleLanguage.md#exitContext%28C,com.oracle.truffle.api.TruffleLanguage.ExitMode,int%29)
## Enum constants
### NATURAL
`NATURAL`. Since 22.0. Natural exit that occurs during normal context close. Cite: `com/oracle/truffle/api/TruffleLanguage.ExitMode.html#NATURAL`
### HARD
`HARD`. Since 22.0. Hard exit triggered by `TruffleContext.closeExited(Node, int)`. Cite: `com/oracle/truffle/api/TruffleLanguage.ExitMode.html#HARD`
## Methods
### values()
`public static TruffleLanguage.ExitMode[] values()`. Returns the enum constants in declaration order. Returns `TruffleLanguage.ExitMode[]`: Returns the enum constants in declaration order. Cite: `com/oracle/truffle/api/TruffleLanguage.ExitMode.html#values()`
### valueOf(String)
`public static TruffleLanguage.ExitMode valueOf(String name)`. Returns the enum constant with the given name. Parameters: `name` `String`: The exact name of the enum constant. Returns `TruffleLanguage.ExitMode`: Returns the enum constant with the given name. Cite: `com/oracle/truffle/api/TruffleLanguage.ExitMode.html#valueOf(java.lang.String)`
## Inherited members
- From class [`Enum`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#clone%28%29), [`compareTo`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#compareTo%28E%29), [`describeConstable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#describeConstable%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#finalize%28%29), [`getDeclaringClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#getDeclaringClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#hashCode%28%29), [`name`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#name%28%29), [`ordinal`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#ordinal%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#toString%28%29), [`valueOf`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleLanguage.InlineParsingRequest
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.31. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public static final class TruffleLanguage.InlineParsingRequest
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `InlineParsingRequest`
Request for inline parsing. Contains information of what to parse and in which context.
## Methods
### getSource()
`public Source getSource()`. Since 0.31. The source code to parse. Returns `Source`: the source code, never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.InlineParsingRequest.html#getSource()`
### getOptionValues()
`public OptionValues getOptionValues()`. Since 25.0. Returns the source option values associated with the parsing request's source and language. This method should be preferred over `Source.getOptions(TruffleLanguage)` when accessing the source options of a source when possible, to avoid parsing the options twice. In order to allow users of the language to specify source options they must be declared by implementing `TruffleLanguage.getSourceOptionDescriptors()`. Cite: `com/oracle/truffle/api/TruffleLanguage.InlineParsingRequest.html#getOptionValues()`
### getLocation()
`public Node getLocation()`. Since 0.31. Specifies the code location for parsing. The location is specified as an instance of a `Node` in the AST. The node can be `com.oracle.truffle.api.instrumentation.EventContext.getInstrumentedNode()`, for example. Returns `Node`: a `Node` defining AST context for the parsing, it's never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.InlineParsingRequest.html#getLocation()`
### getFrame()
`public MaterializedFrame getFrame()`. Since 0.31. Specifies the execution context for parsing. If the parsing request is used for evaluation during halted execution, for example as in `com.oracle.truffle.api.debug.DebugStackFrame.eval(String)` method, this method provides access to current `frame` with local variables, etc. Returns `MaterializedFrame`: a `MaterializedFrame` exposing the current execution state or `null` if there is none. Cite: `com/oracle/truffle/api/TruffleLanguage.InlineParsingRequest.html#getFrame()`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleLanguage.LanguageReference
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.25 revised in 21.3. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public abstract static class TruffleLanguage.LanguageReference
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `LanguageReference`
Represents a reference to the current language instance. The current language is a thread local value that potentially changes when polyglot context is entered or left. Language references are created using [`create(Class)`](com/oracle/truffle/api/TruffleLanguage.LanguageReference.md#create%28java.lang.Class%29) and are intended to be stored in static final fields and accessed at runtime using [`LanguageReference.get(Node)`](com/oracle/truffle/api/TruffleLanguage.LanguageReference.md#get%28com.oracle.truffle.api.nodes.Node%29) with the current [`Node`](com/oracle/truffle/api/nodes/Node.md), if available, as parameter.
Example intended usage:
See [`ContextReference`](com/oracle/truffle/api/TruffleLanguage.ContextReference.md) for a full usage example.
## Constructors
### LanguageReference()
`protected LanguageReference()`. Since 19.0. Constructors for subclasses. Cite: `com/oracle/truffle/api/TruffleLanguage.LanguageReference.html#()`
## Methods
### get(Node)
`public abstract L get(Node node)`. Since 21.3. Returns the current language instance associated with the current thread. An enclosing node should be provided as parameter if available, otherwise `null` may be provided. This method is designed to be called safely from compiled code paths. In order to maximize efficiency in compiled code paths, a partial evaluation constant and adopted node should be passed as parameter. If this is the case then the return language will get constant folded in compiled code paths. The current language is fixed per `RootNode`. It is recommended to \*not\* cache values of the language in the AST to reduce footprint. Getting it through a language reference will either constant fold or be very efficient in compiled code paths. If a language is accessed on an unknown Thread, or in the language class constructor an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) is thrown. See also: `for a full usage example`. Cite: `com/oracle/truffle/api/TruffleLanguage.LanguageReference.html#get(com.oracle.truffle.api.nodes.Node)`
### create(Class)
`public static > TruffleLanguage.LanguageReference create(Class languageClass)`. Since 21.3. Creates a new instance of a langauge reference for an registered language. Throws [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) if the provided language class is not `registered`. Guaranteed to always return the same context reference for a given language class. See `LanguageReference` for a usage example. Cite: `com/oracle/truffle/api/TruffleLanguage.LanguageReference.html#create(java.lang.Class)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◆ TruffleLanguage.ParsingRequest
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.22. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
public static final class TruffleLanguage.ParsingRequest
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `ParsingRequest`
Request for parsing. Contains information of what to parse and in which context.
## Methods
### getSource()
`public Source getSource()`. Since 0.22. The source code to parse. Returns `Source`: the source code, never `null`. Cite: `com/oracle/truffle/api/TruffleLanguage.ParsingRequest.html#getSource()`
### getOptionValues()
`public OptionValues getOptionValues()`. Since 25.0. Returns the source option values associated with the parsing request's source and language. This method should be preferred over `Source.getOptions(TruffleLanguage)` when accessing the source options of a source when possible, to avoid parsing the options twice. In order to allow users of the language to specify source options they must be declared by implementing `TruffleLanguage.getSourceOptionDescriptors()`. Cite: `com/oracle/truffle/api/TruffleLanguage.ParsingRequest.html#getOptionValues()`
### getArgumentNames()
`public List getArgumentNames()`. Since 0.22. Argument names. The result of `parsing` is an instance of `CallTarget` that `can be invoked` without or with some parameters. If the invocation requires some arguments, and the `getSource()` references them, it is essential to name them. Example that uses the argument names: Returns `List`: symbolic names for parameters of `CallTarget.call(java.lang.Object...)`. Cite: `com/oracle/truffle/api/TruffleLanguage.ParsingRequest.html#getArgumentNames()`
```java
public void parseWithParams(Env env) {
Source multiply = Source.newBuilder("js",
"a * b",
"mul.js").build();
CallTarget method = env.parsePublic(multiply, "a", "b");
Number fortyTwo = (Number) method.call(6, 7);
assert 42 == fortyTwo.intValue();
Number ten = (Number) method.call(2, 5);
assert 10 == ten.intValue();
}
```
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# @ TruffleLanguage.Registration
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Annotation interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier. Nested in [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md).
```java
@Retention(RUNTIME)
@Target({TYPE})
public @interface TruffleLanguage.Registration
```
The annotation to use to register your language to the [`Polyglot API`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/package-summary.html). By annotating your implementation of [`TruffleLanguage`](com/oracle/truffle/api/TruffleLanguage.md) by this annotation the language can be discovered on the class path.
## Elements
### id()
`String id() default ""`. Since 0.8 or earlier. Unique id of your language. This id will be exposed to users via the getter. It is used as group identifier for options of the language. Returns `String`: identifier of your language. Default: `""`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#id()`
### name()
`String name() default ""`. Since 0.8 or earlier. Unique name of your language. This name will be exposed to users via the [`org.graalvm.polyglot.Language.getName()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Language.html#getName%28%29) getter. Returns `String`: identifier of your language. Default: `""`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#name()`
### implementationName()
`String implementationName() default ""`. Since 0.8 or earlier. Unique name of your language implementation. Returns `String`: the implementation name of your language. Default: `""`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#implementationName()`
### version()
`String version() default "inherit"`. Since 0.8 or earlier. Unique string identifying the language version. This name will be exposed to users via the [`org.graalvm.polyglot.Language.getVersion()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Language.html#getVersion%28%29) getter. It inherits from [`org.graalvm.polyglot.Engine.getVersion()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Engine.html#getVersion%28%29) by default. Returns `String`: version of your language. Default: `"inherit"`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#version()`
### defaultMimeType()
`String defaultMimeType() default ""`. Since 19.0. Returns the default MIME type of this language. The default MIME type allows embedders and other language or instruments to find out how content is interpreted if no MIME type was specified. The default MIME type must be specified in the list of supported `character` or `byte` based MIME types. The default MIME type is mandatory if more than one supported MIME type was specified. If no default MIME type and no supported MIME types were specified then all sources for this language will be interpreted as `character` based sources. Default: `""`. See also: `LanguageInfo.getDefaultMimeType()`, [`Language.getDefaultMimeType()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Language.html#getDefaultMimeType%28%29), `characterMimeTypes()`, `byteMimeTypes()`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#defaultMimeType()`
### characterMimeTypes()
`String[] characterMimeTypes() default {}`. Since 19.0. List of MIME types supported by this language which sources should be interpreted as `character` based sources. Languages may use MIME types to differentiate supported source kinds. If a MIME type is declared as supported then the language needs to be able to `parse` sources of this kind. If only one supported MIME type was specified by a language then it will be used as `default` MIME type. If no supported character and byte based MIME types are specified then all sources will be interpreted as `character` based. Returns `String[]`: array of MIME types assigned to your language files. Default: `{}`. See also: `defaultMimeType()`, `byteMimeTypes()`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#characterMimeTypes()`
### byteMimeTypes()
`String[] byteMimeTypes() default {}`. Since 19.0. List of MIME types supported by this language which sources should be interpreted as `byte` based sources. Languages may use MIME types to differentiate supported source kinds. If a MIME type is declared as supported, then the language needs to be able to `parse` sources of this kind. If only one supported MIME type was specified by a language then it will be used as `default` MIME type. If no supported character and byte based MIME types are specified then all sources will be interpreted as `character` based. Returns `String[]`: array of MIME types assigned to your language files. Default: `{}`. See also: `defaultMimeType()`, `characterMimeTypes()`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#byteMimeTypes()`
### interactive()
`boolean interactive() default true`. Since 0.22. Specifies if the language is suitable for interactive evaluation of `sources`. `Interactive` languages should be displayed in interactive environments and presented to the user. The default value of this attribute is `true` assuming majority of the languages is interactive. Change the value to `false` to opt-out and turn your language into non-interactive one. Returns `boolean`: `true` if the language should be presented to end-user in an interactive environment. Default: `true`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#interactive()`
### internal()
`boolean internal() default false`. Since 0.27. Returns `true` if this language is intended for internal use only. Internal languages cannot be used in the host environment directly, they can only be used from other languages or from instruments. Default: `false`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#internal()`
### dependentLanguages()
`String[] dependentLanguages() default {}`. Since 0.30. Specifies a list of languages that this language depends on. Languages are referenced using their `id()`. This has the following effects: This language always has access to dependent languages if this language is accessible. Languages may not be accessible if language access is [`restricted`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#create%28java.lang.String...%29).; This language is finalized before dependent language contexts are `finalized`.; This language is disposed before dependent language contexts are `disposed`. `Non-internal` languages implicitly depend on all internal languages. Therefore by default non-internal languages are disposed and finalized before internal languages. Dependent languages should be parsed with `Env.parseInternal(Source, String...)` as the embedder might choose to disable access to it for `Env.parsePublic(Source, String...)`. Dependent languages references are optional. If a dependent language is not installed and the language needs to fail in such a case then the language should fail on `context initialization`. Cycles in dependencies will cause an [`IllegalStateException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalStateException.html) when one of the cyclic languages is [`initialized`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#initialize%28java.lang.String%29). Default: `{}`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#dependentLanguages()`
### contextPolicy()
`TruffleLanguage.ContextPolicy contextPolicy() default EXCLUSIVE`. Since 19.0. Defines the supported policy for reusing `languages` per context. I.e. the policy specifies the degree of sharing that is allowed between multiple language contexts. The default policy is `exclusive`. Every language is encouraged to try to support a context policy that is as permissive as possible, where `exclusive` is the least and `shared` is the most permissive policy. `Parse caching` is scoped per `language` instance, therefore the context policy influences its behavior. The context policy applies to contexts that were created using the [`polyglot API`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html) as well as for `inner contexts`. The context policy does not apply to nodes that were created using the Truffle interop protocol. Therefore, interop message nodes always need to be prepared to be used with policy `ContextPolicy.SHARED`. Default: `EXCLUSIVE`. See also: `TruffleLanguage.parse(ParsingRequest)`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#contextPolicy()`
### services()
`Class>[] services() default {}`. Since 19.0. Declarative list of classes this language is known to provide. The language is supposed to override its `createContext` method and instantiate and `register` all here in defined services. Languages automatically get created but not yet initialized when their registered `service is requested`. Returns `Class>[]`: list of service types that this language can provide. Default: `{}`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#services()`
### fileTypeDetectors()
`Class extends TruffleFile.FileTypeDetector>[] fileTypeDetectors() default {}`. Since 19.0. Declarative list of `TruffleFile.FileTypeDetector` classes provided by this language. The language has to support all MIME types recognized by the registered `file type detectors`. Returns `Class extends TruffleFile.FileTypeDetector>[]`: list of file type detectors. Default: `{}`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#fileTypeDetectors()`
### needsAllEncodings()
`@Deprecated(since = "24.1") boolean needsAllEncodings() default false`. Since 22.1. Deprecated since 24.1. To enable all `TruffleString` encodings, it is sufficient to add the `org.graalvm.shadowed.jcodings` module to the language's module-info `requires` and ensure it is on the module path when languages are loaded. If the module can be found, and at least one languages requires it, all encodings are automatically enabled. When languages are loaded from the class path (i.e. as an unnamed module), having jcodings on the class path is enough to enable it. Returns `true` if the language uses `TruffleString`s with encodings not present in the following list. `UTF-8`; `UTF-16`; `UTF-32`; `ISO-8859-1`; `US-ASCII`; `BYTES`. Default: `false`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#needsAllEncodings()`
### website()
`String website() default ""`. Since 22.1.0. A link to a website with more information about the language. Will be shown in the help text of GraalVM launchers. The link can contain the following substitutions: **`${graalvm-version}`** the current GraalVM version. Optionally, a format string can be provided for the version using `${graalvm-version:format}`. See [`Version.format`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/home/Version.html#format%28java.lang.String%29).; **`${graalvm-website-version}`** the current GraalVM version in a format suitable for links to the GraalVM reference manual. The exact format may change without notice. Returns `String`: URL for language website. Default: `""`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#website()`
### sandbox()
`SandboxPolicy sandbox() default TRUSTED`. Since 23.0. Specifies the most strict sandbox policy in which the language can be used. The language can be used in a context with the specified sandbox policy or a weaker one. For example, if a language specifies `ISOLATED` policy, it can be used in a context configured with sandbox policy `TRUSTED`, `CONSTRAINED` or `ISOLATED`. But it cannot be used in a context configured with the `UNTRUSTED` sandbox policy. Default: `TRUSTED`. See also: [`SandboxPolicy`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html). Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#sandbox()`
### internalResources()
`Class extends InternalResource>[] internalResources() default {}`. Since 23.1. Declarative list of `InternalResource` classes that is associated with this language. Use the `internalResources` attribute solely for registering required internal resources. Optional internal resources should provide the associated language identifier using the `Id.componentId()` method. To unpack all resources of a language embedders may use [`Engine.copyResources(Path, String...)`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Engine.html#copyResources%28java.nio.file.Path,java.lang.String...%29). Default: `{}`. See also: `InternalResource`, `Id`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#internalResources()`
### optionalResources()
`String[] optionalResources() default {}`. Since 25.0. A declarative list of optional `InternalResource` identifiers associated with this language. It is recommended to register all optional resource identifiers here. Specifying the resource identifier allows the language use the resource even if its implementation was omitted at runtime. To use the resource when its implementation was omitted the `polyglot.engine.resourcePath.languageId` system property must be specified and point to a path with the resources. This allows to omit the resource implementation class in standalone distributions. Default: `{}`. See also: `InternalResource`, `Id`. Cite: `com/oracle/truffle/api/TruffleLanguage.Registration.html#optionalResources()`
# ◆ TruffleLogger
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 19.0.
```java
public final class TruffleLogger
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleLogger`
Support for logging in Truffle languages and instruments.
The logger's [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html) configuration is done using the [`Context's options`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#options%28java.util.Map%29). The level option key has the following format: `log.languageId.className.level` or `log.instrumentId.className.level`. The value is either the name of pre-defined [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html) constant or a numeric [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html) value. If not explicitly set in [`Context's options`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.Builder.html#options%28java.util.Map%29) the level is inherited from the parent logger.
The [`TruffleLogger`](com/oracle/truffle/api/TruffleLogger.md) supports [`message parameters`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html#getParameters%28%29) of primitive types and strings. The object parameters are converted into string value before they are passed to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html).
The [`TruffleLogger`](com/oracle/truffle/api/TruffleLogger.md) instances are safe to be used on compiled code paths as well as from multiple-threads.
## Methods
### getLogger(String)
`public static TruffleLogger getLogger(String id)`. Since 19.0. Find or create a root logger for a given language or instrument. If the root logger for given language or instrument already exists it's returned, otherwise a new root logger is created. Parameters: `id` `String`: the unique id of language or instrument. Returns `TruffleLogger`: a `TruffleLogger`. Throws: `NullPointerException` (unchecked): if `id` is null. `IllegalArgumentException` (unchecked): if `id` is not a valid language or instrument id. Cite: `com/oracle/truffle/api/TruffleLogger.html#getLogger(java.lang.String)`
### getLogger(String, Class)
`public static TruffleLogger getLogger(String id, Class> forClass)`. Since 19.0. Find or create a logger for a given language or instrument class. If a logger for the class already exists it's returned, otherwise a new logger is created. Parameters: `id` `String`: the unique id of language or instrument. `forClass` `Class>`: the [`Class`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Class.html) to create a logger for. Returns `TruffleLogger`: a `TruffleLogger`. Throws: `NullPointerException` (unchecked): if `id` or `forClass` is null. `IllegalArgumentException` (unchecked): if `id` is not a valid language or instrument id. Cite: `com/oracle/truffle/api/TruffleLogger.html#getLogger(java.lang.String,java.lang.Class)`
### getLogger(String, String)
`public static TruffleLogger getLogger(String id, String loggerName)`. Since 19.0. Find or create a logger for a given language or instrument. If a logger with given name already exists it's returned, otherwise a new logger is created. Parameters: `id` `String`: the unique id of language or instrument. `loggerName` `String`: the name of a `TruffleLogger`, if a `loggerName` is null or empty a root logger for language or instrument is returned. Returns `TruffleLogger`: a `TruffleLogger`. Throws: `NullPointerException` (unchecked): if `id` is null. `IllegalArgumentException` (unchecked): if `id` is not a valid language or instrument id. Cite: `com/oracle/truffle/api/TruffleLogger.html#getLogger(java.lang.String,java.lang.String)`
### config(String)
`public void config(String message)`. Since 19.0. Logs a message with [`config level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#CONFIG). If the logger is enabled for the [`config level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#CONFIG) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#config(java.lang.String)`
### config(Supplier)
`public void config(Supplier messageSupplier)`. Since 19.0. Logs a message with [`config level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#CONFIG). The message is constructed only when the logger is enabled for the [`config level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#CONFIG). If the logger is enabled for the [`config level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#CONFIG) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#config(java.util.function.Supplier)`
### entering(String, String)
`public void entering(String sourceClass, String sourceMethod)`. Since 19.0. Logs entry into method. This method can be used to log entry into a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "ENTRY" and the given `sourceMethod` and `sourceClass` is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the entered class. `sourceMethod` `String`: the entered method. Cite: `com/oracle/truffle/api/TruffleLogger.html#entering(java.lang.String,java.lang.String)`
### entering(String, String, Object)
`public void entering(String sourceClass, String sourceMethod, Object parameter)`. Since 19.0. Logs entry into method with single parameter. This method can be used to log entry into a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "ENTRY", the given `sourceMethod` and `sourceClass` and given parameter is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the entered class. `sourceMethod` `String`: the entered method. `parameter` `Object`: the method parameter. Cite: `com/oracle/truffle/api/TruffleLogger.html#entering(java.lang.String,java.lang.String,java.lang.Object)`
### entering(String, String, Object[])
`public void entering(String sourceClass, String sourceMethod, Object[] parameters)`. Since 19.0. Logs entry into method with multiple parameters. This method can be used to log entry into a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "ENTRY", the given `sourceMethod` and `sourceClass` and given parameters is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the entered class. `sourceMethod` `String`: the entered method. `parameters` `Object[]`: the method parameters. Cite: `com/oracle/truffle/api/TruffleLogger.html#entering(java.lang.String,java.lang.String,java.lang.Object[])`
### exiting(String, String)
`public void exiting(String sourceClass, String sourceMethod)`. Since 19.0. Logs a return from method. This method can be used to log return from a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "RETURN" and the given `sourceMethod` and `sourceClass` is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the exiting class. `sourceMethod` `String`: the exiting method. Cite: `com/oracle/truffle/api/TruffleLogger.html#exiting(java.lang.String,java.lang.String)`
### exiting(String, String, Object)
`public void exiting(String sourceClass, String sourceMethod, Object result)`. Since 19.0. Logs a return from method with result. This method can be used to log return from a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "RETURN", the given `sourceMethod` and `sourceClass` and method result is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the exiting class. `sourceMethod` `String`: the exiting method. `result` `Object`: the return value. Cite: `com/oracle/truffle/api/TruffleLogger.html#exiting(java.lang.String,java.lang.String,java.lang.Object)`
### fine(String)
`public void fine(String message)`. Since 19.0. Logs a message with [`fine level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINE). If the logger is enabled for the [`fine level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINE) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#fine(java.lang.String)`
### fine(Supplier)
`public void fine(Supplier messageSupplier)`. Since 19.0. Logs a message with [`fine level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINE). The message is constructed only when the logger is enabled for the [`fine level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINE). If the logger is enabled for the [`fine level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINE) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#fine(java.util.function.Supplier)`
### finer(String)
`public void finer(String message)`. Since 19.0. Logs a message with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). If the logger is enabled for the [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#finer(java.lang.String)`
### finer(Supplier)
`public void finer(Supplier messageSupplier)`. Since 19.0. Logs a message with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). The message is constructed only when the logger is enabled for the [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). If the logger is enabled for the [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#finer(java.util.function.Supplier)`
### finest(String)
`public void finest(String message)`. Since 19.0. Logs a message with [`finest level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINEST). If the logger is enabled for the [`finest level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINEST) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#finest(java.lang.String)`
### finest(Supplier)
`public void finest(Supplier messageSupplier)`. Since 19.0. Logs a message with [`finest level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINEST). The message is constructed only when the logger is enabled for the [`finest level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINEST). If the logger is enabled for the [`finest level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINEST) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#finest(java.util.function.Supplier)`
### info(String)
`public void info(String message)`. Since 19.0. Logs a message with [`info level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#INFO). If the logger is enabled for the [`info level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#INFO) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#info(java.lang.String)`
### info(Supplier)
`public void info(Supplier messageSupplier)`. Since 19.0. Logs a message with [`info level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#INFO). The message is constructed only when the logger is enabled for the [`info level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#INFO). If the logger is enabled for the [`info level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#INFO) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#info(java.util.function.Supplier)`
### severe(String)
`public void severe(String message)`. Since 19.0. Logs a message with [`severe level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#SEVERE). If the logger is enabled for the [`severe level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#SEVERE) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#severe(java.lang.String)`
### severe(Supplier)
`public void severe(Supplier messageSupplier)`. Since 19.0. Logs a message with [`severe level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#SEVERE). The message is constructed only when the logger is enabled for the [`severe level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#SEVERE). If the logger is enabled for the [`severe level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#SEVERE) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#severe(java.util.function.Supplier)`
### throwing(String, String, T)
`public T throwing(String sourceClass, String sourceMethod, T thrown)`. Since 19.0. Logs throwing an exception. This method can be used to log exception thrown from a method. A [`LogRecord`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/LogRecord.html) with message "THROW",the given `sourceMethod` and `sourceClass` and `thrown` is logged with [`finer level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#FINER). Parameters: `sourceClass` `String`: the class throwing an exception. `sourceMethod` `String`: the method throwing an exception. `thrown` `T`: the thrown exception. Cite: `com/oracle/truffle/api/TruffleLogger.html#throwing(java.lang.String,java.lang.String,T)`
### warning(String)
`public void warning(String message)`. Since 19.0. Logs a message with [`warning level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING). If the logger is enabled for the [`warning level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#warning(java.lang.String)`
### warning(Supplier)
`public void warning(Supplier messageSupplier)`. Since 19.0. Logs a message with [`warning level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING). The message is constructed only when the logger is enabled for the [`warning level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING). If the logger is enabled for the [`warning level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html#WARNING) the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#warning(java.util.function.Supplier)`
### log(Level, String)
`public void log(Level level, String message)`. Since 19.0. Logs a message. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.lang.String)`
### log(Level, Supplier)
`public void log(Level level, Supplier messageSupplier)`. Since 19.0. Logs a message. The message is constructed only when the logger is enabled for the given `level`. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.util.function.Supplier)`
### log(Level, String, Object)
`public void log(Level level, String message, Object parameter)`. Since 19.0. Logs a message with single parameter. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `message` `String`: the message to log. `parameter` `Object`: the log message parameter. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.lang.String,java.lang.Object)`
### log(Level, String, Object[])
`public void log(Level level, String message, Object[] parameters)`. Since 19.0. Logs a message with multiple parameters. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `message` `String`: the message to log. `parameters` `Object[]`: the log message parameters. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.lang.String,java.lang.Object[])`
### log(Level, String, Throwable)
`public void log(Level level, String message, Throwable thrown)`. Since 19.0. Logs a message with an exception. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `message` `String`: the message to log. `thrown` `Throwable`: the exception to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.lang.String,java.lang.Throwable)`
### log(Level, Throwable, Supplier)
`public void log(Level level, Throwable thrown, Supplier messageSupplier)`. Since 19.0. Logs a message with an exception. The message is constructed only when the logger is enabled for the given `level`. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `thrown` `Throwable`: the exception to log. `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#log(java.util.logging.Level,java.lang.Throwable,java.util.function.Supplier)`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, String message)`. Since 19.0. Logs a message, specifying source class and source method. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `message` `String`: the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.lang.String)`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, Supplier messageSupplier)`. Since 19.0. Logs a message, specifying source class and source method. The message is constructed only when the logger is enabled for the given `level`. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.util.function.Supplier)`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, String message, Object parameter)`. Since 19.0. Logs a message with single parameter, specifying source class and source method. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `message` `String`: the message to log. `parameter` `Object`: the log message parameter. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.lang.String,java.lang.Object)`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, String message, Object[] parameters)`. Since 19.0. Log a message with multiple parameters, specifying source class and source method. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `message` `String`: the message to log. `parameters` `Object[]`: the log message parameters. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.lang.String,java.lang.Object[])`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, String message, Throwable thrown)`. Since 19.0. Logs a message with an exception, specifying source class and source method. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `message` `String`: the message to log. `thrown` `Throwable`: the exception to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.lang.String,java.lang.Throwable)`
### logp(Level, String, …)
`public void logp(Level level, String sourceClass, String sourceMethod, Throwable thrown, Supplier messageSupplier)`. Since 19.0. Logs a message with an exception, specifying source class and source method. The message is constructed only when the logger is enabled for the given `level`. If the logger is enabled for the given `level` the message is sent to the [`Handler`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Handler.html) registered in the current [`Context`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html). Parameters: `level` `Level`: the required [`Level`](https://docs.oracle.com/en/java/javase/25/docs/api/java.logging/java/util/logging/Level.html). `sourceClass` `String`: the class issued the logging request. `sourceMethod` `String`: the method issued the logging request. `thrown` `Throwable`: the exception to log. `messageSupplier` `Supplier`: the [`Supplier`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Supplier.html) called to produce the message to log. Cite: `com/oracle/truffle/api/TruffleLogger.html#logp(java.util.logging.Level,java.lang.String,java.lang.String,java.lang.Throwable,java.util.function.Supplier)`
### getName()
`public String getName()`. Since 19.0. Returns the name of the logger. Returns `String`: the logger name. Cite: `com/oracle/truffle/api/TruffleLogger.html#getName()`
### getParent()
`public TruffleLogger getParent()`. Since 19.0. Returns the parent `TruffleLogger`. Returns `TruffleLogger`: the parent `TruffleLogger` or null when the `TruffleLogger` has no parent. Cite: `com/oracle/truffle/api/TruffleLogger.html#getParent()`
### isLoggable(Level)
`public boolean isLoggable(Level level)`. Since 19.0. Checks if a message of the given level would be logged by this logger. Parameters: `level` `Level`: the required logging level. Returns `boolean`: true if message is loggable by this logger. Cite: `com/oracle/truffle/api/TruffleLogger.html#isLoggable(java.util.logging.Level)`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ TruffleOptionDescriptors
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 23.0.
```java
public interface TruffleOptionDescriptors extends OptionDescriptors
```
Extends: [`OptionDescriptors`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html)
An [`OptionDescriptors`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html) enhanced to provide a sandbox policy for options.
## Methods
### getSandboxPolicy(String)
`SandboxPolicy getSandboxPolicy(String key)`. Since 23.0. Returns a [`SandboxPolicy`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/SandboxPolicy.html) for an option `key`. Cite: `com/oracle/truffle/api/TruffleOptionDescriptors.html#getSandboxPolicy(java.lang.String)`
## Inherited members
- From interface [`OptionDescriptors`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html): [`EMPTY`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html#EMPTY), [`get`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html#get%28java.lang.String%29), [`iterator`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/options/OptionDescriptors.html#iterator%28%29)
- From interface [`Iterable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Iterable.html): [`forEach`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Iterable.html#forEach%28java.util.function.Consumer%29), [`spliterator`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Iterable.html#spliterator%28%29)
# ◆ TruffleOptions
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public final class TruffleOptions
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleOptions`
Class containing general Truffle options.
## Fields
### TraceRewrites
`public static final boolean TraceRewrites`. Since 0.8 or earlier. Enables/disables the rewriting of traces in the Truffle runtime to stdout. Can be set with `-Dtruffle.TraceRewrites=true`. Cite: `com/oracle/truffle/api/TruffleOptions.html#TraceRewrites`
### DetailedRewriteReasons
`public static final boolean DetailedRewriteReasons`. Since 0.8 or earlier. Enables the generation of detailed rewrite reasons. Enabling this may introduce some overhead for rewriting nodes. Can be set with `-Dtruffle.DetailedRewriteReasons=true`. Cite: `com/oracle/truffle/api/TruffleOptions.html#DetailedRewriteReasons`
### DetailedAssertions
`public static final boolean DetailedAssertions`. Since 25.6. Enables expensive assertions in Truffle and guest language implementations. An assertion is expensive if its cost is significant compared to the operation it checks, for example when it recomputes a cached result. Disabled by default. Can be set with `-Dtruffle.DetailedAssertions=true` before this class is initialized. Java assertions must also be enabled for the classes containing the checks. For native images, set the property when building the image. This is not a polyglot option and is not forwarded to polyglot isolates. Use this option to guard expensive checks while keeping inexpensive assertions enabled: Cite: `com/oracle/truffle/api/TruffleOptions.html#DetailedAssertions`
```java
assert !TruffleOptions.DetailedAssertions || expensiveCheck();
```
### TraceRewritesFilterClass
`public static final String TraceRewritesFilterClass`. Since 0.8 or earlier. Filters rewrites that do not contain the given string in the qualified name of the source or target class hierarchy. Can be set with `-Dtruffle.TraceRewritesFilterClass=name`. Cite: `com/oracle/truffle/api/TruffleOptions.html#TraceRewritesFilterClass`
### TraceRewritesFilterFromCost
`@Deprecated public static final NodeCost TraceRewritesFilterFromCost`. Since 0.8 or earlier. Deprecated. in 24.1 without replacement. Cite: `com/oracle/truffle/api/TruffleOptions.html#TraceRewritesFilterFromCost`
### TraceRewritesFilterToCost
`@Deprecated public static final NodeCost TraceRewritesFilterToCost`. Since 0.8 or earlier. Deprecated. in 24.1 without replacement. Cite: `com/oracle/truffle/api/TruffleOptions.html#TraceRewritesFilterToCost`
### AOT
`public static final boolean AOT`. Since 0.8 or earlier. Forces ahead-of-time initialization. Cite: `com/oracle/truffle/api/TruffleOptions.html#AOT`
## Inherited members
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
# ◇ TruffleRuntime
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface TruffleRuntime
```
Interface representing a Truffle runtime object. The runtime is responsible for creating call targets and performing optimizations for them.
## Methods
### getName()
`String getName()`. Since 0.8 or earlier. Name describing this runtime implementation for debugging purposes. Returns `String`: the name as a String. Cite: `com/oracle/truffle/api/TruffleRuntime.html#getName()`
### createDirectCallNode(CallTarget)
`default DirectCallNode createDirectCallNode(CallTarget target)`. Since 0.8 or earlier. Creates a new runtime specific version of `DirectCallNode`. Parameters: `target` `CallTarget`: the direct `CallTarget` to call. Returns `DirectCallNode`: the new call node. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createDirectCallNode(com.oracle.truffle.api.CallTarget)`
### createLoopNode(RepeatingNode)
`LoopNode createLoopNode(RepeatingNode body)`. Since 0.8 or earlier. Creates a new loop node with an implementation provided by a Truffle runtime implementation. Using Truffle loop nodes allows the runtime to do additional optimizations such as on stack replacement for loops. See also: `usage example`. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createLoopNode(com.oracle.truffle.api.nodes.RepeatingNode)`
### createIndirectCallNode()
`default IndirectCallNode createIndirectCallNode()`. Since 0.8 or earlier. Creates a new runtime specific version of `IndirectCallNode`. Returns `IndirectCallNode`: the new call node. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createIndirectCallNode()`
### createAssumption()
`Assumption createAssumption()`. Since 0.8 or earlier. Creates a new assumption object that can be checked and invalidated. Returns `Assumption`: the newly created assumption object. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createAssumption()`
### createAssumption(String)
`Assumption createAssumption(String name)`. Since 0.8 or earlier. Creates a new assumption object with a given name that can be checked and invalidated. Parameters: `name` `String`: the name for the new assumption. Returns `Assumption`: the newly created assumption object. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createAssumption(java.lang.String)`
### createVirtualFrame(Object[], FrameDescriptor)
`VirtualFrame createVirtualFrame(Object[] arguments, FrameDescriptor frameDescriptor)`. Since 0.8 or earlier. Creates a new virtual frame object that can be used to store values and is potentially optimizable by the runtime. Returns `VirtualFrame`: the newly created virtual frame object. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createVirtualFrame(java.lang.Object[],com.oracle.truffle.api.frame.FrameDescriptor)`
### createMaterializedFrame(Object[])
`MaterializedFrame createMaterializedFrame(Object[] arguments)`. Since 0.8 or earlier. Creates a new materialized frame object that can be used to store values. Returns `MaterializedFrame`: the newly created materialized frame object. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createMaterializedFrame(java.lang.Object[])`
### createMaterializedFrame(Object[], FrameDescriptor)
`MaterializedFrame createMaterializedFrame(Object[] arguments, FrameDescriptor frameDescriptor)`. Since 0.8 or earlier. Creates a new materialized frame object with the given frame descriptor that can be used to store values. Parameters: `frameDescriptor` `FrameDescriptor`: the frame descriptor describing this frame's values. Returns `MaterializedFrame`: the newly created materialized frame object. Cite: `com/oracle/truffle/api/TruffleRuntime.html#createMaterializedFrame(java.lang.Object[],com.oracle.truffle.api.frame.FrameDescriptor)`
### iterateFrames(FrameInstanceVisitor)
`default T iterateFrames(FrameInstanceVisitor visitor)`. Since 0.8 or earlier. Accesses the current stack, i.e., the contents of the `Frame`s and the associated `CallTarget`s. Iteration starts at the current frame. Iteration continues as long as `FrameInstanceVisitor.visitFrame`, which is invoked for every `FrameInstance`, returns null. Any non-null result of the visitor indicates that frame iteration should stop. Instances of `FrameInstance` must not escape the invocation of `FrameInstanceVisitor.visitFrame(FrameInstance)`. This rule is currently not enforced, but will be in future versions of Truffle. Note that this method can cause deoptimization if `FrameInstance.getFrame(FrameInstance.FrameAccess)` is called with `FrameAccess.READ_WRITE` or `FrameAccess.MATERIALIZE` on the fast path. Instructions and flags for debugging such deoptimizations can be found in [/truffle/docs/Optimizing.md#debugging-deoptimizations](https://github.com/oracle/graal/blob/master/truffle/docs/Optimizing.md#debugging-deoptimizations) To get possible asynchronous stack frames, use `TruffleStackTrace.getAsynchronousStackTrace(CallTarget, Frame)` and provide call target and frame from the last `FrameInstance`. Parameters: `visitor` `FrameInstanceVisitor`: the visitor that is called for every matching frame. Returns `T`: the last result returned by the visitor (which is non-null to indicate that iteration should stop), or null if the whole stack was iterated. Cite: `com/oracle/truffle/api/TruffleRuntime.html#iterateFrames(com.oracle.truffle.api.frame.FrameInstanceVisitor)`
### iterateFrames(FrameInstanceVisitor, int)
`default T iterateFrames(FrameInstanceVisitor visitor, int skipFrames)`. Since 21.1. Accesses the current stack, i.e., the contents of the `Frame`s and the associated `CallTarget`s. Iteration starts at the current frame and skips a number of frames provided as argument. Iteration continues as long as `FrameInstanceVisitor.visitFrame`, which is invoked for every `FrameInstance`, returns null. Any non-null result of the visitor indicates that frame iteration should stop. Instances of `FrameInstance` must not escape the invocation of `FrameInstanceVisitor.visitFrame(FrameInstance)`. This rule is currently not enforced, but will be in future versions of Truffle. Note that this method can cause deoptimization if `FrameInstance.getFrame(FrameInstance.FrameAccess)` is called with `FrameAccess.READ_WRITE` or `FrameAccess.MATERIALIZE` on the fast path. Instructions and flags for debugging such deoptimizations can be found in [/truffle/docs/Optimizing.md#debugging-deoptimizations](https://github.com/oracle/graal/blob/master/truffle/docs/Optimizing.md#debugging-deoptimizations) To get possible asynchronous stack frames, use `TruffleStackTrace.getAsynchronousStackTrace(CallTarget, Frame)` and provide call target and frame from the last `FrameInstance`. Parameters: `visitor` `FrameInstanceVisitor`: the visitor that is called for every matching frame. `skipFrames` `int`: number of frames to skip before invoking the visitor. Returns `T`: the last result returned by the visitor (which is non-null to indicate that iteration should stop), or null if the whole stack was iterated. Cite: `com/oracle/truffle/api/TruffleRuntime.html#iterateFrames(com.oracle.truffle.api.frame.FrameInstanceVisitor,int)`
### getCapability(Class)
` T getCapability(Class capability)`. Since 0.8 or earlier. Requests a capability from the runtime. Parameters: `capability` `Class`: the type of the interface representing the capability. Returns `T`: an implementation of the capability or `null` if the runtime does not offer it. Cite: `com/oracle/truffle/api/TruffleRuntime.html#getCapability(java.lang.Class)`
### notifyTransferToInterpreter()
`void notifyTransferToInterpreter()`. Since 0.8 or earlier. Internal API method. Do not use. Cite: `com/oracle/truffle/api/TruffleRuntime.html#notifyTransferToInterpreter()`
### isProfilingEnabled()
`boolean isProfilingEnabled()`. Since 0.8 or earlier. Whether or not the `TruffleRuntime` implementation can or wants to use gathered profiling information Truffle compilation. If this method returns `false` then all profiles in the `com.oracle.truffle.api.utilities` package are returning void implementations. If it returns `true` then all implementations gather profilinig information. Cite: `com/oracle/truffle/api/TruffleRuntime.html#isProfilingEnabled()`
# ◇ TruffleRuntimeAccess
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Interface in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 0.8 or earlier.
```java
public interface TruffleRuntimeAccess
```
A service that provides access to a [`TruffleRuntime`](com/oracle/truffle/api/TruffleRuntime.md) implementation.
## Methods
### getRuntime()
`TruffleRuntime getRuntime()`. Since 0.8 or earlier. Gets the `TruffleRuntime` implementation available via this access object. Cite: `com/oracle/truffle/api/TruffleRuntimeAccess.html#getRuntime()`
### getPriority()
`default int getPriority()`. Since 0.28. Allows disambiguation if more than one `TruffleRuntime` implementation is available. Cite: `com/oracle/truffle/api/TruffleRuntimeAccess.html#getPriority()`
# ◆ TruffleSafepoint
[truffle-api](index.md) › [com.oracle.truffle.api](com/oracle/truffle/api/index.md) · Every page: [llms.txt](llms.txt)
Abstract class in [`com.oracle.truffle.api`](com/oracle/truffle/api/index.md). Since 21.1.
```java
public abstract class TruffleSafepoint
```
Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `TruffleSafepoint`
Truffle safepoints allow interrupting the guest language execution to execute thread-local actions submitted by a language or tool. A safepoint is a location during the guest language execution where the state is consistent, and other operations can read its state.
### Supporting Safepoints in a Language
Safepoints are explicitly polled by invoking the [`poll(Node)`](com/oracle/truffle/api/TruffleSafepoint.md#poll%28com.oracle.truffle.api.nodes.Node%29) method. Safepoints are [`polled`](com/oracle/truffle/api/TruffleSafepoint.md#poll%28com.oracle.truffle.api.nodes.Node%29) with relaxed location or with [`exact location`](com/oracle/truffle/api/TruffleSafepoint.md#pollHere%28com.oracle.truffle.api.nodes.Node%29). A poll with a relaxed location is significantly more efficient than a poll with a precise location as the compiler is able to move and combine the poll requests during compilation. A Truffle guest language implementation must ensure that a safepoint is polled repeatedly within a constant time interval. For example, a single arithmetic expression completes within a constant number of CPU cycles. However, a loop that summarizes values over an array uses a non-constant time dependent on the array size. This typically means that safepoints are best polled at the end of loops and at the end of function or method calls to cover recursion. In addition, any guest language code that blocks the execution, like guest language locks, need to use the [`blocking API`](com/oracle/truffle/api/TruffleSafepoint.md#setBlocked%28com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.TruffleSafepoint.Interrupter,com.oracle.truffle.api.TruffleSafepoint.Interruptible,T,java.lang.Runnable,java.util.function.Consumer%29) to allow polling of safepoints while the thread is waiting.
Truffle's [`loop node`](com/oracle/truffle/api/nodes/LoopNode.md) and [`root node`](com/oracle/truffle/api/nodes/RootNode.md) support safepoint polling automatically. No further calls to [`poll(Node)`](com/oracle/truffle/api/TruffleSafepoint.md#poll%28com.oracle.truffle.api.nodes.Node%29) are therefore necessary. Custom loops or loops behind [`boundary`](com/oracle/truffle/api/CompilerDirectives.TruffleBoundary.md) annotated method calls are expected to be notified by the guest language implementation manually.
Thread local actions optionally incur side-effects. By default side-effects are enabled. A language implementation may disable side-effects temporarily for the current thread using [`setAllowSideEffects(boolean)`](com/oracle/truffle/api/TruffleSafepoint.md#setAllowSideEffects%28boolean%29) method.
### Submitting thread local actions
See [`ThreadLocalAction`](com/oracle/truffle/api/ThreadLocalAction.md) for details on how to submit actions.
Further information can be found in the [safepoint tutorial](http://github.com/oracle/graal/blob/master/truffle/docs/Safepoints.md).
**See also**
- [`ThreadLocalAction`](com/oracle/truffle/api/ThreadLocalAction.md)
- [`Context.safepoint()`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Context.html#safepoint%28%29)
## Nested types
- [`TruffleSafepoint.CompiledInterruptible`](com/oracle/truffle/api/TruffleSafepoint.CompiledInterruptible.md) (interface): Just like Interruptible but allows partial evaluation.
- [`TruffleSafepoint.CompiledInterruptibleFunction`](com/oracle/truffle/api/TruffleSafepoint.CompiledInterruptibleFunction.md) (interface): Just like InterruptibleFunction but allows partial evaluation.
- [`TruffleSafepoint.Interrupter`](com/oracle/truffle/api/TruffleSafepoint.Interrupter.md) (interface): An interrupter allows a foreign thread to interrupt the execution on a separate thread.
- [`TruffleSafepoint.Interruptible`](com/oracle/truffle/api/TruffleSafepoint.Interruptible.md) (interface): Function interface that represent interruptable Java methods.
- [`TruffleSafepoint.InterruptibleFunction`](com/oracle/truffle/api/TruffleSafepoint.InterruptibleFunction.md) (interface): Function interface that represent interruptable Java methods.
## Constructors
### TruffleSafepoint(Accessor.EngineSupport)
`protected TruffleSafepoint(Accessor.EngineSupport support)`. Since 21.1. Do not extend this class. This class is intended to be implemented by a Truffle runtime implementation. Cite: `com/oracle/truffle/api/TruffleSafepoint.html#(com.oracle.truffle.api.impl.Accessor.EngineSupport)`
## Methods
### poll(Node)
`public static void poll(Node location)`. Since 21.1. Polls a safepoint at the provided location. This allows to run thread local actions at this location. A Truffle guest language implementation must ensure that a safepoint is polled repeatedly within a constant time interval. See `TruffleSafepoint` for further details. In compiled code calls to this method are removed. Instead the compiler inserts safepoints automatically at loop ends and method exits. In this case the node location is approximated by frame state of method ends and loop exits in the compiler IR. For method ends the parent root node and for loop exits the loop node is passed as location. Guest language exceptions may be thrown by this method. If `side-effects` are allowed then also guest language exceptions may be thrown. Otherwise only internal or [`thread-death`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ThreadDeath.html) exceptions may be thrown. This method is safe to be used on compiled code paths. Polling may be performed on threads without entered polyglot context, polls are ignored there. Example usage with an unbounded loop sum behind a `TruffleBoundary`. Parameters: `location` `Node`: the location of the poll. May be `null`, but it is recommended to always pass a location node, if available. See also: `TruffleSafepoint`, `pollHere(Node)`. Cite: `com/oracle/truffle/api/TruffleSafepoint.html#poll(com.oracle.truffle.api.nodes.Node)`
```java
@TruffleBoundary
int sum(int[] array) {
int sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
TruffleSafepoint.poll();
}
return sum;
}
```
### pollHere(Node)
`public static void pollHere(Node location)`. Since 21.1. Similar to `poll(Node)` but with exact location. A poll with `relaxed location` is significantly more efficient than a poll with precise location as the compiler is able to move and combine the poll requests during compilation. This method is safe to be used on compiled code paths. Usage example: Parameters: `location` `Node`: the location of the poll. Must not be `null`. See also: `poll(Node)`. Cite: `com/oracle/truffle/api/TruffleSafepoint.html#pollHere(com.oracle.truffle.api.nodes.Node)`
```java
TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
boolean prev = safepoint.setAllowSideEffects(false);
try {
// criticial section
} finally {
safepoint.setAllowSideEffects(prev);
TruffleSafepoint.pollHere(this);
}
```
### setBlockedWithException(Node, TruffleSafepoint.Interrupter, …)
`@Deprecated public void setBlockedWithException(Node location, TruffleSafepoint.Interrupter interrupter, TruffleSafepoint.Interruptible interruptible, T object, Runnable beforeInterrupt, Consumer afterInterrupt)`. Since 22.1. Deprecated. Use `setBlocked(Node, Interrupter, Interruptible, Object, Runnable, Consumer)`. Transitions the current thread into a blocked state and calls an interruptible functional method. The blocked state is restored when the interruptible method returns. Setting the blocked state allows safepoint notification while the current thread is blocked. This allows Truffle to interrupt e.g. locks temporarily to perform a thread local action. The `location>` parameter is used `poll` all pending thread local actions before transition to blocked state. The `interrupter` parameter specifies how the blocked state can be interrupted from another thread. The interrupter allows to interrupt the blocked state from other threads. For most blocking java.util.concurrent primitives the `thread interrupter` can be used. If the thread will be blocked in native code, other ways of interrupting, like signals may be used by implementing the `Interrupter` interface. The `interruptible` parameter provides the method that calls the blocking method which throws [`InterruptedException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/InterruptedException.html) on interrupt. In order to avoid allocations of the functional interface a single argument can be provided that is passed to the interface. This is typically the [`lock`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/locks/Lock.html) or [`semaphore`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Semaphore.html) instance. The implementation of this method is expected to throw an [`InterruptedException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/InterruptedException.html) if the `Interrupter.interrupt(Thread)` method is invoked for this thread. For most java.util.concurrent primitives this is supported by using the interruptible blocking method variant, for example [`Lock.lockInterruptibly()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/locks/Lock.html#lockInterruptibly%28%29). Since it is common to use this method with method reference syntax e.g. `Lock::lockInterruptibly` for the interruptible parameter, we implicitlely apply a `boundary` for the entire method call by default. If the interruptible is called from a compiled code path and the interruptible should get partial evaluated, then `CompiledInterruptible` should be used instead of `Interruptible`. In this case the parameter must be a `partial evaluation constant`. The `beforeInterrupt` [`runnable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runnable.html) and `afterInterrupt` [`consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html) optional parameters allow to run code before and after a thread got interrupted and safepoint events are processed. If `null` is provided then no action will be performed. Arbitrary code may be executed in this runnable. Note that the blocked state is temporarily reset to its previous state while the afterInterrupt is called. If an exception is thrown during the processing of the safepoint, `afterInterrupt` will receive the throwable as argument, or `null` if the safepoint successfully completed. This exception will still be thrown after completion of `afterInterrupt`, unless `afterInterrupt` throws an exception of its own. Multiple recursive invocations of this method is supported. The previous blocked state will be restored when the method completes or fails. Example usage: Note there is a short-cut method to achieve the same behavior as in this example `setBlockedThreadInterruptible(Node, Interruptible, Object)`. See also: `TruffleSafepoint`. Cite: `com/oracle/truffle/api/TruffleSafepoint.html#setBlockedWithException(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.TruffleSafepoint.Interrupter,com.oracle.truffle.api.TruffleSafepoint.Interruptible,T,java.lang.Runnable,java.util.function.Consumer)`
```java
Lock lock = new ReentrantLock();
TruffleSafepoint sp = TruffleSafepoint.getCurrent();
sp.setBlocked(location, Interrupter.THREAD_INTERRUPT, ReentrantLock::lockInterruptibly, lock, null, null);
```
### setBlockedFunction(Node, TruffleSafepoint.Interrupter, …)
`public abstract R setBlockedFunction(Node location, TruffleSafepoint.Interrupter interrupter, TruffleSafepoint.InterruptibleFunction interruptible, T object, Runnable beforeInterrupt, Consumer afterInterrupt)`. Since 23.1. Transitions the current thread into a blocked state and calls an interruptible functional method. The blocked state is restored when the interruptible method returns. Setting the blocked state allows safepoint notification while the current thread is blocked. This allows Truffle to interrupt e.g. locks temporarily to perform a thread local action. The `location` parameter is used to `poll` all pending thread local actions before transition to blocked state. It may be `null`, but it is recommended to always pass a location node, if available. The `interrupter` parameter specifies how the blocked state can be interrupted from another thread. The interrupter allows to interrupt the blocked state from other threads. For most blocking java.util.concurrent primitives the `thread interrupter` can be used. If the thread will be blocked in native code, other ways of interrupting, like signals may be used by implementing the `Interrupter` interface. The `interruptible` parameter provides the method that calls the blocking method which throws [`InterruptedException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/InterruptedException.html) on interrupt. In order to avoid allocations of the functional interface a single argument can be provided that is passed to the interface. This is typically the [`lock`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/locks/Lock.html) or [`semaphore`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/Semaphore.html) instance. The implementation of this method is expected to throw an [`InterruptedException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/InterruptedException.html) if the `Interrupter.interrupt(Thread)` method is invoked for this thread. For most java.util.concurrent primitives this is supported by using the interruptible blocking method variant, for example [`Lock.lockInterruptibly()`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/locks/Lock.html#lockInterruptibly%28%29). `boundary` is applied for the entire interruptible method call by default. If the interruptible is called from a compiled code path and the interruptible should get partial evaluated, then `CompiledInterruptibleFunction` should be used instead of `InterruptibleFunction`. In this case the parameter must be a `partial evaluation constant`. The `beforeInterrupt` [`runnable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Runnable.html) and `afterInterrupt` [`consumer`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/function/Consumer.html) optional parameters allow to run code before and after a thread got interrupted and safepoint events are processed. If `null` is provided then no action will be performed. Arbitrary code may be executed in this runnable. Note that the blocked state is temporarily reset to its previous state while the afterInterrupt is called. If an exception is thrown during the processing of the safepoint, `afterInterrupt` will receive the throwable as argument, or `null` if the safepoint successfully completed. This exception will still be thrown after completion of `afterInterrupt`, unless `afterInterrupt` throws an exception of its own. Multiple recursive invocations of this method is supported. The previous blocked state will be restored when the method completes or fails. Example usage: Note there is a short-cut method to achieve the same behavior as in this example `setBlockedThreadInterruptibleFunction(Node, InterruptibleFunction, Object)`. See also: `TruffleSafepoint`. Cite: `com/oracle/truffle/api/TruffleSafepoint.html#setBlockedFunction(com.oracle.truffle.api.nodes.Node,com.oracle.truffle.api.TruffleSafepoint.Interrupter,com.oracle.truffle.api.TruffleSafepoint.InterruptibleFunction,T,java.lang.Runnable,java.util.function.Consumer)`
```java
Queue