Lokalna tablica referencyjna Android JNI, zrzut bieżącego stanu

Każdy programista Android JNI powinien znać tę wspaniałą wiadomość w logcat. Moje pytanie brzmi: Jak mogę powiedzieć maszynie wirtualnej, aby zrzuciła bieżący stan tabeli? Potrzebuję go do celów debugowania, aby upewnić się, że natywne wątki na wyjściu nie mają zaległych odniesień lokalnych.

Author: Pavel P, 2012-11-08

3 answers

Pełne uznanie dla Pawła, ale pomyślałem, że innym spodoba się przykładowy kod:

jclass vm_class = env->FindClass("dalvik/system/VMDebug");
jmethodID dump_mid = env->GetStaticMethodID( vm_class, "dumpReferenceTables", "()V" );
env->CallStaticVoidMethod( vm_class, dump_mid );
 11
Author: JonnyBoy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-07 23:26:15

W przypadku, gdy ktoś musi zrobić coś podobnego, możesz użyć wywrotki z dalvik.system.VMDebug

 4
Author: Pavel P,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-08 06:35:20

I try code below.it działa dobrze.

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): globalny zrzut TABELI odniesienia:

I/art (28913): ostatnie 10 wpisów (z 267):

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

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

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

I / art (28913): 263: 0xa1ba5000 bajt [] (2710656 elements)

I / art (28913): 262: 0xa284d000 bajt [] (30276 elementów)

I / art (28913): 261: 0xa2855000 bajt [] (19312 elementów)

I / art (28913): 260: 0xa1e3b000 bajt [] (6529728 elementów)

I / art (28913): 259: 0x12e1ca60 android.widok.dostępność.AccessibilityManager$1

I / art (28913): 258: 0x12df2c70 android.treść.ContentProvider$Transport

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

I/art (28913): Streszczenie:

I/art (28913) : 2 z Androida.opengl.EGLContext (2 unikalne instancje)

I/art (28913) : 1 z Androida.sprzęt.wyświetlacz.DisplayManagerGlobal$DisplayManagerCallback

I/art (28913) : 223 Jawa.lang.Klasa (172 unikalne instancje)

I/art (28913) : 2 z Androida.opengl.EGLDisplay (2 unikalne instancje)

I/art (28913): 2 z java.lang.ThreadGroup (2 unikalne instancje)

I/art (28913) : 2 z Androida.opengl.EGLSurface (2 unikalne instancje)

I/art (28913): 1 z dalvik.system.VMRuntime

I/art (28913) : 1 z Androida.treść.ContentProvider$Transport

I/art (28913): 1 z dalvik.system.PathClassLoader

I/art (28913) : 1 z Androida.widok.dostępność.AccessibilityManager$1

I/art (28913): 1 z android.app.ActivityThread$ApplicationThread

I / art (28913): 2 bajtów [] (100 elementów) (2 unikalne instancje)

I / art (28913): 7 bajtów [] (8192 elementów) (7 unikalnych instancji)

I / art (28913) : 1 bajtu [] (19312 elementów)

I / art (28913): 1 bajtu [] (30276 elementów)

I / art (28913): 1 bajtu [] (2710656 elementów)

I / art (28913) : 1 bajtu [] (6529728 elements)

I/art (28913)lang.String (2 unikalne instancje)

I/art (28913)lang.Nr ref.WeakReference (15 unikalnych instancji)

 3
Author: Joe Tang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-27 11:25:03