Fixed zapping of contents
BUG= Review-Url: https://codereview.chromium.org/2377943003 Cr-Commit-Position: refs/heads/master@{#39946}
This commit is contained in:
parent
a87f0cfa7c
commit
ae18e6cd8e
1
BUILD.gn
1
BUILD.gn
@ -1706,6 +1706,7 @@ v8_source_set("v8_base") {
|
||||
"src/zone/zone-allocator.h",
|
||||
"src/zone/zone-allocator.h",
|
||||
"src/zone/zone-containers.h",
|
||||
"src/zone/zone-segment.cc",
|
||||
"src/zone/zone-segment.h",
|
||||
"src/zone/zone.cc",
|
||||
"src/zone/zone.h",
|
||||
|
@ -1273,6 +1273,7 @@
|
||||
'wasm/wasm-result.h',
|
||||
'zone/accounting-allocator.cc',
|
||||
'zone/accounting-allocator.h',
|
||||
'zone/zone-segment.cc',
|
||||
'zone/zone-segment.h',
|
||||
'zone/zone.cc',
|
||||
'zone/zone.h',
|
||||
|
@ -29,6 +29,7 @@ Segment* AccountingAllocator::AllocateSegment(size_t bytes) {
|
||||
void AccountingAllocator::FreeSegment(Segment* memory) {
|
||||
base::NoBarrier_AtomicIncrement(
|
||||
¤t_memory_usage_, -static_cast<base::AtomicWord>(memory->size()));
|
||||
memory->ZapHeader();
|
||||
free(memory);
|
||||
}
|
||||
|
||||
|
22
src/zone/zone-segment.cc
Normal file
22
src/zone/zone-segment.cc
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/zone/zone-segment.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
void Segment::ZapContents() {
|
||||
#ifdef DEBUG
|
||||
memset(start(), kZapDeadByte, capacity());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Segment::ZapHeader() {
|
||||
#ifdef DEBUG
|
||||
memset(this, kZapDeadByte, sizeof(Segment));
|
||||
#endif
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace v8
|
@ -38,7 +38,16 @@ class Segment {
|
||||
Address start() const { return address(sizeof(Segment)); }
|
||||
Address end() const { return address(size_); }
|
||||
|
||||
// Zap the contents of the segment (but not the header).
|
||||
void ZapContents();
|
||||
// Zaps the header and makes the segment unusable this way.
|
||||
void ZapHeader();
|
||||
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
// Constant byte value used for zapping dead memory in debug mode.
|
||||
static const unsigned char kZapDeadByte = 0xcd;
|
||||
#endif
|
||||
// Computes the address of the nth byte in this segment.
|
||||
Address address(size_t n) const { return Address(this) + n; }
|
||||
|
||||
|
@ -92,11 +92,6 @@ void* Zone::New(size_t size) {
|
||||
}
|
||||
|
||||
void Zone::DeleteAll() {
|
||||
#ifdef DEBUG
|
||||
// Constant byte value used for zapping dead memory in debug mode.
|
||||
static const unsigned char kZapDeadByte = 0xcd;
|
||||
#endif
|
||||
|
||||
// Find a segment with a suitable size to keep around.
|
||||
Segment* keep = nullptr;
|
||||
// Traverse the chained list of segments, zapping (in debug mode)
|
||||
@ -112,9 +107,8 @@ void Zone::DeleteAll() {
|
||||
#ifdef DEBUG
|
||||
// Un-poison first so the zapping doesn't trigger ASan complaints.
|
||||
ASAN_UNPOISON_MEMORY_REGION(current, size);
|
||||
// Zap the entire current segment (including the header).
|
||||
memset(current, kZapDeadByte, size);
|
||||
#endif
|
||||
current->ZapContents();
|
||||
segment_bytes_allocated_ -= size;
|
||||
allocator_->FreeSegment(current);
|
||||
}
|
||||
@ -131,10 +125,7 @@ void Zone::DeleteAll() {
|
||||
limit_ = keep->end();
|
||||
// Un-poison so we can re-use the segment later.
|
||||
ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity());
|
||||
#ifdef DEBUG
|
||||
// Zap the contents of the kept segment (but not the header).
|
||||
memset(start, kZapDeadByte, keep->capacity());
|
||||
#endif
|
||||
keep->ZapContents();
|
||||
} else {
|
||||
position_ = limit_ = 0;
|
||||
}
|
||||
@ -145,20 +136,14 @@ void Zone::DeleteAll() {
|
||||
}
|
||||
|
||||
void Zone::DeleteKeptSegment() {
|
||||
#ifdef DEBUG
|
||||
// Constant byte value used for zapping dead memory in debug mode.
|
||||
static const unsigned char kZapDeadByte = 0xcd;
|
||||
#endif
|
||||
|
||||
DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr);
|
||||
if (segment_head_ != nullptr) {
|
||||
size_t size = segment_head_->size();
|
||||
#ifdef DEBUG
|
||||
// Un-poison first so the zapping doesn't trigger ASan complaints.
|
||||
ASAN_UNPOISON_MEMORY_REGION(segment_head_, size);
|
||||
// Zap the entire kept segment (including the header).
|
||||
memset(segment_head_, kZapDeadByte, size);
|
||||
#endif
|
||||
segment_head_->ZapContents();
|
||||
segment_bytes_allocated_ -= size;
|
||||
allocator_->FreeSegment(segment_head_);
|
||||
segment_head_ = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user