blob: ca4040d77715f8c1b2a6b67bf75afae058c62095 [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>
Andreas Gampe217488a2017-09-18 08:34:42 -070022
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070023namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070024
Mathieu Chartier50482232013-11-21 11:48:14 -080025static constexpr size_t KB = 1024;
26static constexpr size_t MB = KB * KB;
27static constexpr size_t GB = KB * KB * KB;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070028
Andreas Gampe242947d2014-04-03 13:31:32 -070029// Runtime sizes.
Mathieu Chartier50482232013-11-21 11:48:14 -080030static constexpr size_t kBitsPerByte = 8;
31static constexpr size_t kBitsPerByteLog2 = 3;
Ian Rogers13735952014-10-08 12:43:28 -070032static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033
Ian Rogers0d666d82011-08-14 16:03:46 -070034// Required stack alignment
Mathieu Chartier50482232013-11-21 11:48:14 -080035static constexpr size_t kStackAlignment = 16;
Brian Carlstrom0024d6c2011-08-09 08:26:12 -070036
Elliott Hughes942df412012-03-26 09:46:56 -070037// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
38// compile-time constant so the compiler can generate better code.
Mathieu Chartier50482232013-11-21 11:48:14 -080039static constexpr int kPageSize = 4096;
Brian Carlstromb0460ea2011-07-29 10:08:05 -070040
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010041// Returns whether the given memory offset can be used for generating
42// an implicit null check.
43static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
44 return offset < kPageSize;
45}
46
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070047// Required object alignment
Mathieu Chartier36a270a2016-07-28 18:08:51 -070048static constexpr size_t kObjectAlignmentShift = 3;
49static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070050static constexpr size_t kLargeObjectAlignment = kPageSize;
51
Igor Murashkinf5739722017-08-07 14:42:11 -070052// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
53// returns the same value. By wrapping into a call to another constexpr function, we force it
54// to realize that is not actually always evaluating to the same value.
55static constexpr bool GlobalsReturnSelf(bool self) { return self; }
56
Elliott Hughes67d92002012-03-26 15:08:51 -070057// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
Igor Murashkinf5739722017-08-07 14:42:11 -070058// TODO: Use only __clang_analyzer__ here. b/64455231
59#if defined(NDEBUG) && !defined(__CLION_IDE__)
60static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
Elliott Hughes67d92002012-03-26 15:08:51 -070061#else
Igor Murashkinf5739722017-08-07 14:42:11 -070062static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
Elliott Hughes67d92002012-03-26 15:08:51 -070063#endif
64
Pirama Arumuga Nainarab898922018-01-04 10:37:48 -080065#if defined(ART_PGO_INSTRUMENTATION)
66static constexpr bool kIsPGOInstrumentation = true;
67#else
68static constexpr bool kIsPGOInstrumentation = false;
69#endif
70
Bilyan Borisov3071f802016-03-31 17:15:53 +010071// ART_TARGET - Defined for target builds of ART.
72// ART_TARGET_LINUX - Defined for target Linux builds of ART.
73// ART_TARGET_ANDROID - Defined for target Android builds of ART.
74// Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set.
75// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
76// (usually only available on Android kernels).
Brian Carlstrombcc29262012-11-02 11:36:03 -070077#if defined(ART_TARGET)
Bilyan Borisov3071f802016-03-31 17:15:53 +010078// Useful in conditionals where ART_TARGET isn't.
Mathieu Chartier50482232013-11-21 11:48:14 -080079static constexpr bool kIsTargetBuild = true;
Roland Levillain04147ef2016-09-06 11:09:41 +010080# if defined(ART_TARGET_LINUX)
Bilyan Borisov3071f802016-03-31 17:15:53 +010081static constexpr bool kIsTargetLinux = true;
Roland Levillain04147ef2016-09-06 11:09:41 +010082# elif defined(ART_TARGET_ANDROID)
Bilyan Borisov3071f802016-03-31 17:15:53 +010083static constexpr bool kIsTargetLinux = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010084# else
85# error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds."
86# endif
Brian Carlstrombcc29262012-11-02 11:36:03 -070087#else
Mathieu Chartier50482232013-11-21 11:48:14 -080088static constexpr bool kIsTargetBuild = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010089# if defined(ART_TARGET_LINUX)
90# error "ART_TARGET_LINUX defined for host build."
91# elif defined(ART_TARGET_ANDROID)
92# error "ART_TARGET_ANDROID defined for host build."
93# else
Bilyan Borisov3071f802016-03-31 17:15:53 +010094static constexpr bool kIsTargetLinux = false;
Roland Levillain04147ef2016-09-06 11:09:41 +010095# endif
Bilyan Borisov3071f802016-03-31 17:15:53 +010096#endif
Roland Levillain04147ef2016-09-06 11:09:41 +010097
Colin Crossb20be212016-09-19 13:02:47 -070098// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
99// always available on the host
100#if !defined(ART_TARGET)
Roland Levillain04147ef2016-09-06 11:09:41 +0100101static constexpr bool kHostStaticBuildEnabled = true;
102#else
103static constexpr bool kHostStaticBuildEnabled = false;
Brian Carlstrombcc29262012-11-02 11:36:03 -0700104#endif
105
Mathieu Chartier590fee92013-09-13 13:46:47 -0700106// Garbage collector constants.
Elliott Hughes956af0f2014-12-11 14:34:28 -0800107static constexpr bool kMovingCollector = true;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700108static constexpr bool kMarkCompactSupport = false && kMovingCollector;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700109// True if we allow moving classes.
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700110static constexpr bool kMovingClasses = !kMarkCompactSupport;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700111
Hiroshi Yamauchi79bd2bf2015-03-20 10:28:34 -0700112// If true, enable the tlab allocator by default.
113#ifdef ART_USE_TLAB
114static constexpr bool kUseTlab = true;
115#else
116static constexpr bool kUseTlab = false;
117#endif
118
Ian Rogerse63db272014-07-15 15:36:11 -0700119// Kinds of tracing clocks.
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800120enum class TraceClockSource {
121 kThreadCpu,
122 kWall,
123 kDual, // Both wall and thread CPU clocks.
Ian Rogerse63db272014-07-15 15:36:11 -0700124};
125
Elliott Hughes0a18df82015-01-09 15:16:16 -0800126#if defined(__linux__)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800127static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
Ian Rogerse63db272014-07-15 15:36:11 -0700128#else
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800129static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
Ian Rogerse63db272014-07-15 15:36:11 -0700130#endif
131
Alex Light6e183f22014-07-18 14:57:04 -0700132static constexpr bool kDefaultMustRelocate = true;
133
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700134// Size of a heap reference.
135static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
136
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700137} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700138
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700139#endif // ART_RUNTIME_GLOBALS_H_