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

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

Issue 2625413004: [compiler-dispatcher] make it so that we can always parse on bg threads (Closed)
Patch Set: updates Created 3 years, 11 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
« no previous file with comments | « src/objects.h ('k') | test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 7 #include "include/v8.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
(...skipping 11 matching lines...) Expand all
22 namespace v8 { 22 namespace v8 {
23 namespace internal { 23 namespace internal {
24 24
25 class CompilerDispatcherJobTest : public TestWithContext { 25 class CompilerDispatcherJobTest : public TestWithContext {
26 public: 26 public:
27 CompilerDispatcherJobTest() : tracer_(i_isolate()) {} 27 CompilerDispatcherJobTest() : tracer_(i_isolate()) {}
28 ~CompilerDispatcherJobTest() override {} 28 ~CompilerDispatcherJobTest() override {}
29 29
30 CompilerDispatcherTracer* tracer() { return &tracer_; } 30 CompilerDispatcherTracer* tracer() { return &tracer_; }
31 31
32 private:
33 CompilerDispatcherTracer tracer_;
34
35 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJobTest);
36 };
37
38 class IgnitionCompilerDispatcherJobTest : public CompilerDispatcherJobTest {
39 public:
40 IgnitionCompilerDispatcherJobTest() {}
41 ~IgnitionCompilerDispatcherJobTest() override {}
42
43 static void SetUpTestCase() { 32 static void SetUpTestCase() {
44 old_flag_ = i::FLAG_ignition; 33 old_flag_ = i::FLAG_ignition;
45 i::FLAG_ignition = true; 34 i::FLAG_ignition = true;
46 TestWithContext::SetUpTestCase(); 35 TestWithContext::SetUpTestCase();
47 } 36 }
48 37
49 static void TearDownTestCase() { 38 static void TearDownTestCase() {
50 TestWithContext::TearDownTestCase(); 39 TestWithContext::TearDownTestCase();
51 i::FLAG_ignition = old_flag_; 40 i::FLAG_ignition = old_flag_;
52 } 41 }
53 42
54 private: 43 private:
44 CompilerDispatcherTracer tracer_;
55 static bool old_flag_; 45 static bool old_flag_;
56 DISALLOW_COPY_AND_ASSIGN(IgnitionCompilerDispatcherJobTest); 46
47 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJobTest);
57 }; 48 };
58 49
59 bool IgnitionCompilerDispatcherJobTest::old_flag_; 50 bool CompilerDispatcherJobTest::old_flag_;
60 51
61 namespace { 52 namespace {
62 53
63 const char test_script[] = "(x) { x*x; }"; 54 const char test_script[] = "(x) { x*x; }";
64 55
65 class ScriptResource : public v8::String::ExternalOneByteStringResource { 56 class ScriptResource : public v8::String::ExternalOneByteStringResource {
66 public: 57 public:
67 ScriptResource(const char* data, size_t length) 58 ScriptResource(const char* data, size_t length)
68 : data_(data), length_(length) {} 59 : data_(data), length_(length) {}
69 ~ScriptResource() override = default; 60 ~ScriptResource() override = default;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 94 }
104 95
105 } // namespace 96 } // namespace
106 97
107 TEST_F(CompilerDispatcherJobTest, Construct) { 98 TEST_F(CompilerDispatcherJobTest, Construct) {
108 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 99 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
109 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr), 100 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr),
110 FLAG_stack_size)); 101 FLAG_stack_size));
111 } 102 }
112 103
113 TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) {
114 {
115 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
116 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr),
117 FLAG_stack_size));
118 ASSERT_FALSE(job->can_parse_on_background_thread());
119 }
120 {
121 ScriptResource script(test_script, strlen(test_script));
122 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
123 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script),
124 FLAG_stack_size));
125 ASSERT_TRUE(job->can_parse_on_background_thread());
126 }
127 }
128
129 TEST_F(CompilerDispatcherJobTest, StateTransitions) { 104 TEST_F(CompilerDispatcherJobTest, StateTransitions) {
130 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 105 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
131 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr), 106 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr),
132 FLAG_stack_size)); 107 FLAG_stack_size));
133 108
134 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 109 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
135 job->PrepareToParseOnMainThread(); 110 job->PrepareToParseOnMainThread();
136 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); 111 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse);
137 job->Parse(); 112 job->Parse();
138 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); 113 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 job_->Compile(); 259 job_->Compile();
285 semaphore_->Signal(); 260 semaphore_->Signal();
286 } 261 }
287 262
288 private: 263 private:
289 CompilerDispatcherJob* job_; 264 CompilerDispatcherJob* job_;
290 base::Semaphore* semaphore_; 265 base::Semaphore* semaphore_;
291 DISALLOW_COPY_AND_ASSIGN(CompileTask); 266 DISALLOW_COPY_AND_ASSIGN(CompileTask);
292 }; 267 };
293 268
294 TEST_F(IgnitionCompilerDispatcherJobTest, CompileOnBackgroundThread) { 269 TEST_F(CompilerDispatcherJobTest, CompileOnBackgroundThread) {
295 const char* raw_script = 270 const char* raw_script =
296 "(a, b) {\n" 271 "(a, b) {\n"
297 " var c = a + b;\n" 272 " var c = a + b;\n"
298 " function bar() { return b }\n" 273 " function bar() { return b }\n"
299 " var d = { foo: 100, bar : bar() }\n" 274 " var d = { foo: 100, bar : bar() }\n"
300 " return bar;" 275 " return bar;"
301 "}"; 276 "}";
302 ScriptResource script(raw_script, strlen(raw_script)); 277 ScriptResource script(raw_script, strlen(raw_script));
303 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 278 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
304 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), 279 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script),
305 100)); 280 100));
306 281
307 job->PrepareToParseOnMainThread(); 282 job->PrepareToParseOnMainThread();
308 job->Parse(); 283 job->Parse();
309 job->FinalizeParsingOnMainThread(); 284 job->FinalizeParsingOnMainThread();
310 job->PrepareToCompileOnMainThread(); 285 job->PrepareToCompileOnMainThread();
311 ASSERT_TRUE(job->can_compile_on_background_thread());
312 286
313 base::Semaphore semaphore(0); 287 base::Semaphore semaphore(0);
314 CompileTask* background_task = new CompileTask(job.get(), &semaphore); 288 CompileTask* background_task = new CompileTask(job.get(), &semaphore);
315 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, 289 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task,
316 Platform::kShortRunningTask); 290 Platform::kShortRunningTask);
317 semaphore.Wait(); 291 semaphore.Wait();
318 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); 292 ASSERT_TRUE(job->FinalizeCompilingOnMainThread());
319 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); 293 ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
320 294
321 job->ResetOnMainThread(); 295 job->ResetOnMainThread();
(...skipping 26 matching lines...) Expand all
348 Handle<JSFunction> e = Handle<JSFunction>::cast(RunJS(isolate(), "f();")); 322 Handle<JSFunction> e = Handle<JSFunction>::cast(RunJS(isolate(), "f();"));
349 323
350 ASSERT_FALSE(e->shared()->HasBaselineCode()); 324 ASSERT_FALSE(e->shared()->HasBaselineCode());
351 325
352 job->ResetOnMainThread(); 326 job->ResetOnMainThread();
353 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 327 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
354 } 328 }
355 329
356 } // namespace internal 330 } // namespace internal
357 } // namespace v8 331 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698