OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <memory> |
| 6 |
| 7 #include "src/compiler-dispatcher/compiler-dispatcher.h" |
| 8 #include "src/flags.h" |
| 9 #include "src/handles.h" |
| 10 #include "src/objects-inl.h" |
| 11 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" |
| 12 #include "test/unittests/test-utils.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace v8 { |
| 16 namespace internal { |
| 17 |
| 18 typedef TestWithContext CompilerDispatcherTest; |
| 19 |
| 20 TEST_F(CompilerDispatcherTest, Construct) { |
| 21 std::unique_ptr<CompilerDispatcher> dispatcher( |
| 22 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); |
| 23 } |
| 24 |
| 25 TEST_F(CompilerDispatcherTest, IsEnqueued) { |
| 26 std::unique_ptr<CompilerDispatcher> dispatcher( |
| 27 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); |
| 28 |
| 29 const char script[] = |
| 30 "function g() { var y = 1; function f(x) { return x * y }; return f; } " |
| 31 "g();"; |
| 32 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 33 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 34 |
| 35 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); |
| 36 ASSERT_TRUE(dispatcher->Enqueue(shared)); |
| 37 ASSERT_TRUE(dispatcher->IsEnqueued(shared)); |
| 38 dispatcher->Abort(shared, CompilerDispatcher::BlockingBehavior::kBlock); |
| 39 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); |
| 40 } |
| 41 |
| 42 TEST_F(CompilerDispatcherTest, FinishNow) { |
| 43 std::unique_ptr<CompilerDispatcher> dispatcher( |
| 44 new CompilerDispatcher(i_isolate(), FLAG_stack_size)); |
| 45 |
| 46 const char script[] = |
| 47 "function g() { var y = 1; function f(x) { return x * y }; return f; } " |
| 48 "g();"; |
| 49 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 50 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 51 |
| 52 ASSERT_FALSE(shared->HasBaselineCode()); |
| 53 // Can't finish a SFI that isn't enqueued. |
| 54 ASSERT_FALSE(dispatcher->FinishNow(shared)); |
| 55 ASSERT_TRUE(dispatcher->Enqueue(shared)); |
| 56 ASSERT_TRUE(dispatcher->FinishNow(shared)); |
| 57 // Finishing removes the SFI from the queue. |
| 58 ASSERT_FALSE(dispatcher->IsEnqueued(shared)); |
| 59 ASSERT_TRUE(shared->HasBaselineCode()); |
| 60 } |
| 61 |
| 62 } // namespace internal |
| 63 } // namespace v8 |
OLD | NEW |