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