blob: bc79ff28809879702e6920b1a826273a042cf512 [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.
39static constexpr int kPageSize = 4096;
40
David Srbeckyb674a142018-05-21 10:27:06 +000041// Size of Dex virtual registers.
42static constexpr size_t kVRegSize = 4;
43
David Sehr67bf42e2018-02-26 16:43:04 -080044// Returns whether the given memory offset can be used for generating
45// an implicit null check.
46static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
47 return offset < kPageSize;
48}
49
50// Required object alignment
51static constexpr size_t kObjectAlignmentShift = 3;
52static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
53static constexpr size_t kLargeObjectAlignment = kPageSize;
54
55// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
56// returns the same value. By wrapping into a call to another constexpr function, we force it
57// to realize that is not actually always evaluating to the same value.
58static constexpr bool GlobalsReturnSelf(bool self) { return self; }
59
60// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
61// TODO: Use only __clang_analyzer__ here. b/64455231
62#if defined(NDEBUG) && !defined(__CLION_IDE__)
63static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
64#else
65static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
66#endif
67
68#if defined(ART_PGO_INSTRUMENTATION)
69static constexpr bool kIsPGOInstrumentation = true;
70#else
71static constexpr bool kIsPGOInstrumentation = false;
72#endif
73
74// ART_TARGET - Defined for target builds of ART.
75// ART_TARGET_LINUX - Defined for target Linux builds of ART.
76// ART_TARGET_ANDROID - Defined for target Android builds of ART.
Steve Austin882ed6b2018-06-08 11:40:38 -070077// ART_TARGET_FUCHSIA - Defined for Fuchsia builds of ART.
78// Note: Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA
79// need to be set when ART_TARGET is set.
David Sehr67bf42e2018-02-26 16:43:04 -080080// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
81// (usually only available on Android kernels).
82#if defined(ART_TARGET)
83// Useful in conditionals where ART_TARGET isn't.
84static constexpr bool kIsTargetBuild = true;
85# if defined(ART_TARGET_LINUX)
86static constexpr bool kIsTargetLinux = true;
Steve Austin882ed6b2018-06-08 11:40:38 -070087static constexpr bool kIsTargetFuchsia = false;
David Sehr67bf42e2018-02-26 16:43:04 -080088# elif defined(ART_TARGET_ANDROID)
89static constexpr bool kIsTargetLinux = false;
Steve Austin882ed6b2018-06-08 11:40:38 -070090static constexpr bool kIsTargetFuchsia = false;
91# elif defined(ART_TARGET_FUCHSIA)
92static constexpr bool kIsTargetLinux = false;
93static constexpr bool kIsTargetFuchsia = true;
David Sehr67bf42e2018-02-26 16:43:04 -080094# else
Steve Austin882ed6b2018-06-08 11:40:38 -070095# error "Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA " \
96 "needs to be defined for target builds."
David Sehr67bf42e2018-02-26 16:43:04 -080097# 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."
Steve Austin882ed6b2018-06-08 11:40:38 -0700104# elif defined(ART_TARGET_FUCHSIA)
105# error "ART_TARGET_FUCHSIA defined for host build."
David Sehr67bf42e2018-02-26 16:43:04 -0800106# else
107static constexpr bool kIsTargetLinux = false;
Steve Austin882ed6b2018-06-08 11:40:38 -0700108static constexpr bool kIsTargetFuchsia = false;
David Sehr67bf42e2018-02-26 16:43:04 -0800109# endif
110#endif
111
112// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
113// always available on the host
114#if !defined(ART_TARGET)
115static constexpr bool kHostStaticBuildEnabled = true;
116#else
117static constexpr bool kHostStaticBuildEnabled = false;
118#endif
119
120// Garbage collector constants.
121static constexpr bool kMovingCollector = true;
122static constexpr bool kMarkCompactSupport = false && kMovingCollector;
123// True if we allow moving classes.
124static constexpr bool kMovingClasses = !kMarkCompactSupport;
Mathieu Chartier8d1a9962016-08-17 16:39:45 -0700125// If true, enable generational collection when using the Concurrent Copying
126// collector, i.e. use sticky-bit CC for minor collections and (full) CC for
127// major collections.
128#ifdef ART_USE_GENERATIONAL_CC
129static constexpr bool kEnableGenerationalConcurrentCopyingCollection = true;
130#else
131static constexpr bool kEnableGenerationalConcurrentCopyingCollection = false;
132#endif
David Sehr67bf42e2018-02-26 16:43:04 -0800133
134// If true, enable the tlab allocator by default.
135#ifdef ART_USE_TLAB
136static constexpr bool kUseTlab = true;
137#else
138static constexpr bool kUseTlab = false;
139#endif
140
141// Kinds of tracing clocks.
142enum class TraceClockSource {
143 kThreadCpu,
144 kWall,
145 kDual, // Both wall and thread CPU clocks.
146};
147
148#if defined(__linux__)
149static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
150#else
151static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
152#endif
153
154static constexpr bool kDefaultMustRelocate = true;
155
156// Size of a heap reference.
157static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
158
159} // namespace art
160
161#endif // ART_LIBARTBASE_BASE_GLOBALS_H_