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 "base/macros.h" 22 #include "class.h" 23 #include "dex_cache.h" 24 #include "object.h" 25 #include "object_array.h" 26 #include "string.h" 27 28 namespace art HIDDEN { 29 30 struct ClassExtOffsets; 31 class DexCacheVisitor; 32 33 namespace mirror { 34 35 // C++ mirror of dalvik.system.ClassExt 36 class MANAGED ClassExt : public Object { 37 public: 38 MIRROR_CLASS("Ldalvik/system/ClassExt;"); 39 40 static uint32_t ClassSize(PointerSize pointer_size); 41 42 // Size of an instance of dalvik.system.ClassExt. InstanceSize()43 static constexpr uint32_t InstanceSize() { 44 return sizeof(ClassExt); 45 } 46 47 void SetErroneousStateError(ObjPtr<Throwable> obj) REQUIRES_SHARED(Locks::mutator_lock_); 48 49 ObjPtr<Throwable> GetErroneousStateError() REQUIRES_SHARED(Locks::mutator_lock_); 50 51 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 52 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 53 ObjPtr<ObjectArray<DexCache>> GetObsoleteDexCaches() REQUIRES_SHARED(Locks::mutator_lock_); 54 55 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 56 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 57 bool EnsureInstanceJFieldIDsArrayPresent(size_t count) 58 REQUIRES_SHARED(Locks::mutator_lock_); 59 60 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 61 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 62 ObjPtr<PointerArray> GetInstanceJFieldIDsPointerArray() REQUIRES_SHARED(Locks::mutator_lock_); 63 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 64 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 65 ObjPtr<Object> GetInstanceJFieldIDs() REQUIRES_SHARED(Locks::mutator_lock_); 66 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 67 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 68 bool HasInstanceFieldPointerIdMarker() REQUIRES_SHARED(Locks::mutator_lock_); 69 70 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 71 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 72 bool EnsureStaticJFieldIDsArrayPresent(size_t count) 73 REQUIRES_SHARED(Locks::mutator_lock_); 74 75 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 76 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 77 ObjPtr<PointerArray> GetStaticJFieldIDsPointerArray() REQUIRES_SHARED(Locks::mutator_lock_); 78 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 79 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 80 ObjPtr<Object> GetStaticJFieldIDs() REQUIRES_SHARED(Locks::mutator_lock_); 81 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 82 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 83 bool HasStaticFieldPointerIdMarker() REQUIRES_SHARED(Locks::mutator_lock_); 84 85 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 86 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 87 bool EnsureJMethodIDsArrayPresent(size_t count) 88 REQUIRES_SHARED(Locks::mutator_lock_); 89 90 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 91 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 92 ObjPtr<Object> GetJMethodIDs() REQUIRES_SHARED(Locks::mutator_lock_); 93 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 94 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 95 ObjPtr<PointerArray> GetJMethodIDsPointerArray() REQUIRES_SHARED(Locks::mutator_lock_); 96 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 97 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 98 bool HasMethodPointerIdMarker() REQUIRES_SHARED(Locks::mutator_lock_); 99 100 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 101 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 102 ObjPtr<PointerArray> GetObsoleteMethods() REQUIRES_SHARED(Locks::mutator_lock_); 103 104 ObjPtr<Object> GetOriginalDexFile() REQUIRES_SHARED(Locks::mutator_lock_); 105 106 // Used to manually initialize the ext-ids arrays for the ClassExt associated 107 // with the Class<ClassExt>. This simplifies the id allocation path. 108 EXPORT void SetIdsArraysForClassExtExtData(ObjPtr<Object> marker) 109 REQUIRES_SHARED(Locks::mutator_lock_); 110 111 EXPORT void SetOriginalDexFile(ObjPtr<Object> bytes) REQUIRES_SHARED(Locks::mutator_lock_); 112 GetPreRedefineClassDefIndex()113 uint16_t GetPreRedefineClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_) { 114 return static_cast<uint16_t>( 115 GetField32(OFFSET_OF_OBJECT_MEMBER(ClassExt, pre_redefine_class_def_index_))); 116 } 117 118 EXPORT void SetPreRedefineClassDefIndex(uint16_t index) REQUIRES_SHARED(Locks::mutator_lock_); 119 GetPreRedefineDexFile()120 const DexFile* GetPreRedefineDexFile() REQUIRES_SHARED(Locks::mutator_lock_) { 121 return reinterpret_cast<const DexFile*>(static_cast<uintptr_t>( 122 GetField64(OFFSET_OF_OBJECT_MEMBER(ClassExt, pre_redefine_dex_file_ptr_)))); 123 } 124 125 EXPORT void SetPreRedefineDexFile(const DexFile* dex_file) REQUIRES_SHARED(Locks::mutator_lock_); 126 127 EXPORT void SetObsoleteArrays(ObjPtr<PointerArray> methods, 128 ObjPtr<ObjectArray<DexCache>> dex_caches) 129 REQUIRES_SHARED(Locks::mutator_lock_); 130 131 // Extend the obsolete arrays by the given amount. 132 EXPORT static bool ExtendObsoleteArrays(Handle<ClassExt> h_this, Thread* self, uint32_t increase) 133 REQUIRES_SHARED(Locks::mutator_lock_); 134 135 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, 136 bool kVisitProxyMethod = true, 137 class Visitor> 138 inline void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size) 139 REQUIRES_SHARED(Locks::mutator_lock_); 140 141 // NO_THREAD_SAFETY_ANALYSIS for dex_lock and heap_bitmap_lock_ as both are at 142 // higher lock-level than class-table's lock, which is already acquired and 143 // is at lower (kClassLoaderClassesLock) level. 144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 145 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 146 inline void VisitDexCaches(DexCacheVisitor& visitor) 147 NO_THREAD_SAFETY_ANALYSIS 148 REQUIRES_SHARED(Locks::mutator_lock_); 149 150 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor> 151 inline void VisitMethods(Visitor visitor, PointerSize pointer_size) 152 REQUIRES_SHARED(Locks::mutator_lock_); 153 154 static ObjPtr<ClassExt> Alloc(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); 155 156 // TODO Save the obsolete class, if we have one. 157 // TODO We need this so jit-cleanup can work. the obsolete class might get cleaned up early 158 // otherwise. We should remove the need for this. 159 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 160 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 161 ObjPtr<Class> GetObsoleteClass() REQUIRES_SHARED(Locks::mutator_lock_); 162 EXPORT void SetObsoleteClass(ObjPtr<Class> classes) REQUIRES_SHARED(Locks::mutator_lock_); 163 164 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor> 165 inline void VisitJFieldIDs(Visitor v) REQUIRES_SHARED(Locks::mutator_lock_); 166 167 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor> 168 inline void VisitJMethodIDs(Visitor v) REQUIRES_SHARED(Locks::mutator_lock_); 169 170 private: 171 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, 172 ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 173 bool EnsureJniIdsArrayPresent(MemberOffset off, size_t count) 174 REQUIRES_SHARED(Locks::mutator_lock_); 175 176 // Backing store of user-defined values pertaining to a class. 177 // Maintained by the ClassValue class. 178 HeapReference<Object> class_value_map_; 179 180 // The saved error for this class being erroneous. 181 HeapReference<Throwable> erroneous_state_error_; 182 183 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". 184 // An array containing the jfieldIDs assigned to each field in the corresponding position in the 185 // classes ifields_ array or '0' if no id has been assigned to that field yet. 186 HeapReference<PointerArray> instance_jfield_ids_; 187 188 // An array containing the jmethodIDs assigned to each method in the corresponding position in 189 // the classes methods_ array or '0' if no id has been assigned to that method yet. 190 HeapReference<PointerArray> jmethod_ids_; 191 192 // If set this is the Class object that was being used before a structural redefinition occurred. 193 HeapReference<Class> obsolete_class_; 194 195 HeapReference<ObjectArray<DexCache>> obsolete_dex_caches_; 196 197 HeapReference<PointerArray> obsolete_methods_; 198 199 HeapReference<Object> original_dex_file_; 200 201 // An array containing the jfieldIDs assigned to each field in the corresponding position in the 202 // classes sfields_ array or '0' if no id has been assigned to that field yet. 203 HeapReference<PointerArray> static_jfield_ids_; 204 205 int32_t pre_redefine_class_def_index_; 206 207 // Native pointer to DexFile and ClassDef index of this class before it was JVMTI-redefined. 208 int64_t pre_redefine_dex_file_ptr_; 209 210 friend struct art::ClassExtOffsets; // for verifying offset information 211 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassExt); 212 }; 213 214 } // namespace mirror 215 } // namespace art 216 217 #endif // ART_RUNTIME_MIRROR_CLASS_EXT_H_ 218