| OLD | NEW |
| 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 "src/compiler-dispatcher/compiler-dispatcher.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher.h" |
| 6 | 6 |
| 7 #include "include/v8-platform.h" | 7 #include "include/v8-platform.h" |
| 8 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 8 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
| 9 #include "src/flags.h" | 9 #include "src/flags.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 TEST_F(CompilerDispatcherTest, FinishNow) { | 97 TEST_F(CompilerDispatcherTest, FinishNow) { |
| 98 MockPlatform platform; | 98 MockPlatform platform; |
| 99 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 99 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 100 | 100 |
| 101 const char script[] = | 101 const char script[] = |
| 102 "function g() { var y = 1; function f2(x) { return x * y }; return f2; } " | 102 "function g() { var y = 1; function f2(x) { return x * y }; return f2; } " |
| 103 "g();"; | 103 "g();"; |
| 104 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 104 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 105 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 105 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 106 | 106 |
| 107 ASSERT_FALSE(shared->HasBaselineCode()); | 107 ASSERT_FALSE(shared->is_compiled()); |
| 108 ASSERT_TRUE(dispatcher.Enqueue(shared)); | 108 ASSERT_TRUE(dispatcher.Enqueue(shared)); |
| 109 ASSERT_TRUE(dispatcher.FinishNow(shared)); | 109 ASSERT_TRUE(dispatcher.FinishNow(shared)); |
| 110 // Finishing removes the SFI from the queue. | 110 // Finishing removes the SFI from the queue. |
| 111 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 111 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 112 ASSERT_TRUE(shared->HasBaselineCode()); | 112 ASSERT_TRUE(shared->is_compiled()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(CompilerDispatcherTest, IdleTask) { | 115 TEST_F(CompilerDispatcherTest, IdleTask) { |
| 116 MockPlatform platform; | 116 MockPlatform platform; |
| 117 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 117 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 118 | 118 |
| 119 const char script[] = | 119 const char script[] = |
| 120 "function g() { var y = 1; function f3(x) { return x * y }; return f3; } " | 120 "function g() { var y = 1; function f3(x) { return x * y }; return f3; } " |
| 121 "g();"; | 121 "g();"; |
| 122 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 122 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 123 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 123 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 124 | 124 |
| 125 ASSERT_FALSE(platform.IdleTaskPending()); | 125 ASSERT_FALSE(platform.IdleTaskPending()); |
| 126 ASSERT_TRUE(dispatcher.Enqueue(shared)); | 126 ASSERT_TRUE(dispatcher.Enqueue(shared)); |
| 127 ASSERT_TRUE(platform.IdleTaskPending()); | 127 ASSERT_TRUE(platform.IdleTaskPending()); |
| 128 | 128 |
| 129 // Since time doesn't progress on the MockPlatform, this is enough idle time | 129 // Since time doesn't progress on the MockPlatform, this is enough idle time |
| 130 // to finish compiling the function. | 130 // to finish compiling the function. |
| 131 platform.RunIdleTask(1000.0, 0.0); | 131 platform.RunIdleTask(1000.0, 0.0); |
| 132 | 132 |
| 133 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 133 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 134 ASSERT_TRUE(shared->HasBaselineCode()); | 134 ASSERT_TRUE(shared->is_compiled()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) { | 137 TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) { |
| 138 MockPlatform platform; | 138 MockPlatform platform; |
| 139 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 139 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 140 | 140 |
| 141 const char script[] = | 141 const char script[] = |
| 142 "function g() { var y = 1; function f4(x) { return x * y }; return f4; } " | 142 "function g() { var y = 1; function f4(x) { return x * y }; return f4; } " |
| 143 "g();"; | 143 "g();"; |
| 144 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 144 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 145 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 145 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 146 | 146 |
| 147 ASSERT_FALSE(platform.IdleTaskPending()); | 147 ASSERT_FALSE(platform.IdleTaskPending()); |
| 148 ASSERT_TRUE(dispatcher.Enqueue(shared)); | 148 ASSERT_TRUE(dispatcher.Enqueue(shared)); |
| 149 ASSERT_TRUE(platform.IdleTaskPending()); | 149 ASSERT_TRUE(platform.IdleTaskPending()); |
| 150 | 150 |
| 151 // The job should be scheduled for the main thread. | 151 // The job should be scheduled for the main thread. |
| 152 ASSERT_EQ(dispatcher.jobs_.size(), 1u); | 152 ASSERT_EQ(dispatcher.jobs_.size(), 1u); |
| 153 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 153 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 154 CompileJobStatus::kInitial); | 154 CompileJobStatus::kInitial); |
| 155 | 155 |
| 156 // Only grant a little idle time and have time advance beyond it in one step. | 156 // Only grant a little idle time and have time advance beyond it in one step. |
| 157 platform.RunIdleTask(2.0, 1.0); | 157 platform.RunIdleTask(2.0, 1.0); |
| 158 | 158 |
| 159 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 159 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
| 160 ASSERT_FALSE(shared->HasBaselineCode()); | 160 ASSERT_FALSE(shared->is_compiled()); |
| 161 ASSERT_TRUE(platform.IdleTaskPending()); | 161 ASSERT_TRUE(platform.IdleTaskPending()); |
| 162 | 162 |
| 163 // The job should be still scheduled for the main thread, but ready for | 163 // The job should be still scheduled for the main thread, but ready for |
| 164 // parsing. | 164 // parsing. |
| 165 ASSERT_EQ(dispatcher.jobs_.size(), 1u); | 165 ASSERT_EQ(dispatcher.jobs_.size(), 1u); |
| 166 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 166 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 167 CompileJobStatus::kReadyToParse); | 167 CompileJobStatus::kReadyToParse); |
| 168 | 168 |
| 169 // Only grant a lot of idle time and freeze time. | 169 // Only grant a lot of idle time and freeze time. |
| 170 platform.RunIdleTask(1000.0, 0.0); | 170 platform.RunIdleTask(1000.0, 0.0); |
| 171 | 171 |
| 172 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 172 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 173 ASSERT_TRUE(shared->HasBaselineCode()); | 173 ASSERT_TRUE(shared->is_compiled()); |
| 174 ASSERT_FALSE(platform.IdleTaskPending()); | 174 ASSERT_FALSE(platform.IdleTaskPending()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(CompilerDispatcherTest, IdleTaskException) { | 177 TEST_F(CompilerDispatcherTest, IdleTaskException) { |
| 178 MockPlatform platform; | 178 MockPlatform platform; |
| 179 CompilerDispatcher dispatcher(i_isolate(), &platform, 50); | 179 CompilerDispatcher dispatcher(i_isolate(), &platform, 50); |
| 180 | 180 |
| 181 std::string script("function g() { function f5(x) { var a = "); | 181 std::string script("function g() { function f5(x) { var a = "); |
| 182 for (int i = 0; i < 1000; i++) { | 182 for (int i = 0; i < 1000; i++) { |
| 183 script += "'x' + "; | 183 script += "'x' + "; |
| 184 } | 184 } |
| 185 script += " 'x'; }; return f5; } g();"; | 185 script += " 'x'; }; return f5; } g();"; |
| 186 Handle<JSFunction> f = | 186 Handle<JSFunction> f = |
| 187 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str())); | 187 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str())); |
| 188 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 188 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 189 | 189 |
| 190 ASSERT_FALSE(platform.IdleTaskPending()); | 190 ASSERT_FALSE(platform.IdleTaskPending()); |
| 191 ASSERT_TRUE(dispatcher.Enqueue(shared)); | 191 ASSERT_TRUE(dispatcher.Enqueue(shared)); |
| 192 ASSERT_TRUE(platform.IdleTaskPending()); | 192 ASSERT_TRUE(platform.IdleTaskPending()); |
| 193 | 193 |
| 194 // Idle tasks shouldn't leave exceptions behind. | 194 // Idle tasks shouldn't leave exceptions behind. |
| 195 v8::TryCatch try_catch(isolate()); | 195 v8::TryCatch try_catch(isolate()); |
| 196 | 196 |
| 197 // Since time doesn't progress on the MockPlatform, this is enough idle time | 197 // Since time doesn't progress on the MockPlatform, this is enough idle time |
| 198 // to finish compiling the function. | 198 // to finish compiling the function. |
| 199 platform.RunIdleTask(1000.0, 0.0); | 199 platform.RunIdleTask(1000.0, 0.0); |
| 200 | 200 |
| 201 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 201 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 202 ASSERT_FALSE(shared->HasBaselineCode()); | 202 ASSERT_FALSE(shared->is_compiled()); |
| 203 ASSERT_FALSE(try_catch.HasCaught()); | 203 ASSERT_FALSE(try_catch.HasCaught()); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace internal | 206 } // namespace internal |
| 207 } // namespace v8 | 207 } // namespace v8 |
| OLD | NEW |