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_RUNTIME_GLOBALS_H_ 18 #define ART_RUNTIME_GLOBALS_H_ 19 20 #include <stddef.h> 21 #include <stdint.h> 22 #include "read_barrier_c.h" 23 #include "read_barrier_option.h" 24 25 namespace art { 26 27 static constexpr size_t KB = 1024; 28 static constexpr size_t MB = KB * KB; 29 static constexpr size_t GB = KB * KB * KB; 30 31 // Runtime sizes. 32 static constexpr size_t kBitsPerByte = 8; 33 static constexpr size_t kBitsPerByteLog2 = 3; 34 static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte; 35 36 // Required stack alignment 37 static constexpr size_t kStackAlignment = 16; 38 39 // System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple 40 // compile-time constant so the compiler can generate better code. 41 static constexpr int kPageSize = 4096; 42 43 // Returns whether the given memory offset can be used for generating 44 // an implicit null check. 45 static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) { 46 return offset < kPageSize; 47 } 48 49 // Required object alignment 50 static constexpr size_t kObjectAlignmentShift = 3; 51 static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift; 52 static constexpr size_t kLargeObjectAlignment = kPageSize; 53 54 // Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't. 55 #if defined(NDEBUG) 56 static constexpr bool kIsDebugBuild = false; 57 #else 58 static constexpr bool kIsDebugBuild = true; 59 #endif 60 61 // ART_TARGET - Defined for target builds of ART. 62 // ART_TARGET_LINUX - Defined for target Linux builds of ART. 63 // ART_TARGET_ANDROID - Defined for target Android builds of ART. 64 // Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set. 65 // Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings 66 // (usually only available on Android kernels). 67 #if defined(ART_TARGET) 68 // Useful in conditionals where ART_TARGET isn't. 69 static constexpr bool kIsTargetBuild = true; 70 # if defined(ART_TARGET_LINUX) 71 static constexpr bool kIsTargetLinux = true; 72 # elif defined(ART_TARGET_ANDROID) 73 static constexpr bool kIsTargetLinux = false; 74 # else 75 # error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds." 76 # endif 77 #else 78 static constexpr bool kIsTargetBuild = false; 79 # if defined(ART_TARGET_LINUX) 80 # error "ART_TARGET_LINUX defined for host build." 81 # elif defined(ART_TARGET_ANDROID) 82 # error "ART_TARGET_ANDROID defined for host build." 83 # else 84 static constexpr bool kIsTargetLinux = false; 85 # endif 86 #endif 87 88 // Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are 89 // always available on the host 90 #if !defined(ART_TARGET) 91 static constexpr bool kHostStaticBuildEnabled = true; 92 #else 93 static constexpr bool kHostStaticBuildEnabled = false; 94 #endif 95 96 // Garbage collector constants. 97 static constexpr bool kMovingCollector = true; 98 static constexpr bool kMarkCompactSupport = false && kMovingCollector; 99 // True if we allow moving classes. 100 static constexpr bool kMovingClasses = !kMarkCompactSupport; 101 102 // If true, the quick compiler embeds class pointers in the compiled 103 // code, if possible. 104 static constexpr bool kEmbedClassInCode = true; 105 106 #ifdef USE_BAKER_READ_BARRIER 107 static constexpr bool kUseBakerReadBarrier = true; 108 #else 109 static constexpr bool kUseBakerReadBarrier = false; 110 #endif 111 112 #ifdef USE_BROOKS_READ_BARRIER 113 static constexpr bool kUseBrooksReadBarrier = true; 114 #else 115 static constexpr bool kUseBrooksReadBarrier = false; 116 #endif 117 118 #ifdef USE_TABLE_LOOKUP_READ_BARRIER 119 static constexpr bool kUseTableLookupReadBarrier = true; 120 #else 121 static constexpr bool kUseTableLookupReadBarrier = false; 122 #endif 123 124 static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier; 125 static constexpr bool kUseReadBarrier = 126 kUseBakerReadBarrier || kUseBrooksReadBarrier || kUseTableLookupReadBarrier; 127 128 // Debugging flag that forces the generation of read barriers, but 129 // does not trigger the use of the concurrent copying GC. 130 // 131 // TODO: Remove this flag when the read barriers compiler 132 // instrumentation is completed. 133 static constexpr bool kForceReadBarrier = false; 134 // TODO: Likewise, remove this flag when kForceReadBarrier is removed 135 // and replace it with kUseReadBarrier. 136 static constexpr bool kEmitCompilerReadBarrier = kForceReadBarrier || kUseReadBarrier; 137 138 // If true, references within the heap are poisoned (negated). 139 #ifdef USE_HEAP_POISONING 140 static constexpr bool kPoisonHeapReferences = true; 141 #else 142 static constexpr bool kPoisonHeapReferences = false; 143 #endif 144 145 // If true, enable the tlab allocator by default. 146 #ifdef ART_USE_TLAB 147 static constexpr bool kUseTlab = true; 148 #else 149 static constexpr bool kUseTlab = false; 150 #endif 151 152 // Kinds of tracing clocks. 153 enum class TraceClockSource { 154 kThreadCpu, 155 kWall, 156 kDual, // Both wall and thread CPU clocks. 157 }; 158 159 #if defined(__linux__) 160 static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual; 161 #else 162 static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall; 163 #endif 164 165 static constexpr bool kDefaultMustRelocate = true; 166 167 static constexpr bool kArm32QuickCodeUseSoftFloat = false; 168 169 #ifdef ART_ENABLE_VDEX 170 static constexpr bool kIsVdexEnabled = true; 171 #else 172 static constexpr bool kIsVdexEnabled = false; 173 #endif 174 175 // Size of a heap reference. 176 static constexpr size_t kHeapReferenceSize = sizeof(uint32_t); 177 178 } // namespace art 179 180 #endif // ART_RUNTIME_GLOBALS_H_ 181