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

Side by Side Diff: src/parser.cc

Issue 8677008: Relax inlining limits for simple leaf functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Save/restore node count in FunctionState, add comments. Created 9 years 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
« src/hydrogen.cc ('K') | « src/objects-inl.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 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 bool only_simple_this_property_assignments() { 506 bool only_simple_this_property_assignments() {
507 return only_simple_this_property_assignments_; 507 return only_simple_this_property_assignments_;
508 } 508 }
509 Handle<FixedArray> this_property_assignments() { 509 Handle<FixedArray> this_property_assignments() {
510 return this_property_assignments_; 510 return this_property_assignments_;
511 } 511 }
512 512
513 void AddProperty() { expected_property_count_++; } 513 void AddProperty() { expected_property_count_++; }
514 int expected_property_count() { return expected_property_count_; } 514 int expected_property_count() { return expected_property_count_; }
515 515
516 int ast_node_count() {
517 return parser_->isolate()->ast_node_count();
518 }
519
520 bool is_function_primitive() {
521 return parser_->isolate()->is_function_primitive();
522 }
523
516 private: 524 private:
517 // Used to assign an index to each literal that needs materialization in 525 // Used to assign an index to each literal that needs materialization in
518 // the function. Includes regexp literals, and boilerplate for object and 526 // the function. Includes regexp literals, and boilerplate for object and
519 // array literals. 527 // array literals.
520 int next_materialized_literal_index_; 528 int next_materialized_literal_index_;
521 529
522 // Used to assign a per-function index to try and catch handlers. 530 // Used to assign a per-function index to try and catch handlers.
523 int next_handler_index_; 531 int next_handler_index_;
524 532
525 // Properties count estimation. 533 // Properties count estimation.
526 int expected_property_count_; 534 int expected_property_count_;
527 535
528 // Keeps track of assignments to properties of this. Used for 536 // Keeps track of assignments to properties of this. Used for
529 // optimizing constructors. 537 // optimizing constructors.
530 bool only_simple_this_property_assignments_; 538 bool only_simple_this_property_assignments_;
531 Handle<FixedArray> this_property_assignments_; 539 Handle<FixedArray> this_property_assignments_;
532 540
533 Parser* parser_; 541 Parser* parser_;
534 FunctionState* outer_function_state_; 542 FunctionState* outer_function_state_;
535 Scope* outer_scope_; 543 Scope* outer_scope_;
536 unsigned saved_ast_node_id_; 544 unsigned saved_ast_node_id_;
545 int saved_ast_node_count_;
546 bool saved_is_function_primitive_;
537 }; 547 };
538 548
539 549
540 Parser::FunctionState::FunctionState(Parser* parser, 550 Parser::FunctionState::FunctionState(Parser* parser,
541 Scope* scope, 551 Scope* scope,
542 Isolate* isolate) 552 Isolate* isolate)
543 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 553 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
544 next_handler_index_(0), 554 next_handler_index_(0),
545 expected_property_count_(0), 555 expected_property_count_(0),
546 only_simple_this_property_assignments_(false), 556 only_simple_this_property_assignments_(false),
547 this_property_assignments_(isolate->factory()->empty_fixed_array()), 557 this_property_assignments_(isolate->factory()->empty_fixed_array()),
548 parser_(parser), 558 parser_(parser),
549 outer_function_state_(parser->current_function_state_), 559 outer_function_state_(parser->current_function_state_),
550 outer_scope_(parser->top_scope_), 560 outer_scope_(parser->top_scope_),
551 saved_ast_node_id_(isolate->ast_node_id()) { 561 saved_ast_node_id_(isolate->ast_node_id()),
562 saved_ast_node_count_(isolate->ast_node_count()),
563 saved_is_function_primitive_(isolate->is_function_primitive()) {
552 parser->top_scope_ = scope; 564 parser->top_scope_ = scope;
553 parser->current_function_state_ = this; 565 parser->current_function_state_ = this;
554 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1); 566 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1);
567 isolate->set_ast_node_count(0);
568 isolate->set_is_function_primitive(true);
555 } 569 }
556 570
557 571
558 Parser::FunctionState::~FunctionState() { 572 Parser::FunctionState::~FunctionState() {
559 parser_->top_scope_ = outer_scope_; 573 parser_->top_scope_ = outer_scope_;
560 parser_->current_function_state_ = outer_function_state_; 574 parser_->current_function_state_ = outer_function_state_;
561 parser_->isolate()->set_ast_node_id(saved_ast_node_id_); 575 parser_->isolate()->set_ast_node_id(saved_ast_node_id_);
576 parser_->isolate()->set_ast_node_count(saved_ast_node_count_);
577 parser_->isolate()->set_is_function_primitive(saved_is_function_primitive_);
562 } 578 }
563 579
564 580
565 // ---------------------------------------------------------------------------- 581 // ----------------------------------------------------------------------------
566 // The CHECK_OK macro is a convenient macro to enforce error 582 // The CHECK_OK macro is a convenient macro to enforce error
567 // handling for functions that may fail (by returning !*ok). 583 // handling for functions that may fail (by returning !*ok).
568 // 584 //
569 // CAUTION: This macro appends extra statements after a call, 585 // CAUTION: This macro appends extra statements after a call,
570 // thus it must never be used where only a single statement 586 // thus it must never be used where only a single statement
571 // is correct (e.g. an if statement branch w/o braces)! 587 // is correct (e.g. an if statement branch w/o braces)!
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 no_name, 691 no_name,
676 top_scope_, 692 top_scope_,
677 body, 693 body,
678 function_state.materialized_literal_count(), 694 function_state.materialized_literal_count(),
679 function_state.expected_property_count(), 695 function_state.expected_property_count(),
680 function_state.handler_count(), 696 function_state.handler_count(),
681 function_state.only_simple_this_property_assignments(), 697 function_state.only_simple_this_property_assignments(),
682 function_state.this_property_assignments(), 698 function_state.this_property_assignments(),
683 0, 699 0,
684 FunctionLiteral::ANONYMOUS_EXPRESSION, 700 FunctionLiteral::ANONYMOUS_EXPRESSION,
685 false); // Does not have duplicate parameters. 701 false, // Does not have duplicate parameters.
702 function_state.ast_node_count(),
703 function_state.is_function_primitive());
686 } else if (stack_overflow_) { 704 } else if (stack_overflow_) {
687 isolate()->StackOverflow(); 705 isolate()->StackOverflow();
688 } 706 }
689 } 707 }
690 708
691 // Make sure the target stack is empty. 709 // Make sure the target stack is empty.
692 ASSERT(target_stack_ == NULL); 710 ASSERT(target_stack_ == NULL);
693 711
694 // If there was a syntax error we have to get rid of the AST 712 // If there was a syntax error we have to get rid of the AST
695 // and it is not safe to do so before the scope has been deleted. 713 // and it is not safe to do so before the scope has been deleted.
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 Expect(Token::RPAREN, CHECK_OK); 2194 Expect(Token::RPAREN, CHECK_OK);
2177 2195
2178 top_scope_->DeclarationScope()->RecordWithStatement(); 2196 top_scope_->DeclarationScope()->RecordWithStatement();
2179 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); 2197 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE);
2180 Statement* stmt; 2198 Statement* stmt;
2181 { BlockState block_state(this, with_scope); 2199 { BlockState block_state(this, with_scope);
2182 with_scope->set_start_position(scanner().peek_location().beg_pos); 2200 with_scope->set_start_position(scanner().peek_location().beg_pos);
2183 stmt = ParseStatement(labels, CHECK_OK); 2201 stmt = ParseStatement(labels, CHECK_OK);
2184 with_scope->set_end_position(scanner().location().end_pos); 2202 with_scope->set_end_position(scanner().location().end_pos);
2185 } 2203 }
2186 return new(zone()) WithStatement(expr, stmt); 2204 return new(zone()) WithStatement(isolate(), expr, stmt);
2187 } 2205 }
2188 2206
2189 2207
2190 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { 2208 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
2191 // CaseClause :: 2209 // CaseClause ::
2192 // 'case' Expression ':' Statement* 2210 // 'case' Expression ':' Statement*
2193 // 'default' ':' Statement* 2211 // 'default' ':' Statement*
2194 2212
2195 Expression* label = NULL; // NULL expression indicates default case 2213 Expression* label = NULL; // NULL expression indicates default case
2196 if (peek() == Token::CASE) { 2214 if (peek() == Token::CASE) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 2360
2343 // Simplify the AST nodes by converting: 2361 // Simplify the AST nodes by converting:
2344 // 'try B0 catch B1 finally B2' 2362 // 'try B0 catch B1 finally B2'
2345 // to: 2363 // to:
2346 // 'try { try B0 catch B1 } finally B2' 2364 // 'try { try B0 catch B1 } finally B2'
2347 2365
2348 if (catch_block != NULL && finally_block != NULL) { 2366 if (catch_block != NULL && finally_block != NULL) {
2349 // If we have both, create an inner try/catch. 2367 // If we have both, create an inner try/catch.
2350 ASSERT(catch_scope != NULL && catch_variable != NULL); 2368 ASSERT(catch_scope != NULL && catch_variable != NULL);
2351 int index = current_function_state_->NextHandlerIndex(); 2369 int index = current_function_state_->NextHandlerIndex();
2352 TryCatchStatement* statement = new(zone()) TryCatchStatement(index, 2370 TryCatchStatement* statement = new(zone()) TryCatchStatement(isolate(),
2371 index,
2353 try_block, 2372 try_block,
2354 catch_scope, 2373 catch_scope,
2355 catch_variable, 2374 catch_variable,
2356 catch_block); 2375 catch_block);
2357 statement->set_escaping_targets(try_collector.targets()); 2376 statement->set_escaping_targets(try_collector.targets());
2358 try_block = new(zone()) Block(isolate(), NULL, 1, false); 2377 try_block = new(zone()) Block(isolate(), NULL, 1, false);
2359 try_block->AddStatement(statement); 2378 try_block->AddStatement(statement);
2360 catch_block = NULL; // Clear to indicate it's been handled. 2379 catch_block = NULL; // Clear to indicate it's been handled.
2361 } 2380 }
2362 2381
2363 TryStatement* result = NULL; 2382 TryStatement* result = NULL;
2364 if (catch_block != NULL) { 2383 if (catch_block != NULL) {
2365 ASSERT(finally_block == NULL); 2384 ASSERT(finally_block == NULL);
2366 ASSERT(catch_scope != NULL && catch_variable != NULL); 2385 ASSERT(catch_scope != NULL && catch_variable != NULL);
2367 int index = current_function_state_->NextHandlerIndex(); 2386 int index = current_function_state_->NextHandlerIndex();
2368 result = new(zone()) TryCatchStatement(index, 2387 result = new(zone()) TryCatchStatement(isolate(),
2388 index,
2369 try_block, 2389 try_block,
2370 catch_scope, 2390 catch_scope,
2371 catch_variable, 2391 catch_variable,
2372 catch_block); 2392 catch_block);
2373 } else { 2393 } else {
2374 ASSERT(finally_block != NULL); 2394 ASSERT(finally_block != NULL);
2375 int index = current_function_state_->NextHandlerIndex(); 2395 int index = current_function_state_->NextHandlerIndex();
2376 result = new(zone()) TryFinallyStatement(index, 2396 result = new(zone()) TryFinallyStatement(isolate(),
2397 index,
2377 try_block, 2398 try_block,
2378 finally_block); 2399 finally_block);
2379 // Combine the jump targets of the try block and the possible catch block. 2400 // Combine the jump targets of the try block and the possible catch block.
2380 try_collector.targets()->AddAll(*catch_collector.targets()); 2401 try_collector.targets()->AddAll(*catch_collector.targets());
2381 } 2402 }
2382 2403
2383 result->set_escaping_targets(try_collector.targets()); 2404 result->set_escaping_targets(try_collector.targets());
2384 return result; 2405 return result;
2385 } 2406 }
2386 2407
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
3934 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) 3955 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_)
3935 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) 3956 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE)
3936 : NewScope(top_scope_, FUNCTION_SCOPE); 3957 : NewScope(top_scope_, FUNCTION_SCOPE);
3937 ZoneList<Statement*>* body = NULL; 3958 ZoneList<Statement*>* body = NULL;
3938 int materialized_literal_count; 3959 int materialized_literal_count;
3939 int expected_property_count; 3960 int expected_property_count;
3940 int handler_count = 0; 3961 int handler_count = 0;
3941 bool only_simple_this_property_assignments; 3962 bool only_simple_this_property_assignments;
3942 Handle<FixedArray> this_property_assignments; 3963 Handle<FixedArray> this_property_assignments;
3943 bool has_duplicate_parameters = false; 3964 bool has_duplicate_parameters = false;
3965 int ast_node_count;
3966 bool is_function_primitive;
3944 // Parse function body. 3967 // Parse function body.
3945 { FunctionState function_state(this, scope, isolate()); 3968 { FunctionState function_state(this, scope, isolate());
3946 top_scope_->SetScopeName(function_name); 3969 top_scope_->SetScopeName(function_name);
3947 3970
3948 // FormalParameterList :: 3971 // FormalParameterList ::
3949 // '(' (Identifier)*[','] ')' 3972 // '(' (Identifier)*[','] ')'
3950 Expect(Token::LPAREN, CHECK_OK); 3973 Expect(Token::LPAREN, CHECK_OK);
3951 scope->set_start_position(scanner().location().beg_pos); 3974 scope->set_start_position(scanner().location().beg_pos);
3952 Scanner::Location name_loc = Scanner::Location::invalid(); 3975 Scanner::Location name_loc = Scanner::Location::invalid();
3953 Scanner::Location dupe_loc = Scanner::Location::invalid(); 3976 Scanner::Location dupe_loc = Scanner::Location::invalid();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
4031 } 4054 }
4032 isolate()->counters()->total_preparse_skipped()->Increment( 4055 isolate()->counters()->total_preparse_skipped()->Increment(
4033 scope->end_position() - function_block_pos); 4056 scope->end_position() - function_block_pos);
4034 // Seek to position just before terminal '}'. 4057 // Seek to position just before terminal '}'.
4035 scanner().SeekForward(scope->end_position() - 1); 4058 scanner().SeekForward(scope->end_position() - 1);
4036 materialized_literal_count = entry.literal_count(); 4059 materialized_literal_count = entry.literal_count();
4037 expected_property_count = entry.property_count(); 4060 expected_property_count = entry.property_count();
4038 top_scope_->SetStrictModeFlag(entry.strict_mode_flag()); 4061 top_scope_->SetStrictModeFlag(entry.strict_mode_flag());
4039 only_simple_this_property_assignments = false; 4062 only_simple_this_property_assignments = false;
4040 this_property_assignments = isolate()->factory()->empty_fixed_array(); 4063 this_property_assignments = isolate()->factory()->empty_fixed_array();
4064 // Give up computing the node count and the "primitive" flag when
4065 // parsing lazily.
4066 ast_node_count = 0;
4067 is_function_primitive = false;
4041 Expect(Token::RBRACE, CHECK_OK); 4068 Expect(Token::RBRACE, CHECK_OK);
4042 } 4069 }
4043 } 4070 }
4044 4071
4045 if (!is_lazily_compiled) { 4072 if (!is_lazily_compiled) {
4046 body = new(zone()) ZoneList<Statement*>(8); 4073 body = new(zone()) ZoneList<Statement*>(8);
4047 if (fvar != NULL) { 4074 if (fvar != NULL) {
4048 VariableProxy* fproxy = top_scope_->NewUnresolved(function_name); 4075 VariableProxy* fproxy = top_scope_->NewUnresolved(function_name);
4049 fproxy->BindTo(fvar); 4076 fproxy->BindTo(fvar);
4050 body->Add(new(zone()) ExpressionStatement( 4077 body->Add(new(zone()) ExpressionStatement(
4051 new(zone()) Assignment(isolate(), 4078 new(zone()) Assignment(isolate(),
4052 fvar_init_op, 4079 fvar_init_op,
4053 fproxy, 4080 fproxy,
4054 new(zone()) ThisFunction(isolate()), 4081 new(zone()) ThisFunction(isolate()),
4055 RelocInfo::kNoPosition))); 4082 RelocInfo::kNoPosition)));
4056 } 4083 }
4057 ParseSourceElements(body, Token::RBRACE, CHECK_OK); 4084 ParseSourceElements(body, Token::RBRACE, CHECK_OK);
4058 4085
4059 materialized_literal_count = function_state.materialized_literal_count(); 4086 materialized_literal_count = function_state.materialized_literal_count();
4060 expected_property_count = function_state.expected_property_count(); 4087 expected_property_count = function_state.expected_property_count();
4061 handler_count = function_state.handler_count(); 4088 handler_count = function_state.handler_count();
4062 only_simple_this_property_assignments = 4089 only_simple_this_property_assignments =
4063 function_state.only_simple_this_property_assignments(); 4090 function_state.only_simple_this_property_assignments();
4064 this_property_assignments = function_state.this_property_assignments(); 4091 this_property_assignments = function_state.this_property_assignments();
4065 4092 ast_node_count = function_state.ast_node_count();
4093 is_function_primitive = function_state.is_function_primitive();
4066 Expect(Token::RBRACE, CHECK_OK); 4094 Expect(Token::RBRACE, CHECK_OK);
4067 scope->set_end_position(scanner().location().end_pos); 4095 scope->set_end_position(scanner().location().end_pos);
4068 } 4096 }
4069 4097
4070 // Validate strict mode. 4098 // Validate strict mode.
4071 if (top_scope_->is_strict_mode()) { 4099 if (top_scope_->is_strict_mode()) {
4072 if (IsEvalOrArguments(function_name)) { 4100 if (IsEvalOrArguments(function_name)) {
4073 int start_pos = scope->start_position(); 4101 int start_pos = scope->start_position();
4074 int position = function_token_position != RelocInfo::kNoPosition 4102 int position = function_token_position != RelocInfo::kNoPosition
4075 ? function_token_position 4103 ? function_token_position
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4124 function_name, 4152 function_name,
4125 scope, 4153 scope,
4126 body, 4154 body,
4127 materialized_literal_count, 4155 materialized_literal_count,
4128 expected_property_count, 4156 expected_property_count,
4129 handler_count, 4157 handler_count,
4130 only_simple_this_property_assignments, 4158 only_simple_this_property_assignments,
4131 this_property_assignments, 4159 this_property_assignments,
4132 num_parameters, 4160 num_parameters,
4133 type, 4161 type,
4134 has_duplicate_parameters); 4162 has_duplicate_parameters,
4163 ast_node_count,
4164 is_function_primitive);
4135 function_literal->set_function_token_position(function_token_position); 4165 function_literal->set_function_token_position(function_token_position);
4136 4166
4137 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4167 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
4138 return function_literal; 4168 return function_literal;
4139 } 4169 }
4140 4170
4141 4171
4142 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4172 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4143 // CallRuntime :: 4173 // CallRuntime ::
4144 // '%' Identifier Arguments 4174 // '%' Identifier Arguments
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after
5459 ASSERT(info->isolate()->has_pending_exception()); 5489 ASSERT(info->isolate()->has_pending_exception());
5460 } else { 5490 } else {
5461 result = parser.ParseProgram(info); 5491 result = parser.ParseProgram(info);
5462 } 5492 }
5463 } 5493 }
5464 info->SetFunction(result); 5494 info->SetFunction(result);
5465 return (result != NULL); 5495 return (result != NULL);
5466 } 5496 }
5467 5497
5468 } } // namespace v8::internal 5498 } } // namespace v8::internal
OLDNEW
« src/hydrogen.cc ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698