David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace art { |
| 24 | |
| 25 | static constexpr size_t KB = 1024; |
| 26 | static constexpr size_t MB = KB * KB; |
| 27 | static constexpr size_t GB = KB * KB * KB; |
| 28 | |
| 29 | // Runtime sizes. |
| 30 | static constexpr size_t kBitsPerByte = 8; |
| 31 | static constexpr size_t kBitsPerByteLog2 = 3; |
| 32 | static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte; |
| 33 | |
| 34 | // Required stack alignment |
| 35 | static 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. |
| 39 | static constexpr int kPageSize = 4096; |
| 40 | |
David Srbecky | b674a14 | 2018-05-21 10:27:06 +0000 | [diff] [blame] | 41 | // Size of Dex virtual registers. |
| 42 | static constexpr size_t kVRegSize = 4; |
| 43 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 44 | // Returns whether the given memory offset can be used for generating |
| 45 | // an implicit null check. |
| 46 | static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) { |
| 47 | return offset < kPageSize; |
| 48 | } |
| 49 | |
| 50 | // Required object alignment |
| 51 | static constexpr size_t kObjectAlignmentShift = 3; |
| 52 | static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift; |
| 53 | static 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. |
| 58 | static 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__) |
| 63 | static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false); |
| 64 | #else |
| 65 | static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true); |
| 66 | #endif |
| 67 | |
| 68 | #if defined(ART_PGO_INSTRUMENTATION) |
| 69 | static constexpr bool kIsPGOInstrumentation = true; |
| 70 | #else |
| 71 | static 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 Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 77 | // 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 Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 80 | // 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. |
| 84 | static constexpr bool kIsTargetBuild = true; |
| 85 | # if defined(ART_TARGET_LINUX) |
| 86 | static constexpr bool kIsTargetLinux = true; |
Steve Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 87 | static constexpr bool kIsTargetFuchsia = false; |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 88 | # elif defined(ART_TARGET_ANDROID) |
| 89 | static constexpr bool kIsTargetLinux = false; |
Steve Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 90 | static constexpr bool kIsTargetFuchsia = false; |
| 91 | # elif defined(ART_TARGET_FUCHSIA) |
| 92 | static constexpr bool kIsTargetLinux = false; |
| 93 | static constexpr bool kIsTargetFuchsia = true; |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 94 | # else |
Steve Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 95 | # error "Either ART_TARGET_LINUX, ART_TARGET_ANDROID or ART_TARGET_FUCHSIA " \ |
| 96 | "needs to be defined for target builds." |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 97 | # endif |
| 98 | #else |
| 99 | static 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 Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 104 | # elif defined(ART_TARGET_FUCHSIA) |
| 105 | # error "ART_TARGET_FUCHSIA defined for host build." |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 106 | # else |
| 107 | static constexpr bool kIsTargetLinux = false; |
Steve Austin | 882ed6b | 2018-06-08 11:40:38 -0700 | [diff] [blame] | 108 | static constexpr bool kIsTargetFuchsia = false; |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 109 | # 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) |
| 115 | static constexpr bool kHostStaticBuildEnabled = true; |
| 116 | #else |
| 117 | static constexpr bool kHostStaticBuildEnabled = false; |
| 118 | #endif |
| 119 | |
| 120 | // Garbage collector constants. |
| 121 | static constexpr bool kMovingCollector = true; |
| 122 | static constexpr bool kMarkCompactSupport = false && kMovingCollector; |
| 123 | // True if we allow moving classes. |
| 124 | static constexpr bool kMovingClasses = !kMarkCompactSupport; |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 125 | // 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 |
| 129 | static constexpr bool kEnableGenerationalConcurrentCopyingCollection = true; |
| 130 | #else |
| 131 | static constexpr bool kEnableGenerationalConcurrentCopyingCollection = false; |
| 132 | #endif |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 133 | |
| 134 | // If true, enable the tlab allocator by default. |
| 135 | #ifdef ART_USE_TLAB |
| 136 | static constexpr bool kUseTlab = true; |
| 137 | #else |
| 138 | static constexpr bool kUseTlab = false; |
| 139 | #endif |
| 140 | |
| 141 | // Kinds of tracing clocks. |
| 142 | enum class TraceClockSource { |
| 143 | kThreadCpu, |
| 144 | kWall, |
| 145 | kDual, // Both wall and thread CPU clocks. |
| 146 | }; |
| 147 | |
| 148 | #if defined(__linux__) |
| 149 | static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual; |
| 150 | #else |
| 151 | static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall; |
| 152 | #endif |
| 153 | |
| 154 | static constexpr bool kDefaultMustRelocate = true; |
| 155 | |
| 156 | // Size of a heap reference. |
| 157 | static constexpr size_t kHeapReferenceSize = sizeof(uint32_t); |
| 158 | |
| 159 | } // namespace art |
| 160 | |
| 161 | #endif // ART_LIBARTBASE_BASE_GLOBALS_H_ |