1 /*
2  * Copyright (C) 2014 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_READ_BARRIER_CONFIG_H_
18 #define ART_RUNTIME_READ_BARRIER_CONFIG_H_
19 
20 // This is a mixed C-C++ header file that has a global section at the start
21 // and a C++ section at the end, because asm_support.h is a C header file and
22 // cannot include any C++ syntax.
23 
24 // Global (C) part.
25 
26 // Uncomment one of the following two and the two fields in
27 // Object.java (libcore) to enable baker, brooks (unimplemented), or
28 // table-lookup read barriers.
29 
30 #ifdef ART_USE_READ_BARRIER
31 #if ART_READ_BARRIER_TYPE_IS_BAKER
32 #define USE_BAKER_READ_BARRIER
33 #elif ART_READ_BARRIER_TYPE_IS_BROOKS
34 #define USE_BROOKS_READ_BARRIER
35 #elif ART_READ_BARRIER_TYPE_IS_TABLELOOKUP
36 #define USE_TABLE_LOOKUP_READ_BARRIER
37 #else
38 #error "ART read barrier type must be set"
39 #endif
40 #endif  // ART_USE_READ_BARRIER
41 
42 #if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER)
43 #define USE_BAKER_OR_BROOKS_READ_BARRIER
44 #endif
45 
46 #if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER) || defined(USE_TABLE_LOOKUP_READ_BARRIER)
47 #define USE_READ_BARRIER
48 #endif
49 
50 #if defined(USE_BAKER_READ_BARRIER) && defined(USE_BROOKS_READ_BARRIER)
51 #error "Only one of Baker or Brooks can be enabled at a time."
52 #endif
53 
54 
55 // C++-specific configuration part..
56 
57 #ifdef __cplusplus
58 
59 namespace art {
60 
61 #ifdef USE_BAKER_READ_BARRIER
62 static constexpr bool kUseBakerReadBarrier = true;
63 #else
64 static constexpr bool kUseBakerReadBarrier = false;
65 #endif
66 
67 #ifdef USE_BROOKS_READ_BARRIER
68 static constexpr bool kUseBrooksReadBarrier = true;
69 #else
70 static constexpr bool kUseBrooksReadBarrier = false;
71 #endif
72 
73 #ifdef USE_TABLE_LOOKUP_READ_BARRIER
74 static constexpr bool kUseTableLookupReadBarrier = true;
75 #else
76 static constexpr bool kUseTableLookupReadBarrier = false;
77 #endif
78 
79 static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
80 static constexpr bool kUseReadBarrier =
81     kUseBakerReadBarrier || kUseBrooksReadBarrier || kUseTableLookupReadBarrier;
82 
83 // Debugging flag that forces the generation of read barriers, but
84 // does not trigger the use of the concurrent copying GC.
85 //
86 // TODO: Remove this flag when the read barriers compiler
87 // instrumentation is completed.
88 static constexpr bool kForceReadBarrier = false;
89 // TODO: Likewise, remove this flag when kForceReadBarrier is removed
90 // and replace it with kUseReadBarrier.
91 static constexpr bool kEmitCompilerReadBarrier = kForceReadBarrier || kUseReadBarrier;
92 
93 }  // namespace art
94 
95 #endif  // __cplusplus
96 
97 #endif  // ART_RUNTIME_READ_BARRIER_CONFIG_H_
98