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/parsing/parsing.h" | |
17 #include "src/v8.h" | 16 #include "src/v8.h" |
18 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" | 17 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" |
19 #include "test/unittests/test-utils.h" | 18 #include "test/unittests/test-utils.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 namespace v8 { | 21 namespace v8 { |
23 namespace internal { | 22 namespace internal { |
24 | 23 |
25 class CompilerDispatcherTest : public TestWithContext { | 24 class CompilerDispatcherTest : public TestWithContext { |
26 public: | 25 public: |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 809 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
811 | 810 |
812 const char script[] = | 811 const char script[] = |
813 "function g() { var y = 1; function f17(x) { return x * y }; return f17; " | 812 "function g() { var y = 1; function f17(x) { return x * y }; return f17; " |
814 "} g();"; | 813 "} g();"; |
815 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 814 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
816 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 815 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
817 | 816 |
818 ParseInfo parse_info(shared); | 817 ParseInfo parse_info(shared); |
819 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 818 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
820 std::shared_ptr<DeferredHandles> handles; | |
821 | 819 |
822 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 820 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
823 ASSERT_TRUE(dispatcher.Enqueue(shared, parse_info.literal(), | 821 ASSERT_TRUE(dispatcher.Enqueue(shared, parse_info.literal())); |
824 parse_info.zone_shared(), handles, handles)); | |
825 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 822 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
826 | 823 |
827 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 824 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
828 CompileJobStatus::kAnalyzed); | 825 CompileJobStatus::kAnalyzed); |
829 | 826 |
830 ASSERT_TRUE(platform.IdleTaskPending()); | 827 ASSERT_TRUE(platform.IdleTaskPending()); |
831 platform.ClearIdleTask(); | 828 platform.ClearIdleTask(); |
832 ASSERT_FALSE(platform.BackgroundTasksPending()); | 829 ASSERT_FALSE(platform.BackgroundTasksPending()); |
833 } | 830 } |
834 | 831 |
835 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { | 832 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { |
836 MockPlatform platform; | 833 MockPlatform platform; |
837 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 834 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
838 | 835 |
839 const char script[] = | 836 const char script[] = |
840 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " | 837 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " |
841 "} g();"; | 838 "} g();"; |
842 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 839 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
843 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 840 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
844 | 841 |
845 ParseInfo parse_info(shared); | 842 ParseInfo parse_info(shared); |
846 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 843 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
847 std::shared_ptr<DeferredHandles> handles; | |
848 | 844 |
849 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 845 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
850 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal(), | 846 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal())); |
851 parse_info.zone_shared(), handles, | |
852 handles)); | |
853 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 847 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
854 | 848 |
855 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 849 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
856 CompileJobStatus::kReadyToCompile); | 850 CompileJobStatus::kReadyToCompile); |
857 | 851 |
858 ASSERT_TRUE(platform.IdleTaskPending()); | 852 ASSERT_TRUE(platform.IdleTaskPending()); |
859 ASSERT_TRUE(platform.BackgroundTasksPending()); | 853 ASSERT_TRUE(platform.BackgroundTasksPending()); |
860 platform.ClearIdleTask(); | 854 platform.ClearIdleTask(); |
861 platform.ClearBackgroundTasks(); | 855 platform.ClearBackgroundTasks(); |
862 } | 856 } |
(...skipping 13 matching lines...) Expand all Loading... |
876 "} g();"; | 870 "} g();"; |
877 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); | 871 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); |
878 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); | 872 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); |
879 | 873 |
880 ASSERT_FALSE(shared1->is_compiled()); | 874 ASSERT_FALSE(shared1->is_compiled()); |
881 ASSERT_FALSE(shared2->is_compiled()); | 875 ASSERT_FALSE(shared2->is_compiled()); |
882 | 876 |
883 // Enqueue shared1 as already parsed. | 877 // Enqueue shared1 as already parsed. |
884 ParseInfo parse_info(shared1); | 878 ParseInfo parse_info(shared1); |
885 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 879 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
886 std::shared_ptr<DeferredHandles> handles; | 880 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal())); |
887 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal(), | |
888 parse_info.zone_shared(), handles, handles)); | |
889 | 881 |
890 // Enqueue shared2 for parsing and compiling | 882 // Enqueue shared2 for parsing and compiling |
891 ASSERT_TRUE(dispatcher.Enqueue(shared2)); | 883 ASSERT_TRUE(dispatcher.Enqueue(shared2)); |
892 | 884 |
893 ASSERT_TRUE(dispatcher.FinishAllNow()); | 885 ASSERT_TRUE(dispatcher.FinishAllNow()); |
894 | 886 |
895 // Finishing removes the SFI from the queue. | 887 // Finishing removes the SFI from the queue. |
896 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); | 888 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); |
897 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); | 889 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); |
898 ASSERT_TRUE(shared1->is_compiled()); | 890 ASSERT_TRUE(shared1->is_compiled()); |
899 ASSERT_TRUE(shared2->is_compiled()); | 891 ASSERT_TRUE(shared2->is_compiled()); |
900 ASSERT_TRUE(platform.IdleTaskPending()); | 892 ASSERT_TRUE(platform.IdleTaskPending()); |
901 platform.ClearIdleTask(); | 893 platform.ClearIdleTask(); |
902 } | 894 } |
903 | 895 |
904 TEST_F(CompilerDispatcherTest, CompileParsedOutOfScope) { | |
905 MockPlatform platform; | |
906 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | |
907 | |
908 const char script[] = | |
909 "function g() { var y = 1; function f20(x) { return x + y }; return f20; " | |
910 "} g();"; | |
911 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | |
912 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | |
913 | |
914 { | |
915 HandleScope scope(i_isolate()); // Create handles scope for parsing. | |
916 | |
917 ASSERT_FALSE(shared->is_compiled()); | |
918 ParseInfo parse_info(shared); | |
919 | |
920 ASSERT_TRUE(parsing::ParseAny(&parse_info)); | |
921 DeferredHandleScope handles_scope(i_isolate()); | |
922 { ASSERT_TRUE(Compiler::Analyze(&parse_info)); } | |
923 std::shared_ptr<DeferredHandles> compilation_handles( | |
924 handles_scope.Detach()); | |
925 | |
926 ASSERT_FALSE(platform.IdleTaskPending()); | |
927 ASSERT_TRUE(dispatcher.Enqueue( | |
928 shared, parse_info.literal(), parse_info.zone_shared(), | |
929 parse_info.deferred_handles(), compilation_handles)); | |
930 ASSERT_TRUE(platform.IdleTaskPending()); | |
931 } | |
932 // Exit the handles scope and destroy ParseInfo before running the idle task. | |
933 | |
934 // Since time doesn't progress on the MockPlatform, this is enough idle time | |
935 // to finish compiling the function. | |
936 platform.RunIdleTask(1000.0, 0.0); | |
937 | |
938 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | |
939 ASSERT_TRUE(shared->is_compiled()); | |
940 } | |
941 | |
942 } // namespace internal | 896 } // namespace internal |
943 } // namespace v8 | 897 } // namespace v8 |
OLD | NEW |