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