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 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void* data = AllocateUninitialized(actual_length); | 94 void* data = AllocateUninitialized(actual_length); |
95 return data == NULL ? data : memset(data, 0, actual_length); | 95 return data == NULL ? data : memset(data, 0, actual_length); |
96 } | 96 } |
97 void* AllocateUninitialized(size_t length) override { | 97 void* AllocateUninitialized(size_t length) override { |
98 return length > 10 * MB ? malloc(1) : malloc(length); | 98 return length > 10 * MB ? malloc(1) : malloc(length); |
99 } | 99 } |
100 void Free(void* p, size_t) override { free(p); } | 100 void Free(void* p, size_t) override { free(p); } |
101 }; | 101 }; |
102 | 102 |
103 | 103 |
| 104 #ifndef V8_SHARED |
| 105 // Predictable v8::Platform implementation. All background and foreground |
| 106 // tasks are run immediately, delayed tasks are not executed at all. |
| 107 class PredictablePlatform : public Platform { |
| 108 public: |
| 109 PredictablePlatform() {} |
| 110 |
| 111 void CallOnBackgroundThread(Task* task, |
| 112 ExpectedRuntime expected_runtime) override { |
| 113 task->Run(); |
| 114 delete task; |
| 115 } |
| 116 |
| 117 void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { |
| 118 task->Run(); |
| 119 delete task; |
| 120 } |
| 121 |
| 122 void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task, |
| 123 double delay_in_seconds) override { |
| 124 delete task; |
| 125 } |
| 126 |
| 127 void CallIdleOnForegroundThread(v8::Isolate* isolate, |
| 128 IdleTask* task) override { |
| 129 UNREACHABLE(); |
| 130 } |
| 131 |
| 132 bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; } |
| 133 |
| 134 double MonotonicallyIncreasingTime() override { |
| 135 return synthetic_time_in_sec_ += 0.00001; |
| 136 } |
| 137 |
| 138 private: |
| 139 double synthetic_time_in_sec_ = 0.0; |
| 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(PredictablePlatform); |
| 142 }; |
| 143 #endif // !V8_SHARED |
| 144 |
| 145 |
104 v8::Platform* g_platform = NULL; | 146 v8::Platform* g_platform = NULL; |
105 | 147 |
106 | 148 |
107 static Local<Value> Throw(Isolate* isolate, const char* message) { | 149 static Local<Value> Throw(Isolate* isolate, const char* message) { |
108 return isolate->ThrowException( | 150 return isolate->ThrowException( |
109 String::NewFromUtf8(isolate, message, NewStringType::kNormal) | 151 String::NewFromUtf8(isolate, message, NewStringType::kNormal) |
110 .ToLocalChecked()); | 152 .ToLocalChecked()); |
111 } | 153 } |
112 | 154 |
113 | 155 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (index < 0 || index >= realm_count_ || realms_[index].IsEmpty()) { | 460 if (index < 0 || index >= realm_count_ || realms_[index].IsEmpty()) { |
419 Throw(args.GetIsolate(), "Invalid realm index"); | 461 Throw(args.GetIsolate(), "Invalid realm index"); |
420 return -1; | 462 return -1; |
421 } | 463 } |
422 return index; | 464 return index; |
423 } | 465 } |
424 | 466 |
425 | 467 |
426 #ifndef V8_SHARED | 468 #ifndef V8_SHARED |
427 // performance.now() returns a time stamp as double, measured in milliseconds. | 469 // performance.now() returns a time stamp as double, measured in milliseconds. |
428 // When FLAG_verify_predictable mode is enabled it returns current value | 470 // When FLAG_verify_predictable mode is enabled it returns result of |
429 // of Heap::allocations_count(). | 471 // v8::Platform::MonotonicallyIncreasingTime(). |
430 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { | 472 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { |
431 if (i::FLAG_verify_predictable) { | 473 if (i::FLAG_verify_predictable) { |
432 Isolate* v8_isolate = args.GetIsolate(); | 474 args.GetReturnValue().Set(g_platform->MonotonicallyIncreasingTime()); |
433 i::Heap* heap = reinterpret_cast<i::Isolate*>(v8_isolate)->heap(); | |
434 args.GetReturnValue().Set(heap->synthetic_time()); | |
435 } else { | 475 } else { |
436 base::TimeDelta delta = | 476 base::TimeDelta delta = |
437 base::TimeTicks::HighResolutionNow() - kInitialTicks; | 477 base::TimeTicks::HighResolutionNow() - kInitialTicks; |
438 args.GetReturnValue().Set(delta.InMillisecondsF()); | 478 args.GetReturnValue().Set(delta.InMillisecondsF()); |
439 } | 479 } |
440 } | 480 } |
441 #endif // !V8_SHARED | 481 #endif // !V8_SHARED |
442 | 482 |
443 | 483 |
444 // Realm.current() returns the index of the currently active realm. | 484 // Realm.current() returns the index of the currently active realm. |
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 if (options.invoke_weak_callbacks) { | 2049 if (options.invoke_weak_callbacks) { |
2010 // By sending a low memory notifications, we will try hard to collect all | 2050 // By sending a low memory notifications, we will try hard to collect all |
2011 // garbage and will therefore also invoke all weak callbacks of actually | 2051 // garbage and will therefore also invoke all weak callbacks of actually |
2012 // unreachable persistent handles. | 2052 // unreachable persistent handles. |
2013 isolate->LowMemoryNotification(); | 2053 isolate->LowMemoryNotification(); |
2014 } | 2054 } |
2015 } | 2055 } |
2016 | 2056 |
2017 | 2057 |
2018 void Shell::EmptyMessageQueues(Isolate* isolate) { | 2058 void Shell::EmptyMessageQueues(Isolate* isolate) { |
2019 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; | 2059 #ifndef V8_SHARED |
| 2060 if (!i::FLAG_verify_predictable) { |
| 2061 #endif |
| 2062 while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; |
| 2063 #ifndef V8_SHARED |
| 2064 } |
| 2065 #endif |
2020 } | 2066 } |
2021 | 2067 |
2022 | 2068 |
2023 #ifndef V8_SHARED | 2069 #ifndef V8_SHARED |
2024 bool Shell::SerializeValue(Isolate* isolate, Local<Value> value, | 2070 bool Shell::SerializeValue(Isolate* isolate, Local<Value> value, |
2025 const ObjectList& to_transfer, | 2071 const ObjectList& to_transfer, |
2026 ObjectList* seen_objects, | 2072 ObjectList* seen_objects, |
2027 SerializationData* out_data) { | 2073 SerializationData* out_data) { |
2028 DCHECK(out_data); | 2074 DCHECK(out_data); |
2029 Local<Context> context = isolate->GetCurrentContext(); | 2075 Local<Context> context = isolate->GetCurrentContext(); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 2397 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
2352 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); | 2398 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); |
2353 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | 2399 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
2354 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); | 2400 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); |
2355 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | 2401 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
2356 _set_error_mode(_OUT_TO_STDERR); | 2402 _set_error_mode(_OUT_TO_STDERR); |
2357 #endif // defined(_MSC_VER) | 2403 #endif // defined(_MSC_VER) |
2358 #endif // defined(_WIN32) || defined(_WIN64) | 2404 #endif // defined(_WIN32) || defined(_WIN64) |
2359 if (!SetOptions(argc, argv)) return 1; | 2405 if (!SetOptions(argc, argv)) return 1; |
2360 v8::V8::InitializeICU(options.icu_data_file); | 2406 v8::V8::InitializeICU(options.icu_data_file); |
| 2407 #ifndef V8_SHARED |
| 2408 g_platform = i::FLAG_verify_predictable |
| 2409 ? new PredictablePlatform() |
| 2410 : v8::platform::CreateDefaultPlatform(); |
| 2411 #else |
2361 g_platform = v8::platform::CreateDefaultPlatform(); | 2412 g_platform = v8::platform::CreateDefaultPlatform(); |
| 2413 #endif // !V8_SHARED |
| 2414 |
2362 v8::V8::InitializePlatform(g_platform); | 2415 v8::V8::InitializePlatform(g_platform); |
2363 v8::V8::Initialize(); | 2416 v8::V8::Initialize(); |
2364 if (options.natives_blob || options.snapshot_blob) { | 2417 if (options.natives_blob || options.snapshot_blob) { |
2365 v8::V8::InitializeExternalStartupData(options.natives_blob, | 2418 v8::V8::InitializeExternalStartupData(options.natives_blob, |
2366 options.snapshot_blob); | 2419 options.snapshot_blob); |
2367 } else { | 2420 } else { |
2368 v8::V8::InitializeExternalStartupData(argv[0]); | 2421 v8::V8::InitializeExternalStartupData(argv[0]); |
2369 } | 2422 } |
2370 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); | 2423 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
2371 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); | 2424 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2476 } | 2529 } |
2477 | 2530 |
2478 } // namespace v8 | 2531 } // namespace v8 |
2479 | 2532 |
2480 | 2533 |
2481 #ifndef GOOGLE3 | 2534 #ifndef GOOGLE3 |
2482 int main(int argc, char* argv[]) { | 2535 int main(int argc, char* argv[]) { |
2483 return v8::Shell::Main(argc, argv); | 2536 return v8::Shell::Main(argc, argv); |
2484 } | 2537 } |
2485 #endif | 2538 #endif |
OLD | NEW |