// A system-weak container mapping objects to elements of the template type. This corresponds // to a weak hash map. For historical reasons the stored value is called "tag." template <typename T> class JvmtiWeakTable : public art::gc::SystemWeakHolder { public:
JvmtiWeakTable()
: art::gc::SystemWeakHolder(art::kTaggingLockLevel),
update_since_last_sweep_(false) {
}
// Remove the mapping for the given object, returning whether such a mapping existed (and the old // value).
ALWAYS_INLINE bool Remove(art::ObjPtr<art::mirror::Object> obj, /* out */ T* tag)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(!allow_disallow_lock_);
ALWAYS_INLINE bool RemoveLocked(art::ObjPtr<art::mirror::Object> obj, /* out */ T* tag)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(allow_disallow_lock_);
// Set the mapping for the given object. Returns true if this overwrites an already existing // mapping.
ALWAYS_INLINE virtualbool Set(art::ObjPtr<art::mirror::Object> obj, T tag)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(!allow_disallow_lock_);
ALWAYS_INLINE virtualbool SetLocked(art::ObjPtr<art::mirror::Object> obj, T tag)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(allow_disallow_lock_);
// Return the value associated with the given object. Returns true if the mapping exists, false // otherwise. bool GetTag(art::ObjPtr<art::mirror::Object> obj, /* out */ T* result)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(!allow_disallow_lock_) {
art::Thread* self = art::Thread::Current();
art::MutexLock mu(self, allow_disallow_lock_);
Wait(self);
// Sweep the container. DO NOT CALL MANUALLY.
ALWAYS_INLINE void Sweep(art::IsMarkedVisitor* visitor)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(!allow_disallow_lock_);
// Return all objects that have a value mapping in tags.
ALWAYS_INLINE
jvmtiError GetTaggedObjects(jvmtiEnv* jvmti_env,
jint tag_count, const T* tags, /* out */ jint* count_ptr, /* out */ jobject** object_result_ptr, /* out */ T** tag_result_ptr)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(!allow_disallow_lock_);
protected: // Should HandleNullSweep be called when Sweep detects the release of an object? virtualbool DoesHandleNullOnSweep() { returnfalse;
} // If DoesHandleNullOnSweep returns true, this function will be called. virtualvoid HandleNullSweep([[maybe_unused]] T tag) {}
bool GetTagLocked(art::Thread* self, art::ObjPtr<art::mirror::Object> obj, /* out */ T* result)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(allow_disallow_lock_) { auto it = tagged_objects_.find(art::GcRoot<art::mirror::Object>(obj)); if (it != tagged_objects_.end()) {
*result = it->second; returntrue;
}
// Performance optimization: To avoid multiple table updates, ensure that during GC we // only update once. See the comment on the implementation of GetTagSlowPath. if (art::gUseReadBarrier &&
self != nullptr &&
self->GetIsGcMarking() &&
!update_since_last_sweep_) { return GetTagSlowPath(self, obj, result);
}
returnfalse;
}
// Slow-path for GetTag. We didn't find the object, but we might be storing from-pointers and // are asked to retrieve with a to-pointer.
ALWAYS_INLINE bool GetTagSlowPath(art::Thread* self, art::ObjPtr<art::mirror::Object> obj, /* out */ T* result)
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(allow_disallow_lock_);
// Update the table by doing read barriers on each element, ensuring that to-space pointers // are stored.
ALWAYS_INLINE void UpdateTableWithReadBarrier()
REQUIRES_SHARED(art::Locks::mutator_lock_)
REQUIRES(allow_disallow_lock_);
using TagAllocator = JvmtiAllocator<std::pair<const art::GcRoot<art::mirror::Object>, T>>; using TagMap = std::unordered_map<art::GcRoot<art::mirror::Object>,
T,
HashGcRoot,
EqGcRoot,
TagAllocator>;
TagMap tagged_objects_ GUARDED_BY(allow_disallow_lock_) GUARDED_BY(art::Locks::mutator_lock_); // To avoid repeatedly scanning the whole table, remember if we did that since the last sweep. bool update_since_last_sweep_;
};
} // namespace openjdkjvmti
#endif// ART_OPENJDKJVMTI_JVMTI_WEAK_TABLE_H_
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
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.