From 4dfd5e5ee22693d5c4efc2ef2df369a04f762e15 Mon Sep 17 00:00:00 2001 From: binji Date: Fri, 17 Feb 2017 10:55:54 -0800 Subject: [PATCH] Make regress-crbug-514081 less flaky by having max serialization size BUG=v8:5906 R=machenbach@chromium.org Review-Url: https://codereview.chromium.org/2697723004 Cr-Commit-Position: refs/heads/master@{#43292} --- src/d8.cc | 11 ++++++++++- test/mjsunit/mjsunit.status | 3 --- test/mjsunit/regress/regress-crbug-514081.js | 16 +++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/d8.cc b/src/d8.cc index 1f35210f8a..a37eb9f9d1 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -66,6 +66,7 @@ namespace { const int MB = 1024 * 1024; const int kMaxWorkers = 50; +const int kMaxSerializerMemoryUsage = 1 * MB; // Arbitrary maximum for testing. #define USE_VM 1 #define VM_THRESHOLD 65536 @@ -2567,7 +2568,9 @@ void Shell::EmptyMessageQueues(Isolate* isolate) { class Serializer : public ValueSerializer::Delegate { public: explicit Serializer(Isolate* isolate) - : isolate_(isolate), serializer_(isolate, this) {} + : isolate_(isolate), + serializer_(isolate, this), + current_memory_usage_(0) {} Maybe WriteValue(Local context, Local value, Local transfer) { @@ -2618,6 +2621,11 @@ class Serializer : public ValueSerializer::Delegate { void* ReallocateBufferMemory(void* old_buffer, size_t size, size_t* actual_size) override { + // Not accurate, because we don't take into account reallocated buffers, + // but this is fine for testing. + current_memory_usage_ += size; + if (current_memory_usage_ > kMaxSerializerMemoryUsage) return nullptr; + void* result = realloc(old_buffer, size); *actual_size = result ? size : 0; return result; @@ -2695,6 +2703,7 @@ class Serializer : public ValueSerializer::Delegate { std::unique_ptr data_; std::vector> array_buffers_; std::vector> shared_array_buffers_; + size_t current_memory_usage_; DISALLOW_COPY_AND_ASSIGN(Serializer); }; diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index 2b014f9123..75070c3b89 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -172,9 +172,6 @@ # BUG(v8:5807): Flaky data race. 'wasm/embenchen/fannkuch': [PASS, ['tsan', SKIP]], - - # BUG(v8:5906). - 'regress/regress-crbug-514081': [PASS, ['system == linux', SKIP]], }], # ALWAYS ['novfp3 == True', { diff --git a/test/mjsunit/regress/regress-crbug-514081.js b/test/mjsunit/regress/regress-crbug-514081.js index af31f4b9c6..ee3ed81300 100644 --- a/test/mjsunit/regress/regress-crbug-514081.js +++ b/test/mjsunit/regress/regress-crbug-514081.js @@ -5,16 +5,14 @@ if (this.Worker) { var __v_7 = new Worker('onmessage = function() {};'); var e; + var ab = new ArrayBuffer(2 * 1000 * 1000); try { - var ab = new ArrayBuffer(2147483648); - try { - __v_7.postMessage(ab); - } catch (e) { - // postMessage failed, should be a DataCloneError message. - assertContains('cloned', e.message); - } + __v_7.postMessage(ab); + threw = false; } catch (e) { - // Creating the ArrayBuffer failed. - assertInstanceof(e, RangeError); + // postMessage failed, should be a DataCloneError message. + assertContains('cloned', e.message); + threw = true; } + assertTrue(threw, 'Should throw when trying to serialize large message.'); }