Commit c7e26aca authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[zone] Cleanup zone allocations in src/parsing and src/diagnostics

... by migrating old-style code
  MyObject* obj = new (zone) MyObject(...)

to the new style
  MyObject* obj = zone->New<MyObject>(...)

Bug: v8:10689
Change-Id: I08e513911a6b4e5d564cab42720a197d1244dd2e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2292238Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68819}
parent fc48a228
......@@ -570,8 +570,8 @@ class MachO {
class ELF {
public:
explicit ELF(Zone* zone) : sections_(zone) {
sections_.push_back(new (zone) ELFSection("", ELFSection::TYPE_NULL, 0));
sections_.push_back(new (zone) ELFStringTable(".shstrtab"));
sections_.push_back(zone->New<ELFSection>("", ELFSection::TYPE_NULL, 0));
sections_.push_back(zone->New<ELFStringTable>(".shstrtab"));
}
void Write(Writer* w) {
......@@ -974,8 +974,8 @@ class CodeDescription {
#if defined(__ELF)
static void CreateSymbolsTable(CodeDescription* desc, Zone* zone, ELF* elf,
size_t text_section_index) {
ELFSymbolTable* symtab = new (zone) ELFSymbolTable(".symtab", zone);
ELFStringTable* strtab = new (zone) ELFStringTable(".strtab");
ELFSymbolTable* symtab = zone->New<ELFSymbolTable>(".symtab", zone);
ELFStringTable* strtab = zone->New<ELFStringTable>(".strtab");
// Symbol table should be followed by the linked string table.
elf->AddSection(symtab);
......@@ -1692,12 +1692,12 @@ bool UnwindInfoSection::WriteBodyInternal(Writer* w) {
static void CreateDWARFSections(CodeDescription* desc, Zone* zone,
DebugObject* obj) {
if (desc->IsLineInfoAvailable()) {
obj->AddSection(new (zone) DebugInfoSection(desc));
obj->AddSection(new (zone) DebugAbbrevSection(desc));
obj->AddSection(new (zone) DebugLineSection(desc));
obj->AddSection(zone->New<DebugInfoSection>(desc));
obj->AddSection(zone->New<DebugAbbrevSection>(desc));
obj->AddSection(zone->New<DebugLineSection>(desc));
}
#if V8_TARGET_ARCH_X64
obj->AddSection(new (zone) UnwindInfoSection(desc));
obj->AddSection(zone->New<UnwindInfoSection>(desc));
#endif
}
......@@ -1789,8 +1789,11 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Isolate* isolate) {
MachO mach_o(&zone);
Writer w(&mach_o);
mach_o.AddSection(new (&zone) MachOTextSection(
kCodeAlignment, desc->CodeStart(), desc->CodeSize()));
const uint32_t code_alignment = static_cast<uint32_t>(kCodeAlignment);
static_assert(code_alignment == kCodeAlignment,
"Unsupported code alignment value");
mach_o.AddSection(zone.New<MachOTextSection>(
code_alignment, desc->CodeStart(), desc->CodeSize()));
CreateDWARFSections(desc, &zone, &mach_o);
......@@ -1800,7 +1803,7 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Isolate* isolate) {
ELF elf(&zone);
Writer w(&elf);
size_t text_section_index = elf.AddSection(new (&zone) FullHeaderELFSection(
size_t text_section_index = elf.AddSection(zone.New<FullHeaderELFSection>(
".text", ELFSection::TYPE_NOBITS, kCodeAlignment, desc->CodeStart(), 0,
desc->CodeSize(), ELFSection::FLAG_ALLOC | ELFSection::FLAG_EXEC));
......
......@@ -286,7 +286,7 @@ AstValueFactory* ParseInfo::GetOrCreateAstValueFactory() {
void ParseInfo::AllocateSourceRangeMap() {
DCHECK(flags().block_coverage_enabled());
DCHECK_NULL(source_range_map());
set_source_range_map(new (zone()) SourceRangeMap(zone()));
set_source_range_map(zone()->New<SourceRangeMap>(zone()));
}
void ParseInfo::ResetCharacterStream() { character_stream_.reset(); }
......
......@@ -328,7 +328,7 @@ class ParserBase {
BlockState(Zone* zone, Scope** scope_stack)
: BlockState(scope_stack,
new (zone) Scope(zone, *scope_stack, BLOCK_SCOPE)) {}
zone->New<Scope>(zone, *scope_stack, BLOCK_SCOPE)) {}
~BlockState() { *scope_stack_ = outer_scope_; }
......@@ -693,11 +693,14 @@ class ParserBase {
// Add {label} to both {labels} and {own_labels}.
if (*labels == nullptr) {
DCHECK_NULL(*own_labels);
*labels = new (zone()) ZonePtrList<const AstRawString>(1, zone());
*own_labels = new (zone()) ZonePtrList<const AstRawString>(1, zone());
*labels =
zone()->template New<ZonePtrList<const AstRawString>>(1, zone());
*own_labels =
zone()->template New<ZonePtrList<const AstRawString>>(1, zone());
} else {
if (*own_labels == nullptr) {
*own_labels = new (zone()) ZonePtrList<const AstRawString>(1, zone());
*own_labels =
zone()->template New<ZonePtrList<const AstRawString>>(1, zone());
}
}
(*labels)->Add(label, zone());
......@@ -758,24 +761,24 @@ class ParserBase {
}
DeclarationScope* NewScriptScope(REPLMode repl_mode) const {
return new (zone())
DeclarationScope(zone(), ast_value_factory(), repl_mode);
return zone()->template New<DeclarationScope>(zone(), ast_value_factory(),
repl_mode);
}
DeclarationScope* NewVarblockScope() const {
return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
return zone()->template New<DeclarationScope>(zone(), scope(), BLOCK_SCOPE);
}
ModuleScope* NewModuleScope(DeclarationScope* parent) const {
return new (zone()) ModuleScope(parent, ast_value_factory());
return zone()->template New<ModuleScope>(parent, ast_value_factory());
}
DeclarationScope* NewEvalScope(Scope* parent) const {
return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE);
return zone()->template New<DeclarationScope>(zone(), parent, EVAL_SCOPE);
}
ClassScope* NewClassScope(Scope* parent, bool is_anonymous) const {
return new (zone()) ClassScope(zone(), parent, is_anonymous);
return zone()->template New<ClassScope>(zone(), parent, is_anonymous);
}
Scope* NewScope(ScopeType scope_type) const {
......@@ -792,7 +795,7 @@ class ParserBase {
DCHECK_NE(SCRIPT_SCOPE, scope_type);
DCHECK_NE(MODULE_SCOPE, scope_type);
DCHECK_NOT_NULL(parent);
return new (zone()) Scope(zone(), parent, scope_type);
return zone()->template New<Scope>(zone(), parent, scope_type);
}
// Creates a function scope that always allocates in zone(). The function
......@@ -802,8 +805,8 @@ class ParserBase {
Zone* parse_zone = nullptr) const {
DCHECK(ast_value_factory());
if (parse_zone == nullptr) parse_zone = zone();
DeclarationScope* result = new (zone())
DeclarationScope(parse_zone, scope(), FUNCTION_SCOPE, kind);
DeclarationScope* result = zone()->template New<DeclarationScope>(
parse_zone, scope(), FUNCTION_SCOPE, kind);
// Record presence of an inner function scope
function_state_->RecordFunctionOrEvalCall();
......@@ -5281,7 +5284,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
auto labels_copy =
labels == nullptr
? labels
: new (zone()) ZonePtrList<const AstRawString>(*labels, zone());
: zone()->template New<ZonePtrList<const AstRawString>>(*labels,
zone());
then_statement = ParseScopedStatement(labels_copy);
}
......
......@@ -718,7 +718,7 @@ ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments(
Handle<FixedArray> arguments = maybe_wrapped_arguments_.ToHandleChecked();
int arguments_length = arguments->length();
ZonePtrList<const AstRawString>* arguments_for_wrapped_function =
new (zone) ZonePtrList<const AstRawString>(arguments_length, zone);
zone->New<ZonePtrList<const AstRawString>>(arguments_length, zone);
for (int i = 0; i < arguments_length; i++) {
const AstRawString* argument_string = ast_value_factory()->GetString(
Handle<String>(String::cast(arguments->get(i)), isolate));
......@@ -1085,7 +1085,7 @@ ZoneChunkList<Parser::ExportClauseData>* Parser::ParseExportClause(
// IdentifierName
// IdentifierName 'as' IdentifierName
ZoneChunkList<ExportClauseData>* export_data =
new (zone()) ZoneChunkList<ExportClauseData>(zone());
zone()->New<ZoneChunkList<ExportClauseData>>(zone());
Expect(Token::LBRACE);
......@@ -1138,7 +1138,7 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) {
Expect(Token::LBRACE);
auto result = new (zone()) ZonePtrList<const NamedImport>(1, zone());
auto result = zone()->New<ZonePtrList<const NamedImport>>(1, zone());
while (peek() != Token::RBRACE) {
const AstRawString* import_name = ParsePropertyName();
const AstRawString* local_name = import_name;
......@@ -1163,7 +1163,7 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) {
kNeedsInitialization, position());
NamedImport* import =
new (zone()) NamedImport(import_name, local_name, location);
zone()->New<NamedImport>(import_name, local_name, location);
result->Add(import, zone());
if (peek() == Token::RBRACE) break;
......@@ -3148,7 +3148,7 @@ void Parser::ParseOnBackground(ParseInfo* info, int start_position,
}
Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) {
return new (zone()) TemplateLiteral(zone(), pos);
return zone()->New<TemplateLiteral>(zone(), pos);
}
void Parser::AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
......
......@@ -822,18 +822,18 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
V8_INLINE ZonePtrList<Expression>* NewExpressionList(int size) const {
return new (zone()) ZonePtrList<Expression>(size, zone());
return zone()->New<ZonePtrList<Expression>>(size, zone());
}
V8_INLINE ZonePtrList<ObjectLiteral::Property>* NewObjectPropertyList(
int size) const {
return new (zone()) ZonePtrList<ObjectLiteral::Property>(size, zone());
return zone()->New<ZonePtrList<ObjectLiteral::Property>>(size, zone());
}
V8_INLINE ZonePtrList<ClassLiteral::Property>* NewClassPropertyList(
int size) const {
return new (zone()) ZonePtrList<ClassLiteral::Property>(size, zone());
return zone()->New<ZonePtrList<ClassLiteral::Property>>(size, zone());
}
V8_INLINE ZonePtrList<Statement>* NewStatementList(int size) const {
return new (zone()) ZonePtrList<Statement>(size, zone());
return zone()->New<ZonePtrList<Statement>>(size, zone());
}
Expression* NewV8Intrinsic(const AstRawString* name,
......@@ -854,10 +854,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int initializer_end_position,
bool is_rest) {
parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest);
auto parameter = new (parameters->scope->zone())
ParserFormalParameters::Parameter(pattern, initializer,
scanner()->location().beg_pos,
initializer_end_position, is_rest);
auto parameter =
parameters->scope->zone()->New<ParserFormalParameters::Parameter>(
pattern, initializer, scanner()->location().beg_pos,
initializer_end_position, is_rest);
parameters->params.Add(parameter);
}
......@@ -918,7 +918,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
SourceRange range = ranges->GetRange(SourceRangeKind::kRight);
source_range_map_->Insert(
nary_op, new (zone()) NaryOperationSourceRanges(zone(), range));
nary_op, zone()->New<NaryOperationSourceRanges>(zone(), range));
}
V8_INLINE void AppendNaryOperationSourceRange(NaryOperation* node,
......@@ -936,14 +936,14 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int32_t continuation_position) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node, new (zone()) BlockSourceRanges(continuation_position));
node, zone()->New<BlockSourceRanges>(continuation_position));
}
V8_INLINE void RecordCaseClauseSourceRange(CaseClause* node,
const SourceRange& body_range) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(node,
new (zone()) CaseClauseSourceRanges(body_range));
zone()->New<CaseClauseSourceRanges>(body_range));
}
V8_INLINE void RecordConditionalSourceRange(Expression* node,
......@@ -952,20 +952,20 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node->AsConditional(),
new (zone()) ConditionalSourceRanges(then_range, else_range));
zone()->New<ConditionalSourceRanges>(then_range, else_range));
}
V8_INLINE void RecordFunctionLiteralSourceRange(FunctionLiteral* node) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(node, new (zone()) FunctionLiteralSourceRanges);
source_range_map_->Insert(node, zone()->New<FunctionLiteralSourceRanges>());
}
V8_INLINE void RecordBinaryOperationSourceRange(
Expression* node, const SourceRange& right_range) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(node->AsBinaryOperation(),
new (zone())
BinaryOperationSourceRanges(right_range));
source_range_map_->Insert(
node->AsBinaryOperation(),
zone()->New<BinaryOperationSourceRanges>(right_range));
}
V8_INLINE void RecordJumpStatementSourceRange(Statement* node,
......@@ -973,7 +973,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
static_cast<JumpStatement*>(node),
new (zone()) JumpStatementSourceRanges(continuation_position));
zone()->New<JumpStatementSourceRanges>(continuation_position));
}
V8_INLINE void RecordIfStatementSourceRange(Statement* node,
......@@ -982,22 +982,22 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node->AsIfStatement(),
new (zone()) IfStatementSourceRanges(then_range, else_range));
zone()->New<IfStatementSourceRanges>(then_range, else_range));
}
V8_INLINE void RecordIterationStatementSourceRange(
IterationStatement* node, const SourceRange& body_range) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node, new (zone()) IterationStatementSourceRanges(body_range));
node, zone()->New<IterationStatementSourceRanges>(body_range));
}
V8_INLINE void RecordSuspendSourceRange(Expression* node,
int32_t continuation_position) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(static_cast<Suspend*>(node),
new (zone())
SuspendSourceRanges(continuation_position));
source_range_map_->Insert(
static_cast<Suspend*>(node),
zone()->New<SuspendSourceRanges>(continuation_position));
}
V8_INLINE void RecordSwitchStatementSourceRange(
......@@ -1005,7 +1005,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node->AsSwitchStatement(),
new (zone()) SwitchStatementSourceRanges(continuation_position));
zone()->New<SwitchStatementSourceRanges>(continuation_position));
}
V8_INLINE void RecordThrowSourceRange(Statement* node,
......@@ -1014,21 +1014,21 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
ExpressionStatement* expr_stmt = static_cast<ExpressionStatement*>(node);
Throw* throw_expr = expr_stmt->expression()->AsThrow();
source_range_map_->Insert(
throw_expr, new (zone()) ThrowSourceRanges(continuation_position));
throw_expr, zone()->New<ThrowSourceRanges>(continuation_position));
}
V8_INLINE void RecordTryCatchStatementSourceRange(
TryCatchStatement* node, const SourceRange& body_range) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node, new (zone()) TryCatchStatementSourceRanges(body_range));
node, zone()->New<TryCatchStatementSourceRanges>(body_range));
}
V8_INLINE void RecordTryFinallyStatementSourceRange(
TryFinallyStatement* node, const SourceRange& body_range) {
if (source_range_map_ == nullptr) return;
source_range_map_->Insert(
node, new (zone()) TryFinallyStatementSourceRanges(body_range));
node, zone()->New<TryFinallyStatementSourceRanges>(body_range));
}
// Generate the next internal variable name for binding an exported namespace
......
......@@ -223,7 +223,7 @@ class ZonePreparseData : public ZoneObject {
ZonePreparseData* PreparseDataBuilder::ByteData::CopyToZone(
Zone* zone, int children_length) {
DCHECK(is_finalized_);
return new (zone) ZonePreparseData(zone, &zone_byte_data_, children_length);
return zone->New<ZonePreparseData>(zone, &zone_byte_data_, children_length);
}
// Implementation of ConsumedPreparseData for PreparseData
......
......@@ -104,9 +104,9 @@ PreparseDataBuilder::PreparseDataBuilder(Zone* zone,
void PreparseDataBuilder::DataGatheringScope::Start(
DeclarationScope* function_scope) {
Zone* main_zone = preparser_->main_zone();
builder_ = new (main_zone)
PreparseDataBuilder(main_zone, preparser_->preparse_data_builder(),
preparser_->preparse_data_builder_buffer());
builder_ = main_zone->New<PreparseDataBuilder>(
main_zone, preparser_->preparse_data_builder(),
preparser_->preparse_data_builder_buffer());
preparser_->set_preparse_data_builder(builder_);
function_scope->set_preparse_data_builder(builder_);
}
......@@ -128,9 +128,11 @@ void PreparseDataBuilder::ByteData::Start(std::vector<uint8_t>* buffer) {
DCHECK_EQ(index_, 0);
}
// This struct is just a type tag for Zone::NewArray<T>(size_t) call.
struct RawPreparseData {};
void PreparseDataBuilder::ByteData::Finalize(Zone* zone) {
uint8_t* raw_zone_data =
static_cast<uint8_t*>(ZoneAllocationPolicy(zone).New(index_));
uint8_t* raw_zone_data = zone->NewArray<uint8_t, RawPreparseData>(index_);
memcpy(raw_zone_data, byte_data_->data(), index_);
byte_data_->resize(0);
zone_byte_data_ = Vector<uint8_t>(raw_zone_data, index_);
......@@ -557,17 +559,17 @@ class ZoneProducedPreparseData final : public ProducedPreparseData {
ProducedPreparseData* ProducedPreparseData::For(PreparseDataBuilder* builder,
Zone* zone) {
return new (zone) BuilderProducedPreparseData(builder);
return zone->New<BuilderProducedPreparseData>(builder);
}
ProducedPreparseData* ProducedPreparseData::For(Handle<PreparseData> data,
Zone* zone) {
return new (zone) OnHeapProducedPreparseData(data);
return zone->New<OnHeapProducedPreparseData>(data);
}
ProducedPreparseData* ProducedPreparseData::For(ZonePreparseData* data,
Zone* zone) {
return new (zone) ZoneProducedPreparseData(data);
return zone->New<ZoneProducedPreparseData>(data);
}
template <class Data>
......
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