globals.h revision 345c4b19758703793ed31024cfb79940e2c63b75
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 25namespace art { 26 27typedef uint8_t byte; 28typedef intptr_t word; 29typedef uintptr_t uword; 30 31static constexpr size_t KB = 1024; 32static constexpr size_t MB = KB * KB; 33static constexpr size_t GB = KB * KB * KB; 34 35// Runtime sizes. 36static constexpr size_t kWordSize = sizeof(word); 37static constexpr size_t kPointerSize = sizeof(void*); 38 39static constexpr size_t kBitsPerByte = 8; 40static constexpr size_t kBitsPerByteLog2 = 3; 41static constexpr int kBitsPerWord = kWordSize * kBitsPerByte; 42static constexpr size_t kWordHighBitMask = static_cast<size_t>(1) << (kBitsPerWord - 1); 43 44// Required stack alignment 45static 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. 49static constexpr int kPageSize = 4096; 50 51// Required object alignment 52static constexpr size_t kObjectAlignment = 8; 53static 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) 57static constexpr bool kIsDebugBuild = false; 58#else 59static 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) 64static constexpr bool kIsTargetBuild = true; 65#else 66static constexpr bool kIsTargetBuild = false; 67#endif 68 69#if defined(ART_USE_PORTABLE_COMPILER) 70static constexpr bool kUsePortableCompiler = true; 71#else 72static constexpr bool kUsePortableCompiler = false; 73#endif 74 75// Garbage collector constants. 76static constexpr bool kMovingCollector = true && !kUsePortableCompiler; 77static constexpr bool kMarkCompactSupport = false && kMovingCollector; 78// True if we allow moving field arrays, this can cause complication with mark compact. 79static constexpr bool kMoveFieldArrays = !kMarkCompactSupport; 80// True if we allow moving classes. 81static constexpr bool kMovingClasses = !kMarkCompactSupport; 82// True if we allow moving fields. 83static constexpr bool kMovingFields = false; 84// True if we allow moving methods. 85static constexpr bool kMovingMethods = false; 86 87// If true, the quick compiler embeds class pointers in the compiled 88// code, if possible. 89static constexpr bool kEmbedClassInCode = true; 90 91#ifdef USE_BAKER_READ_BARRIER 92static constexpr bool kUseBakerReadBarrier = true; 93#else 94static constexpr bool kUseBakerReadBarrier = false; 95#endif 96 97#ifdef USE_BROOKS_READ_BARRIER 98static constexpr bool kUseBrooksReadBarrier = true; 99#else 100static constexpr bool kUseBrooksReadBarrier = false; 101#endif 102 103static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier; 104 105// If true, references within the heap are poisoned (negated). 106static constexpr bool kPoisonHeapReferences = false; 107 108// Kinds of tracing clocks. 109enum TraceClockSource { 110 kTraceClockSourceThreadCpu, 111 kTraceClockSourceWall, 112 kTraceClockSourceDual, // Both wall and thread CPU clocks. 113}; 114 115#if defined(HAVE_POSIX_CLOCKS) 116static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceDual; 117#else 118static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceWall; 119#endif 120 121static constexpr bool kDefaultMustRelocate = true; 122 123} // namespace art 124 125#endif // ART_RUNTIME_GLOBALS_H_ 126