Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -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 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_CLASS_H_ |
| 18 | #define ART_RUNTIME_MIRROR_CLASS_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 20 | #include "dex_file.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 21 | #include "gc_root.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 22 | #include "gc/allocator_type.h" |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 23 | #include "invoke_type.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "modifiers.h" |
| 25 | #include "object.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 26 | #include "object_array.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 27 | #include "object_callbacks.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "primitive.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 29 | #include "read_barrier_option.h" |
Hiroshi Yamauchi | f4c15a1 | 2014-10-20 16:56:58 -0700 | [diff] [blame] | 30 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | |
Mathieu Chartier | cd195fe | 2014-11-25 18:36:01 -0800 | [diff] [blame] | 32 | #ifndef IMT_SIZE |
| 33 | #error IMT_SIZE not defined |
| 34 | #endif |
| 35 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | namespace art { |
| 37 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | struct ClassOffsets; |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 39 | template<class T> class Handle; |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 40 | template<class T> class Handle; |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 41 | class Signature; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | class StringPiece; |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 43 | template<size_t kNumReferences> class PACKED(4) StackHandleScope; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | |
| 45 | namespace mirror { |
| 46 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 47 | class ArtField; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 48 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 49 | class ClassLoader; |
| 50 | class DexCache; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 51 | class IfTable; |
| 52 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | // C++ mirror of java.lang.Class |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 54 | class MANAGED Class FINAL : public Object { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 55 | public: |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 56 | // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when |
| 57 | // this is the value. |
| 58 | // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by |
| 59 | // 2 ref instance fields.] |
| 60 | static constexpr uint32_t kClassWalkSuper = 0xC0000000; |
| 61 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 62 | // Interface method table size. Increasing this value reduces the chance of two interface methods |
| 63 | // colliding in the interface method table but increases the size of classes that implement |
| 64 | // (non-marker) interfaces. |
Mathieu Chartier | cd195fe | 2014-11-25 18:36:01 -0800 | [diff] [blame] | 65 | static constexpr size_t kImtSize = IMT_SIZE; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 66 | |
| 67 | // imtable entry embedded in class object. |
| 68 | struct MANAGED ImTableEntry { |
| 69 | HeapReference<ArtMethod> method; |
| 70 | }; |
| 71 | |
| 72 | // vtable entry embedded in class object. |
| 73 | struct MANAGED VTableEntry { |
| 74 | HeapReference<ArtMethod> method; |
| 75 | }; |
| 76 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 77 | // Class Status |
| 78 | // |
Mingyao Yang | 46f0e97 | 2014-09-10 15:16:19 -0700 | [diff] [blame] | 79 | // kStatusRetired: Class that's temporarily used till class linking time |
| 80 | // has its (vtable) size figured out and has been cloned to one with the |
| 81 | // right size which will be the one used later. The old one is retired and |
| 82 | // will be gc'ed once all refs to the class point to the newly |
| 83 | // cloned version. |
| 84 | // |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 85 | // kStatusNotReady: If a Class cannot be found in the class table by |
| 86 | // FindClass, it allocates an new one with AllocClass in the |
| 87 | // kStatusNotReady and calls LoadClass. Note if it does find a |
| 88 | // class, it may not be kStatusResolved and it will try to push it |
| 89 | // forward toward kStatusResolved. |
| 90 | // |
| 91 | // kStatusIdx: LoadClass populates with Class with information from |
| 92 | // the DexFile, moving the status to kStatusIdx, indicating that the |
| 93 | // Class value in super_class_ has not been populated. The new Class |
| 94 | // can then be inserted into the classes table. |
| 95 | // |
| 96 | // kStatusLoaded: After taking a lock on Class, the ClassLinker will |
| 97 | // attempt to move a kStatusIdx class forward to kStatusLoaded by |
| 98 | // using ResolveClass to initialize the super_class_ and ensuring the |
| 99 | // interfaces are resolved. |
| 100 | // |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 101 | // kStatusResolving: Class is just cloned with the right size from |
| 102 | // temporary class that's acting as a placeholder for linking. The old |
| 103 | // class will be retired. New class is set to this status first before |
| 104 | // moving on to being resolved. |
| 105 | // |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 106 | // kStatusResolved: Still holding the lock on Class, the ClassLinker |
| 107 | // shows linking is complete and fields of the Class populated by making |
| 108 | // it kStatusResolved. Java allows circularities of the form where a super |
| 109 | // class has a field that is of the type of the sub class. We need to be able |
| 110 | // to fully resolve super classes while resolving types for fields. |
| 111 | // |
| 112 | // kStatusRetryVerificationAtRuntime: The verifier sets a class to |
| 113 | // this state if it encounters a soft failure at compile time. This |
| 114 | // often happens when there are unresolved classes in other dex |
| 115 | // files, and this status marks a class as needing to be verified |
| 116 | // again at runtime. |
| 117 | // |
| 118 | // TODO: Explain the other states |
| 119 | enum Status { |
Brian Carlstrom | f397866 | 2014-09-11 12:21:04 -0700 | [diff] [blame] | 120 | kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 121 | kStatusError = -1, |
| 122 | kStatusNotReady = 0, |
| 123 | kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_. |
| 124 | kStatusLoaded = 2, // DEX idx values resolved. |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 125 | kStatusResolving = 3, // Just cloned from temporary class object. |
| 126 | kStatusResolved = 4, // Part of linking. |
| 127 | kStatusVerifying = 5, // In the process of being verified. |
| 128 | kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime. |
| 129 | kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime. |
| 130 | kStatusVerified = 8, // Logically part of linking; done pre-init. |
| 131 | kStatusInitializing = 9, // Class init in progress. |
| 132 | kStatusInitialized = 10, // Ready to go. |
| 133 | kStatusMax = 11, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 136 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 137 | Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 138 | static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32"); |
Ian Rogers | 03dbc04 | 2014-06-02 14:24:56 -0700 | [diff] [blame] | 139 | return static_cast<Status>( |
| 140 | GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_))); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 143 | void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 144 | |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 145 | static MemberOffset StatusOffset() { |
| 146 | return OFFSET_OF_OBJECT_MEMBER(Class, status_); |
| 147 | } |
| 148 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 149 | // Returns true if the class has been retired. |
| 150 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 151 | bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 152 | return GetStatus<kVerifyFlags>() == kStatusRetired; |
| 153 | } |
| 154 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | // Returns true if the class has failed to link. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 156 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 157 | bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 158 | return GetStatus<kVerifyFlags>() == kStatusError; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Returns true if the class has been loaded. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 162 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 163 | bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 164 | return GetStatus<kVerifyFlags>() >= kStatusIdx; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Returns true if the class has been loaded. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 168 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 169 | bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 170 | return GetStatus<kVerifyFlags>() >= kStatusLoaded; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // Returns true if the class has been linked. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 174 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 175 | bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 176 | return GetStatus<kVerifyFlags>() >= kStatusResolved; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // Returns true if the class was compile-time verified. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 180 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 181 | bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 182 | return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // Returns true if the class has been verified. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 186 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 187 | bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 188 | return GetStatus<kVerifyFlags>() >= kStatusVerified; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Returns true if the class is initializing. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 192 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 193 | bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 194 | return GetStatus<kVerifyFlags>() >= kStatusInitializing; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // Returns true if the class is initialized. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 198 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 199 | bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 200 | return GetStatus<kVerifyFlags>() == kStatusInitialized; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 203 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 204 | ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 206 | void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 207 | |
| 208 | // Returns true if the class is an interface. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 209 | ALWAYS_INLINE bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 210 | return (GetAccessFlags() & kAccInterface) != 0; |
| 211 | } |
| 212 | |
| 213 | // Returns true if the class is declared public. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 214 | ALWAYS_INLINE bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 215 | return (GetAccessFlags() & kAccPublic) != 0; |
| 216 | } |
| 217 | |
| 218 | // Returns true if the class is declared final. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 219 | ALWAYS_INLINE bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 220 | return (GetAccessFlags() & kAccFinal) != 0; |
| 221 | } |
| 222 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 223 | ALWAYS_INLINE bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 224 | return (GetAccessFlags() & kAccClassIsFinalizable) != 0; |
| 225 | } |
| 226 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 227 | ALWAYS_INLINE void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 228 | uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 229 | SetAccessFlags(flags | kAccClassIsFinalizable); |
| 230 | } |
| 231 | |
| 232 | // Returns true if the class is abstract. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 233 | ALWAYS_INLINE bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 234 | return (GetAccessFlags() & kAccAbstract) != 0; |
| 235 | } |
| 236 | |
| 237 | // Returns true if the class is an annotation. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 238 | ALWAYS_INLINE bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 239 | return (GetAccessFlags() & kAccAnnotation) != 0; |
| 240 | } |
| 241 | |
| 242 | // Returns true if the class is synthetic. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 243 | ALWAYS_INLINE bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 244 | return (GetAccessFlags() & kAccSynthetic) != 0; |
| 245 | } |
| 246 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 247 | // Returns true if the class can avoid access checks. |
| 248 | bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 249 | return (GetAccessFlags() & kAccPreverified) != 0; |
| 250 | } |
| 251 | |
| 252 | void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 253 | uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_)); |
| 254 | SetAccessFlags(flags | kAccPreverified); |
| 255 | } |
| 256 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 257 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 258 | bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 259 | return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 262 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 263 | bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 264 | return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 267 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 268 | bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 269 | return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 272 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 273 | bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 274 | return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 277 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 278 | bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 279 | return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Ian Rogers | 04f94f4 | 2013-06-10 15:09:26 -0700 | [diff] [blame] | 282 | // Can references of this type be assigned to by things of another type? For non-array types |
| 283 | // this is a matter of whether sub-classes may exist - which they can't if the type is final. |
| 284 | // For array classes, where all the classes are final due to there being no sub-classes, an |
| 285 | // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other |
| 286 | // types as the component is final. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 287 | bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 04f94f4 | 2013-06-10 15:09:26 -0700 | [diff] [blame] | 288 | if (!IsArrayClass()) { |
| 289 | return IsFinal(); |
| 290 | } else { |
| 291 | Class* component = GetComponentType(); |
| 292 | if (component->IsPrimitive()) { |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 293 | return true; |
Ian Rogers | 04f94f4 | 2013-06-10 15:09:26 -0700 | [diff] [blame] | 294 | } else { |
| 295 | return component->CannotBeAssignedFromOtherTypes(); |
| 296 | } |
| 297 | } |
| 298 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 299 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 300 | // Returns true if this class is the placeholder and should retire and |
| 301 | // be replaced with a class with the right size for embedded imt/vtable. |
| 302 | bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 303 | Status s = GetStatus(); |
| 304 | return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable(); |
| 305 | } |
| 306 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 307 | String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 308 | void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name. |
| 309 | // Computes the name, then sets the cached value. |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 310 | static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 311 | |
Mathieu Chartier | c2f4d02 | 2014-03-03 16:11:42 -0800 | [diff] [blame] | 312 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 313 | bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 314 | // Read access flags without using getter as whether something is a proxy can be check in |
| 315 | // any loaded state |
| 316 | // TODO: switch to a check if the super class is java.lang.reflect.Proxy? |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 317 | uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 318 | return (access_flags & kAccClassIsProxy) != 0; |
| 319 | } |
| 320 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 321 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 322 | Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 323 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 324 | void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 325 | DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t)); |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 326 | int32_t v32 = static_cast<int32_t>(new_type); |
| 327 | DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero"; |
| 328 | // Store the component size shift in the upper 16 bits. |
| 329 | v32 |= Primitive::ComponentSizeShift(new_type) << 16; |
| 330 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 333 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 334 | size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 335 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 336 | // Returns true if the class is a primitive type. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 337 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 338 | bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 339 | return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 342 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 343 | bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 344 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 347 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 348 | bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 349 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 352 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 353 | bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 354 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 357 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 358 | bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 359 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 362 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 363 | bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 364 | return GetPrimitiveType() == Primitive::kPrimInt; |
| 365 | } |
| 366 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 367 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 368 | bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 369 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 372 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 373 | bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 374 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 377 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 378 | bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 379 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 382 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 383 | bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 384 | return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 387 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 388 | bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 389 | return IsArrayClass<kVerifyFlags>() && |
| 390 | GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()-> |
| 391 | IsPrimitive(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | // Depth of class from java.lang.Object |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 395 | uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 396 | uint32_t depth = 0; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 397 | for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) { |
| 398 | depth++; |
| 399 | } |
| 400 | return depth; |
| 401 | } |
| 402 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 403 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 404 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 405 | bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 406 | return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 409 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 410 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 411 | bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 412 | |
Hiroshi Yamauchi | bd0fb61 | 2014-05-20 13:46:00 -0700 | [diff] [blame] | 413 | bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 414 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 415 | bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 416 | |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 417 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Hiroshi Yamauchi | bd0fb61 | 2014-05-20 13:46:00 -0700 | [diff] [blame] | 418 | bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 419 | |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 420 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Hiroshi Yamauchi | bd0fb61 | 2014-05-20 13:46:00 -0700 | [diff] [blame] | 421 | bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 422 | |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 423 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
| 424 | bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 425 | |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 426 | static MemberOffset ComponentTypeOffset() { |
| 427 | return OFFSET_OF_OBJECT_MEMBER(Class, component_type_); |
| 428 | } |
| 429 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 430 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 431 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 432 | Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 433 | return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 437 | DCHECK(GetComponentType() == NULL); |
| 438 | DCHECK(new_component_type != NULL); |
Sebastien Hertz | ee1d79a | 2014-02-21 15:46:30 +0100 | [diff] [blame] | 439 | // Component type is invariant: use non-transactional mode without check. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 440 | SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 443 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 444 | size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 445 | return 1U << GetComponentSizeShift(); |
| 446 | } |
| 447 | |
| 448 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
| 449 | size_t GetComponentSizeShift() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 450 | return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 453 | bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 454 | return !IsPrimitive() && GetSuperClass() == NULL; |
| 455 | } |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 456 | |
| 457 | bool IsInstantiableNonArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 458 | return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass(); |
| 459 | } |
| 460 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 461 | bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 462 | return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || |
| 463 | ((IsAbstract()) && IsArrayClass()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 466 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 467 | bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 468 | return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // Creates a raw object instance but does not invoke the default constructor. |
Mathieu Chartier | 8668c3c | 2014-04-24 16:48:11 -0700 | [diff] [blame] | 472 | template<bool kIsInstrumented, bool kCheckAddFinalizer = true> |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 473 | ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type) |
| 474 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 475 | |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 476 | Object* AllocObject(Thread* self) |
| 477 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 478 | Object* AllocNonMovableObject(Thread* self) |
| 479 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 480 | |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 481 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 482 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 483 | bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 484 | // Classes and arrays vary in size, and so the object_size_ field cannot |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 485 | // be used to Get their instance size |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 486 | return IsClassClass<kVerifyFlags, kReadBarrierOption>() || |
| 487 | IsArrayClass<kVerifyFlags, kReadBarrierOption>(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 490 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 491 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 492 | uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 493 | return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 496 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 497 | uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 498 | return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 501 | void SetClassSize(uint32_t new_class_size) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 502 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 503 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 504 | // Compute how many bytes would be used a class with the given elements. |
| 505 | static uint32_t ComputeClassSize(bool has_embedded_tables, |
| 506 | uint32_t num_vtable_entries, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 507 | uint32_t num_8bit_static_fields, |
| 508 | uint32_t num_16bit_static_fields, |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 509 | uint32_t num_32bit_static_fields, |
| 510 | uint32_t num_64bit_static_fields, |
| 511 | uint32_t num_ref_static_fields); |
| 512 | |
| 513 | // The size of java.lang.Class.class. |
| 514 | static uint32_t ClassClassSize() { |
| 515 | // The number of vtable entries in java.lang.Class. |
Brian Carlstrom | b144fce | 2014-10-16 22:02:23 -0700 | [diff] [blame] | 516 | uint32_t vtable_entries = Object::kVTableLength + 66; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 517 | return ComputeClassSize(true, vtable_entries, 0, 0, 0, 1, 0); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // The size of a java.lang.Class representing a primitive such as int.class. |
| 521 | static uint32_t PrimitiveClassSize() { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 522 | return ComputeClassSize(false, 0, 0, 0, 0, 0, 0); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 525 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 526 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 527 | uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 528 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 529 | void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 530 | DCHECK(!IsVariableSize()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 531 | // Not called within a transaction. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 532 | return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 535 | void SetObjectSizeWithoutChecks(uint32_t new_object_size) |
| 536 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 537 | // Not called within a transaction. |
| 538 | return SetField32<false, false, kVerifyNone>( |
| 539 | OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size); |
| 540 | } |
| 541 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 542 | // Returns true if this class is in the same packages as that class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 543 | bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 544 | |
| 545 | static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2); |
| 546 | |
| 547 | // Returns true if this class can access that class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 548 | bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 549 | return that->IsPublic() || this->IsInSamePackage(that); |
| 550 | } |
| 551 | |
| 552 | // Can this class access a member in the provided class with the provided member access flags? |
| 553 | // Note that access to the class isn't checked in case the declaring class is protected and the |
| 554 | // method has been exposed by a public sub-class |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 555 | bool CanAccessMember(Class* access_to, uint32_t member_flags) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 556 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 557 | // Classes can access all of their own members |
| 558 | if (this == access_to) { |
| 559 | return true; |
| 560 | } |
| 561 | // Public members are trivially accessible |
| 562 | if (member_flags & kAccPublic) { |
| 563 | return true; |
| 564 | } |
| 565 | // Private members are trivially not accessible |
| 566 | if (member_flags & kAccPrivate) { |
| 567 | return false; |
| 568 | } |
| 569 | // Check for protected access from a sub-class, which may or may not be in the same package. |
| 570 | if (member_flags & kAccProtected) { |
Andreas Gampe | 13f8a16 | 2014-08-08 19:55:37 -0700 | [diff] [blame] | 571 | if (!this->IsInterface() && this->IsSubClass(access_to)) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 572 | return true; |
| 573 | } |
| 574 | } |
| 575 | // Allow protected access from other classes in the same package. |
| 576 | return this->IsInSamePackage(access_to); |
| 577 | } |
| 578 | |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 579 | // Can this class access a resolved field? |
| 580 | // Note that access to field's class is checked and this may require looking up the class |
| 581 | // referenced by the FieldId in the DexFile in case the declaring class is inaccessible. |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 582 | bool CanAccessResolvedField(Class* access_to, ArtField* field, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 583 | DexCache* dex_cache, uint32_t field_idx) |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 584 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 585 | bool CheckResolvedFieldAccess(Class* access_to, ArtField* field, |
| 586 | uint32_t field_idx) |
| 587 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 588 | |
| 589 | // Can this class access a resolved method? |
| 590 | // Note that access to methods's class is checked and this may require looking up the class |
| 591 | // referenced by the MethodId in the DexFile in case the declaring class is inaccessible. |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 592 | bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 593 | DexCache* dex_cache, uint32_t method_idx) |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 594 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 595 | template <InvokeType throw_invoke_type> |
| 596 | bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method, |
| 597 | uint32_t method_idx) |
| 598 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 599 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 600 | bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 601 | |
| 602 | // Can src be assigned to this class? For example, String can be assigned to Object (by an |
| 603 | // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing |
| 604 | // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface |
| 605 | // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign |
| 606 | // to themselves. Classes for primitive types may not assign to each other. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 607 | ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 608 | DCHECK(src != NULL); |
| 609 | if (this == src) { |
| 610 | // Can always assign to things of the same type. |
| 611 | return true; |
| 612 | } else if (IsObjectClass()) { |
| 613 | // Can assign any reference to java.lang.Object. |
| 614 | return !src->IsPrimitive(); |
| 615 | } else if (IsInterface()) { |
| 616 | return src->Implements(this); |
| 617 | } else if (src->IsArrayClass()) { |
| 618 | return IsAssignableFromArray(src); |
| 619 | } else { |
| 620 | return !src->IsInterface() && src->IsSubClass(this); |
| 621 | } |
| 622 | } |
| 623 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 624 | ALWAYS_INLINE Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 625 | |
| 626 | void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 627 | // Super class is assigned once, except during class linker initialization. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 628 | Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 629 | DCHECK(old_super_class == nullptr || old_super_class == new_super_class); |
| 630 | DCHECK(new_super_class != nullptr); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 631 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 634 | bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 635 | return GetSuperClass() != NULL; |
| 636 | } |
| 637 | |
| 638 | static MemberOffset SuperClassOffset() { |
| 639 | return MemberOffset(OFFSETOF_MEMBER(Class, super_class_)); |
| 640 | } |
| 641 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 642 | ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 643 | |
| 644 | void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 645 | |
| 646 | static MemberOffset DexCacheOffset() { |
| 647 | return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_)); |
| 648 | } |
| 649 | |
| 650 | enum { |
| 651 | kDumpClassFullDetail = 1, |
| 652 | kDumpClassClassLoader = (1 << 1), |
| 653 | kDumpClassInitialized = (1 << 2), |
| 654 | }; |
| 655 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 656 | void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 657 | |
Mathieu Chartier | c2f4d02 | 2014-03-03 16:11:42 -0800 | [diff] [blame] | 658 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 659 | DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 660 | |
Mathieu Chartier | 91a6dc4 | 2014-12-01 10:31:15 -0800 | [diff] [blame] | 661 | // Also updates the dex_cache_strings_ variable from new_dex_cache. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 662 | void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 663 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 664 | ALWAYS_INLINE ObjectArray<ArtMethod>* GetDirectMethods() |
| 665 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 666 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 667 | void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 668 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 669 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 670 | ALWAYS_INLINE ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 671 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 672 | void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 673 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 674 | |
| 675 | // Returns the number of static, private, and constructor methods. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 676 | uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 677 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 678 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 679 | ALWAYS_INLINE ObjectArray<ArtMethod>* GetVirtualMethods() |
| 680 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 681 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 682 | ALWAYS_INLINE void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 683 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 684 | |
| 685 | // Returns the number of non-inherited virtual methods. |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 686 | ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 687 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 688 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 689 | ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 690 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 691 | ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 692 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 693 | void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 694 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 695 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 696 | ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 697 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 698 | ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTableDuringLinking() |
| 699 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 700 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 701 | void SetVTable(ObjectArray<ArtMethod>* new_vtable) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 702 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 703 | |
| 704 | static MemberOffset VTableOffset() { |
| 705 | return OFFSET_OF_OBJECT_MEMBER(Class, vtable_); |
| 706 | } |
| 707 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 708 | static MemberOffset EmbeddedImTableOffset() { |
| 709 | return MemberOffset(sizeof(Class)); |
| 710 | } |
| 711 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 712 | static MemberOffset EmbeddedVTableLengthOffset() { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 713 | return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry)); |
| 714 | } |
| 715 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 716 | static MemberOffset EmbeddedVTableOffset() { |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 717 | return MemberOffset(sizeof(Class) + kImtSize * sizeof(ImTableEntry) + sizeof(int32_t)); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 720 | bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 721 | return IsInstantiable(); |
| 722 | } |
| 723 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 724 | bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 725 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 726 | ArtMethod* GetEmbeddedImTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 727 | |
| 728 | void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 729 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 730 | int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 731 | |
| 732 | ArtMethod* GetVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 733 | |
| 734 | int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 735 | |
| 736 | void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 737 | |
| 738 | ArtMethod* GetEmbeddedVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 739 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 740 | void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 741 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 742 | void PopulateEmbeddedImtAndVTable(StackHandleScope<kImtSize>* imt_handle_scope) |
| 743 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 744 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 745 | // Given a method implemented by this class but potentially from a super class, return the |
| 746 | // specific implementation method for this class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 747 | ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 748 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 749 | |
| 750 | // Given a method implemented by this class' super class, return the specific implementation |
| 751 | // method for this class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 752 | ArtMethod* FindVirtualMethodForSuper(ArtMethod* method) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 753 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 754 | |
| 755 | // Given a method implemented by this class, but potentially from a |
| 756 | // super class or interface, return the specific implementation |
| 757 | // method for this class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 758 | ArtMethod* FindVirtualMethodForInterface(ArtMethod* method) |
Ian Rogers | 1ffa32f | 2013-02-05 18:29:08 -0800 | [diff] [blame] | 759 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 760 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 761 | ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 762 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 763 | |
Brian Carlstrom | 004644f | 2014-06-18 08:34:01 -0700 | [diff] [blame] | 764 | ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature) |
| 765 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 766 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 767 | ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 768 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 769 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 770 | ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 771 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 772 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 773 | ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 774 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 775 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 776 | ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 777 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 778 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 779 | ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 780 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 781 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 782 | ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 783 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 784 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 785 | ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 786 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 787 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 788 | ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 789 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 790 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 791 | ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 792 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 793 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 794 | ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 795 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 796 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 797 | ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 798 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 799 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 800 | ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 801 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 802 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 803 | ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 804 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 805 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 806 | ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 807 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 808 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 809 | ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 810 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 811 | ALWAYS_INLINE int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 812 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 813 | ALWAYS_INLINE IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 814 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 815 | ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 816 | |
| 817 | // Get instance fields of the class (See also GetSFields). |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 818 | ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 819 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 820 | void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 821 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 822 | uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 823 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 824 | ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 825 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 826 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 827 | void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 828 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 829 | |
| 830 | // Returns the number of instance fields containing reference types. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 831 | uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 832 | DCHECK(IsResolved() || IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 833 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 836 | uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 837 | DCHECK(IsLoaded() || IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 838 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 841 | void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 842 | // Not called within a transaction. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 843 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 846 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 847 | uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 848 | |
| 849 | void SetReferenceInstanceOffsets(uint32_t new_reference_offsets) |
| 850 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 851 | |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 852 | // Get the offset of the first reference instance field. Other reference instance fields follow. |
| 853 | MemberOffset GetFirstReferenceInstanceFieldOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 854 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 855 | // Returns the number of static fields containing reference types. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 856 | uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 857 | DCHECK(IsResolved() || IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 858 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 861 | uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 862 | DCHECK(IsLoaded() || IsErroneous() || IsRetired()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 863 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 866 | void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 867 | // Not called within a transaction. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 868 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 871 | // Get the offset of the first reference static field. Other reference static fields follow. |
| 872 | MemberOffset GetFirstReferenceStaticFieldOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 873 | |
| 874 | // Get the offset of the first reference static field. Other reference static fields follow. |
| 875 | MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking() |
| 876 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 877 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 878 | // Gets the static fields of the class. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 879 | ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 880 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 881 | void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 882 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 883 | uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 884 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 885 | // TODO: uint16_t |
| 886 | ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 887 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 888 | // TODO: uint16_t |
| 889 | void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 890 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 891 | // Find a static or instance field using the JLS resolution order |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 892 | static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name, |
| 893 | const StringPiece& type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 894 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 895 | |
| 896 | // Finds the given instance field in this class or a superclass. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 897 | ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 898 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 899 | |
| 900 | // Finds the given instance field in this class or a superclass, only searches classes that |
| 901 | // have the same dex cache. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 902 | ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 903 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 904 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 905 | ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 906 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 907 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 908 | ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 909 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 910 | |
| 911 | // Finds the given static field in this class or a superclass. |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 912 | static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name, |
| 913 | const StringPiece& type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 914 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 915 | |
| 916 | // Finds the given static field in this class or superclass, only searches classes that |
| 917 | // have the same dex cache. |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 918 | static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache, |
| 919 | uint32_t dex_field_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 920 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 921 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 922 | ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 923 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 924 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 925 | ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 926 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 927 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 928 | pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 929 | DCHECK(IsIdxLoaded() || IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 930 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 931 | } |
| 932 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 933 | void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 934 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 935 | Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 936 | // DCHECK(IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 937 | return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 940 | uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 941 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_)); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 944 | void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 945 | // Not called within a transaction. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 946 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 949 | uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 950 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 953 | void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 954 | // Not called within a transaction. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 955 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 958 | static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 959 | DCHECK(!java_lang_Class_.IsNull()); |
| 960 | return java_lang_Class_.Read(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | // Can't call this SetClass or else gets called instead of Object::SetClass in places. |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 964 | static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 965 | static void ResetClass(); |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 966 | static void VisitRoots(RootCallback* callback, void* arg) |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 967 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 968 | |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 969 | // When class is verified, set the kAccPreverified flag on each method. |
| 970 | void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 971 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 972 | template <bool kVisitClass, typename Visitor> |
| 973 | void VisitReferences(mirror::Class* klass, const Visitor& visitor) |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 974 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 975 | |
| 976 | // Visit references within the embedded tables of the class. |
| 977 | // TODO: remove NO_THREAD_SAFETY_ANALYSIS when annotalysis handles visitors better. |
| 978 | template<typename Visitor> |
| 979 | void VisitEmbeddedImtAndVTable(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 980 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 981 | // Get the descriptor of the class. In a few cases a std::string is required, rather than |
| 982 | // always create one the storage argument is populated and its internal c_str() returned. We do |
| 983 | // this to avoid memory allocation in the common case. |
| 984 | const char* GetDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 985 | |
| 986 | const char* GetArrayDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 987 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 988 | bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 989 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 990 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 991 | const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 992 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 993 | ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 994 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 995 | uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 996 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 997 | static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass, |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 998 | uint32_t idx) |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 999 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1000 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 1001 | const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1002 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 1003 | std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1004 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 1005 | const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1006 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 1007 | const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1008 | |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 1009 | // Asserts we are initialized or initializing in the given thread. |
| 1010 | void AssertInitializedOrInitializingInThread(Thread* self) |
| 1011 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1012 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 1013 | Class* CopyOf(Thread* self, int32_t new_length, StackHandleScope<kImtSize>* imt_handle_scope) |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1014 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1015 | |
| 1016 | // For proxy class only. |
| 1017 | ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1018 | |
| 1019 | // For proxy class only. |
| 1020 | ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1021 | |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 1022 | // For reference class only. |
| 1023 | MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1024 | MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1025 | bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1026 | void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1027 | |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 1028 | ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1029 | void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) |
| 1030 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1031 | static MemberOffset DexCacheStringsOffset() { |
| 1032 | return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_); |
| 1033 | } |
| 1034 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1035 | // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore |
| 1036 | // fence. |
| 1037 | class InitializeClassVisitor { |
| 1038 | public: |
| 1039 | explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) { |
| 1040 | } |
| 1041 | |
| 1042 | void operator()(mirror::Object* obj, size_t usable_size) const |
| 1043 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1044 | |
| 1045 | private: |
| 1046 | const uint32_t class_size_; |
| 1047 | |
| 1048 | DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor); |
| 1049 | }; |
| 1050 | |
Sebastien Hertz | 6963e44 | 2014-11-26 22:11:27 +0100 | [diff] [blame] | 1051 | // Returns true if the class loader is null, ie the class loader is the boot strap class loader. |
| 1052 | bool IsBootStrapClassLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1053 | return GetClassLoader() == nullptr; |
| 1054 | } |
| 1055 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1056 | private: |
| 1057 | void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1058 | |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 1059 | template <bool throw_on_failure, bool use_referrers_cache> |
| 1060 | bool ResolvedFieldAccessTest(Class* access_to, ArtField* field, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1061 | uint32_t field_idx, DexCache* dex_cache) |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 1062 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1063 | template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type> |
| 1064 | bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1065 | uint32_t method_idx, DexCache* dex_cache) |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 1066 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1067 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1068 | bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1069 | bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1070 | bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1071 | |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 1072 | void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 1073 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1074 | // defining class loader, or NULL for the "bootstrap" system loader |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1075 | HeapReference<ClassLoader> class_loader_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1076 | |
| 1077 | // For array classes, the component class object for instanceof/checkcast |
| 1078 | // (for String[][][], this will be String[][]). NULL for non-array classes. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1079 | HeapReference<Class> component_type_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1080 | |
| 1081 | // DexCache of resolved constant pool entries (will be NULL for classes generated by the |
| 1082 | // runtime such as arrays and primitive classes). |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1083 | HeapReference<DexCache> dex_cache_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1084 | |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 1085 | // Short cuts to dex_cache_ member for fast compiled code access. |
| 1086 | HeapReference<ObjectArray<String>> dex_cache_strings_; |
| 1087 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1088 | // static, private, and <init> methods |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1089 | HeapReference<ObjectArray<ArtMethod>> direct_methods_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1090 | |
| 1091 | // instance fields |
| 1092 | // |
| 1093 | // These describe the layout of the contents of an Object. |
| 1094 | // Note that only the fields directly declared by this class are |
| 1095 | // listed in ifields; fields declared by a superclass are listed in |
| 1096 | // the superclass's Class.ifields. |
| 1097 | // |
| 1098 | // All instance fields that refer to objects are guaranteed to be at |
| 1099 | // the beginning of the field list. num_reference_instance_fields_ |
| 1100 | // specifies the number of reference fields. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1101 | HeapReference<ObjectArray<ArtField>> ifields_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1102 | |
| 1103 | // The interface table (iftable_) contains pairs of a interface class and an array of the |
| 1104 | // interface methods. There is one pair per interface supported by this class. That means one |
| 1105 | // pair for each interface we support directly, indirectly via superclass, or indirectly via a |
| 1106 | // superinterface. This will be null if neither we nor our superclass implement any interfaces. |
| 1107 | // |
| 1108 | // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()". |
| 1109 | // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a |
| 1110 | // single vtable. |
| 1111 | // |
| 1112 | // For every interface a concrete class implements, we create an array of the concrete vtable_ |
| 1113 | // methods for the methods in the interface. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1114 | HeapReference<IfTable> iftable_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1115 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1116 | // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName |
| 1117 | HeapReference<String> name_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1118 | |
| 1119 | // Static fields |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1120 | HeapReference<ObjectArray<ArtField>> sfields_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1121 | |
| 1122 | // The superclass, or NULL if this is java.lang.Object, an interface or primitive type. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1123 | HeapReference<Class> super_class_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1124 | |
| 1125 | // If class verify fails, we must return same error on subsequent tries. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1126 | HeapReference<Class> verify_error_class_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1127 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1128 | // Virtual methods defined in this class; invoked through vtable. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1129 | HeapReference<ObjectArray<ArtMethod>> virtual_methods_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1130 | |
| 1131 | // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is |
| 1132 | // copied in, and virtual methods from our class either replace those from the super or are |
| 1133 | // appended. For abstract classes, methods may be created in the vtable that aren't in |
| 1134 | // virtual_ methods_ for miranda methods. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1135 | HeapReference<ObjectArray<ArtMethod>> vtable_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1136 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1137 | // Access flags; low 16 bits are defined by VM spec. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1138 | uint32_t access_flags_; |
| 1139 | |
| 1140 | // Total size of the Class instance; used when allocating storage on gc heap. |
| 1141 | // See also object_size_. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1142 | uint32_t class_size_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1143 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1144 | // Tid used to check for recursive <clinit> invocation. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1145 | pid_t clinit_thread_id_; |
| 1146 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1147 | // ClassDef index in dex file, -1 if no class definition such as an array. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1148 | // TODO: really 16bits |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1149 | int32_t dex_class_def_idx_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1150 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1151 | // Type index in dex file. |
| 1152 | // TODO: really 16bits |
| 1153 | int32_t dex_type_idx_; |
| 1154 | |
| 1155 | // Number of instance fields that are object refs. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1156 | uint32_t num_reference_instance_fields_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1157 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1158 | // Number of static fields that are object refs, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1159 | uint32_t num_reference_static_fields_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1160 | |
| 1161 | // Total object size; used when allocating storage on gc heap. |
| 1162 | // (For interfaces and abstract classes this will be zero.) |
| 1163 | // See also class_size_. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1164 | uint32_t object_size_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1165 | |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 1166 | // The lower 16 bits contains a Primitive::Type value. The upper 16 |
| 1167 | // bits contains the size shift of the primitive type. |
| 1168 | uint32_t primitive_type_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1169 | |
| 1170 | // Bitmap of offsets of ifields. |
| 1171 | uint32_t reference_instance_offsets_; |
| 1172 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1173 | // State of class initialization. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1174 | Status status_; |
| 1175 | |
| 1176 | // TODO: ? |
| 1177 | // initiating class loader list |
| 1178 | // NOTE: for classes with low serialNumber, these are unused, and the |
| 1179 | // values are kept in a table in gDvm. |
| 1180 | // InitiatingLoaderList initiating_loader_list_; |
| 1181 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1182 | // The following data exist in real class objects. |
| 1183 | // Embedded Imtable, for class object that's not an interface, fixed size. |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 1184 | // ImTableEntry embedded_imtable_[0]; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1185 | // Embedded Vtable, for class object that's not an interface, variable size. |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 1186 | // VTableEntry embedded_vtable_[0]; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1187 | // Static fields, variable size. |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 1188 | // uint32_t fields_[0]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1189 | |
| 1190 | // java.lang.Class |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 1191 | static GcRoot<Class> java_lang_Class_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1192 | |
| 1193 | friend struct art::ClassOffsets; // for verifying offset information |
| 1194 | DISALLOW_IMPLICIT_CONSTRUCTORS(Class); |
| 1195 | }; |
| 1196 | |
| 1197 | std::ostream& operator<<(std::ostream& os, const Class::Status& rhs); |
| 1198 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1199 | } // namespace mirror |
| 1200 | } // namespace art |
| 1201 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 1202 | #endif // ART_RUNTIME_MIRROR_CLASS_H_ |