Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | #ifndef ART_RUNTIME_HANDLE_SCOPE_H_ |
| 18 | #define ART_RUNTIME_HANDLE_SCOPE_H_ |
| 19 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 20 | #include <stack> |
| 21 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 22 | #include <android-base/logging.h> |
| 23 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 24 | #include "base/enums.h" |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 25 | #include "base/locks.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 26 | #include "base/macros.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 27 | #include "stack_reference.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 28 | |
| 29 | namespace art { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 30 | |
Andreas Gampe | a1ffdba | 2019-01-04 16:08:51 -0800 | [diff] [blame] | 31 | template<class T> class Handle; |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 32 | class HandleScope; |
Andreas Gampe | a1ffdba | 2019-01-04 16:08:51 -0800 | [diff] [blame] | 33 | template<class T> class HandleWrapper; |
| 34 | template<class T> class HandleWrapperObjPtr; |
| 35 | template<class T> class MutableHandle; |
Andreas Gampe | c73cb64 | 2017-02-22 10:11:30 -0800 | [diff] [blame] | 36 | template<class MirrorType> class ObjPtr; |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 37 | class Thread; |
| 38 | class VariableSizedHandleScope; |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 39 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 40 | namespace mirror { |
| 41 | class Object; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 42 | } // namespace mirror |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 43 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 44 | // Basic handle scope, tracked by a list. May be variable sized. |
| 45 | class PACKED(4) BaseHandleScope { |
| 46 | public: |
| 47 | bool IsVariableSized() const { |
| 48 | return number_of_references_ == kNumReferencesVariableSized; |
| 49 | } |
| 50 | |
| 51 | // Number of references contained within this handle scope. |
| 52 | ALWAYS_INLINE uint32_t NumberOfReferences() const; |
| 53 | |
| 54 | ALWAYS_INLINE bool Contains(StackReference<mirror::Object>* handle_scope_entry) const; |
| 55 | |
| 56 | template <typename Visitor> |
| 57 | ALWAYS_INLINE void VisitRoots(Visitor& visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
| 58 | |
| 59 | // Link to previous BaseHandleScope or null. |
| 60 | BaseHandleScope* GetLink() const { |
| 61 | return link_; |
| 62 | } |
| 63 | |
| 64 | ALWAYS_INLINE VariableSizedHandleScope* AsVariableSized(); |
| 65 | ALWAYS_INLINE HandleScope* AsHandleScope(); |
| 66 | ALWAYS_INLINE const VariableSizedHandleScope* AsVariableSized() const; |
| 67 | ALWAYS_INLINE const HandleScope* AsHandleScope() const; |
| 68 | |
| 69 | protected: |
| 70 | BaseHandleScope(BaseHandleScope* link, uint32_t num_references) |
| 71 | : link_(link), |
| 72 | number_of_references_(num_references) {} |
| 73 | |
| 74 | // Variable sized constructor. |
Andreas Gampe | ea47ff8 | 2016-11-03 08:20:17 -0700 | [diff] [blame] | 75 | explicit BaseHandleScope(BaseHandleScope* link) |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 76 | : link_(link), |
| 77 | number_of_references_(kNumReferencesVariableSized) {} |
| 78 | |
| 79 | static constexpr int32_t kNumReferencesVariableSized = -1; |
| 80 | |
| 81 | // Link-list of handle scopes. The root is held by a Thread. |
| 82 | BaseHandleScope* const link_; |
| 83 | |
| 84 | // Number of handlerized references. -1 for variable sized handle scopes. |
| 85 | const int32_t number_of_references_; |
| 86 | |
| 87 | private: |
| 88 | DISALLOW_COPY_AND_ASSIGN(BaseHandleScope); |
| 89 | }; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 90 | |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 91 | // HandleScopes are scoped objects containing a number of Handles. They are used to allocate |
| 92 | // handles, for these handles (and the objects contained within them) to be visible/roots for the |
| 93 | // GC. It is most common to stack allocate HandleScopes using StackHandleScope. |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 94 | class PACKED(4) HandleScope : public BaseHandleScope { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 95 | public: |
| 96 | ~HandleScope() {} |
| 97 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 98 | // We have versions with and without explicit pointer size of the following. The first two are |
| 99 | // used at runtime, so OFFSETOF_MEMBER computes the right offsets automatically. The last one |
| 100 | // takes the pointer size explicitly so that at compile time we can cross-compile correctly. |
| 101 | |
| 102 | // Returns the size of a HandleScope containing num_references handles. |
Mathieu Chartier | 3e0acf6 | 2015-01-08 09:41:25 -0800 | [diff] [blame] | 103 | static size_t SizeOf(uint32_t num_references); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 104 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 105 | // Returns the size of a HandleScope containing num_references handles. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 106 | static size_t SizeOf(PointerSize pointer_size, uint32_t num_references); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 107 | |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 108 | ALWAYS_INLINE ObjPtr<mirror::Object> GetReference(size_t i) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 109 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 110 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 111 | ALWAYS_INLINE Handle<mirror::Object> GetHandle(size_t i); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 112 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 113 | ALWAYS_INLINE MutableHandle<mirror::Object> GetMutableHandle(size_t i) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 114 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 115 | |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 116 | ALWAYS_INLINE void SetReference(size_t i, ObjPtr<mirror::Object> object) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 117 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 118 | |
Mathieu Chartier | 3e0acf6 | 2015-01-08 09:41:25 -0800 | [diff] [blame] | 119 | ALWAYS_INLINE bool Contains(StackReference<mirror::Object>* handle_scope_entry) const; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 120 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 121 | // Offset of link within HandleScope, used by generated code. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 122 | static constexpr size_t LinkOffset(PointerSize pointer_size ATTRIBUTE_UNUSED) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 126 | // Offset of length within handle scope, used by generated code. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 127 | static constexpr size_t NumberOfReferencesOffset(PointerSize pointer_size) { |
| 128 | return static_cast<size_t>(pointer_size); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 131 | // Offset of link within handle scope, used by generated code. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 132 | static constexpr size_t ReferencesOffset(PointerSize pointer_size) { |
| 133 | return NumberOfReferencesOffset(pointer_size) + sizeof(number_of_references_); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 136 | // Placement new creation. |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 137 | static HandleScope* Create(void* storage, BaseHandleScope* link, uint32_t num_references) |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 138 | WARN_UNUSED { |
| 139 | return new (storage) HandleScope(link, num_references); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 142 | // Number of references contained within this handle scope. |
| 143 | ALWAYS_INLINE uint32_t NumberOfReferences() const { |
| 144 | DCHECK_GE(number_of_references_, 0); |
| 145 | return static_cast<uint32_t>(number_of_references_); |
| 146 | } |
| 147 | |
| 148 | template <typename Visitor> |
Andreas Gampe | a1ffdba | 2019-01-04 16:08:51 -0800 | [diff] [blame] | 149 | ALWAYS_INLINE void VisitRoots(Visitor& visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 150 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 151 | protected: |
| 152 | // Return backing storage used for references. |
| 153 | ALWAYS_INLINE StackReference<mirror::Object>* GetReferences() const { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 154 | uintptr_t address = reinterpret_cast<uintptr_t>(this) + ReferencesOffset(kRuntimePointerSize); |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 155 | return reinterpret_cast<StackReference<mirror::Object>*>(address); |
| 156 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 157 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 158 | explicit HandleScope(size_t number_of_references) : HandleScope(nullptr, number_of_references) {} |
Mathieu Chartier | d035c2d | 2014-10-27 17:30:20 -0700 | [diff] [blame] | 159 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 160 | // Semi-hidden constructor. Construction expected by generated code and StackHandleScope. |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 161 | HandleScope(BaseHandleScope* link, uint32_t num_references) |
| 162 | : BaseHandleScope(link, num_references) {} |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 163 | |
| 164 | // Storage for references. |
| 165 | // StackReference<mirror::Object> references_[number_of_references_] |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 166 | |
| 167 | private: |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 168 | DISALLOW_COPY_AND_ASSIGN(HandleScope); |
| 169 | }; |
| 170 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 171 | // Fixed size handle scope that is not necessarily linked in the thread. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 172 | template<size_t kNumReferences> |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 173 | class PACKED(4) FixedSizeHandleScope : public HandleScope { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 174 | public: |
Ian Rogers | b5cb18a | 2014-10-21 15:05:36 -0700 | [diff] [blame] | 175 | template<class T> |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 176 | ALWAYS_INLINE MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bc56fc3 | 2014-06-03 15:37:03 -0700 | [diff] [blame] | 177 | |
Ian Rogers | b5cb18a | 2014-10-21 15:05:36 -0700 | [diff] [blame] | 178 | template<class T> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 179 | ALWAYS_INLINE HandleWrapper<T> NewHandleWrapper(T** object) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 180 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | b5cb18a | 2014-10-21 15:05:36 -0700 | [diff] [blame] | 181 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 182 | template<class T> |
| 183 | ALWAYS_INLINE HandleWrapperObjPtr<T> NewHandleWrapper(ObjPtr<T>* object) |
| 184 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 185 | |
Andreas Gampe | c73cb64 | 2017-02-22 10:11:30 -0800 | [diff] [blame] | 186 | template<class MirrorType> |
| 187 | ALWAYS_INLINE MutableHandle<MirrorType> NewHandle(ObjPtr<MirrorType> object) |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 188 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 189 | |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 190 | ALWAYS_INLINE void SetReference(size_t i, ObjPtr<mirror::Object> object) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 191 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bc56fc3 | 2014-06-03 15:37:03 -0700 | [diff] [blame] | 192 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 193 | size_t RemainingSlots() const { |
| 194 | return kNumReferences - pos_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 197 | private: |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 198 | explicit ALWAYS_INLINE FixedSizeHandleScope(BaseHandleScope* link, |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 199 | ObjPtr<mirror::Object> fill_value = nullptr); |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 200 | ALWAYS_INLINE ~FixedSizeHandleScope() {} |
| 201 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 202 | template<class T> |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 203 | ALWAYS_INLINE MutableHandle<T> GetHandle(size_t i) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 204 | DCHECK_LT(i, kNumReferences); |
| 205 | return MutableHandle<T>(&GetReferences()[i]); |
| 206 | } |
| 207 | |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 208 | // Reference storage needs to be first as expected by the HandleScope layout. |
| 209 | StackReference<mirror::Object> storage_[kNumReferences]; |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 210 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 211 | // Position new handles will be created. |
Vladimir Marko | 26248c7 | 2017-02-21 17:00:28 +0000 | [diff] [blame] | 212 | uint32_t pos_ = 0; |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 213 | |
| 214 | template<size_t kNumRefs> friend class StackHandleScope; |
| 215 | friend class VariableSizedHandleScope; |
| 216 | }; |
| 217 | |
| 218 | // Scoped handle storage of a fixed size that is stack allocated. |
| 219 | template<size_t kNumReferences> |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 220 | class PACKED(4) StackHandleScope final : public FixedSizeHandleScope<kNumReferences> { |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 221 | public: |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 222 | explicit ALWAYS_INLINE StackHandleScope(Thread* self, |
| 223 | ObjPtr<mirror::Object> fill_value = nullptr); |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 224 | ALWAYS_INLINE ~StackHandleScope(); |
| 225 | |
| 226 | Thread* Self() const { |
| 227 | return self_; |
| 228 | } |
| 229 | |
| 230 | private: |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 231 | // The thread that the stack handle scope is a linked list upon. The stack handle scope will |
| 232 | // push and pop itself from this thread. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 233 | Thread* const self_; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 236 | // Utility class to manage a variable sized handle scope by having a list of fixed size handle |
| 237 | // scopes. |
| 238 | // Calls to NewHandle will create a new handle inside the current FixedSizeHandleScope. |
| 239 | // When the current handle scope becomes full a new one is created and put at the front of the |
| 240 | // list. |
| 241 | class VariableSizedHandleScope : public BaseHandleScope { |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 242 | public: |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 243 | explicit VariableSizedHandleScope(Thread* const self); |
| 244 | ~VariableSizedHandleScope(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 245 | |
| 246 | template<class T> |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 247 | MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 248 | |
Andreas Gampe | c73cb64 | 2017-02-22 10:11:30 -0800 | [diff] [blame] | 249 | template<class MirrorType> |
| 250 | MutableHandle<MirrorType> NewHandle(ObjPtr<MirrorType> ptr) |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 251 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 252 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 253 | // Number of references contained within this handle scope. |
| 254 | ALWAYS_INLINE uint32_t NumberOfReferences() const; |
| 255 | |
| 256 | ALWAYS_INLINE bool Contains(StackReference<mirror::Object>* handle_scope_entry) const; |
| 257 | |
| 258 | template <typename Visitor> |
| 259 | void VisitRoots(Visitor& visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
| 260 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 261 | private: |
Alex Light | de7718d | 2019-01-14 10:13:40 -0800 | [diff] [blame] | 262 | static constexpr size_t kMaxLocalScopeSize = 64u; |
| 263 | // In order to have consistent compilation with both 32bit and 64bit dex2oat |
| 264 | // binaries we need this to be an actual constant. We picked this because it |
| 265 | // will ensure that we use <64bit internal scopes. |
| 266 | static constexpr size_t kNumReferencesPerScope = 12u; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 267 | |
| 268 | Thread* const self_; |
| 269 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 270 | // Linked list of fixed size handle scopes. |
| 271 | using LocalScopeType = FixedSizeHandleScope<kNumReferencesPerScope>; |
Alex Light | de7718d | 2019-01-14 10:13:40 -0800 | [diff] [blame] | 272 | static_assert(sizeof(LocalScopeType) <= kMaxLocalScopeSize, "Unexpected size of LocalScopeType"); |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 273 | LocalScopeType* current_scope_; |
Mathieu Chartier | c550327 | 2020-02-11 10:01:18 -0800 | [diff] [blame] | 274 | LocalScopeType first_scope_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 275 | |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(VariableSizedHandleScope); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 279 | } // namespace art |
| 280 | |
| 281 | #endif // ART_RUNTIME_HANDLE_SCOPE_H_ |