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

Side by Side Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc

Issue 2573493002: Use idle time to make progress on scheduled compilation jobs (Closed)
Patch Set: Created 4 years 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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "include/v8-platform.h"
7 #include "src/compiler-dispatcher/compiler-dispatcher.h" 8 #include "src/compiler-dispatcher/compiler-dispatcher.h"
8 #include "src/flags.h" 9 #include "src/flags.h"
9 #include "src/handles.h" 10 #include "src/handles.h"
10 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
11 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" 12 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h"
12 #include "test/unittests/test-utils.h" 13 #include "test/unittests/test-utils.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 18
18 typedef TestWithContext CompilerDispatcherTest; 19 typedef TestWithContext CompilerDispatcherTest;
19 20
21 namespace {
22
23 class MockPlatform : public v8::Platform {
24 public:
25 MockPlatform() : task_(nullptr), time_(0.0) {}
26 ~MockPlatform() override = default;
27
28 void CallOnBackgroundThread(Task* task,
29 ExpectedRuntime expected_runtime) override {
30 UNREACHABLE();
31 }
32
33 void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
34 UNREACHABLE();
35 }
36
37 void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task,
38 double delay_in_seconds) override {
39 UNREACHABLE();
40 }
41
42 void CallIdleOnForegroundThread(v8::Isolate* isolate,
43 IdleTask* task) override {
44 task_ = task;
45 }
46
47 bool IdleTasksEnabled(v8::Isolate* isolate) override { return true; }
48
49 double MonotonicallyIncreasingTime() override { return time_; }
50
51 void RunIdleTask(double deadline_in_seconds) {
52 ASSERT_TRUE(task_ != nullptr);
53 IdleTask* task = task_;
54 task_ = nullptr;
55 task->Run(deadline_in_seconds);
56 delete task;
57 }
58
59 bool IdleTaskPending() const { return !!task_; }
60
61 void set_time(double time) { time_ = time; }
62
63 private:
64 IdleTask* task_;
65 double time_;
66
67 DISALLOW_COPY_AND_ASSIGN(MockPlatform);
68 };
69
70 } // namespace
71
20 TEST_F(CompilerDispatcherTest, Construct) { 72 TEST_F(CompilerDispatcherTest, Construct) {
73 std::unique_ptr<MockPlatform> platform(new MockPlatform);
vogelheim 2016/12/12 17:51:32 [Here & below:] Why not just have stack allocated
jochen (gone - plz use gerrit) 2016/12/15 13:54:34 done
21 std::unique_ptr<CompilerDispatcher> dispatcher( 74 std::unique_ptr<CompilerDispatcher> dispatcher(
22 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); 75 new CompilerDispatcher(i_isolate(), platform.get(), FLAG_stack_size));
23 } 76 }
24 77
25 TEST_F(CompilerDispatcherTest, IsEnqueued) { 78 TEST_F(CompilerDispatcherTest, IsEnqueued) {
79 std::unique_ptr<MockPlatform> platform(new MockPlatform);
26 std::unique_ptr<CompilerDispatcher> dispatcher( 80 std::unique_ptr<CompilerDispatcher> dispatcher(
27 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); 81 new CompilerDispatcher(i_isolate(), platform.get(), FLAG_stack_size));
28 82
29 const char script[] = 83 const char script[] =
30 "function g() { var y = 1; function f(x) { return x * y }; return f; } " 84 "function g() { var y = 1; function f(x) { return x * y }; return f; } "
31 "g();"; 85 "g();";
32 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 86 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
33 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 87 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
34 88
35 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); 89 ASSERT_FALSE(dispatcher->IsEnqueued(shared));
36 ASSERT_TRUE(dispatcher->Enqueue(shared)); 90 ASSERT_TRUE(dispatcher->Enqueue(shared));
37 ASSERT_TRUE(dispatcher->IsEnqueued(shared)); 91 ASSERT_TRUE(dispatcher->IsEnqueued(shared));
38 dispatcher->Abort(shared, CompilerDispatcher::BlockingBehavior::kBlock); 92 dispatcher->Abort(shared, CompilerDispatcher::BlockingBehavior::kBlock);
39 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); 93 ASSERT_FALSE(dispatcher->IsEnqueued(shared));
40 } 94 }
41 95
42 TEST_F(CompilerDispatcherTest, FinishNow) { 96 TEST_F(CompilerDispatcherTest, FinishNow) {
97 std::unique_ptr<MockPlatform> platform(new MockPlatform);
43 std::unique_ptr<CompilerDispatcher> dispatcher( 98 std::unique_ptr<CompilerDispatcher> dispatcher(
44 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); 99 new CompilerDispatcher(i_isolate(), platform.get(), FLAG_stack_size));
45 100
46 const char script[] = 101 const char script[] =
47 "function g() { var y = 1; function f(x) { return x * y }; return f; } " 102 "function g() { var y = 1; function f(x) { return x * y }; return f; } "
48 "g();"; 103 "g();";
49 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 104 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
50 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 105 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
51 106
52 ASSERT_FALSE(shared->HasBaselineCode()); 107 ASSERT_FALSE(shared->HasBaselineCode());
53 ASSERT_TRUE(dispatcher->Enqueue(shared)); 108 ASSERT_TRUE(dispatcher->Enqueue(shared));
54 ASSERT_TRUE(dispatcher->FinishNow(shared)); 109 ASSERT_TRUE(dispatcher->FinishNow(shared));
55 // Finishing removes the SFI from the queue. 110 // Finishing removes the SFI from the queue.
56 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); 111 ASSERT_FALSE(dispatcher->IsEnqueued(shared));
57 ASSERT_TRUE(shared->HasBaselineCode()); 112 ASSERT_TRUE(shared->HasBaselineCode());
58 } 113 }
59 114
115 TEST_F(CompilerDispatcherTest, IdleTask) {
116 std::unique_ptr<MockPlatform> platform(new MockPlatform);
117 std::unique_ptr<CompilerDispatcher> dispatcher(
118 new CompilerDispatcher(i_isolate(), platform.get(), FLAG_stack_size));
119
120 const char script[] =
121 "function g() { var y = 1; function f(x) { return x * y }; return f; } "
122 "g();";
123 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
124 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
125
126 ASSERT_FALSE(platform->IdleTaskPending());
127 ASSERT_TRUE(dispatcher->Enqueue(shared));
128 ASSERT_TRUE(platform->IdleTaskPending());
129
130 // Since time doesn't progress on the MockPlatform, this is enough idle time
131 // to finish compiling the function.
132 platform->RunIdleTask(1000.0);
133
134 ASSERT_FALSE(dispatcher->IsEnqueued(shared));
135 ASSERT_TRUE(shared->HasBaselineCode());
136 }
137
138 TEST_F(CompilerDispatcherTest, IdleTaskException) {
139 std::unique_ptr<MockPlatform> platform(new MockPlatform);
140 std::unique_ptr<CompilerDispatcher> dispatcher(
141 new CompilerDispatcher(i_isolate(), platform.get(), 50));
142
143 std::string script("function g() { function f(x) { var a = ");
144 for (int i = 0; i < 1000; i++) {
145 script += "'x' + ";
146 }
147 script += " 'x'; }; return f; } g();";
148 Handle<JSFunction> f =
149 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str()));
150 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
151
152 ASSERT_FALSE(platform->IdleTaskPending());
153 ASSERT_TRUE(dispatcher->Enqueue(shared));
154 ASSERT_TRUE(platform->IdleTaskPending());
155
156 // Idle tasks shouldn't leave exceptions behind.
157 v8::TryCatch try_catch(isolate());
158
159 // Since time doesn't progress on the MockPlatform, this is enough idle time
160 // to finish compiling the function.
161 platform->RunIdleTask(1000.0);
162
163 ASSERT_FALSE(dispatcher->IsEnqueued(shared));
164 ASSERT_FALSE(shared->HasBaselineCode());
165 ASSERT_FALSE(try_catch.HasCaught());
166 }
167
marja 2016/12/13 09:09:01 Can you add the following tests Test 1: - Do some
60 } // namespace internal 168 } // namespace internal
61 } // namespace v8 169 } // namespace v8
OLDNEW
« src/compiler-dispatcher/compiler-dispatcher.cc ('K') | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698