Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: src/d8.cc

Issue 2697723004: Make regress-crbug-514081 less flaky by having max serialization size (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 1f35210f8a22ec45090de562e486b9a8a208db20..a37eb9f9d1fbf6eddb4f9d85a7d82f379d3bacee 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<bool> WriteValue(Local<Context> context, Local<Value> value,
Local<Value> 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<SerializationData> data_;
std::vector<Global<ArrayBuffer>> array_buffers_;
std::vector<Global<SharedArrayBuffer>> shared_array_buffers_;
+ size_t current_memory_usage_;
DISALLOW_COPY_AND_ASSIGN(Serializer);
};
« no previous file with comments | « no previous file | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698