blob: 8d37b8ad02ceedaf32350a308473c7214f80498b [file] [log] [blame]
David Sehr67bf42e2018-02-26 16:43:04 -08001/*
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.
Eric Holkf1e1dd12020-08-21 15:38:12 -070039static constexpr size_t kPageSize = 4096;
David Sehr67bf42e2018-02-26 16:43:04 -080040
David Sehr67bf42e2018-02-26 16:43:04 -080041// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
42// returns the same value. By wrapping into a call to another constexpr function, we force it
43// to realize that is not actually always evaluating to the same value.
44static constexpr bool GlobalsReturnSelf(bool self) { return self; }
45
46// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
47// TODO: Use only __clang_analyzer__ here. b/64455231
48#if defined(NDEBUG) && !defined(__CLION_IDE__)
49static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
50#else
51static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
52#endif
53
54#if defined(ART_PGO_INSTRUMENTATION)
55static constexpr bool kIsPGOInstrumentation = true;
56#else
57static constexpr bool kIsPGOInstrumentation = false;
58#endif
59
60// ART_TARGET - Defined for target builds of ART.
61// ART_TARGET_LINUX - Defined for target Linux builds of ART.
62// ART_TARGET_ANDROID - Defined for target Android builds of ART.
Steve Austin882ed6b2018-06-08 11:40:38 -070063// ART_TARGET_FUCHSIA - Defined for Fuchsia builds of ART.
64// Note: Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA
65// need to be set when ART_TARGET is set.
David Sehr67bf42e2018-02-26 16:43:04 -080066// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
67// (usually only available on Android kernels).
68#if defined(ART_TARGET)
69// Useful in conditionals where ART_TARGET isn't.
70static constexpr bool kIsTargetBuild = true;
71# if defined(ART_TARGET_LINUX)
72static constexpr bool kIsTargetLinux = true;
Steve Austin882ed6b2018-06-08 11:40:38 -070073static constexpr bool kIsTargetFuchsia = false;
Jiakai Zhang015665f2022-02-07 16:12:57 +000074static constexpr bool kIsTargetAndroid = false;
David Sehr67bf42e2018-02-26 16:43:04 -080075# elif defined(ART_TARGET_ANDROID)
76static constexpr bool kIsTargetLinux = false;
Steve Austin882ed6b2018-06-08 11:40:38 -070077static constexpr bool kIsTargetFuchsia = false;
Jiakai Zhang015665f2022-02-07 16:12:57 +000078static constexpr bool kIsTargetAndroid = true;
Steve Austin882ed6b2018-06-08 11:40:38 -070079# elif defined(ART_TARGET_FUCHSIA)
80static constexpr bool kIsTargetLinux = false;
81static constexpr bool kIsTargetFuchsia = true;
Jiakai Zhang015665f2022-02-07 16:12:57 +000082static constexpr bool kIsTargetAndroid = false;
David Sehr67bf42e2018-02-26 16:43:04 -080083# else
Steve Austin882ed6b2018-06-08 11:40:38 -070084# error "Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA " \
85 "needs to be defined for target builds."
David Sehr67bf42e2018-02-26 16:43:04 -080086# endif
87#else
88static constexpr bool kIsTargetBuild = false;
89# if defined(ART_TARGET_LINUX)
90# error "ART_TARGET_LINUX defined for host build."
91# elif defined(ART_TARGET_ANDROID)
92# error "ART_TARGET_ANDROID defined for host build."
Steve Austin882ed6b2018-06-08 11:40:38 -070093# elif defined(ART_TARGET_FUCHSIA)
94# error "ART_TARGET_FUCHSIA defined for host build."
David Sehr67bf42e2018-02-26 16:43:04 -080095# else
96static constexpr bool kIsTargetLinux = false;
Steve Austin882ed6b2018-06-08 11:40:38 -070097static constexpr bool kIsTargetFuchsia = false;
Jiakai Zhang015665f2022-02-07 16:12:57 +000098static constexpr bool kIsTargetAndroid = false;
David Sehr67bf42e2018-02-26 16:43:04 -080099# endif
100#endif
101
102// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
103// always available on the host
104#if !defined(ART_TARGET)
105static constexpr bool kHostStaticBuildEnabled = true;
106#else
107static constexpr bool kHostStaticBuildEnabled = false;
108#endif
109
David Sehr67bf42e2018-02-26 16:43:04 -0800110} // namespace art
111
112#endif // ART_LIBARTBASE_BASE_GLOBALS_H_