Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 #ifndef CHECK | 59 #ifndef CHECK |
| 60 #define CHECK(condition) assert(condition) | 60 #define CHECK(condition) assert(condition) |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 namespace v8 { | 63 namespace v8 { |
| 64 | 64 |
| 65 namespace { | 65 namespace { |
| 66 | 66 |
| 67 const int MB = 1024 * 1024; | 67 const int MB = 1024 * 1024; |
| 68 const int kMaxWorkers = 50; | 68 const int kMaxWorkers = 50; |
| 69 const int kMaxSerializerMemoryUsage = 1 * MB; // Arbitrary maximum for testing. | |
| 69 | 70 |
| 70 #define USE_VM 1 | 71 #define USE_VM 1 |
| 71 #define VM_THRESHOLD 65536 | 72 #define VM_THRESHOLD 65536 |
| 72 // TODO(titzer): allocations should fail if >= 2gb because of | 73 // TODO(titzer): allocations should fail if >= 2gb because of |
| 73 // array buffers storing the lengths as a SMI internally. | 74 // array buffers storing the lengths as a SMI internally. |
| 74 #define TWO_GB (2u * 1024u * 1024u * 1024u) | 75 #define TWO_GB (2u * 1024u * 1024u * 1024u) |
| 75 | 76 |
| 76 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 77 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 77 public: | 78 public: |
| 78 virtual void* Allocate(size_t length) { | 79 virtual void* Allocate(size_t length) { |
| (...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2464 options.trace_enabled = true; | 2465 options.trace_enabled = true; |
| 2465 argv[i] = NULL; | 2466 argv[i] = NULL; |
| 2466 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) { | 2467 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) { |
| 2467 options.trace_config = argv[i] + 15; | 2468 options.trace_config = argv[i] + 15; |
| 2468 argv[i] = NULL; | 2469 argv[i] = NULL; |
| 2469 } else if (strcmp(argv[i], "--enable-inspector") == 0) { | 2470 } else if (strcmp(argv[i], "--enable-inspector") == 0) { |
| 2470 options.enable_inspector = true; | 2471 options.enable_inspector = true; |
| 2471 argv[i] = NULL; | 2472 argv[i] = NULL; |
| 2472 } else if (strncmp(argv[i], "--lcov=", 7) == 0) { | 2473 } else if (strncmp(argv[i], "--lcov=", 7) == 0) { |
| 2473 options.lcov_file = argv[i] + 7; | 2474 options.lcov_file = argv[i] + 7; |
| 2474 argv[i] = NULL; | |
|
Yang
2017/02/16 07:59:32
Accidental change?
binji
2017/02/17 00:49:13
Oops, fixed.
| |
| 2475 } | 2475 } |
| 2476 } | 2476 } |
| 2477 | 2477 |
| 2478 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 2478 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 2479 | 2479 |
| 2480 // Set up isolated source groups. | 2480 // Set up isolated source groups. |
| 2481 options.isolate_sources = new SourceGroup[options.num_isolates]; | 2481 options.isolate_sources = new SourceGroup[options.num_isolates]; |
| 2482 SourceGroup* current = options.isolate_sources; | 2482 SourceGroup* current = options.isolate_sources; |
| 2483 current->Begin(argv, 1); | 2483 current->Begin(argv, 1); |
| 2484 for (int i = 1; i < argc; i++) { | 2484 for (int i = 1; i < argc; i++) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2564 if (!i::FLAG_verify_predictable) { | 2564 if (!i::FLAG_verify_predictable) { |
| 2565 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; | 2565 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; |
| 2566 v8::platform::RunIdleTasks(g_platform, isolate, | 2566 v8::platform::RunIdleTasks(g_platform, isolate, |
| 2567 50.0 / base::Time::kMillisecondsPerSecond); | 2567 50.0 / base::Time::kMillisecondsPerSecond); |
| 2568 } | 2568 } |
| 2569 } | 2569 } |
| 2570 | 2570 |
| 2571 class Serializer : public ValueSerializer::Delegate { | 2571 class Serializer : public ValueSerializer::Delegate { |
| 2572 public: | 2572 public: |
| 2573 explicit Serializer(Isolate* isolate) | 2573 explicit Serializer(Isolate* isolate) |
| 2574 : isolate_(isolate), serializer_(isolate, this) {} | 2574 : isolate_(isolate), |
| 2575 serializer_(isolate, this), | |
| 2576 current_memory_usage_(0) {} | |
| 2575 | 2577 |
| 2576 Maybe<bool> WriteValue(Local<Context> context, Local<Value> value, | 2578 Maybe<bool> WriteValue(Local<Context> context, Local<Value> value, |
| 2577 Local<Value> transfer) { | 2579 Local<Value> transfer) { |
| 2578 bool ok; | 2580 bool ok; |
| 2579 DCHECK(!data_); | 2581 DCHECK(!data_); |
| 2580 data_.reset(new SerializationData); | 2582 data_.reset(new SerializationData); |
| 2581 if (!PrepareTransfer(context, transfer).To(&ok)) { | 2583 if (!PrepareTransfer(context, transfer).To(&ok)) { |
| 2582 return Nothing<bool>(); | 2584 return Nothing<bool>(); |
| 2583 } | 2585 } |
| 2584 serializer_.WriteHeader(); | 2586 serializer_.WriteHeader(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2615 } | 2617 } |
| 2616 } | 2618 } |
| 2617 | 2619 |
| 2618 size_t index = shared_array_buffers_.size(); | 2620 size_t index = shared_array_buffers_.size(); |
| 2619 shared_array_buffers_.emplace_back(isolate_, shared_array_buffer); | 2621 shared_array_buffers_.emplace_back(isolate_, shared_array_buffer); |
| 2620 return Just<uint32_t>(static_cast<uint32_t>(index)); | 2622 return Just<uint32_t>(static_cast<uint32_t>(index)); |
| 2621 } | 2623 } |
| 2622 | 2624 |
| 2623 void* ReallocateBufferMemory(void* old_buffer, size_t size, | 2625 void* ReallocateBufferMemory(void* old_buffer, size_t size, |
| 2624 size_t* actual_size) override { | 2626 size_t* actual_size) override { |
| 2627 // Not accurate, because we don't take into account reallocated buffers, | |
| 2628 // but this is fine for testing. | |
| 2629 current_memory_usage_ += size; | |
| 2630 if (current_memory_usage_ > kMaxSerializerMemoryUsage) return nullptr; | |
| 2631 | |
| 2625 void* result = realloc(old_buffer, size); | 2632 void* result = realloc(old_buffer, size); |
| 2626 *actual_size = result ? size : 0; | 2633 *actual_size = result ? size : 0; |
| 2627 return result; | 2634 return result; |
| 2628 } | 2635 } |
| 2629 | 2636 |
| 2630 void FreeBufferMemory(void* buffer) override { free(buffer); } | 2637 void FreeBufferMemory(void* buffer) override { free(buffer); } |
| 2631 | 2638 |
| 2632 private: | 2639 private: |
| 2633 Maybe<bool> PrepareTransfer(Local<Context> context, Local<Value> transfer) { | 2640 Maybe<bool> PrepareTransfer(Local<Context> context, Local<Value> transfer) { |
| 2634 if (transfer->IsArray()) { | 2641 if (transfer->IsArray()) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2692 } | 2699 } |
| 2693 | 2700 |
| 2694 return Just(true); | 2701 return Just(true); |
| 2695 } | 2702 } |
| 2696 | 2703 |
| 2697 Isolate* isolate_; | 2704 Isolate* isolate_; |
| 2698 ValueSerializer serializer_; | 2705 ValueSerializer serializer_; |
| 2699 std::unique_ptr<SerializationData> data_; | 2706 std::unique_ptr<SerializationData> data_; |
| 2700 std::vector<Global<ArrayBuffer>> array_buffers_; | 2707 std::vector<Global<ArrayBuffer>> array_buffers_; |
| 2701 std::vector<Global<SharedArrayBuffer>> shared_array_buffers_; | 2708 std::vector<Global<SharedArrayBuffer>> shared_array_buffers_; |
| 2709 size_t current_memory_usage_; | |
| 2702 | 2710 |
| 2703 DISALLOW_COPY_AND_ASSIGN(Serializer); | 2711 DISALLOW_COPY_AND_ASSIGN(Serializer); |
| 2704 }; | 2712 }; |
| 2705 | 2713 |
| 2706 class Deserializer : public ValueDeserializer::Delegate { | 2714 class Deserializer : public ValueDeserializer::Delegate { |
| 2707 public: | 2715 public: |
| 2708 Deserializer(Isolate* isolate, std::unique_ptr<SerializationData> data) | 2716 Deserializer(Isolate* isolate, std::unique_ptr<SerializationData> data) |
| 2709 : isolate_(isolate), | 2717 : isolate_(isolate), |
| 2710 deserializer_(isolate, data->data(), data->size(), this), | 2718 deserializer_(isolate, data->data(), data->size(), this), |
| 2711 data_(std::move(data)) { | 2719 data_(std::move(data)) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3001 } | 3009 } |
| 3002 | 3010 |
| 3003 } // namespace v8 | 3011 } // namespace v8 |
| 3004 | 3012 |
| 3005 | 3013 |
| 3006 #ifndef GOOGLE3 | 3014 #ifndef GOOGLE3 |
| 3007 int main(int argc, char* argv[]) { | 3015 int main(int argc, char* argv[]) { |
| 3008 return v8::Shell::Main(argc, argv); | 3016 return v8::Shell::Main(argc, argv); |
| 3009 } | 3017 } |
| 3010 #endif | 3018 #endif |
| OLD | NEW |