简体   繁体   English

Android JNI本地引用表,转储当前状态

[英]Android JNI local reference table, dump current state

Any Android JNI developer should be familiar with this wonderful message in logcat. 任何Android JNI开发人员都应该熟悉logcat中的这条精彩消息。 My question is: how can I tell the VM to dump current table state? 我的问题是:如何告诉VM转储当前表状态? I need it for debugging purposes to make sure that native threads at exit have no outstanding local references. 我需要它来进行调试,以确保退出时的本机线程没有未完成的本地引用。

Full credit to Pavel, but I thought others might like the example code: 完全归功于Pavel,但我认为其他人可能会喜欢示例代码:

jclass vm_class = env->FindClass("dalvik/system/VMDebug");
jmethodID dump_mid = env->GetStaticMethodID( vm_class, "dumpReferenceTables", "()V" );
env->CallStaticVoidMethod( vm_class, dump_mid );

如果有人需要做类似的事情,你可以使用dalvik.system.VMDebug中的dumpReferenceTables

I try code below.it works well. 我尝试下面的代码。它运作良好。

try {
    Class cls = Class.forName("android.os.Debug");
    Method method = cls.getDeclaredMethod("dumpReferenceTables");
    Constructor con= cls.getDeclaredConstructor();
    con.setAccessible(true);
    method.invoke(con.newInstance());
    //call method dumpReferenceTables of dalvik.system.VMDebug
    //to dump reference table at last.
}
catch(Exception e){
    Log.i(TAG,"exception="+e.getMessage());
}

I/art (28913): global reference table dump: I / art(28913):全局引用表转储:

I/art (28913): Last 10 entries (of 267): I / art(28913):最后10个条目(267个):

I/art (28913): 266: 0x12e340c0 java.lang.ref.WeakReference I / art(28913):266:0x12e340c0 java.lang.ref.WeakReference

I/art (28913): 265: 0x12e34060 java.lang.ref.WeakReference I / art(28913):265:0x12e34060 java.lang.ref.WeakReference

I/art (28913): 264: 0x12e24220 java.lang.ref.WeakReference I / art(28913):264:0x12e24220 java.lang.ref.WeakReference

I/art (28913): 263: 0xa1ba5000 byte[] (2710656 elements) I / art(28913):263:0xa1ba5000 byte [](2710656个元素)

I/art (28913): 262: 0xa284d000 byte[] (30276 elements) I / art(28913):262:0xa284d000 byte [](30276个元素)

I/art (28913): 261: 0xa2855000 byte[] (19312 elements) I / art(28913):261:0xa2855000 byte [](19312个元素)

I/art (28913): 260: 0xa1e3b000 byte[] (6529728 elements) I / art(28913):260:0xa1e3b000 byte [](6529728个元素)

I/art (28913): 259: 0x12e1ca60 android.view.accessibility.AccessibilityManager$1 我/艺术(28913):259:0x12e1ca60 android.view.accessibility.AccessibilityManager $ 1

I/art (28913): 258: 0x12df2c70 android.content.ContentProvider$Transport I / art(28913):258:0x12df2c70 android.content.ContentProvider $ Transport

I/art (28913): 257: 0x12ed4040 java.lang.ref.WeakReference I / art(28913):257:0x12ed4040 java.lang.ref.WeakReference

I/art (28913): Summary: 我/艺术(28913):摘要:

I/art (28913): 2 of android.opengl.EGLContext (2 unique instances) I / art(28913):android.opengl.EGLContext中的2个(2个唯一实例)

I/art (28913): 1 of android.hardware.display.DisplayManagerGlobal$DisplayManagerCallback I / art(28913):android.hardware.display.DisplayManagerGlobal中的1个$ DisplayManagerCallback

I/art (28913): 223 of java.lang.Class (172 unique instances) I / art(28913):java.lang.Class的223(172个唯一实例)

I/art (28913): 2 of android.opengl.EGLDisplay (2 unique instances) I / art(28913):android.opengl.EGLDisplay中的2个(2个唯一实例)

I/art (28913): 2 of java.lang.ThreadGroup (2 unique instances) I / art(28913):java.lang.ThreadGroup中的2个(2个唯一实例)

I/art (28913): 2 of android.opengl.EGLSurface (2 unique instances) I / art(28913):android.opengl.EGLSurface中的2个(2个唯一实例)

I/art (28913): 1 of dalvik.system.VMRuntime I / art(28913):dalvik.system.VMRuntime中的1

I/art (28913): 1 of android.content.ContentProvider$Transport I / art(28913):1。android.content.ContentProvider $ Transport

I/art (28913): 1 of dalvik.system.PathClassLoader I / art(28913):dalvik.system.PathClassLoader中的1个

I/art (28913): 1 of android.view.accessibility.AccessibilityManager$1 I / art(28913):android.view.accessibility.AccessibilityManager $ 1中的1

I/art (28913): 1 of android.app.ActivityThread$ApplicationThread I / art(28913):android.app.ActivityThread $ ApplicationThread中的1个

I/art (28913): 2 of byte[] (100 elements) (2 unique instances) I / art(28913):2个byte [](100个元素)(2个唯一实例)

I/art (28913): 7 of byte[] (8192 elements) (7 unique instances) I / art(28913):7个byte [](8192个元素)(7个唯一实例)

I/art (28913): 1 of byte[] (19312 elements) I / art(28913):1个字节[](19312个元素)

I/art (28913): 1 of byte[] (30276 elements) I / art(28913):1个byte [](30276个元素)

I/art (28913): 1 of byte[] (2710656 elements) I / art(28913):1个字节[](2710656个元素)

I/art (28913): 1 of byte[] (6529728 elements) I / art(28913):1个字节[](6529728个元素)

I/art (28913): 2 of java.lang.String (2 unique instances) I / art(28913):java.lang.String中的2个(2个唯一实例)

I/art (28913): 15 of java.lang.ref.WeakReference (15 unique instances) I / art(28913):java.lang.ref.WeakReference中的15个(15个唯一实例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM