blob: 7e85231d208036356860cf23bb61bff050c01de5 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GLOBALS_H_
18#define ART_RUNTIME_GLOBALS_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Carl Shapiro1fb86202011-06-27 17:43:13 -070020#include <stddef.h>
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070021#include <stdint.h>
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070022#include "read_barrier_c.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070023
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070024namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070025
26typedef uint8_t byte;
27typedef intptr_t word;
28typedef uintptr_t uword;
29
Mathieu Chartier50482232013-11-21 11:48:14 -080030static constexpr size_t KB = 1024;
31static constexpr size_t MB = KB * KB;
32static constexpr size_t GB = KB * KB * KB;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033
Andreas Gampe242947d2014-04-03 13:31:32 -070034// Runtime sizes.
Mathieu Chartier50482232013-11-21 11:48:14 -080035static constexpr size_t kWordSize = sizeof(word);
36static constexpr size_t kPointerSize = sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070037
Andreas Gampe242947d2014-04-03 13:31:32 -070038// Architecture-specific pointer sizes
39static constexpr size_t kArmPointerSize = 4;
40static constexpr size_t kArm64PointerSize = 8;
41static constexpr size_t kMipsPointerSize = 4;
42static constexpr size_t kX86PointerSize = 4;
43static constexpr size_t kX86_64PointerSize = 8;
44
Mathieu Chartier50482232013-11-21 11:48:14 -080045static constexpr size_t kBitsPerByte = 8;
46static constexpr size_t kBitsPerByteLog2 = 3;
47static constexpr int kBitsPerWord = kWordSize * kBitsPerByte;
Ian Rogersef7d42f2014-01-06 12:55:46 -080048static constexpr size_t kWordHighBitMask = static_cast<size_t>(1) << (kBitsPerWord - 1);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070049
Ian Rogers0d666d82011-08-14 16:03:46 -070050// Required stack alignment
Mathieu Chartier50482232013-11-21 11:48:14 -080051static constexpr size_t kStackAlignment = 16;
Brian Carlstrom0024d6c2011-08-09 08:26:12 -070052
Ian Rogers408f79a2011-08-23 18:22:33 -070053// Required object alignment
Mathieu Chartier50482232013-11-21 11:48:14 -080054static constexpr size_t kObjectAlignment = 8;
Ian Rogers408f79a2011-08-23 18:22:33 -070055
Logan Chien468a7b12012-05-25 20:56:35 +080056// ARM instruction alignment. ARM processors require code to be 4-byte aligned,
57// but ARM ELF requires 8..
Mathieu Chartier50482232013-11-21 11:48:14 -080058static constexpr size_t kArmAlignment = 8;
Brian Carlstrome24fa612011-09-29 00:53:55 -070059
Stuart Monteithb95a5342014-03-12 13:32:32 +000060// ARM64 instruction alignment. AArch64 require code to be 4-byte aligned.
61// AArch64 ELF requires at least 4.
62static constexpr size_t kArm64Alignment = 4;
63
Elliott Hughes742e25e2012-04-24 18:11:08 -070064// MIPS instruction alignment. MIPS processors require code to be 4-byte aligned.
jeffhao7fbee072012-08-24 17:56:54 -070065// TODO: Can this be 4?
Mathieu Chartier50482232013-11-21 11:48:14 -080066static constexpr size_t kMipsAlignment = 8;
Elliott Hughes742e25e2012-04-24 18:11:08 -070067
Elliott Hughes942df412012-03-26 09:46:56 -070068// X86 instruction alignment. This is the recommended alignment for maximum performance.
Mathieu Chartier50482232013-11-21 11:48:14 -080069static constexpr size_t kX86Alignment = 16;
Ian Rogersb41b33b2012-03-20 14:22:54 -070070
Elliott Hughes942df412012-03-26 09:46:56 -070071// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
72// compile-time constant so the compiler can generate better code.
Mathieu Chartier50482232013-11-21 11:48:14 -080073static constexpr int kPageSize = 4096;
Brian Carlstromb0460ea2011-07-29 10:08:05 -070074
Elliott Hughes67d92002012-03-26 15:08:51 -070075// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
76#if defined(NDEBUG)
Mathieu Chartier50482232013-11-21 11:48:14 -080077static constexpr bool kIsDebugBuild = false;
Elliott Hughes67d92002012-03-26 15:08:51 -070078#else
Mathieu Chartier50482232013-11-21 11:48:14 -080079static constexpr bool kIsDebugBuild = true;
Elliott Hughes67d92002012-03-26 15:08:51 -070080#endif
81
Brian Carlstrombcc29262012-11-02 11:36:03 -070082// Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't.
83#if defined(ART_TARGET)
Mathieu Chartier50482232013-11-21 11:48:14 -080084static constexpr bool kIsTargetBuild = true;
Brian Carlstrombcc29262012-11-02 11:36:03 -070085#else
Mathieu Chartier50482232013-11-21 11:48:14 -080086static constexpr bool kIsTargetBuild = false;
Brian Carlstrombcc29262012-11-02 11:36:03 -070087#endif
88
Mathieu Chartier46bc7782013-11-12 17:03:02 -080089#if defined(ART_USE_PORTABLE_COMPILER)
Mathieu Chartier50482232013-11-21 11:48:14 -080090static constexpr bool kUsePortableCompiler = true;
Mathieu Chartier46bc7782013-11-12 17:03:02 -080091#else
Mathieu Chartier50482232013-11-21 11:48:14 -080092static constexpr bool kUsePortableCompiler = false;
Mathieu Chartier46bc7782013-11-12 17:03:02 -080093#endif
94
Mathieu Chartier590fee92013-09-13 13:46:47 -070095// Garbage collector constants.
Mathieu Chartier50482232013-11-21 11:48:14 -080096static constexpr bool kMovingCollector = true && !kUsePortableCompiler;
Mathieu Chartier590fee92013-09-13 13:46:47 -070097// True if we allow moving classes.
Mathieu Chartierc528dba2013-11-26 12:00:11 -080098static constexpr bool kMovingClasses = true;
Mathieu Chartier590fee92013-09-13 13:46:47 -070099// True if we allow moving fields.
100static constexpr bool kMovingFields = false;
101// True if we allow moving methods.
102static constexpr bool kMovingMethods = false;
103
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800104// If true, the quick compiler embeds class pointers in the compiled
105// code, if possible.
106static constexpr bool kEmbedClassInCode = true;
107
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700108#ifdef USE_BAKER_READ_BARRIER
109static constexpr bool kUseBakerReadBarrier = true;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800110#else
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700111static constexpr bool kUseBakerReadBarrier = false;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800112#endif
113
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700114#ifdef USE_BROOKS_READ_BARRIER
115static constexpr bool kUseBrooksReadBarrier = true;
116#else
117static constexpr bool kUseBrooksReadBarrier = false;
118#endif
119
120static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
121
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800122// If true, references within the heap are poisoned (negated).
123static constexpr bool kPoisonHeapReferences = false;
124
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700125} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700126
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700127#endif // ART_RUNTIME_GLOBALS_H_