1 /* 2 * Copyright (C) 2016 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_CLASS_EXT_H_ 18 #define ART_RUNTIME_MIRROR_CLASS_EXT_H_ 19 20 #include "array.h" 21 #include "class.h" 22 #include "dex_cache.h" 23 #include "gc_root.h" 24 #include "object.h" 25 #include "object_array.h" 26 #include "object_callbacks.h" 27 #include "string.h" 28 29 namespace art { 30 31 struct ClassExtOffsets; 32 33 namespace mirror { 34 35 // C++ mirror of dalvik.system.ClassExt 36 class MANAGED ClassExt : public Object { 37 public: 38 static uint32_t ClassSize(PointerSize pointer_size); 39 40 // Size of an instance of dalvik.system.ClassExt. InstanceSize()41 static constexpr uint32_t InstanceSize() { 42 return sizeof(ClassExt); 43 } 44 45 void SetVerifyError(ObjPtr<Object> obj) REQUIRES_SHARED(Locks::mutator_lock_); 46 GetVerifyError()47 Object* GetVerifyError() REQUIRES_SHARED(Locks::mutator_lock_) { 48 return GetFieldObject<ClassExt>(OFFSET_OF_OBJECT_MEMBER(ClassExt, verify_error_)); 49 } 50 GetObsoleteDexCaches()51 ObjectArray<DexCache>* GetObsoleteDexCaches() REQUIRES_SHARED(Locks::mutator_lock_) { 52 return GetFieldObject<ObjectArray<DexCache>>( 53 OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_dex_caches_)); 54 } 55 56 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 57 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> GetObsoleteMethods()58 inline PointerArray* GetObsoleteMethods() REQUIRES_SHARED(Locks::mutator_lock_) { 59 return GetFieldObject<PointerArray, kVerifyFlags, kReadBarrierOption>( 60 OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_methods_)); 61 } 62 GetOriginalDexFile()63 Object* GetOriginalDexFile() REQUIRES_SHARED(Locks::mutator_lock_) { 64 return GetFieldObject<Object>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_)); 65 } 66 67 void SetOriginalDexFile(ObjPtr<Object> bytes) REQUIRES_SHARED(Locks::mutator_lock_); 68 69 void SetObsoleteArrays(ObjPtr<PointerArray> methods, ObjPtr<ObjectArray<DexCache>> dex_caches) 70 REQUIRES_SHARED(Locks::mutator_lock_); 71 72 // Extend the obsolete arrays by the given amount. 73 bool ExtendObsoleteArrays(Thread* self, uint32_t increase) 74 REQUIRES_SHARED(Locks::mutator_lock_); 75 76 static void SetClass(ObjPtr<Class> dalvik_system_ClassExt); 77 static void ResetClass(); 78 static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); 79 80 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor> 81 inline void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size) 82 REQUIRES_SHARED(Locks::mutator_lock_); 83 84 static ClassExt* Alloc(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); 85 86 private: 87 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". 88 HeapReference<ObjectArray<DexCache>> obsolete_dex_caches_; 89 90 HeapReference<PointerArray> obsolete_methods_; 91 92 HeapReference<Object> original_dex_file_; 93 94 // The saved verification error of this class. 95 HeapReference<Object> verify_error_; 96 97 static GcRoot<Class> dalvik_system_ClassExt_; 98 99 friend struct art::ClassExtOffsets; // for verifying offset information 100 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassExt); 101 }; 102 103 } // namespace mirror 104 } // namespace art 105 106 #endif // ART_RUNTIME_MIRROR_CLASS_EXT_H_ 107