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