Pre-allocate memory at a few (non-exhaustive) sites that are on the exit path after we OOM, in an attempt to make that path complete more quickly and successfully.
--
MOS_MIGRATED_REVID=123040502
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index e9a91dc..8c9af36 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -141,6 +141,10 @@
private static final Logger LOG = Logger.getLogger(BlazeRuntime.class.getName());
+ // Pre-allocate memory for this object in case of an OOM.
+ private static final CommandCompleteEvent OOM_COMMAND_COMPLETE_EVENT =
+ new CommandCompleteEvent(ExitCode.OOM_ERROR.getNumericExitCode());
+
private final Iterable<BlazeModule> blazeModules;
private final Map<String, BlazeCommand> commandMap = new LinkedHashMap<>();
private final Clock clock;
@@ -505,14 +509,18 @@
* Posts the {@link CommandCompleteEvent}, so that listeners can tidy up. Called by {@link
* #afterCommand}, and by BugReport when crashing from an exception in an async thread.
*/
- public void notifyCommandComplete(int exitCode) {
+ void notifyCommandComplete(int exitCode) {
if (!storedExitCode.compareAndSet(ExitCode.RESERVED.getNumericExitCode(), exitCode)) {
// This command has already been called, presumably because there is a race between the main
// thread and a worker thread that crashed. Don't try to arbitrate the dispute. If the main
// thread won the race (unlikely, but possible), this may be incorrectly logged as a success.
return;
}
- workspace.getSkyframeExecutor().getEventBus().post(new CommandCompleteEvent(exitCode));
+ CommandCompleteEvent commandCompleteEvent =
+ exitCode == ExitCode.OOM_ERROR.getNumericExitCode()
+ ? OOM_COMMAND_COMPLETE_EVENT
+ : new CommandCompleteEvent(exitCode);
+ workspace.getSkyframeExecutor().getEventBus().post(commandCompleteEvent);
}
/**