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

Unified Diff: src/parser.cc

Issue 1304923004: When parsing inner functions, try to allocate in a temporary Zone (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 07f842a119b06e9c83fb3ad647e990a1d1cedb0c..188500d66a0b8b7ad3e0bb86bd3dfa423fc26f8d 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4206,10 +4206,40 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
}
}
if (!is_lazily_parsed) {
+ // Determine whether the function body can be discarded after parsing.
+ // The preconditions are:
+ // - Lazy compilation has to be enabled.
+ // - Neither V8 natives nor native function declarations can be allowed,
+ // since parsing one would retroactively force the function to be
+ // eagerly compiled.
+ // - The invoker of this parser can't depend on the AST being eagerly
+ // built (either because the function is about to be compiled, or
+ // because the AST is going to be inspected for some reason).
+ // - Because of the above, we can't be attempting to parse a
+ // FunctionExpression; even without enclosing parentheses it might be
+ // immediately invoked.
+ // - The function literal shouldn't be hinted to eagerly compile.
+ bool can_use_temp_zone =
+ FLAG_lazy && !allow_natives() && extension_ == NULL && allow_lazy() &&
+ function_type == FunctionLiteral::DECLARATION &&
+ eager_compile_hint != FunctionLiteral::kShouldEagerCompile;
+ Zone* outer_zone = factory()->zone();
+ Zone temp_zone;
+ if (can_use_temp_zone) {
+ // For the purpose of scope analysis, some HeapObjects allocated by the
+ // factory must persist after the function body is thrown away and
+ // temp_zone is deallocated. These objects are instead allocated in a
+ // parser-persistent zone (see parser_zone_ in AstNodeFactory).
+ factory()->set_zone(&temp_zone);
+ }
body = ParseEagerFunctionBody(function_name, pos, formals, kind,
function_type, CHECK_OK);
materialized_literal_count = function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
+ if (can_use_temp_zone) {
+ body = NULL;
+ factory()->set_zone(outer_zone);
Michael Starzinger 2015/09/10 12:16:54 Suggestion as discsussed offline: This explicit re
conradw 2015/09/10 13:12:40 Sounds good! Done.
+ }
}
// Parsing the body may change the language mode in our scope.
« no previous file with comments | « src/ast.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698