#include <stdlib.h>
#include <memory>
#include "include/v8-initialization.h"
#include "include/v8-platform.h"
#include "src/base/bounded-page-allocator.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
#include "src/common/globals.h"
#include "src/heap/allocation-result.h"
#include "src/heap/factory.h"
#include "src/heap/heap.h"
#include "src/heap/large-spaces.h"
#include "src/heap/main-allocator.h"
#include "src/heap/memory-allocator.h"
#include "src/heap/mutable-page-metadata.h"
#include "src/heap/spaces-inl.h"
#include "src/heap/spaces.h"
#include "src/objects/free-space.h"
#include "src/objects/objects-inl.h"
#include "src/snapshot/snapshot.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-tester.h"
#include "test/cctest/heap/heap-utils.h"
namespace v8 {
namespace internal {
namespace heap {
class V8_NODISCARD TestMemoryAllocatorScope { … };
class V8_NODISCARD TestCodePageAllocatorScope { … };
static void VerifyMemoryChunk(Isolate* isolate, Heap* heap,
v8::PageAllocator* code_page_allocator,
size_t area_size, Executability executable,
PageSize page_size, LargeObjectSpace* space) { … }
static unsigned int PseudorandomAreaSize() { … }
TEST(MutablePageMetadata) { … }
TEST(MemoryAllocator) { … }
TEST(ComputeDiscardMemoryAreas) { … }
TEST(SemiSpaceNewSpace) { … }
TEST(PagedNewSpace) { … }
TEST(OldSpace) { … }
TEST(OldLargeObjectSpace) { … }
#ifndef DEBUG
TEST(SizeOfInitialHeap) {
ManualGCScope manual_gc_scope;
if (i::v8_flags.always_turbofan) return;
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
if (!isolate->snapshot_available()) return;
HandleScope scope(isolate);
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
if (!CcTest::global()
->Get(context, v8_str("assertEquals"))
.ToLocalChecked()
->IsUndefined()) {
return;
}
size_t initial_lo_space = isolate->heap()->lo_space()->Size();
#if V8_OS_LINUX && V8_HOST_ARCH_PPC64
const size_t kMaxInitialSizePerSpace = 3 * MB;
#else
const size_t kMaxInitialSizePerSpace = 2 * MB;
#endif
Heap* heap = isolate->heap();
for (int i = FIRST_GROWABLE_PAGED_SPACE; i <= LAST_GROWABLE_PAGED_SPACE;
i++) {
if (!heap->paged_space(i)) continue;
if (i == CODE_SPACE && i::v8_flags.debug_code) continue;
CHECK_LE(heap->paged_space(i)->CommittedMemory(), kMaxInitialSizePerSpace);
}
CompileRun("/*empty*/");
CHECK_EQ(initial_lo_space,
static_cast<size_t>(isolate->heap()->lo_space()->Size()));
}
#endif
class Observer : public AllocationObserver { … };
HEAP_TEST(Regress777177) { … }
HEAP_TEST(Regress791582) { … }
TEST(ShrinkPageToHighWaterMarkFreeSpaceEnd) { … }
TEST(ShrinkPageToHighWaterMarkNoFiller) { … }
TEST(ShrinkPageToHighWaterMarkOneWordFiller) { … }
TEST(ShrinkPageToHighWaterMarkTwoWordFiller) { … }
namespace {
class FailingPageAllocator : public v8::PageAllocator { … };
}
TEST(NoMemoryForNewPage) { … }
namespace {
class V8_NODISCARD ReadOnlySpaceScope { … };
}
TEST(ReadOnlySpaceMetrics_OnePage) { … }
TEST(ReadOnlySpaceMetrics_AlignedAllocations) { … }
TEST(ReadOnlySpaceMetrics_TwoPages) { … }
}
}
}