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 typedef uint8_t byte; 28 typedef intptr_t word; 29 typedef uintptr_t uword; 30 31 static constexpr size_t KB = 1024; 32 static constexpr size_t MB = KB * KB; 33 static constexpr size_t GB = KB * KB * KB; 34 35 // Runtime sizes. 36 static constexpr size_t kWordSize = sizeof(word); 37 static constexpr size_t kPointerSize = sizeof(void*); 38 39 static constexpr size_t kBitsPerByte = 8; 40 static constexpr size_t kBitsPerByteLog2 = 3; 41 static constexpr int kBitsPerWord = kWordSize * kBitsPerByte; 42 static constexpr size_t kWordHighBitMask = static_cast<size_t>(1) << (kBitsPerWord - 1); 43 44 // Required stack alignment 45 static constexpr size_t kStackAlignment = 16; 46 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. 49 static constexpr int kPageSize = 4096; 50 51 // Required object alignment 52 static constexpr size_t kObjectAlignment = 8; 53 static constexpr size_t kLargeObjectAlignment = kPageSize; 54 55 // Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't. 56 #if defined(NDEBUG) 57 static constexpr bool kIsDebugBuild = false; 58 #else 59 static constexpr bool kIsDebugBuild = true; 60 #endif 61 62 // Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't. 63 #if defined(ART_TARGET) 64 static constexpr bool kIsTargetBuild = true; 65 #else 66 static constexpr bool kIsTargetBuild = false; 67 #endif 68 69 #if defined(ART_USE_PORTABLE_COMPILER) 70 static constexpr bool kUsePortableCompiler = true; 71 #else 72 static constexpr bool kUsePortableCompiler = false; 73 #endif 74 75 // Garbage collector constants. 76 static constexpr bool kMovingCollector = true && !kUsePortableCompiler; 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; 80 // True if we allow moving classes. 81 static constexpr bool kMovingClasses = !kMarkCompactSupport; 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 87 // If true, the quick compiler embeds class pointers in the compiled 88 // code, if possible. 89 static constexpr bool kEmbedClassInCode = true; 90 91 #ifdef USE_BAKER_READ_BARRIER 92 static constexpr bool kUseBakerReadBarrier = true; 93 #else 94 static constexpr bool kUseBakerReadBarrier = false; 95 #endif 96 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 105 // If true, references within the heap are poisoned (negated). 106 static constexpr bool kPoisonHeapReferences = false; 107 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 121 static constexpr bool kDefaultMustRelocate = true; 122 123 } // namespace art 124 125 #endif // ART_RUNTIME_GLOBALS_H_ 126