Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_DEX_CACHE_H_ |
| 18 | #define ART_SRC_DEX_CACHE_H_ |
| 19 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 20 | #include "dex_file.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 21 | #include "globals.h" |
| 22 | #include "macros.h" |
| 23 | #include "object.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class Class; |
| 28 | class Field; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 29 | class ImageWriter; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 30 | class AbstractMethod; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 31 | class String; |
| 32 | union JValue; |
| 33 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 34 | class MANAGED DexCacheClass : public Class { |
| 35 | private: |
| 36 | DISALLOW_IMPLICIT_CONSTRUCTORS(DexCacheClass); |
| 37 | }; |
| 38 | |
| 39 | class MANAGED DexCache : public Object { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 40 | public: |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 41 | void Init(const DexFile* dex_file, |
| 42 | String* location, |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 43 | ObjectArray<String>* strings, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 44 | ObjectArray<Class>* types, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 45 | ObjectArray<AbstractMethod>* methods, |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 46 | ObjectArray<Field>* fields, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 47 | ObjectArray<StaticStorageBase>* initialized_static_storage) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 48 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 49 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 50 | void Fixup(AbstractMethod* trampoline) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 51 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 52 | String* GetLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 53 | return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), false); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 54 | } |
| 55 | |
buzbee | 5cd2180 | 2011-08-26 10:40:14 -0700 | [diff] [blame] | 56 | static MemberOffset StringsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 57 | return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 60 | static MemberOffset ResolvedFieldsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 61 | return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 64 | static MemberOffset ResolvedMethodsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 65 | return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 68 | size_t NumStrings() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 69 | return GetStrings()->GetLength(); |
| 70 | } |
| 71 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 72 | size_t NumResolvedTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 73 | return GetResolvedTypes()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 76 | size_t NumResolvedMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 77 | return GetResolvedMethods()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 80 | size_t NumResolvedFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 81 | return GetResolvedFields()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 84 | size_t NumInitializedStaticStorage() const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 85 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 86 | return GetInitializedStaticStorage()->GetLength(); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 89 | String* GetResolvedString(uint32_t string_idx) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 90 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 91 | return GetStrings()->Get(string_idx); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 94 | void SetResolvedString(uint32_t string_idx, String* resolved) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 96 | GetStrings()->Set(string_idx, resolved); |
| 97 | } |
| 98 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 99 | Class* GetResolvedType(uint32_t type_idx) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 100 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 101 | return GetResolvedTypes()->Get(type_idx); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 104 | void SetResolvedType(uint32_t type_idx, Class* resolved) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 105 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 106 | GetResolvedTypes()->Set(type_idx, resolved); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 109 | AbstractMethod* GetResolvedMethod(uint32_t method_idx) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 110 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 111 | AbstractMethod* method = GetResolvedMethods()->Get(method_idx); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 112 | // Hide resolution trampoline methods from the caller |
| 113 | if (method != NULL && method->GetDexMethodIndex() == DexFile::kDexNoIndex16) { |
| 114 | DCHECK(method == Runtime::Current()->GetResolutionMethod()); |
| 115 | return NULL; |
| 116 | } else { |
| 117 | return method; |
| 118 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 121 | void SetResolvedMethod(uint32_t method_idx, AbstractMethod* resolved) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 123 | GetResolvedMethods()->Set(method_idx, resolved); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 126 | Field* GetResolvedField(uint32_t field_idx) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 127 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 128 | return GetResolvedFields()->Get(field_idx); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 131 | void SetResolvedField(uint32_t field_idx, Field* resolved) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 132 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 133 | GetResolvedFields()->Set(field_idx, resolved); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 136 | ObjectArray<String>* GetStrings() const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 137 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 138 | return GetFieldObject< ObjectArray<String>* >(StringsOffset(), false); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 139 | } |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 140 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 141 | ObjectArray<Class>* GetResolvedTypes() const |
| 142 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 143 | return GetFieldObject< ObjectArray<Class>* >( |
| 144 | OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), false); |
| 145 | } |
| 146 | |
| 147 | ObjectArray<AbstractMethod>* GetResolvedMethods() const |
| 148 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 149 | return GetFieldObject< ObjectArray<AbstractMethod>* >(ResolvedMethodsOffset(), false); |
| 150 | } |
| 151 | |
| 152 | ObjectArray<Field>* GetResolvedFields() const |
| 153 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 154 | return GetFieldObject< ObjectArray<Field>* >(ResolvedFieldsOffset(), false); |
| 155 | } |
| 156 | |
| 157 | ObjectArray<StaticStorageBase>* GetInitializedStaticStorage() const |
| 158 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 159 | return GetFieldObject< ObjectArray<StaticStorageBase>* >( |
| 160 | OFFSET_OF_OBJECT_MEMBER(DexCache, initialized_static_storage_), false); |
| 161 | } |
| 162 | |
| 163 | const DexFile* GetDexFile() const { |
| 164 | return GetFieldPtr<const DexFile*>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), false); |
| 165 | } |
| 166 | |
| 167 | void SetDexFile(const DexFile* dex_file) { |
| 168 | return SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 169 | } |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 170 | |
| 171 | private: |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 172 | ObjectArray<StaticStorageBase>* initialized_static_storage_; |
| 173 | String* location_; |
| 174 | ObjectArray<Object>* resolved_fields_; |
| 175 | ObjectArray<AbstractMethod>* resolved_methods_; |
| 176 | ObjectArray<Class>* resolved_types_; |
| 177 | ObjectArray<String>* strings_; |
| 178 | uint32_t dex_file_; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 179 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 180 | friend struct DexCacheOffsets; // for verifying offset information |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 181 | DISALLOW_IMPLICIT_CONSTRUCTORS(DexCache); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 184 | } // namespace art |
| 185 | |
| 186 | #endif // ART_SRC_DEX_CACHE_H_ |