Skip to content

Commit 295ee7e

Browse files
isheludkoCommit Bot
authored andcommitted
[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: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#68789}
1 parent 734ea68 commit 295ee7e

20 files changed

Lines changed: 62 additions & 55 deletions

src/wasm/baseline/liftoff-compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ class LiftoffCompiler {
19051905
// If we are generating debugging code, we really need to spill all
19061906
// registers to make them inspectable when stopping at the trap.
19071907
auto* spilled =
1908-
new (compilation_zone_) SpilledRegistersBeforeTrap(compilation_zone_);
1908+
compilation_zone_->New<SpilledRegistersBeforeTrap>(compilation_zone_);
19091909
for (uint32_t i = 0, e = __ cache_state()->stack_height(); i < e; ++i) {
19101910
auto& slot = __ cache_state()->stack_state[i];
19111911
if (!slot.is_reg()) continue;

src/wasm/function-body-decoder-impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ class WasmDecoder : public Decoder {
10721072

10731073
// The number of locals_count is augmented by 2 so that 'locals_count - 2'
10741074
// can be used to track mem_size, and 'locals_count - 1' to track mem_start.
1075-
BitVector* assigned = new (zone) BitVector(locals_count, zone);
1075+
BitVector* assigned = zone->New<BitVector>(locals_count, zone);
10761076
int depth = 0;
10771077
// Iteratively process all AST nodes nested inside the loop.
10781078
while (pc < decoder->end() && VALIDATE(decoder->ok())) {

src/wasm/graph-builder-interface.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class WasmGraphBuildingInterface {
118118
TFNode* start = builder_->Start(
119119
static_cast<int>(decoder->sig_->parameter_count() + 1 + 1));
120120
uint32_t num_locals = decoder->num_locals();
121-
SsaEnv* ssa_env = new (decoder->zone())
122-
SsaEnv(decoder->zone(), SsaEnv::kReached, start, start, num_locals);
121+
SsaEnv* ssa_env = decoder->zone()->New<SsaEnv>(
122+
decoder->zone(), SsaEnv::kReached, start, start, num_locals);
123123

124124
// Initialize effect and control before initializing the locals default
125125
// values (which might require instance loads) or loading the context.
@@ -189,7 +189,7 @@ class WasmGraphBuildingInterface {
189189
catch_env->state = SsaEnv::kUnreachable;
190190
SsaEnv* try_env = Steal(decoder->zone(), outer_env);
191191
SetEnv(try_env);
192-
TryInfo* try_info = new (decoder->zone()) TryInfo(catch_env);
192+
TryInfo* try_info = decoder->zone()->New<TryInfo>(catch_env);
193193
block->end_env = outer_env;
194194
block->try_info = try_info;
195195
block->previous_catch = current_catch_;
@@ -1026,7 +1026,7 @@ class WasmGraphBuildingInterface {
10261026
ssa_env_->control = control();
10271027
ssa_env_->effect = effect();
10281028
}
1029-
SsaEnv* result = new (zone) SsaEnv(*from);
1029+
SsaEnv* result = zone->New<SsaEnv>(*from);
10301030
result->state = SsaEnv::kReached;
10311031
return result;
10321032
}
@@ -1039,14 +1039,14 @@ class WasmGraphBuildingInterface {
10391039
ssa_env_->control = control();
10401040
ssa_env_->effect = effect();
10411041
}
1042-
SsaEnv* result = new (zone) SsaEnv(std::move(*from));
1042+
SsaEnv* result = zone->New<SsaEnv>(std::move(*from));
10431043
result->state = SsaEnv::kReached;
10441044
return result;
10451045
}
10461046

10471047
// Create an unreachable environment.
10481048
SsaEnv* UnreachableEnv(Zone* zone) {
1049-
return new (zone) SsaEnv(zone, SsaEnv::kUnreachable, nullptr, nullptr, 0);
1049+
return zone->New<SsaEnv>(zone, SsaEnv::kUnreachable, nullptr, nullptr, 0);
10501050
}
10511051

10521052
void DoCall(FullDecoder* decoder, uint32_t table_index, TFNode* index_node,

src/wasm/local-decl-encoder.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ namespace v8 {
1111
namespace internal {
1212
namespace wasm {
1313

14+
// This struct is just a type tag for Zone::NewArray<T>(size_t) call.
15+
struct LocalDeclEncoderBuffer {};
16+
1417
void LocalDeclEncoder::Prepend(Zone* zone, const byte** start,
1518
const byte** end) const {
1619
size_t size = (*end - *start);
17-
byte* buffer = reinterpret_cast<byte*>(zone->New(Size() + size));
20+
byte* buffer = zone->NewArray<byte, LocalDeclEncoderBuffer>(Size() + size);
1821
size_t pos = Emit(buffer);
1922
if (size > 0) {
2023
memcpy(buffer + pos, *start, size);

src/wasm/module-decoder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ class ModuleDecoderImpl : public Decoder {
18411841
for (uint32_t i = 0; i < return_count; ++i) buffer[b++] = returns[i];
18421842
for (uint32_t i = 0; i < param_count; ++i) buffer[b++] = params[i];
18431843

1844-
return new (zone) FunctionSig(return_count, param_count, buffer);
1844+
return zone->New<FunctionSig>(return_count, param_count, buffer);
18451845
}
18461846

18471847
const StructType* consume_struct(Zone* zone) {
@@ -1859,7 +1859,7 @@ class ModuleDecoderImpl : public Decoder {
18591859
}
18601860
if (failed()) return nullptr;
18611861
uint32_t* offsets = zone->NewArray<uint32_t>(field_count);
1862-
return new (zone) StructType(field_count, offsets, fields, mutabilities);
1862+
return zone->New<StructType>(field_count, offsets, fields, mutabilities);
18631863
}
18641864

18651865
const ArrayType* consume_array(Zone* zone) {
@@ -1870,7 +1870,7 @@ class ModuleDecoderImpl : public Decoder {
18701870
if (!mutability) {
18711871
error(this->pc() - 1, "immutable arrays are not supported yet");
18721872
}
1873-
return new (zone) ArrayType(field, mutability);
1873+
return zone->New<ArrayType>(field, mutability);
18741874
}
18751875

18761876
// Consume the attribute field of an exception.

src/wasm/struct-types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class StructType : public ZoneObject {
9696
StructType* Build() {
9797
DCHECK_EQ(cursor_, field_count_);
9898
uint32_t* offsets = zone_->NewArray<uint32_t>(field_count_);
99-
return new (zone_)
100-
StructType(field_count_, offsets, buffer_, mutabilities_);
99+
return zone_->New<StructType>(field_count_, offsets, buffer_,
100+
mutabilities_);
101101
}
102102

103103
private:

src/wasm/wasm-module-builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ WasmModuleBuilder::WasmModuleBuilder(Zone* zone)
256256
has_shared_memory_(false) {}
257257

258258
WasmFunctionBuilder* WasmModuleBuilder::AddFunction(FunctionSig* sig) {
259-
functions_.push_back(new (zone_) WasmFunctionBuilder(this));
259+
functions_.push_back(zone_->New<WasmFunctionBuilder>(this));
260260
// Add the signature if one was provided here.
261261
if (sig) functions_.back()->SetSignature(sig);
262262
return functions_.back();

src/wasm/wasm-module-builder.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ namespace wasm {
2222

2323
class ZoneBuffer : public ZoneObject {
2424
public:
25+
// This struct is just a type tag for Zone::NewArray<T>(size_t) call.
26+
struct Buffer {};
27+
2528
static constexpr size_t kInitialSize = 1024;
2629
explicit ZoneBuffer(Zone* zone, size_t initial = kInitialSize)
27-
: zone_(zone), buffer_(reinterpret_cast<byte*>(zone->New(initial))) {
30+
: zone_(zone), buffer_(zone->NewArray<byte, Buffer>(initial)) {
2831
pos_ = buffer_;
2932
end_ = buffer_ + initial;
3033
}
@@ -130,7 +133,7 @@ class ZoneBuffer : public ZoneObject {
130133
void EnsureSpace(size_t size) {
131134
if ((pos_ + size) > end_) {
132135
size_t new_size = size + (end_ - buffer_) * 2;
133-
byte* new_buffer = reinterpret_cast<byte*>(zone_->New(new_size));
136+
byte* new_buffer = zone_->NewArray<byte, Buffer>(new_size);
134137
memcpy(new_buffer, buffer_, (pos_ - buffer_));
135138
pos_ = new_buffer + (pos_ - buffer_);
136139
buffer_ = new_buffer;
@@ -203,6 +206,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
203206
private:
204207
explicit WasmFunctionBuilder(WasmModuleBuilder* builder);
205208
friend class WasmModuleBuilder;
209+
friend Zone;
206210

207211
struct DirectCallIndex {
208212
size_t offset;

src/wasm/wasm-objects.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ const wasm::FunctionSig* WasmJSFunction::GetSignature(Zone* zone) {
19201920
}
19211921
int return_count = function_data.serialized_return_count();
19221922
int parameter_count = function_data.serialized_parameter_count();
1923-
return new (zone) wasm::FunctionSig(return_count, parameter_count, types);
1923+
return zone->New<wasm::FunctionSig>(return_count, parameter_count, types);
19241924
}
19251925

19261926
bool WasmJSFunction::MatchesSignature(const wasm::FunctionSig* sig) {

test/cctest/wasm/test-gc.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class WasmGCTester {
6868
}
6969

7070
uint32_t DefineArray(ValueType element_type, bool mutability) {
71-
return builder_.AddArrayType(new (&zone)
72-
ArrayType(element_type, mutability));
71+
return builder_.AddArrayType(zone.New<ArrayType>(element_type, mutability));
7372
}
7473

7574
void CompileModule() {

0 commit comments

Comments
 (0)