chromium/v8/src/utils/identity-map.h

// Copyright 2015 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_UTILS_IDENTITY_MAP_H_
#define V8_UTILS_IDENTITY_MAP_H_

#include <type_traits>

#include "src/base/functional.h"
#include "src/handles/handles.h"
#include "src/objects/tagged.h"

namespace v8 {
namespace internal {

// Forward declarations.
class Heap;
class StrongRootsEntry;

template <typename T>
struct IdentityMapFindResult {};

// Base class of identity maps contains shared code for all template
// instantiations.
class V8_EXPORT_PRIVATE IdentityMapBase {};

// Implements an identity map from object addresses to a given value type {V}.
// The map is robust w.r.t. garbage collection by synchronization with the
// supplied {heap}.
//
//  * Keys are treated as strong roots.
//  * The value type {V} must be reinterpret_cast'able to {uintptr_t}
//  * The value type {V} must not be a heap type.
//
// Note: IdentityMap methods must not be called during the mark-compact phase
// since rehashing there may lead to incorrect results.
// Note: When using IdentityMap in concurrent settings, be aware that reads
// (e.g. `Find`) may trigger lazy rehashing and thus must be treated as write
// operations wrt synchronization.
template <typename V, class AllocationPolicy>
class IdentityMap : public IdentityMapBase {};

}  // namespace internal
}  // namespace v8

#endif  // V8_UTILS_IDENTITY_MAP_H_