blob: 0522f134afa3f0f3c1cf5babd6d1dc54d1a33245 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstrom7e49dca2011-07-22 18:07:34 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_DEX_CACHE_H_
18#define ART_RUNTIME_MIRROR_DEX_CACHE_H_
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070019
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "art_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "class.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070022#include "object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "object_array.h"
24#include "string.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070025
26namespace art {
27
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028struct DexCacheOffsets;
29class DexFile;
30class ImageWriter;
31union JValue;
32
33namespace mirror {
34
Brian Carlstromea46f952013-07-30 01:26:50 -070035class ArtField;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070036class Class;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070037
Mathieu Chartier66f19252012-09-18 08:57:04 -070038class MANAGED DexCacheClass : public Class {
39 private:
40 DISALLOW_IMPLICIT_CONSTRUCTORS(DexCacheClass);
41};
42
43class MANAGED DexCache : public Object {
Brian Carlstrom83db7722011-08-26 17:32:56 -070044 public:
Mathieu Chartier66f19252012-09-18 08:57:04 -070045 void Init(const DexFile* dex_file,
46 String* location,
Brian Carlstroma663ea52011-08-19 23:33:41 -070047 ObjectArray<String>* strings,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070048 ObjectArray<Class>* types,
Brian Carlstromea46f952013-07-30 01:26:50 -070049 ObjectArray<ArtMethod>* methods,
50 ObjectArray<ArtField>* fields,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070051 ObjectArray<StaticStorageBase>* initialized_static_storage)
Ian Rogersb726dcb2012-09-05 08:57:23 -070052 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070053
Brian Carlstromea46f952013-07-30 01:26:50 -070054 void Fixup(ArtMethod* trampoline) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -080055
Ian Rogersb726dcb2012-09-05 08:57:23 -070056 String* GetLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier66f19252012-09-18 08:57:04 -070057 return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), false);
Brian Carlstroma663ea52011-08-19 23:33:41 -070058 }
59
buzbee5cd21802011-08-26 10:40:14 -070060 static MemberOffset StringsOffset() {
Mathieu Chartier66f19252012-09-18 08:57:04 -070061 return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_);
buzbeec5ef0462011-08-25 18:44:49 -070062 }
63
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070064 static MemberOffset ResolvedFieldsOffset() {
Mathieu Chartier66f19252012-09-18 08:57:04 -070065 return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_);
buzbeec5ef0462011-08-25 18:44:49 -070066 }
67
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070068 static MemberOffset ResolvedMethodsOffset() {
Mathieu Chartier66f19252012-09-18 08:57:04 -070069 return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_);
buzbeec5ef0462011-08-25 18:44:49 -070070 }
71
Ian Rogersb726dcb2012-09-05 08:57:23 -070072 size_t NumStrings() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070073 return GetStrings()->GetLength();
74 }
75
Ian Rogersb726dcb2012-09-05 08:57:23 -070076 size_t NumResolvedTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070077 return GetResolvedTypes()->GetLength();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070078 }
79
Ian Rogersb726dcb2012-09-05 08:57:23 -070080 size_t NumResolvedMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070081 return GetResolvedMethods()->GetLength();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070082 }
83
Ian Rogersb726dcb2012-09-05 08:57:23 -070084 size_t NumResolvedFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070085 return GetResolvedFields()->GetLength();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070086 }
87
Ian Rogers00f7d0e2012-07-19 15:28:27 -070088 size_t NumInitializedStaticStorage() const
Ian Rogersb726dcb2012-09-05 08:57:23 -070089 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070090 return GetInitializedStaticStorage()->GetLength();
Brian Carlstrom83db7722011-08-26 17:32:56 -070091 }
92
Ian Rogers00f7d0e2012-07-19 15:28:27 -070093 String* GetResolvedString(uint32_t string_idx) const
Ian Rogersb726dcb2012-09-05 08:57:23 -070094 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom4a96b602011-07-26 16:40:23 -070095 return GetStrings()->Get(string_idx);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070096 }
97
Ian Rogers00f7d0e2012-07-19 15:28:27 -070098 void SetResolvedString(uint32_t string_idx, String* resolved)
Ian Rogersb726dcb2012-09-05 08:57:23 -070099 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700100 GetStrings()->Set(string_idx, resolved);
101 }
102
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700103 Class* GetResolvedType(uint32_t type_idx) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700104 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700105 return GetResolvedTypes()->Get(type_idx);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700106 }
107
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700108 void SetResolvedType(uint32_t type_idx, Class* resolved)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700110 GetResolvedTypes()->Set(type_idx, resolved);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700111 }
112
Brian Carlstromea46f952013-07-30 01:26:50 -0700113 ArtMethod* GetResolvedMethod(uint32_t method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700115
Brian Carlstromea46f952013-07-30 01:26:50 -0700116 void SetResolvedMethod(uint32_t method_idx, ArtMethod* resolved)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700117 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700118 GetResolvedMethods()->Set(method_idx, resolved);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700119 }
120
Brian Carlstromea46f952013-07-30 01:26:50 -0700121 ArtField* GetResolvedField(uint32_t field_idx) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700122 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700123 return GetResolvedFields()->Get(field_idx);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700124 }
125
Brian Carlstromea46f952013-07-30 01:26:50 -0700126 void SetResolvedField(uint32_t field_idx, ArtField* resolved)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700127 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700128 GetResolvedFields()->Set(field_idx, resolved);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700129 }
130
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700131 ObjectArray<String>* GetStrings() const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700132 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier66f19252012-09-18 08:57:04 -0700133 return GetFieldObject< ObjectArray<String>* >(StringsOffset(), false);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700134 }
Brian Carlstrom83db7722011-08-26 17:32:56 -0700135
Mathieu Chartier66f19252012-09-18 08:57:04 -0700136 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
Brian Carlstromea46f952013-07-30 01:26:50 -0700142 ObjectArray<ArtMethod>* GetResolvedMethods() const
Mathieu Chartier66f19252012-09-18 08:57:04 -0700143 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700144 return GetFieldObject< ObjectArray<ArtMethod>* >(ResolvedMethodsOffset(), false);
Mathieu Chartier66f19252012-09-18 08:57:04 -0700145 }
146
Brian Carlstromea46f952013-07-30 01:26:50 -0700147 ObjectArray<ArtField>* GetResolvedFields() const
Mathieu Chartier66f19252012-09-18 08:57:04 -0700148 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700149 return GetFieldObject< ObjectArray<ArtField>* >(ResolvedFieldsOffset(), false);
Mathieu Chartier66f19252012-09-18 08:57:04 -0700150 }
151
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
158 const DexFile* GetDexFile() const {
159 return GetFieldPtr<const DexFile*>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), false);
160 }
161
162 void SetDexFile(const DexFile* dex_file) {
163 return SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700164 }
Brian Carlstromc4fa2c02011-08-21 03:00:12 -0700165
166 private:
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700167 Object* dex_;
Mathieu Chartier66f19252012-09-18 08:57:04 -0700168 ObjectArray<StaticStorageBase>* initialized_static_storage_;
169 String* location_;
Brian Carlstromea46f952013-07-30 01:26:50 -0700170 ObjectArray<ArtField>* resolved_fields_;
171 ObjectArray<ArtMethod>* resolved_methods_;
Mathieu Chartier66f19252012-09-18 08:57:04 -0700172 ObjectArray<Class>* resolved_types_;
173 ObjectArray<String>* strings_;
174 uint32_t dex_file_;
Brian Carlstrom83db7722011-08-26 17:32:56 -0700175
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700176 friend struct art::DexCacheOffsets; // for verifying offset information
Brian Carlstromc4fa2c02011-08-21 03:00:12 -0700177 DISALLOW_IMPLICIT_CONSTRUCTORS(DexCache);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700178};
179
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700181} // namespace art
182
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700183#endif // ART_RUNTIME_MIRROR_DEX_CACHE_H_