当前位置: 首页 > news >正文

art虚拟机中的gcroot

 

MAT help文档中的注释

Garbage Collection Roots

A garbage collection root is an object that is accessible from outside the heap. The following reasons make an object a GC root:

System Class

Class loaded by bootstrap/system class loader. For example, everything from the rt.jar like java.util.* .

JNI Local

Local variable in native code, such as user defined JNI code or JVM internal code.

JNI Global

Global variable in native code, such as user defined JNI code or JVM internal code.

Thread Block

Object referred to from a currently active thread block.

Thread

A started, but not stopped, thread.

Busy Monitor

Everything that has called wait() or notify() or that is synchronized. For example, by calling synchronized(Object) or by entering a synchronized method. Static method means class, non-static method means object.

Java Local

Local variable. For example, input parameters or locally created objects of methods that are still in the stack of a thread.

Native Stack

In or out parameters in native code, such as user defined JNI code or JVM internal code. This is often the case as many methods have native parts and the objects handled as method parameters become GC roots. For example, parameters used for file/network I/O methods or reflection.

Finalizable

An object which is in a queue awaiting its finalizer to be run.

Unfinalized

An object which has a finalize method, but has not been finalized and is not yet on the finalizer queue.

Unreachable

An object which is unreachable from any other root, but has been marked as a root by MAT to retain objects which otherwise would not be included in the analysis.

Java Stack Frame

A Java stack frame, holding local variables. Only generated when the dump is parsed with the preference set to treat Java stack frames as objects.

art虚拟机中的gcroot枚举

enum RootType {

kRootUnknown = 0,

kRootJNIGlobal,//env->newGlobalRef

kRootJNILocal,  //env->newlocalRef

kRootJavaFrame, //java栈帧

kRootNativeStack,

kRootStickyClass,

kRootThreadBlock,

kRootMonitorUsed,

kRootThreadObject, //线程对象本身,对应java Thread对象

kRootInternedString,

kRootFinalizing, // used for HPROF's conversion to HprofHeapTag

kRootDebugger,

kRootReferenceCleanup, // used for HPROF's conversion to HprofHeapTag

kRootVMInternal,

kRootJNIMonitor, //线程锁

};

怎么扫描gcroot的

art虚拟机中cc(concurren_copying)算法会把gcroot拷贝到regionspace的tospace类型的region中,

Thread相关的gcroot

1.kRootThreadObject 线程对象本身

2.kRootJNILocal,即通过newlocalRef添加到localRefenceTable中的java obj

在​​​​​​FlipThreadRoots 方法中会调用

void Thread::VisitRoots(RootVisitor* visitor) {const uint32_t thread_id = GetThreadId();visitor->VisitRootIfNonNull(&tlsPtr_.opeer, RootInfo(kRootThreadObject, thread_id));if (tlsPtr_.exception != nullptr && tlsPtr_.exception != GetDeoptimizationException()) {visitor->VisitRoot(reinterpret_cast<mirror::Object**>(&tlsPtr_.exception),RootInfo(kRootNativeStack, thread_id));}if (tlsPtr_.async_exception != nullptr) {visitor->VisitRoot(reinterpret_cast<mirror::Object**>(&tlsPtr_.async_exception),RootInfo(kRootNativeStack, thread_id));}visitor->VisitRootIfNonNull(&tlsPtr_.monitor_enter_object, RootInfo(kRootNativeStack, thread_id));tlsPtr_.jni_env->VisitJniLocalRoots(visitor, RootInfo(kRootJNILocal, thread_id));tlsPtr_.jni_env->VisitMonitorRoots(visitor, RootInfo(kRootJNIMonitor, thread_id));HandleScopeVisitRoots(visitor, thread_id);// Visit roots for deoptimization.if (tlsPtr_.stacked_shadow_frame_record != nullptr) {RootCallbackVisitor visitor_to_callback(visitor, thread_id);ReferenceMapVisitor<RootCallbackVisitor, kPrecise> mapper(this, nullptr, visitor_to_callback);for (StackedShadowFrameRecord* record = tlsPtr_.stacked_shadow_frame_record;record != nullptr;record = record->GetLink()) {for (ShadowFrame* shadow_frame = record->GetShadowFrame();shadow_frame != nullptr;shadow_frame = shadow_frame->GetLink()) {mapper.VisitShadowFrame(shadow_frame);}}}for (DeoptimizationContextRecord* record = tlsPtr_.deoptimization_context_stack;record != nullptr;record = record->GetLink()) {if (record->IsReference()) {visitor->VisitRootIfNonNull(record->GetReturnValueAsGCRoot(),RootInfo(kRootThreadObject, thread_id));}visitor->VisitRootIfNonNull(record->GetPendingExceptionAsGCRoot(),RootInfo(kRootThreadObject, thread_id));}if (tlsPtr_.frame_id_to_shadow_frame != nullptr) {RootCallbackVisitor visitor_to_callback(visitor, thread_id);ReferenceMapVisitor<RootCallbackVisitor, kPrecise> mapper(this, nullptr, visitor_to_callback);for (FrameIdToShadowFrame* record = tlsPtr_.frame_id_to_shadow_frame;record != nullptr;record = record->GetNext()) {mapper.VisitShadowFrame(record->GetShadowFrame());}}// Visit roots on this thread's stackRuntimeContextType context;RootCallbackVisitor visitor_to_callback(visitor, thread_id);ReferenceMapVisitor<RootCallbackVisitor, kPrecise> mapper(this, &context, visitor_to_callback);mapper.template WalkStack<StackVisitor::CountTransitions::kNo>(false);
}

全局的gcroot

void Runtime::VisitNonThreadRoots(RootVisitor* visitor) {java_vm_->VisitRoots(visitor); //kRootGlobalsentinel_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));pre_allocated_OutOfMemoryError_when_throwing_exception_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));pre_allocated_OutOfMemoryError_when_throwing_oome_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));pre_allocated_OutOfMemoryError_when_handling_stack_overflow_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));pre_allocated_NoClassDefFoundError_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));VisitImageRoots(visitor);class_linker_->VisitTransactionRoots(visitor);
}


http://www.mrgr.cn/news/52072.html

相关文章:

  • 证明一个特定形式的函数在其三个正根中,两个较小根处的导数之和小于零
  • 北京十大取保候审律师事务所有哪些
  • Linux 命令 chown 和 chmod 的区别
  • 进行SEDEX认证需要准备哪些资料?
  • Java中Dom4j的配置与使用详细解析
  • 为什么k8s不支持docker-kubernetes
  • 【ArcPy】在pycharm中调试arcpy工具代码
  • c语言库文件
  • c++初阶数据结构速成
  • 自动驾驶系统研发系列—智能驾驶新技能:MEB低速紧急制动系统带来更多驾驶安全保障
  • 充电宝哪个品牌性价比高?2024精选五款推荐,新手买前必看!
  • 就是这个样的粗爆,手搓一个计算器:卡路里计算器
  • 产品经理图书推荐 《人工智能产品经理:AI时代PM修炼手册》
  • 基于单片机的搬运机器人控制系统
  • OpenCV高级图形用户界面(15)注册一个回调函数来处理鼠标事件的函数setMouseCallback()的使用
  • Cannot determine local hostname
  • KNN的 k 设置的过大会有什么问题
  • ZBrush和3D-Coat各自的优缺点是什么?
  • 番茄工作法计时器:高效时间管理利器
  • 鸿蒙开发案例:绘制中国象棋棋盘与棋子的技术教程