12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
16a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_GLOBALS_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_GLOBALS_H_
19a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
201fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#include <stddef.h>
21a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro#include <stdint.h>
22800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi#include "read_barrier_c.h"
236e83c172f385cb45dd13bbcf41d2df8e410828c6Hiroshi Yamauchi#include "read_barrier_option.h"
24a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
256b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art {
26a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2750482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t KB = 1024;
2850482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t MB = KB * KB;
2950482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t GB = KB * KB * KB;
306d8dd47f2f65c4476b31672b6f2c7bbf9020fe3aElliott Hughes
31242947dbcdc4038ddd8ac522bb480f82e7d92ffaAndreas Gampe// Runtime sizes.
3250482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t kBitsPerByte = 8;
3350482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t kBitsPerByteLog2 = 3;
3413735955f39b3b304c37d2b2840663c131262c18Ian Rogersstatic constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
35a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
360d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers// Required stack alignment
3750482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr size_t kStackAlignment = 16;
380024d6cb8043a8967fdfb20561f321b2fe65c41fBrian Carlstrom
39942df41c03ddb9f7b47a34fcfc4414d8b8ca8ce1Elliott Hughes// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
40942df41c03ddb9f7b47a34fcfc4414d8b8ca8ce1Elliott Hughes// compile-time constant so the compiler can generate better code.
4150482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr int kPageSize = 4096;
42b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom
43a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier// Required object alignment
44a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartierstatic constexpr size_t kObjectAlignment = 8;
45a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartierstatic constexpr size_t kLargeObjectAlignment = kPageSize;
46a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier
4767d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
4867d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes#if defined(NDEBUG)
4950482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr bool kIsDebugBuild = false;
5067d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes#else
5150482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr bool kIsDebugBuild = true;
5267d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes#endif
5367d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes
54bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom// Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't.
55bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#if defined(ART_TARGET)
5650482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr bool kIsTargetBuild = true;
57bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#else
5850482234bed852766498321f71d2ff5e46e4fec2Mathieu Chartierstatic constexpr bool kIsTargetBuild = false;
59bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#endif
60bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom
619bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffray#if defined(ART_USE_OPTIMIZING_COMPILER)
629bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffraystatic constexpr bool kUseOptimizingCompiler = true;
639bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffray#else
649bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffraystatic constexpr bool kUseOptimizingCompiler = false;
659bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffray#endif
669bb492a33c97e72d0c43a4ee968e34cc32534981Nicolas Geoffray
67590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier// Garbage collector constants.
68956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughesstatic constexpr bool kMovingCollector = true;
6952e4b43d62896b56f8c2bd041e528472bb4a0d8dMathieu Chartierstatic constexpr bool kMarkCompactSupport = false && kMovingCollector;
70590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier// True if we allow moving classes.
7152e4b43d62896b56f8c2bd041e528472bb4a0d8dMathieu Chartierstatic constexpr bool kMovingClasses = !kMarkCompactSupport;
72590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier
73be1ca55db3362f5b100c4c65da5342fd299520bbHiroshi Yamauchi// If true, the quick compiler embeds class pointers in the compiled
74be1ca55db3362f5b100c4c65da5342fd299520bbHiroshi Yamauchi// code, if possible.
75be1ca55db3362f5b100c4c65da5342fd299520bbHiroshi Yamauchistatic constexpr bool kEmbedClassInCode = true;
76be1ca55db3362f5b100c4c65da5342fd299520bbHiroshi Yamauchi
77624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#ifdef USE_BAKER_READ_BARRIER
78624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchistatic constexpr bool kUseBakerReadBarrier = true;
799d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi#else
80624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchistatic constexpr bool kUseBakerReadBarrier = false;
819d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi#endif
829d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi
83624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#ifdef USE_BROOKS_READ_BARRIER
84624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchistatic constexpr bool kUseBrooksReadBarrier = true;
85624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#else
86624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchistatic constexpr bool kUseBrooksReadBarrier = false;
87624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#endif
88624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi
892cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchi#ifdef USE_TABLE_LOOKUP_READ_BARRIER
902cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchistatic constexpr bool kUseTableLookupReadBarrier = true;
912cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchi#else
922cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchistatic constexpr bool kUseTableLookupReadBarrier = false;
932cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchi#endif
942cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchi
95624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchistatic constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
962cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchistatic constexpr bool kUseReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier ||
972cd334ae2d4287216523882f0d298cf3901b7ab1Hiroshi Yamauchi    kUseTableLookupReadBarrier;
98624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi
99e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchi// If true, references within the heap are poisoned (negated).
100b0d22f178c0a8d1ee7d3692f282bb46c53cc2036Hiroshi Yamauchi#ifdef ART_HEAP_POISONING
101b0d22f178c0a8d1ee7d3692f282bb46c53cc2036Hiroshi Yamauchistatic constexpr bool kPoisonHeapReferences = true;
102b0d22f178c0a8d1ee7d3692f282bb46c53cc2036Hiroshi Yamauchi#else
103e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchistatic constexpr bool kPoisonHeapReferences = false;
104b0d22f178c0a8d1ee7d3692f282bb46c53cc2036Hiroshi Yamauchi#endif
105e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchi
10679bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchi// If true, enable the tlab allocator by default.
10779bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchi#ifdef ART_USE_TLAB
10879bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchistatic constexpr bool kUseTlab = true;
10979bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchi#else
11079bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchistatic constexpr bool kUseTlab = false;
11179bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchi#endif
11279bd2bfa8f1602067fd381834206ed6b7e73a9beHiroshi Yamauchi
113e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers// Kinds of tracing clocks.
114aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkinenum class TraceClockSource {
115aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  kThreadCpu,
116aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  kWall,
117aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  kDual,  // Both wall and thread CPU clocks.
118e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers};
119e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers
1200a18df82f4dea95b7398f8c934341fccbf04eeeeElliott Hughes#if defined(__linux__)
121aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkinstatic constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
122e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#else
123aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkinstatic constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
124e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#endif
125e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers
1266e183f2e973a20f2eaca135c240908e1bf98c5d0Alex Lightstatic constexpr bool kDefaultMustRelocate = true;
1276e183f2e973a20f2eaca135c240908e1bf98c5d0Alex Light
1285667fdbb6e441dee7534ade18b628ed396daf593Zheng Xustatic constexpr bool kArm32QuickCodeUseSoftFloat = false;
1295667fdbb6e441dee7534ade18b628ed396daf593Zheng Xu
1306b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro}  // namespace art
131a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
132fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_GLOBALS_H_
133