Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) |
| 55 : isolate_(script->GetIsolate()), | 55 : isolate_(script->GetIsolate()), |
| 56 flags_(0), | 56 flags_(LanguageModeField::encode(CLASSIC_MODE)), |
| 57 function_(NULL), | 57 function_(NULL), |
| 58 scope_(NULL), | 58 scope_(NULL), |
| 59 script_(script), | 59 script_(script), |
| 60 extension_(NULL), | 60 extension_(NULL), |
| 61 pre_parse_data_(NULL), | 61 pre_parse_data_(NULL), |
| 62 osr_ast_id_(AstNode::kNoNumber) { | 62 osr_ast_id_(AstNode::kNoNumber) { |
| 63 Initialize(NONOPT); | 63 Initialize(NONOPT); |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) | 67 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) |
| 68 : isolate_(shared_info->GetIsolate()), | 68 : isolate_(shared_info->GetIsolate()), |
| 69 flags_(IsLazy::encode(true)), | 69 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 70 IsLazy::encode(true)), | |
| 70 function_(NULL), | 71 function_(NULL), |
| 71 scope_(NULL), | 72 scope_(NULL), |
| 72 shared_info_(shared_info), | 73 shared_info_(shared_info), |
| 73 script_(Handle<Script>(Script::cast(shared_info->script()))), | 74 script_(Handle<Script>(Script::cast(shared_info->script()))), |
| 74 extension_(NULL), | 75 extension_(NULL), |
| 75 pre_parse_data_(NULL), | 76 pre_parse_data_(NULL), |
| 76 osr_ast_id_(AstNode::kNoNumber) { | 77 osr_ast_id_(AstNode::kNoNumber) { |
| 77 Initialize(BASE); | 78 Initialize(BASE); |
| 78 } | 79 } |
| 79 | 80 |
| 80 | 81 |
| 81 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) | 82 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) |
| 82 : isolate_(closure->GetIsolate()), | 83 : isolate_(closure->GetIsolate()), |
| 83 flags_(IsLazy::encode(true)), | 84 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 85 IsLazy::encode(true)), | |
| 84 function_(NULL), | 86 function_(NULL), |
| 85 scope_(NULL), | 87 scope_(NULL), |
| 86 closure_(closure), | 88 closure_(closure), |
| 87 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 89 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 88 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 90 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| 89 extension_(NULL), | 91 extension_(NULL), |
| 90 pre_parse_data_(NULL), | 92 pre_parse_data_(NULL), |
| 91 osr_ast_id_(AstNode::kNoNumber) { | 93 osr_ast_id_(AstNode::kNoNumber) { |
| 92 Initialize(BASE); | 94 Initialize(BASE); |
| 93 } | 95 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 } | 528 } |
| 527 | 529 |
| 528 if (result.is_null()) isolate->ReportPendingMessages(); | 530 if (result.is_null()) isolate->ReportPendingMessages(); |
| 529 return result; | 531 return result; |
| 530 } | 532 } |
| 531 | 533 |
| 532 | 534 |
| 533 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, | 535 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| 534 Handle<Context> context, | 536 Handle<Context> context, |
| 535 bool is_global, | 537 bool is_global, |
| 536 StrictModeFlag strict_mode) { | 538 LanguageMode language_mode) { |
| 537 Isolate* isolate = source->GetIsolate(); | 539 Isolate* isolate = source->GetIsolate(); |
| 538 int source_length = source->length(); | 540 int source_length = source->length(); |
| 539 isolate->counters()->total_eval_size()->Increment(source_length); | 541 isolate->counters()->total_eval_size()->Increment(source_length); |
| 540 isolate->counters()->total_compile_size()->Increment(source_length); | 542 isolate->counters()->total_compile_size()->Increment(source_length); |
| 541 | 543 |
| 542 // The VM is in the COMPILER state until exiting this function. | 544 // The VM is in the COMPILER state until exiting this function. |
| 543 VMState state(isolate, COMPILER); | 545 VMState state(isolate, COMPILER); |
| 544 | 546 |
| 545 // Do a lookup in the compilation cache; if the entry is not there, invoke | 547 // Do a lookup in the compilation cache; if the entry is not there, invoke |
| 546 // the compiler and add the result to the cache. | 548 // the compiler and add the result to the cache. |
| 547 Handle<SharedFunctionInfo> result; | 549 Handle<SharedFunctionInfo> result; |
| 548 CompilationCache* compilation_cache = isolate->compilation_cache(); | 550 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 549 result = compilation_cache->LookupEval(source, | 551 result = compilation_cache->LookupEval(source, |
| 550 context, | 552 context, |
| 551 is_global, | 553 is_global, |
| 552 strict_mode); | 554 language_mode); |
| 553 | 555 |
| 554 if (result.is_null()) { | 556 if (result.is_null()) { |
| 555 // Create a script object describing the script to be compiled. | 557 // Create a script object describing the script to be compiled. |
| 556 Handle<Script> script = isolate->factory()->NewScript(source); | 558 Handle<Script> script = isolate->factory()->NewScript(source); |
| 557 CompilationInfo info(script); | 559 CompilationInfo info(script); |
| 558 info.MarkAsEval(); | 560 info.MarkAsEval(); |
| 559 if (is_global) info.MarkAsGlobal(); | 561 if (is_global) info.MarkAsGlobal(); |
| 560 info.SetStrictModeFlag(strict_mode); | 562 info.SetLanguageMode(language_mode); |
| 561 info.SetCallingContext(context); | 563 info.SetCallingContext(context); |
| 562 result = MakeFunctionInfo(&info); | 564 result = MakeFunctionInfo(&info); |
| 563 if (!result.is_null()) { | 565 if (!result.is_null()) { |
| 564 CompilationCache* compilation_cache = isolate->compilation_cache(); | 566 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 565 // If caller is strict mode, the result must be strict as well, | 567 // If caller is strict mode, the result must be in strict mode or |
| 566 // but not the other way around. Consider: | 568 // extended mode as well, but not the other way around. Consider: |
| 567 // eval("'use strict'; ..."); | 569 // eval("'use strict'; ..."); |
| 568 // TODO(keuchel): adapt this for extended mode. | 570 ASSERT(language_mode != STRICT_MODE || |
| 569 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); | 571 result->is_strict_or_extended_mode()); |
| 572 // If caller is in extended mode, the result must also be in | |
| 573 // extended mode. | |
| 574 ASSERT(language_mode != EXTENDED_MODE || | |
| 575 result->is_extended_mode()); | |
| 570 compilation_cache->PutEval(source, context, is_global, result); | 576 compilation_cache->PutEval(source, context, is_global, result); |
| 571 } | 577 } |
| 572 } | 578 } |
| 573 | 579 |
| 574 return result; | 580 return result; |
| 575 } | 581 } |
| 576 | 582 |
| 577 | 583 |
| 578 bool Compiler::CompileLazy(CompilationInfo* info) { | 584 bool Compiler::CompileLazy(CompilationInfo* info) { |
| 579 Isolate* isolate = info->isolate(); | 585 Isolate* isolate = info->isolate(); |
| 580 | 586 |
| 581 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 587 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
| 582 | 588 |
| 583 // The VM is in the COMPILER state until exiting this function. | 589 // The VM is in the COMPILER state until exiting this function. |
| 584 VMState state(isolate, COMPILER); | 590 VMState state(isolate, COMPILER); |
| 585 | 591 |
| 586 PostponeInterruptsScope postpone(isolate); | 592 PostponeInterruptsScope postpone(isolate); |
| 587 | 593 |
| 588 Handle<SharedFunctionInfo> shared = info->shared_info(); | 594 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 589 int compiled_size = shared->end_position() - shared->start_position(); | 595 int compiled_size = shared->end_position() - shared->start_position(); |
| 590 isolate->counters()->total_compile_size()->Increment(compiled_size); | 596 isolate->counters()->total_compile_size()->Increment(compiled_size); |
| 591 | 597 |
| 592 // Generate the AST for the lazily compiled function. | 598 // Generate the AST for the lazily compiled function. |
| 593 if (ParserApi::Parse(info)) { | 599 if (ParserApi::Parse(info)) { |
| 594 // Measure how long it takes to do the lazy compilation; only take the | 600 // Measure how long it takes to do the lazy compilation; only take the |
| 595 // rest of the function into account to avoid overlap with the lazy | 601 // rest of the function into account to avoid overlap with the lazy |
| 596 // parsing statistics. | 602 // parsing statistics. |
| 597 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 603 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 598 | 604 |
| 599 // After parsing we know function's strict mode. Remember it. | 605 // After parsing we know function's language mode. Remember it. |
| 600 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); | 606 LanguageMode language_mode = info->function()->language_mode(); |
| 601 ASSERT(info->strict_mode_flag() == kNonStrictMode || | 607 ASSERT(info->language_mode() != STRICT_MODE || |
| 602 info->strict_mode_flag() == strict_mode); | 608 language_mode == STRICT_MODE || |
| 603 ASSERT(shared->strict_mode_flag() == kNonStrictMode || | 609 language_mode == EXTENDED_MODE); |
| 604 shared->strict_mode_flag() == strict_mode); | 610 ASSERT(info->language_mode() != EXTENDED_MODE || |
| 605 info->SetStrictModeFlag(strict_mode); | 611 language_mode == EXTENDED_MODE); |
| 606 shared->set_strict_mode_flag(strict_mode); | 612 ASSERT(shared->language_mode() != STRICT_MODE || |
| 613 language_mode == STRICT_MODE || | |
| 614 language_mode == EXTENDED_MODE); | |
| 615 ASSERT(shared->language_mode() != EXTENDED_MODE || | |
| 616 language_mode == EXTENDED_MODE); | |
|
rossberg
2011/11/08 15:02:46
These assertions can be simplified, too.
Steven
2011/11/08 16:13:49
Done.
| |
| 617 info->SetLanguageMode(language_mode); | |
| 618 shared->set_language_mode(language_mode); | |
| 607 | 619 |
| 608 // Compile the code. | 620 // Compile the code. |
| 609 if (!MakeCode(info)) { | 621 if (!MakeCode(info)) { |
| 610 if (!isolate->has_pending_exception()) { | 622 if (!isolate->has_pending_exception()) { |
| 611 isolate->StackOverflow(); | 623 isolate->StackOverflow(); |
| 612 } | 624 } |
| 613 } else { | 625 } else { |
| 614 ASSERT(!info->code().is_null()); | 626 ASSERT(!info->code().is_null()); |
| 615 Handle<Code> code = info->code(); | 627 Handle<Code> code = info->code(); |
| 616 // Set optimizable to false if this is disallowed by the shared | 628 // Set optimizable to false if this is disallowed by the shared |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 return false; | 687 return false; |
| 676 } | 688 } |
| 677 | 689 |
| 678 | 690 |
| 679 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 691 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
| 680 Handle<Script> script) { | 692 Handle<Script> script) { |
| 681 // Precondition: code has been parsed and scopes have been analyzed. | 693 // Precondition: code has been parsed and scopes have been analyzed. |
| 682 CompilationInfo info(script); | 694 CompilationInfo info(script); |
| 683 info.SetFunction(literal); | 695 info.SetFunction(literal); |
| 684 info.SetScope(literal->scope()); | 696 info.SetScope(literal->scope()); |
| 685 info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); | 697 info.SetLanguageMode(literal->scope()->language_mode()); |
| 686 | 698 |
| 687 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 699 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
| 688 // Determine if the function can be lazily compiled. This is necessary to | 700 // Determine if the function can be lazily compiled. This is necessary to |
| 689 // allow some of our builtin JS files to be lazily compiled. These | 701 // allow some of our builtin JS files to be lazily compiled. These |
| 690 // builtins cannot be handled lazily by the parser, since we have to know | 702 // builtins cannot be handled lazily by the parser, since we have to know |
| 691 // if a function uses the special natives syntax, which is something the | 703 // if a function uses the special natives syntax, which is something the |
| 692 // parser records. | 704 // parser records. |
| 693 bool allow_lazy = literal->AllowsLazyCompilation() && | 705 bool allow_lazy = literal->AllowsLazyCompilation() && |
| 694 !LiveEditFunctionTracker::IsActive(info.isolate()); | 706 !LiveEditFunctionTracker::IsActive(info.isolate()); |
| 695 | 707 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 function_info->set_start_position(lit->start_position()); | 753 function_info->set_start_position(lit->start_position()); |
| 742 function_info->set_end_position(lit->end_position()); | 754 function_info->set_end_position(lit->end_position()); |
| 743 function_info->set_is_expression(lit->is_expression()); | 755 function_info->set_is_expression(lit->is_expression()); |
| 744 function_info->set_is_anonymous(lit->is_anonymous()); | 756 function_info->set_is_anonymous(lit->is_anonymous()); |
| 745 function_info->set_is_toplevel(is_toplevel); | 757 function_info->set_is_toplevel(is_toplevel); |
| 746 function_info->set_inferred_name(*lit->inferred_name()); | 758 function_info->set_inferred_name(*lit->inferred_name()); |
| 747 function_info->SetThisPropertyAssignmentsInfo( | 759 function_info->SetThisPropertyAssignmentsInfo( |
| 748 lit->has_only_simple_this_property_assignments(), | 760 lit->has_only_simple_this_property_assignments(), |
| 749 *lit->this_property_assignments()); | 761 *lit->this_property_assignments()); |
| 750 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 762 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| 751 function_info->set_strict_mode_flag(lit->strict_mode_flag()); | 763 function_info->set_language_mode(lit->language_mode()); |
| 752 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 764 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 753 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 765 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| 754 } | 766 } |
| 755 | 767 |
| 756 | 768 |
| 757 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 769 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 758 CompilationInfo* info, | 770 CompilationInfo* info, |
| 759 Handle<SharedFunctionInfo> shared) { | 771 Handle<SharedFunctionInfo> shared) { |
| 760 // SharedFunctionInfo is passed separately, because if CompilationInfo | 772 // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 761 // was created using Script object, it will not have it. | 773 // was created using Script object, it will not have it. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 787 } | 799 } |
| 788 } | 800 } |
| 789 | 801 |
| 790 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 802 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 791 Handle<Script>(info->script()), | 803 Handle<Script>(info->script()), |
| 792 Handle<Code>(info->code()), | 804 Handle<Code>(info->code()), |
| 793 info)); | 805 info)); |
| 794 } | 806 } |
| 795 | 807 |
| 796 } } // namespace v8::internal | 808 } } // namespace v8::internal |
| OLD | NEW |