globals.h revision be1ca55db3362f5b100c4c65da5342fd299520bb
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 23namespace art { 24 25typedef uint8_t byte; 26typedef intptr_t word; 27typedef uintptr_t uword; 28 29static constexpr size_t KB = 1024; 30static constexpr size_t MB = KB * KB; 31static constexpr size_t GB = KB * KB * KB; 32 33static constexpr size_t kWordSize = sizeof(word); 34static constexpr size_t kPointerSize = sizeof(void*); 35 36static constexpr size_t kBitsPerByte = 8; 37static constexpr size_t kBitsPerByteLog2 = 3; 38static constexpr int kBitsPerWord = kWordSize * kBitsPerByte; 39static constexpr size_t kWordHighBitMask = 1 << (kBitsPerWord - 1); 40 41// Required stack alignment 42static constexpr size_t kStackAlignment = 16; 43 44// Required object alignment 45static constexpr size_t kObjectAlignment = 8; 46 47// ARM instruction alignment. ARM processors require code to be 4-byte aligned, 48// but ARM ELF requires 8.. 49static constexpr size_t kArmAlignment = 8; 50 51// MIPS instruction alignment. MIPS processors require code to be 4-byte aligned. 52// TODO: Can this be 4? 53static constexpr size_t kMipsAlignment = 8; 54 55// X86 instruction alignment. This is the recommended alignment for maximum performance. 56static constexpr size_t kX86Alignment = 16; 57 58// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple 59// compile-time constant so the compiler can generate better code. 60static constexpr int kPageSize = 4096; 61 62// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't. 63#if defined(NDEBUG) 64static constexpr bool kIsDebugBuild = false; 65#else 66static constexpr bool kIsDebugBuild = true; 67#endif 68 69// Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't. 70#if defined(ART_TARGET) 71static constexpr bool kIsTargetBuild = true; 72#else 73static constexpr bool kIsTargetBuild = false; 74#endif 75 76#if defined(ART_USE_PORTABLE_COMPILER) 77static constexpr bool kUsePortableCompiler = true; 78#else 79static constexpr bool kUsePortableCompiler = false; 80#endif 81 82// Garbage collector constants. 83static constexpr bool kMovingCollector = true && !kUsePortableCompiler; 84// True if we allow moving classes. 85static constexpr bool kMovingClasses = true; 86// True if we allow moving fields. 87static constexpr bool kMovingFields = false; 88// True if we allow moving methods. 89static constexpr bool kMovingMethods = false; 90 91// If true, the quick compiler embeds class pointers in the compiled 92// code, if possible. 93static constexpr bool kEmbedClassInCode = true; 94 95} // namespace art 96 97#endif // ART_RUNTIME_GLOBALS_H_ 98