1 /*
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  */
16 
17 #ifndef ART_RUNTIME_RUNTIME_GLOBALS_H_
18 #define ART_RUNTIME_RUNTIME_GLOBALS_H_
19 
20 #include "base/globals.h"
21 
22 namespace art {
23 
24 // Size of Dex virtual registers.
25 static constexpr size_t kVRegSize = 4;
26 
27 // Returns whether the given memory offset can be used for generating
28 // an implicit null check.
CanDoImplicitNullCheckOn(uintptr_t offset)29 static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
30   return offset < kPageSize;
31 }
32 
33 // Required object alignment
34 static constexpr size_t kObjectAlignmentShift = 3;
35 static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
36 static constexpr size_t kLargeObjectAlignment = kPageSize;
37 
38 // Garbage collector constants.
39 static constexpr bool kMovingCollector = true;
40 static constexpr bool kMarkCompactSupport = false && kMovingCollector;
41 // True if we allow moving classes.
42 static constexpr bool kMovingClasses = !kMarkCompactSupport;
43 // When using the Concurrent Copying (CC) collector, if
44 // `ART_USE_GENERATIONAL_CC` is true, enable generational collection by default,
45 // i.e. use sticky-bit CC for minor collections and (full) CC for major
46 // collections.
47 // This default value can be overridden with the runtime option
48 // `-Xgc:[no]generational_cc`.
49 //
50 // TODO(b/67628039): Consider either:
51 // - renaming this to a better descriptive name (e.g.
52 //   `ART_USE_GENERATIONAL_CC_BY_DEFAULT`); or
53 // - removing `ART_USE_GENERATIONAL_CC` and having a fixed default value.
54 // Any of these changes will require adjusting users of this preprocessor
55 // directive and the corresponding build system environment variable (e.g. in
56 // ART's continuous testing).
57 #ifdef ART_USE_GENERATIONAL_CC
58 static constexpr bool kEnableGenerationalCCByDefault = true;
59 #else
60 static constexpr bool kEnableGenerationalCCByDefault = false;
61 #endif
62 
63 // If true, enable the tlab allocator by default.
64 #ifdef ART_USE_TLAB
65 static constexpr bool kUseTlab = true;
66 #else
67 static constexpr bool kUseTlab = false;
68 #endif
69 
70 // Kinds of tracing clocks.
71 enum class TraceClockSource {
72   kThreadCpu,
73   kWall,
74   kDual,  // Both wall and thread CPU clocks.
75 };
76 
77 #if defined(__linux__)
78 static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
79 #else
80 static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
81 #endif
82 
83 static constexpr bool kDefaultMustRelocate = true;
84 
85 // Size of a heap reference.
86 static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
87 
88 }  // namespace art
89 
90 #endif  // ART_RUNTIME_RUNTIME_GLOBALS_H_
91