v8/test/unittests/heap/heap-utils.h
Michael Lippautz df212a095b cppgc,api: Add support for JS->C++ write barriers
Provide a way to trigger a write barrier when updating the embedder
fields. In future, such a mechanism should be encapsulated into V8.

Bug: chromium:1056170
Change-Id: I4e43362993c3e58d5bebdd58a7d46a39c0aa4f06
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2640419
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72227}
2021-01-21 14:28:00 +00:00

51 lines
1.5 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_HEAP_UTILS_H_
#define V8_UNITTESTS_HEAP_HEAP_UTILS_H_
#include "src/base/macros.h"
#include "src/common/globals.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
class HeapInternalsBase {
protected:
void SimulateIncrementalMarking(Heap* heap, bool force_completion);
};
template <typename TMixin>
class WithHeapInternals : public TMixin, HeapInternalsBase {
public:
WithHeapInternals() = default;
WithHeapInternals(const WithHeapInternals&) = delete;
WithHeapInternals& operator=(const WithHeapInternals&) = delete;
void CollectGarbage(i::AllocationSpace space) {
heap()->CollectGarbage(space, i::GarbageCollectionReason::kTesting);
}
Heap* heap() const { return this->i_isolate()->heap(); }
void SimulateIncrementalMarking(bool force_completion = true) {
return HeapInternalsBase::SimulateIncrementalMarking(heap(),
force_completion);
}
};
using TestWithHeapInternals = //
WithHeapInternals< //
WithInternalIsolateMixin< //
WithIsolateScopeMixin< //
WithIsolateMixin< //
::testing::Test>>>>;
} // namespace internal
} // namespace v8
#endif // V8_UNITTESTS_HEAP_HEAP_UTILS_H_