2020-10-22 07:02:17 +00:00
|
|
|
// 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_UNIFIED_HEAP_UTILS_H_
|
|
|
|
#define V8_UNITTESTS_HEAP_UNIFIED_HEAP_UTILS_H_
|
|
|
|
|
2020-10-28 08:13:33 +00:00
|
|
|
#include "include/cppgc/heap.h"
|
2020-10-22 07:02:17 +00:00
|
|
|
#include "include/v8.h"
|
2020-10-28 08:13:33 +00:00
|
|
|
#include "test/unittests/heap/heap-utils.h"
|
2020-10-22 07:02:17 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
2021-02-09 09:02:40 +00:00
|
|
|
|
|
|
|
class CppHeap;
|
|
|
|
|
2020-10-22 07:02:17 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2020-10-28 08:13:33 +00:00
|
|
|
class CppHeap;
|
|
|
|
|
|
|
|
class UnifiedHeapTest : public TestWithHeapInternals {
|
|
|
|
public:
|
|
|
|
UnifiedHeapTest();
|
2021-01-21 11:03:56 +00:00
|
|
|
~UnifiedHeapTest() override = default;
|
2020-10-28 08:13:33 +00:00
|
|
|
|
2021-01-21 15:19:19 +00:00
|
|
|
void CollectGarbageWithEmbedderStack(cppgc::Heap::SweepingType sweeping_type =
|
|
|
|
cppgc::Heap::SweepingType::kAtomic);
|
|
|
|
void CollectGarbageWithoutEmbedderStack(
|
|
|
|
cppgc::Heap::SweepingType sweeping_type =
|
|
|
|
cppgc::Heap::SweepingType::kAtomic);
|
2020-10-28 08:13:33 +00:00
|
|
|
|
|
|
|
CppHeap& cpp_heap() const;
|
|
|
|
cppgc::AllocationHandle& allocation_handle();
|
2021-02-09 09:02:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<v8::CppHeap> cpp_heap_;
|
2020-10-28 08:13:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WrapperHelper {
|
|
|
|
public:
|
|
|
|
// Sets up a V8 API object so that it points back to a C++ object. The setup
|
|
|
|
// used is recognized by the GC and references will be followed for liveness
|
|
|
|
// analysis (marking) as well as tooling (snapshot).
|
|
|
|
static v8::Local<v8::Object> CreateWrapper(v8::Local<v8::Context> context,
|
|
|
|
void* wrappable_object,
|
|
|
|
const char* class_name = "");
|
|
|
|
|
|
|
|
// Resets the connection of a wrapper (JS) to its wrappable (C++), meaning
|
|
|
|
// that the wrappable object is not longer kept alive by the wrapper object.
|
|
|
|
static void ResetWrappableConnection(v8::Local<v8::Object> api_object);
|
2021-01-21 11:03:56 +00:00
|
|
|
|
|
|
|
// Sets up the connection of a wrapper (JS) to its wrappable (C++). Does not
|
|
|
|
// emit any possibly needed write barrier.
|
|
|
|
static void SetWrappableConnection(v8::Local<v8::Object> api_object, void*,
|
|
|
|
void*);
|
2020-10-28 08:13:33 +00:00
|
|
|
};
|
2020-10-22 07:02:17 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_UNITTESTS_HEAP_UNIFIED_HEAP_UTILS_H_
|