blob: 107e0646a86b670a3f5a3d304eda591fde6e6a60 [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
27typedef uint8_t byte;
28typedef intptr_t word;
29typedef uintptr_t uword;
30
Mathieu Chartier50482232013-11-21 11:48:14 -080031static constexpr size_t KB = 1024;
32static constexpr size_t MB = KB * KB;
33static constexpr size_t GB = KB * KB * KB;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070034
Andreas Gampe242947d2014-04-03 13:31:32 -070035// Runtime sizes.
Mathieu Chartier50482232013-11-21 11:48:14 -080036static constexpr size_t kWordSize = sizeof(word);
37static constexpr size_t kPointerSize = sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070038
Mathieu Chartier50482232013-11-21 11:48:14 -080039static constexpr size_t kBitsPerByte = 8;
40static constexpr size_t kBitsPerByteLog2 = 3;
41static constexpr int kBitsPerWord = kWordSize * kBitsPerByte;
Ian Rogersef7d42f2014-01-06 12:55:46 -080042static constexpr size_t kWordHighBitMask = static_cast<size_t>(1) << (kBitsPerWord - 1);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070043
Ian Rogers0d666d82011-08-14 16:03:46 -070044// Required stack alignment
Mathieu Chartier50482232013-11-21 11:48:14 -080045static constexpr size_t kStackAlignment = 16;
Brian Carlstrom0024d6c2011-08-09 08:26:12 -070046
Elliott Hughes942df412012-03-26 09:46:56 -070047// 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.
Mathieu Chartier50482232013-11-21 11:48:14 -080049static constexpr int kPageSize = 4096;
Brian Carlstromb0460ea2011-07-29 10:08:05 -070050
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070051// Required object alignment
52static constexpr size_t kObjectAlignment = 8;
53static constexpr size_t kLargeObjectAlignment = kPageSize;
54
Elliott Hughes67d92002012-03-26 15:08:51 -070055// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
56#if defined(NDEBUG)
Mathieu Chartier50482232013-11-21 11:48:14 -080057static constexpr bool kIsDebugBuild = false;
Elliott Hughes67d92002012-03-26 15:08:51 -070058#else
Mathieu Chartier50482232013-11-21 11:48:14 -080059static constexpr bool kIsDebugBuild = true;
Elliott Hughes67d92002012-03-26 15:08:51 -070060#endif
61
Brian Carlstrombcc29262012-11-02 11:36:03 -070062// Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't.
63#if defined(ART_TARGET)
Mathieu Chartier50482232013-11-21 11:48:14 -080064static constexpr bool kIsTargetBuild = true;
Brian Carlstrombcc29262012-11-02 11:36:03 -070065#else
Mathieu Chartier50482232013-11-21 11:48:14 -080066static constexpr bool kIsTargetBuild = false;
Brian Carlstrombcc29262012-11-02 11:36:03 -070067#endif
68
Mathieu Chartier46bc7782013-11-12 17:03:02 -080069#if defined(ART_USE_PORTABLE_COMPILER)
Mathieu Chartier50482232013-11-21 11:48:14 -080070static constexpr bool kUsePortableCompiler = true;
Mathieu Chartier46bc7782013-11-12 17:03:02 -080071#else
Mathieu Chartier50482232013-11-21 11:48:14 -080072static constexpr bool kUsePortableCompiler = false;
Mathieu Chartier46bc7782013-11-12 17:03:02 -080073#endif
74
Mathieu Chartier590fee92013-09-13 13:46:47 -070075// Garbage collector constants.
Mathieu Chartier50482232013-11-21 11:48:14 -080076static constexpr bool kMovingCollector = true && !kUsePortableCompiler;
Mathieu Chartier52e4b432014-06-10 11:22:31 -070077static constexpr bool kMarkCompactSupport = false && kMovingCollector;
78// True if we allow moving field arrays, this can cause complication with mark compact.
79static constexpr bool kMoveFieldArrays = !kMarkCompactSupport;
Mathieu Chartier590fee92013-09-13 13:46:47 -070080// True if we allow moving classes.
Mathieu Chartier52e4b432014-06-10 11:22:31 -070081static constexpr bool kMovingClasses = !kMarkCompactSupport;
Mathieu Chartier590fee92013-09-13 13:46:47 -070082// True if we allow moving fields.
83static constexpr bool kMovingFields = false;
84// True if we allow moving methods.
85static constexpr bool kMovingMethods = false;
86
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080087// If true, the quick compiler embeds class pointers in the compiled
88// code, if possible.
89static constexpr bool kEmbedClassInCode = true;
90
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070091#ifdef USE_BAKER_READ_BARRIER
92static constexpr bool kUseBakerReadBarrier = true;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080093#else
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070094static constexpr bool kUseBakerReadBarrier = false;
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080095#endif
96
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070097#ifdef USE_BROOKS_READ_BARRIER
98static constexpr bool kUseBrooksReadBarrier = true;
99#else
100static constexpr bool kUseBrooksReadBarrier = false;
101#endif
102
103static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
104
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800105// If true, references within the heap are poisoned (negated).
106static constexpr bool kPoisonHeapReferences = false;
107
Ian Rogerse63db272014-07-15 15:36:11 -0700108// Kinds of tracing clocks.
109enum TraceClockSource {
110 kTraceClockSourceThreadCpu,
111 kTraceClockSourceWall,
112 kTraceClockSourceDual, // Both wall and thread CPU clocks.
113};
114
115#if defined(HAVE_POSIX_CLOCKS)
116static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceDual;
117#else
118static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceWall;
119#endif
120
Alex Light6e183f22014-07-18 14:57:04 -0700121static constexpr bool kDefaultMustRelocate = true;
122
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700123} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700124
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700125#endif // ART_RUNTIME_GLOBALS_H_