diff options
author | 2016-05-23 21:55:20 +0000 | |
---|---|---|
committer | 2016-05-24 11:58:09 +0000 | |
commit | 39a5513a8ba407af6a24edbc34d04d80ed40d8e2 (patch) | |
tree | 6784685ce2e08c8de795c6ae277da3bb1e19807a /src/main/java/com/google | |
parent | 19fde1fc26d261fa95e115c3a0bfb0bd92f1e13a (diff) |
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
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java | 12 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java | 9 |
2 files changed, 16 insertions, 5 deletions
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 e9a91dcee4..8c9af364ce 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 @@ public final class BlazeRuntime { 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 @@ public final class BlazeRuntime { * 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); } /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java index 39c2c8902c..3aea75e6d9 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java @@ -30,6 +30,10 @@ import java.util.logging.Logger; class OomSignalHandler extends AbstractSignalHandler { private static final Logger LOG = Logger.getLogger(OomSignalHandler.class.getName()); private static final Signal SIGUSR2 = new Signal("USR2"); + private static final String MESSAGE = "SIGUSR2 received, presumably from JVM due to OOM"; + // Pre-allocate memory for object that will be used during an OOM, because there may not be spare + // memory when we're OOMing. That's kind of the point of an OOM. + private static final OutOfMemoryError OUT_OF_MEMORY_ERROR = new OutOfMemoryError(MESSAGE); OomSignalHandler() { super(SIGUSR2); @@ -37,10 +41,9 @@ class OomSignalHandler extends AbstractSignalHandler { @Override protected void onSignal() { - String message = "SIGUSR2 received, presumably from JVM due to OOM"; - LOG.info(message); + LOG.info(MESSAGE); OutErr.SYSTEM_OUT_ERR.printErrLn( "Exiting as if we OOM'd because SIGUSR2 received, presumably from JVM"); - BugReport.handleCrash(new OutOfMemoryError(message)); + BugReport.handleCrash(OUT_OF_MEMORY_ERROR); } } |