Commit 09a854c7 authored by marja's avatar marja Committed by Commit bot

Put FunctionLiterals into temp_zone too.

This reduces memory usage when parsing (because temp_zones are discarded
every now and then) and work done by FuncNameInferrer.

BUG=

Review-Url: https://codereview.chromium.org/2156013002
Cr-Commit-Position: refs/heads/master@{#37863}
parent 1eadc764
......@@ -3407,8 +3407,8 @@ class AstNodeFactory final BASE_EMBEDDED {
FunctionLiteral::FunctionType function_type,
FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
int position) {
return new (parser_zone_) FunctionLiteral(
parser_zone_, name, ast_value_factory_, scope, body,
return new (local_zone_) FunctionLiteral(
local_zone_, name, ast_value_factory_, scope, body,
materialized_literal_count, expected_property_count, parameter_count,
function_type, has_duplicate_parameters, eager_compile_hint, kind,
position, true);
......
......@@ -166,6 +166,27 @@ int ParseData::FunctionsSize() {
return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]);
}
// Helper for putting parts of the parse results into a temporary zone when
// parsing inner function bodies.
class DiscardableZoneScope {
public:
DiscardableZoneScope(Parser* parser, Zone* temp_zone, bool use_temp_zone)
: ast_node_factory_scope_(parser->factory(), temp_zone, use_temp_zone),
fni_(parser->ast_value_factory_, temp_zone),
parser_(parser),
prev_fni_(parser->fni_) {
if (use_temp_zone) {
parser_->fni_ = &fni_;
}
}
~DiscardableZoneScope() { parser_->fni_ = prev_fni_; }
private:
AstNodeFactory::BodyScope ast_node_factory_scope_;
FuncNameInferrer fni_;
Parser* parser_;
FuncNameInferrer* prev_fni_;
};
void Parser::SetCachedData(ParseInfo* info) {
if (compile_options_ == ScriptCompiler::kNoCompileOptions) {
......@@ -4421,7 +4442,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_type == FunctionLiteral::kDeclaration &&
eager_compile_hint != FunctionLiteral::kShouldEagerCompile &&
!(FLAG_validate_asm && scope->asm_function());
// Open a new BodyScope, which sets our AstNodeFactory to allocate in the
// Open a new zone scope, which sets our AstNodeFactory to allocate in the
// new temporary zone if the preconditions are satisfied, and ensures that
// the previous zone is always restored after parsing the body.
// For the purpose of scope analysis, some ZoneObjects allocated by the
......@@ -4430,8 +4451,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// parser-persistent zone (see parser_zone_ in AstNodeFactory).
{
Zone temp_zone(zone()->allocator());
AstNodeFactory::BodyScope inner(factory(), &temp_zone, use_temp_zone);
DiscardableZoneScope(this, &temp_zone, use_temp_zone);
body = ParseEagerFunctionBody(function_name, pos, formals, kind,
function_type, CHECK_OK);
}
......
......@@ -720,6 +720,7 @@ class Parser : public ParserBase<ParserTraits> {
private:
friend class ParserTraits;
friend class DiscardableZoneScope;
// Runtime encoding of different completion modes.
enum CompletionKind {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment