Flutter Engine
The Flutter Engine
globals.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_GLOBALS_H_
6#define RUNTIME_VM_GLOBALS_H_
7
8// This file contains global definitions for the VM library only. Anything that
9// is more globally useful should be added to 'vm/globals.h'.
10
11#include "platform/globals.h"
12
13#if defined(_WIN32)
14// Undef conflicting defines.
15#undef PARITY_EVEN
16#undef PARITY_ODD
17#undef near
18#endif // defined(_WIN32)
19
20namespace dart {
21// Smi value range is from -(2^N) to (2^N)-1.
22// N=30 (32-bit build) or N=62 (64-bit build).
23#if !defined(DART_COMPRESSED_POINTERS)
24const intptr_t kSmiBits = kBitsPerWord - 2;
25#else
26const intptr_t kSmiBits = 30;
27#endif
28const intptr_t kSmiMax = (static_cast<intptr_t>(1) << kSmiBits) - 1;
29const intptr_t kSmiMin = -(static_cast<intptr_t>(1) << kSmiBits);
30
31// Hard coded from above but for 32-bit architectures.
32const intptr_t kSmiBits32 = kBitsPerInt32 - 2;
33const intptr_t kSmiMax32 = (static_cast<intptr_t>(1) << kSmiBits32) - 1;
34const intptr_t kSmiMin32 = -(static_cast<intptr_t>(1) << kSmiBits32);
35
36#if defined(DART_COMPRESSED_POINTERS)
37static constexpr intptr_t kCompressedWordSize = kInt32Size;
38static constexpr intptr_t kCompressedWordSizeLog2 = kInt32SizeLog2;
39typedef uint32_t compressed_uword;
40typedef int32_t compressed_word;
41#else
42static constexpr intptr_t kCompressedWordSize = kWordSize;
43static constexpr intptr_t kCompressedWordSizeLog2 = kWordSizeLog2;
44typedef uintptr_t compressed_uword;
45typedef intptr_t compressed_word;
46#endif
47// 32-bit: 2^32 addresses => kMaxAddrSpaceMB = 2^(32 - MBLog2) = 2^12 MB
48// 64-bit: 2^48 addresses => kMaxAddrSpaceMB = 2^(48 - MBLog2) = 2^28 MB
49const intptr_t kMaxAddrSpaceMB = (kWordSize <= 4) ? 4096 : 268435456;
51 << MBLog2;
52
53// Number of bytes per BigInt digit.
54const intptr_t kBytesPerBigIntDigit = 4;
55
56// The default old gen heap size in MB, where 0 -- unlimited.
57// 32-bit: OS limit is 2 or 3 GB
58// 64-bit: Linux's limit is
59// sysctl vm.max_map_count (default 2^16) * 512 KB Pages = 32 GB
60// Set the VM limit below the OS limit to increase the likelihood of failing
61// gracefully with a Dart OutOfMemory exception instead of SIGABORT.
62const intptr_t kDefaultMaxOldGenHeapSize = (kWordSize <= 4) ? 1536 : 30720;
63const intptr_t kDefaultNewGenSemiMaxSize = (kWordSize <= 4) ? 8 : 16;
64
65#define kPosInfinity bit_cast<double>(DART_UINT64_C(0x7ff0000000000000))
66#define kNegInfinity bit_cast<double>(DART_UINT64_C(0xfff0000000000000))
67
68// The expression ARRAY_SIZE(array) is a compile-time constant of type
69// size_t which represents the number of elements of the given
70// array. You should only use ARRAY_SIZE on statically allocated
71// arrays.
72#define ARRAY_SIZE(array) \
73 ((sizeof(array) / sizeof(*(array))) / \
74 static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) // NOLINT
75
76#if defined(PRODUCT) && defined(DEBUG)
77#error Both PRODUCT and DEBUG defined.
78#endif // defined(PRODUCT) && defined(DEBUG)
79
80#if defined(PRODUCT)
81#define NOT_IN_PRODUCT(code)
82#define ONLY_IN_PRODUCT(code) code
83#else // defined(PRODUCT)
84#define NOT_IN_PRODUCT(code) code
85#define ONLY_IN_PRODUCT(code)
86#endif // defined(PRODUCT)
87
88#if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER)
89#error DART_PRECOMPILED_RUNTIME and DART_PRECOMPILER are mutually exclusive
90#endif // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER)
91
92#if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT)
93#error DART_PRECOMPILED_RUNTIME and DART_NOSNAPSHOT are mutually exclusive
94#endif // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT)
95
96#if defined(DART_PRECOMPILED_RUNTIME)
97#define NOT_IN_PRECOMPILED(code)
98#define ONLY_IN_PRECOMPILED(code) code
99#else
100#define NOT_IN_PRECOMPILED(code) code
101#define ONLY_IN_PRECOMPILED(code)
102#endif // defined(DART_PRECOMPILED_RUNTIME)
103
104#if defined(TARGET_ARCH_IA32)
105#define NOT_IN_IA32(code)
106#else
107#define NOT_IN_IA32(code) code
108#endif
109
110#if defined(DART_PRECOMPILED_RUNTIME)
111#define NOT_IN_PRECOMPILED_RUNTIME(code)
112#else
113#define NOT_IN_PRECOMPILED_RUNTIME(code) code
114#endif // defined(DART_PRECOMPILED_RUNTIME)
115
116#if !defined(DART_DISABLE_TIMELINE) && \
117 (defined(DART_ENABLE_TIMELINE) || !defined(PRODUCT) || \
118 defined(DART_HOST_OS_FUCHSIA) || defined(DART_TARGET_OS_FUCHSIA) || \
119 defined(DART_TARGET_OS_ANDROID) || defined(DART_TARGET_OS_MACOS))
120#define SUPPORT_TIMELINE 1
121#endif
122
123#if defined(ARCH_IS_64_BIT) && !defined(IS_SIMARM_HOST64)
124#define HASH_IN_OBJECT_HEADER 1
125#endif
126
127// The expression OFFSET_OF(type, field) computes the byte-offset of
128// the specified field relative to the containing type.
129//
130// The expression OFFSET_OF_RETURNED_VALUE(type, accessor) computes the
131// byte-offset of the return value of the accessor to the containing type.
132//
133// None of these use 0 or nullptr, which causes a problem with the compiler
134// warnings we have enabled (which is also why 'offsetof' doesn't seem to work).
135// The workaround is to use the non-zero value kOffsetOfPtr.
136const intptr_t kOffsetOfPtr = 32;
137
138#define OFFSET_OF(type, field) \
139 (reinterpret_cast<intptr_t>( \
140 &(reinterpret_cast<type*>(kOffsetOfPtr)->field)) - \
141 kOffsetOfPtr) // NOLINT
142
143#define OFFSET_OF_RETURNED_VALUE(type, accessor) \
144 (reinterpret_cast<intptr_t>( \
145 (reinterpret_cast<type*>(kOffsetOfPtr)->accessor())) - \
146 kOffsetOfPtr) // NOLINT
147
148#define SIZE_OF_RETURNED_VALUE(type, method) \
149 sizeof(reinterpret_cast<type*>(kOffsetOfPtr)->method())
150
151#define SIZE_OF_DEREFERENCED_RETURNED_VALUE(type, method) \
152 sizeof(*(reinterpret_cast<type*>(kOffsetOfPtr))->method())
153
154#define OPEN_ARRAY_START(type, align) \
155 do { \
156 const uword result = reinterpret_cast<uword>(this) + sizeof(*this); \
157 ASSERT(Utils::IsAligned(result, alignof(align))); \
158 return reinterpret_cast<type*>(result); \
159 } while (0)
160
161// A type large enough to contain the value of the C++ vtable. This is needed
162// to support the handle operations.
164
165// When using GCC we can use GCC attributes to ensure that certain
166// constants are 8 or 16 byte aligned.
167#if defined(DART_HOST_OS_WINDOWS)
168#define ALIGN8 __declspec(align(8))
169#define ALIGN16 __declspec(align(16))
170#else
171#define ALIGN8 __attribute__((aligned(8)))
172#define ALIGN16 __attribute__((aligned(16)))
173#endif
174
175// Zap value used to indicate uninitialized handle area (debug purposes).
176#if defined(ARCH_IS_32_BIT)
177static constexpr uword kZapUninitializedWord = 0xabababab;
178#else
179static constexpr uword kZapUninitializedWord = 0xabababababababab;
180#endif
181static constexpr intptr_t kAllocationCanary = 123;
182
183// Macros to get the contents of the fp register.
184#if defined(DART_HOST_OS_WINDOWS)
185
186// clang-format off
187#if defined(HOST_ARCH_IA32)
188#define COPY_FP_REGISTER(fp) \
189 __asm { mov fp, ebp} \
190 ; // NOLINT
191// clang-format on
192#else
193// Inline assembly is only available on x86; return the stack pointer instead.
194#define COPY_FP_REGISTER(fp) fp = OSThread::GetCurrentStackPointer();
195#endif
196
197#else // !defined(DART_HOST_OS_WINDOWS))
198
199// Assume GCC-compatible builtins.
200#define COPY_FP_REGISTER(fp) \
201 fp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0));
202
203#endif // !defined(DART_HOST_OS_WINDOWS))
204
205#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64) || \
206 defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_RISCV32) || \
207 defined(TARGET_ARCH_RISCV64)
208#define TARGET_USES_OBJECT_POOL 1
209#endif
210
211#if defined(DART_PRECOMPILER) && \
212 (defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM) || \
213 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_RISCV32) || \
214 defined(TARGET_ARCH_RISCV64))
215#define DART_SUPPORT_PRECOMPILATION 1
216#endif
217
218} // namespace dart
219
220#endif // RUNTIME_VM_GLOBALS_H_
Definition: dart_vm.cc:33
const intptr_t kOffsetOfPtr
Definition: globals.h:136
const intptr_t kSmiBits
Definition: globals.h:24
static constexpr intptr_t kCompressedWordSizeLog2
Definition: globals.h:43
const intptr_t kSmiMax
Definition: globals.h:28
constexpr intptr_t kBitsPerWord
Definition: globals.h:514
static constexpr intptr_t kAllocationCanary
Definition: globals.h:181
uword cpp_vtable
Definition: globals.h:163
constexpr intptr_t MBLog2
Definition: globals.h:529
constexpr intptr_t kInt32SizeLog2
Definition: globals.h:449
const intptr_t kSmiMax32
Definition: globals.h:33
intptr_t compressed_word
Definition: globals.h:45
const intptr_t kDefaultNewGenSemiMaxSize
Definition: globals.h:63
constexpr intptr_t kWordSizeLog2
Definition: globals.h:507
const intptr_t kSmiMin32
Definition: globals.h:34
uintptr_t uword
Definition: globals.h:501
uintptr_t compressed_uword
Definition: globals.h:44
static constexpr uword kZapUninitializedWord
Definition: globals.h:179
constexpr intptr_t kInt32Size
Definition: globals.h:450
constexpr intptr_t kBitsPerInt32
Definition: globals.h:466
static constexpr intptr_t kCompressedWordSize
Definition: globals.h:42
const intptr_t kDefaultMaxOldGenHeapSize
Definition: globals.h:62
const intptr_t kBytesPerBigIntDigit
Definition: globals.h:54
constexpr intptr_t kWordSize
Definition: globals.h:509
const intptr_t kSmiBits32
Definition: globals.h:32
const intptr_t kSmiMin
Definition: globals.h:29
const intptr_t kMaxAddrSpaceInWords
Definition: globals.h:50
const intptr_t kMaxAddrSpaceMB
Definition: globals.h:49