| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "runtime-profiler.h" | 44 #include "runtime-profiler.h" |
| 45 #include "scanner-character-streams.h" | 45 #include "scanner-character-streams.h" |
| 46 #include "scopeinfo.h" | 46 #include "scopeinfo.h" |
| 47 #include "scopes.h" | 47 #include "scopes.h" |
| 48 #include "vm-state-inl.h" | 48 #include "vm-state-inl.h" |
| 49 | 49 |
| 50 namespace v8 { | 50 namespace v8 { |
| 51 namespace internal { | 51 namespace internal { |
| 52 | 52 |
| 53 | 53 |
| 54 CompilationInfo::CompilationInfo(Handle<Script> script) | 54 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) |
| 55 : isolate_(script->GetIsolate()), | 55 : isolate_(script->GetIsolate()), |
| 56 flags_(LanguageModeField::encode(CLASSIC_MODE)), | 56 flags_(LanguageModeField::encode(CLASSIC_MODE)), |
| 57 function_(NULL), | 57 function_(NULL), |
| 58 scope_(NULL), | 58 scope_(NULL), |
| 59 global_scope_(NULL), | 59 global_scope_(NULL), |
| 60 script_(script), | 60 script_(script), |
| 61 extension_(NULL), | 61 extension_(NULL), |
| 62 pre_parse_data_(NULL), | 62 pre_parse_data_(NULL), |
| 63 osr_ast_id_(AstNode::kNoNumber) { | 63 osr_ast_id_(AstNode::kNoNumber), |
| 64 zone_(zone) { |
| 64 Initialize(BASE); | 65 Initialize(BASE); |
| 65 } | 66 } |
| 66 | 67 |
| 67 | 68 |
| 68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) | 69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| 70 Zone* zone) |
| 69 : isolate_(shared_info->GetIsolate()), | 71 : isolate_(shared_info->GetIsolate()), |
| 70 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 72 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 71 IsLazy::encode(true)), | 73 IsLazy::encode(true)), |
| 72 function_(NULL), | 74 function_(NULL), |
| 73 scope_(NULL), | 75 scope_(NULL), |
| 74 global_scope_(NULL), | 76 global_scope_(NULL), |
| 75 shared_info_(shared_info), | 77 shared_info_(shared_info), |
| 76 script_(Handle<Script>(Script::cast(shared_info->script()))), | 78 script_(Handle<Script>(Script::cast(shared_info->script()))), |
| 77 extension_(NULL), | 79 extension_(NULL), |
| 78 pre_parse_data_(NULL), | 80 pre_parse_data_(NULL), |
| 79 osr_ast_id_(AstNode::kNoNumber) { | 81 osr_ast_id_(AstNode::kNoNumber), |
| 82 zone_(zone) { |
| 80 Initialize(BASE); | 83 Initialize(BASE); |
| 81 } | 84 } |
| 82 | 85 |
| 83 | 86 |
| 84 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) | 87 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
| 85 : isolate_(closure->GetIsolate()), | 88 : isolate_(closure->GetIsolate()), |
| 86 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 89 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 87 IsLazy::encode(true)), | 90 IsLazy::encode(true)), |
| 88 function_(NULL), | 91 function_(NULL), |
| 89 scope_(NULL), | 92 scope_(NULL), |
| 90 global_scope_(NULL), | 93 global_scope_(NULL), |
| 91 closure_(closure), | 94 closure_(closure), |
| 92 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 95 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 93 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 96 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| 94 extension_(NULL), | 97 extension_(NULL), |
| 95 pre_parse_data_(NULL), | 98 pre_parse_data_(NULL), |
| 96 osr_ast_id_(AstNode::kNoNumber) { | 99 osr_ast_id_(AstNode::kNoNumber), |
| 100 zone_(zone) { |
| 97 Initialize(BASE); | 101 Initialize(BASE); |
| 98 } | 102 } |
| 99 | 103 |
| 100 | 104 |
| 101 // Disable optimization for the rest of the compilation pipeline. | 105 // Disable optimization for the rest of the compilation pipeline. |
| 102 void CompilationInfo::DisableOptimization() { | 106 void CompilationInfo::DisableOptimization() { |
| 103 bool is_optimizable_closure = | 107 bool is_optimizable_closure = |
| 104 FLAG_optimize_closures && | 108 FLAG_optimize_closures && |
| 105 closure_.is_null() && | 109 closure_.is_null() && |
| 106 !scope_->HasTrivialOuterContext() && | 110 !scope_->HasTrivialOuterContext() && |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 258 } |
| 255 | 259 |
| 256 // Recompile the unoptimized version of the code if the current version | 260 // Recompile the unoptimized version of the code if the current version |
| 257 // doesn't have deoptimization support. Alternatively, we may decide to | 261 // doesn't have deoptimization support. Alternatively, we may decide to |
| 258 // run the full code generator to get a baseline for the compile-time | 262 // run the full code generator to get a baseline for the compile-time |
| 259 // performance of the hydrogen-based compiler. | 263 // performance of the hydrogen-based compiler. |
| 260 int64_t start = OS::Ticks(); | 264 int64_t start = OS::Ticks(); |
| 261 bool should_recompile = !info->shared_info()->has_deoptimization_support(); | 265 bool should_recompile = !info->shared_info()->has_deoptimization_support(); |
| 262 if (should_recompile || FLAG_hydrogen_stats) { | 266 if (should_recompile || FLAG_hydrogen_stats) { |
| 263 HPhase phase(HPhase::kFullCodeGen); | 267 HPhase phase(HPhase::kFullCodeGen); |
| 264 CompilationInfo unoptimized(info->shared_info()); | 268 CompilationInfoWithZone unoptimized(info->shared_info()); |
| 265 // Note that we use the same AST that we will use for generating the | 269 // Note that we use the same AST that we will use for generating the |
| 266 // optimized code. | 270 // optimized code. |
| 267 unoptimized.SetFunction(info->function()); | 271 unoptimized.SetFunction(info->function()); |
| 268 unoptimized.SetScope(info->scope()); | 272 unoptimized.SetScope(info->scope()); |
| 269 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 273 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
| 270 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 274 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
| 271 if (should_recompile) { | 275 if (should_recompile) { |
| 272 if (!succeeded) return false; | 276 if (!succeeded) return false; |
| 273 Handle<SharedFunctionInfo> shared = info->shared_info(); | 277 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 274 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 278 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 ASSERT(info->shared_info()->has_deoptimization_support()); | 291 ASSERT(info->shared_info()->has_deoptimization_support()); |
| 288 | 292 |
| 289 if (FLAG_trace_hydrogen) { | 293 if (FLAG_trace_hydrogen) { |
| 290 PrintF("-----------------------------------------------------------\n"); | 294 PrintF("-----------------------------------------------------------\n"); |
| 291 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 295 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
| 292 HTracer::Instance()->TraceCompilation(info->function()); | 296 HTracer::Instance()->TraceCompilation(info->function()); |
| 293 } | 297 } |
| 294 | 298 |
| 295 Handle<Context> global_context(info->closure()->context()->global_context()); | 299 Handle<Context> global_context(info->closure()->context()->global_context()); |
| 296 TypeFeedbackOracle oracle(code, global_context, info->isolate(), | 300 TypeFeedbackOracle oracle(code, global_context, info->isolate(), |
| 297 info->isolate()->zone()); | 301 info->zone()); |
| 298 HGraphBuilder builder(info, &oracle, info->isolate()->zone()); | 302 HGraphBuilder builder(info, &oracle); |
| 299 HPhase phase(HPhase::kTotal); | 303 HPhase phase(HPhase::kTotal); |
| 300 HGraph* graph = builder.CreateGraph(); | 304 HGraph* graph = builder.CreateGraph(); |
| 301 if (info->isolate()->has_pending_exception()) { | 305 if (info->isolate()->has_pending_exception()) { |
| 302 info->SetCode(Handle<Code>::null()); | 306 info->SetCode(Handle<Code>::null()); |
| 303 return false; | 307 return false; |
| 304 } | 308 } |
| 305 | 309 |
| 306 if (graph != NULL) { | 310 if (graph != NULL) { |
| 307 Handle<Code> optimized_code = graph->Compile(info, graph->zone()); | 311 Handle<Code> optimized_code = graph->Compile(); |
| 308 if (!optimized_code.is_null()) { | 312 if (!optimized_code.is_null()) { |
| 309 info->SetCode(optimized_code); | 313 info->SetCode(optimized_code); |
| 310 FinishOptimization(info->closure(), start); | 314 FinishOptimization(info->closure(), start); |
| 311 return true; | 315 return true; |
| 312 } | 316 } |
| 313 } | 317 } |
| 314 | 318 |
| 315 // Keep using the shared code. | 319 // Keep using the shared code. |
| 316 info->AbortOptimization(); | 320 info->AbortOptimization(); |
| 317 if (!builder.inline_bailout()) { | 321 if (!builder.inline_bailout()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 340 } | 344 } |
| 341 | 345 |
| 342 | 346 |
| 343 #ifdef ENABLE_DEBUGGER_SUPPORT | 347 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 344 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 348 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
| 345 // Precondition: code has been parsed. Postcondition: the code field in | 349 // Precondition: code has been parsed. Postcondition: the code field in |
| 346 // the compilation info is set if compilation succeeded. | 350 // the compilation info is set if compilation succeeded. |
| 347 bool succeeded = MakeCode(info); | 351 bool succeeded = MakeCode(info); |
| 348 if (!info->shared_info().is_null()) { | 352 if (!info->shared_info().is_null()) { |
| 349 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), | 353 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), |
| 350 info->isolate()->zone()); | 354 info->zone()); |
| 351 info->shared_info()->set_scope_info(*scope_info); | 355 info->shared_info()->set_scope_info(*scope_info); |
| 352 } | 356 } |
| 353 return succeeded; | 357 return succeeded; |
| 354 } | 358 } |
| 355 #endif | 359 #endif |
| 356 | 360 |
| 357 | 361 |
| 358 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { | 362 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
| 359 Isolate* isolate = info->isolate(); | 363 Isolate* isolate = info->isolate(); |
| 360 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 364 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT); |
| 361 PostponeInterruptsScope postpone(isolate); | 365 PostponeInterruptsScope postpone(isolate); |
| 362 | 366 |
| 363 ASSERT(!isolate->global_context().is_null()); | 367 ASSERT(!isolate->global_context().is_null()); |
| 364 Handle<Script> script = info->script(); | 368 Handle<Script> script = info->script(); |
| 365 script->set_context_data((*isolate->global_context())->data()); | 369 script->set_context_data((*isolate->global_context())->data()); |
| 366 | 370 |
| 367 #ifdef ENABLE_DEBUGGER_SUPPORT | 371 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 368 if (info->is_eval()) { | 372 if (info->is_eval()) { |
| 369 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; | 373 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; |
| 370 script->set_compilation_type(Smi::FromInt(compilation_type)); | 374 script->set_compilation_type(Smi::FromInt(compilation_type)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 return Handle<SharedFunctionInfo>::null(); | 418 return Handle<SharedFunctionInfo>::null(); |
| 415 } | 419 } |
| 416 | 420 |
| 417 // Allocate function. | 421 // Allocate function. |
| 418 ASSERT(!info->code().is_null()); | 422 ASSERT(!info->code().is_null()); |
| 419 Handle<SharedFunctionInfo> result = | 423 Handle<SharedFunctionInfo> result = |
| 420 isolate->factory()->NewSharedFunctionInfo( | 424 isolate->factory()->NewSharedFunctionInfo( |
| 421 lit->name(), | 425 lit->name(), |
| 422 lit->materialized_literal_count(), | 426 lit->materialized_literal_count(), |
| 423 info->code(), | 427 info->code(), |
| 424 ScopeInfo::Create(info->scope(), info->isolate()->zone())); | 428 ScopeInfo::Create(info->scope(), info->zone())); |
| 425 | 429 |
| 426 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 430 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 427 Compiler::SetFunctionInfo(result, lit, true, script); | 431 Compiler::SetFunctionInfo(result, lit, true, script); |
| 428 | 432 |
| 429 if (script->name()->IsString()) { | 433 if (script->name()->IsString()) { |
| 430 PROFILE(isolate, CodeCreateEvent( | 434 PROFILE(isolate, CodeCreateEvent( |
| 431 info->is_eval() | 435 info->is_eval() |
| 432 ? Logger::EVAL_TAG | 436 ? Logger::EVAL_TAG |
| 433 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 437 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 434 *info->code(), | 438 *info->code(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 456 | 460 |
| 457 script->set_compilation_state( | 461 script->set_compilation_state( |
| 458 Smi::FromInt(Script::COMPILATION_STATE_COMPILED)); | 462 Smi::FromInt(Script::COMPILATION_STATE_COMPILED)); |
| 459 | 463 |
| 460 #ifdef ENABLE_DEBUGGER_SUPPORT | 464 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 461 // Notify debugger | 465 // Notify debugger |
| 462 isolate->debugger()->OnAfterCompile( | 466 isolate->debugger()->OnAfterCompile( |
| 463 script, Debugger::NO_AFTER_COMPILE_FLAGS); | 467 script, Debugger::NO_AFTER_COMPILE_FLAGS); |
| 464 #endif | 468 #endif |
| 465 | 469 |
| 466 live_edit_tracker.RecordFunctionInfo(result, lit, isolate->zone()); | 470 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
| 467 | 471 |
| 468 return result; | 472 return result; |
| 469 } | 473 } |
| 470 | 474 |
| 471 | 475 |
| 472 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, | 476 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
| 473 Handle<Object> script_name, | 477 Handle<Object> script_name, |
| 474 int line_offset, | 478 int line_offset, |
| 475 int column_offset, | 479 int column_offset, |
| 476 v8::Extension* extension, | 480 v8::Extension* extension, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 if (!script_name.is_null()) { | 518 if (!script_name.is_null()) { |
| 515 script->set_name(*script_name); | 519 script->set_name(*script_name); |
| 516 script->set_line_offset(Smi::FromInt(line_offset)); | 520 script->set_line_offset(Smi::FromInt(line_offset)); |
| 517 script->set_column_offset(Smi::FromInt(column_offset)); | 521 script->set_column_offset(Smi::FromInt(column_offset)); |
| 518 } | 522 } |
| 519 | 523 |
| 520 script->set_data(script_data.is_null() ? HEAP->undefined_value() | 524 script->set_data(script_data.is_null() ? HEAP->undefined_value() |
| 521 : *script_data); | 525 : *script_data); |
| 522 | 526 |
| 523 // Compile the function and add it to the cache. | 527 // Compile the function and add it to the cache. |
| 524 CompilationInfo info(script); | 528 CompilationInfoWithZone info(script); |
| 525 info.MarkAsGlobal(); | 529 info.MarkAsGlobal(); |
| 526 info.SetExtension(extension); | 530 info.SetExtension(extension); |
| 527 info.SetPreParseData(pre_data); | 531 info.SetPreParseData(pre_data); |
| 528 if (FLAG_use_strict) { | 532 if (FLAG_use_strict) { |
| 529 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); | 533 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); |
| 530 } | 534 } |
| 531 result = MakeFunctionInfo(&info); | 535 result = MakeFunctionInfo(&info); |
| 532 if (extension == NULL && !result.is_null()) { | 536 if (extension == NULL && !result.is_null()) { |
| 533 compilation_cache->PutScript(source, result); | 537 compilation_cache->PutScript(source, result); |
| 534 } | 538 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 562 CompilationCache* compilation_cache = isolate->compilation_cache(); | 566 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 563 result = compilation_cache->LookupEval(source, | 567 result = compilation_cache->LookupEval(source, |
| 564 context, | 568 context, |
| 565 is_global, | 569 is_global, |
| 566 language_mode, | 570 language_mode, |
| 567 scope_position); | 571 scope_position); |
| 568 | 572 |
| 569 if (result.is_null()) { | 573 if (result.is_null()) { |
| 570 // Create a script object describing the script to be compiled. | 574 // Create a script object describing the script to be compiled. |
| 571 Handle<Script> script = isolate->factory()->NewScript(source); | 575 Handle<Script> script = isolate->factory()->NewScript(source); |
| 572 CompilationInfo info(script); | 576 CompilationInfoWithZone info(script); |
| 573 info.MarkAsEval(); | 577 info.MarkAsEval(); |
| 574 if (is_global) info.MarkAsGlobal(); | 578 if (is_global) info.MarkAsGlobal(); |
| 575 info.SetLanguageMode(language_mode); | 579 info.SetLanguageMode(language_mode); |
| 576 info.SetCallingContext(context); | 580 info.SetCallingContext(context); |
| 577 result = MakeFunctionInfo(&info); | 581 result = MakeFunctionInfo(&info); |
| 578 if (!result.is_null()) { | 582 if (!result.is_null()) { |
| 579 // Explicitly disable optimization for eval code. We're not yet prepared | 583 // Explicitly disable optimization for eval code. We're not yet prepared |
| 580 // to handle eval-code in the optimizing compiler. | 584 // to handle eval-code in the optimizing compiler. |
| 581 result->DisableOptimization(); | 585 result->DisableOptimization(); |
| 582 | 586 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 597 } | 601 } |
| 598 } | 602 } |
| 599 | 603 |
| 600 return result; | 604 return result; |
| 601 } | 605 } |
| 602 | 606 |
| 603 | 607 |
| 604 bool Compiler::CompileLazy(CompilationInfo* info) { | 608 bool Compiler::CompileLazy(CompilationInfo* info) { |
| 605 Isolate* isolate = info->isolate(); | 609 Isolate* isolate = info->isolate(); |
| 606 | 610 |
| 607 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 611 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT); |
| 608 | 612 |
| 609 // The VM is in the COMPILER state until exiting this function. | 613 // The VM is in the COMPILER state until exiting this function. |
| 610 VMState state(isolate, COMPILER); | 614 VMState state(isolate, COMPILER); |
| 611 | 615 |
| 612 PostponeInterruptsScope postpone(isolate); | 616 PostponeInterruptsScope postpone(isolate); |
| 613 | 617 |
| 614 Handle<SharedFunctionInfo> shared = info->shared_info(); | 618 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 615 int compiled_size = shared->end_position() - shared->start_position(); | 619 int compiled_size = shared->end_position() - shared->start_position(); |
| 616 isolate->counters()->total_compile_size()->Increment(compiled_size); | 620 isolate->counters()->total_compile_size()->Increment(compiled_size); |
| 617 | 621 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 SharedFunctionInfo::AddToOptimizedCodeMap( | 689 SharedFunctionInfo::AddToOptimizedCodeMap( |
| 686 shared, global_context, code, literals); | 690 shared, global_context, code, literals); |
| 687 } | 691 } |
| 688 } else { | 692 } else { |
| 689 // Update the shared function info with the compiled code and the | 693 // Update the shared function info with the compiled code and the |
| 690 // scope info. Please note, that the order of the shared function | 694 // scope info. Please note, that the order of the shared function |
| 691 // info initialization is important since set_scope_info might | 695 // info initialization is important since set_scope_info might |
| 692 // trigger a GC, causing the ASSERT below to be invalid if the code | 696 // trigger a GC, causing the ASSERT below to be invalid if the code |
| 693 // was flushed. By setting the code object last we avoid this. | 697 // was flushed. By setting the code object last we avoid this. |
| 694 Handle<ScopeInfo> scope_info = | 698 Handle<ScopeInfo> scope_info = |
| 695 ScopeInfo::Create(info->scope(), info->isolate()->zone()); | 699 ScopeInfo::Create(info->scope(), info->zone()); |
| 696 shared->set_scope_info(*scope_info); | 700 shared->set_scope_info(*scope_info); |
| 697 shared->set_code(*code); | 701 shared->set_code(*code); |
| 698 if (!function.is_null()) { | 702 if (!function.is_null()) { |
| 699 function->ReplaceCode(*code); | 703 function->ReplaceCode(*code); |
| 700 ASSERT(!function->IsOptimized()); | 704 ASSERT(!function->IsOptimized()); |
| 701 } | 705 } |
| 702 | 706 |
| 703 // Set the expected number of properties for instances. | 707 // Set the expected number of properties for instances. |
| 704 FunctionLiteral* lit = info->function(); | 708 FunctionLiteral* lit = info->function(); |
| 705 int expected = lit->expected_property_count(); | 709 int expected = lit->expected_property_count(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 720 shared->set_ast_node_count(lit->ast_node_count()); | 724 shared->set_ast_node_count(lit->ast_node_count()); |
| 721 | 725 |
| 722 if (V8::UseCrankshaft()&& | 726 if (V8::UseCrankshaft()&& |
| 723 !function.is_null() && | 727 !function.is_null() && |
| 724 !shared->optimization_disabled()) { | 728 !shared->optimization_disabled()) { |
| 725 // If we're asked to always optimize, we compile the optimized | 729 // If we're asked to always optimize, we compile the optimized |
| 726 // version of the function right away - unless the debugger is | 730 // version of the function right away - unless the debugger is |
| 727 // active as it makes no sense to compile optimized code then. | 731 // active as it makes no sense to compile optimized code then. |
| 728 if (FLAG_always_opt && | 732 if (FLAG_always_opt && |
| 729 !Isolate::Current()->DebuggerHasBreakPoints()) { | 733 !Isolate::Current()->DebuggerHasBreakPoints()) { |
| 730 CompilationInfo optimized(function); | 734 CompilationInfoWithZone optimized(function); |
| 731 optimized.SetOptimizing(AstNode::kNoNumber); | 735 optimized.SetOptimizing(AstNode::kNoNumber); |
| 732 return CompileLazy(&optimized); | 736 return CompileLazy(&optimized); |
| 733 } | 737 } |
| 734 } | 738 } |
| 735 } | 739 } |
| 736 | 740 |
| 737 return true; | 741 return true; |
| 738 } | 742 } |
| 739 } | 743 } |
| 740 | 744 |
| 741 ASSERT(info->code().is_null()); | 745 ASSERT(info->code().is_null()); |
| 742 return false; | 746 return false; |
| 743 } | 747 } |
| 744 | 748 |
| 745 | 749 |
| 746 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 750 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
| 747 Handle<Script> script) { | 751 Handle<Script> script) { |
| 748 // Precondition: code has been parsed and scopes have been analyzed. | 752 // Precondition: code has been parsed and scopes have been analyzed. |
| 749 CompilationInfo info(script); | 753 CompilationInfoWithZone info(script); |
| 750 info.SetFunction(literal); | 754 info.SetFunction(literal); |
| 751 info.SetScope(literal->scope()); | 755 info.SetScope(literal->scope()); |
| 752 info.SetLanguageMode(literal->scope()->language_mode()); | 756 info.SetLanguageMode(literal->scope()->language_mode()); |
| 753 | 757 |
| 754 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 758 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
| 755 // Determine if the function can be lazily compiled. This is necessary to | 759 // Determine if the function can be lazily compiled. This is necessary to |
| 756 // allow some of our builtin JS files to be lazily compiled. These | 760 // allow some of our builtin JS files to be lazily compiled. These |
| 757 // builtins cannot be handled lazily by the parser, since we have to know | 761 // builtins cannot be handled lazily by the parser, since we have to know |
| 758 // if a function uses the special natives syntax, which is something the | 762 // if a function uses the special natives syntax, which is something the |
| 759 // parser records. | 763 // parser records. |
| 760 // If the debugger requests compilation for break points, we cannot be | 764 // If the debugger requests compilation for break points, we cannot be |
| 761 // aggressive about lazy compilation, because it might trigger compilation | 765 // aggressive about lazy compilation, because it might trigger compilation |
| 762 // of functions without an outer context when setting a breakpoint through | 766 // of functions without an outer context when setting a breakpoint through |
| 763 // Runtime::FindSharedFunctionInfoInScript. | 767 // Runtime::FindSharedFunctionInfoInScript. |
| 764 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 768 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
| 765 bool allow_lazy = literal->AllowsLazyCompilation() && | 769 bool allow_lazy = literal->AllowsLazyCompilation() && |
| 766 !LiveEditFunctionTracker::IsActive(info.isolate()) && | 770 !LiveEditFunctionTracker::IsActive(info.isolate()) && |
| 767 (!info.isolate()->DebuggerHasBreakPoints() || allow_lazy_without_ctx); | 771 (!info.isolate()->DebuggerHasBreakPoints() || allow_lazy_without_ctx); |
| 768 | 772 |
| 769 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); | 773 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); |
| 770 | 774 |
| 771 // Generate code | 775 // Generate code |
| 772 if (FLAG_lazy && allow_lazy) { | 776 if (FLAG_lazy && allow_lazy) { |
| 773 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 777 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
| 774 info.SetCode(code); | 778 info.SetCode(code); |
| 775 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || | 779 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || |
| 776 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { | 780 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { |
| 777 ASSERT(!info.code().is_null()); | 781 ASSERT(!info.code().is_null()); |
| 778 scope_info = ScopeInfo::Create(info.scope(), info.isolate()->zone()); | 782 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
| 779 } else { | 783 } else { |
| 780 return Handle<SharedFunctionInfo>::null(); | 784 return Handle<SharedFunctionInfo>::null(); |
| 781 } | 785 } |
| 782 | 786 |
| 783 // Create a shared function info object. | 787 // Create a shared function info object. |
| 784 Handle<SharedFunctionInfo> result = | 788 Handle<SharedFunctionInfo> result = |
| 785 FACTORY->NewSharedFunctionInfo(literal->name(), | 789 FACTORY->NewSharedFunctionInfo(literal->name(), |
| 786 literal->materialized_literal_count(), | 790 literal->materialized_literal_count(), |
| 787 info.code(), | 791 info.code(), |
| 788 scope_info); | 792 scope_info); |
| 789 SetFunctionInfo(result, literal, false, script); | 793 SetFunctionInfo(result, literal, false, script); |
| 790 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 794 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
| 791 result->set_allows_lazy_compilation(allow_lazy); | 795 result->set_allows_lazy_compilation(allow_lazy); |
| 792 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); | 796 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); |
| 793 | 797 |
| 794 // Set the expected number of properties for instances and return | 798 // Set the expected number of properties for instances and return |
| 795 // the resulting function. | 799 // the resulting function. |
| 796 SetExpectedNofPropertiesFromEstimate(result, | 800 SetExpectedNofPropertiesFromEstimate(result, |
| 797 literal->expected_property_count()); | 801 literal->expected_property_count()); |
| 798 live_edit_tracker.RecordFunctionInfo(result, literal, info.isolate()->zone()); | 802 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
| 799 return result; | 803 return result; |
| 800 } | 804 } |
| 801 | 805 |
| 802 | 806 |
| 803 // Sets the function info on a function. | 807 // Sets the function info on a function. |
| 804 // The start_position points to the first '(' character after the function name | 808 // The start_position points to the first '(' character after the function name |
| 805 // in the full script source. When counting characters in the script source the | 809 // in the full script source. When counting characters in the script source the |
| 806 // the first character is number 0 (not 1). | 810 // the first character is number 0 (not 1). |
| 807 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 811 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| 808 FunctionLiteral* lit, | 812 FunctionLiteral* lit, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 } | 871 } |
| 868 } | 872 } |
| 869 | 873 |
| 870 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 874 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 871 Handle<Script>(info->script()), | 875 Handle<Script>(info->script()), |
| 872 Handle<Code>(info->code()), | 876 Handle<Code>(info->code()), |
| 873 info)); | 877 info)); |
| 874 } | 878 } |
| 875 | 879 |
| 876 } } // namespace v8::internal | 880 } } // namespace v8::internal |
| OLD | NEW |