diff options
author | 2017-08-15 21:09:50 +0200 | |
---|---|---|
committer | 2017-08-16 11:05:55 +0200 | |
commit | ff746b4aaa5bb7109ff543a72c165fa6e785916f (patch) | |
tree | 3d4d848b744542e099bc398bf4b82b42fffa8a0d /src/main/java/com/google | |
parent | 7481de4637998750a0f0eda2e39d09a5a9f84be9 (diff) |
Add the command option --experimental_oom_more_eagerly_threshold. This will replace the startup option after a deprecation period.
PiperOrigin-RevId: 165340514
Diffstat (limited to 'src/main/java/com/google')
5 files changed, 57 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java index 54803ea944..bfa3f28489 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java @@ -470,6 +470,27 @@ public class BlazeCommandDispatcher { reporter.addHandler(handler); env.getEventBus().register(handler); + int oomMoreEagerlyThreshold = commonOptions.oomMoreEagerlyThreshold; + if (oomMoreEagerlyThreshold == 100) { + oomMoreEagerlyThreshold = + runtime + .getStartupOptionsProvider() + .getOptions(BlazeServerStartupOptions.class) + .oomMoreEagerlyThreshold; + } + if (oomMoreEagerlyThreshold < 0 || oomMoreEagerlyThreshold > 100) { + reporter.handle(Event.error("--oom_more_eagerly_threshold must be non-negative percent")); + return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode(); + } + if (oomMoreEagerlyThreshold != 100) { + try { + RetainedHeapLimiter.maybeInstallRetainedHeapLimiter(oomMoreEagerlyThreshold); + } catch (OptionsParsingException e) { + reporter.handle(Event.error(e.getMessage())); + return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode(); + } + } + // We register an ANSI-allowing handler associated with {@code handler} so that ANSI control // codes can be re-introduced later even if blaze is invoked with --color=no. This is useful // for commands such as 'blaze run' where the output of the final executable shouldn't be 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 2d5e8f0510..e37a6ec753 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 @@ -913,9 +913,6 @@ public final class BlazeRuntime { BlazeServerStartupOptions startupOptions = options.getOptions(BlazeServerStartupOptions.class); String productName = startupOptions.productName.toLowerCase(Locale.US); - if (startupOptions.oomMoreEagerlyThreshold != 100) { - new RetainedHeapLimiter(startupOptions.oomMoreEagerlyThreshold).install(); - } PathFragment workspaceDirectory = startupOptions.workspaceDirectory; PathFragment installBase = startupOptions.installBase; PathFragment outputBase = startupOptions.outputBase; diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java index 03932bb007..a5bb9d7531 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java @@ -209,7 +209,8 @@ public class BlazeServerStartupOptions extends OptionsBase { help = "If set, attempt to detect Java heap OOM conditions and exit before thrashing. Only " + "honored when --batch is also passed. In some cases, builds that previously " - + "succeeded may OOM if they were close to OOMing before." + + "succeeded may OOM if they were close to OOMing before. Deprecated: " + + "Use the command argument --experimental_oom_more_eagerly_threshold instead." ) public boolean oomMoreEagerly; @@ -220,8 +221,9 @@ public class BlazeServerStartupOptions extends OptionsBase { documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS, effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE, OptionEffectTag.EAGERNESS_TO_EXIT}, help = - "If this flag is set, Blaze will OOM if, after two full GC's, more than this " - + "percentage of the (old gen) heap is still occupied." + "If this flag is set, Blaze will OOM if, after two full GC's, more than this percentage of " + + "the (old gen) heap is still occupied. Deprecated: Use the command argument " + + "--experimental_oom_more_eagerly_threshold instead." ) public int oomMoreEagerlyThreshold; diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java index d5131c29d7..0800367703 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java @@ -287,6 +287,17 @@ public class CommonCommandOptions extends OptionsBase { public boolean gcWatchdog; @Option( + name = "experimental_oom_more_eagerly_threshold", + defaultValue = "100", + documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY, + effectTags = {OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS}, + help = + "If this flag is set to a value less than 100, Blaze will OOM if, after two full GC's, more" + + "than this percentage of the (old gen) heap is still occupied." + ) + public int oomMoreEagerlyThreshold; + + @Option( name = "startup_time", defaultValue = "0", documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/RetainedHeapLimiter.java b/src/main/java/com/google/devtools/build/lib/runtime/RetainedHeapLimiter.java index a98e540737..bdd594886f 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/RetainedHeapLimiter.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/RetainedHeapLimiter.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.runtime; import com.google.devtools.build.lib.util.Preconditions; +import com.google.devtools.common.options.OptionsParsingException; import com.sun.management.GarbageCollectionNotificationInfo; import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; @@ -38,6 +39,25 @@ class RetainedHeapLimiter implements NotificationListener { private static final Logger LOG = Logger.getLogger(RetainedHeapLimiter.class.getName()); private static final long MIN_TIME_BETWEEN_TRIGGERED_GC_MILLISECONDS = 60000; + private static int registeredOccupiedHeapPercentageThreshold = -1; + + static void maybeInstallRetainedHeapLimiter(int occupiedHeapPercentageThreshold) + throws OptionsParsingException { + if (registeredOccupiedHeapPercentageThreshold == -1) { + registeredOccupiedHeapPercentageThreshold = occupiedHeapPercentageThreshold; + new RetainedHeapLimiter(occupiedHeapPercentageThreshold).install(); + } + if (registeredOccupiedHeapPercentageThreshold != occupiedHeapPercentageThreshold) { + throw new OptionsParsingException( + "Old threshold of " + + registeredOccupiedHeapPercentageThreshold + + " not equal to new threshold of " + + occupiedHeapPercentageThreshold + + ". To change the threshold, shut down the server and restart it with the desired " + + "value"); + } + } + private boolean installed = false; private final AtomicBoolean throwingOom = new AtomicBoolean(false); private long lastTriggeredGcInMilliseconds = 0; |