| 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/base/platform/semaphore.h" | 8 #include "src/base/platform/semaphore.h" |
| 9 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 9 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
| 10 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" | 10 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" |
| 11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
| 12 #include "src/flags.h" | 12 #include "src/flags.h" |
| 13 #include "src/handles.h" | 13 #include "src/handles.h" |
| 14 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 15 #include "src/parsing/parse-info.h" | 15 #include "src/parsing/parse-info.h" |
| 16 #include "src/v8.h" | 16 #include "src/v8.h" |
| 17 #include "src/zone/zone.h" |
| 17 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" | 18 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" |
| 18 #include "test/unittests/test-utils.h" | 19 #include "test/unittests/test-utils.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace v8 { | 22 namespace v8 { |
| 22 namespace internal { | 23 namespace internal { |
| 23 | 24 |
| 24 class CompilerDispatcherTest : public TestWithContext { | 25 class CompilerDispatcherTest : public TestWithContext { |
| 25 public: | 26 public: |
| 26 CompilerDispatcherTest() = default; | 27 CompilerDispatcherTest() = default; |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 TEST_F(CompilerDispatcherTest, EnqueueParsed) { | 808 TEST_F(CompilerDispatcherTest, EnqueueParsed) { |
| 808 MockPlatform platform; | 809 MockPlatform platform; |
| 809 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 810 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 810 | 811 |
| 811 const char script[] = | 812 const char script[] = |
| 812 "function g() { var y = 1; function f17(x) { return x * y }; return f17; " | 813 "function g() { var y = 1; function f17(x) { return x * y }; return f17; " |
| 813 "} g();"; | 814 "} g();"; |
| 814 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 815 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 815 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 816 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 816 | 817 |
| 817 ParseInfo parse_info(shared); | 818 Zone zone(i_isolate()->allocator(), ZONE_NAME); |
| 819 ParseInfo parse_info(&zone, shared); |
| 818 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 820 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 819 | 821 |
| 820 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 822 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 821 ASSERT_TRUE(dispatcher.Enqueue(shared, parse_info.literal())); | 823 ASSERT_TRUE(dispatcher.Enqueue(shared, parse_info.literal())); |
| 822 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 824 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
| 823 | 825 |
| 824 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 826 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 825 CompileJobStatus::kAnalyzed); | 827 CompileJobStatus::kAnalyzed); |
| 826 | 828 |
| 827 ASSERT_TRUE(platform.IdleTaskPending()); | 829 ASSERT_TRUE(platform.IdleTaskPending()); |
| 828 platform.ClearIdleTask(); | 830 platform.ClearIdleTask(); |
| 829 ASSERT_FALSE(platform.BackgroundTasksPending()); | 831 ASSERT_FALSE(platform.BackgroundTasksPending()); |
| 830 } | 832 } |
| 831 | 833 |
| 832 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { | 834 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { |
| 833 MockPlatform platform; | 835 MockPlatform platform; |
| 834 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 836 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 835 | 837 |
| 836 const char script[] = | 838 const char script[] = |
| 837 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " | 839 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " |
| 838 "} g();"; | 840 "} g();"; |
| 839 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 841 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 840 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 842 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 841 | 843 |
| 842 ParseInfo parse_info(shared); | 844 Zone zone(i_isolate()->allocator(), ZONE_NAME); |
| 845 ParseInfo parse_info(&zone, shared); |
| 843 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 846 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 844 | 847 |
| 845 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 848 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 846 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal())); | 849 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal())); |
| 847 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 850 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
| 848 | 851 |
| 849 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 852 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 850 CompileJobStatus::kReadyToCompile); | 853 CompileJobStatus::kReadyToCompile); |
| 851 | 854 |
| 852 ASSERT_TRUE(platform.IdleTaskPending()); | 855 ASSERT_TRUE(platform.IdleTaskPending()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 868 const char script2[] = | 871 const char script2[] = |
| 869 "function g() { var y = 1; function f20(x) { return x * y }; return f20; " | 872 "function g() { var y = 1; function f20(x) { return x * y }; return f20; " |
| 870 "} g();"; | 873 "} g();"; |
| 871 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); | 874 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); |
| 872 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); | 875 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); |
| 873 | 876 |
| 874 ASSERT_FALSE(shared1->is_compiled()); | 877 ASSERT_FALSE(shared1->is_compiled()); |
| 875 ASSERT_FALSE(shared2->is_compiled()); | 878 ASSERT_FALSE(shared2->is_compiled()); |
| 876 | 879 |
| 877 // Enqueue shared1 as already parsed. | 880 // Enqueue shared1 as already parsed. |
| 878 ParseInfo parse_info(shared1); | 881 Zone zone(i_isolate()->allocator(), ZONE_NAME); |
| 882 ParseInfo parse_info(&zone, shared1); |
| 879 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 883 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 880 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal())); | 884 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal())); |
| 881 | 885 |
| 882 // Enqueue shared2 for parsing and compiling | 886 // Enqueue shared2 for parsing and compiling |
| 883 ASSERT_TRUE(dispatcher.Enqueue(shared2)); | 887 ASSERT_TRUE(dispatcher.Enqueue(shared2)); |
| 884 | 888 |
| 885 ASSERT_TRUE(dispatcher.FinishAllNow()); | 889 ASSERT_TRUE(dispatcher.FinishAllNow()); |
| 886 | 890 |
| 887 // Finishing removes the SFI from the queue. | 891 // Finishing removes the SFI from the queue. |
| 888 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); | 892 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); |
| 889 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); | 893 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); |
| 890 ASSERT_TRUE(shared1->is_compiled()); | 894 ASSERT_TRUE(shared1->is_compiled()); |
| 891 ASSERT_TRUE(shared2->is_compiled()); | 895 ASSERT_TRUE(shared2->is_compiled()); |
| 892 ASSERT_TRUE(platform.IdleTaskPending()); | 896 ASSERT_TRUE(platform.IdleTaskPending()); |
| 893 platform.ClearIdleTask(); | 897 platform.ClearIdleTask(); |
| 894 } | 898 } |
| 895 | 899 |
| 896 } // namespace internal | 900 } // namespace internal |
| 897 } // namespace v8 | 901 } // namespace v8 |
| OLD | NEW |