Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 10:08:49

0001 // Copyright 2022 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
0004 
0005 #ifndef INCLUDE_CPPGC_INTERNAL_BASE_PAGE_HANDLE_H_
0006 #define INCLUDE_CPPGC_INTERNAL_BASE_PAGE_HANDLE_H_
0007 
0008 #include "cppgc/heap-handle.h"
0009 #include "cppgc/internal/api-constants.h"
0010 #include "cppgc/internal/logging.h"
0011 #include "v8config.h"  // NOLINT(build/include_directory)
0012 
0013 namespace cppgc {
0014 namespace internal {
0015 
0016 // The class is needed in the header to allow for fast access to HeapHandle in
0017 // the write barrier.
0018 class BasePageHandle {
0019  public:
0020   static V8_INLINE BasePageHandle* FromPayload(void* payload) {
0021     return reinterpret_cast<BasePageHandle*>(
0022         (reinterpret_cast<uintptr_t>(payload) &
0023          ~(api_constants::kPageSize - 1)) +
0024         api_constants::kGuardPageSize);
0025   }
0026   static V8_INLINE const BasePageHandle* FromPayload(const void* payload) {
0027     return FromPayload(const_cast<void*>(payload));
0028   }
0029 
0030   HeapHandle& heap_handle() { return heap_handle_; }
0031   const HeapHandle& heap_handle() const { return heap_handle_; }
0032 
0033  protected:
0034   explicit BasePageHandle(HeapHandle& heap_handle) : heap_handle_(heap_handle) {
0035     CPPGC_DCHECK(reinterpret_cast<uintptr_t>(this) % api_constants::kPageSize ==
0036                  api_constants::kGuardPageSize);
0037   }
0038 
0039   HeapHandle& heap_handle_;
0040 };
0041 
0042 }  // namespace internal
0043 }  // namespace cppgc
0044 
0045 #endif  // INCLUDE_CPPGC_INTERNAL_BASE_PAGE_HANDLE_H_