[heap] Move BaseSpace into base-space.h
Bug: v8:10473 Change-Id: Ic53130ca5103ba219329f7b204b218bc021f07f3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2252178 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/master@{#68427}
This commit is contained in:
parent
8bdce52713
commit
30f409c751
2
BUILD.gn
2
BUILD.gn
@ -2452,6 +2452,8 @@ v8_source_set("v8_base_without_compiler") {
|
||||
"src/heap/array-buffer-tracker.cc",
|
||||
"src/heap/array-buffer-tracker.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.h",
|
||||
"src/heap/code-object-registry.cc",
|
||||
|
@ -8463,7 +8463,7 @@ bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
|
||||
i::Heap* heap = isolate->heap();
|
||||
|
||||
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 (V8_SHARED_RO_HEAP_BOOL) {
|
||||
|
33
src/heap/base-space.cc
Normal file
33
src/heap/base-space.cc
Normal file
@ -0,0 +1,33 @@
|
||||
// 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
|
83
src/heap/base-space.h
Normal file
83
src/heap/base-space.h
Normal file
@ -0,0 +1,83 @@
|
||||
// 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) {
|
||||
std::stringstream stream;
|
||||
stream << DICT(
|
||||
MEMBER("name")
|
||||
<< ESCAPE(GetSpaceName(static_cast<AllocationSpace>(space_index)))
|
||||
<< ESCAPE(BaseSpace::GetSpaceName(
|
||||
static_cast<AllocationSpace>(space_index)))
|
||||
<< ","
|
||||
MEMBER("size") << space_stats.space_size() << ","
|
||||
MEMBER("used_size") << space_stats.space_used_size() << ","
|
||||
@ -891,29 +892,6 @@ size_t Heap::UsedGlobalHandlesSize() {
|
||||
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(
|
||||
const PretenuringFeedbackMap& local_pretenuring_feedback) {
|
||||
AllocationSite site;
|
||||
|
@ -776,9 +776,6 @@ class Heap {
|
||||
inline PagedSpace* paged_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. ==============================================
|
||||
// ===========================================================================
|
||||
|
@ -12,11 +12,10 @@
|
||||
#include "src/base/macros.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/heap/allocation-stats.h"
|
||||
#include "src/heap/base-space.h"
|
||||
#include "src/heap/basic-memory-chunk.h"
|
||||
#include "src/heap/list.h"
|
||||
#include "src/heap/memory-chunk.h"
|
||||
#include "src/heap/paged-spaces.h"
|
||||
#include "src/heap/spaces.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "src/base/iterator.h"
|
||||
#include "src/base/macros.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/heap/base-space.h"
|
||||
#include "src/heap/basic-memory-chunk.h"
|
||||
#include "src/heap/free-list.h"
|
||||
#include "src/heap/heap.h"
|
||||
@ -104,63 +104,6 @@ class SemiSpace;
|
||||
#define DCHECK_CODEOBJECT_SIZE(size, code_space) \
|
||||
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
|
||||
// sealed after startup (i.e. not ReadOnlySpace).
|
||||
|
@ -142,7 +142,8 @@ void SerializerAllocator::OutputStatistics() {
|
||||
PrintF(" Spaces (bytes):\n");
|
||||
|
||||
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");
|
||||
|
||||
|
@ -53,13 +53,14 @@ void Serializer::OutputStatistics(const char* name) {
|
||||
|
||||
#ifdef OBJECT_PRINT
|
||||
PrintF(" Instance types (count and bytes):\n");
|
||||
#define PRINT_INSTANCE_TYPE(Name) \
|
||||
for (int space = 0; space < kNumberOfSpaces; ++space) { \
|
||||
if (instance_type_count_[space][Name]) { \
|
||||
PrintF("%10d %10zu %-10s %s\n", instance_type_count_[space][Name], \
|
||||
instance_type_size_[space][Name], \
|
||||
Heap::GetSpaceName(static_cast<AllocationSpace>(space)), #Name); \
|
||||
} \
|
||||
#define PRINT_INSTANCE_TYPE(Name) \
|
||||
for (int space = 0; space < kNumberOfSpaces; ++space) { \
|
||||
if (instance_type_count_[space][Name]) { \
|
||||
PrintF("%10d %10zu %-10s %s\n", instance_type_count_[space][Name], \
|
||||
instance_type_size_[space][Name], \
|
||||
BaseSpace::GetSpaceName(static_cast<AllocationSpace>(space)), \
|
||||
#Name); \
|
||||
} \
|
||||
}
|
||||
INSTANCE_TYPE_LIST(PRINT_INSTANCE_TYPE)
|
||||
#undef PRINT_INSTANCE_TYPE
|
||||
|
@ -139,13 +139,15 @@ static int DumpHeapConstants(FILE* out, const char* argv0) {
|
||||
for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
|
||||
object = ro_iterator.Next()) {
|
||||
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());
|
||||
for (i::HeapObject object = iterator.Next(); !object.is_null();
|
||||
object = iterator.Next()) {
|
||||
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");
|
||||
}
|
||||
@ -159,7 +161,8 @@ static int DumpHeapConstants(FILE* out, const char* argv0) {
|
||||
object = ro_iterator.Next()) {
|
||||
// Skip read-only heap maps, they will be reported elsewhere.
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user