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

[zone] Cleanup zone allocations in src/ast and tests

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

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

Bug: v8:10689
Change-Id: I79fc4f9793a0c7a3bd38230ca4e23d33344fc1b2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2288863Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68792}
parent e4f5f23b
......@@ -268,21 +268,21 @@ AstStringConstants::AstStringConstants(Isolate* isolate, uint64_t hash_seed)
string_table_(AstRawString::Compare),
hash_seed_(hash_seed) {
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
#define F(name, str) \
{ \
const char* data = str; \
Vector<const uint8_t> literal(reinterpret_cast<const uint8_t*>(data), \
static_cast<int>(strlen(data))); \
uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( \
literal.begin(), literal.length(), hash_seed_); \
name##_string_ = new (&zone_) AstRawString(true, literal, hash_field); \
/* The Handle returned by the factory is located on the roots */ \
/* array, not on the temporary HandleScope, so this is safe. */ \
name##_string_->set_string(isolate->factory()->name##_string()); \
base::HashMap::Entry* entry = \
string_table_.InsertNew(name##_string_, name##_string_->Hash()); \
DCHECK_NULL(entry->value); \
entry->value = reinterpret_cast<void*>(1); \
#define F(name, str) \
{ \
const char* data = str; \
Vector<const uint8_t> literal(reinterpret_cast<const uint8_t*>(data), \
static_cast<int>(strlen(data))); \
uint32_t hash_field = StringHasher::HashSequentialString<uint8_t>( \
literal.begin(), literal.length(), hash_seed_); \
name##_string_ = zone_.New<AstRawString>(true, literal, hash_field); \
/* The Handle returned by the factory is located on the roots */ \
/* array, not on the temporary HandleScope, so this is safe. */ \
name##_string_->set_string(isolate->factory()->name##_string()); \
base::HashMap::Entry* entry = \
string_table_.InsertNew(name##_string_, name##_string_->Hash()); \
DCHECK_NULL(entry->value); \
entry->value = reinterpret_cast<void*>(1); \
}
AST_STRING_CONSTANTS(F)
#undef F
......@@ -333,7 +333,7 @@ const AstRawString* AstValueFactory::CloneFromOtherFactory(
}
AstConsString* AstValueFactory::NewConsString() {
return new (zone()) AstConsString;
return zone()->New<AstConsString>();
}
AstConsString* AstValueFactory::NewConsString(const AstRawString* str) {
......@@ -379,7 +379,7 @@ AstRawString* AstValueFactory::GetString(uint32_t hash_field, bool is_one_byte,
int length = literal_bytes.length();
byte* new_literal_bytes = zone()->NewArray<byte>(length);
memcpy(new_literal_bytes, literal_bytes.begin(), length);
AstRawString* new_string = new (zone()) AstRawString(
AstRawString* new_string = zone()->New<AstRawString>(
is_one_byte, Vector<const byte>(new_literal_bytes, length), hash_field);
CHECK_NOT_NULL(new_string);
AddString(new_string);
......
......@@ -83,6 +83,7 @@ class AstRawString final : public ZoneObject {
friend class AstRawStringInternalizationKey;
friend class AstStringConstants;
friend class AstValueFactory;
friend Zone;
// Members accessed only by the AstValueFactory & related classes:
static bool Compare(void* a, void* b);
......@@ -133,8 +134,7 @@ class AstConsString final : public ZoneObject {
if (!IsEmpty()) {
// We're putting the new string to the head of the list, meaning
// the string segments will be in reverse order.
Segment* tmp = new (zone->New(sizeof(Segment))) Segment;
*tmp = segment_;
Segment* tmp = zone->New<Segment>(segment_);
segment_.next = tmp;
}
segment_.string = s;
......@@ -163,6 +163,7 @@ class AstConsString final : public ZoneObject {
private:
friend class AstValueFactory;
friend Zone;
AstConsString() : string_(), segment_({nullptr, nullptr}) {}
......
......@@ -1063,7 +1063,7 @@ Literal* AstNodeFactory::NewNumberLiteral(double number, int pos) {
if (DoubleToSmiInteger(number, &int_value)) {
return NewSmiLiteral(int_value, pos);
}
return new (zone_) Literal(number, pos);
return zone_->New<Literal>(number, pos);
}
const char* CallRuntime::debug_name() {
......
This diff is collapsed.
......@@ -32,7 +32,7 @@ void SourceTextModuleDescriptor::AddImport(
const AstRawString* import_name, const AstRawString* local_name,
const AstRawString* module_request, const Scanner::Location loc,
const Scanner::Location specifier_loc, Zone* zone) {
Entry* entry = new (zone) Entry(loc);
Entry* entry = zone->New<Entry>(loc);
entry->local_name = local_name;
entry->import_name = import_name;
entry->module_request = AddModuleRequest(module_request, specifier_loc);
......@@ -43,7 +43,7 @@ void SourceTextModuleDescriptor::AddStarImport(
const AstRawString* local_name, const AstRawString* module_request,
const Scanner::Location loc, const Scanner::Location specifier_loc,
Zone* zone) {
Entry* entry = new (zone) Entry(loc);
Entry* entry = zone->New<Entry>(loc);
entry->local_name = local_name;
entry->module_request = AddModuleRequest(module_request, specifier_loc);
AddNamespaceImport(entry, zone);
......@@ -57,7 +57,7 @@ void SourceTextModuleDescriptor::AddEmptyImport(
void SourceTextModuleDescriptor::AddExport(const AstRawString* local_name,
const AstRawString* export_name,
Scanner::Location loc, Zone* zone) {
Entry* entry = new (zone) Entry(loc);
Entry* entry = zone->New<Entry>(loc);
entry->export_name = export_name;
entry->local_name = local_name;
AddRegularExport(entry);
......@@ -69,7 +69,7 @@ void SourceTextModuleDescriptor::AddExport(
const Scanner::Location specifier_loc, Zone* zone) {
DCHECK_NOT_NULL(import_name);
DCHECK_NOT_NULL(export_name);
Entry* entry = new (zone) Entry(loc);
Entry* entry = zone->New<Entry>(loc);
entry->export_name = export_name;
entry->import_name = import_name;
entry->module_request = AddModuleRequest(module_request, specifier_loc);
......@@ -79,7 +79,7 @@ void SourceTextModuleDescriptor::AddExport(
void SourceTextModuleDescriptor::AddStarExport(
const AstRawString* module_request, const Scanner::Location loc,
const Scanner::Location specifier_loc, Zone* zone) {
Entry* entry = new (zone) Entry(loc);
Entry* entry = zone->New<Entry>(loc);
entry->module_request = AddModuleRequest(module_request, specifier_loc);
AddSpecialExport(entry, zone);
}
......
......@@ -54,7 +54,7 @@ Variable* VariableMap::Declare(Zone* zone, Scope* scope,
// The variable has not been declared yet -> insert it.
DCHECK_EQ(name, p->key);
Variable* variable =
new (zone) Variable(scope, name, mode, kind, initialization_flag,
zone->New<Variable>(scope, name, mode, kind, initialization_flag,
maybe_assigned_flag, is_static_flag);
p->value = variable;
}
......@@ -138,8 +138,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
ModuleScope::ModuleScope(DeclarationScope* script_scope,
AstValueFactory* avfactory)
: DeclarationScope(avfactory->zone(), script_scope, MODULE_SCOPE, kModule),
module_descriptor_(new (avfactory->zone())
SourceTextModuleDescriptor(avfactory->zone())) {
module_descriptor_(avfactory->zone()->New<SourceTextModuleDescriptor>(
avfactory->zone())) {
set_language_mode(LanguageMode::kStrict);
DeclareThis(avfactory);
}
......@@ -357,13 +357,13 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
while (!scope_info.is_null()) {
if (scope_info.scope_type() == WITH_SCOPE) {
if (scope_info.IsDebugEvaluateScope()) {
outer_scope = new (zone)
DeclarationScope(zone, FUNCTION_SCOPE, handle(scope_info, isolate));
outer_scope = zone->New<DeclarationScope>(zone, FUNCTION_SCOPE,
handle(scope_info, isolate));
outer_scope->set_is_debug_evaluate_scope();
} else {
// For scope analysis, debug-evaluate is equivalent to a with scope.
outer_scope =
new (zone) Scope(zone, WITH_SCOPE, handle(scope_info, isolate));
zone->New<Scope>(zone, WITH_SCOPE, handle(scope_info, isolate));
}
} else if (scope_info.scope_type() == SCRIPT_SCOPE) {
......@@ -377,28 +377,28 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
DCHECK(!scope_info.HasOuterScopeInfo());
break;
} else if (scope_info.scope_type() == FUNCTION_SCOPE) {
outer_scope = new (zone)
DeclarationScope(zone, FUNCTION_SCOPE, handle(scope_info, isolate));
outer_scope = zone->New<DeclarationScope>(zone, FUNCTION_SCOPE,
handle(scope_info, isolate));
if (scope_info.IsAsmModule()) {
outer_scope->AsDeclarationScope()->set_is_asm_module();
}
} else if (scope_info.scope_type() == EVAL_SCOPE) {
outer_scope = new (zone)
DeclarationScope(zone, EVAL_SCOPE, handle(scope_info, isolate));
outer_scope = zone->New<DeclarationScope>(zone, EVAL_SCOPE,
handle(scope_info, isolate));
} else if (scope_info.scope_type() == CLASS_SCOPE) {
outer_scope = new (zone) ClassScope(isolate, zone, ast_value_factory,
outer_scope = zone->New<ClassScope>(isolate, zone, ast_value_factory,
handle(scope_info, isolate));
} else if (scope_info.scope_type() == BLOCK_SCOPE) {
if (scope_info.is_declaration_scope()) {
outer_scope = new (zone)
DeclarationScope(zone, BLOCK_SCOPE, handle(scope_info, isolate));
outer_scope = zone->New<DeclarationScope>(zone, BLOCK_SCOPE,
handle(scope_info, isolate));
} else {
outer_scope =
new (zone) Scope(zone, BLOCK_SCOPE, handle(scope_info, isolate));
zone->New<Scope>(zone, BLOCK_SCOPE, handle(scope_info, isolate));
}
} else if (scope_info.scope_type() == MODULE_SCOPE) {
outer_scope = new (zone)
ModuleScope(isolate, handle(scope_info, isolate), ast_value_factory);
outer_scope = zone->New<ModuleScope>(isolate, handle(scope_info, isolate),
ast_value_factory);
} else {
DCHECK_EQ(scope_info.scope_type(), CATCH_SCOPE);
DCHECK_EQ(scope_info.ContextLocalCount(), 1);
......@@ -407,9 +407,9 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
String name = scope_info.ContextLocalName(0);
MaybeAssignedFlag maybe_assigned =
scope_info.ContextLocalMaybeAssignedFlag(0);
outer_scope = new (zone)
Scope(zone, ast_value_factory->GetString(handle(name, isolate)),
maybe_assigned, handle(scope_info, isolate));
outer_scope = zone->New<Scope>(
zone, ast_value_factory->GetString(handle(name, isolate)),
maybe_assigned, handle(scope_info, isolate));
}
if (deserialization_mode == DeserializationMode::kScopesOnly) {
outer_scope->scope_info_ = Handle<ScopeInfo>::null();
......@@ -621,12 +621,12 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
bool derived_constructor = IsDerivedConstructor(function_kind_);
receiver_ = new (zone())
Variable(this, ast_value_factory->this_string(),
derived_constructor ? VariableMode::kConst : VariableMode::kVar,
THIS_VARIABLE,
derived_constructor ? kNeedsInitialization : kCreatedInitialized,
kNotAssigned);
receiver_ = zone()->New<Variable>(
this, ast_value_factory->this_string(),
derived_constructor ? VariableMode::kConst : VariableMode::kVar,
THIS_VARIABLE,
derived_constructor ? kNeedsInitialization : kCreatedInitialized,
kNotAssigned);
}
void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) {
......@@ -677,8 +677,8 @@ Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name,
DCHECK_NULL(cache->variables_.Lookup(name));
VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE
: NORMAL_VARIABLE;
function_ = new (zone())
Variable(this, name, VariableMode::kConst, kind, kCreatedInitialized);
function_ = zone()->New<Variable>(this, name, VariableMode::kConst, kind,
kCreatedInitialized);
if (sloppy_eval_can_extend_vars()) {
cache->NonLocal(name, VariableMode::kDynamic);
} else {
......@@ -1131,7 +1131,7 @@ Variable* Scope::NewTemporary(const AstRawString* name) {
Variable* Scope::NewTemporary(const AstRawString* name,
MaybeAssignedFlag maybe_assigned) {
DeclarationScope* scope = GetClosureScope();
Variable* var = new (zone()) Variable(scope, name, VariableMode::kTemporary,
Variable* var = zone()->New<Variable>(scope, name, VariableMode::kTemporary,
NORMAL_VARIABLE, kCreatedInitialized);
scope->AddLocal(var);
if (maybe_assigned == kMaybeAssigned) var->SetMaybeAssigned();
......
......@@ -699,6 +699,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
friend class DeclarationScope;
friend class ClassScope;
friend class ScopeTestHelper;
friend Zone;
Zone* zone_;
......@@ -1260,7 +1261,7 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
V8_INLINE RareData* EnsureRareData() {
if (rare_data_ == nullptr) {
rare_data_ = new (zone_) RareData;
rare_data_ = zone_->New<RareData>();
}
return rare_data_;
}
......@@ -1441,8 +1442,8 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope {
}
V8_INLINE RareData* EnsureRareData() {
if (GetRareData() == nullptr) {
rare_data_and_is_parsing_heritage_.SetPointer(new (zone_)
RareData(zone_));
rare_data_and_is_parsing_heritage_.SetPointer(
zone_->New<RareData>(zone_));
}
return GetRareData();
}
......
......@@ -3375,7 +3375,7 @@ TEST(SerializationOfMaybeAssignmentFlag) {
i::Handle<i::String> str = name->string();
CHECK(str->IsInternalizedString());
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, &avf);
zone.New<i::DeclarationScope>(&zone, &avf);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context->scope_info(), script_scope, &avf,
i::Scope::DeserializationMode::kIncludingVariables);
......@@ -3424,7 +3424,7 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
avf.Internalize(isolate);
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, &avf);
zone.New<i::DeclarationScope>(&zone, &avf);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context->scope_info(), script_scope, &avf,
i::Scope::DeserializationMode::kIncludingVariables);
......@@ -4349,7 +4349,7 @@ i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone,
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(
i::JSReceiver::GetProperty(isolate, m, name).ToHandleChecked());
i::DeclarationScope* script_scope =
new (zone) i::DeclarationScope(zone, &avf);
zone->New<i::DeclarationScope>(zone, &avf);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, zone, f->context().scope_info(), script_scope, &avf,
i::Scope::DeserializationMode::kIncludingVariables);
......
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