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 int scope_position) { | 539 int scope_position) { |
538 Isolate* isolate = source->GetIsolate(); | 540 Isolate* isolate = source->GetIsolate(); |
539 int source_length = source->length(); | 541 int source_length = source->length(); |
540 isolate->counters()->total_eval_size()->Increment(source_length); | 542 isolate->counters()->total_eval_size()->Increment(source_length); |
541 isolate->counters()->total_compile_size()->Increment(source_length); | 543 isolate->counters()->total_compile_size()->Increment(source_length); |
542 | 544 |
543 // The VM is in the COMPILER state until exiting this function. | 545 // The VM is in the COMPILER state until exiting this function. |
544 VMState state(isolate, COMPILER); | 546 VMState state(isolate, COMPILER); |
545 | 547 |
546 // Do a lookup in the compilation cache; if the entry is not there, invoke | 548 // Do a lookup in the compilation cache; if the entry is not there, invoke |
547 // the compiler and add the result to the cache. | 549 // the compiler and add the result to the cache. |
548 Handle<SharedFunctionInfo> result; | 550 Handle<SharedFunctionInfo> result; |
549 CompilationCache* compilation_cache = isolate->compilation_cache(); | 551 CompilationCache* compilation_cache = isolate->compilation_cache(); |
550 result = compilation_cache->LookupEval(source, | 552 result = compilation_cache->LookupEval(source, |
551 context, | 553 context, |
552 is_global, | 554 is_global, |
553 strict_mode, | 555 language_mode, |
554 scope_position); | 556 scope_position); |
555 | 557 |
556 if (result.is_null()) { | 558 if (result.is_null()) { |
557 // Create a script object describing the script to be compiled. | 559 // Create a script object describing the script to be compiled. |
558 Handle<Script> script = isolate->factory()->NewScript(source); | 560 Handle<Script> script = isolate->factory()->NewScript(source); |
559 CompilationInfo info(script); | 561 CompilationInfo info(script); |
560 info.MarkAsEval(); | 562 info.MarkAsEval(); |
561 if (is_global) info.MarkAsGlobal(); | 563 if (is_global) info.MarkAsGlobal(); |
562 info.SetStrictModeFlag(strict_mode); | 564 info.SetLanguageMode(language_mode); |
563 info.SetCallingContext(context); | 565 info.SetCallingContext(context); |
564 result = MakeFunctionInfo(&info); | 566 result = MakeFunctionInfo(&info); |
565 if (!result.is_null()) { | 567 if (!result.is_null()) { |
566 // If caller is strict mode, the result must be strict as well, | 568 // If caller is strict mode, the result must be in strict mode or |
567 // but not the other way around. Consider: | 569 // extended mode as well, but not the other way around. Consider: |
568 // eval("'use strict'; ..."); | 570 // eval("'use strict'; ..."); |
569 // TODO(keuchel): adapt this for extended mode. | 571 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); |
570 ASSERT(strict_mode == kNonStrictMode || result->strict_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()); | |
571 compilation_cache->PutEval( | 576 compilation_cache->PutEval( |
572 source, context, is_global, result, scope_position); | 577 source, context, is_global, result, scope_position); |
573 } | 578 } |
574 } | 579 } |
575 | 580 |
576 return result; | 581 return result; |
577 } | 582 } |
578 | 583 |
579 | 584 |
580 bool Compiler::CompileLazy(CompilationInfo* info) { | 585 bool Compiler::CompileLazy(CompilationInfo* info) { |
(...skipping 10 matching lines...) Expand all Loading... | |
591 int compiled_size = shared->end_position() - shared->start_position(); | 596 int compiled_size = shared->end_position() - shared->start_position(); |
592 isolate->counters()->total_compile_size()->Increment(compiled_size); | 597 isolate->counters()->total_compile_size()->Increment(compiled_size); |
593 | 598 |
594 // Generate the AST for the lazily compiled function. | 599 // Generate the AST for the lazily compiled function. |
595 if (ParserApi::Parse(info)) { | 600 if (ParserApi::Parse(info)) { |
596 // Measure how long it takes to do the lazy compilation; only take the | 601 // Measure how long it takes to do the lazy compilation; only take the |
597 // rest of the function into account to avoid overlap with the lazy | 602 // rest of the function into account to avoid overlap with the lazy |
598 // parsing statistics. | 603 // parsing statistics. |
599 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 604 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
600 | 605 |
601 // After parsing we know function's strict mode. Remember it. | 606 // After parsing we know function's language mode. Remember it. |
Rico
2011/11/14 14:58:52
we know the functions's ...
^
Steven
2011/11/15 13:33:30
Done.
| |
602 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); | 607 LanguageMode language_mode = info->function()->language_mode(); |
603 ASSERT(info->strict_mode_flag() == kNonStrictMode || | 608 info->SetLanguageMode(language_mode); |
604 info->strict_mode_flag() == strict_mode); | 609 shared->set_language_mode(language_mode); |
605 ASSERT(shared->strict_mode_flag() == kNonStrictMode || | |
606 shared->strict_mode_flag() == strict_mode); | |
607 info->SetStrictModeFlag(strict_mode); | |
608 shared->set_strict_mode_flag(strict_mode); | |
609 | 610 |
610 // Compile the code. | 611 // Compile the code. |
611 if (!MakeCode(info)) { | 612 if (!MakeCode(info)) { |
612 if (!isolate->has_pending_exception()) { | 613 if (!isolate->has_pending_exception()) { |
613 isolate->StackOverflow(); | 614 isolate->StackOverflow(); |
614 } | 615 } |
615 } else { | 616 } else { |
616 ASSERT(!info->code().is_null()); | 617 ASSERT(!info->code().is_null()); |
617 Handle<Code> code = info->code(); | 618 Handle<Code> code = info->code(); |
618 // Set optimizable to false if this is disallowed by the shared | 619 // Set optimizable to false if this is disallowed by the shared |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 return false; | 678 return false; |
678 } | 679 } |
679 | 680 |
680 | 681 |
681 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 682 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
682 Handle<Script> script) { | 683 Handle<Script> script) { |
683 // Precondition: code has been parsed and scopes have been analyzed. | 684 // Precondition: code has been parsed and scopes have been analyzed. |
684 CompilationInfo info(script); | 685 CompilationInfo info(script); |
685 info.SetFunction(literal); | 686 info.SetFunction(literal); |
686 info.SetScope(literal->scope()); | 687 info.SetScope(literal->scope()); |
687 info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); | 688 info.SetLanguageMode(literal->scope()->language_mode()); |
688 | 689 |
689 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 690 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
690 // Determine if the function can be lazily compiled. This is necessary to | 691 // Determine if the function can be lazily compiled. This is necessary to |
691 // allow some of our builtin JS files to be lazily compiled. These | 692 // allow some of our builtin JS files to be lazily compiled. These |
692 // builtins cannot be handled lazily by the parser, since we have to know | 693 // builtins cannot be handled lazily by the parser, since we have to know |
693 // if a function uses the special natives syntax, which is something the | 694 // if a function uses the special natives syntax, which is something the |
694 // parser records. | 695 // parser records. |
695 bool allow_lazy = literal->AllowsLazyCompilation() && | 696 bool allow_lazy = literal->AllowsLazyCompilation() && |
696 !LiveEditFunctionTracker::IsActive(info.isolate()); | 697 !LiveEditFunctionTracker::IsActive(info.isolate()); |
697 | 698 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 function_info->set_start_position(lit->start_position()); | 744 function_info->set_start_position(lit->start_position()); |
744 function_info->set_end_position(lit->end_position()); | 745 function_info->set_end_position(lit->end_position()); |
745 function_info->set_is_expression(lit->is_expression()); | 746 function_info->set_is_expression(lit->is_expression()); |
746 function_info->set_is_anonymous(lit->is_anonymous()); | 747 function_info->set_is_anonymous(lit->is_anonymous()); |
747 function_info->set_is_toplevel(is_toplevel); | 748 function_info->set_is_toplevel(is_toplevel); |
748 function_info->set_inferred_name(*lit->inferred_name()); | 749 function_info->set_inferred_name(*lit->inferred_name()); |
749 function_info->SetThisPropertyAssignmentsInfo( | 750 function_info->SetThisPropertyAssignmentsInfo( |
750 lit->has_only_simple_this_property_assignments(), | 751 lit->has_only_simple_this_property_assignments(), |
751 *lit->this_property_assignments()); | 752 *lit->this_property_assignments()); |
752 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 753 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
753 function_info->set_strict_mode_flag(lit->strict_mode_flag()); | 754 function_info->set_language_mode(lit->language_mode()); |
754 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 755 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
755 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 756 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
756 } | 757 } |
757 | 758 |
758 | 759 |
759 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 760 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
760 CompilationInfo* info, | 761 CompilationInfo* info, |
761 Handle<SharedFunctionInfo> shared) { | 762 Handle<SharedFunctionInfo> shared) { |
762 // SharedFunctionInfo is passed separately, because if CompilationInfo | 763 // SharedFunctionInfo is passed separately, because if CompilationInfo |
763 // was created using Script object, it will not have it. | 764 // was created using Script object, it will not have it. |
(...skipping 25 matching lines...) Expand all Loading... | |
789 } | 790 } |
790 } | 791 } |
791 | 792 |
792 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 793 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
793 Handle<Script>(info->script()), | 794 Handle<Script>(info->script()), |
794 Handle<Code>(info->code()), | 795 Handle<Code>(info->code()), |
795 info)); | 796 info)); |
796 } | 797 } |
797 | 798 |
798 } } // namespace v8::internal | 799 } } // namespace v8::internal |
OLD | NEW |