globals.h revision 41c507a9dae44b8329a857da3d9810fab2e9ddc6
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; 77// True if we allow moving classes. 78static constexpr bool kMovingClasses = true; 79// True if we allow moving fields. 80static constexpr bool kMovingFields = false; 81// True if we allow moving methods. 82static constexpr bool kMovingMethods = false; 83 84// If true, the quick compiler embeds class pointers in the compiled 85// code, if possible. 86static constexpr bool kEmbedClassInCode = true; 87 88#ifdef USE_BAKER_READ_BARRIER 89static constexpr bool kUseBakerReadBarrier = true; 90#else 91static constexpr bool kUseBakerReadBarrier = false; 92#endif 93 94#ifdef USE_BROOKS_READ_BARRIER 95static constexpr bool kUseBrooksReadBarrier = true; 96#else 97static constexpr bool kUseBrooksReadBarrier = false; 98#endif 99 100static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier; 101 102// If true, references within the heap are poisoned (negated). 103static constexpr bool kPoisonHeapReferences = false; 104 105} // namespace art 106 107#endif // ART_RUNTIME_GLOBALS_H_ 108