• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEX_CACHE_H_
18 #define ART_RUNTIME_MIRROR_DEX_CACHE_H_
19 
20 #include "art_method.h"
21 #include "class.h"
22 #include "object.h"
23 #include "object_array.h"
24 #include "string.h"
25 
26 namespace art {
27 
28 struct DexCacheOffsets;
29 class DexFile;
30 class ImageWriter;
31 union JValue;
32 
33 namespace mirror {
34 
35 class ArtField;
36 class Class;
37 
38 class MANAGED DexCacheClass : public Class {
39  private:
40   DISALLOW_IMPLICIT_CONSTRUCTORS(DexCacheClass);
41 };
42 
43 class MANAGED DexCache : public Object {
44  public:
45   void Init(const DexFile* dex_file,
46             String* location,
47             ObjectArray<String>* strings,
48             ObjectArray<Class>* types,
49             ObjectArray<ArtMethod>* methods,
50             ObjectArray<ArtField>* fields,
51             ObjectArray<StaticStorageBase>* initialized_static_storage)
52       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
53 
54   void Fixup(ArtMethod* trampoline) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
55 
GetLocation()56   String* GetLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
57     return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), false);
58   }
59 
StringsOffset()60   static MemberOffset StringsOffset() {
61     return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_);
62   }
63 
ResolvedFieldsOffset()64   static MemberOffset ResolvedFieldsOffset() {
65     return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_);
66   }
67 
ResolvedMethodsOffset()68   static MemberOffset ResolvedMethodsOffset() {
69     return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_);
70   }
71 
NumStrings()72   size_t NumStrings() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
73     return GetStrings()->GetLength();
74   }
75 
NumResolvedTypes()76   size_t NumResolvedTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
77     return GetResolvedTypes()->GetLength();
78   }
79 
NumResolvedMethods()80   size_t NumResolvedMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
81     return GetResolvedMethods()->GetLength();
82   }
83 
NumResolvedFields()84   size_t NumResolvedFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
85     return GetResolvedFields()->GetLength();
86   }
87 
NumInitializedStaticStorage()88   size_t NumInitializedStaticStorage() const
89       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
90     return GetInitializedStaticStorage()->GetLength();
91   }
92 
GetResolvedString(uint32_t string_idx)93   String* GetResolvedString(uint32_t string_idx) const
94       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
95     return GetStrings()->Get(string_idx);
96   }
97 
SetResolvedString(uint32_t string_idx,String * resolved)98   void SetResolvedString(uint32_t string_idx, String* resolved)
99       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
100     GetStrings()->Set(string_idx, resolved);
101   }
102 
GetResolvedType(uint32_t type_idx)103   Class* GetResolvedType(uint32_t type_idx) const
104       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
105     return GetResolvedTypes()->Get(type_idx);
106   }
107 
SetResolvedType(uint32_t type_idx,Class * resolved)108   void SetResolvedType(uint32_t type_idx, Class* resolved)
109       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
110     GetResolvedTypes()->Set(type_idx, resolved);
111   }
112 
113   ArtMethod* GetResolvedMethod(uint32_t method_idx) const
114       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
115 
SetResolvedMethod(uint32_t method_idx,ArtMethod * resolved)116   void SetResolvedMethod(uint32_t method_idx, ArtMethod* resolved)
117       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
118     GetResolvedMethods()->Set(method_idx, resolved);
119   }
120 
GetResolvedField(uint32_t field_idx)121   ArtField* GetResolvedField(uint32_t field_idx) const
122       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
123     return GetResolvedFields()->Get(field_idx);
124   }
125 
SetResolvedField(uint32_t field_idx,ArtField * resolved)126   void SetResolvedField(uint32_t field_idx, ArtField* resolved)
127       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
128     GetResolvedFields()->Set(field_idx, resolved);
129   }
130 
GetStrings()131   ObjectArray<String>* GetStrings() const
132       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
133     return GetFieldObject< ObjectArray<String>* >(StringsOffset(), false);
134   }
135 
GetResolvedTypes()136   ObjectArray<Class>* GetResolvedTypes() const
137       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
138     return GetFieldObject< ObjectArray<Class>* >(
139         OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), false);
140   }
141 
GetResolvedMethods()142   ObjectArray<ArtMethod>* GetResolvedMethods() const
143       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
144     return GetFieldObject< ObjectArray<ArtMethod>* >(ResolvedMethodsOffset(), false);
145   }
146 
GetResolvedFields()147   ObjectArray<ArtField>* GetResolvedFields() const
148       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
149     return GetFieldObject< ObjectArray<ArtField>* >(ResolvedFieldsOffset(), false);
150   }
151 
GetInitializedStaticStorage()152   ObjectArray<StaticStorageBase>* GetInitializedStaticStorage() const
153       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
154     return GetFieldObject< ObjectArray<StaticStorageBase>* >(
155         OFFSET_OF_OBJECT_MEMBER(DexCache, initialized_static_storage_), false);
156   }
157 
GetDexFile()158   const DexFile* GetDexFile() const {
159     return GetFieldPtr<const DexFile*>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), false);
160   }
161 
SetDexFile(const DexFile * dex_file)162   void SetDexFile(const DexFile* dex_file) {
163     return SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false);
164   }
165 
166  private:
167   Object* dex_;
168   ObjectArray<StaticStorageBase>* initialized_static_storage_;
169   String* location_;
170   ObjectArray<ArtField>* resolved_fields_;
171   ObjectArray<ArtMethod>* resolved_methods_;
172   ObjectArray<Class>* resolved_types_;
173   ObjectArray<String>* strings_;
174   uint32_t dex_file_;
175 
176   friend struct art::DexCacheOffsets;  // for verifying offset information
177   DISALLOW_IMPLICIT_CONSTRUCTORS(DexCache);
178 };
179 
180 }  // namespace mirror
181 }  // namespace art
182 
183 #endif  // ART_RUNTIME_MIRROR_DEX_CACHE_H_
184