1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2018 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include "base/bit_field.h" 21*795d594fSAndroid Build Coastguard Worker #include "base/bit_utils.h" 22*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 23*795d594fSAndroid Build Coastguard Worker #include "base/mutex.h" 24*795d594fSAndroid Build Coastguard Worker #include "obj_ptr.h" 25*795d594fSAndroid Build Coastguard Worker #include "offsets.h" 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 28*795d594fSAndroid Build Coastguard Worker 29*795d594fSAndroid Build Coastguard Worker class ClassLinker; 30*795d594fSAndroid Build Coastguard Worker class MemberOffset; 31*795d594fSAndroid Build Coastguard Worker class Thread; 32*795d594fSAndroid Build Coastguard Worker 33*795d594fSAndroid Build Coastguard Worker namespace mirror { 34*795d594fSAndroid Build Coastguard Worker class Object; 35*795d594fSAndroid Build Coastguard Worker template <class T> class ObjectArray; 36*795d594fSAndroid Build Coastguard Worker } // namespace mirror 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker #define BOXED_TYPES(V) \ 39*795d594fSAndroid Build Coastguard Worker V(Byte, -128, 127, DataType::Type::kInt8, 0) \ 40*795d594fSAndroid Build Coastguard Worker V(Short, -128, 127, DataType::Type::kInt16, kByteCacheLastIndex) \ 41*795d594fSAndroid Build Coastguard Worker V(Character, 0, 127, DataType::Type::kUint16, kShortCacheLastIndex) \ 42*795d594fSAndroid Build Coastguard Worker V(Integer, -128, 127, DataType::Type::kInt32, kCharacterCacheLastIndex) 43*795d594fSAndroid Build Coastguard Worker 44*795d594fSAndroid Build Coastguard Worker #define DEFINE_BOXED_CONSTANTS(name, low, high, unused, start_index) \ 45*795d594fSAndroid Build Coastguard Worker static constexpr size_t k ##name ##CacheLastIndex = start_index + (high - low + 1); \ 46*795d594fSAndroid Build Coastguard Worker static constexpr size_t k ##name ##CacheFirstIndex = start_index; 47*795d594fSAndroid Build Coastguard Worker BOXED_TYPES(DEFINE_BOXED_CONSTANTS) 48*795d594fSAndroid Build Coastguard Worker 49*795d594fSAndroid Build Coastguard Worker static constexpr size_t kNumberOfBoxedCaches = kIntegerCacheLastIndex; 50*795d594fSAndroid Build Coastguard Worker #undef DEFINE_BOXED_CONSTANTS 51*795d594fSAndroid Build Coastguard Worker 52*795d594fSAndroid Build Coastguard Worker class IntrinsicObjects { 53*795d594fSAndroid Build Coastguard Worker public: 54*795d594fSAndroid Build Coastguard Worker enum class PatchType { 55*795d594fSAndroid Build Coastguard Worker kValueOfObject, 56*795d594fSAndroid Build Coastguard Worker kValueOfArray, 57*795d594fSAndroid Build Coastguard Worker 58*795d594fSAndroid Build Coastguard Worker kLast = kValueOfArray 59*795d594fSAndroid Build Coastguard Worker }; 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker static uint32_t EncodePatch(PatchType patch_type, uint32_t index = 0u) { 62*795d594fSAndroid Build Coastguard Worker return PatchTypeField::Encode(static_cast<uint32_t>(patch_type)) | IndexField::Encode(index); 63*795d594fSAndroid Build Coastguard Worker } 64*795d594fSAndroid Build Coastguard Worker DecodePatchType(uint32_t intrinsic_data)65*795d594fSAndroid Build Coastguard Worker static PatchType DecodePatchType(uint32_t intrinsic_data) { 66*795d594fSAndroid Build Coastguard Worker return static_cast<PatchType>(PatchTypeField::Decode(intrinsic_data)); 67*795d594fSAndroid Build Coastguard Worker } 68*795d594fSAndroid Build Coastguard Worker DecodePatchIndex(uint32_t intrinsic_data)69*795d594fSAndroid Build Coastguard Worker static uint32_t DecodePatchIndex(uint32_t intrinsic_data) { 70*795d594fSAndroid Build Coastguard Worker return IndexField::Decode(intrinsic_data); 71*795d594fSAndroid Build Coastguard Worker } 72*795d594fSAndroid Build Coastguard Worker 73*795d594fSAndroid Build Coastguard Worker // Helpers returning addresses of objects, suitable for embedding in generated code. 74*795d594fSAndroid Build Coastguard Worker #define DEFINE_BOXED_ACCESSES(name, unused1, unused2, unused3, start_index) \ 75*795d594fSAndroid Build Coastguard Worker static ObjPtr<mirror::Object> Get ##name ##ValueOfObject( \ 76*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects, \ 77*795d594fSAndroid Build Coastguard Worker uint32_t index) REQUIRES_SHARED(Locks::mutator_lock_) { \ 78*795d594fSAndroid Build Coastguard Worker return GetValueOfObject(boot_image_live_objects, k ##name ##CacheFirstIndex, index); \ 79*795d594fSAndroid Build Coastguard Worker } \ 80*795d594fSAndroid Build Coastguard Worker static MemberOffset Get ##name ##ValueOfArrayDataOffset( \ 81*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects) \ 82*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_) { \ 83*795d594fSAndroid Build Coastguard Worker return GetValueOfArrayDataOffset(boot_image_live_objects, k ##name ##CacheFirstIndex); \ 84*795d594fSAndroid Build Coastguard Worker } 85*795d594fSAndroid Build Coastguard Worker BOXED_TYPES(DEFINE_BOXED_ACCESSES) 86*795d594fSAndroid Build Coastguard Worker #undef DEFINED_BOXED_ACCESSES 87*795d594fSAndroid Build Coastguard Worker 88*795d594fSAndroid Build Coastguard Worker EXPORT static void FillIntrinsicObjects( 89*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects, size_t start_index) 90*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 91*795d594fSAndroid Build Coastguard Worker GetNumberOfIntrinsicObjects()92*795d594fSAndroid Build Coastguard Worker static constexpr size_t GetNumberOfIntrinsicObjects() { 93*795d594fSAndroid Build Coastguard Worker return kNumberOfBoxedCaches; 94*795d594fSAndroid Build Coastguard Worker } 95*795d594fSAndroid Build Coastguard Worker 96*795d594fSAndroid Build Coastguard Worker EXPORT static ObjPtr<mirror::Object> GetValueOfObject( 97*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects, 98*795d594fSAndroid Build Coastguard Worker size_t start_index, 99*795d594fSAndroid Build Coastguard Worker uint32_t index) REQUIRES_SHARED(Locks::mutator_lock_); 100*795d594fSAndroid Build Coastguard Worker 101*795d594fSAndroid Build Coastguard Worker EXPORT static MemberOffset GetValueOfArrayDataOffset( 102*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects, 103*795d594fSAndroid Build Coastguard Worker size_t start_index) REQUIRES_SHARED(Locks::mutator_lock_); 104*795d594fSAndroid Build Coastguard Worker 105*795d594fSAndroid Build Coastguard Worker private: 106*795d594fSAndroid Build Coastguard Worker static constexpr size_t kPatchTypeBits = 107*795d594fSAndroid Build Coastguard Worker MinimumBitsToStore(static_cast<uint32_t>(PatchType::kLast)); 108*795d594fSAndroid Build Coastguard Worker static constexpr size_t kIndexBits = BitSizeOf<uint32_t>() - kPatchTypeBits; 109*795d594fSAndroid Build Coastguard Worker using PatchTypeField = BitField<uint32_t, 0u, kPatchTypeBits>; 110*795d594fSAndroid Build Coastguard Worker using IndexField = BitField<uint32_t, kPatchTypeBits, kIndexBits>; 111*795d594fSAndroid Build Coastguard Worker }; 112*795d594fSAndroid Build Coastguard Worker 113*795d594fSAndroid Build Coastguard Worker } // namespace art 114*795d594fSAndroid Build Coastguard Worker 115*795d594fSAndroid Build Coastguard Worker #endif // ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ 116