File indexing completed on 2025-02-23 10:08:49
0001
0002
0003
0004
0005 #ifndef INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_H_
0006 #define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_H_
0007
0008 #include <climits>
0009 #include <cstddef>
0010
0011 #include "cppgc/internal/api-constants.h"
0012 #include "cppgc/internal/base-page-handle.h"
0013 #include "v8config.h" // NOLINT(build/include_directory)
0014
0015 #if defined(CPPGC_CAGED_HEAP)
0016
0017 namespace cppgc {
0018 namespace internal {
0019
0020 class V8_EXPORT CagedHeapBase {
0021 public:
0022 V8_INLINE static uintptr_t OffsetFromAddress(const void* address) {
0023 return reinterpret_cast<uintptr_t>(address) &
0024 (api_constants::kCagedHeapReservationAlignment - 1);
0025 }
0026
0027 V8_INLINE static bool IsWithinCage(const void* address) {
0028 CPPGC_DCHECK(g_heap_base_);
0029 return (reinterpret_cast<uintptr_t>(address) &
0030 ~(api_constants::kCagedHeapReservationAlignment - 1)) ==
0031 g_heap_base_;
0032 }
0033
0034 V8_INLINE static bool AreWithinCage(const void* addr1, const void* addr2) {
0035 #if defined(CPPGC_2GB_CAGE)
0036 static constexpr size_t kHeapBaseShift = sizeof(uint32_t) * CHAR_BIT - 1;
0037 #else
0038 #if defined(CPPGC_POINTER_COMPRESSION)
0039 static constexpr size_t kHeapBaseShift =
0040 31 + api_constants::kPointerCompressionShift;
0041 #else
0042 static constexpr size_t kHeapBaseShift = sizeof(uint32_t) * CHAR_BIT;
0043 #endif
0044 #endif
0045 static_assert((static_cast<size_t>(1) << kHeapBaseShift) ==
0046 api_constants::kCagedHeapMaxReservationSize);
0047 CPPGC_DCHECK(g_heap_base_);
0048 return !(((reinterpret_cast<uintptr_t>(addr1) ^ g_heap_base_) |
0049 (reinterpret_cast<uintptr_t>(addr2) ^ g_heap_base_)) >>
0050 kHeapBaseShift);
0051 }
0052
0053 V8_INLINE static uintptr_t GetBase() { return g_heap_base_; }
0054 V8_INLINE static size_t GetAgeTableSize() { return g_age_table_size_; }
0055
0056 private:
0057 friend class CagedHeap;
0058
0059 static uintptr_t g_heap_base_;
0060 static size_t g_age_table_size_;
0061 };
0062
0063 }
0064 }
0065
0066 #endif
0067
0068 #endif