v8/include/cppgc/heap.h
Michael Lippautz f67e8ab213 cppgc: Add public garbage collection call
Adds a public method that embedders can use to trigger garbage
collections. Such garbage collections are always required to have a
source and reason specifying which components calls it why.

Change-Id: I6ae983f99227febc1b7f0dd15c191d5b1eaaf3f3
Bug: chromium:1056170
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2181332
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Anton Bikineev <bikineev@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67631}
2020-05-06 21:58:11 +00:00

86 lines
2.1 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 INCLUDE_CPPGC_HEAP_H_
#define INCLUDE_CPPGC_HEAP_H_
#include <memory>
#include "v8config.h" // NOLINT(build/include_directory)
namespace cppgc {
namespace internal {
class Heap;
} // namespace internal
class V8_EXPORT Heap {
public:
// Normal spaces are used to store objects of different size classes:
// - kNormal1: < 32 bytes
// - kNormal2: < 64 bytes
// - kNormal3: < 128 bytes
// - kNormal4: >= 128 bytes
// Objects of size greater than 2^16 get stored in the large space. Users can
// register up to 4 arenas for application specific needs.
enum class SpaceType {
kNormal1,
kNormal2,
kNormal3,
kNormal4,
kLarge,
kUserDefined1,
kUserDefined2,
kUserDefined3,
kUserDefined4,
};
static constexpr size_t kMaxNumberOfSpaces =
static_cast<size_t>(SpaceType::kUserDefined4) + 1;
/**
* Specifies the stack state the embedder is in.
*/
enum class StackState : uint8_t {
/**
* The embedder does not know anything about it's stack.
*/
kUnkown,
/**
* The stack is empty, i.e., it does not contain any raw pointers
* to garbage-collected objects.
*/
kEmpty,
/**
* The stack is non-empty, i.e., it may contain raw pointers to
* garabge-collected objects.
*/
kNonEmpty,
};
static std::unique_ptr<Heap> Create();
virtual ~Heap() = default;
/**
* Forces garbage collection.
*
* \param source String specifying the source (or caller) triggering a
* forced garbage collection.
* \param reason String specifying the reason for the forced garbage
* collection.
* \param stack_state The embedder stack state, see StackState.
*/
void ForceGarbageCollectionSlow(const char* source, const char* reason,
StackState stack_state = StackState::kUnkown);
private:
Heap() = default;
friend class internal::Heap;
};
} // namespace cppgc
#endif // INCLUDE_CPPGC_HEAP_H_