Skip to content

Commit 89e0902

Browse files
backesCommit Bot
authored andcommitted
[codegen] Reduce kMinimalBufferSize and add kDefaultBufferSize
In Liftoff, we have a good estimate about how big the generated code might get. Also, we often compile hundreds of functions which each hold an assembler buffer alive until we finally add that code to the wasm module. In order to reduce memory consumption in Liftoff, this CL reduces {AssemblerBase::kMinimalBufferSize} from 4096 to 128, and adds {AssemblerBase::kDefaultBufferSize} to be used instead. R=jkummerow@chromium.org Change-Id: I7029bf501244770f4824a86b233d7f99c4b7910b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1914559 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#64958}
1 parent 315c416 commit 89e0902

15 files changed

Lines changed: 24 additions & 9 deletions

src/codegen/arm/assembler-arm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
11981198
// not have to check for overflow. The same is true for writes of large
11991199
// relocation info entries.
12001200
static constexpr int kGap = 32;
1201+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
12011202

12021203
// Relocation info generation
12031204
// Each relocation is encoded as a variable size value

src/codegen/arm64/assembler-arm64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
26392639
// relocation info entries, and debug strings encoded in the instruction
26402640
// stream.
26412641
static constexpr int kGap = 64;
2642+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
26422643

26432644
public:
26442645
#ifdef DEBUG

src/codegen/assembler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ AssemblerBase::AssemblerBase(const AssemblerOptions& options,
140140
predictable_code_size_(false),
141141
constant_pool_available_(false),
142142
jump_optimization_info_(nullptr) {
143-
if (!buffer_) buffer_ = NewAssemblerBuffer(kMinimalBufferSize);
143+
if (!buffer_) buffer_ = NewAssemblerBuffer(kDefaultBufferSize);
144144
buffer_start_ = buffer_->start();
145145
pc_ = buffer_start_;
146146
}

src/codegen/assembler.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
271271
}
272272
}
273273

274-
static const int kMinimalBufferSize = 4 * KB;
274+
// The minimum buffer size. Should be at least two times the platform-specific
275+
// {Assembler::kGap}.
276+
static constexpr int kMinimalBufferSize = 128;
277+
278+
// The default buffer size used if we do not know the final size of the
279+
// generated code.
280+
static constexpr int kDefaultBufferSize = 4 * KB;
275281

276282
protected:
277283
// Add 'target' to the {code_targets_} vector, if necessary, and return the

src/codegen/ia32/assembler-ia32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
361361
// otherwise valid instructions.)
362362
// This allows for a single, fast space check per instruction.
363363
static constexpr int kGap = 32;
364+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
364365

365366
public:
366367
// Create an assembler. Instructions and relocation information are emitted

src/codegen/mips/assembler-mips.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
16101610
// not have to check for overflow. The same is true for writes of large
16111611
// relocation info entries.
16121612
static constexpr int kGap = 32;
1613+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
16131614

16141615
// Repeated checking whether the trampoline pool should be emitted is rather
16151616
// expensive. By default we only check again once a number of instructions

src/codegen/mips64/assembler-mips64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
16431643
// not have to check for overflow. The same is true for writes of large
16441644
// relocation info entries.
16451645
static constexpr int kGap = 64;
1646+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
16461647

16471648
// Repeated checking whether the trampoline pool should be emitted is rather
16481649
// expensive. By default we only check again once a number of instructions

src/codegen/ppc/assembler-ppc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ class Assembler : public AssemblerBase {
11581158
// not have to check for overflow. The same is true for writes of large
11591159
// relocation info entries.
11601160
static constexpr int kGap = 32;
1161+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
11611162

11621163
RelocInfoWriter reloc_info_writer;
11631164

src/codegen/s390/assembler-s390.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
13841384
// not have to check for overflow. The same is true for writes of large
13851385
// relocation info entries.
13861386
static constexpr int kGap = 32;
1387+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
13871388

13881389
// Relocation info generation
13891390
// Each relocation is encoded as a variable size value

src/codegen/x64/assembler-x64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
317317
// otherwise valid instructions.)
318318
// This allows for a single, fast space check per instruction.
319319
static constexpr int kGap = 32;
320+
STATIC_ASSERT(AssemblerBase::kMinimalBufferSize >= 2 * kGap);
320321

321322
public:
322323
// Create an assembler. Instructions and relocation information are emitted

0 commit comments

Comments
 (0)