Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: src/compiler.cc

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even more rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler.h ('k') | src/d8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 793
794 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? 794 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
795 FixedArray* array = isolate->native_context()->embedder_data(); 795 FixedArray* array = isolate->native_context()->embedder_data();
796 script->set_context_data(array->get(0)); 796 script->set_context_data(array->get(0));
797 797
798 isolate->debug()->OnBeforeCompile(script); 798 isolate->debug()->OnBeforeCompile(script);
799 799
800 ASSERT(info->is_eval() || info->is_global()); 800 ASSERT(info->is_eval() || info->is_global());
801 801
802 bool parse_allow_lazy = 802 bool parse_allow_lazy =
803 (info->cached_data_mode() == CONSUME_CACHED_DATA || 803 (info->compile_options() == ScriptCompiler::kConsumeParserCache ||
804 String::cast(script->source())->length() > FLAG_min_preparse_length) && 804 String::cast(script->source())->length() > FLAG_min_preparse_length) &&
805 !DebuggerWantsEagerCompilation(info); 805 !DebuggerWantsEagerCompilation(info);
806 806
807 if (!parse_allow_lazy && info->cached_data_mode() != NO_CACHED_DATA) { 807 if (!parse_allow_lazy &&
808 (info->compile_options() == ScriptCompiler::kProduceParserCache ||
809 info->compile_options() == ScriptCompiler::kConsumeParserCache)) {
808 // We are going to parse eagerly, but we either 1) have cached data produced 810 // We are going to parse eagerly, but we either 1) have cached data produced
809 // by lazy parsing or 2) are asked to generate cached data. We cannot use 811 // by lazy parsing or 2) are asked to generate cached data. We cannot use
810 // the existing data, since it won't contain all the symbols we need for 812 // the existing data, since it won't contain all the symbols we need for
811 // eager parsing. In addition, it doesn't make sense to produce the data 813 // eager parsing. In addition, it doesn't make sense to produce the data
812 // when parsing eagerly. That data would contain all symbols, but no 814 // when parsing eagerly. That data would contain all symbols, but no
813 // functions, so it cannot be used to aid lazy parsing later. 815 // functions, so it cannot be used to aid lazy parsing later.
814 info->SetCachedData(NULL, NO_CACHED_DATA); 816 info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions);
815 } 817 }
816 818
817 Handle<SharedFunctionInfo> result; 819 Handle<SharedFunctionInfo> result;
818 820
819 { VMState<COMPILER> state(info->isolate()); 821 { VMState<COMPILER> state(info->isolate());
820 if (!Parser::Parse(info, parse_allow_lazy)) { 822 if (!Parser::Parse(info, parse_allow_lazy)) {
821 return Handle<SharedFunctionInfo>::null(); 823 return Handle<SharedFunctionInfo>::null();
822 } 824 }
823 825
824 FunctionLiteral* lit = info->function(); 826 FunctionLiteral* lit = info->function();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { 927 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
926 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); 928 shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
927 } 929 }
928 930
929 return isolate->factory()->NewFunctionFromSharedFunctionInfo( 931 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
930 shared_info, context, NOT_TENURED); 932 shared_info, context, NOT_TENURED);
931 } 933 }
932 934
933 935
934 Handle<SharedFunctionInfo> Compiler::CompileScript( 936 Handle<SharedFunctionInfo> Compiler::CompileScript(
935 Handle<String> source, 937 Handle<String> source, Handle<Object> script_name, int line_offset,
936 Handle<Object> script_name, 938 int column_offset, bool is_shared_cross_origin, Handle<Context> context,
937 int line_offset, 939 v8::Extension* extension, ScriptData** cached_data,
938 int column_offset, 940 ScriptCompiler::CompileOptions compile_options, NativesFlag natives) {
939 bool is_shared_cross_origin, 941 if (compile_options == ScriptCompiler::kNoCompileOptions) {
940 Handle<Context> context,
941 v8::Extension* extension,
942 ScriptData** cached_data,
943 CachedDataMode cached_data_mode,
944 NativesFlag natives) {
945 if (cached_data_mode == NO_CACHED_DATA) {
946 cached_data = NULL; 942 cached_data = NULL;
947 } else if (cached_data_mode == PRODUCE_CACHED_DATA) { 943 } else if (compile_options == ScriptCompiler::kProduceParserCache ||
944 compile_options == ScriptCompiler::kProduceCodeCache) {
948 ASSERT(cached_data && !*cached_data); 945 ASSERT(cached_data && !*cached_data);
949 ASSERT(extension == NULL); 946 ASSERT(extension == NULL);
950 } else { 947 } else {
951 ASSERT(cached_data_mode == CONSUME_CACHED_DATA); 948 ASSERT(compile_options == ScriptCompiler::kConsumeParserCache ||
949 compile_options == ScriptCompiler::kConsumeCodeCache);
952 ASSERT(cached_data && *cached_data); 950 ASSERT(cached_data && *cached_data);
953 ASSERT(extension == NULL); 951 ASSERT(extension == NULL);
954 } 952 }
955 Isolate* isolate = source->GetIsolate(); 953 Isolate* isolate = source->GetIsolate();
956 int source_length = source->length(); 954 int source_length = source->length();
957 isolate->counters()->total_load_size()->Increment(source_length); 955 isolate->counters()->total_load_size()->Increment(source_length);
958 isolate->counters()->total_compile_size()->Increment(source_length); 956 isolate->counters()->total_compile_size()->Increment(source_length);
959 957
960 CompilationCache* compilation_cache = isolate->compilation_cache(); 958 CompilationCache* compilation_cache = isolate->compilation_cache();
961 959
962 // Do a lookup in the compilation cache but not for extensions. 960 // Do a lookup in the compilation cache but not for extensions.
963 MaybeHandle<SharedFunctionInfo> maybe_result; 961 MaybeHandle<SharedFunctionInfo> maybe_result;
964 Handle<SharedFunctionInfo> result; 962 Handle<SharedFunctionInfo> result;
965 if (extension == NULL) { 963 if (extension == NULL) {
966 maybe_result = compilation_cache->LookupScript( 964 maybe_result = compilation_cache->LookupScript(
967 source, script_name, line_offset, column_offset, 965 source, script_name, line_offset, column_offset,
968 is_shared_cross_origin, context); 966 is_shared_cross_origin, context);
969 if (maybe_result.is_null() && FLAG_serialize_toplevel && 967 if (maybe_result.is_null() && FLAG_serialize_toplevel &&
970 cached_data_mode == CONSUME_CACHED_DATA) { 968 compile_options == ScriptCompiler::kConsumeCodeCache) {
971 return CodeSerializer::Deserialize(isolate, *cached_data, source); 969 return CodeSerializer::Deserialize(isolate, *cached_data, source);
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(isolate, result, source); 1005 *cached_data = CodeSerializer::Serialize(isolate, result, source);
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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 AllowHandleDereference allow_deref; 1335 AllowHandleDereference allow_deref;
1335 bool tracing_on = info()->IsStub() 1336 bool tracing_on = info()->IsStub()
1336 ? FLAG_trace_hydrogen_stubs 1337 ? FLAG_trace_hydrogen_stubs
1337 : (FLAG_trace_hydrogen && 1338 : (FLAG_trace_hydrogen &&
1338 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1339 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1339 return (tracing_on && 1340 return (tracing_on &&
1340 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1341 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1341 } 1342 }
1342 1343
1343 } } // namespace v8::internal 1344 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/d8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698