1# listextensions
2
3listextensions is a jvmti agent that will print the details of all available jvmti extension
4functions and events.
5
6# Usage
7### Build
8>    `m liblistextensions`
9
10The libraries will be built for 32-bit, 64-bit, host and target. Below examples
11assume you want to use the 64-bit version.
12
13#### ART
14>    `art -Xplugin:$ANDROID_HOST_OUT/lib64/libopenjdkjvmti.so '-agentpath:liblistextensions.so' -cp tmp/java/helloworld.dex -Xint helloworld`
15
16This will print something similar to:
17```
18dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:104] Found 13 extension functions
19dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:107] com.android.art.heap.get_object_heap_id
20dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:108]       desc: Retrieve the heap id of the object tagged with the given argument. An arbitrary object is chosen if multiple objects exist with the same tag.
21dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:109]       arguments: (count: 2)
22dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:112]               tag (IN, JLONG)
23dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:112]               heap_id (OUT, JINT)
24dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:114]       Errors: (count: 1)
25dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:118]               JVMTI_ERROR_NOT_FOUND
26dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:107] com.android.art.heap.get_heap_name
27dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:108]       desc: Retrieve the name of the heap with the given id.
28dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:109]       arguments: (count: 2)
29dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:112]               heap_id (IN, JINT)
30dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:112]               heap_name (ALLOC_BUF, CCHAR)
31dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:114]       Errors: (count: 1)
32dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:118]               JVMTI_ERROR_ILLEGAL_ARGUMENT
33...
34dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:130] Found 2 extension events
35dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:133] com.android.art.internal.ddm.publish_chunk
36dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:134]       index: 86
37dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:135]       desc: Called when there is new ddms information that the agent or other clients can use. The agent is given the 'type' of the ddms chunk and a 'data_size' byte-buffer in 'data'. The 'data' pointer is only valid for the duration of the publish_chunk event. The agent is responsible for interpreting the information present in the 'data' buffer. This is provided for backwards-compatibility support only. Agents should prefer to use relevant JVMTI events and functions above listening for this event.
38dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:136]       event arguments: (count: 4)
39dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:139]               jni_env (IN_PTR, JNIENV)
40dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:139]               type (IN, JINT)
41dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:139]               data_size (IN, JINT)
42dalvikvm64 I 07-30 10:47:37 154719 154719 list-extensions.cc:139]               data (IN_BUF, JBYTE)
43...
44```
45
46* `-Xplugin` and `-agentpath` need to be used, otherwise the agent will fail during init.
47* If using `libartd.so`, make sure to use the debug version of jvmti.
48
49>    `adb shell setenforce 0`
50>
51>    `adb push $ANDROID_PRODUCT_OUT/system/lib64/liblistextensions.so /data/local/tmp/`
52>
53>    `adb shell am start-activity --attach-agent /data/local/tmp/liblistextensions.so some.debuggable.apps/.the.app.MainActivity`
54
55#### RI
56>    `java -agentpath:liblistextensions.so -cp tmp/helloworld/classes helloworld`
57