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

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

Issue 2662883003: Add a test for OptimizingCompileDispatcher::Flush's non-blocking behavior (Closed)
Patch Set: updates Created 3 years, 10 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 | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
6
7 #include "src/base/atomic-utils.h"
8 #include "src/base/platform/semaphore.h"
9 #include "src/compilation-info.h"
10 #include "src/compiler.h"
11 #include "src/handles.h"
12 #include "src/isolate.h"
13 #include "src/objects-inl.h"
14 #include "src/parsing/parse-info.h"
15 #include "src/zone/zone.h"
16 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h"
17 #include "test/unittests/test-utils.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace v8 {
21 namespace internal {
22
23 typedef TestWithContext OptimizingCompileDispatcherTest;
24
25 namespace {
26
27 class BlockingCompilationJob : public CompilationJob {
28 public:
29 BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
30 : CompilationJob(isolate, &info_, "BlockingCompilationJob",
31 State::kReadyToExecute),
32 zone_(isolate->allocator(), ZONE_NAME),
33 parse_info_(&zone_, handle(function->shared())),
34 info_(&parse_info_, function),
35 blocking_(false),
36 semaphore_(0) {}
37 ~BlockingCompilationJob() override = default;
38
39 bool IsBlocking() const { return blocking_.Value(); }
40 void Signal() { semaphore_.Signal(); }
41
42 // CompilationJob implementation.
43 Status PrepareJobImpl() override {
44 UNREACHABLE();
45 return FAILED;
46 }
47
48 Status ExecuteJobImpl() override {
49 blocking_.SetValue(true);
50 semaphore_.Wait();
51 blocking_.SetValue(false);
52 return SUCCEEDED;
53 }
54
55 Status FinalizeJobImpl() override { return SUCCEEDED; }
56
57 private:
58 Zone zone_;
59 ParseInfo parse_info_;
60 CompilationInfo info_;
61 base::AtomicValue<bool> blocking_;
62 base::Semaphore semaphore_;
63
64 DISALLOW_COPY_AND_ASSIGN(BlockingCompilationJob);
65 };
66
67 } // namespace
68
69 TEST_F(OptimizingCompileDispatcherTest, Construct) {
70 OptimizingCompileDispatcher dispatcher(i_isolate());
71 ASSERT_TRUE(OptimizingCompileDispatcher::Enabled());
72 ASSERT_TRUE(dispatcher.IsQueueAvailable());
73 }
74
75 TEST_F(OptimizingCompileDispatcherTest, NonBlockingFlush) {
76 Handle<JSFunction> fun = Handle<JSFunction>::cast(
77 RunJS(isolate(), "function f() { function g() {}; return g;}; f();"));
78 BlockingCompilationJob* job = new BlockingCompilationJob(i_isolate(), fun);
79
80 OptimizingCompileDispatcher dispatcher(i_isolate());
81 ASSERT_TRUE(OptimizingCompileDispatcher::Enabled());
82 ASSERT_TRUE(dispatcher.IsQueueAvailable());
83 dispatcher.QueueForOptimization(job);
84
85 // Busy-wait for the job to run on a background thread.
86 while (!job->IsBlocking()) {
87 }
88
89 // Should not block.
90 dispatcher.Flush(OptimizingCompileDispatcher::BlockingBehavior::kDontBlock);
91
92 // Unblock the job & finish.
93 job->Signal();
94 dispatcher.Stop();
95 }
96
97 } // namespace internal
98 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698