Skip to content

Commit

Permalink
Use virtual thread for include scanning if async execution is enabled.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 642616320
Change-Id: If27df6f81393556cef58d6b83c24e49576b89e4d
  • Loading branch information
coeuvre authored and copybara-github committed Jun 12, 2024
1 parent 0a94bc1 commit 5d70544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ java_library(
name = "includescanning",
srcs = glob(["*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib:build-request-options",
"//src/main/java/com/google/devtools/build/lib:runtime",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:action_input_helper",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.BuildRequestOptions;
import com.google.devtools.build.lib.concurrent.ExecutorUtil;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadHostile;
import com.google.devtools.build.lib.events.Event;
Expand Down Expand Up @@ -67,6 +68,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -328,8 +330,14 @@ public void executionPhaseEnding() {

@Override
public void executorCreated() {
var buildRequestOptions = env.getOptions().getOptions(BuildRequestOptions.class);
var useAsyncExecution = buildRequestOptions != null && buildRequestOptions.useAsyncExecution;
int threads = options.includeScanningParallelism;
if (threads > 0) {
if (useAsyncExecution) {
includePool =
Executors.newThreadPerTaskExecutor(
Thread.ofVirtual().name("Include scanner ", 0).factory());
} else if (threads > 0) {
logger.atInfo().log("Include scanning configured to use a pool with %d threads", threads);
if (options.experimentalReuseIncludeScanningThreads) {
includePool =
Expand Down

0 comments on commit 5d70544

Please sign in to comment.