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

Side by Side Diff: src/parser.cc

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even more rebase Created 6 years, 5 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') | test/cctest/cctest.h » ('j') | 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 // 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/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return Data()[PreparseDataConstants::kVersionOffset]; 247 return Data()[PreparseDataConstants::kVersionOffset];
248 } 248 }
249 249
250 250
251 int ParseData::FunctionsSize() { 251 int ParseData::FunctionsSize() {
252 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); 252 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]);
253 } 253 }
254 254
255 255
256 void Parser::SetCachedData() { 256 void Parser::SetCachedData() {
257 if (cached_data_mode() == NO_CACHED_DATA) { 257 if (compile_options() == ScriptCompiler::kNoCompileOptions) {
258 cached_parse_data_ = NULL; 258 cached_parse_data_ = NULL;
259 } else { 259 } else {
260 ASSERT(info_->cached_data() != NULL); 260 ASSERT(info_->cached_data() != NULL);
261 if (cached_data_mode() == CONSUME_CACHED_DATA) { 261 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
262 cached_parse_data_ = new ParseData(*info_->cached_data()); 262 cached_parse_data_ = new ParseData(*info_->cached_data());
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267 267
268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
269 ASSERT(ast_value_factory_); 269 ASSERT(ast_value_factory_);
270 Scope* result = 270 Scope* result =
271 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone()); 271 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone());
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 Handle<String> source(String::cast(script_->source())); 734 Handle<String> source(String::cast(script_->source()));
735 isolate()->counters()->total_parse_size()->Increment(source->length()); 735 isolate()->counters()->total_parse_size()->Increment(source->length());
736 base::ElapsedTimer timer; 736 base::ElapsedTimer timer;
737 if (FLAG_trace_parse) { 737 if (FLAG_trace_parse) {
738 timer.Start(); 738 timer.Start();
739 } 739 }
740 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); 740 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
741 741
742 // Initialize parser state. 742 // Initialize parser state.
743 CompleteParserRecorder recorder; 743 CompleteParserRecorder recorder;
744 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 744
745 if (compile_options() == ScriptCompiler::kProduceParserCache) {
745 log_ = &recorder; 746 log_ = &recorder;
746 } else if (cached_data_mode() == CONSUME_CACHED_DATA) { 747 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) {
747 cached_parse_data_->Initialize(); 748 cached_parse_data_->Initialize();
748 } 749 }
749 750
750 source = String::Flatten(source); 751 source = String::Flatten(source);
751 FunctionLiteral* result; 752 FunctionLiteral* result;
752 if (source->IsExternalTwoByteString()) { 753 if (source->IsExternalTwoByteString()) {
753 // Notice that the stream is destroyed at the end of the branch block. 754 // Notice that the stream is destroyed at the end of the branch block.
754 // The last line of the blocks can't be moved outside, even though they're 755 // The last line of the blocks can't be moved outside, even though they're
755 // identical calls. 756 // identical calls.
756 ExternalTwoByteStringUtf16CharacterStream stream( 757 ExternalTwoByteStringUtf16CharacterStream stream(
(...skipping 12 matching lines...) Expand all
769 PrintF("[parsing eval"); 770 PrintF("[parsing eval");
770 } else if (info()->script()->name()->IsString()) { 771 } else if (info()->script()->name()->IsString()) {
771 String* name = String::cast(info()->script()->name()); 772 String* name = String::cast(info()->script()->name());
772 SmartArrayPointer<char> name_chars = name->ToCString(); 773 SmartArrayPointer<char> name_chars = name->ToCString();
773 PrintF("[parsing script: %s", name_chars.get()); 774 PrintF("[parsing script: %s", name_chars.get());
774 } else { 775 } else {
775 PrintF("[parsing script"); 776 PrintF("[parsing script");
776 } 777 }
777 PrintF(" - took %0.3f ms]\n", ms); 778 PrintF(" - took %0.3f ms]\n", ms);
778 } 779 }
779 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 780 if (compile_options() == ScriptCompiler::kProduceParserCache) {
780 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); 781 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
781 log_ = NULL; 782 log_ = NULL;
782 } 783 }
783 return result; 784 return result;
784 } 785 }
785 786
786 787
787 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 788 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
788 Handle<String> source) { 789 Handle<String> source) {
789 ASSERT(scope_ == NULL); 790 ASSERT(scope_ == NULL);
(...skipping 2811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3601 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3602 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3602 return function_literal; 3603 return function_literal;
3603 } 3604 }
3604 3605
3605 3606
3606 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, 3607 void Parser::SkipLazyFunctionBody(const AstRawString* function_name,
3607 int* materialized_literal_count, 3608 int* materialized_literal_count,
3608 int* expected_property_count, 3609 int* expected_property_count,
3609 bool* ok) { 3610 bool* ok) {
3610 int function_block_pos = position(); 3611 int function_block_pos = position();
3611 if (cached_data_mode() == CONSUME_CACHED_DATA) { 3612 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
3612 // If we have cached data, we use it to skip parsing the function body. The 3613 // If we have cached data, we use it to skip parsing the function body. The
3613 // data contains the information we need to construct the lazy function. 3614 // data contains the information we need to construct the lazy function.
3614 FunctionEntry entry = 3615 FunctionEntry entry =
3615 cached_parse_data_->GetFunctionEntry(function_block_pos); 3616 cached_parse_data_->GetFunctionEntry(function_block_pos);
3616 // Check that cached data is valid. 3617 // Check that cached data is valid.
3617 CHECK(entry.is_valid()); 3618 CHECK(entry.is_valid());
3618 // End position greater than end of stream is safe, and hard to check. 3619 // End position greater than end of stream is safe, and hard to check.
3619 CHECK(entry.end_pos() > function_block_pos); 3620 CHECK(entry.end_pos() > function_block_pos);
3620 scanner()->SeekForward(entry.end_pos() - 1); 3621 scanner()->SeekForward(entry.end_pos() - 1);
3621 3622
(...skipping 29 matching lines...) Expand all
3651 scope_->set_end_position(logger.end()); 3652 scope_->set_end_position(logger.end());
3652 Expect(Token::RBRACE, ok); 3653 Expect(Token::RBRACE, ok);
3653 if (!*ok) { 3654 if (!*ok) {
3654 return; 3655 return;
3655 } 3656 }
3656 isolate()->counters()->total_preparse_skipped()->Increment( 3657 isolate()->counters()->total_preparse_skipped()->Increment(
3657 scope_->end_position() - function_block_pos); 3658 scope_->end_position() - function_block_pos);
3658 *materialized_literal_count = logger.literals(); 3659 *materialized_literal_count = logger.literals();
3659 *expected_property_count = logger.properties(); 3660 *expected_property_count = logger.properties();
3660 scope_->SetStrictMode(logger.strict_mode()); 3661 scope_->SetStrictMode(logger.strict_mode());
3661 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 3662 if (compile_options() == ScriptCompiler::kProduceParserCache) {
3662 ASSERT(log_); 3663 ASSERT(log_);
3663 // Position right after terminal '}'. 3664 // Position right after terminal '}'.
3664 int body_end = scanner()->location().end_pos; 3665 int body_end = scanner()->location().end_pos;
3665 log_->LogFunction(function_block_pos, body_end, 3666 log_->LogFunction(function_block_pos, body_end,
3666 *materialized_literal_count, 3667 *materialized_literal_count,
3667 *expected_property_count, 3668 *expected_property_count,
3668 scope_->strict_mode()); 3669 scope_->strict_mode());
3669 } 3670 }
3670 } 3671 }
3671 } 3672 }
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4807 info()->SetAstValueFactory(ast_value_factory_); 4808 info()->SetAstValueFactory(ast_value_factory_);
4808 } 4809 }
4809 ast_value_factory_ = NULL; 4810 ast_value_factory_ = NULL;
4810 4811
4811 InternalizeUseCounts(); 4812 InternalizeUseCounts();
4812 4813
4813 return (result != NULL); 4814 return (result != NULL);
4814 } 4815 }
4815 4816
4816 } } // namespace v8::internal 4817 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | test/cctest/cctest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698