Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parser.cc

Issue 17817003: Remove useless ZoneScopes from Parser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 559 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
560 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 560 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
561 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 561 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
562 set_allow_lazy(false); // Must be explicitly enabled. 562 set_allow_lazy(false); // Must be explicitly enabled.
563 set_allow_generators(FLAG_harmony_generators); 563 set_allow_generators(FLAG_harmony_generators);
564 set_allow_for_of(FLAG_harmony_iteration); 564 set_allow_for_of(FLAG_harmony_iteration);
565 } 565 }
566 566
567 567
568 FunctionLiteral* Parser::ParseProgram() { 568 FunctionLiteral* Parser::ParseProgram() {
569 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT);
570 HistogramTimerScope timer(isolate()->counters()->parse()); 569 HistogramTimerScope timer(isolate()->counters()->parse());
571 Handle<String> source(String::cast(script_->source())); 570 Handle<String> source(String::cast(script_->source()));
572 isolate()->counters()->total_parse_size()->Increment(source->length()); 571 isolate()->counters()->total_parse_size()->Increment(source->length());
573 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; 572 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0;
574 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 573 fni_ = new(zone()) FuncNameInferrer(isolate(), zone());
575 574
576 // Initialize parser state. 575 // Initialize parser state.
577 source->TryFlatten(); 576 source->TryFlatten();
578 FunctionLiteral* result; 577 FunctionLiteral* result;
579 if (source->IsExternalTwoByteString()) { 578 if (source->IsExternalTwoByteString()) {
580 // Notice that the stream is destroyed at the end of the branch block. 579 // Notice that the stream is destroyed at the end of the branch block.
581 // The last line of the blocks can't be moved outside, even though they're 580 // The last line of the blocks can't be moved outside, even though they're
582 // identical calls. 581 // identical calls.
583 ExternalTwoByteStringUtf16CharacterStream stream( 582 ExternalTwoByteStringUtf16CharacterStream stream(
584 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); 583 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
585 scanner_.Initialize(&stream); 584 scanner_.Initialize(&stream);
586 result = DoParseProgram(info(), source, &zone_scope); 585 result = DoParseProgram(info(), source);
587 } else { 586 } else {
588 GenericStringUtf16CharacterStream stream(source, 0, source->length()); 587 GenericStringUtf16CharacterStream stream(source, 0, source->length());
589 scanner_.Initialize(&stream); 588 scanner_.Initialize(&stream);
590 result = DoParseProgram(info(), source, &zone_scope); 589 result = DoParseProgram(info(), source);
591 } 590 }
592 591
593 if (FLAG_trace_parse && result != NULL) { 592 if (FLAG_trace_parse && result != NULL) {
594 double ms = static_cast<double>(OS::Ticks() - start) / 1000; 593 double ms = static_cast<double>(OS::Ticks() - start) / 1000;
595 if (info()->is_eval()) { 594 if (info()->is_eval()) {
596 PrintF("[parsing eval"); 595 PrintF("[parsing eval");
597 } else if (info()->script()->name()->IsString()) { 596 } else if (info()->script()->name()->IsString()) {
598 String* name = String::cast(info()->script()->name()); 597 String* name = String::cast(info()->script()->name());
599 SmartArrayPointer<char> name_chars = name->ToCString(); 598 SmartArrayPointer<char> name_chars = name->ToCString();
600 PrintF("[parsing script: %s", *name_chars); 599 PrintF("[parsing script: %s", *name_chars);
601 } else { 600 } else {
602 PrintF("[parsing script"); 601 PrintF("[parsing script");
603 } 602 }
604 PrintF(" - took %0.3f ms]\n", ms); 603 PrintF(" - took %0.3f ms]\n", ms);
605 } 604 }
606 return result; 605 return result;
607 } 606 }
608 607
609 608
610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 609 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
611 Handle<String> source, 610 Handle<String> source) {
612 ZoneScope* zone_scope) {
613 ASSERT(top_scope_ == NULL); 611 ASSERT(top_scope_ == NULL);
614 ASSERT(target_stack_ == NULL); 612 ASSERT(target_stack_ == NULL);
615 if (pre_parse_data_ != NULL) pre_parse_data_->Initialize(); 613 if (pre_parse_data_ != NULL) pre_parse_data_->Initialize();
616 614
617 Handle<String> no_name = isolate()->factory()->empty_string(); 615 Handle<String> no_name = isolate()->factory()->empty_string();
618 616
619 FunctionLiteral* result = NULL; 617 FunctionLiteral* result = NULL;
620 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); 618 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE);
621 info->SetGlobalScope(scope); 619 info->SetGlobalScope(scope);
622 if (!info->context().is_null()) { 620 if (!info->context().is_null()) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 FunctionLiteral::kNotGenerator); 681 FunctionLiteral::kNotGenerator);
684 result->set_ast_properties(factory()->visitor()->ast_properties()); 682 result->set_ast_properties(factory()->visitor()->ast_properties());
685 } else if (stack_overflow_) { 683 } else if (stack_overflow_) {
686 isolate()->StackOverflow(); 684 isolate()->StackOverflow();
687 } 685 }
688 } 686 }
689 687
690 // Make sure the target stack is empty. 688 // Make sure the target stack is empty.
691 ASSERT(target_stack_ == NULL); 689 ASSERT(target_stack_ == NULL);
692 690
693 // If there was a syntax error we have to get rid of the AST
694 // and it is not safe to do so before the scope has been deleted.
695 if (result == NULL) zone_scope->DeleteOnExit();
696 return result; 691 return result;
697 } 692 }
698 693
699 694
700 FunctionLiteral* Parser::ParseLazy() { 695 FunctionLiteral* Parser::ParseLazy() {
701 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT);
702 HistogramTimerScope timer(isolate()->counters()->parse_lazy()); 696 HistogramTimerScope timer(isolate()->counters()->parse_lazy());
703 Handle<String> source(String::cast(script_->source())); 697 Handle<String> source(String::cast(script_->source()));
704 isolate()->counters()->total_parse_size()->Increment(source->length()); 698 isolate()->counters()->total_parse_size()->Increment(source->length());
705 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; 699 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0;
706 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 700 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
707 701
708 // Initialize parser state. 702 // Initialize parser state.
709 source->TryFlatten(); 703 source->TryFlatten();
710 FunctionLiteral* result; 704 FunctionLiteral* result;
711 if (source->IsExternalTwoByteString()) { 705 if (source->IsExternalTwoByteString()) {
712 ExternalTwoByteStringUtf16CharacterStream stream( 706 ExternalTwoByteStringUtf16CharacterStream stream(
713 Handle<ExternalTwoByteString>::cast(source), 707 Handle<ExternalTwoByteString>::cast(source),
714 shared_info->start_position(), 708 shared_info->start_position(),
715 shared_info->end_position()); 709 shared_info->end_position());
716 result = ParseLazy(&stream, &zone_scope); 710 result = ParseLazy(&stream);
717 } else { 711 } else {
718 GenericStringUtf16CharacterStream stream(source, 712 GenericStringUtf16CharacterStream stream(source,
719 shared_info->start_position(), 713 shared_info->start_position(),
720 shared_info->end_position()); 714 shared_info->end_position());
721 result = ParseLazy(&stream, &zone_scope); 715 result = ParseLazy(&stream);
722 } 716 }
723 717
724 if (FLAG_trace_parse && result != NULL) { 718 if (FLAG_trace_parse && result != NULL) {
725 double ms = static_cast<double>(OS::Ticks() - start) / 1000; 719 double ms = static_cast<double>(OS::Ticks() - start) / 1000;
726 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); 720 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString();
727 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); 721 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms);
728 } 722 }
729 return result; 723 return result;
730 } 724 }
731 725
732 726
733 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source, 727 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
734 ZoneScope* zone_scope) {
735 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 728 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
736 scanner_.Initialize(source); 729 scanner_.Initialize(source);
737 ASSERT(top_scope_ == NULL); 730 ASSERT(top_scope_ == NULL);
738 ASSERT(target_stack_ == NULL); 731 ASSERT(target_stack_ == NULL);
739 732
740 Handle<String> name(String::cast(shared_info->name())); 733 Handle<String> name(String::cast(shared_info->name()));
741 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 734 fni_ = new(zone()) FuncNameInferrer(isolate(), zone());
742 fni_->PushEnclosingName(name); 735 fni_->PushEnclosingName(name);
743 736
744 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 737 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
(...skipping 27 matching lines...) Expand all
772 RelocInfo::kNoPosition, 765 RelocInfo::kNoPosition,
773 function_type, 766 function_type,
774 &ok); 767 &ok);
775 // Make sure the results agree. 768 // Make sure the results agree.
776 ASSERT(ok == (result != NULL)); 769 ASSERT(ok == (result != NULL));
777 } 770 }
778 771
779 // Make sure the target stack is empty. 772 // Make sure the target stack is empty.
780 ASSERT(target_stack_ == NULL); 773 ASSERT(target_stack_ == NULL);
781 774
782 // If there was a stack overflow we have to get rid of AST and it is
783 // not safe to do before scope has been deleted.
784 if (result == NULL) { 775 if (result == NULL) {
785 zone_scope->DeleteOnExit();
786 if (stack_overflow_) isolate()->StackOverflow(); 776 if (stack_overflow_) isolate()->StackOverflow();
787 } else { 777 } else {
788 Handle<String> inferred_name(shared_info->inferred_name()); 778 Handle<String> inferred_name(shared_info->inferred_name());
789 result->set_inferred_name(inferred_name); 779 result->set_inferred_name(inferred_name);
790 } 780 }
791 return result; 781 return result;
792 } 782 }
793 783
794 784
795 Handle<String> Parser::GetSymbol() { 785 Handle<String> Parser::GetSymbol() {
(...skipping 5129 matching lines...) Expand 10 before | Expand all | Expand 10 after
5925 ASSERT(info()->isolate()->has_pending_exception()); 5915 ASSERT(info()->isolate()->has_pending_exception());
5926 } else { 5916 } else {
5927 result = ParseProgram(); 5917 result = ParseProgram();
5928 } 5918 }
5929 } 5919 }
5930 info()->SetFunction(result); 5920 info()->SetFunction(result);
5931 return (result != NULL); 5921 return (result != NULL);
5932 } 5922 }
5933 5923
5934 } } // namespace v8::internal 5924 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698