Skip to content

Commit

Permalink
[GR-23129] Add an engine option for TruffleRuntime to specify compile…
Browse files Browse the repository at this point in the history
…r idle delay.

PullRequest: graal/6515
  • Loading branch information
tzezula committed Jun 24, 2020
2 parents 4e33c75 + 09d3091 commit 9290bfb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ private String indent(int nameLength) {
@Option(help = "Manually set the number of compiler threads", category = OptionCategory.EXPERT)
public static final OptionKey<Integer> CompilerThreads = new OptionKey<>(0);

@Option(help = "Set the time in milliseconds an idle Truffle compiler thread will wait for new tasks before terminating. " +
"New compiler threads will be started once new compilation tasks are submitted. " +
"Select '0' to never terminate the Truffle compiler thread. " +
"The option is not supported by all Truffle runtimes. On the runtime which doesn't support it the option has no effect.",
category = OptionCategory.EXPERT)
public static final OptionKey<Long> CompilerIdleDelay = new OptionKey<>(1000L);

@Option(help = "Minimum number of invocations or loop iterations needed to compile a guest language root.",
category = OptionCategory.EXPERT)
public static final OptionKey<Integer> CompilationThreshold = new OptionKey<>(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.graalvm.compiler.truffle.runtime.hotspot.libgraal;

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
import static org.graalvm.compiler.truffle.options.PolyglotCompilerOptions.CompilerIdleDelay;
import static org.graalvm.libgraal.LibGraalScope.getIsolateThread;

import java.io.IOException;
Expand All @@ -43,6 +44,7 @@

import jdk.vm.ci.hotspot.HotSpotResolvedJavaType;
import jdk.vm.ci.meta.MetaAccessProvider;
import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget;

/**
* A {@link TruffleRuntime} that uses libgraal for compilation.
Expand Down Expand Up @@ -96,9 +98,8 @@ protected AutoCloseable openCompilerThreadScope() {
}

@Override
protected long getCompilerIdleDelay() {
// TODO: introduce a polyglot option (GR-23129)
return 1000L;
protected long getCompilerIdleDelay(OptimizedCallTarget callTarget) {
return callTarget.getOptionValue(CompilerIdleDelay);
}

@SuppressWarnings("try")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private ExecutorService getExecutorService(OptimizedCallTarget callTarget) {

ThreadFactory factory = newThreadFactory("TruffleCompilerThread", callTarget);

long compilerIdleDelay = runtime.getCompilerIdleDelay();
long compilerIdleDelay = runtime.getCompilerIdleDelay(callTarget);
long keepAliveTime = compilerIdleDelay >= 0 ? compilerIdleDelay : 0;
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threads, threads,
keepAliveTime, TimeUnit.MILLISECONDS,
Expand All @@ -96,7 +96,7 @@ protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
return new RequestFutureTask<>((RequestImpl<T>) callable);
}
};
if (compilerIdleDelay >= 0) {
if (compilerIdleDelay > 0) {
threadPoolExecutor.allowCoreThreadTimeOut(true);
}
return compilationExecutorService = threadPoolExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,9 @@ private static <T extends Annotation> T getAnnotation(Class<T> annotationClass,

/**
* Gets a closeable that will be used in a try-with-resources statement surrounding the run-loop
* of a Truffle compiler thread. In conjunction with {@link #getCompilerIdleDelay()}, this can
* be used to release resources held by idle Truffle compiler threads.
* of a Truffle compiler thread. In conjunction with
* {@link #getCompilerIdleDelay(OptimizedCallTarget)}, this can be used to release resources
* held by idle Truffle compiler threads.
*
* If a non-null value is returned, its {@link AutoCloseable#close()} must not throw an
* exception.
Expand All @@ -1075,10 +1076,10 @@ protected AutoCloseable openCompilerThreadScope() {

/**
* Gets the time in milliseconds an idle Truffle compiler thread will wait for new tasks before
* terminating. A value of {@code < 0} means that Truffle compiler threads block indefinitely
* terminating. A value of {@code <= 0} means that Truffle compiler threads block indefinitely
* waiting for a task and thus never terminate.
*/
protected long getCompilerIdleDelay() {
return -1;
protected long getCompilerIdleDelay(@SuppressWarnings("unused") OptimizedCallTarget callTarget) {
return 0;
}
}

0 comments on commit 9290bfb

Please sign in to comment.