Commit 59bed933 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[zone] Simplify and inline Zone::New

This separates the fast-non-asan path from the asan path so it can be inlined.
Additionally avoid updating allocation_size_ on each Zone::New call.
Inlining Zone::New actually reduces binary size by 50kb...

Change-Id: Ie5d58638284e5a1a5e0198c24080b0f600d79092
Reviewed-on: https://chromium-review.googlesource.com/c/1288641Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56780}
parent c7328012
......@@ -48,7 +48,7 @@ Zone::~Zone() {
DCHECK_EQ(segment_bytes_allocated_, 0);
}
void* Zone::New(size_t size) {
void* Zone::AsanNew(size_t size) {
CHECK(!sealed_);
// Round up the requested size to fit the alignment.
......@@ -58,7 +58,7 @@ void* Zone::New(size_t size) {
Address result = position_;
const size_t size_with_redzone = size + kASanRedzoneBytes;
DCHECK(limit_ >= position_);
DCHECK_LE(position_, limit_);
if (size_with_redzone > limit_ - position_) {
result = NewExpand(size_with_redzone);
} else {
......@@ -72,7 +72,6 @@ void* Zone::New(size_t size) {
// Check that the result has the proper alignment and return it.
DCHECK(IsAligned(result, kAlignmentInBytes));
allocation_size_ += size;
return reinterpret_cast<void*>(result);
}
......@@ -122,6 +121,8 @@ Address Zone::NewExpand(size_t size) {
DCHECK_EQ(size, RoundDown(size, kAlignmentInBytes));
DCHECK(limit_ - position_ < size);
// Commit the allocation_size_ of segment_head_ if any.
allocation_size_ = allocation_size();
// Compute the new segment size. We use a 'high water mark'
// strategy, where we increase the segment size every time we expand
// except that we employ a maximum segment size when we delete. This
......
......@@ -47,7 +47,21 @@ class V8_EXPORT_PRIVATE Zone final {
// Allocate 'size' bytes of memory in the Zone; expands the Zone by
// allocating new segments of memory on demand using malloc().
void* New(size_t size);
void* New(size_t size) {
#ifdef V8_USE_ADDRESS_SANITIZER
return AsanNew(size);
#else
size = RoundUp(size, kAlignmentInBytes);
Address result = position_;
if (V8_UNLIKELY(size > limit_ - position_)) {
result = NewExpand(size);
} else {
position_ += size;
}
return reinterpret_cast<void*>(result);
#endif
}
void* AsanNew(size_t size);
template <typename T>
T* NewArray(size_t length) {
......@@ -70,7 +84,10 @@ class V8_EXPORT_PRIVATE Zone final {
const char* name() const { return name_; }
size_t allocation_size() const { return allocation_size_; }
size_t allocation_size() const {
size_t extra = segment_head_ ? position_ - segment_head_->start() : 0;
return allocation_size_ + extra;
}
AccountingAllocator* allocator() const { return allocator_; }
......
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