⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 263290 in webkit


Ignore:
Timestamp:
Jun 19, 2020, 3:13:47 PM (6 years ago)
Author:
sbarati@apple.com
Message:

Have a memory monitor thread in jsc shell when running tests using --memory-limited
https://bugs.webkit.org/show_bug.cgi?id=213389

Reviewed by Mark Lam.

Source/JavaScriptCore:

When testing on iOS, there are times high memory usage from a JSC test
will jetsam our entire test runner. This makes it so we don't get any test
results from that test run, which can make it difficult to track testing
results.

This patch introduces an optional memory monitoring thread to the JSC
shell. It's a best effort approach. If memory usage exceeds the passed
in threshold, we crash the process. Similar to how the timeout mechanism
works. On Cocoa platforms, we also perform this check in the low memory
warning handler.

Currently, we use this feature when running JSC stress tests in
"--memory-limited" mode.

  • jsc.cpp:

(crashIfExceedingMemoryLimit):
(startMemoryMonitoringThreadIfNeeded):
(jscmain):

Tools:

  • Scripts/run-jsc-stress-tests:
  • Scripts/webkitruby/jsc-stress-test-writer-default.rb:
  • Scripts/webkitruby/jsc-stress-test-writer-ruby.rb:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r263283 r263290  
     12020-06-19  Saam Barati  <sbarati@apple.com>
     2
     3        Have a memory monitor thread in jsc shell when running tests using --memory-limited
     4        https://bugs.webkit.org/show_bug.cgi?id=213389
     5
     6        Reviewed by Mark Lam.
     7
     8        When testing on iOS, there are times high memory usage from a JSC test
     9        will jetsam our entire test runner. This makes it so we don't get any test
     10        results from that test run, which can make it difficult to track testing
     11        results.
     12       
     13        This patch introduces an optional memory monitoring thread to the JSC
     14        shell. It's a best effort approach. If memory usage exceeds the passed
     15        in threshold, we crash the process. Similar to how the timeout mechanism
     16        works. On Cocoa platforms, we also perform this check in the low memory
     17        warning handler.
     18       
     19        Currently, we use this feature when running JSC stress tests in
     20        "--memory-limited" mode.
     21
     22        * jsc.cpp:
     23        (crashIfExceedingMemoryLimit):
     24        (startMemoryMonitoringThreadIfNeeded):
     25        (jscmain):
     26
    1272020-06-19  Mark Lam  <mark.lam@apple.com>
    228
  • trunk/Source/JavaScriptCore/jsc.cpp

    r263117 r263290  
    24972497int jscmain(int argc, char** argv);
    24982498
     2499#if OS(DARWIN) || OS(LINUX)
     2500static size_t memoryLimit;
     2501
     2502static void crashIfExceedingMemoryLimit()
     2503{
     2504    if (!memoryLimit)
     2505        return;
     2506    MemoryFootprint footprint = MemoryFootprint::now();
     2507    if (footprint.current > memoryLimit) {
     2508        dataLogLn("Crashing because current footprint: ", footprint.current, " exceeds limit: ", memoryLimit);
     2509        CRASH();
     2510    }
     2511}
     2512
     2513static void startMemoryMonitoringThreadIfNeeded()
     2514{
     2515    char* memoryLimitString = getenv("JSCTEST_memoryLimit");
     2516    if (!memoryLimitString)
     2517        return;
     2518
     2519    if (sscanf(memoryLimitString, "%zu", &memoryLimit) != 1) {
     2520        dataLogLn("WARNING: malformed JSCTEST_memoryLimit environment variable");
     2521        return;
     2522    }
     2523
     2524    if (!memoryLimit)
     2525        return;
     2526
     2527    Thread::create("jsc Memory Monitor", [=] {
     2528        while (true) {
     2529            sleep(Seconds::fromMilliseconds(5));
     2530            crashIfExceedingMemoryLimit();
     2531        }
     2532    });
     2533}
     2534#endif // OS(DARWIN) || OS(LINUX)
     2535
    24992536static double s_desiredTimeout;
    25002537static double s_timeoutMultiplier = 1.0;
     
    32543291    initializeTimeoutIfNeeded();
    32553292
     3293#if OS(DARWIN) || OS(LINUX)
     3294    startMemoryMonitoringThreadIfNeeded();
     3295#endif
     3296
    32563297    if (Options::useSuperSampler())
    32573298        enableSuperSampler();
     
    32773318    Box<Synchronous> memoryPressureSynchronousState = Box<Synchronous>::create(Synchronous::No);
    32783319    memoryPressureHandler.setLowMemoryHandler([=] (Critical critical, Synchronous synchronous) {
     3320        crashIfExceedingMemoryLimit();
     3321
    32793322        // We set these racily with respect to reading them from the JS execution thread.
    32803323        *memoryPressureCriticalState = critical;
  • trunk/Tools/ChangeLog

    r263275 r263290  
     12020-06-19  Saam Barati  <sbarati@apple.com>
     2
     3        Have a memory monitor thread in jsc shell when running tests using --memory-limited
     4        https://bugs.webkit.org/show_bug.cgi?id=213389
     5
     6        Reviewed by Mark Lam.
     7
     8        * Scripts/run-jsc-stress-tests:
     9        * Scripts/webkitruby/jsc-stress-test-writer-default.rb:
     10        * Scripts/webkitruby/jsc-stress-test-writer-ruby.rb:
     11
    1122020-06-19  Chris Fleizach  <cfleizach@apple.com>
    213
  • trunk/Tools/Scripts/run-jsc-stress-tests

    r263235 r263290  
    20922092        remoteScript += "export LD_LIBRARY_PATH=#{remoteHost.remoteDirectory}/#{$outputDir.basename}/#{$jscPath.dirname} && "
    20932093        remoteScript += "export JSCTEST_timeout=#{Shellwords.shellescape(ENV['JSCTEST_timeout'])} && "
     2094        remoteScript += "export JSCTEST_memoryLimit=#{Shellwords.shellescape(ENV['JSCTEST_memoryLimit'])} && "
    20942095        remoteScript += "export TZ=#{Shellwords.shellescape(ENV['TZ'])} && "
    20952096        $envVars.each { |var| remoteScript += "export " << var << "\n" }
     
    22242225end
    22252226
     2227if !ENV["JSCTEST_memoryLimit"] && $memoryLimited
     2228    ENV["JSCTEST_memoryLimit"] = (600 * 1024 * 1024).to_s
     2229end
     2230
    22262231# Some tests fail if the time zone is not set to US/Pacific
    22272232# https://webkit.org/b/136363
  • trunk/Tools/Scripts/webkitruby/jsc-stress-test-writer-default.rb

    r262991 r263290  
    257257        script += "export DYLD_FRAMEWORK_PATH=$(cd #{$testingFrameworkPath.dirname}; pwd)\n"
    258258        script += "export JSCTEST_timeout=#{Shellwords.shellescape(ENV['JSCTEST_timeout'])}\n"
     259        script += "export JSCTEST_memoryLimit=#{Shellwords.shellescape(ENV['JSCTEST_memoryLimit'])}\n"
    259260        $envVars.each { |var| script += "export " << var << "\n" }
    260261        script += "#{shellCommand} || exit 1"
  • trunk/Tools/Scripts/webkitruby/jsc-stress-test-writer-ruby.rb

    r262991 r263290  
    314314        script += "            ENV[\"DYLD_FRAMEWORK_PATH\"] = \"#{$testingFrameworkPath.dirname}\"\n"
    315315        script += "            ENV[\"JSCTEST_timeout\"] = \"#{ENV['JSCTEST_timeout']}\"\n"
     316        script += "            ENV[\"JSCTEST_memoryLimit\"] = \"#{ENV['JSCTEST_memoryLimit']}\"\n"
    316317
    317318        script += "            #{shellCommand}"
Note: See TracChangeset for help on using the changeset viewer.