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