template<class T> class Handle; class HandleScope; template<class T> class HandleWrapper; template<class T> class HandleWrapperObjPtr; template<class T> class MutableHandle; template<class MirrorType> class ObjPtr; class Thread; class VariableSizedHandleScope;
namespace mirror { class Object;
} // namespace mirror
// Basic handle scope, tracked by a list. May be variable sized. class PACKED(4) BaseHandleScope { public: bool IsVariableSized() const { return capacity_ == kNumReferencesVariableSized;
}
// The current size of this handle scope.
ALWAYS_INLINE uint32_t Size() const;
// The current capacity of this handle scope. // It can change (increase) only for a `VariableSizedHandleScope`.
ALWAYS_INLINE uint32_t Capacity() const;
// HandleScopes are scoped objects containing a number of Handles. They are used to allocate // handles, for these handles (and the objects contained within them) to be visible/roots for the // GC. It is most common to stack allocate HandleScopes using StackHandleScope. class PACKED(4) HandleScope : public BaseHandleScope { public:
~HandleScope() {}
// Offset of link within HandleScope, used by generated code. static constexpr size_t LinkOffset([[maybe_unused]] PointerSize pointer_size) { return0; }
// Offset of length within handle scope, used by generated code. static constexpr size_t CapacityOffset(PointerSize pointer_size) { returnstatic_cast<size_t>(pointer_size);
}
// Offset of link within handle scope, used by generated code. static constexpr size_t ReferencesOffset(PointerSize pointer_size) { return CapacityOffset(pointer_size) + sizeof(capacity_) + sizeof(size_);
}
// The current size of this handle scope.
ALWAYS_INLINE uint32_t Size() const { return size_;
}
// The capacity of this handle scope, immutable.
ALWAYS_INLINE uint32_t Capacity() const {
DCHECK_GT(capacity_, 0); returnstatic_cast<uint32_t>(capacity_);
}
HandleScope(BaseHandleScope* link, uint32_t capacity)
: BaseHandleScope(link, capacity) { // Handle scope should be created only if we have a code path that stores something in it. // We may not take that code path and the handle scope may remain empty.
DCHECK_NE(capacity, 0u);
}
// Position new handles will be created.
uint32_t size_ = 0;
// Storage for references is in derived classes. // StackReference<mirror::Object> references_[capacity_]
// Fixed size handle scope that is not necessarily linked in the thread. template<size_t kNumReferences> class PACKED(4) FixedSizeHandleScope : public HandleScope { private: explicit ALWAYS_INLINE FixedSizeHandleScope(BaseHandleScope* link)
REQUIRES_SHARED(Locks::mutator_lock_);
ALWAYS_INLINE ~FixedSizeHandleScope() REQUIRES_SHARED(Locks::mutator_lock_) {}
// Scoped handle storage of a fixed size that is stack allocated. template<size_t kNumReferences> class PACKED(4) StackHandleScope final : public FixedSizeHandleScope<kNumReferences> { public: explicit ALWAYS_INLINE StackHandleScope(Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_);
private: // The thread that the stack handle scope is a linked list upon. The stack handle scope will // push and pop itself from this thread.
Thread* const self_;
};
// Utility class to manage a variable sized handle scope by having a list of fixed size handle // scopes. // Calls to NewHandle will create a new handle inside the current FixedSizeHandleScope. // When the current handle scope becomes full a new one is created and put at the front of the // list. class VariableSizedHandleScope : public BaseHandleScope { public: explicit VariableSizedHandleScope(Thread* const self) REQUIRES_SHARED(Locks::mutator_lock_);
~VariableSizedHandleScope() REQUIRES_SHARED(Locks::mutator_lock_);
// The current size of this handle scope.
ALWAYS_INLINE uint32_t Size() const;
// The current capacity of this handle scope.
ALWAYS_INLINE uint32_t Capacity() const;
// Retrieve a `Handle<>` based on the slot index (in handle creation order). // Note: This is linear in the size of the scope, so it should be used carefully. template<class T>
ALWAYS_INLINE Handle<T> GetHandle(size_t i) REQUIRES_SHARED(Locks::mutator_lock_);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.