blob: 256306d1de8359ee58c70b874b4e4a313ee48fb2 [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"
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070023#include "read_barrier_option.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070024
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070025namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070026
Mathieu Chartier50482232013-11-21 11:48:14 -080027static constexpr size_t KB = 1024;
28static constexpr size_t MB = KB * KB;
29static constexpr size_t GB = KB * KB * KB;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070030
Andreas Gampe242947d2014-04-03 13:31:32 -070031// Runtime sizes.
Mathieu Chartier50482232013-11-21 11:48:14 -080032static constexpr size_t kBitsPerByte = 8;
33static constexpr size_t kBitsPerByteLog2 = 3;
Ian Rogers13735952014-10-08 12:43:28 -070034static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070035
Ian Rogers0d666d82011-08-14 16:03:46 -070036// Required stack alignment
Mathieu Chartier50482232013-11-21 11:48:14 -080037static constexpr size_t kStackAlignment = 16;
Brian Carlstrom0024d6c2011-08-09 08:26:12 -070038
Elliott Hughes942df412012-03-26 09:46:56 -070039// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
40// compile-time constant so the compiler can generate better code.
Mathieu Chartier50482232013-11-21 11:48:14 -080041static constexpr int kPageSize = 4096;
Brian Carlstromb0460ea2011-07-29 10:08:05 -070042
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010043// Returns whether the given memory offset can be used for generating
44// an implicit null check.
45static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
46 return offset < kPageSize;
47}
48
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070049// Required object alignment
Mathieu Chartier36a270a2016-07-28 18:08:51 -070050static constexpr size_t kObjectAlignmentShift = 3;
51static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070052static constexpr size_t kLargeObjectAlignment = kPageSize;
53
Igor Murashkinf5739722017-08-07 14:42:11 -070054// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
55// returns the same value. By wrapping into a call to another constexpr function, we force it
56// to realize that is not actually always evaluating to the same value.
57static constexpr bool GlobalsReturnSelf(bool self) { return self; }
58
Elliott Hughes67d92002012-03-26 15:08:51 -070059// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
Igor Murashkinf5739722017-08-07 14:42:11 -070060// TODO: Use only __clang_analyzer__ here. b/64455231
61#if defined(NDEBUG) && !defined(__CLION_IDE__)
62static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
Elliott Hughes67d92002012-03-26 15:08:51 -070063#else
Igor Murashkinf5739722017-08-07 14:42:11 -070064static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
Elliott Hughes67d92002012-03-26 15:08:51 -070065#endif
66
Bilyan Borisov3071f802016-03-31 17:15:53 +010067// ART_TARGET - Defined for target builds of ART.
68// ART_TARGET_LINUX - Defined for target Linux builds of ART.
69// ART_TARGET_ANDROID - Defined for target Android builds of ART.
70// Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set.
71// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
72// (usually only available on Android kernels).
Brian Carlstrombcc29262012-11-02 11:36:03 -070073#if defined(ART_TARGET)
Bilyan Borisov3071f802016-03-31 17:15:53 +010074// Useful in conditionals where ART_TARGET isn't.
Mathieu Chartier50482232013-11-21 11:48:14 -080075static constexpr bool kIsTargetBuild = true;
Roland Levillain04147ef2016-09-06 11:09:41 +010076# if defined(ART_TARGET_LINUX)
Bilyan Borisov3071f802016-03-31 17:15:53 +010077static constexpr bool kIsTargetLinux = true;
Roland Levillain04147ef2016-09-06 11:09:41 +010078# elif defined(ART_TARGET_ANDROID)
Bilyan Borisov3071f802016-03-31 17:15:53 +010079static constexpr bool kIsTargetLinux = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010080# else
81# error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds."
82# endif
Brian Carlstrombcc29262012-11-02 11:36:03 -070083#else
Mathieu Chartier50482232013-11-21 11:48:14 -080084static constexpr bool kIsTargetBuild = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010085# if defined(ART_TARGET_LINUX)
86# error "ART_TARGET_LINUX defined for host build."
87# elif defined(ART_TARGET_ANDROID)
88# error "ART_TARGET_ANDROID defined for host build."
89# else
Bilyan Borisov3071f802016-03-31 17:15:53 +010090static constexpr bool kIsTargetLinux = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010091# endif
Bilyan Borisov3071f802016-03-31 17:15:53 +010092#endif
Roland Levillain04147ef2016-09-06 11:09:41 +010093
Colin Crossb20be212016-09-19 13:02:47 -070094// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
95// always available on the host
96#if !defined(ART_TARGET)
Roland Levillain04147ef2016-09-06 11:09:41 +010097static constexpr bool kHostStaticBuildEnabled = true;
98#else
99static constexpr bool kHostStaticBuildEnabled = false;
Brian Carlstrombcc29262012-11-02 11:36:03 -0700100#endif
101
Mathieu Chartier590fee92013-09-13 13:46:47 -0700102// Garbage collector constants.
Elliott Hughes956af0f2014-12-11 14:34:28 -0800103static constexpr bool kMovingCollector = true;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700104static constexpr bool kMarkCompactSupport = false && kMovingCollector;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700105// True if we allow moving classes.
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700106static constexpr bool kMovingClasses = !kMarkCompactSupport;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700107
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800108// If true, the quick compiler embeds class pointers in the compiled
109// code, if possible.
110static constexpr bool kEmbedClassInCode = true;
111
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700112#ifdef USE_BAKER_READ_BARRIER
113static constexpr bool kUseBakerReadBarrier = true;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800114#else
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700115static constexpr bool kUseBakerReadBarrier = false;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800116#endif
117
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700118#ifdef USE_BROOKS_READ_BARRIER
119static constexpr bool kUseBrooksReadBarrier = true;
120#else
121static constexpr bool kUseBrooksReadBarrier = false;
122#endif
123
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800124#ifdef USE_TABLE_LOOKUP_READ_BARRIER
125static constexpr bool kUseTableLookupReadBarrier = true;
126#else
127static constexpr bool kUseTableLookupReadBarrier = false;
128#endif
129
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700130static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
Roland Levillain0d5a2812015-11-13 10:07:31 +0000131static constexpr bool kUseReadBarrier =
132 kUseBakerReadBarrier || kUseBrooksReadBarrier || kUseTableLookupReadBarrier;
133
134// Debugging flag that forces the generation of read barriers, but
135// does not trigger the use of the concurrent copying GC.
136//
137// TODO: Remove this flag when the read barriers compiler
138// instrumentation is completed.
139static constexpr bool kForceReadBarrier = false;
140// TODO: Likewise, remove this flag when kForceReadBarrier is removed
141// and replace it with kUseReadBarrier.
142static constexpr bool kEmitCompilerReadBarrier = kForceReadBarrier || kUseReadBarrier;
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700143
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800144// If true, references within the heap are poisoned (negated).
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700145#ifdef USE_HEAP_POISONING
Hiroshi Yamauchib0d22f12014-12-08 12:08:46 -0800146static constexpr bool kPoisonHeapReferences = true;
147#else
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800148static constexpr bool kPoisonHeapReferences = false;
Hiroshi Yamauchib0d22f12014-12-08 12:08:46 -0800149#endif
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800150
Hiroshi Yamauchi79bd2bf2015-03-20 10:28:34 -0700151// If true, enable the tlab allocator by default.
152#ifdef ART_USE_TLAB
153static constexpr bool kUseTlab = true;
154#else
155static constexpr bool kUseTlab = false;
156#endif
157
Ian Rogerse63db272014-07-15 15:36:11 -0700158// Kinds of tracing clocks.
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800159enum class TraceClockSource {
160 kThreadCpu,
161 kWall,
162 kDual, // Both wall and thread CPU clocks.
Ian Rogerse63db272014-07-15 15:36:11 -0700163};
164
Elliott Hughes0a18df82015-01-09 15:16:16 -0800165#if defined(__linux__)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800166static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
Ian Rogerse63db272014-07-15 15:36:11 -0700167#else
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800168static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
Ian Rogerse63db272014-07-15 15:36:11 -0700169#endif
170
Alex Light6e183f22014-07-18 14:57:04 -0700171static constexpr bool kDefaultMustRelocate = true;
172
Zheng Xu5667fdb2014-10-23 18:29:55 +0800173static constexpr bool kArm32QuickCodeUseSoftFloat = false;
174
David Brazdil7b49e6c2016-09-01 11:06:18 +0100175#ifdef ART_ENABLE_VDEX
176static constexpr bool kIsVdexEnabled = true;
177#else
178static constexpr bool kIsVdexEnabled = false;
179#endif
180
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700181// Size of a heap reference.
182static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
183
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700184} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700185
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700186#endif // ART_RUNTIME_GLOBALS_H_