Commit 30f409c7 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[heap] Move BaseSpace into base-space.h

Bug: v8:10473
Change-Id: Ic53130ca5103ba219329f7b204b218bc021f07f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2252178Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68427}
parent 8bdce527
...@@ -2452,6 +2452,8 @@ v8_source_set("v8_base_without_compiler") { ...@@ -2452,6 +2452,8 @@ v8_source_set("v8_base_without_compiler") {
"src/heap/array-buffer-tracker.cc", "src/heap/array-buffer-tracker.cc",
"src/heap/array-buffer-tracker.h", "src/heap/array-buffer-tracker.h",
"src/heap/barrier.h", "src/heap/barrier.h",
"src/heap/base-space.cc",
"src/heap/base-space.h",
"src/heap/basic-memory-chunk.cc", "src/heap/basic-memory-chunk.cc",
"src/heap/basic-memory-chunk.h", "src/heap/basic-memory-chunk.h",
"src/heap/code-object-registry.cc", "src/heap/code-object-registry.cc",
......
...@@ -8463,7 +8463,7 @@ bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics, ...@@ -8463,7 +8463,7 @@ bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
i::Heap* heap = isolate->heap(); i::Heap* heap = isolate->heap();
i::AllocationSpace allocation_space = static_cast<i::AllocationSpace>(index); i::AllocationSpace allocation_space = static_cast<i::AllocationSpace>(index);
space_statistics->space_name_ = i::Heap::GetSpaceName(allocation_space); space_statistics->space_name_ = i::BaseSpace::GetSpaceName(allocation_space);
if (allocation_space == i::RO_SPACE) { if (allocation_space == i::RO_SPACE) {
if (V8_SHARED_RO_HEAP_BOOL) { if (V8_SHARED_RO_HEAP_BOOL) {
......
// Copyright 2020 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/heap/base-space.h"
namespace v8 {
namespace internal {
const char* BaseSpace::GetSpaceName(AllocationSpace space) {
switch (space) {
case NEW_SPACE:
return "new_space";
case OLD_SPACE:
return "old_space";
case MAP_SPACE:
return "map_space";
case CODE_SPACE:
return "code_space";
case LO_SPACE:
return "large_object_space";
case NEW_LO_SPACE:
return "new_large_object_space";
case CODE_LO_SPACE:
return "code_large_object_space";
case RO_SPACE:
return "read_only_space";
}
UNREACHABLE();
}
} // namespace internal
} // namespace v8
// Copyright 2020 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.
#ifndef V8_HEAP_BASE_SPACE_H_
#define V8_HEAP_BASE_SPACE_H_
#include <atomic>
#include "src/base/macros.h"
#include "src/common/globals.h"
#include "src/logging/log.h"
#include "src/utils/allocation.h"
namespace v8 {
namespace internal {
class Heap;
// ----------------------------------------------------------------------------
// BaseSpace is the abstract superclass for all allocation spaces.
class V8_EXPORT_PRIVATE BaseSpace : public Malloced {
public:
Heap* heap() const {
DCHECK_NOT_NULL(heap_);
return heap_;
}
AllocationSpace identity() { return id_; }
// Returns name of the space.
static const char* GetSpaceName(AllocationSpace space);
const char* name() { return GetSpaceName(id_); }
void AccountCommitted(size_t bytes) {
DCHECK_GE(committed_ + bytes, committed_);
committed_ += bytes;
if (committed_ > max_committed_) {
max_committed_ = committed_;
}
}
void AccountUncommitted(size_t bytes) {
DCHECK_GE(committed_, committed_ - bytes);
committed_ -= bytes;
}
// Return the total amount committed memory for this space, i.e., allocatable
// memory and page headers.
virtual size_t CommittedMemory() { return committed_; }
virtual size_t MaximumCommittedMemory() { return max_committed_; }
// Approximate amount of physical memory committed for this space.
virtual size_t CommittedPhysicalMemory() = 0;
// Returns allocated size.
virtual size_t Size() = 0;
protected:
BaseSpace(Heap* heap, AllocationSpace id)
: heap_(heap), id_(id), committed_(0), max_committed_(0) {}
// Even though this has no virtual functions, this ensures that pointers are
// stable through casting.
virtual ~BaseSpace() = default;
protected:
Heap* heap_;
AllocationSpace id_;
// Keeps track of committed memory in a space.
std::atomic<size_t> committed_;
size_t max_committed_;
DISALLOW_COPY_AND_ASSIGN(BaseSpace);
};
} // namespace internal
} // namespace v8
#endif // V8_HEAP_BASE_SPACE_H_
...@@ -643,7 +643,8 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) { ...@@ -643,7 +643,8 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
std::stringstream stream; std::stringstream stream;
stream << DICT( stream << DICT(
MEMBER("name") MEMBER("name")
<< ESCAPE(GetSpaceName(static_cast<AllocationSpace>(space_index))) << ESCAPE(BaseSpace::GetSpaceName(
static_cast<AllocationSpace>(space_index)))
<< "," << ","
MEMBER("size") << space_stats.space_size() << "," MEMBER("size") << space_stats.space_size() << ","
MEMBER("used_size") << space_stats.space_used_size() << "," MEMBER("used_size") << space_stats.space_used_size() << ","
...@@ -891,29 +892,6 @@ size_t Heap::UsedGlobalHandlesSize() { ...@@ -891,29 +892,6 @@ size_t Heap::UsedGlobalHandlesSize() {
return isolate_->global_handles()->UsedSize(); return isolate_->global_handles()->UsedSize();
} }
// static
const char* Heap::GetSpaceName(AllocationSpace space) {
switch (space) {
case NEW_SPACE:
return "new_space";
case OLD_SPACE:
return "old_space";
case MAP_SPACE:
return "map_space";
case CODE_SPACE:
return "code_space";
case LO_SPACE:
return "large_object_space";
case NEW_LO_SPACE:
return "new_large_object_space";
case CODE_LO_SPACE:
return "code_large_object_space";
case RO_SPACE:
return "read_only_space";
}
UNREACHABLE();
}
void Heap::MergeAllocationSitePretenuringFeedback( void Heap::MergeAllocationSitePretenuringFeedback(
const PretenuringFeedbackMap& local_pretenuring_feedback) { const PretenuringFeedbackMap& local_pretenuring_feedback) {
AllocationSite site; AllocationSite site;
......
...@@ -776,9 +776,6 @@ class Heap { ...@@ -776,9 +776,6 @@ class Heap {
inline PagedSpace* paged_space(int idx); inline PagedSpace* paged_space(int idx);
inline Space* space(int idx); inline Space* space(int idx);
// Returns name of the space.
V8_EXPORT_PRIVATE static const char* GetSpaceName(AllocationSpace space);
// =========================================================================== // ===========================================================================
// Getters to other components. ============================================== // Getters to other components. ==============================================
// =========================================================================== // ===========================================================================
......
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/heap/allocation-stats.h" #include "src/heap/allocation-stats.h"
#include "src/heap/base-space.h"
#include "src/heap/basic-memory-chunk.h" #include "src/heap/basic-memory-chunk.h"
#include "src/heap/list.h" #include "src/heap/list.h"
#include "src/heap/memory-chunk.h" #include "src/heap/memory-chunk.h"
#include "src/heap/paged-spaces.h"
#include "src/heap/spaces.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <unordered_map>
#include <vector> #include <vector>
#include "src/base/iterator.h" #include "src/base/iterator.h"
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/heap/base-space.h"
#include "src/heap/basic-memory-chunk.h" #include "src/heap/basic-memory-chunk.h"
#include "src/heap/free-list.h" #include "src/heap/free-list.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
...@@ -104,63 +104,6 @@ class SemiSpace; ...@@ -104,63 +104,6 @@ class SemiSpace;
#define DCHECK_CODEOBJECT_SIZE(size, code_space) \ #define DCHECK_CODEOBJECT_SIZE(size, code_space) \
DCHECK((0 < size) && (size <= code_space->AreaSize())) DCHECK((0 < size) && (size <= code_space->AreaSize()))
// ----------------------------------------------------------------------------
// BaseSpace is the abstract superclass for all allocation spaces.
class V8_EXPORT_PRIVATE BaseSpace : public Malloced {
public:
Heap* heap() const {
DCHECK_NOT_NULL(heap_);
return heap_;
}
AllocationSpace identity() { return id_; }
const char* name() { return Heap::GetSpaceName(id_); }
void AccountCommitted(size_t bytes) {
DCHECK_GE(committed_ + bytes, committed_);
committed_ += bytes;
if (committed_ > max_committed_) {
max_committed_ = committed_;
}
}
void AccountUncommitted(size_t bytes) {
DCHECK_GE(committed_, committed_ - bytes);
committed_ -= bytes;
}
// Return the total amount committed memory for this space, i.e., allocatable
// memory and page headers.
virtual size_t CommittedMemory() { return committed_; }
virtual size_t MaximumCommittedMemory() { return max_committed_; }
// Approximate amount of physical memory committed for this space.
virtual size_t CommittedPhysicalMemory() = 0;
// Returns allocated size.
virtual size_t Size() = 0;
protected:
BaseSpace(Heap* heap, AllocationSpace id)
: heap_(heap), id_(id), committed_(0), max_committed_(0) {}
// Even though this has no virtual functions, this ensures that pointers are
// stable through casting.
virtual ~BaseSpace() = default;
protected:
Heap* heap_;
AllocationSpace id_;
// Keeps track of committed memory in a space.
std::atomic<size_t> committed_;
size_t max_committed_;
DISALLOW_COPY_AND_ASSIGN(BaseSpace);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Space is the abstract superclass for all allocation spaces that are not // Space is the abstract superclass for all allocation spaces that are not
// sealed after startup (i.e. not ReadOnlySpace). // sealed after startup (i.e. not ReadOnlySpace).
......
...@@ -142,7 +142,8 @@ void SerializerAllocator::OutputStatistics() { ...@@ -142,7 +142,8 @@ void SerializerAllocator::OutputStatistics() {
PrintF(" Spaces (bytes):\n"); PrintF(" Spaces (bytes):\n");
for (int space = 0; space < kNumberOfSpaces; space++) { for (int space = 0; space < kNumberOfSpaces; space++) {
PrintF("%16s", Heap::GetSpaceName(static_cast<AllocationSpace>(space))); PrintF("%16s",
BaseSpace::GetSpaceName(static_cast<AllocationSpace>(space)));
} }
PrintF("\n"); PrintF("\n");
......
...@@ -53,13 +53,14 @@ void Serializer::OutputStatistics(const char* name) { ...@@ -53,13 +53,14 @@ void Serializer::OutputStatistics(const char* name) {
#ifdef OBJECT_PRINT #ifdef OBJECT_PRINT
PrintF(" Instance types (count and bytes):\n"); PrintF(" Instance types (count and bytes):\n");
#define PRINT_INSTANCE_TYPE(Name) \ #define PRINT_INSTANCE_TYPE(Name) \
for (int space = 0; space < kNumberOfSpaces; ++space) { \ for (int space = 0; space < kNumberOfSpaces; ++space) { \
if (instance_type_count_[space][Name]) { \ if (instance_type_count_[space][Name]) { \
PrintF("%10d %10zu %-10s %s\n", instance_type_count_[space][Name], \ PrintF("%10d %10zu %-10s %s\n", instance_type_count_[space][Name], \
instance_type_size_[space][Name], \ instance_type_size_[space][Name], \
Heap::GetSpaceName(static_cast<AllocationSpace>(space)), #Name); \ BaseSpace::GetSpaceName(static_cast<AllocationSpace>(space)), \
} \ #Name); \
} \
} }
INSTANCE_TYPE_LIST(PRINT_INSTANCE_TYPE) INSTANCE_TYPE_LIST(PRINT_INSTANCE_TYPE)
#undef PRINT_INSTANCE_TYPE #undef PRINT_INSTANCE_TYPE
......
...@@ -139,13 +139,15 @@ static int DumpHeapConstants(FILE* out, const char* argv0) { ...@@ -139,13 +139,15 @@ static int DumpHeapConstants(FILE* out, const char* argv0) {
for (i::HeapObject object = ro_iterator.Next(); !object.is_null(); for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
object = ro_iterator.Next()) { object = ro_iterator.Next()) {
if (!object.IsMap()) continue; if (!object.IsMap()) continue;
DumpKnownMap(out, heap, i::Heap::GetSpaceName(i::RO_SPACE), object); DumpKnownMap(out, heap, i::BaseSpace::GetSpaceName(i::RO_SPACE),
object);
} }
i::PagedSpaceObjectIterator iterator(heap, heap->map_space()); i::PagedSpaceObjectIterator iterator(heap, heap->map_space());
for (i::HeapObject object = iterator.Next(); !object.is_null(); for (i::HeapObject object = iterator.Next(); !object.is_null();
object = iterator.Next()) { object = iterator.Next()) {
if (!object.IsMap()) continue; if (!object.IsMap()) continue;
DumpKnownMap(out, heap, i::Heap::GetSpaceName(i::MAP_SPACE), object); DumpKnownMap(out, heap, i::BaseSpace::GetSpaceName(i::MAP_SPACE),
object);
} }
i::PrintF(out, "}\n"); i::PrintF(out, "}\n");
} }
...@@ -159,7 +161,8 @@ static int DumpHeapConstants(FILE* out, const char* argv0) { ...@@ -159,7 +161,8 @@ static int DumpHeapConstants(FILE* out, const char* argv0) {
object = ro_iterator.Next()) { object = ro_iterator.Next()) {
// Skip read-only heap maps, they will be reported elsewhere. // Skip read-only heap maps, they will be reported elsewhere.
if (object.IsMap()) continue; if (object.IsMap()) continue;
DumpKnownObject(out, heap, i::Heap::GetSpaceName(i::RO_SPACE), object); DumpKnownObject(out, heap, i::BaseSpace::GetSpaceName(i::RO_SPACE),
object);
} }
i::PagedSpaceIterator spit(heap); i::PagedSpaceIterator spit(heap);
......
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