OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 void CompilationInfo::Initialize(Isolate* isolate, | 107 void CompilationInfo::Initialize(Isolate* isolate, |
108 Mode mode, | 108 Mode mode, |
109 Zone* zone) { | 109 Zone* zone) { |
110 isolate_ = isolate; | 110 isolate_ = isolate; |
111 function_ = NULL; | 111 function_ = NULL; |
112 scope_ = NULL; | 112 scope_ = NULL; |
113 global_scope_ = NULL; | 113 global_scope_ = NULL; |
114 extension_ = NULL; | 114 extension_ = NULL; |
115 cached_data_ = NULL; | 115 cached_data_ = NULL; |
116 cached_data_mode_ = NO_CACHED_DATA; | 116 compile_options_ = ScriptCompiler::kNoCompileOptions; |
117 zone_ = zone; | 117 zone_ = zone; |
118 deferred_handles_ = NULL; | 118 deferred_handles_ = NULL; |
119 code_stub_ = NULL; | 119 code_stub_ = NULL; |
120 prologue_offset_ = Code::kPrologueOffsetNotSet; | 120 prologue_offset_ = Code::kPrologueOffsetNotSet; |
121 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); | 121 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); |
122 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() | 122 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
123 ? new List<OffsetRange>(2) : NULL; | 123 ? new List<OffsetRange>(2) : NULL; |
124 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 124 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
125 dependencies_[i] = NULL; | 125 dependencies_[i] = NULL; |
126 } | 126 } |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 792 |
793 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 793 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
794 FixedArray* array = isolate->native_context()->embedder_data(); | 794 FixedArray* array = isolate->native_context()->embedder_data(); |
795 script->set_context_data(array->get(0)); | 795 script->set_context_data(array->get(0)); |
796 | 796 |
797 isolate->debug()->OnBeforeCompile(script); | 797 isolate->debug()->OnBeforeCompile(script); |
798 | 798 |
799 ASSERT(info->is_eval() || info->is_global()); | 799 ASSERT(info->is_eval() || info->is_global()); |
800 | 800 |
801 bool parse_allow_lazy = | 801 bool parse_allow_lazy = |
802 (info->cached_data_mode() == CONSUME_CACHED_DATA || | 802 (info->compile_options() == ScriptCompiler::kConsumeParserCache || |
803 String::cast(script->source())->length() > FLAG_min_preparse_length) && | 803 String::cast(script->source())->length() > FLAG_min_preparse_length) && |
804 !DebuggerWantsEagerCompilation(info); | 804 !DebuggerWantsEagerCompilation(info); |
805 | 805 |
806 if (!parse_allow_lazy && info->cached_data_mode() != NO_CACHED_DATA) { | 806 if (!parse_allow_lazy && |
| 807 (info->compile_options() == ScriptCompiler::kProduceParserCache || |
| 808 info->compile_options() == ScriptCompiler::kConsumeParserCache)) { |
807 // We are going to parse eagerly, but we either 1) have cached data produced | 809 // We are going to parse eagerly, but we either 1) have cached data produced |
808 // by lazy parsing or 2) are asked to generate cached data. We cannot use | 810 // by lazy parsing or 2) are asked to generate cached data. We cannot use |
809 // the existing data, since it won't contain all the symbols we need for | 811 // the existing data, since it won't contain all the symbols we need for |
810 // eager parsing. In addition, it doesn't make sense to produce the data | 812 // eager parsing. In addition, it doesn't make sense to produce the data |
811 // when parsing eagerly. That data would contain all symbols, but no | 813 // when parsing eagerly. That data would contain all symbols, but no |
812 // functions, so it cannot be used to aid lazy parsing later. | 814 // functions, so it cannot be used to aid lazy parsing later. |
813 info->SetCachedData(NULL, NO_CACHED_DATA); | 815 info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions); |
814 } | 816 } |
815 | 817 |
816 Handle<SharedFunctionInfo> result; | 818 Handle<SharedFunctionInfo> result; |
817 | 819 |
818 { VMState<COMPILER> state(info->isolate()); | 820 { VMState<COMPILER> state(info->isolate()); |
819 if (!Parser::Parse(info, parse_allow_lazy)) { | 821 if (!Parser::Parse(info, parse_allow_lazy)) { |
820 return Handle<SharedFunctionInfo>::null(); | 822 return Handle<SharedFunctionInfo>::null(); |
821 } | 823 } |
822 | 824 |
823 FunctionLiteral* lit = info->function(); | 825 FunctionLiteral* lit = info->function(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { | 926 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { |
925 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); | 927 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); |
926 } | 928 } |
927 | 929 |
928 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 930 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
929 shared_info, context, NOT_TENURED); | 931 shared_info, context, NOT_TENURED); |
930 } | 932 } |
931 | 933 |
932 | 934 |
933 Handle<SharedFunctionInfo> Compiler::CompileScript( | 935 Handle<SharedFunctionInfo> Compiler::CompileScript( |
934 Handle<String> source, | 936 Handle<String> source, Handle<Object> script_name, int line_offset, |
935 Handle<Object> script_name, | 937 int column_offset, bool is_shared_cross_origin, Handle<Context> context, |
936 int line_offset, | 938 v8::Extension* extension, ScriptData** cached_data, |
937 int column_offset, | 939 ScriptCompiler::CompileOptions compile_options, NativesFlag natives) { |
938 bool is_shared_cross_origin, | 940 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
939 Handle<Context> context, | |
940 v8::Extension* extension, | |
941 ScriptData** cached_data, | |
942 CachedDataMode cached_data_mode, | |
943 NativesFlag natives) { | |
944 if (cached_data_mode == NO_CACHED_DATA) { | |
945 cached_data = NULL; | 941 cached_data = NULL; |
946 } else if (cached_data_mode == PRODUCE_CACHED_DATA) { | 942 } else if (compile_options == ScriptCompiler::kProduceParserCache || |
| 943 compile_options == ScriptCompiler::kProduceCodeCache) { |
947 ASSERT(cached_data && !*cached_data); | 944 ASSERT(cached_data && !*cached_data); |
948 ASSERT(extension == NULL); | 945 ASSERT(extension == NULL); |
949 } else { | 946 } else { |
950 ASSERT(cached_data_mode == CONSUME_CACHED_DATA); | 947 ASSERT(compile_options == ScriptCompiler::kConsumeParserCache || |
| 948 compile_options == ScriptCompiler::kConsumeCodeCache); |
951 ASSERT(cached_data && *cached_data); | 949 ASSERT(cached_data && *cached_data); |
952 ASSERT(extension == NULL); | 950 ASSERT(extension == NULL); |
953 } | 951 } |
954 Isolate* isolate = source->GetIsolate(); | 952 Isolate* isolate = source->GetIsolate(); |
955 int source_length = source->length(); | 953 int source_length = source->length(); |
956 isolate->counters()->total_load_size()->Increment(source_length); | 954 isolate->counters()->total_load_size()->Increment(source_length); |
957 isolate->counters()->total_compile_size()->Increment(source_length); | 955 isolate->counters()->total_compile_size()->Increment(source_length); |
958 | 956 |
959 CompilationCache* compilation_cache = isolate->compilation_cache(); | 957 CompilationCache* compilation_cache = isolate->compilation_cache(); |
960 | 958 |
961 // Do a lookup in the compilation cache but not for extensions. | 959 // Do a lookup in the compilation cache but not for extensions. |
962 MaybeHandle<SharedFunctionInfo> maybe_result; | 960 MaybeHandle<SharedFunctionInfo> maybe_result; |
963 Handle<SharedFunctionInfo> result; | 961 Handle<SharedFunctionInfo> result; |
964 if (extension == NULL) { | 962 if (extension == NULL) { |
965 maybe_result = compilation_cache->LookupScript( | 963 maybe_result = compilation_cache->LookupScript( |
966 source, script_name, line_offset, column_offset, | 964 source, script_name, line_offset, column_offset, |
967 is_shared_cross_origin, context); | 965 is_shared_cross_origin, context); |
968 if (maybe_result.is_null() && FLAG_serialize_toplevel && | 966 if (maybe_result.is_null() && FLAG_serialize_toplevel && |
969 cached_data_mode == CONSUME_CACHED_DATA) { | 967 compile_options == ScriptCompiler::kConsumeCodeCache) { |
970 Object* des = CodeSerializer::Deserialize(isolate, *cached_data); | 968 Object* des = CodeSerializer::Deserialize(isolate, *cached_data); |
971 return handle(SharedFunctionInfo::cast(des), isolate); | 969 return handle(SharedFunctionInfo::cast(des), isolate); |
972 } | 970 } |
973 } | 971 } |
974 | 972 |
975 if (!maybe_result.ToHandle(&result)) { | 973 if (!maybe_result.ToHandle(&result)) { |
976 // No cache entry found. Compile the script. | 974 // No cache entry found. Compile the script. |
977 | 975 |
978 // Create a script object describing the script to be compiled. | 976 // Create a script object describing the script to be compiled. |
979 Handle<Script> script = isolate->factory()->NewScript(source); | 977 Handle<Script> script = isolate->factory()->NewScript(source); |
980 if (natives == NATIVES_CODE) { | 978 if (natives == NATIVES_CODE) { |
981 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 979 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
982 } | 980 } |
983 if (!script_name.is_null()) { | 981 if (!script_name.is_null()) { |
984 script->set_name(*script_name); | 982 script->set_name(*script_name); |
985 script->set_line_offset(Smi::FromInt(line_offset)); | 983 script->set_line_offset(Smi::FromInt(line_offset)); |
986 script->set_column_offset(Smi::FromInt(column_offset)); | 984 script->set_column_offset(Smi::FromInt(column_offset)); |
987 } | 985 } |
988 script->set_is_shared_cross_origin(is_shared_cross_origin); | 986 script->set_is_shared_cross_origin(is_shared_cross_origin); |
989 | 987 |
990 // Compile the function and add it to the cache. | 988 // Compile the function and add it to the cache. |
991 CompilationInfoWithZone info(script); | 989 CompilationInfoWithZone info(script); |
992 info.MarkAsGlobal(); | 990 info.MarkAsGlobal(); |
993 info.SetCachedData(cached_data, cached_data_mode); | 991 info.SetCachedData(cached_data, compile_options); |
994 info.SetExtension(extension); | 992 info.SetExtension(extension); |
995 info.SetContext(context); | 993 info.SetContext(context); |
996 if (FLAG_serialize_toplevel && cached_data_mode == PRODUCE_CACHED_DATA) { | 994 if (FLAG_serialize_toplevel && |
| 995 compile_options == ScriptCompiler::kProduceCodeCache) { |
997 info.PrepareForSerializing(); | 996 info.PrepareForSerializing(); |
998 } | 997 } |
999 if (FLAG_use_strict) info.SetStrictMode(STRICT); | 998 if (FLAG_use_strict) info.SetStrictMode(STRICT); |
1000 | 999 |
1001 result = CompileToplevel(&info); | 1000 result = CompileToplevel(&info); |
1002 if (extension == NULL && !result.is_null() && !result->dont_cache()) { | 1001 if (extension == NULL && !result.is_null() && !result->dont_cache()) { |
1003 compilation_cache->PutScript(source, context, result); | 1002 compilation_cache->PutScript(source, context, result); |
1004 if (FLAG_serialize_toplevel && cached_data_mode == PRODUCE_CACHED_DATA) { | 1003 if (FLAG_serialize_toplevel && |
| 1004 compile_options == ScriptCompiler::kProduceCodeCache) { |
1005 *cached_data = CodeSerializer::Serialize(result); | 1005 *cached_data = CodeSerializer::Serialize(result); |
1006 } | 1006 } |
1007 } | 1007 } |
| 1008 |
1008 if (result.is_null()) isolate->ReportPendingMessages(); | 1009 if (result.is_null()) isolate->ReportPendingMessages(); |
1009 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { | 1010 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { |
1010 result->ResetForNewContext(isolate->heap()->global_ic_age()); | 1011 result->ResetForNewContext(isolate->heap()->global_ic_age()); |
1011 } | 1012 } |
1012 return result; | 1013 return result; |
1013 } | 1014 } |
1014 | 1015 |
1015 | 1016 |
1016 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 1017 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
1017 Handle<Script> script) { | 1018 Handle<Script> script) { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 AllowHandleDereference allow_deref; | 1337 AllowHandleDereference allow_deref; |
1337 bool tracing_on = info()->IsStub() | 1338 bool tracing_on = info()->IsStub() |
1338 ? FLAG_trace_hydrogen_stubs | 1339 ? FLAG_trace_hydrogen_stubs |
1339 : (FLAG_trace_hydrogen && | 1340 : (FLAG_trace_hydrogen && |
1340 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1341 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1341 return (tracing_on && | 1342 return (tracing_on && |
1342 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1343 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1343 } | 1344 } |
1344 | 1345 |
1345 } } // namespace v8::internal | 1346 } } // namespace v8::internal |
OLD | NEW |