1 // Copyright 2020 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_HEAP_CPPGC_GLOBALS_H_ 6 #define V8_HEAP_CPPGC_GLOBALS_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include "include/cppgc/internal/gc-info.h" 12 13 namespace cppgc { 14 namespace internal { 15 16 using Address = uint8_t*; 17 using ConstAddress = const uint8_t*; 18 19 constexpr size_t kKB = 1024; 20 constexpr size_t kMB = kKB * 1024; 21 constexpr size_t kGB = kMB * 1024; 22 23 // AccessMode used for choosing between atomic and non-atomic accesses. 24 enum class AccessMode : uint8_t { kNonAtomic, kAtomic }; 25 26 // See 6.7.6 (http://eel.is/c++draft/basic.align) for alignment restrictions. We 27 // do not fully support all alignment restrictions (following 28 // alignof(std::max_align_t)) but limit to alignof(double). 29 // 30 // This means that any scalar type with stricter alignment requirements (in 31 // practice: long double) cannot be used unrestricted in garbage-collected 32 // objects. 33 // 34 // Note: We use the same allocation granularity on 32-bit and 64-bit systems. 35 constexpr size_t kAllocationGranularity = 8; 36 constexpr size_t kAllocationMask = kAllocationGranularity - 1; 37 38 constexpr size_t kPageSizeLog2 = 17; 39 constexpr size_t kPageSize = 1 << kPageSizeLog2; 40 constexpr size_t kPageOffsetMask = kPageSize - 1; 41 constexpr size_t kPageBaseMask = ~kPageOffsetMask; 42 43 // Guard pages are always put into memory. Whether they are actually protected 44 // depends on the allocator provided to the garbage collector. 45 constexpr size_t kGuardPageSize = 4096; 46 47 constexpr size_t kLargeObjectSizeThreshold = kPageSize / 2; 48 49 constexpr GCInfoIndex kFreeListGCInfoIndex = 0; 50 constexpr size_t kFreeListEntrySize = 2 * sizeof(uintptr_t); 51 52 constexpr size_t kCagedHeapReservationSize = static_cast<size_t>(4) * kGB; 53 constexpr size_t kCagedHeapReservationAlignment = kCagedHeapReservationSize; 54 55 } // namespace internal 56 } // namespace cppgc 57 58 #endif // V8_HEAP_CPPGC_GLOBALS_H_ 59