| 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/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), | 737 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
| 738 parse_info->function())) { | 738 parse_info->function())) { |
| 739 return false; | 739 return false; |
| 740 } | 740 } |
| 741 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); | 741 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
| 742 if (!shared_info.is_null()) { | 742 if (!shared_info.is_null()) { |
| 743 FunctionLiteral* lit = parse_info->function(); | 743 FunctionLiteral* lit = parse_info->function(); |
| 744 shared_info->set_ast_node_count(lit->ast_node_count()); | 744 shared_info->set_ast_node_count(lit->ast_node_count()); |
| 745 MaybeDisableOptimization(shared_info, lit->dont_optimize_reason()); | 745 MaybeDisableOptimization(shared_info, lit->dont_optimize_reason()); |
| 746 shared_info->set_dont_crankshaft(lit->flags()->Contains(kDontCrankshaft)); | 746 shared_info->set_dont_crankshaft(lit->flags()->Contains(kDontCrankshaft)); |
| 747 shared_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | |
| 748 } | 747 } |
| 749 return true; | 748 return true; |
| 750 } | 749 } |
| 751 | 750 |
| 752 | 751 |
| 753 bool Compiler::Analyze(ParseInfo* info) { | 752 bool Compiler::Analyze(ParseInfo* info) { |
| 754 DCHECK(info->function() != NULL); | 753 DCHECK(info->function() != NULL); |
| 755 if (!Rewriter::Rewrite(info)) return false; | 754 if (!Rewriter::Rewrite(info)) return false; |
| 756 if (!Scope::Analyze(info)) return false; | 755 if (!Scope::Analyze(info)) return false; |
| 757 if (!Renumber(info)) return false; | 756 if (!Renumber(info)) return false; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 } else { | 1164 } else { |
| 1166 // Explicitly disable optimization for eval code. We're not yet prepared | 1165 // Explicitly disable optimization for eval code. We're not yet prepared |
| 1167 // to handle eval-code in the optimizing compiler. | 1166 // to handle eval-code in the optimizing compiler. |
| 1168 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { | 1167 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { |
| 1169 shared_info->DisableOptimization(kEval); | 1168 shared_info->DisableOptimization(kEval); |
| 1170 } | 1169 } |
| 1171 | 1170 |
| 1172 // If caller is strict mode, the result must be in strict mode as well. | 1171 // If caller is strict mode, the result must be in strict mode as well. |
| 1173 DCHECK(is_sloppy(language_mode) || | 1172 DCHECK(is_sloppy(language_mode) || |
| 1174 is_strict(shared_info->language_mode())); | 1173 is_strict(shared_info->language_mode())); |
| 1175 if (!shared_info->dont_cache()) { | 1174 compilation_cache->PutEval(source, outer_info, context, shared_info, |
| 1176 compilation_cache->PutEval(source, outer_info, context, shared_info, | 1175 scope_position); |
| 1177 scope_position); | |
| 1178 } | |
| 1179 } | 1176 } |
| 1180 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { | 1177 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { |
| 1181 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); | 1178 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); |
| 1182 } | 1179 } |
| 1183 | 1180 |
| 1184 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1181 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1185 shared_info, context, NOT_TENURED); | 1182 shared_info, context, NOT_TENURED); |
| 1186 } | 1183 } |
| 1187 | 1184 |
| 1188 | 1185 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 context, language_mode); | 1226 context, language_mode); |
| 1230 if (maybe_result.is_null() && FLAG_serialize_toplevel && | 1227 if (maybe_result.is_null() && FLAG_serialize_toplevel && |
| 1231 compile_options == ScriptCompiler::kConsumeCodeCache && | 1228 compile_options == ScriptCompiler::kConsumeCodeCache && |
| 1232 !isolate->debug()->is_loaded()) { | 1229 !isolate->debug()->is_loaded()) { |
| 1233 // Then check cached code provided by embedder. | 1230 // Then check cached code provided by embedder. |
| 1234 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); | 1231 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); |
| 1235 Handle<SharedFunctionInfo> result; | 1232 Handle<SharedFunctionInfo> result; |
| 1236 if (CodeSerializer::Deserialize(isolate, *cached_data, source) | 1233 if (CodeSerializer::Deserialize(isolate, *cached_data, source) |
| 1237 .ToHandle(&result)) { | 1234 .ToHandle(&result)) { |
| 1238 // Promote to per-isolate compilation cache. | 1235 // Promote to per-isolate compilation cache. |
| 1239 DCHECK(!result->dont_cache()); | |
| 1240 compilation_cache->PutScript(source, context, language_mode, result); | 1236 compilation_cache->PutScript(source, context, language_mode, result); |
| 1241 return result; | 1237 return result; |
| 1242 } | 1238 } |
| 1243 // Deserializer failed. Fall through to compile. | 1239 // Deserializer failed. Fall through to compile. |
| 1244 } | 1240 } |
| 1245 } | 1241 } |
| 1246 | 1242 |
| 1247 base::ElapsedTimer timer; | 1243 base::ElapsedTimer timer; |
| 1248 if (FLAG_profile_deserialization && FLAG_serialize_toplevel && | 1244 if (FLAG_profile_deserialization && FLAG_serialize_toplevel && |
| 1249 compile_options == ScriptCompiler::kProduceCodeCache) { | 1245 compile_options == ScriptCompiler::kProduceCodeCache) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 parse_info.set_extension(extension); | 1280 parse_info.set_extension(extension); |
| 1285 parse_info.set_context(context); | 1281 parse_info.set_context(context); |
| 1286 if (FLAG_serialize_toplevel && | 1282 if (FLAG_serialize_toplevel && |
| 1287 compile_options == ScriptCompiler::kProduceCodeCache) { | 1283 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1288 info.PrepareForSerializing(); | 1284 info.PrepareForSerializing(); |
| 1289 } | 1285 } |
| 1290 | 1286 |
| 1291 parse_info.set_language_mode( | 1287 parse_info.set_language_mode( |
| 1292 static_cast<LanguageMode>(info.language_mode() | language_mode)); | 1288 static_cast<LanguageMode>(info.language_mode() | language_mode)); |
| 1293 result = CompileToplevel(&info); | 1289 result = CompileToplevel(&info); |
| 1294 if (extension == NULL && !result.is_null() && !result->dont_cache()) { | 1290 if (extension == NULL && !result.is_null()) { |
| 1295 compilation_cache->PutScript(source, context, language_mode, result); | 1291 compilation_cache->PutScript(source, context, language_mode, result); |
| 1296 if (FLAG_serialize_toplevel && | 1292 if (FLAG_serialize_toplevel && |
| 1297 compile_options == ScriptCompiler::kProduceCodeCache) { | 1293 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1298 HistogramTimerScope histogram_timer( | 1294 HistogramTimerScope histogram_timer( |
| 1299 isolate->counters()->compile_serialize()); | 1295 isolate->counters()->compile_serialize()); |
| 1300 *cached_data = CodeSerializer::Serialize(isolate, result, source); | 1296 *cached_data = CodeSerializer::Serialize(isolate, result, source); |
| 1301 if (FLAG_profile_deserialization) { | 1297 if (FLAG_profile_deserialization) { |
| 1302 PrintF("[Compiling and serializing took %0.3f ms]\n", | 1298 PrintF("[Compiling and serializing took %0.3f ms]\n", |
| 1303 timer.Elapsed().InMillisecondsF()); | 1299 timer.Elapsed().InMillisecondsF()); |
| 1304 } | 1300 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 | 1564 |
| 1569 | 1565 |
| 1570 #if DEBUG | 1566 #if DEBUG |
| 1571 void CompilationInfo::PrintAstForTesting() { | 1567 void CompilationInfo::PrintAstForTesting() { |
| 1572 PrintF("--- Source from AST ---\n%s\n", | 1568 PrintF("--- Source from AST ---\n%s\n", |
| 1573 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1569 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1574 } | 1570 } |
| 1575 #endif | 1571 #endif |
| 1576 } // namespace internal | 1572 } // namespace internal |
| 1577 } // namespace v8 | 1573 } // namespace v8 |
| OLD | NEW |