base/unix_file/fd_file.h \
dex_file.h \
dex_instruction.h \
+ gc_root.h \
gc/allocator/rosalloc.h \
gc/collector/gc_type.h \
gc/allocator_type.h \
WriterMutexLock mu(Thread::Current(), *Locks::classlinker_classes_lock_);
if ((flags & kVisitRootFlagAllRoots) != 0) {
for (GcRoot<mirror::Class>& root : class_table_) {
- root.VisitRoot(callback, arg, 0, kRootStickyClass);
+ root.VisitRoot(callback, arg, RootInfo(kRootStickyClass));
}
for (GcRoot<mirror::Class>& root : pre_zygote_class_table_) {
- root.VisitRoot(callback, arg, 0, kRootStickyClass);
+ root.VisitRoot(callback, arg, RootInfo(kRootStickyClass));
}
} else if ((flags & kVisitRootFlagNewRoots) != 0) {
for (auto& root : new_class_roots_) {
mirror::Class* old_ref = root.Read<kWithoutReadBarrier>();
- root.VisitRoot(callback, arg, 0, kRootStickyClass);
+ root.VisitRoot(callback, arg, RootInfo(kRootStickyClass));
mirror::Class* new_ref = root.Read<kWithoutReadBarrier>();
if (UNLIKELY(new_ref != old_ref)) {
// Uh ohes, GC moved a root in the log. Need to search the class_table and update the
// corresponding object. This is slow, but luckily for us, this may only happen with a
// concurrent moving GC.
auto it = class_table_.Find(GcRoot<mirror::Class>(old_ref));
- class_table_.Erase(it);
- class_table_.Insert(GcRoot<mirror::Class>(new_ref));
+ DCHECK(it != class_table_.end());
+ *it = GcRoot<mirror::Class>(new_ref);
}
}
}
// reinit references to when reinitializing a ClassLinker from a
// mapped image.
void ClassLinker::VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags) {
- class_roots_.VisitRoot(callback, arg, 0, kRootVMInternal);
+ class_roots_.VisitRoot(callback, arg, RootInfo(kRootVMInternal));
Thread* self = Thread::Current();
{
ReaderMutexLock mu(self, dex_lock_);
if ((flags & kVisitRootFlagAllRoots) != 0) {
for (GcRoot<mirror::DexCache>& dex_cache : dex_caches_) {
- dex_cache.VisitRoot(callback, arg, 0, kRootVMInternal);
+ dex_cache.VisitRoot(callback, arg, RootInfo(kRootVMInternal));
}
} else if ((flags & kVisitRootFlagNewRoots) != 0) {
for (size_t index : new_dex_cache_roots_) {
- dex_caches_[index].VisitRoot(callback, arg, 0, kRootVMInternal);
+ dex_caches_[index].VisitRoot(callback, arg, RootInfo(kRootVMInternal));
}
}
if ((flags & kVisitRootFlagClearRootLog) != 0) {
}
}
VisitClassRoots(callback, arg, flags);
- array_iftable_.VisitRoot(callback, arg, 0, kRootVMInternal);
+ array_iftable_.VisitRoot(callback, arg, RootInfo(kRootVMInternal));
DCHECK(!array_iftable_.IsNull());
for (size_t i = 0; i < kFindArrayCacheSize; ++i) {
- if (!find_array_class_cache_[i].IsNull()) {
- find_array_class_cache_[i].VisitRoot(callback, arg, 0, kRootVMInternal);
- }
+ find_array_class_cache_[i].VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
}
}
}
}
- static void TestRootVisitor(mirror::Object** root, void*, uint32_t, RootType) {
+ static void TestRootVisitor(mirror::Object** root, void*, const RootInfo&) {
EXPECT_TRUE(*root != nullptr);
}
};
// Breakpoints.
static std::vector<Breakpoint> gBreakpoints GUARDED_BY(Locks::breakpoint_lock_);
-void DebugInvokeReq::VisitRoots(RootCallback* callback, void* arg, uint32_t tid,
- RootType root_type) {
+void DebugInvokeReq::VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) {
if (receiver != nullptr) {
- callback(&receiver, arg, tid, root_type);
+ callback(&receiver, arg, root_info);
}
if (thread != nullptr) {
- callback(&thread, arg, tid, root_type);
+ callback(&thread, arg, root_info);
}
if (klass != nullptr) {
- callback(reinterpret_cast<mirror::Object**>(&klass), arg, tid, root_type);
+ callback(reinterpret_cast<mirror::Object**>(&klass), arg, root_info);
}
if (method != nullptr) {
- callback(reinterpret_cast<mirror::Object**>(&method), arg, tid, root_type);
+ callback(reinterpret_cast<mirror::Object**>(&method), arg, root_info);
}
}
method = nullptr;
}
-void SingleStepControl::VisitRoots(RootCallback* callback, void* arg, uint32_t tid,
- RootType root_type) {
+void SingleStepControl::VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) {
if (method != nullptr) {
- callback(reinterpret_cast<mirror::Object**>(&method), arg, tid, root_type);
+ callback(reinterpret_cast<mirror::Object**>(&method), arg, root_info);
}
}
#include <string>
#include <vector>
+#include "gc_root.h"
#include "jdwp/jdwp.h"
#include "jni.h"
#include "jvalue.h"
Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
ConditionVariable cond GUARDED_BY(lock);
- void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
+ void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
void Clear();
// single-step depth.
int stack_depth;
- void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
+ void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
bool ContainsDexPc(uint32_t dex_pc) const;
}
void MarkCompact::MarkHeapReferenceCallback(mirror::HeapReference<mirror::Object>* obj_ptr,
- void* arg) {
+ void* arg) {
reinterpret_cast<MarkCompact*>(arg)->MarkObject(obj_ptr->AsMirrorPtr());
}
void MarkCompact::DelayReferenceReferentCallback(mirror::Class* klass, mirror::Reference* ref,
- void* arg) {
+ void* arg) {
reinterpret_cast<MarkCompact*>(arg)->DelayReferenceReferent(klass, ref);
}
-void MarkCompact::MarkRootCallback(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void MarkCompact::MarkRootCallback(Object** root, void* arg, const RootInfo& /*root_info*/) {
reinterpret_cast<MarkCompact*>(arg)->MarkObject(*root);
}
-void MarkCompact::UpdateRootCallback(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void MarkCompact::UpdateRootCallback(Object** root, void* arg, const RootInfo& /*root_info*/) {
mirror::Object* obj = *root;
mirror::Object* new_obj = reinterpret_cast<MarkCompact*>(arg)->GetMarkedForwardAddress(obj);
if (obj != new_obj) {
#include "base/macros.h"
#include "base/mutex.h"
#include "garbage_collector.h"
+#include "gc_root.h"
#include "gc/accounting/heap_bitmap.h"
#include "immune_region.h"
#include "lock_word.h"
void SweepSystemWeaks()
SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
- static void MarkRootCallback(mirror::Object** root, void* arg, uint32_t /*tid*/,
- RootType /*root_type*/)
+ static void MarkRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
static mirror::Object* MarkObjectCallback(mirror::Object* root, void* arg)
EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
// Update the references of objects by using the forwarding addresses.
void UpdateReferences() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
- static void UpdateRootCallback(mirror::Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/)
+ static void UpdateRootCallback(mirror::Object** root, void* arg, const RootInfo& /*root_info*/)
EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
// Move objects and restore lock words.
}
}
-void MarkSweep::MarkRootParallelCallback(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void MarkSweep::MarkRootParallelCallback(Object** root, void* arg, const RootInfo& /*root_info*/) {
reinterpret_cast<MarkSweep*>(arg)->MarkObjectNonNullParallel(*root);
}
-void MarkSweep::VerifyRootMarked(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void MarkSweep::VerifyRootMarked(Object** root, void* arg, const RootInfo& /*root_info*/) {
CHECK(reinterpret_cast<MarkSweep*>(arg)->IsMarked(*root));
}
-void MarkSweep::MarkRootCallback(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void MarkSweep::MarkRootCallback(Object** root, void* arg, const RootInfo& /*root_info*/) {
reinterpret_cast<MarkSweep*>(arg)->MarkObjectNonNull(*root);
}
-void MarkSweep::VerifyRootCallback(const Object* root, void* arg, size_t vreg,
- const StackVisitor* visitor, RootType root_type) {
- reinterpret_cast<MarkSweep*>(arg)->VerifyRoot(root, vreg, visitor, root_type);
+void MarkSweep::VerifyRootCallback(Object** root, void* arg, const RootInfo& root_info) {
+ reinterpret_cast<MarkSweep*>(arg)->VerifyRoot(*root, root_info);
}
-void MarkSweep::VerifyRoot(const Object* root, size_t vreg, const StackVisitor* visitor,
- RootType root_type) {
+void MarkSweep::VerifyRoot(const Object* root, const RootInfo& root_info) {
// See if the root is on any space bitmap.
if (heap_->GetLiveBitmap()->GetContinuousSpaceBitmap(root) == nullptr) {
space::LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace();
if (large_object_space != nullptr && !large_object_space->Contains(root)) {
- LOG(ERROR) << "Found invalid root: " << root << " with type " << root_type;
- if (visitor != NULL) {
- LOG(ERROR) << visitor->DescribeLocation() << " in VReg: " << vreg;
- }
+ LOG(ERROR) << "Found invalid root: " << root << " ";
+ root_info.Describe(LOG(ERROR));
}
}
}
void MarkSweep::VerifyRoots() {
- Runtime::Current()->GetThreadList()->VerifyRoots(VerifyRootCallback, this);
+ Runtime::Current()->GetThreadList()->VisitRoots(VerifyRootCallback, this);
}
void MarkSweep::MarkRoots(Thread* self) {
#include "base/macros.h"
#include "base/mutex.h"
#include "garbage_collector.h"
+#include "gc_root.h"
#include "gc/accounting/heap_bitmap.h"
#include "immune_region.h"
#include "object_callbacks.h"
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
- static void MarkRootCallback(mirror::Object** root, void* arg, uint32_t thread_id,
- RootType root_type)
+ static void MarkRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
- static void VerifyRootMarked(mirror::Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/)
+ static void VerifyRootMarked(mirror::Object** root, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- static void MarkRootParallelCallback(mirror::Object** root, void* arg, uint32_t thread_id,
- RootType root_type)
+ static void MarkRootParallelCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
// Marks an object.
// whether or not we care about pauses.
size_t GetThreadCount(bool paused) const;
- static void VerifyRootCallback(const mirror::Object* root, void* arg, size_t vreg,
- const StackVisitor *visitor, RootType root_type);
+ static void VerifyRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info);
- void VerifyRoot(const mirror::Object* root, size_t vreg, const StackVisitor* visitor,
- RootType root_type) NO_THREAD_SAFETY_ANALYSIS;
+ void VerifyRoot(const mirror::Object* root, const RootInfo& root_info) NO_THREAD_SAFETY_ANALYSIS;
// Push a single reference on a mark stack.
void PushOnMarkStack(mirror::Object* obj);
reinterpret_cast<SemiSpace*>(arg)->DelayReferenceReferent(klass, ref);
}
-void SemiSpace::MarkRootCallback(Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+void SemiSpace::MarkRootCallback(Object** root, void* arg, const RootInfo& /*root_info*/) {
auto ref = StackReference<mirror::Object>::FromMirrorPtr(*root);
reinterpret_cast<SemiSpace*>(arg)->MarkObject(&ref);
if (*root != ref.AsMirrorPtr()) {
#include "base/macros.h"
#include "base/mutex.h"
#include "garbage_collector.h"
+#include "gc_root.h"
#include "gc/accounting/heap_bitmap.h"
#include "immune_region.h"
#include "mirror/object_reference.h"
void SweepSystemWeaks()
SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
- static void MarkRootCallback(mirror::Object** root, void* arg, uint32_t /*tid*/,
- RootType /*root_type*/)
+ static void MarkRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
static mirror::Object* MarkObjectCallback(mirror::Object* root, void* arg)
gc_complete_cond_->Broadcast(self);
}
-static void RootMatchesObjectVisitor(mirror::Object** root, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/) {
+static void RootMatchesObjectVisitor(mirror::Object** root, void* arg,
+ const RootInfo& /*root_info*/) {
mirror::Object* obj = reinterpret_cast<mirror::Object*>(arg);
if (*root == obj) {
LOG(INFO) << "Object " << obj << " is a root";
return heap_->IsLiveObjectLocked(obj, true, false, true);
}
- static void VerifyRootCallback(mirror::Object** root, void* arg, uint32_t thread_id,
- RootType root_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ static void VerifyRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
VerifyReferenceVisitor* visitor = reinterpret_cast<VerifyReferenceVisitor*>(arg);
if (!visitor->VerifyReference(nullptr, *root, MemberOffset(0))) {
LOG(ERROR) << "Root " << *root << " is dead with type " << PrettyTypeOf(*root)
- << " thread_id= " << thread_id << " root_type= " << root_type;
+ << " thread_id= " << root_info.GetThreadId() << " root_type= " << root_info.GetType();
}
}
#include "base/macros.h"
#include "base/mutex.h" // For Locks::mutator_lock_.
-#include "object_callbacks.h"
namespace art {
+namespace mirror {
+class Object;
+} // namespace mirror
+
+enum RootType {
+ kRootUnknown = 0,
+ kRootJNIGlobal,
+ kRootJNILocal,
+ kRootJavaFrame,
+ kRootNativeStack,
+ kRootStickyClass,
+ kRootThreadBlock,
+ kRootMonitorUsed,
+ kRootThreadObject,
+ kRootInternedString,
+ kRootDebugger,
+ kRootVMInternal,
+ kRootJNIMonitor,
+};
+std::ostream& operator<<(std::ostream& os, const RootType& root_type);
+
+class RootInfo {
+ public:
+ // Thread id 0 is for non thread roots.
+ explicit RootInfo(RootType type, uint32_t thread_id = 0)
+ : type_(type), thread_id_(thread_id) {
+ }
+ virtual ~RootInfo() {
+ }
+ RootType GetType() const {
+ return type_;
+ }
+ uint32_t GetThreadId() const {
+ return thread_id_;
+ }
+ virtual void Describe(std::ostream& os) const {
+ os << "Type=" << type_ << " thread_id=" << thread_id_;
+ }
+
+ private:
+ const RootType type_;
+ const uint32_t thread_id_;
+};
+
+// Returns the new address of the object, returns root if it has not moved. tid and root_type are
+// only used by hprof.
+typedef void (RootCallback)(mirror::Object** root, void* arg, const RootInfo& root_info);
+
template<class MirrorType>
class PACKED(4) GcRoot {
public:
template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
ALWAYS_INLINE MirrorType* Read() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void VisitRoot(RootCallback* callback, void* arg, uint32_t thread_id, RootType root_type) const {
+ void VisitRoot(RootCallback* callback, void* arg, const RootInfo& info) const {
DCHECK(!IsNull());
- callback(reinterpret_cast<mirror::Object**>(&root_), arg, thread_id, root_type);
+ callback(reinterpret_cast<mirror::Object**>(&root_), arg, info);
DCHECK(!IsNull());
}
+ void VisitRootIfNonNull(RootCallback* callback, void* arg, const RootInfo& info) const {
+ if (!IsNull()) {
+ VisitRoot(callback, arg, info);
+ }
+ }
+
// This is only used by IrtIterator.
ALWAYS_INLINE MirrorType** AddressWithoutBarrier() {
return &root_;
#include "common_throws.h"
#include "debugger.h"
#include "dex_file-inl.h"
+#include "gc_root.h"
#include "gc/accounting/heap_bitmap.h"
#include "gc/heap.h"
#include "gc/space/space.h"
EndianOutput* output;
};
- static void RootVisitor(mirror::Object** obj, void* arg, uint32_t thread_id, RootType root_type)
+ static void RootVisitor(mirror::Object** obj, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
DCHECK(arg != nullptr);
DCHECK(obj != nullptr);
DCHECK(*obj != nullptr);
Env* env = reinterpret_cast<Env*>(arg);
- env->hprof->VisitRoot(*obj, thread_id, root_type, env->output);
+ env->hprof->VisitRoot(*obj, root_info, env->output);
}
static void VisitObjectCallback(mirror::Object* obj, void* arg)
}
}
- void VisitRoot(const mirror::Object* obj, uint32_t thread_id, RootType type, EndianOutput* output)
+ void VisitRoot(const mirror::Object* obj, const RootInfo& root_info, EndianOutput* output)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
void MarkRootObject(const mirror::Object* obj, jobject jni_obj, HprofHeapTag heap_tag,
uint32_t thread_serial, EndianOutput* output);
__ UpdateU4(size_patch_offset, output->Length() - (size_patch_offset + 4));
}
-void Hprof::VisitRoot(const mirror::Object* obj, uint32_t thread_id, RootType type,
- EndianOutput* output) {
+void Hprof::VisitRoot(const mirror::Object* obj, const RootInfo& info, EndianOutput* output) {
static const HprofHeapTag xlate[] = {
HPROF_ROOT_UNKNOWN,
HPROF_ROOT_JNI_GLOBAL,
HPROF_ROOT_VM_INTERNAL,
HPROF_ROOT_JNI_MONITOR,
};
- CHECK_LT(type, sizeof(xlate) / sizeof(HprofHeapTag));
+ CHECK_LT(info.GetType(), sizeof(xlate) / sizeof(HprofHeapTag));
if (obj == nullptr) {
return;
}
- MarkRootObject(obj, 0, xlate[type], thread_id, output);
+ MarkRootObject(obj, 0, xlate[info.GetType()], info.GetThreadId(), output);
}
// If "direct_to_ddms" is true, the other arguments are ignored, and data is
madvise(release_start, release_end - release_start, MADV_DONTNEED);
}
-void IndirectReferenceTable::VisitRoots(RootCallback* callback, void* arg, uint32_t tid,
- RootType root_type) {
+void IndirectReferenceTable::VisitRoots(RootCallback* callback, void* arg,
+ const RootInfo& root_info) {
for (auto ref : *this) {
if (*ref == nullptr) {
// Need to skip null entries to make it possible to do the
// non-null check after the call back.
continue;
}
- callback(ref, arg, tid, root_type);
+ callback(ref, arg, root_info);
DCHECK(*ref != nullptr);
}
}
namespace art {
+class RootInfo;
+
namespace mirror {
class Object;
} // namespace mirror
return IrtIterator(table_, Capacity(), Capacity());
}
- void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
+ void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
uint32_t GetSegmentState() const {
return;
}
for (auto pair : deoptimized_methods_) {
- pair.second.VisitRoot(callback, arg, 0, kRootVMInternal);
+ pair.second.VisitRoot(callback, arg, RootInfo(kRootVMInternal));
}
}
} else if ((flags & kVisitRootFlagNewRoots) != 0) {
for (auto& root : new_strong_intern_roots_) {
mirror::String* old_ref = root.Read<kWithoutReadBarrier>();
- root.VisitRoot(callback, arg, 0, kRootInternedString);
+ root.VisitRoot(callback, arg, RootInfo(kRootInternedString));
mirror::String* new_ref = root.Read<kWithoutReadBarrier>();
if (new_ref != old_ref) {
// The GC moved a root in the log. Need to search the strong interns and update the
void InternTable::Table::VisitRoots(RootCallback* callback, void* arg) {
for (auto& intern : pre_zygote_table_) {
- intern.VisitRoot(callback, arg, 0, kRootInternedString);
+ intern.VisitRoot(callback, arg, RootInfo(kRootInternedString));
}
for (auto& intern : post_zygote_table_) {
- intern.VisitRoot(callback, arg, 0, kRootInternedString);
+ intern.VisitRoot(callback, arg, RootInfo(kRootInternedString));
}
}
void JavaVMExt::VisitRoots(RootCallback* callback, void* arg) {
Thread* self = Thread::Current();
- {
- ReaderMutexLock mu(self, globals_lock_);
- globals_.VisitRoots(callback, arg, 0, kRootJNIGlobal);
- }
+ ReaderMutexLock mu(self, globals_lock_);
+ globals_.VisitRoots(callback, arg, RootInfo(kRootJNIGlobal));
// The weak_globals table is visited by the GC itself (because it mutates the table).
}
template<class T>
inline void PrimitiveArray<T>::VisitRoots(RootCallback* callback, void* arg) {
- if (!array_class_.IsNull()) {
- array_class_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ array_class_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
template<typename T>
}
void ArtField::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_reflect_ArtField_.IsNull()) {
- java_lang_reflect_ArtField_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_reflect_ArtField_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
// TODO: we could speed up the search if fields are ordered by offsets.
void ArtMethod::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_reflect_ArtMethod_.IsNull()) {
- java_lang_reflect_ArtMethod_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_reflect_ArtMethod_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
mirror::String* ArtMethod::GetNameAsString(Thread* self) {
}
void Class::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_Class_.IsNull()) {
- java_lang_Class_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_Class_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
void Class::SetStatus(Status new_status, Thread* self) {
}
void Reference::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_ref_Reference_.IsNull()) {
- java_lang_ref_Reference_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_ref_Reference_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
} // namespace mirror
}
void StackTraceElement::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_StackTraceElement_.IsNull()) {
- java_lang_StackTraceElement_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_StackTraceElement_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
}
void String::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_String_.IsNull()) {
- java_lang_String_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_String_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
} // namespace mirror
}
void Throwable::VisitRoots(RootCallback* callback, void* arg) {
- if (!java_lang_Throwable_.IsNull()) {
- java_lang_Throwable_.VisitRoot(callback, arg, 0, kRootStickyClass);
- }
+ java_lang_Throwable_.VisitRootIfNonNull(callback, arg, RootInfo(kRootStickyClass));
}
} // namespace mirror
typedef std::map<std::string, mirror::String*> StringTable;
static void PreloadDexCachesStringsCallback(mirror::Object** root, void* arg,
- uint32_t /*thread_id*/, RootType /*root_type*/)
+ const RootInfo& /*root_info*/)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
StringTable& table = *reinterpret_cast<StringTable*>(arg);
mirror::String* string = const_cast<mirror::Object*>(*root)->AsString();
} // namespace mirror
class StackVisitor;
-enum RootType {
- kRootUnknown = 0,
- kRootJNIGlobal,
- kRootJNILocal,
- kRootJavaFrame,
- kRootNativeStack,
- kRootStickyClass,
- kRootThreadBlock,
- kRootMonitorUsed,
- kRootThreadObject,
- kRootInternedString,
- kRootDebugger,
- kRootVMInternal,
- kRootJNIMonitor,
-};
-std::ostream& operator<<(std::ostream& os, const RootType& root_type);
-
-// Returns the new address of the object, returns root if it has not moved. tid and root_type are
-// only used by hprof.
-typedef void (RootCallback)(mirror::Object** root, void* arg, uint32_t thread_id,
- RootType root_type);
// A callback for visiting an object in the heap.
typedef void (ObjectCallback)(mirror::Object* obj, void* arg);
// A callback used for marking an object, returns the new address of the object if the object moved.
typedef mirror::Object* (MarkObjectCallback)(mirror::Object* obj, void* arg) WARN_UNUSED;
-// A callback for verifying roots.
-typedef void (VerifyRootCallback)(const mirror::Object* root, void* arg, size_t vreg,
- const StackVisitor* visitor, RootType root_type);
typedef void (MarkHeapReferenceCallback)(mirror::HeapReference<mirror::Object>* ref, void* arg);
typedef void (DelayReferenceReferentCallback)(mirror::Class* klass, mirror::Reference* ref, void* arg);
DumpSummaryLine(os, prev, GetElementCount(prev), identical, equiv);
}
-void ReferenceTable::VisitRoots(RootCallback* visitor, void* arg, uint32_t tid,
- RootType root_type) {
+void ReferenceTable::VisitRoots(RootCallback* visitor, void* arg, const RootInfo& root_info) {
for (GcRoot<mirror::Object>& root : entries_) {
- root.VisitRoot(visitor, arg, tid, root_type);
+ root.VisitRoot(visitor, arg, root_info);
}
}
void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void VisitRoots(RootCallback* visitor, void* arg, uint32_t tid, RootType root_type);
+ void VisitRoots(RootCallback* visitor, void* arg, const RootInfo& root_info);
private:
typedef std::vector<GcRoot<mirror::Object>,
void Runtime::VisitNonThreadRoots(RootCallback* callback, void* arg) {
java_vm_->VisitRoots(callback, arg);
- if (!sentinel_.IsNull()) {
- sentinel_.VisitRoot(callback, arg, 0, kRootVMInternal);
- DCHECK(!sentinel_.IsNull());
- }
- if (!pre_allocated_OutOfMemoryError_.IsNull()) {
- pre_allocated_OutOfMemoryError_.VisitRoot(callback, arg, 0, kRootVMInternal);
- DCHECK(!pre_allocated_OutOfMemoryError_.IsNull());
- }
- resolution_method_.VisitRoot(callback, arg, 0, kRootVMInternal);
- DCHECK(!resolution_method_.IsNull());
- if (!pre_allocated_NoClassDefFoundError_.IsNull()) {
- pre_allocated_NoClassDefFoundError_.VisitRoot(callback, arg, 0, kRootVMInternal);
- DCHECK(!pre_allocated_NoClassDefFoundError_.IsNull());
- }
- if (HasImtConflictMethod()) {
- imt_conflict_method_.VisitRoot(callback, arg, 0, kRootVMInternal);
- }
- if (!imt_unimplemented_method_.IsNull()) {
- imt_unimplemented_method_.VisitRoot(callback, arg, 0, kRootVMInternal);
- }
- if (HasDefaultImt()) {
- default_imt_.VisitRoot(callback, arg, 0, kRootVMInternal);
- }
+ sentinel_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
+ pre_allocated_OutOfMemoryError_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
+ resolution_method_.VisitRoot(callback, arg, RootInfo(kRootVMInternal));
+ pre_allocated_NoClassDefFoundError_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
+ imt_conflict_method_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
+ imt_unimplemented_method_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
+ default_imt_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
- if (!callee_save_methods_[i].IsNull()) {
- callee_save_methods_[i].VisitRoot(callback, arg, 0, kRootVMInternal);
- }
+ callee_save_methods_[i].VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal));
}
verifier::MethodVerifier::VisitStaticRoots(callback, arg);
{
}
}
+void JavaFrameRootInfo::Describe(std::ostream& os) const {
+ const StackVisitor* visitor = stack_visitor_;
+ CHECK(visitor != nullptr);
+ os << "Type=" << GetType() << " thread_id=" << GetThreadId() << " location=" <<
+ visitor->DescribeLocation() << " vreg=" << vreg_;
+}
+
} // namespace art
#include "arch/instruction_set.h"
#include "dex_file.h"
+#include "gc_root.h"
#include "mirror/object_reference.h"
#include "throw_location.h"
#include "utils.h"
DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
};
+class JavaFrameRootInfo : public RootInfo {
+ public:
+ JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg)
+ : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) {
+ }
+ virtual void Describe(std::ostream& os) const OVERRIDE
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
+ private:
+ const StackVisitor* const stack_visitor_;
+ const size_t vreg_;
+};
+
// The managed stack is used to record fragments of managed code stacks. Managed code stacks
// may either be shadow frames or lists of frames using fixed frame sizes. Transition records are
// necessary for transitions between code using different frame layouts and transitions into native
}
}
-static void MonitorExitVisitor(mirror::Object** object, void* arg, uint32_t /*thread_id*/,
- RootType /*root_type*/)
+static void MonitorExitVisitor(mirror::Object** object, void* arg, const RootInfo& /*root_info*/)
NO_THREAD_SAFETY_ANALYSIS {
Thread* self = reinterpret_cast<Thread*>(arg);
mirror::Object* entered_monitor = *object;
if (tlsPtr_.jni_env != nullptr) {
// On thread detach, all monitors entered with JNI MonitorEnter are automatically exited.
- tlsPtr_.jni_env->monitors.VisitRoots(MonitorExitVisitor, self, 0, kRootVMInternal);
+ tlsPtr_.jni_env->monitors.VisitRoots(MonitorExitVisitor, self, RootInfo(kRootVMInternal));
// Release locally held global references which releasing may require the mutator lock.
if (tlsPtr_.jpeer != nullptr) {
// If pthread_create fails we don't have a jni env here.
mirror::Object* object = cur->GetReference(j);
if (object != nullptr) {
mirror::Object* old_obj = object;
- visitor(&object, arg, thread_id, kRootNativeStack);
+ visitor(&object, arg, RootInfo(kRootNativeStack, thread_id));
if (old_obj != object) {
cur->SetReference(j, object);
}
RootCallbackVisitor(RootCallback* callback, void* arg, uint32_t tid)
: callback_(callback), arg_(arg), tid_(tid) {}
- void operator()(mirror::Object** obj, size_t, const StackVisitor*) const {
- callback_(obj, arg_, tid_, kRootJavaFrame);
+ void operator()(mirror::Object** obj, size_t vreg, const StackVisitor* stack_visitor) const {
+ callback_(obj, arg_, JavaFrameRootInfo(tid_, stack_visitor, vreg));
}
private:
void Thread::VisitRoots(RootCallback* visitor, void* arg) {
uint32_t thread_id = GetThreadId();
if (tlsPtr_.opeer != nullptr) {
- visitor(&tlsPtr_.opeer, arg, thread_id, kRootThreadObject);
+ visitor(&tlsPtr_.opeer, arg, RootInfo(kRootThreadObject, thread_id));
}
if (tlsPtr_.exception != nullptr && tlsPtr_.exception != GetDeoptimizationException()) {
- visitor(reinterpret_cast<mirror::Object**>(&tlsPtr_.exception), arg, thread_id, kRootNativeStack);
+ visitor(reinterpret_cast<mirror::Object**>(&tlsPtr_.exception), arg,
+ RootInfo(kRootNativeStack, thread_id));
}
tlsPtr_.throw_location.VisitRoots(visitor, arg);
if (tlsPtr_.monitor_enter_object != nullptr) {
- visitor(&tlsPtr_.monitor_enter_object, arg, thread_id, kRootNativeStack);
+ visitor(&tlsPtr_.monitor_enter_object, arg, RootInfo(kRootNativeStack, thread_id));
}
- tlsPtr_.jni_env->locals.VisitRoots(visitor, arg, thread_id, kRootJNILocal);
- tlsPtr_.jni_env->monitors.VisitRoots(visitor, arg, thread_id, kRootJNIMonitor);
+ tlsPtr_.jni_env->locals.VisitRoots(visitor, arg, RootInfo(kRootJNILocal, thread_id));
+ tlsPtr_.jni_env->monitors.VisitRoots(visitor, arg, RootInfo(kRootJNIMonitor, thread_id));
HandleScopeVisitRoots(visitor, arg, thread_id);
if (tlsPtr_.debug_invoke_req != nullptr) {
- tlsPtr_.debug_invoke_req->VisitRoots(visitor, arg, thread_id, kRootDebugger);
+ tlsPtr_.debug_invoke_req->VisitRoots(visitor, arg, RootInfo(kRootDebugger, thread_id));
}
if (tlsPtr_.single_step_control != nullptr) {
- tlsPtr_.single_step_control->VisitRoots(visitor, arg, thread_id, kRootDebugger);
+ tlsPtr_.single_step_control->VisitRoots(visitor, arg, RootInfo(kRootDebugger, thread_id));
}
if (tlsPtr_.deoptimization_shadow_frame != nullptr) {
RootCallbackVisitor visitorToCallback(visitor, arg, thread_id);
}
}
if (tlsPtr_.shadow_frame_under_construction != nullptr) {
- RootCallbackVisitor visitorToCallback(visitor, arg, thread_id);
- ReferenceMapVisitor<RootCallbackVisitor> mapper(this, nullptr, visitorToCallback);
+ RootCallbackVisitor visitor_to_callback(visitor, arg, thread_id);
+ ReferenceMapVisitor<RootCallbackVisitor> mapper(this, nullptr, visitor_to_callback);
for (ShadowFrame* shadow_frame = tlsPtr_.shadow_frame_under_construction;
shadow_frame != nullptr;
shadow_frame = shadow_frame->GetLink()) {
}
// Visit roots on this thread's stack
Context* context = GetLongJumpContext();
- RootCallbackVisitor visitorToCallback(visitor, arg, thread_id);
- ReferenceMapVisitor<RootCallbackVisitor> mapper(this, context, visitorToCallback);
+ RootCallbackVisitor visitor_to_callback(visitor, arg, thread_id);
+ ReferenceMapVisitor<RootCallbackVisitor> mapper(this, context, visitor_to_callback);
mapper.WalkStack();
ReleaseLongJumpContext(context);
for (instrumentation::InstrumentationStackFrame& frame : *GetInstrumentationStack()) {
if (frame.this_object_ != nullptr) {
- visitor(&frame.this_object_, arg, thread_id, kRootJavaFrame);
+ visitor(&frame.this_object_, arg, RootInfo(kRootVMInternal, thread_id));
}
DCHECK(frame.method_ != nullptr);
- visitor(reinterpret_cast<mirror::Object**>(&frame.method_), arg, thread_id, kRootJavaFrame);
+ visitor(reinterpret_cast<mirror::Object**>(&frame.method_), arg,
+ RootInfo(kRootVMInternal, thread_id));
}
}
-static void VerifyRoot(mirror::Object** root, void* /*arg*/, uint32_t /*thread_id*/,
- RootType /*root_type*/) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+static void VerifyRoot(mirror::Object** root, void* /*arg*/, const RootInfo& /*root_info*/)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
VerifyObject(*root);
}
}
}
-class VerifyRootWrapperArg {
- public:
- VerifyRootWrapperArg(VerifyRootCallback* callback, void* arg) : callback_(callback), arg_(arg) {
- }
- VerifyRootCallback* const callback_;
- void* const arg_;
-};
-
-static void VerifyRootWrapperCallback(mirror::Object** root, void* arg, uint32_t /*thread_id*/,
- RootType root_type) {
- VerifyRootWrapperArg* wrapperArg = reinterpret_cast<VerifyRootWrapperArg*>(arg);
- wrapperArg->callback_(*root, wrapperArg->arg_, 0, NULL, root_type);
-}
-
-void ThreadList::VerifyRoots(VerifyRootCallback* callback, void* arg) const {
- VerifyRootWrapperArg wrapper(callback, arg);
- MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
- for (const auto& thread : list_) {
- thread->VisitRoots(VerifyRootWrapperCallback, &wrapper);
- }
-}
-
uint32_t ThreadList::AllocThreadId(Thread* self) {
MutexLock mu(self, *Locks::allocated_thread_ids_lock_);
for (size_t i = 0; i < allocated_ids_.size(); ++i) {
#include "base/histogram.h"
#include "base/mutex.h"
+#include "gc_root.h"
#include "jni.h"
#include "object_callbacks.h"
void VisitRoots(RootCallback* callback, void* arg) const
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void VerifyRoots(VerifyRootCallback* callback, void* arg) const
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
// Return a copy of the thread list.
std::list<Thread*> GetList() EXCLUSIVE_LOCKS_REQUIRED(Locks::thread_list_lock_) {
return list_;
void ThrowLocation::VisitRoots(RootCallback* visitor, void* arg) {
if (this_object_ != nullptr) {
- visitor(&this_object_, arg, 0, kRootVMInternal);
+ visitor(&this_object_, arg, RootInfo(kRootVMInternal));
DCHECK(this_object_ != nullptr);
}
if (method_ != nullptr) {
- visitor(reinterpret_cast<mirror::Object**>(&method_), arg, 0, kRootVMInternal);
+ visitor(reinterpret_cast<mirror::Object**>(&method_), arg, RootInfo(kRootVMInternal));
DCHECK(method_ != nullptr);
}
}
#include "object_callbacks.h"
#include "base/macros.h"
#include "base/mutex.h"
+#include "gc_root.h"
#include <stdint.h>
#include <string>
it.second.VisitRoots(callback, arg);
mirror::Object* old_root = it.first;
mirror::Object* new_root = old_root;
- callback(&new_root, arg, 0, kRootUnknown);
+ callback(&new_root, arg, RootInfo(kRootUnknown));
if (new_root != old_root) {
moving_roots.push_back(std::make_pair(old_root, new_root));
}
mirror::Array* old_root = it.first;
CHECK(!old_root->IsObjectArray());
mirror::Array* new_root = old_root;
- callback(reinterpret_cast<mirror::Object**>(&new_root), arg, 0, kRootUnknown);
+ callback(reinterpret_cast<mirror::Object**>(&new_root), arg, RootInfo(kRootUnknown));
if (new_root != old_root) {
moving_roots.push_back(std::make_pair(old_root, new_root));
}
mirror::Object* obj =
reinterpret_cast<mirror::Object*>(static_cast<uintptr_t>(field_value.value));
if (obj != nullptr) {
- callback(&obj, arg, 0, kRootUnknown);
+ callback(&obj, arg, RootInfo(kRootUnknown));
field_value.value = reinterpret_cast<uintptr_t>(obj);
}
}
}
void Transaction::InternStringLog::VisitRoots(RootCallback* callback, void* arg) {
- callback(reinterpret_cast<mirror::Object**>(&str_), arg, 0, kRootInternedString);
+ callback(reinterpret_cast<mirror::Object**>(&str_), arg, RootInfo(kRootInternedString));
}
void Transaction::ArrayLog::LogValue(size_t index, uint64_t value) {
#include "base/macros.h"
#include "base/mutex.h"
#include "base/value_object.h"
+#include "gc_root.h"
#include "object_callbacks.h"
#include "offsets.h"
#include "primitive.h"
}
void RegType::VisitRoots(RootCallback* callback, void* arg) const {
- if (!klass_.IsNull()) {
- callback(reinterpret_cast<mirror::Object**>(&klass_), arg, 0, kRootUnknown);
- }
+ klass_.VisitRootIfNonNull(callback, arg, RootInfo(kRootUnknown));
}
void UninitializedThisReferenceType::CheckInvariants() const {