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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_DEX_CACHE_H_ |
| 18 | #define ART_RUNTIME_MIRROR_DEX_CACHE_H_ |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 19 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 20 | #include "art_field.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 22 | #include "class.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 23 | #include "object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "object_array.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | struct DexCacheOffsets; |
| 29 | class DexFile; |
| 30 | class ImageWriter; |
| 31 | union JValue; |
| 32 | |
| 33 | namespace mirror { |
| 34 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 35 | class String; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 36 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 37 | // C++ mirror of java.lang.DexCache. |
| 38 | class MANAGED DexCache FINAL : public Object { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 39 | public: |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 40 | // Size of java.lang.DexCache.class. |
| 41 | static uint32_t ClassSize(); |
| 42 | |
| 43 | // Size of an instance of java.lang.DexCache not including referenced values. |
| 44 | static constexpr uint32_t InstanceSize() { |
| 45 | return sizeof(DexCache); |
| 46 | } |
| 47 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 48 | void Init(const DexFile* dex_file, |
| 49 | String* location, |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 50 | ObjectArray<String>* strings, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 51 | ObjectArray<Class>* types, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 52 | ObjectArray<ArtMethod>* methods, |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 53 | ObjectArray<ArtField>* fields) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 54 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 55 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 56 | void Fixup(ArtMethod* trampoline) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 57 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 58 | String* GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 59 | return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_)); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 60 | } |
| 61 | |
buzbee | 5cd2180 | 2011-08-26 10:40:14 -0700 | [diff] [blame] | 62 | static MemberOffset StringsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 63 | return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 66 | static MemberOffset ResolvedFieldsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 67 | return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 70 | static MemberOffset ResolvedMethodsOffset() { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 71 | return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 74 | size_t NumStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 75 | return GetStrings()->GetLength(); |
| 76 | } |
| 77 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 78 | size_t NumResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 79 | return GetResolvedTypes()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 82 | size_t NumResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 83 | return GetResolvedMethods()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 86 | size_t NumResolvedFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 87 | return GetResolvedFields()->GetLength(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 90 | String* GetResolvedString(uint32_t string_idx) 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 | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 94 | void SetResolvedString(uint32_t string_idx, String* resolved) ALWAYS_INLINE |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 96 | // TODO default transaction support. |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 97 | GetStrings()->Set(string_idx, resolved); |
| 98 | } |
| 99 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 100 | Class* GetResolvedType(uint32_t type_idx) ALWAYS_INLINE |
| 101 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 102 | return GetResolvedTypes()->Get(type_idx); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Andreas Gampe | aa910d5 | 2014-07-30 18:59:05 -0700 | [diff] [blame] | 105 | void SetResolvedType(uint32_t type_idx, Class* resolved) |
| 106 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 107 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 108 | ArtMethod* GetResolvedMethod(uint32_t method_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 109 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 110 | void SetResolvedMethod(uint32_t method_idx, ArtMethod* resolved) ALWAYS_INLINE |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 111 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 112 | GetResolvedMethods()->Set(method_idx, resolved); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 115 | ArtField* GetResolvedField(uint32_t field_idx) ALWAYS_INLINE |
| 116 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 117 | ArtField* field = GetResolvedFields()->Get(field_idx); |
| 118 | if (UNLIKELY(field == nullptr || field->GetDeclaringClass()->IsErroneous())) { |
| 119 | return nullptr; |
| 120 | } else { |
| 121 | return field; |
| 122 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 125 | void SetResolvedField(uint32_t field_idx, ArtField* resolved) ALWAYS_INLINE |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 126 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 127 | GetResolvedFields()->Set(field_idx, resolved); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 130 | ObjectArray<String>* GetStrings() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 131 | return GetFieldObject< ObjectArray<String>>(StringsOffset()); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 132 | } |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 133 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 134 | ObjectArray<Class>* GetResolvedTypes() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 135 | return GetFieldObject<ObjectArray<Class>>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 136 | OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_)); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 139 | ObjectArray<ArtMethod>* GetResolvedMethods() ALWAYS_INLINE |
| 140 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 141 | return GetFieldObject< ObjectArray<ArtMethod>>(ResolvedMethodsOffset()); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 144 | ObjectArray<ArtField>* GetResolvedFields() ALWAYS_INLINE |
| 145 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 146 | return GetFieldObject<ObjectArray<ArtField>>(ResolvedFieldsOffset()); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 149 | const DexFile* GetDexFile() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 150 | return GetFieldPtr<const DexFile*>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_)); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 153 | void SetDexFile(const DexFile* dex_file) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 154 | ALWAYS_INLINE { |
| 155 | return SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 156 | } |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 157 | |
| 158 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 159 | HeapReference<Object> dex_; |
| 160 | HeapReference<String> location_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 161 | HeapReference<ObjectArray<ArtField>> resolved_fields_; |
| 162 | HeapReference<ObjectArray<ArtMethod>> resolved_methods_; |
| 163 | HeapReference<ObjectArray<Class>> resolved_types_; |
| 164 | HeapReference<ObjectArray<String>> strings_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 165 | uint64_t dex_file_; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 166 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 167 | friend struct art::DexCacheOffsets; // for verifying offset information |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 168 | DISALLOW_IMPLICIT_CONSTRUCTORS(DexCache); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | } // namespace mirror |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 172 | } // namespace art |
| 173 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 174 | #endif // ART_RUNTIME_MIRROR_DEX_CACHE_H_ |