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_MIRROR_IFTABLE_H_ 18 #define ART_RUNTIME_MIRROR_IFTABLE_H_ 19 20 #include "base/casts.h" 21 #include "object_array.h" 22 23 namespace art { 24 namespace mirror { 25 26 class MANAGED IfTable FINAL : public ObjectArray<Object> { 27 public: 28 ALWAYS_INLINE Class* GetInterface(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_) { 29 Class* interface = GetWithoutChecks((i * kMax) + kInterface)->AsClass(); 30 DCHECK(interface != nullptr); 31 return interface; 32 } 33 34 ALWAYS_INLINE void SetInterface(int32_t i, Class* interface) 35 SHARED_REQUIRES(Locks::mutator_lock_); 36 37 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 38 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 39 PointerArray* GetMethodArray(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_) { 40 auto* method_array = down_cast<PointerArray*>(Get<kVerifyFlags, kReadBarrierOption>( 41 (i * kMax) + kMethodArray)); 42 DCHECK(method_array != nullptr); 43 return method_array; 44 } 45 46 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 47 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 48 size_t GetMethodArrayCount(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_) { 49 auto* method_array = down_cast<PointerArray*>( 50 Get<kVerifyFlags, kReadBarrierOption>((i * kMax) + kMethodArray)); 51 return method_array == nullptr ? 0u : method_array->GetLength(); 52 } 53 54 void SetMethodArray(int32_t i, PointerArray* arr) SHARED_REQUIRES(Locks::mutator_lock_) { 55 DCHECK(arr != nullptr); 56 auto idx = i * kMax + kMethodArray; 57 DCHECK(Get(idx) == nullptr); 58 Set<false>(idx, arr); 59 } 60 61 size_t Count() SHARED_REQUIRES(Locks::mutator_lock_) { 62 return GetLength() / kMax; 63 } 64 65 enum { 66 // Points to the interface class. 67 kInterface = 0, 68 // Method pointers into the vtable, allow fast map from interface method index to concrete 69 // instance method. 70 kMethodArray = 1, 71 kMax = 2, 72 }; 73 74 private: 75 DISALLOW_IMPLICIT_CONSTRUCTORS(IfTable); 76 }; 77 78 } // namespace mirror 79 } // namespace art 80 81 #endif // ART_RUNTIME_MIRROR_IFTABLE_H_ 82