| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 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 | 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/optimizing-compile-dispatcher.h" | 5 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" |
| 6 | 6 |
| 7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
| 8 #include "src/base/platform/semaphore.h" | 8 #include "src/base/platform/semaphore.h" |
| 9 #include "src/compilation-info.h" | 9 #include "src/compilation-info.h" |
| 10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
| 11 #include "src/handles.h" | 11 #include "src/handles.h" |
| 12 #include "src/isolate.h" | 12 #include "src/isolate.h" |
| 13 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
| 14 #include "src/parsing/parse-info.h" | 14 #include "src/parsing/parse-info.h" |
| 15 #include "src/zone/zone.h" |
| 15 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" | 16 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" |
| 16 #include "test/unittests/test-utils.h" | 17 #include "test/unittests/test-utils.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace v8 { | 20 namespace v8 { |
| 20 namespace internal { | 21 namespace internal { |
| 21 | 22 |
| 22 typedef TestWithContext OptimizingCompileDispatcherTest; | 23 typedef TestWithContext OptimizingCompileDispatcherTest; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 class BlockingCompilationJob : public CompilationJob { | 27 class BlockingCompilationJob : public CompilationJob { |
| 27 public: | 28 public: |
| 28 BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function) | 29 BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function) |
| 29 : CompilationJob(isolate, &info_, "BlockingCompilationJob", | 30 : CompilationJob(isolate, &info_, "BlockingCompilationJob", |
| 30 State::kReadyToExecute), | 31 State::kReadyToExecute), |
| 31 parse_info_(handle(function->shared())), | 32 zone_(isolate->allocator(), ZONE_NAME), |
| 33 parse_info_(&zone_, handle(function->shared())), |
| 32 info_(&parse_info_, function), | 34 info_(&parse_info_, function), |
| 33 blocking_(false), | 35 blocking_(false), |
| 34 semaphore_(0) {} | 36 semaphore_(0) {} |
| 35 ~BlockingCompilationJob() override = default; | 37 ~BlockingCompilationJob() override = default; |
| 36 | 38 |
| 37 bool IsBlocking() const { return blocking_.Value(); } | 39 bool IsBlocking() const { return blocking_.Value(); } |
| 38 void Signal() { semaphore_.Signal(); } | 40 void Signal() { semaphore_.Signal(); } |
| 39 | 41 |
| 40 // CompilationJob implementation. | 42 // CompilationJob implementation. |
| 41 Status PrepareJobImpl() override { | 43 Status PrepareJobImpl() override { |
| 42 UNREACHABLE(); | 44 UNREACHABLE(); |
| 43 return FAILED; | 45 return FAILED; |
| 44 } | 46 } |
| 45 | 47 |
| 46 Status ExecuteJobImpl() override { | 48 Status ExecuteJobImpl() override { |
| 47 blocking_.SetValue(true); | 49 blocking_.SetValue(true); |
| 48 semaphore_.Wait(); | 50 semaphore_.Wait(); |
| 49 blocking_.SetValue(false); | 51 blocking_.SetValue(false); |
| 50 return SUCCEEDED; | 52 return SUCCEEDED; |
| 51 } | 53 } |
| 52 | 54 |
| 53 Status FinalizeJobImpl() override { return SUCCEEDED; } | 55 Status FinalizeJobImpl() override { return SUCCEEDED; } |
| 54 | 56 |
| 55 private: | 57 private: |
| 58 Zone zone_; |
| 56 ParseInfo parse_info_; | 59 ParseInfo parse_info_; |
| 57 CompilationInfo info_; | 60 CompilationInfo info_; |
| 58 base::AtomicValue<bool> blocking_; | 61 base::AtomicValue<bool> blocking_; |
| 59 base::Semaphore semaphore_; | 62 base::Semaphore semaphore_; |
| 60 | 63 |
| 61 DISALLOW_COPY_AND_ASSIGN(BlockingCompilationJob); | 64 DISALLOW_COPY_AND_ASSIGN(BlockingCompilationJob); |
| 62 }; | 65 }; |
| 63 | 66 |
| 64 } // namespace | 67 } // namespace |
| 65 | 68 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 // Should not block. | 89 // Should not block. |
| 87 dispatcher.Flush(OptimizingCompileDispatcher::BlockingBehavior::kDontBlock); | 90 dispatcher.Flush(OptimizingCompileDispatcher::BlockingBehavior::kDontBlock); |
| 88 | 91 |
| 89 // Unblock the job & finish. | 92 // Unblock the job & finish. |
| 90 job->Signal(); | 93 job->Signal(); |
| 91 dispatcher.Stop(); | 94 dispatcher.Stop(); |
| 92 } | 95 } |
| 93 | 96 |
| 94 } // namespace internal | 97 } // namespace internal |
| 95 } // namespace v8 | 98 } // namespace v8 |
| OLD | NEW |