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, 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_TABLELOOKUP 34 #define USE_TABLE_LOOKUP_READ_BARRIER 35 #else 36 #error "ART read barrier type must be set" 37 #endif 38 #endif // ART_USE_READ_BARRIER 39 40 #if defined(USE_BAKER_READ_BARRIER) || defined(USE_TABLE_LOOKUP_READ_BARRIER) 41 #define USE_READ_BARRIER 42 #endif 43 44 // Reserve marking register (and its refreshing logic) for all GCs as nterp 45 // requires it. In the future if and when nterp is made independent of 46 // read-barrier, we can switch back to the current behavior by making this 47 // definition conditional on USE_BAKER_READ_BARRIER and setting 48 // kReserveMarkingRegister to kUseBakerReadBarrier. 49 #define RESERVE_MARKING_REGISTER 50 51 // C++-specific configuration part.. 52 53 #ifdef __cplusplus 54 55 #include "base/globals.h" 56 #include "base/macros.h" 57 58 namespace art HIDDEN { 59 60 #ifdef USE_BAKER_READ_BARRIER 61 static constexpr bool kUseBakerReadBarrier = true; 62 #else 63 static constexpr bool kUseBakerReadBarrier = false; 64 #endif 65 66 // Read comment for RESERVE_MARKING_REGISTER above 67 static constexpr bool kReserveMarkingRegister = true; 68 69 #ifdef USE_TABLE_LOOKUP_READ_BARRIER 70 static constexpr bool kUseTableLookupReadBarrier = true; 71 #else 72 static constexpr bool kUseTableLookupReadBarrier = false; 73 #endif 74 75 // Only if read-barrier isn't forced (see build/art.go) but is selected, that we need 76 // to see if we support userfaultfd GC. All the other cases can be constexpr here. 77 #ifdef ART_FORCE_USE_READ_BARRIER 78 constexpr bool gUseReadBarrier = kUseBakerReadBarrier || kUseTableLookupReadBarrier; 79 constexpr bool gUseUserfaultfd = !gUseReadBarrier; 80 static_assert(!gUseUserfaultfd); 81 #else 82 #ifndef ART_USE_READ_BARRIER 83 constexpr bool gUseReadBarrier = false; 84 #ifdef ART_DEFAULT_GC_TYPE_IS_CMC 85 constexpr bool gUseUserfaultfd = true; 86 #else 87 constexpr bool gUseUserfaultfd = false; 88 #endif 89 #else 90 EXPORT extern const bool gUseReadBarrier; 91 EXPORT extern const bool gUseUserfaultfd; 92 #endif 93 #endif 94 95 // Disabled for performance reasons. 96 static constexpr bool kCheckDebugDisallowReadBarrierCount = kIsDebugBuild; 97 98 } // namespace art 99 100 #endif // __cplusplus 101 102 #endif // ART_RUNTIME_READ_BARRIER_CONFIG_H_ 103