Commit ea2460e2 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[heap] Make AllocationStats methods const

Adds const modifiers to several methods and their parameters in
AllocationStats, BasicMemoryChunk and ReadOnlySpace.

Also moves BasicMemoryChunk::OffsetToAddress to ReadOnlyPage.

Bug: v8:10454
Change-Id: Ibda8f9212d95dff71ed1d8f1f985eb1c7e6087aa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2284986
Commit-Queue: Dan Elphick <delphick@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Auto-Submit: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68721}
parent 6e6f6d09
......@@ -49,16 +49,16 @@ class AllocationStats {
}
// Accessors for the allocation statistics.
size_t Capacity() { return capacity_; }
size_t MaxCapacity() { return max_capacity_; }
size_t Size() { return size_; }
size_t Capacity() const { return capacity_; }
size_t MaxCapacity() const { return max_capacity_; }
size_t Size() const { return size_; }
#ifdef DEBUG
size_t AllocatedOnPage(BasicMemoryChunk* page) {
return allocated_on_page_[page];
size_t AllocatedOnPage(const BasicMemoryChunk* page) const {
return allocated_on_page_.at(page);
}
#endif
void IncreaseAllocatedBytes(size_t bytes, BasicMemoryChunk* page) {
void IncreaseAllocatedBytes(size_t bytes, const BasicMemoryChunk* page) {
#ifdef DEBUG
size_t size = size_;
DCHECK_GE(size + bytes, size);
......@@ -69,7 +69,7 @@ class AllocationStats {
#endif
}
void DecreaseAllocatedBytes(size_t bytes, BasicMemoryChunk* page) {
void DecreaseAllocatedBytes(size_t bytes, const BasicMemoryChunk* page) {
DCHECK_GE(size_, bytes);
size_.fetch_sub(bytes);
#ifdef DEBUG
......@@ -106,7 +106,7 @@ class AllocationStats {
std::atomic<size_t> size_;
#ifdef DEBUG
std::unordered_map<BasicMemoryChunk*, size_t, BasicMemoryChunk::Hasher>
std::unordered_map<const BasicMemoryChunk*, size_t, BasicMemoryChunk::Hasher>
allocated_on_page_;
#endif
};
......
......@@ -24,7 +24,7 @@ class BasicMemoryChunk {
public:
// Use with std data structures.
struct Hasher {
size_t operator()(BasicMemoryChunk* const chunk) const {
size_t operator()(const BasicMemoryChunk* const chunk) const {
return reinterpret_cast<size_t>(chunk) >> kPageSizeBits;
}
};
......@@ -116,14 +116,6 @@ class BasicMemoryChunk {
// Returns the offset of a given address to this page.
inline size_t Offset(Address a) { return static_cast<size_t>(a - address()); }
// Returns the address for a given offset to the this page.
Address OffsetToAddress(size_t offset) {
Address address_in_page = address() + offset;
DCHECK_GE(address_in_page, area_start());
DCHECK_LT(address_in_page, area_end());
return address_in_page;
}
// Some callers rely on the fact that this can operate on both
// tagged and aligned object addresses.
inline uint32_t AddressToMarkbitIndex(Address addr) const {
......@@ -269,9 +261,9 @@ class BasicMemoryChunk {
BaseSpace* owner,
VirtualMemory reservation);
size_t wasted_memory() { return wasted_memory_; }
size_t wasted_memory() const { return wasted_memory_; }
void add_wasted_memory(size_t waste) { wasted_memory_ += waste; }
size_t allocated_bytes() { return allocated_bytes_; }
size_t allocated_bytes() const { return allocated_bytes_; }
static const intptr_t kSizeOffset = 0;
static const intptr_t kFlagsOffset = kSizeOffset + kSizetSize;
......
......@@ -31,6 +31,21 @@ class ReadOnlyPage : public BasicMemoryChunk {
size_t ShrinkToHighWaterMark();
// Returns the address for a given offset in this page.
Address OffsetToAddress(size_t offset) const {
Address address_in_page = address() + offset;
if (V8_SHARED_RO_HEAP_BOOL && COMPRESS_POINTERS_BOOL) {
// Pointer compression with share ReadOnlyPages means that the area_start
// and area_end cannot be defined since they are stored within the pages
// which can be mapped at multiple memory addresses.
DCHECK_LT(offset, size());
} else {
DCHECK_GE(address_in_page, area_start());
DCHECK_LT(address_in_page, area_end());
}
return address_in_page;
}
private:
friend class ReadOnlySpace;
};
......@@ -123,7 +138,7 @@ class ReadOnlySpace : public BaseSpace {
#endif // VERIFY_HEAP
// Return size of allocatable area on a page in this space.
int AreaSize() { return static_cast<int>(area_size_); }
int AreaSize() const { return static_cast<int>(area_size_); }
ReadOnlyPage* InitializePage(BasicMemoryChunk* chunk);
......
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