Skip to content

Commit

Permalink
Run a manual GC after clearing the in-memory graph from a `--keep_sta…
Browse files Browse the repository at this point in the history
…te_after_build` command.

Same purpose as unknown commit except for cases where the previous build kept state.

PiperOrigin-RevId: 550048302
Change-Id: I6bf3ef26edfcd9f63ff2f71790dd28f15de9d714
  • Loading branch information
justinhorvitz authored and copybara-github committed Jul 21, 2023
1 parent f786333 commit f4b01b1
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.profiler.GoogleAutoProfilerUtils;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.repository.ExternalPackageHelper;
Expand Down Expand Up @@ -123,6 +124,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
private boolean trackIncrementalState = true;

private boolean evaluatorNeedsReset = false;
private boolean lastCommandKeptState = false;
private boolean needGcAfterResettingEvaluator = false;

private final AtomicInteger outputDirtyFiles = new AtomicInteger();
private final ArrayBlockingQueue<String> outputDirtyFilesExecPathSample =
Expand Down Expand Up @@ -258,6 +261,15 @@ public WorkspaceInfoFromDiff sync(
// or if the graph doesn't have edges, so that a fresh graph can be used.
resetEvaluator();
evaluatorNeedsReset = false;
if (needGcAfterResettingEvaluator) {
// Collect weakly reachable objects to avoid resurrection. See b/291641466.
try (var profiler =
GoogleAutoProfilerUtils.logged(
"manual GC to clean up from --keep_state_after_build command")) {
System.gc();
}
needGcAfterResettingEvaluator = false;
}
}
super.sync(
eventHandler,
Expand Down Expand Up @@ -389,13 +401,17 @@ public void decideKeepIncrementalState(
}

// Now check if it is necessary to wipe the previous state. We do this if either the previous
// or current incrementalStateRetentionStrategy requires the build to have been isolated.
// or current command requires the build to have been isolated.
if (oldValueOfTrackIncrementalState != trackIncrementalState) {
logger.atInfo().log("Set incremental state to %b", trackIncrementalState);
evaluatorNeedsReset = true;
} else if (!trackIncrementalState) {
evaluatorNeedsReset = true;
}
if (evaluatorNeedsReset && lastCommandKeptState) {
needGcAfterResettingEvaluator = true;
}
lastCommandKeptState = keepStateAfterBuild;
}

@Override
Expand Down

0 comments on commit f4b01b1

Please sign in to comment.