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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 argv[i] = NULL; 2389 argv[i] = NULL;
2390 } else if (strcmp(argv[i], "--enable-tracing") == 0) { 2390 } else if (strcmp(argv[i], "--enable-tracing") == 0) {
2391 options.trace_enabled = true; 2391 options.trace_enabled = true;
2392 argv[i] = NULL; 2392 argv[i] = NULL;
2393 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) { 2393 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) {
2394 options.trace_config = argv[i] + 15; 2394 options.trace_config = argv[i] + 15;
2395 argv[i] = NULL; 2395 argv[i] = NULL;
2396 } else if (strcmp(argv[i], "--enable-inspector") == 0) { 2396 } else if (strcmp(argv[i], "--enable-inspector") == 0) {
2397 options.enable_inspector = true; 2397 options.enable_inspector = true;
2398 argv[i] = NULL; 2398 argv[i] = NULL;
2399 } else if (strncmp(argv[i], "--max-serializer-memory-usage=", 30) == 0) {
2400 options.max_serializer_memory_usage = atoi(argv[i] + 30);
2401 argv[i] = NULL;
2399 } 2402 }
2400 } 2403 }
2401 2404
2402 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 2405 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
2403 2406
2404 // Set up isolated source groups. 2407 // Set up isolated source groups.
2405 options.isolate_sources = new SourceGroup[options.num_isolates]; 2408 options.isolate_sources = new SourceGroup[options.num_isolates];
2406 SourceGroup* current = options.isolate_sources; 2409 SourceGroup* current = options.isolate_sources;
2407 current->Begin(argv, 1); 2410 current->Begin(argv, 1);
2408 for (int i = 1; i < argc; i++) { 2411 for (int i = 1; i < argc; i++) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 void Shell::EmptyMessageQueues(Isolate* isolate) { 2486 void Shell::EmptyMessageQueues(Isolate* isolate) {
2484 if (!i::FLAG_verify_predictable) { 2487 if (!i::FLAG_verify_predictable) {
2485 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; 2488 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue;
2486 v8::platform::RunIdleTasks(g_platform, isolate, 2489 v8::platform::RunIdleTasks(g_platform, isolate,
2487 50.0 / base::Time::kMillisecondsPerSecond); 2490 50.0 / base::Time::kMillisecondsPerSecond);
2488 } 2491 }
2489 } 2492 }
2490 2493
2491 class Serializer : public ValueSerializer::Delegate { 2494 class Serializer : public ValueSerializer::Delegate {
2492 public: 2495 public:
2493 explicit Serializer(Isolate* isolate) 2496 Serializer(Isolate* isolate, size_t max_memory_usage)
2494 : isolate_(isolate), serializer_(isolate, this) {} 2497 : isolate_(isolate),
2498 serializer_(isolate, this),
2499 max_memory_usage_(max_memory_usage),
2500 current_memory_usage_(0) {}
2495 2501
2496 Maybe<bool> WriteValue(Local<Context> context, Local<Value> value, 2502 Maybe<bool> WriteValue(Local<Context> context, Local<Value> value,
2497 Local<Value> transfer) { 2503 Local<Value> transfer) {
2498 bool ok; 2504 bool ok;
2499 DCHECK(!data_); 2505 DCHECK(!data_);
2500 data_.reset(new SerializationData); 2506 data_.reset(new SerializationData);
2501 if (!PrepareTransfer(context, transfer).To(&ok)) { 2507 if (!PrepareTransfer(context, transfer).To(&ok)) {
2502 return Nothing<bool>(); 2508 return Nothing<bool>();
2503 } 2509 }
2504 serializer_.WriteHeader(); 2510 serializer_.WriteHeader();
(...skipping 30 matching lines...) Expand all
2535 } 2541 }
2536 } 2542 }
2537 2543
2538 size_t index = shared_array_buffers_.size(); 2544 size_t index = shared_array_buffers_.size();
2539 shared_array_buffers_.emplace_back(isolate_, shared_array_buffer); 2545 shared_array_buffers_.emplace_back(isolate_, shared_array_buffer);
2540 return Just<uint32_t>(static_cast<uint32_t>(index)); 2546 return Just<uint32_t>(static_cast<uint32_t>(index));
2541 } 2547 }
2542 2548
2543 void* ReallocateBufferMemory(void* old_buffer, size_t size, 2549 void* ReallocateBufferMemory(void* old_buffer, size_t size,
2544 size_t* actual_size) override { 2550 size_t* actual_size) override {
2551 current_memory_usage_ += size;
Michael Achenbach 2017/02/15 09:35:24 You could nest the addition within a condition abo
binji 2017/02/15 20:31:55 Right, I added a comment about that.
2552 if (max_memory_usage_ != 0 && current_memory_usage_ > max_memory_usage_)
2553 return nullptr;
2554
2545 void* result = realloc(old_buffer, size); 2555 void* result = realloc(old_buffer, size);
2546 *actual_size = result ? size : 0; 2556 *actual_size = result ? size : 0;
2547 return result; 2557 return result;
2548 } 2558 }
2549 2559
2550 void FreeBufferMemory(void* buffer) override { free(buffer); } 2560 void FreeBufferMemory(void* buffer) override { free(buffer); }
2551 2561
2552 private: 2562 private:
2553 Maybe<bool> PrepareTransfer(Local<Context> context, Local<Value> transfer) { 2563 Maybe<bool> PrepareTransfer(Local<Context> context, Local<Value> transfer) {
2554 if (transfer->IsArray()) { 2564 if (transfer->IsArray()) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 } 2622 }
2613 2623
2614 return Just(true); 2624 return Just(true);
2615 } 2625 }
2616 2626
2617 Isolate* isolate_; 2627 Isolate* isolate_;
2618 ValueSerializer serializer_; 2628 ValueSerializer serializer_;
2619 std::unique_ptr<SerializationData> data_; 2629 std::unique_ptr<SerializationData> data_;
2620 std::vector<Global<ArrayBuffer>> array_buffers_; 2630 std::vector<Global<ArrayBuffer>> array_buffers_;
2621 std::vector<Global<SharedArrayBuffer>> shared_array_buffers_; 2631 std::vector<Global<SharedArrayBuffer>> shared_array_buffers_;
2632 size_t max_memory_usage_; /* For testing when memory exhaustion. */
Michael Achenbach 2017/02/15 09:35:24 nit: remove "when"?
binji 2017/02/15 20:31:55 Done.
2633 size_t current_memory_usage_;
2622 2634
2623 DISALLOW_COPY_AND_ASSIGN(Serializer); 2635 DISALLOW_COPY_AND_ASSIGN(Serializer);
2624 }; 2636 };
2625 2637
2626 class Deserializer : public ValueDeserializer::Delegate { 2638 class Deserializer : public ValueDeserializer::Delegate {
2627 public: 2639 public:
2628 Deserializer(Isolate* isolate, std::unique_ptr<SerializationData> data) 2640 Deserializer(Isolate* isolate, std::unique_ptr<SerializationData> data)
2629 : isolate_(isolate), 2641 : isolate_(isolate),
2630 deserializer_(isolate, data->data(), data->size(), this), 2642 deserializer_(isolate, data->data(), data->size(), this),
2631 data_(std::move(data)) { 2643 data_(std::move(data)) {
(...skipping 28 matching lines...) Expand all
2660 ValueDeserializer deserializer_; 2672 ValueDeserializer deserializer_;
2661 std::unique_ptr<SerializationData> data_; 2673 std::unique_ptr<SerializationData> data_;
2662 2674
2663 DISALLOW_COPY_AND_ASSIGN(Deserializer); 2675 DISALLOW_COPY_AND_ASSIGN(Deserializer);
2664 }; 2676 };
2665 2677
2666 std::unique_ptr<SerializationData> Shell::SerializeValue( 2678 std::unique_ptr<SerializationData> Shell::SerializeValue(
2667 Isolate* isolate, Local<Value> value, Local<Value> transfer) { 2679 Isolate* isolate, Local<Value> value, Local<Value> transfer) {
2668 bool ok; 2680 bool ok;
2669 Local<Context> context = isolate->GetCurrentContext(); 2681 Local<Context> context = isolate->GetCurrentContext();
2670 Serializer serializer(isolate); 2682 Serializer serializer(isolate, options.max_serializer_memory_usage);
2671 if (serializer.WriteValue(context, value, transfer).To(&ok)) { 2683 if (serializer.WriteValue(context, value, transfer).To(&ok)) {
2672 std::unique_ptr<SerializationData> data = serializer.Release(); 2684 std::unique_ptr<SerializationData> data = serializer.Release();
2673 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer()); 2685 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
2674 data->AppendExternalizedContentsTo(&externalized_contents_); 2686 data->AppendExternalizedContentsTo(&externalized_contents_);
2675 return data; 2687 return data;
2676 } 2688 }
2677 return nullptr; 2689 return nullptr;
2678 } 2690 }
2679 2691
2680 MaybeLocal<Value> Shell::DeserializeValue( 2692 MaybeLocal<Value> Shell::DeserializeValue(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 } 2940 }
2929 2941
2930 } // namespace v8 2942 } // namespace v8
2931 2943
2932 2944
2933 #ifndef GOOGLE3 2945 #ifndef GOOGLE3
2934 int main(int argc, char* argv[]) { 2946 int main(int argc, char* argv[]) {
2935 return v8::Shell::Main(argc, argv); 2947 return v8::Shell::Main(argc, argv);
2936 } 2948 }
2937 #endif 2949 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/mjsunit.status » ('j') | test/mjsunit/mjsunit.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698