blob: bfc8a841d94bd2c1ea8207890b60fc74e884f3eb [file] [log] [blame]
// Copyright 2019 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.
#include "src/base/macros.h"
#include "src/heap/heap.h"
#include "src/objects.h"
#include "src/roots.h"
namespace v8 {
namespace internal {
class ReadOnlySpace;
class ReadOnlyDeserializer;
// This class transparently manages read-only space, roots and cache creation
// and destruction.
class ReadOnlyHeap final {
static constexpr size_t kEntriesCount =
// If necessary create read-only heap and initialize its artifacts (if the
// deserializer is provided).
// TODO(goszczycki): Ideally we'd create this without needing a heap.
static void SetUp(Isolate* isolate, ReadOnlyDeserializer* des);
// Indicate that all read-only space objects have been created and will not
// be written to. This is not thread safe, and should really only be used as
// part of mksnapshot or when read-only heap sharing is disabled.
void OnCreateHeapObjectsComplete();
// Indicate that the current isolate no longer requires the read-only heap and
// it may be safely disposed of.
void OnHeapTearDown();
// Returns whether the object resides in the read-only space.
static bool Contains(Object object);
std::vector<Object>* read_only_object_cache() {
return &read_only_object_cache_;
ReadOnlySpace* read_only_space() const { return read_only_space_; }
static ReadOnlyHeap* Init(Isolate* isolate, ReadOnlyDeserializer* des);
bool deserializing_ = false;
ReadOnlySpace* read_only_space_ = nullptr;
std::vector<Object> read_only_object_cache_;
Address read_only_roots_[kEntriesCount];
explicit ReadOnlyHeap(ReadOnlySpace* ro_space) : read_only_space_(ro_space) {}
} // namespace internal
} // namespace v8