935d915186
Unified heap support in V8 requires having another (at least internal) heap that implements a unfied garbage collection strategy. This will not re-use the already existing cppgc::Heap because there should be no way in creating such a heap externally or scheduling stand-alone garbage collections. In order to have a common token, this CL introduces AllocationHandle which can be passed to MakeGarbageCollected to allocate C++ objects. V8 (soon) and the stand-alone heap both have methods to retrieve such a handle. This works around a problem with creating diamond class hierarchies when a base class would be exposed on the public API level. Fast paths for Blink are still possible because allocation handles can be cached the same way (e.g. global, or TLS) as a heap can be cached. Tbr: yangguo@chromium.org Bug: chromium:1056170 Change-Id: I8e9472a2c24ef82d1178953e8429b1fd8a2344bc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2238027 Commit-Queue: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Omer Katz <omerkatz@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#68310}
72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
// 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_UNITTESTS_HEAP_CPPGC_TESTS_H_
|
|
#define V8_UNITTESTS_HEAP_CPPGC_TESTS_H_
|
|
|
|
#include "include/cppgc/heap.h"
|
|
#include "include/cppgc/platform.h"
|
|
#include "src/heap/cppgc/heap.h"
|
|
#include "test/unittests/heap/cppgc/test-platform.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace cppgc {
|
|
namespace internal {
|
|
namespace testing {
|
|
|
|
class TestWithPlatform : public ::testing::Test {
|
|
protected:
|
|
static void SetUpTestSuite();
|
|
static void TearDownTestSuite();
|
|
|
|
TestPlatform& GetPlatform() const { return *platform_; }
|
|
|
|
protected:
|
|
static std::shared_ptr<TestPlatform> platform_;
|
|
};
|
|
|
|
class TestWithHeap : public TestWithPlatform {
|
|
protected:
|
|
TestWithHeap();
|
|
|
|
void PreciseGC() {
|
|
heap_->ForceGarbageCollectionSlow("TestWithHeap", "Testing",
|
|
cppgc::Heap::StackState::kNoHeapPointers);
|
|
}
|
|
|
|
cppgc::Heap* GetHeap() const { return heap_.get(); }
|
|
|
|
cppgc::AllocationHandle& GetAllocationHandle() const {
|
|
return allocation_handle_;
|
|
}
|
|
|
|
std::unique_ptr<Marker>& GetMarkerRef() {
|
|
return Heap::From(GetHeap())->marker_;
|
|
}
|
|
|
|
void ResetLinearAllocationBuffers();
|
|
|
|
private:
|
|
std::unique_ptr<cppgc::Heap> heap_;
|
|
cppgc::AllocationHandle& allocation_handle_;
|
|
};
|
|
|
|
// Restrictive test fixture that supports allocation but will make sure no
|
|
// garbage collection is triggered. This is useful for writing idiomatic
|
|
// tests where object are allocated on the managed heap while still avoiding
|
|
// far reaching test consquences of full garbage collection calls.
|
|
class TestSupportingAllocationOnly : public TestWithHeap {
|
|
protected:
|
|
TestSupportingAllocationOnly();
|
|
|
|
private:
|
|
Heap::NoGCScope no_gc_scope_;
|
|
};
|
|
|
|
} // namespace testing
|
|
} // namespace internal
|
|
} // namespace cppgc
|
|
|
|
#endif // V8_UNITTESTS_HEAP_CPPGC_TESTS_H_
|