Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -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 | */ |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_GLOBALS_H_ |
| 18 | #define ART_RUNTIME_GLOBALS_H_ |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 19 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 20 | #include <stddef.h> |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
Hiroshi Yamauchi | 800ac2d | 2014-04-02 17:32:54 -0700 | [diff] [blame] | 22 | #include "read_barrier_c.h" |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 23 | #include "read_barrier_option.h" |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 24 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 25 | namespace art { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 26 | |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 27 | static constexpr size_t KB = 1024; |
| 28 | static constexpr size_t MB = KB * KB; |
| 29 | static constexpr size_t GB = KB * KB * KB; |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 30 | |
Andreas Gampe | 242947d | 2014-04-03 13:31:32 -0700 | [diff] [blame] | 31 | // Runtime sizes. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 32 | static constexpr size_t kBitsPerByte = 8; |
| 33 | static constexpr size_t kBitsPerByteLog2 = 3; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 34 | static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte; |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 35 | |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 36 | // Required stack alignment |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 37 | static constexpr size_t kStackAlignment = 16; |
Brian Carlstrom | 0024d6c | 2011-08-09 08:26:12 -0700 | [diff] [blame] | 38 | |
Elliott Hughes | 942df41 | 2012-03-26 09:46:56 -0700 | [diff] [blame] | 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. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 41 | static constexpr int kPageSize = 4096; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 42 | |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 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 | |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 49 | // Required object alignment |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 50 | static constexpr size_t kObjectAlignmentShift = 3; |
| 51 | static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift; |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 52 | static constexpr size_t kLargeObjectAlignment = kPageSize; |
| 53 | |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 54 | // Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't. |
| 55 | #if defined(NDEBUG) |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 56 | static constexpr bool kIsDebugBuild = false; |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 57 | #else |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 58 | static constexpr bool kIsDebugBuild = true; |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 59 | #endif |
| 60 | |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 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). |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 67 | #if defined(ART_TARGET) |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 68 | // Useful in conditionals where ART_TARGET isn't. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 69 | static constexpr bool kIsTargetBuild = true; |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 70 | # if defined(ART_TARGET_LINUX) |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 71 | static constexpr bool kIsTargetLinux = true; |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 72 | # elif defined(ART_TARGET_ANDROID) |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 73 | static constexpr bool kIsTargetLinux = false; |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 74 | # else |
| 75 | # error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds." |
| 76 | # endif |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 77 | #else |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 78 | static constexpr bool kIsTargetBuild = false; |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 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 |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 84 | static constexpr bool kIsTargetLinux = false; |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 85 | # endif |
Bilyan Borisov | 3071f80 | 2016-03-31 17:15:53 +0100 | [diff] [blame] | 86 | #endif |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 87 | |
Colin Cross | b20be21 | 2016-09-19 13:02:47 -0700 | [diff] [blame] | 88 | // Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are |
| 89 | // always available on the host |
| 90 | #if !defined(ART_TARGET) |
Roland Levillain | 04147ef | 2016-09-06 11:09:41 +0100 | [diff] [blame] | 91 | static constexpr bool kHostStaticBuildEnabled = true; |
| 92 | #else |
| 93 | static constexpr bool kHostStaticBuildEnabled = false; |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 96 | // Garbage collector constants. |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 97 | static constexpr bool kMovingCollector = true; |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 98 | static constexpr bool kMarkCompactSupport = false && kMovingCollector; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 99 | // True if we allow moving classes. |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 100 | static constexpr bool kMovingClasses = !kMarkCompactSupport; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 101 | |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 102 | // If true, the quick compiler embeds class pointers in the compiled |
| 103 | // code, if possible. |
| 104 | static constexpr bool kEmbedClassInCode = true; |
| 105 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 106 | #ifdef USE_BAKER_READ_BARRIER |
| 107 | static constexpr bool kUseBakerReadBarrier = true; |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 108 | #else |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 109 | static constexpr bool kUseBakerReadBarrier = false; |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 110 | #endif |
| 111 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 112 | #ifdef USE_BROOKS_READ_BARRIER |
| 113 | static constexpr bool kUseBrooksReadBarrier = true; |
| 114 | #else |
| 115 | static constexpr bool kUseBrooksReadBarrier = false; |
| 116 | #endif |
| 117 | |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 118 | #ifdef USE_TABLE_LOOKUP_READ_BARRIER |
| 119 | static constexpr bool kUseTableLookupReadBarrier = true; |
| 120 | #else |
| 121 | static constexpr bool kUseTableLookupReadBarrier = false; |
| 122 | #endif |
| 123 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 124 | static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 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; |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 137 | |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 138 | // If true, references within the heap are poisoned (negated). |
Hiroshi Yamauchi | bfa5eb6 | 2015-05-29 15:04:41 -0700 | [diff] [blame] | 139 | #ifdef USE_HEAP_POISONING |
Hiroshi Yamauchi | b0d22f1 | 2014-12-08 12:08:46 -0800 | [diff] [blame] | 140 | static constexpr bool kPoisonHeapReferences = true; |
| 141 | #else |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 142 | static constexpr bool kPoisonHeapReferences = false; |
Hiroshi Yamauchi | b0d22f1 | 2014-12-08 12:08:46 -0800 | [diff] [blame] | 143 | #endif |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 144 | |
Hiroshi Yamauchi | 79bd2bf | 2015-03-20 10:28:34 -0700 | [diff] [blame] | 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 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 152 | // Kinds of tracing clocks. |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 153 | enum class TraceClockSource { |
| 154 | kThreadCpu, |
| 155 | kWall, |
| 156 | kDual, // Both wall and thread CPU clocks. |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 159 | #if defined(__linux__) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 160 | static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 161 | #else |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 162 | static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 163 | #endif |
| 164 | |
Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 165 | static constexpr bool kDefaultMustRelocate = true; |
| 166 | |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 167 | static constexpr bool kArm32QuickCodeUseSoftFloat = false; |
| 168 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 169 | #ifdef ART_ENABLE_VDEX |
| 170 | static constexpr bool kIsVdexEnabled = true; |
| 171 | #else |
| 172 | static constexpr bool kIsVdexEnabled = false; |
| 173 | #endif |
| 174 | |
Mathieu Chartier | a058fdf | 2016-10-06 15:13:58 -0700 | [diff] [blame] | 175 | // Size of a heap reference. |
| 176 | static constexpr size_t kHeapReferenceSize = sizeof(uint32_t); |
| 177 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 178 | } // namespace art |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 179 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 180 | #endif // ART_RUNTIME_GLOBALS_H_ |