blob: 4103154db18921b1dff8913a4f71bc07697d52fd [file] [log] [blame]
Martin Stjernholmc15e7e42020-12-02 22:50:53 +00001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_LIBARTBASE_BASE_GLOBALS_H_
18#define ART_LIBARTBASE_BASE_GLOBALS_H_
19
20#include <stddef.h>
21#include <stdint.h>
22
23namespace art {
24
25static constexpr size_t KB = 1024;
26static constexpr size_t MB = KB * KB;
27static constexpr size_t GB = KB * KB * KB;
28
29// Runtime sizes.
30static constexpr size_t kBitsPerByte = 8;
31static constexpr size_t kBitsPerByteLog2 = 3;
32static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
33
34// Required stack alignment
35static constexpr size_t kStackAlignment = 16;
36
37// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
38// compile-time constant so the compiler can generate better code.
39static constexpr size_t kPageSize = 4096;
40
Fairphone ODM25c12f52023-12-15 17:24:06 +080041// TODO: Kernels for arm and x86 in both, 32-bit and 64-bit modes use 512 entries per page-table
42// page. Find a way to confirm that in userspace.
43// Address range covered by 1 Page Middle Directory (PMD) entry in the page table
44static constexpr size_t kPMDSize = (kPageSize / sizeof(uint64_t)) * kPageSize;
45// Address range covered by 1 Page Upper Directory (PUD) entry in the page table
46static constexpr size_t kPUDSize = (kPageSize / sizeof(uint64_t)) * kPMDSize;
47// Returns the ideal alignment corresponding to page-table levels for the
48// given size.
49static constexpr size_t BestPageTableAlignment(size_t size) {
50 return size < kPUDSize ? kPMDSize : kPUDSize;
51}
Martin Stjernholmc15e7e42020-12-02 22:50:53 +000052// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
53// returns the same value. By wrapping into a call to another constexpr function, we force it
54// to realize that is not actually always evaluating to the same value.
55static constexpr bool GlobalsReturnSelf(bool self) { return self; }
56
57// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
58// TODO: Use only __clang_analyzer__ here. b/64455231
59#if defined(NDEBUG) && !defined(__CLION_IDE__)
60static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
61#else
62static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
63#endif
64
65#if defined(ART_PGO_INSTRUMENTATION)
66static constexpr bool kIsPGOInstrumentation = true;
67#else
68static constexpr bool kIsPGOInstrumentation = false;
69#endif
70
71// ART_TARGET - Defined for target builds of ART.
72// ART_TARGET_LINUX - Defined for target Linux builds of ART.
73// ART_TARGET_ANDROID - Defined for target Android builds of ART.
74// ART_TARGET_FUCHSIA - Defined for Fuchsia builds of ART.
75// Note: Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA
76// need to be set when ART_TARGET is set.
77// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
78// (usually only available on Android kernels).
79#if defined(ART_TARGET)
80// Useful in conditionals where ART_TARGET isn't.
81static constexpr bool kIsTargetBuild = true;
82# if defined(ART_TARGET_LINUX)
83static constexpr bool kIsTargetLinux = true;
84static constexpr bool kIsTargetFuchsia = false;
satayev499be972022-05-13 15:05:39 +000085static constexpr bool kIsTargetAndroid = false;
Martin Stjernholmc15e7e42020-12-02 22:50:53 +000086# elif defined(ART_TARGET_ANDROID)
87static constexpr bool kIsTargetLinux = false;
88static constexpr bool kIsTargetFuchsia = false;
satayev499be972022-05-13 15:05:39 +000089static constexpr bool kIsTargetAndroid = true;
Martin Stjernholmc15e7e42020-12-02 22:50:53 +000090# elif defined(ART_TARGET_FUCHSIA)
91static constexpr bool kIsTargetLinux = false;
92static constexpr bool kIsTargetFuchsia = true;
satayev499be972022-05-13 15:05:39 +000093static constexpr bool kIsTargetAndroid = false;
Martin Stjernholmc15e7e42020-12-02 22:50:53 +000094# else
95# error "Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA " \
96 "needs to be defined for target builds."
97# endif
98#else
99static constexpr bool kIsTargetBuild = false;
100# if defined(ART_TARGET_LINUX)
101# error "ART_TARGET_LINUX defined for host build."
102# elif defined(ART_TARGET_ANDROID)
103# error "ART_TARGET_ANDROID defined for host build."
104# elif defined(ART_TARGET_FUCHSIA)
105# error "ART_TARGET_FUCHSIA defined for host build."
106# else
107static constexpr bool kIsTargetLinux = false;
108static constexpr bool kIsTargetFuchsia = false;
satayev499be972022-05-13 15:05:39 +0000109static constexpr bool kIsTargetAndroid = false;
Martin Stjernholmc15e7e42020-12-02 22:50:53 +0000110# endif
111#endif
112
113// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
114// always available on the host
115#if !defined(ART_TARGET)
116static constexpr bool kHostStaticBuildEnabled = true;
117#else
118static constexpr bool kHostStaticBuildEnabled = false;
119#endif
120
Fairphone ODM25c12f52023-12-15 17:24:06 +0800121// System property for phenotype flag to test disabling compact dex and in
122// particular dexlayout.
123// TODO(b/256664509): Clean this up.
124static constexpr char kPhDisableCompactDex[] =
125 "persist.device_config.runtime_native_boot.disable_compact_dex";
126
Martin Stjernholmc15e7e42020-12-02 22:50:53 +0000127} // namespace art
128
129#endif // ART_LIBARTBASE_BASE_GLOBALS_H_