Commit 295ee7ef authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[zone] Cleanup zone allocations in src/wasm 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: I2fc4a44ea05e4d087565811f343893f0e97dc660
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2288857
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68789}
parent 734ea682
...@@ -1905,7 +1905,7 @@ class LiftoffCompiler { ...@@ -1905,7 +1905,7 @@ class LiftoffCompiler {
// If we are generating debugging code, we really need to spill all // If we are generating debugging code, we really need to spill all
// registers to make them inspectable when stopping at the trap. // registers to make them inspectable when stopping at the trap.
auto* spilled = auto* spilled =
new (compilation_zone_) SpilledRegistersBeforeTrap(compilation_zone_); compilation_zone_->New<SpilledRegistersBeforeTrap>(compilation_zone_);
for (uint32_t i = 0, e = __ cache_state()->stack_height(); i < e; ++i) { for (uint32_t i = 0, e = __ cache_state()->stack_height(); i < e; ++i) {
auto& slot = __ cache_state()->stack_state[i]; auto& slot = __ cache_state()->stack_state[i];
if (!slot.is_reg()) continue; if (!slot.is_reg()) continue;
......
...@@ -1072,7 +1072,7 @@ class WasmDecoder : public Decoder { ...@@ -1072,7 +1072,7 @@ class WasmDecoder : public Decoder {
// The number of locals_count is augmented by 2 so that 'locals_count - 2' // The number of locals_count is augmented by 2 so that 'locals_count - 2'
// can be used to track mem_size, and 'locals_count - 1' to track mem_start. // can be used to track mem_size, and 'locals_count - 1' to track mem_start.
BitVector* assigned = new (zone) BitVector(locals_count, zone); BitVector* assigned = zone->New<BitVector>(locals_count, zone);
int depth = 0; int depth = 0;
// Iteratively process all AST nodes nested inside the loop. // Iteratively process all AST nodes nested inside the loop.
while (pc < decoder->end() && VALIDATE(decoder->ok())) { while (pc < decoder->end() && VALIDATE(decoder->ok())) {
......
...@@ -118,8 +118,8 @@ class WasmGraphBuildingInterface { ...@@ -118,8 +118,8 @@ class WasmGraphBuildingInterface {
TFNode* start = builder_->Start( TFNode* start = builder_->Start(
static_cast<int>(decoder->sig_->parameter_count() + 1 + 1)); static_cast<int>(decoder->sig_->parameter_count() + 1 + 1));
uint32_t num_locals = decoder->num_locals(); uint32_t num_locals = decoder->num_locals();
SsaEnv* ssa_env = new (decoder->zone()) SsaEnv* ssa_env = decoder->zone()->New<SsaEnv>(
SsaEnv(decoder->zone(), SsaEnv::kReached, start, start, num_locals); decoder->zone(), SsaEnv::kReached, start, start, num_locals);
// Initialize effect and control before initializing the locals default // Initialize effect and control before initializing the locals default
// values (which might require instance loads) or loading the context. // values (which might require instance loads) or loading the context.
...@@ -189,7 +189,7 @@ class WasmGraphBuildingInterface { ...@@ -189,7 +189,7 @@ class WasmGraphBuildingInterface {
catch_env->state = SsaEnv::kUnreachable; catch_env->state = SsaEnv::kUnreachable;
SsaEnv* try_env = Steal(decoder->zone(), outer_env); SsaEnv* try_env = Steal(decoder->zone(), outer_env);
SetEnv(try_env); SetEnv(try_env);
TryInfo* try_info = new (decoder->zone()) TryInfo(catch_env); TryInfo* try_info = decoder->zone()->New<TryInfo>(catch_env);
block->end_env = outer_env; block->end_env = outer_env;
block->try_info = try_info; block->try_info = try_info;
block->previous_catch = current_catch_; block->previous_catch = current_catch_;
...@@ -1026,7 +1026,7 @@ class WasmGraphBuildingInterface { ...@@ -1026,7 +1026,7 @@ class WasmGraphBuildingInterface {
ssa_env_->control = control(); ssa_env_->control = control();
ssa_env_->effect = effect(); ssa_env_->effect = effect();
} }
SsaEnv* result = new (zone) SsaEnv(*from); SsaEnv* result = zone->New<SsaEnv>(*from);
result->state = SsaEnv::kReached; result->state = SsaEnv::kReached;
return result; return result;
} }
...@@ -1039,14 +1039,14 @@ class WasmGraphBuildingInterface { ...@@ -1039,14 +1039,14 @@ class WasmGraphBuildingInterface {
ssa_env_->control = control(); ssa_env_->control = control();
ssa_env_->effect = effect(); ssa_env_->effect = effect();
} }
SsaEnv* result = new (zone) SsaEnv(std::move(*from)); SsaEnv* result = zone->New<SsaEnv>(std::move(*from));
result->state = SsaEnv::kReached; result->state = SsaEnv::kReached;
return result; return result;
} }
// Create an unreachable environment. // Create an unreachable environment.
SsaEnv* UnreachableEnv(Zone* zone) { SsaEnv* UnreachableEnv(Zone* zone) {
return new (zone) SsaEnv(zone, SsaEnv::kUnreachable, nullptr, nullptr, 0); return zone->New<SsaEnv>(zone, SsaEnv::kUnreachable, nullptr, nullptr, 0);
} }
void DoCall(FullDecoder* decoder, uint32_t table_index, TFNode* index_node, void DoCall(FullDecoder* decoder, uint32_t table_index, TFNode* index_node,
......
...@@ -11,10 +11,13 @@ namespace v8 { ...@@ -11,10 +11,13 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
// This struct is just a type tag for Zone::NewArray<T>(size_t) call.
struct LocalDeclEncoderBuffer {};
void LocalDeclEncoder::Prepend(Zone* zone, const byte** start, void LocalDeclEncoder::Prepend(Zone* zone, const byte** start,
const byte** end) const { const byte** end) const {
size_t size = (*end - *start); size_t size = (*end - *start);
byte* buffer = reinterpret_cast<byte*>(zone->New(Size() + size)); byte* buffer = zone->NewArray<byte, LocalDeclEncoderBuffer>(Size() + size);
size_t pos = Emit(buffer); size_t pos = Emit(buffer);
if (size > 0) { if (size > 0) {
memcpy(buffer + pos, *start, size); memcpy(buffer + pos, *start, size);
......
...@@ -1841,7 +1841,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1841,7 +1841,7 @@ class ModuleDecoderImpl : public Decoder {
for (uint32_t i = 0; i < return_count; ++i) buffer[b++] = returns[i]; for (uint32_t i = 0; i < return_count; ++i) buffer[b++] = returns[i];
for (uint32_t i = 0; i < param_count; ++i) buffer[b++] = params[i]; for (uint32_t i = 0; i < param_count; ++i) buffer[b++] = params[i];
return new (zone) FunctionSig(return_count, param_count, buffer); return zone->New<FunctionSig>(return_count, param_count, buffer);
} }
const StructType* consume_struct(Zone* zone) { const StructType* consume_struct(Zone* zone) {
...@@ -1859,7 +1859,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1859,7 +1859,7 @@ class ModuleDecoderImpl : public Decoder {
} }
if (failed()) return nullptr; if (failed()) return nullptr;
uint32_t* offsets = zone->NewArray<uint32_t>(field_count); uint32_t* offsets = zone->NewArray<uint32_t>(field_count);
return new (zone) StructType(field_count, offsets, fields, mutabilities); return zone->New<StructType>(field_count, offsets, fields, mutabilities);
} }
const ArrayType* consume_array(Zone* zone) { const ArrayType* consume_array(Zone* zone) {
...@@ -1870,7 +1870,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1870,7 +1870,7 @@ class ModuleDecoderImpl : public Decoder {
if (!mutability) { if (!mutability) {
error(this->pc() - 1, "immutable arrays are not supported yet"); error(this->pc() - 1, "immutable arrays are not supported yet");
} }
return new (zone) ArrayType(field, mutability); return zone->New<ArrayType>(field, mutability);
} }
// Consume the attribute field of an exception. // Consume the attribute field of an exception.
......
...@@ -96,8 +96,8 @@ class StructType : public ZoneObject { ...@@ -96,8 +96,8 @@ class StructType : public ZoneObject {
StructType* Build() { StructType* Build() {
DCHECK_EQ(cursor_, field_count_); DCHECK_EQ(cursor_, field_count_);
uint32_t* offsets = zone_->NewArray<uint32_t>(field_count_); uint32_t* offsets = zone_->NewArray<uint32_t>(field_count_);
return new (zone_) return zone_->New<StructType>(field_count_, offsets, buffer_,
StructType(field_count_, offsets, buffer_, mutabilities_); mutabilities_);
} }
private: private:
......
...@@ -256,7 +256,7 @@ WasmModuleBuilder::WasmModuleBuilder(Zone* zone) ...@@ -256,7 +256,7 @@ WasmModuleBuilder::WasmModuleBuilder(Zone* zone)
has_shared_memory_(false) {} has_shared_memory_(false) {}
WasmFunctionBuilder* WasmModuleBuilder::AddFunction(FunctionSig* sig) { WasmFunctionBuilder* WasmModuleBuilder::AddFunction(FunctionSig* sig) {
functions_.push_back(new (zone_) WasmFunctionBuilder(this)); functions_.push_back(zone_->New<WasmFunctionBuilder>(this));
// Add the signature if one was provided here. // Add the signature if one was provided here.
if (sig) functions_.back()->SetSignature(sig); if (sig) functions_.back()->SetSignature(sig);
return functions_.back(); return functions_.back();
......
...@@ -22,9 +22,12 @@ namespace wasm { ...@@ -22,9 +22,12 @@ namespace wasm {
class ZoneBuffer : public ZoneObject { class ZoneBuffer : public ZoneObject {
public: public:
// This struct is just a type tag for Zone::NewArray<T>(size_t) call.
struct Buffer {};
static constexpr size_t kInitialSize = 1024; static constexpr size_t kInitialSize = 1024;
explicit ZoneBuffer(Zone* zone, size_t initial = kInitialSize) explicit ZoneBuffer(Zone* zone, size_t initial = kInitialSize)
: zone_(zone), buffer_(reinterpret_cast<byte*>(zone->New(initial))) { : zone_(zone), buffer_(zone->NewArray<byte, Buffer>(initial)) {
pos_ = buffer_; pos_ = buffer_;
end_ = buffer_ + initial; end_ = buffer_ + initial;
} }
...@@ -130,7 +133,7 @@ class ZoneBuffer : public ZoneObject { ...@@ -130,7 +133,7 @@ class ZoneBuffer : public ZoneObject {
void EnsureSpace(size_t size) { void EnsureSpace(size_t size) {
if ((pos_ + size) > end_) { if ((pos_ + size) > end_) {
size_t new_size = size + (end_ - buffer_) * 2; size_t new_size = size + (end_ - buffer_) * 2;
byte* new_buffer = reinterpret_cast<byte*>(zone_->New(new_size)); byte* new_buffer = zone_->NewArray<byte, Buffer>(new_size);
memcpy(new_buffer, buffer_, (pos_ - buffer_)); memcpy(new_buffer, buffer_, (pos_ - buffer_));
pos_ = new_buffer + (pos_ - buffer_); pos_ = new_buffer + (pos_ - buffer_);
buffer_ = new_buffer; buffer_ = new_buffer;
...@@ -203,6 +206,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { ...@@ -203,6 +206,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
private: private:
explicit WasmFunctionBuilder(WasmModuleBuilder* builder); explicit WasmFunctionBuilder(WasmModuleBuilder* builder);
friend class WasmModuleBuilder; friend class WasmModuleBuilder;
friend Zone;
struct DirectCallIndex { struct DirectCallIndex {
size_t offset; size_t offset;
......
...@@ -1920,7 +1920,7 @@ const wasm::FunctionSig* WasmJSFunction::GetSignature(Zone* zone) { ...@@ -1920,7 +1920,7 @@ const wasm::FunctionSig* WasmJSFunction::GetSignature(Zone* zone) {
} }
int return_count = function_data.serialized_return_count(); int return_count = function_data.serialized_return_count();
int parameter_count = function_data.serialized_parameter_count(); int parameter_count = function_data.serialized_parameter_count();
return new (zone) wasm::FunctionSig(return_count, parameter_count, types); return zone->New<wasm::FunctionSig>(return_count, parameter_count, types);
} }
bool WasmJSFunction::MatchesSignature(const wasm::FunctionSig* sig) { bool WasmJSFunction::MatchesSignature(const wasm::FunctionSig* sig) {
......
...@@ -68,8 +68,7 @@ class WasmGCTester { ...@@ -68,8 +68,7 @@ class WasmGCTester {
} }
uint32_t DefineArray(ValueType element_type, bool mutability) { uint32_t DefineArray(ValueType element_type, bool mutability) {
return builder_.AddArrayType(new (&zone) return builder_.AddArrayType(zone.New<ArrayType>(element_type, mutability));
ArrayType(element_type, mutability));
} }
void CompileModule() { void CompileModule() {
......
...@@ -80,7 +80,7 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) { ...@@ -80,7 +80,7 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(6)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(6)), WASM_DROP,
......
...@@ -145,8 +145,8 @@ class LiftoffCompileEnvironment { ...@@ -145,8 +145,8 @@ class LiftoffCompileEnvironment {
std::copy(return_types.begin(), return_types.end(), storage); std::copy(return_types.begin(), return_types.end(), storage);
std::copy(param_types.begin(), param_types.end(), std::copy(param_types.begin(), param_types.end(),
storage + return_types.size()); storage + return_types.size());
FunctionSig* sig = new (&zone_) FunctionSig* sig = zone_.New<FunctionSig>(return_types.size(),
FunctionSig{return_types.size(), param_types.size(), storage}; param_types.size(), storage);
module_builder_.AddSignature(sig); module_builder_.AddSignature(sig);
return sig; return sig;
} }
......
...@@ -84,7 +84,7 @@ TEST(Run_WasmModule_Return114) { ...@@ -84,7 +84,7 @@ TEST(Run_WasmModule_Return114) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
...@@ -105,7 +105,7 @@ TEST(Run_WasmModule_CompilationHintsLazy) { ...@@ -105,7 +105,7 @@ TEST(Run_WasmModule_CompilationHintsLazy) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
// Build module with one lazy function. // Build module with one lazy function.
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
...@@ -166,7 +166,7 @@ TEST(Run_WasmModule_CompilationHintsNoTiering) { ...@@ -166,7 +166,7 @@ TEST(Run_WasmModule_CompilationHintsNoTiering) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
// Build module with regularly compiled function (no tiering). // Build module with regularly compiled function (no tiering).
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
...@@ -212,7 +212,7 @@ TEST(Run_WasmModule_CompilationHintsTierUp) { ...@@ -212,7 +212,7 @@ TEST(Run_WasmModule_CompilationHintsTierUp) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
// Build module with tiering compilation hint. // Build module with tiering compilation hint.
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
...@@ -277,7 +277,7 @@ TEST(Run_WasmModule_CompilationHintsLazyBaselineEagerTopTier) { ...@@ -277,7 +277,7 @@ TEST(Run_WasmModule_CompilationHintsLazyBaselineEagerTopTier) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
// Build module with tiering compilation hint. // Build module with tiering compilation hint.
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
...@@ -329,7 +329,7 @@ TEST(Run_WasmModule_CallAdd) { ...@@ -329,7 +329,7 @@ TEST(Run_WasmModule_CallAdd) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii());
uint16_t param1 = 0; uint16_t param1 = 0;
...@@ -356,7 +356,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) { ...@@ -356,7 +356,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
...@@ -377,7 +377,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { ...@@ -377,7 +377,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
uint16_t localIndex = f->AddLocal(kWasmI32); uint16_t localIndex = f->AddLocal(kWasmI32);
...@@ -402,7 +402,7 @@ TEST(Run_WasmModule_CallMain_recursive) { ...@@ -402,7 +402,7 @@ TEST(Run_WasmModule_CallMain_recursive) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
uint16_t localIndex = f->AddLocal(kWasmI32); uint16_t localIndex = f->AddLocal(kWasmI32);
...@@ -427,7 +427,7 @@ TEST(Run_WasmModule_Global) { ...@@ -427,7 +427,7 @@ TEST(Run_WasmModule_Global) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
uint32_t global1 = builder->AddGlobal(kWasmI32); uint32_t global1 = builder->AddGlobal(kWasmI32);
uint32_t global2 = builder->AddGlobal(kWasmI32); uint32_t global2 = builder->AddGlobal(kWasmI32);
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
...@@ -453,7 +453,7 @@ TEST(MemorySize) { ...@@ -453,7 +453,7 @@ TEST(MemorySize) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_MEMORY_SIZE}; byte code[] = {WASM_MEMORY_SIZE};
...@@ -471,7 +471,7 @@ TEST(Run_WasmModule_MemSize_GrowMem) { ...@@ -471,7 +471,7 @@ TEST(Run_WasmModule_MemSize_GrowMem) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP,
...@@ -490,7 +490,7 @@ TEST(MemoryGrowZero) { ...@@ -490,7 +490,7 @@ TEST(MemoryGrowZero) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))};
...@@ -553,7 +553,7 @@ TEST(TestInterruptLoop) { ...@@ -553,7 +553,7 @@ TEST(TestInterruptLoop) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = { byte code[] = {
...@@ -597,7 +597,7 @@ TEST(Run_WasmModule_MemoryGrowInIf) { ...@@ -597,7 +597,7 @@ TEST(Run_WasmModule_MemoryGrowInIf) {
TestSignatures sigs; TestSignatures sigs;
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
...@@ -618,7 +618,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) { ...@@ -618,7 +618,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)),
...@@ -640,7 +640,7 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) { ...@@ -640,7 +640,7 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) {
Isolate* isolate = CcTest::InitIsolateOnce(); Isolate* isolate = CcTest::InitIsolateOnce();
Zone zone(isolate->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
...@@ -687,7 +687,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) { ...@@ -687,7 +687,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP,
...@@ -742,7 +742,7 @@ TEST(Run_WasmModule_Global_init) { ...@@ -742,7 +742,7 @@ TEST(Run_WasmModule_Global_init) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
TestSignatures sigs; TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
uint32_t global1 = uint32_t global1 =
builder->AddGlobal(kWasmI32, false, WasmInitExpr(777777)); builder->AddGlobal(kWasmI32, false, WasmInitExpr(777777));
uint32_t global2 = uint32_t global2 =
...@@ -769,7 +769,7 @@ static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) { ...@@ -769,7 +769,7 @@ static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) {
for (int padding = 0; padding < 5; padding++) { for (int padding = 0; padding < 5; padding++) {
// Test with a simple initializer // Test with a simple initializer
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
for (int i = 0; i < padding; i++) { // pad global before for (int i = 0; i < padding; i++) { // pad global before
builder->AddGlobal(kWasmI32, false, WasmInitExpr(i + 20000)); builder->AddGlobal(kWasmI32, false, WasmInitExpr(i + 20000));
......
...@@ -54,7 +54,7 @@ using CallbackFn = bool (*)(Local<v8::Context>, Local<v8::String>); ...@@ -54,7 +54,7 @@ using CallbackFn = bool (*)(Local<v8::Context>, Local<v8::String>);
CallbackFn Callback[kNumTestValues] = {nullptr, FalseCallback, TrueCallback}; CallbackFn Callback[kNumTestValues] = {nullptr, FalseCallback, TrueCallback};
void BuildTrivialModule(Zone* zone, ZoneBuffer* buffer) { void BuildTrivialModule(Zone* zone, ZoneBuffer* buffer) {
WasmModuleBuilder* builder = new (zone) WasmModuleBuilder(zone); WasmModuleBuilder* builder = zone->New<WasmModuleBuilder>(zone);
builder->WriteTo(buffer); builder->WriteTo(buffer);
} }
......
...@@ -37,7 +37,7 @@ class WasmSerializationTest { ...@@ -37,7 +37,7 @@ class WasmSerializationTest {
} }
static void BuildWireBytes(Zone* zone, ZoneBuffer* buffer) { static void BuildWireBytes(Zone* zone, ZoneBuffer* buffer) {
WasmModuleBuilder* builder = new (zone) WasmModuleBuilder(zone); WasmModuleBuilder* builder = zone->New<WasmModuleBuilder>(zone);
TestSignatures sigs; TestSignatures sigs;
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
......
...@@ -132,8 +132,8 @@ namespace { ...@@ -132,8 +132,8 @@ namespace {
ZoneBuffer* BuildReturnConstantModule(Zone* zone, int constant) { ZoneBuffer* BuildReturnConstantModule(Zone* zone, int constant) {
TestSignatures sigs; TestSignatures sigs;
ZoneBuffer* buffer = new (zone) ZoneBuffer(zone); ZoneBuffer* buffer = zone->New<ZoneBuffer>(zone);
WasmModuleBuilder* builder = new (zone) WasmModuleBuilder(zone); WasmModuleBuilder* builder = zone->New<WasmModuleBuilder>(zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
f->builder()->AddExport(CStrVector("main"), f); f->builder()->AddExport(CStrVector("main"), f);
byte code[] = {WASM_I32V_2(constant)}; byte code[] = {WASM_I32V_2(constant)};
......
...@@ -501,7 +501,7 @@ Handle<Code> WasmFunctionWrapper::GetWrapperCode() { ...@@ -501,7 +501,7 @@ Handle<Code> WasmFunctionWrapper::GetWrapperCode() {
void WasmFunctionCompiler::Build(const byte* start, const byte* end) { void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
size_t locals_size = local_decls.Size(); size_t locals_size = local_decls.Size();
size_t total_size = end - start + locals_size + 1; size_t total_size = end - start + locals_size + 1;
byte* buffer = static_cast<byte*>(zone()->New(total_size)); byte* buffer = zone()->NewArray<byte>(total_size);
// Prepend the local decls to the code. // Prepend the local decls to the code.
local_decls.Emit(buffer); local_decls.Emit(buffer);
// Emit the code. // Emit the code.
...@@ -588,7 +588,7 @@ FunctionSig* WasmRunnerBase::CreateSig(Zone* zone, MachineType return_type, ...@@ -588,7 +588,7 @@ FunctionSig* WasmRunnerBase::CreateSig(Zone* zone, MachineType return_type,
CHECK_NE(MachineType::None(), param); CHECK_NE(MachineType::None(), param);
sig_types[idx++] = ValueType::For(param); sig_types[idx++] = ValueType::For(param);
} }
return new (zone) FunctionSig(return_count, param_count, sig_types); return zone->New<FunctionSig>(return_count, param_count, sig_types);
} }
// static // static
......
...@@ -654,6 +654,8 @@ class SideTable : public ZoneObject { ...@@ -654,6 +654,8 @@ class SideTable : public ZoneObject {
// Represents a control flow label. // Represents a control flow label.
class CLabel : public ZoneObject { class CLabel : public ZoneObject {
friend Zone;
explicit CLabel(Zone* zone, int32_t target_stack_height, uint32_t arity) explicit CLabel(Zone* zone, int32_t target_stack_height, uint32_t arity)
: target_stack_height(target_stack_height), arity(arity), refs(zone) { : target_stack_height(target_stack_height), arity(arity), refs(zone) {
DCHECK_LE(0, target_stack_height); DCHECK_LE(0, target_stack_height);
...@@ -671,7 +673,7 @@ class SideTable : public ZoneObject { ...@@ -671,7 +673,7 @@ class SideTable : public ZoneObject {
ZoneVector<Ref> refs; ZoneVector<Ref> refs;
static CLabel* New(Zone* zone, int32_t stack_height, uint32_t arity) { static CLabel* New(Zone* zone, int32_t stack_height, uint32_t arity) {
return new (zone) CLabel(zone, stack_height, arity); return zone->New<CLabel>(zone, stack_height, arity);
} }
// Bind this label to the given PC. // Bind this label to the given PC.
...@@ -1014,7 +1016,7 @@ class CodeMap { ...@@ -1014,7 +1016,7 @@ class CodeMap {
DCHECK_EQ(code->function->imported, code->start == nullptr); DCHECK_EQ(code->function->imported, code->start == nullptr);
if (!code->side_table && code->start) { if (!code->side_table && code->start) {
// Compute the control targets map and the local declarations. // Compute the control targets map and the local declarations.
code->side_table = new (zone_) SideTable(zone_, module_, code); code->side_table = zone_->New<SideTable>(zone_, module_, code);
} }
return code; return code;
} }
......
...@@ -131,8 +131,7 @@ class TestModuleBuilder { ...@@ -131,8 +131,7 @@ class TestModuleBuilder {
} }
byte AddArray(ValueType type, bool mutability) { byte AddArray(ValueType type, bool mutability) {
ArrayType* array = ArrayType* array = mod.signature_zone->New<ArrayType>(type, mutability);
new (mod.signature_zone.get()) ArrayType(type, mutability);
mod.add_array_type(array); mod.add_array_type(array);
return static_cast<byte>(mod.type_kinds.size() - 1); return static_cast<byte>(mod.type_kinds.size() - 1);
} }
...@@ -205,7 +204,7 @@ class FunctionBodyDecoderTest : public TestWithZone { ...@@ -205,7 +204,7 @@ class FunctionBodyDecoderTest : public TestWithZone {
size_t locals_size = local_decls.Size(); size_t locals_size = local_decls.Size();
size_t total_size = size_t total_size =
code.size() + locals_size + (append_end == kAppendEnd ? 1 : 0); code.size() + locals_size + (append_end == kAppendEnd ? 1 : 0);
byte* buffer = static_cast<byte*>(zone()->New(total_size)); byte* buffer = zone()->NewArray<byte>(total_size);
// Prepend the local decls to the code. // Prepend the local decls to the code.
local_decls.Emit(buffer); local_decls.Emit(buffer);
// Emit the code. // Emit the code.
......
...@@ -29,7 +29,7 @@ void DefineStruct(WasmModule* module, std::initializer_list<FieldInit> fields) { ...@@ -29,7 +29,7 @@ void DefineStruct(WasmModule* module, std::initializer_list<FieldInit> fields) {
} }
void DefineArray(WasmModule* module, FieldInit element_type) { void DefineArray(WasmModule* module, FieldInit element_type) {
module->add_array_type(new (module->signature_zone.get()) ArrayType( module->add_array_type(module->signature_zone->New<ArrayType>(
element_type.first, element_type.second)); element_type.first, element_type.second));
} }
......
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