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