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 | |
| 27 | typedef uint8_t byte; |
| 28 | typedef intptr_t word; |
| 29 | typedef uintptr_t uword; |
| 30 | |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 31 | static constexpr size_t KB = 1024; |
| 32 | static constexpr size_t MB = KB * KB; |
| 33 | static constexpr size_t GB = KB * KB * KB; |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 34 | |
Andreas Gampe | 242947d | 2014-04-03 13:31:32 -0700 | [diff] [blame] | 35 | // Runtime sizes. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 36 | static constexpr size_t kWordSize = sizeof(word); |
| 37 | static constexpr size_t kPointerSize = sizeof(void*); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 38 | |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 39 | static constexpr size_t kBitsPerByte = 8; |
| 40 | static constexpr size_t kBitsPerByteLog2 = 3; |
| 41 | static constexpr int kBitsPerWord = kWordSize * kBitsPerByte; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 42 | static constexpr size_t kWordHighBitMask = static_cast<size_t>(1) << (kBitsPerWord - 1); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 43 | |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 44 | // Required stack alignment |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 45 | static constexpr size_t kStackAlignment = 16; |
Brian Carlstrom | 0024d6c | 2011-08-09 08:26:12 -0700 | [diff] [blame] | 46 | |
Elliott Hughes | 942df41 | 2012-03-26 09:46:56 -0700 | [diff] [blame] | 47 | // System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple |
| 48 | // compile-time constant so the compiler can generate better code. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 49 | static constexpr int kPageSize = 4096; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 50 | |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 51 | // Required object alignment |
| 52 | static constexpr size_t kObjectAlignment = 8; |
| 53 | static constexpr size_t kLargeObjectAlignment = kPageSize; |
| 54 | |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 55 | // Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't. |
| 56 | #if defined(NDEBUG) |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 57 | static constexpr bool kIsDebugBuild = false; |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 58 | #else |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 59 | static constexpr bool kIsDebugBuild = true; |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 62 | // Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't. |
| 63 | #if defined(ART_TARGET) |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 64 | static constexpr bool kIsTargetBuild = true; |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 65 | #else |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 66 | static constexpr bool kIsTargetBuild = false; |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 67 | #endif |
| 68 | |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 69 | #if defined(ART_USE_PORTABLE_COMPILER) |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 70 | static constexpr bool kUsePortableCompiler = true; |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 71 | #else |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 72 | static constexpr bool kUsePortableCompiler = false; |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 73 | #endif |
| 74 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 75 | // Garbage collector constants. |
Mathieu Chartier | 5048223 | 2013-11-21 11:48:14 -0800 | [diff] [blame] | 76 | static constexpr bool kMovingCollector = true && !kUsePortableCompiler; |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 77 | static constexpr bool kMarkCompactSupport = false && kMovingCollector; |
| 78 | // True if we allow moving field arrays, this can cause complication with mark compact. |
| 79 | static constexpr bool kMoveFieldArrays = !kMarkCompactSupport; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 80 | // True if we allow moving classes. |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 81 | static constexpr bool kMovingClasses = !kMarkCompactSupport; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 82 | // True if we allow moving fields. |
| 83 | static constexpr bool kMovingFields = false; |
| 84 | // True if we allow moving methods. |
| 85 | static constexpr bool kMovingMethods = false; |
| 86 | |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 87 | // If true, the quick compiler embeds class pointers in the compiled |
| 88 | // code, if possible. |
| 89 | static constexpr bool kEmbedClassInCode = true; |
| 90 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 91 | #ifdef USE_BAKER_READ_BARRIER |
| 92 | static constexpr bool kUseBakerReadBarrier = true; |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 93 | #else |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 94 | static constexpr bool kUseBakerReadBarrier = false; |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 95 | #endif |
| 96 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 97 | #ifdef USE_BROOKS_READ_BARRIER |
| 98 | static constexpr bool kUseBrooksReadBarrier = true; |
| 99 | #else |
| 100 | static constexpr bool kUseBrooksReadBarrier = false; |
| 101 | #endif |
| 102 | |
| 103 | static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier; |
| 104 | |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 105 | // If true, references within the heap are poisoned (negated). |
| 106 | static constexpr bool kPoisonHeapReferences = false; |
| 107 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 108 | // Kinds of tracing clocks. |
| 109 | enum TraceClockSource { |
| 110 | kTraceClockSourceThreadCpu, |
| 111 | kTraceClockSourceWall, |
| 112 | kTraceClockSourceDual, // Both wall and thread CPU clocks. |
| 113 | }; |
| 114 | |
| 115 | #if defined(HAVE_POSIX_CLOCKS) |
| 116 | static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceDual; |
| 117 | #else |
| 118 | static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceWall; |
| 119 | #endif |
| 120 | |
Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 121 | static constexpr bool kDefaultMustRelocate = true; |
| 122 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 123 | } // namespace art |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 124 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 125 | #endif // ART_RUNTIME_GLOBALS_H_ |