| 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/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/ast-this-access-visitor.h" | 10 #include "src/ast-this-access-visitor.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // with deoptimization support. | 183 // with deoptimization support. |
| 184 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); | 184 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); |
| 185 | 185 |
| 186 if (isolate_->debug()->is_active()) MarkAsDebug(); | 186 if (isolate_->debug()->is_active()) MarkAsDebug(); |
| 187 if (FLAG_context_specialization) MarkAsContextSpecializing(); | 187 if (FLAG_context_specialization) MarkAsContextSpecializing(); |
| 188 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); | 188 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); |
| 189 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); | 189 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); |
| 190 if (FLAG_turbo_types) MarkAsTypingEnabled(); | 190 if (FLAG_turbo_types) MarkAsTypingEnabled(); |
| 191 | 191 |
| 192 if (!shared_info_.is_null()) { | 192 if (!shared_info_.is_null()) { |
| 193 DCHECK(strict_mode() == SLOPPY); | 193 DCHECK(is_sloppy(language_mode())); |
| 194 SetStrictMode(shared_info_->strict_mode()); | 194 SetLanguageMode(shared_info_->language_mode()); |
| 195 } | 195 } |
| 196 bailout_reason_ = kNoReason; | 196 bailout_reason_ = kNoReason; |
| 197 | 197 |
| 198 if (!shared_info().is_null() && shared_info()->is_compiled()) { | 198 if (!shared_info().is_null() && shared_info()->is_compiled()) { |
| 199 // We should initialize the CompilationInfo feedback vector from the | 199 // We should initialize the CompilationInfo feedback vector from the |
| 200 // passed in shared info, rather than creating a new one. | 200 // passed in shared info, rather than creating a new one. |
| 201 feedback_vector_ = | 201 feedback_vector_ = |
| 202 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate); | 202 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate); |
| 203 } | 203 } |
| 204 } | 204 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 function_info->set_function_token_position(lit->function_token_position()); | 624 function_info->set_function_token_position(lit->function_token_position()); |
| 625 function_info->set_start_position(lit->start_position()); | 625 function_info->set_start_position(lit->start_position()); |
| 626 function_info->set_end_position(lit->end_position()); | 626 function_info->set_end_position(lit->end_position()); |
| 627 function_info->set_is_expression(lit->is_expression()); | 627 function_info->set_is_expression(lit->is_expression()); |
| 628 function_info->set_is_anonymous(lit->is_anonymous()); | 628 function_info->set_is_anonymous(lit->is_anonymous()); |
| 629 function_info->set_is_toplevel(is_toplevel); | 629 function_info->set_is_toplevel(is_toplevel); |
| 630 function_info->set_inferred_name(*lit->inferred_name()); | 630 function_info->set_inferred_name(*lit->inferred_name()); |
| 631 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 631 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| 632 function_info->set_allows_lazy_compilation_without_context( | 632 function_info->set_allows_lazy_compilation_without_context( |
| 633 lit->AllowsLazyCompilationWithoutContext()); | 633 lit->AllowsLazyCompilationWithoutContext()); |
| 634 function_info->set_strict_mode(lit->strict_mode()); | 634 function_info->set_language_mode(lit->language_mode()); |
| 635 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 635 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 636 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 636 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| 637 function_info->set_ast_node_count(lit->ast_node_count()); | 637 function_info->set_ast_node_count(lit->ast_node_count()); |
| 638 function_info->set_is_function(lit->is_function()); | 638 function_info->set_is_function(lit->is_function()); |
| 639 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); | 639 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); |
| 640 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | 640 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
| 641 function_info->set_kind(lit->kind()); | 641 function_info->set_kind(lit->kind()); |
| 642 function_info->set_uses_super_property(lit->uses_super_property()); | 642 function_info->set_uses_super_property(lit->uses_super_property()); |
| 643 function_info->set_uses_super_constructor_call( | 643 function_info->set_uses_super_constructor_call( |
| 644 lit->uses_super_constructor_call()); | 644 lit->uses_super_constructor_call()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 693 |
| 694 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( | 694 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
| 695 CompilationInfo* info) { | 695 CompilationInfo* info) { |
| 696 VMState<COMPILER> state(info->isolate()); | 696 VMState<COMPILER> state(info->isolate()); |
| 697 PostponeInterruptsScope postpone(info->isolate()); | 697 PostponeInterruptsScope postpone(info->isolate()); |
| 698 | 698 |
| 699 // Parse and update CompilationInfo with the results. | 699 // Parse and update CompilationInfo with the results. |
| 700 if (!Parser::Parse(info)) return MaybeHandle<Code>(); | 700 if (!Parser::Parse(info)) return MaybeHandle<Code>(); |
| 701 Handle<SharedFunctionInfo> shared = info->shared_info(); | 701 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 702 FunctionLiteral* lit = info->function(); | 702 FunctionLiteral* lit = info->function(); |
| 703 shared->set_strict_mode(lit->strict_mode()); | 703 shared->set_language_mode(lit->language_mode()); |
| 704 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 704 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
| 705 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); | 705 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); |
| 706 | 706 |
| 707 // Compile unoptimized code. | 707 // Compile unoptimized code. |
| 708 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 708 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
| 709 | 709 |
| 710 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 710 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
| 711 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 711 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
| 712 | 712 |
| 713 // Update the shared function info with the scope info. Allocating the | 713 // Update the shared function info with the scope info. Allocating the |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 isolate->debug()->OnAfterCompile(script); | 1218 isolate->debug()->OnAfterCompile(script); |
| 1219 | 1219 |
| 1220 return result; | 1220 return result; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 | 1223 |
| 1224 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1224 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
| 1225 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1225 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 1226 Handle<Context> context, StrictMode strict_mode, | 1226 Handle<Context> context, LanguageMode language_mode, |
| 1227 ParseRestriction restriction, int scope_position) { | 1227 ParseRestriction restriction, int scope_position) { |
| 1228 Isolate* isolate = source->GetIsolate(); | 1228 Isolate* isolate = source->GetIsolate(); |
| 1229 int source_length = source->length(); | 1229 int source_length = source->length(); |
| 1230 isolate->counters()->total_eval_size()->Increment(source_length); | 1230 isolate->counters()->total_eval_size()->Increment(source_length); |
| 1231 isolate->counters()->total_compile_size()->Increment(source_length); | 1231 isolate->counters()->total_compile_size()->Increment(source_length); |
| 1232 | 1232 |
| 1233 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1233 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 1234 MaybeHandle<SharedFunctionInfo> maybe_shared_info = | 1234 MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
| 1235 compilation_cache->LookupEval(source, outer_info, context, strict_mode, | 1235 compilation_cache->LookupEval(source, outer_info, context, language_mode, |
| 1236 scope_position); | 1236 scope_position); |
| 1237 Handle<SharedFunctionInfo> shared_info; | 1237 Handle<SharedFunctionInfo> shared_info; |
| 1238 | 1238 |
| 1239 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1239 if (!maybe_shared_info.ToHandle(&shared_info)) { |
| 1240 Handle<Script> script = isolate->factory()->NewScript(source); | 1240 Handle<Script> script = isolate->factory()->NewScript(source); |
| 1241 CompilationInfoWithZone info(script); | 1241 CompilationInfoWithZone info(script); |
| 1242 info.MarkAsEval(); | 1242 info.MarkAsEval(); |
| 1243 if (context->IsNativeContext()) info.MarkAsGlobal(); | 1243 if (context->IsNativeContext()) info.MarkAsGlobal(); |
| 1244 info.SetStrictMode(strict_mode); | 1244 info.SetLanguageMode(language_mode); |
| 1245 info.SetParseRestriction(restriction); | 1245 info.SetParseRestriction(restriction); |
| 1246 info.SetContext(context); | 1246 info.SetContext(context); |
| 1247 | 1247 |
| 1248 Debug::RecordEvalCaller(script); | 1248 Debug::RecordEvalCaller(script); |
| 1249 | 1249 |
| 1250 shared_info = CompileToplevel(&info); | 1250 shared_info = CompileToplevel(&info); |
| 1251 | 1251 |
| 1252 if (shared_info.is_null()) { | 1252 if (shared_info.is_null()) { |
| 1253 return MaybeHandle<JSFunction>(); | 1253 return MaybeHandle<JSFunction>(); |
| 1254 } else { | 1254 } else { |
| 1255 // Explicitly disable optimization for eval code. We're not yet prepared | 1255 // Explicitly disable optimization for eval code. We're not yet prepared |
| 1256 // to handle eval-code in the optimizing compiler. | 1256 // to handle eval-code in the optimizing compiler. |
| 1257 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { | 1257 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { |
| 1258 shared_info->DisableOptimization(kEval); | 1258 shared_info->DisableOptimization(kEval); |
| 1259 } | 1259 } |
| 1260 | 1260 |
| 1261 // If caller is strict mode, the result must be in strict mode as well. | 1261 // If caller is strict mode, the result must be in strict mode as well. |
| 1262 DCHECK(strict_mode == SLOPPY || shared_info->strict_mode() == STRICT); | 1262 DCHECK(is_sloppy(language_mode) || |
| 1263 is_strict(shared_info->language_mode())); |
| 1263 if (!shared_info->dont_cache()) { | 1264 if (!shared_info->dont_cache()) { |
| 1264 compilation_cache->PutEval(source, outer_info, context, shared_info, | 1265 compilation_cache->PutEval(source, outer_info, context, shared_info, |
| 1265 scope_position); | 1266 scope_position); |
| 1266 } | 1267 } |
| 1267 } | 1268 } |
| 1268 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { | 1269 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { |
| 1269 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); | 1270 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); |
| 1270 } | 1271 } |
| 1271 | 1272 |
| 1272 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1273 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 // Compile the function and add it to the cache. | 1346 // Compile the function and add it to the cache. |
| 1346 CompilationInfoWithZone info(script); | 1347 CompilationInfoWithZone info(script); |
| 1347 info.MarkAsGlobal(); | 1348 info.MarkAsGlobal(); |
| 1348 info.SetCachedData(cached_data, compile_options); | 1349 info.SetCachedData(cached_data, compile_options); |
| 1349 info.SetExtension(extension); | 1350 info.SetExtension(extension); |
| 1350 info.SetContext(context); | 1351 info.SetContext(context); |
| 1351 if (FLAG_serialize_toplevel && | 1352 if (FLAG_serialize_toplevel && |
| 1352 compile_options == ScriptCompiler::kProduceCodeCache) { | 1353 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1353 info.PrepareForSerializing(); | 1354 info.PrepareForSerializing(); |
| 1354 } | 1355 } |
| 1355 if (FLAG_use_strict) info.SetStrictMode(STRICT); | 1356 if (FLAG_use_strict) { |
| 1357 info.SetLanguageMode( |
| 1358 static_cast<LanguageMode>(info.language_mode() | STRICT)); |
| 1359 } |
| 1356 | 1360 |
| 1357 result = CompileToplevel(&info); | 1361 result = CompileToplevel(&info); |
| 1358 if (extension == NULL && !result.is_null() && !result->dont_cache()) { | 1362 if (extension == NULL && !result.is_null() && !result->dont_cache()) { |
| 1359 compilation_cache->PutScript(source, context, result); | 1363 compilation_cache->PutScript(source, context, result); |
| 1360 if (FLAG_serialize_toplevel && | 1364 if (FLAG_serialize_toplevel && |
| 1361 compile_options == ScriptCompiler::kProduceCodeCache) { | 1365 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1362 HistogramTimerScope histogram_timer( | 1366 HistogramTimerScope histogram_timer( |
| 1363 isolate->counters()->compile_serialize()); | 1367 isolate->counters()->compile_serialize()); |
| 1364 *cached_data = CodeSerializer::Serialize(isolate, result, source); | 1368 *cached_data = CodeSerializer::Serialize(isolate, result, source); |
| 1365 if (FLAG_profile_deserialization) { | 1369 if (FLAG_profile_deserialization) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1376 return result; | 1380 return result; |
| 1377 } | 1381 } |
| 1378 | 1382 |
| 1379 | 1383 |
| 1380 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( | 1384 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( |
| 1381 CompilationInfo* info, int source_length) { | 1385 CompilationInfo* info, int source_length) { |
| 1382 Isolate* isolate = info->isolate(); | 1386 Isolate* isolate = info->isolate(); |
| 1383 isolate->counters()->total_load_size()->Increment(source_length); | 1387 isolate->counters()->total_load_size()->Increment(source_length); |
| 1384 isolate->counters()->total_compile_size()->Increment(source_length); | 1388 isolate->counters()->total_compile_size()->Increment(source_length); |
| 1385 | 1389 |
| 1386 if (FLAG_use_strict) info->SetStrictMode(STRICT); | 1390 if (FLAG_use_strict) { |
| 1391 info->SetLanguageMode( |
| 1392 static_cast<LanguageMode>(info->language_mode() | STRICT)); |
| 1393 } |
| 1387 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the | 1394 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the |
| 1388 // real code caching lands, streaming needs to be adapted to use it. | 1395 // real code caching lands, streaming needs to be adapted to use it. |
| 1389 return CompileToplevel(info); | 1396 return CompileToplevel(info); |
| 1390 } | 1397 } |
| 1391 | 1398 |
| 1392 | 1399 |
| 1393 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( | 1400 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( |
| 1394 FunctionLiteral* literal, Handle<Script> script, | 1401 FunctionLiteral* literal, Handle<Script> script, |
| 1395 CompilationInfo* outer_info) { | 1402 CompilationInfo* outer_info) { |
| 1396 // Precondition: code has been parsed and scopes have been analyzed. | 1403 // Precondition: code has been parsed and scopes have been analyzed. |
| 1397 CompilationInfoWithZone info(script); | 1404 CompilationInfoWithZone info(script); |
| 1398 info.SetFunction(literal); | 1405 info.SetFunction(literal); |
| 1399 info.PrepareForCompilation(literal->scope()); | 1406 info.PrepareForCompilation(literal->scope()); |
| 1400 info.SetStrictMode(literal->scope()->strict_mode()); | 1407 info.SetLanguageMode(literal->scope()->language_mode()); |
| 1401 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1408 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
| 1402 | 1409 |
| 1403 Isolate* isolate = info.isolate(); | 1410 Isolate* isolate = info.isolate(); |
| 1404 Factory* factory = isolate->factory(); | 1411 Factory* factory = isolate->factory(); |
| 1405 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | 1412 LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
| 1406 // Determine if the function can be lazily compiled. This is necessary to | 1413 // Determine if the function can be lazily compiled. This is necessary to |
| 1407 // allow some of our builtin JS files to be lazily compiled. These | 1414 // allow some of our builtin JS files to be lazily compiled. These |
| 1408 // builtins cannot be handled lazily by the parser, since we have to know | 1415 // builtins cannot be handled lazily by the parser, since we have to know |
| 1409 // if a function uses the special natives syntax, which is something the | 1416 // if a function uses the special natives syntax, which is something the |
| 1410 // parser records. | 1417 // parser records. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 } | 1609 } |
| 1603 | 1610 |
| 1604 | 1611 |
| 1605 #if DEBUG | 1612 #if DEBUG |
| 1606 void CompilationInfo::PrintAstForTesting() { | 1613 void CompilationInfo::PrintAstForTesting() { |
| 1607 PrintF("--- Source from AST ---\n%s\n", | 1614 PrintF("--- Source from AST ---\n%s\n", |
| 1608 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1615 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1609 } | 1616 } |
| 1610 #endif | 1617 #endif |
| 1611 } } // namespace v8::internal | 1618 } } // namespace v8::internal |
| OLD | NEW |