代码fork自 https://github.com/AndroidAdvanceWithGeektime/JVMTI_Sample
感谢原作者分享!
该例子主要展示了JVM TI支持的几种功能:
- Memory Alloc Tracker
- GC Event Tracker
- JNI Method Rebind
- Class Retransform
- getObjectSize
- RedefineClasses (实现android studio 3.5的apply change功能)
注意:例子最好在9.0上测试,支持模拟器,8.0下修改 Class 功能无效
产生的日志可以在 Logcat 中查看
I/jvmti: ==========alloc callback======= [I {size:32}
I/jvmti: ==========alloc callback======= java.lang.ref.WeakReference {size:24}
I/jvmti: ==========alloc callback======= java.lang.ref.WeakReference {size:24}
I/jvmti: ==========alloc callback======= [Ljava.lang.Object; {size:16}
I/jvmti: ==========触发 GCStart=======
I/jvmti: ==========触发 GCFinish=======