chromium/v8/src/wasm/std-object-sizes.h

// Copyright 2023 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.

#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif  // !V8_ENABLE_WEBASSEMBLY

#ifndef V8_WASM_STD_OBJECT_SIZES_H_
#define V8_WASM_STD_OBJECT_SIZES_H_

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "include/v8config.h"

namespace v8::internal::wasm {

// These helpers are used to estimate the memory consumption of standard
// data structures off the managed heap.
// The size of the container itself is not included here, because it's
// typically included in the size of the containing element.

template <typename T>
inline size_t ContentSize(const std::vector<T>& vector) {}

template <typename Key, typename T>
inline size_t ContentSize(const std::map<Key, T>& map) {}

template <typename Key, typename T, typename Hash>
inline size_t ContentSize(const std::unordered_map<Key, T, Hash>& map) {}

template <typename T>
inline size_t ContentSize(std::unordered_set<T> set) {}

// To make it less likely for size estimation functions to become outdated
// when the classes they're responsible for change, we insert static asserts
// about the respective class's size into them to at least catch some possible
// future modifications. Since object sizes are toolchain specific, we define
// restrictions here under which we enable these checks.
// When one of these checks fails, that probably means you've added fields to
// a class guarded by it. Update the respective EstimateCurrentMemoryConsumption
// function accordingly, and then update the check's expected size.
#if V8_TARGET_ARCH_X64 && defined(__clang__) && V8_TARGET_OS_LINUX &&          \
    !V8_USE_ADDRESS_SANITIZER && !V8_USE_MEMORY_SANITIZER && defined(DEBUG) && \
    V8_COMPRESS_POINTERS && !defined(V8_GC_MOLE) && defined(_LIBCPP_VERSION)
#define UPDATE_WHEN_CLASS_CHANGES(classname, size)
#else
#define UPDATE_WHEN_CLASS_CHANGES
#endif

}  // namespace v8::internal::wasm

#endif  // V8_WASM_STD_OBJECT_SIZES_H_