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