| 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" |
| 16 #include "src/v8.h" | 17 #include "src/v8.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: |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ParseInfo parse_info(shared); |
| 818 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 819 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 820 std::shared_ptr<DeferredHandles> handles; |
| 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(), |
| 824 parse_info.zone_shared(), handles, handles)); |
| 822 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 825 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
| 823 | 826 |
| 824 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 827 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 825 CompileJobStatus::kAnalyzed); | 828 CompileJobStatus::kAnalyzed); |
| 826 | 829 |
| 827 ASSERT_TRUE(platform.IdleTaskPending()); | 830 ASSERT_TRUE(platform.IdleTaskPending()); |
| 828 platform.ClearIdleTask(); | 831 platform.ClearIdleTask(); |
| 829 ASSERT_FALSE(platform.BackgroundTasksPending()); | 832 ASSERT_FALSE(platform.BackgroundTasksPending()); |
| 830 } | 833 } |
| 831 | 834 |
| 832 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { | 835 TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) { |
| 833 MockPlatform platform; | 836 MockPlatform platform; |
| 834 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 837 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| 835 | 838 |
| 836 const char script[] = | 839 const char script[] = |
| 837 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " | 840 "function g() { var y = 1; function f18(x) { return x * y }; return f18; " |
| 838 "} g();"; | 841 "} g();"; |
| 839 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 842 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
| 840 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 843 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
| 841 | 844 |
| 842 ParseInfo parse_info(shared); | 845 ParseInfo parse_info(shared); |
| 843 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 846 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 847 std::shared_ptr<DeferredHandles> handles; |
| 844 | 848 |
| 845 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 849 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| 846 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal())); | 850 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared, parse_info.literal(), |
| 851 parse_info.zone_shared(), handles, |
| 852 handles)); |
| 847 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); | 853 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); |
| 848 | 854 |
| 849 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == | 855 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == |
| 850 CompileJobStatus::kReadyToCompile); | 856 CompileJobStatus::kReadyToCompile); |
| 851 | 857 |
| 852 ASSERT_TRUE(platform.IdleTaskPending()); | 858 ASSERT_TRUE(platform.IdleTaskPending()); |
| 853 ASSERT_TRUE(platform.BackgroundTasksPending()); | 859 ASSERT_TRUE(platform.BackgroundTasksPending()); |
| 854 platform.ClearIdleTask(); | 860 platform.ClearIdleTask(); |
| 855 platform.ClearBackgroundTasks(); | 861 platform.ClearBackgroundTasks(); |
| 856 } | 862 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 870 "} g();"; | 876 "} g();"; |
| 871 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); | 877 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); |
| 872 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); | 878 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); |
| 873 | 879 |
| 874 ASSERT_FALSE(shared1->is_compiled()); | 880 ASSERT_FALSE(shared1->is_compiled()); |
| 875 ASSERT_FALSE(shared2->is_compiled()); | 881 ASSERT_FALSE(shared2->is_compiled()); |
| 876 | 882 |
| 877 // Enqueue shared1 as already parsed. | 883 // Enqueue shared1 as already parsed. |
| 878 ParseInfo parse_info(shared1); | 884 ParseInfo parse_info(shared1); |
| 879 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); | 885 ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| 880 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal())); | 886 std::shared_ptr<DeferredHandles> handles; |
| 887 ASSERT_TRUE(dispatcher.Enqueue(shared1, parse_info.literal(), |
| 888 parse_info.zone_shared(), handles, handles)); |
| 881 | 889 |
| 882 // Enqueue shared2 for parsing and compiling | 890 // Enqueue shared2 for parsing and compiling |
| 883 ASSERT_TRUE(dispatcher.Enqueue(shared2)); | 891 ASSERT_TRUE(dispatcher.Enqueue(shared2)); |
| 884 | 892 |
| 885 ASSERT_TRUE(dispatcher.FinishAllNow()); | 893 ASSERT_TRUE(dispatcher.FinishAllNow()); |
| 886 | 894 |
| 887 // Finishing removes the SFI from the queue. | 895 // Finishing removes the SFI from the queue. |
| 888 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); | 896 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); |
| 889 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); | 897 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); |
| 890 ASSERT_TRUE(shared1->is_compiled()); | 898 ASSERT_TRUE(shared1->is_compiled()); |
| 891 ASSERT_TRUE(shared2->is_compiled()); | 899 ASSERT_TRUE(shared2->is_compiled()); |
| 892 ASSERT_TRUE(platform.IdleTaskPending()); | 900 ASSERT_TRUE(platform.IdleTaskPending()); |
| 893 platform.ClearIdleTask(); | 901 platform.ClearIdleTask(); |
| 894 } | 902 } |
| 895 | 903 |
| 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 |
| 896 } // namespace internal | 942 } // namespace internal |
| 897 } // namespace v8 | 943 } // namespace v8 |
| OLD | NEW |