Elide GraalVM25.6.0-elide.4
All types
Versions and modules

ResourceLimits.Builder

Javaclassin org.graalvm.polyglotsince 19.3

public final class ResourceLimits.Builder
Inheritance
  1. Object
  2. Builder
Enclosing type
ResourceLimits

A builder used to construct resource limits. Builder instances are not thread-safe and may not be used from multiple threads at the same time.

Methods4

ResourceLimits.Builder statementLimit(long, Predicate<Source>)

statementLimit

since 19.3
public ResourceLimits.Builder statementLimit(long limit, Predicate<Source> sourceFilter)

Specifies the maximum number of statements a context may execute until the onLimit event is notified and the context will be closed. After the statement limit was triggered for a context, it is no longer usable and every use of the context will throw a PolyglotException that returns true for PolyglotException.isCancelled(). The statement limit is independent of the number of threads executing and is applied per context. Invoking this method multiple times overwrites previous statement limit configurations. If the statement limit is exceeded then the onLimit listener is notified.

By default there is no statement limit applied. The limit may be set to 0 to disable it. In addition to the limit a source filter may be set to indicate for which sources the limit should be applied. If the source filter is null then it will be applied to all internal and public sources. The provided limit must not be negative otherwise an IllegalArgumentException is thrown. If a shared engine is used then the same source filter instance must be used for all contexts of an engine. Otherwise an IllegalArgumentException is thrown when the context is built. The limit itself may vary between contexts.

The statement limit is applied to the context and all inner contexts it spawns. Therefore, new inner contexts cannot be used to exceed the statement limit.

Note that attaching a statement limit to a context reduces the throughput of all guest applications with the same engine. The statement counter needs to be updated with every statement that is executed. It is recommended to benchmark the use of the statement limit before it is used in production.

Note that the complexity of a single statement may not be constant time depending on the guest language. For example, statements that execute JavaScript builtins, like Array.sort, may account for a single statement, but its execution time is dependent on the size of the array. The statement count limit is therefore not suitable to perform time boxing and must be combined with other more reliable measures.

Parameters

limitlong
No description.
sourceFilterPredicate<Source>
No description.

Returns

ResourceLimits.Builder
No description.
ResourceLimits.Builder onLimit(Consumer<ResourceLimitEvent>)

onLimit

since 19.3

Notified when a resource limit is reached. Default is null. May be set to null to disable events.

Parameters

onLimitConsumer<ResourceLimitEvent>
No description.

Returns

ResourceLimits.Builder
No description.
String toString()Described in toString().

toString

since 25.3
public String toString()

Described in toString().

Returns

String
No description.
ResourceLimits build()

build

since 19.3
public ResourceLimits build()

Builds the limit configuration object.

Returns

ResourceLimits
No description.

Inherited members