diff options
author | 2017-01-05 20:21:35 +0000 | |
---|---|---|
committer | 2017-01-05 21:10:56 +0000 | |
commit | 7be337f50d7b14205c56ec75d86bd9a7e835fbe5 (patch) | |
tree | 6518a43eba7679bd5f339d82d11f0f1c234aa6e9 /src/main/java/com/google/devtools/build/lib | |
parent | bf51766b1ec67159b1c55889ac55a2e37faeeb02 (diff) |
Rollback of commit 70c5790e4fb01db382d61d457596a46b68ba8d13.
(Tests kept.)
*** Reason for rollback ***
[]
*** Original change description ***
When --experimental_oom_more_eagerly is enabled, tell Bazel to exit with an OutOfMemoryError and have the JVM send Bazel a SIGUSR2 when it detects an OOM. This should help in certain pathological cases when Bazel GC thrashes for some time after an OOM has been detected.
--
PiperOrigin-RevId: 143694970
MOS_MIGRATED_REVID=143694970
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
4 files changed, 38 insertions, 129 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 74c49f4189..532923c54a 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 @@ -698,7 +698,7 @@ public final class BlazeRuntime { new InterruptSignalHandler() { @Override - protected void onSignal() { + public void run() { LOG.info("User interrupt"); OutErr.SYSTEM_OUT_ERR.printErrLn("Blaze received an interrupt"); mainThread.interrupt(); @@ -764,13 +764,14 @@ public final class BlazeRuntime { final RPCServer blazeServer = createBlazeRPCServer(modules, Arrays.asList(args)); // Register the signal handler. - sigintHandler = new InterruptSignalHandler() { - @Override - protected void onSignal() { - LOG.severe("User interrupt"); - blazeServer.interrupt(); - } - }; + sigintHandler = + new InterruptSignalHandler() { + @Override + public void run() { + LOG.severe("User interrupt"); + blazeServer.interrupt(); + } + }; blazeServer.serve(); return ExitCode.SUCCESS.getNumericExitCode(); @@ -902,9 +903,6 @@ public final class BlazeRuntime { if (startupOptions.oomMoreEagerlyThreshold != 100) { new RetainedHeapLimiter(startupOptions.oomMoreEagerlyThreshold).install(); } - if (startupOptions.oomMoreEagerly) { - new OomSignalHandler(); - } PathFragment workspaceDirectory = startupOptions.workspaceDirectory; PathFragment installBase = startupOptions.installBase; PathFragment outputBase = startupOptions.outputBase; 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 deleted file mode 100644 index f8dcb3237e..0000000000 --- a/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.runtime; - -import com.google.devtools.build.lib.server.signal.AbstractSignalHandler; -import com.google.devtools.build.lib.util.ExitCode; -import com.google.devtools.build.lib.util.OS; -import com.google.devtools.build.lib.util.io.OutErr; - -import sun.misc.Signal; - -import java.util.logging.Logger; - -/** - * Class that causes Blaze to exit with {@link ExitCode#OOM_ERROR} when the JVM receives a - * {@code SIGUSR2} signal. - * - * <p>The Blaze client can be configured to send {@code SIGUSR2} on an OOM. - */ -class OomSignalHandler extends AbstractSignalHandler { - private static final Logger LOG = Logger.getLogger(OomSignalHandler.class.getName()); - private static final Signal SIGUSR2 = (OS.getCurrent() != OS.WINDOWS) ? new Signal("USR2") : null; - 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 = - withNoStack(new OutOfMemoryError(MESSAGE)); - - private static <T extends Throwable> T withNoStack(T throwable) { - throwable.setStackTrace(new StackTraceElement[0]); - return throwable; - } - - OomSignalHandler() { - super(SIGUSR2); - } - - @Override - protected void onSignal() { - LOG.info(MESSAGE); - OutErr.SYSTEM_OUT_ERR.printErrLn( - "Exiting as if we OOM'd because SIGUSR2 received, presumably from JVM"); - BugReport.handleCrash(OUT_OF_MEMORY_ERROR); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/server/signal/AbstractSignalHandler.java b/src/main/java/com/google/devtools/build/lib/server/signal/AbstractSignalHandler.java deleted file mode 100644 index 627a38311e..0000000000 --- a/src/main/java/com/google/devtools/build/lib/server/signal/AbstractSignalHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.server.signal; - - -import com.google.devtools.build.lib.util.Preconditions; - -import sun.misc.Signal; -import sun.misc.SignalHandler; - -/** - * A facade around {@link sun.misc.Signal} providing special-purpose signal handling. - * - * <p>We use this code in preference to using sun.misc directly since the latter is deprecated, and - * depending on it causes javac to emit an unsuppressable warning that sun.misc is - * "Sun proprietary API and may be removed in a future release". - */ -public abstract class AbstractSignalHandler { - private final Signal signal; - private SignalHandler oldHandler; - - /** - * Constructs an AbstractSignalHandler instance. Until the uninstall() method is invoked, the - * delivery of {@code signal} to this process will cause the run() method to be invoked in another - * thread. - */ - protected AbstractSignalHandler(Signal signal) { - this.signal = signal; - this.oldHandler = - Signal.handle( - signal, - new SignalHandler() { - @Override - public void handle(Signal signal) { - onSignal(); - } - }); - } - - protected abstract void onSignal(); - - /** Disables signal handling. */ - public final synchronized void uninstall() { - Preconditions.checkNotNull(oldHandler, "uninstall() already called"); - Signal.handle(signal, oldHandler); - oldHandler = null; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/server/signal/InterruptSignalHandler.java b/src/main/java/com/google/devtools/build/lib/server/signal/InterruptSignalHandler.java index f2dc729cef..74196e2caa 100644 --- a/src/main/java/com/google/devtools/build/lib/server/signal/InterruptSignalHandler.java +++ b/src/main/java/com/google/devtools/build/lib/server/signal/InterruptSignalHandler.java @@ -13,18 +13,44 @@ // limitations under the License. package com.google.devtools.build.lib.server.signal; +import com.google.devtools.build.lib.util.Preconditions; import sun.misc.Signal; +import sun.misc.SignalHandler; + +/** + * A facade around sun.misc.Signal providing special-purpose SIGINT handling. + * + * <p>We use this code in preference to using sun.misc directly since the latter is deprecated, and + * depending on it causes the jdk1.6 javac to emit an unsuppressable warning that sun.misc is + * "Sun proprietary API and may be removed in a future release". + */ +public abstract class InterruptSignalHandler implements Runnable { -/** Class that can be extended to handle SIGINT in a custom way. */ -public abstract class InterruptSignalHandler extends AbstractSignalHandler { private static final Signal SIGINT = new Signal("INT"); + private SignalHandler oldHandler; + /** * Constructs an InterruptSignalHandler instance. Until the uninstall() * method is invoked, the delivery of a SIGINT signal to this process will * cause the run() method to be invoked in another thread. */ protected InterruptSignalHandler() { - super(SIGINT); + this.oldHandler = + Signal.handle( + SIGINT, + new SignalHandler() { + @Override + public void handle(Signal signal) { + run(); + } + }); + } + + /** Disables SIGINT handling. */ + public final synchronized void uninstall() { + Preconditions.checkNotNull(oldHandler, "uninstall() already called"); + Signal.handle(SIGINT, oldHandler); + oldHandler = null; } } |