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