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

Side by Side Diff: src/compiler.cc

Issue 373713006: Introduce code serializer/deserializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments and rebased 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/assembler.h ('k') | src/flag-definitions.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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 bool is_shared_cross_origin, 926 bool is_shared_cross_origin,
927 Handle<Context> context, 927 Handle<Context> context,
928 v8::Extension* extension, 928 v8::Extension* extension,
929 ScriptData** cached_data, 929 ScriptData** cached_data,
930 CachedDataMode cached_data_mode, 930 CachedDataMode cached_data_mode,
931 NativesFlag natives) { 931 NativesFlag natives) {
932 if (cached_data_mode == NO_CACHED_DATA) { 932 if (cached_data_mode == NO_CACHED_DATA) {
933 cached_data = NULL; 933 cached_data = NULL;
934 } else if (cached_data_mode == PRODUCE_CACHED_DATA) { 934 } else if (cached_data_mode == PRODUCE_CACHED_DATA) {
935 ASSERT(cached_data && !*cached_data); 935 ASSERT(cached_data && !*cached_data);
936 ASSERT(extension == NULL);
936 } else { 937 } else {
937 ASSERT(cached_data_mode == CONSUME_CACHED_DATA); 938 ASSERT(cached_data_mode == CONSUME_CACHED_DATA);
938 ASSERT(cached_data && *cached_data); 939 ASSERT(cached_data && *cached_data);
940 ASSERT(extension == NULL);
939 } 941 }
940 Isolate* isolate = source->GetIsolate(); 942 Isolate* isolate = source->GetIsolate();
941 int source_length = source->length(); 943 int source_length = source->length();
942 isolate->counters()->total_load_size()->Increment(source_length); 944 isolate->counters()->total_load_size()->Increment(source_length);
943 isolate->counters()->total_compile_size()->Increment(source_length); 945 isolate->counters()->total_compile_size()->Increment(source_length);
944 946
945 CompilationCache* compilation_cache = isolate->compilation_cache(); 947 CompilationCache* compilation_cache = isolate->compilation_cache();
946 948
947 // Do a lookup in the compilation cache but not for extensions. 949 // Do a lookup in the compilation cache but not for extensions.
948 MaybeHandle<SharedFunctionInfo> maybe_result; 950 MaybeHandle<SharedFunctionInfo> maybe_result;
949 Handle<SharedFunctionInfo> result; 951 Handle<SharedFunctionInfo> result;
950 if (extension == NULL) { 952 if (extension == NULL) {
951 maybe_result = compilation_cache->LookupScript( 953 maybe_result = compilation_cache->LookupScript(
952 source, script_name, line_offset, column_offset, 954 source, script_name, line_offset, column_offset,
953 is_shared_cross_origin, context); 955 is_shared_cross_origin, context);
956 if (maybe_result.is_null() && FLAG_serialize_toplevel &&
957 cached_data_mode == CONSUME_CACHED_DATA) {
958 Object* des = CodeSerializer::Deserialize(isolate, *cached_data);
959 return handle(SharedFunctionInfo::cast(des), isolate);
960 }
954 } 961 }
955 962
956 if (!maybe_result.ToHandle(&result)) { 963 if (!maybe_result.ToHandle(&result)) {
957 // No cache entry found. Compile the script. 964 // No cache entry found. Compile the script.
958 965
959 // Create a script object describing the script to be compiled. 966 // Create a script object describing the script to be compiled.
960 Handle<Script> script = isolate->factory()->NewScript(source); 967 Handle<Script> script = isolate->factory()->NewScript(source);
961 if (natives == NATIVES_CODE) { 968 if (natives == NATIVES_CODE) {
962 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 969 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
963 } 970 }
964 if (!script_name.is_null()) { 971 if (!script_name.is_null()) {
965 script->set_name(*script_name); 972 script->set_name(*script_name);
966 script->set_line_offset(Smi::FromInt(line_offset)); 973 script->set_line_offset(Smi::FromInt(line_offset));
967 script->set_column_offset(Smi::FromInt(column_offset)); 974 script->set_column_offset(Smi::FromInt(column_offset));
968 } 975 }
969 script->set_is_shared_cross_origin(is_shared_cross_origin); 976 script->set_is_shared_cross_origin(is_shared_cross_origin);
970 977
971 // Compile the function and add it to the cache. 978 // Compile the function and add it to the cache.
972 CompilationInfoWithZone info(script); 979 CompilationInfoWithZone info(script);
973 info.MarkAsGlobal(); 980 info.MarkAsGlobal();
981 info.SetCachedData(cached_data, cached_data_mode);
974 info.SetExtension(extension); 982 info.SetExtension(extension);
975 info.SetCachedData(cached_data, cached_data_mode);
976 info.SetContext(context); 983 info.SetContext(context);
977 if (FLAG_use_strict) info.SetStrictMode(STRICT); 984 if (FLAG_use_strict) info.SetStrictMode(STRICT);
985
978 result = CompileToplevel(&info); 986 result = CompileToplevel(&info);
979 if (extension == NULL && !result.is_null() && !result->dont_cache()) { 987 if (extension == NULL && !result.is_null() && !result->dont_cache()) {
980 compilation_cache->PutScript(source, context, result); 988 compilation_cache->PutScript(source, context, result);
989 if (FLAG_serialize_toplevel && cached_data_mode == PRODUCE_CACHED_DATA) {
990 *cached_data = CodeSerializer::Serialize(result);
991 }
981 } 992 }
982 if (result.is_null()) isolate->ReportPendingMessages(); 993 if (result.is_null()) isolate->ReportPendingMessages();
983 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { 994 } else if (result->ic_age() != isolate->heap()->global_ic_age()) {
984 result->ResetForNewContext(isolate->heap()->global_ic_age()); 995 result->ResetForNewContext(isolate->heap()->global_ic_age());
985 } 996 }
986 return result; 997 return result;
987 } 998 }
988 999
989 1000
990 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, 1001 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
991 Handle<Script> script) { 1002 Handle<Script> script) {
992 // Precondition: code has been parsed and scopes have been analyzed. 1003 // Precondition: code has been parsed and scopes have been analyzed.
993 CompilationInfoWithZone info(script); 1004 CompilationInfoWithZone info(script);
994 info.SetFunction(literal); 1005 info.SetFunction(literal);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 AllowHandleDereference allow_deref; 1321 AllowHandleDereference allow_deref;
1311 bool tracing_on = info()->IsStub() 1322 bool tracing_on = info()->IsStub()
1312 ? FLAG_trace_hydrogen_stubs 1323 ? FLAG_trace_hydrogen_stubs
1313 : (FLAG_trace_hydrogen && 1324 : (FLAG_trace_hydrogen &&
1314 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1325 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1315 return (tracing_on && 1326 return (tracing_on &&
1316 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1327 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1317 } 1328 }
1318 1329
1319 } } // namespace v8::internal 1330 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/assembler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698