Debian Codegraph @

tools/jvmti-agents/field-counts/README.md

raw
1 # fieldcount
2
3 fieldcount is a JVMTI agent designed to investigate the types being held by specific fields and
4 how large the objects referenced by these fields are.
5
6 Note that just by using the agent some fields might be written (for example fields related to
7 keeping track of jfieldIDs). Users should be aware of this.
8
9 # Usage
10 ### Build
11 > `m libfieldcount libfieldcounts`
12
13 The libraries will be built for 32-bit, 64-bit, host and target. Below examples
14 assume you want to use the 64-bit version.
15
16 ### Command Line
17
18 The agent is loaded using -agentpath like normal. It takes arguments in the
19 following format:
20 > `Lname/of/class;.nameOfField:Ltype/of/field;[,...]`
21
22 #### ART
23 ```shell
24 art -Xplugin:$ANDROID_HOST_OUT/lib64/libopenjdkjvmti.so '-agentpath:libfieldcount.so=Ljava/lang/Class;.extData:Ldalvik/system/ClassExt;,Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object;' -cp tmp/java/helloworld.dex -Xint helloworld
25 ```
26
27 * `-Xplugin` and `-agentpath` need to be used, otherwise the agent will fail during init.
28 * If using `libartd.so`, make sure to use the debug version of jvmti.
29
30 ```shell
31 adb shell setenforce 0
32
33 adb push $ANDROID_PRODUCT_OUT/system/lib64/libfieldcounts.so /data/local/tmp/
34
35 adb shell am start-activity --attach-agent '/data/local/tmp/libfieldcounts.so=Ljava/lang/Class;.extData:Ldalvik/system/ClassExt;,Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object;' some.debuggable.apps/.the.app.MainActivity
36 ```
37
38 #### RI
39 > `java '-agentpath:libfieldcount.so=Lname/of/class;.nameOfField:Ltype/of/field;' -cp tmp/helloworld/classes helloworld`
40
41 ### Printing the Results
42 All statistics gathered during the trace are printed automatically when the
43 program normally exits. In the case of Android applications, they are always
44 killed, so we need to manually print the results.
45
46 > `kill -SIGQUIT $(pid com.littleinc.orm_benchmark)`
47
48 Will initiate a dump of the counts (to logcat).
49
50 The dump will look something like this.
51
52 ```
53 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:60] listing field Ljava/lang/Class;.extData:Ldalvik/system/ClassExt;
54 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:60] listing field Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object;
55 Hello, world!
56 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:97] Dumping counts of fields.
57 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:98] Field name Type Count Total Size
58 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:155] Ljava/lang/Class;.extData:Ldalvik/system/ClassExt; <ALL TYPES> 2800 3024
59 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:161] Ljava/lang/Class;.extData:Ldalvik/system/ClassExt; Ldalvik/system/ClassExt; 64 3024
60 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:161] Ljava/lang/Class;.extData:Ldalvik/system/ClassExt; <null> 2738 0
61 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:155] Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object; <ALL TYPES> 63 10008
62 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:161] Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object; <null> 26 0
63 dalvikvm64 I 06-27 14:24:59 183155 183155 fieldcount.cc:161] Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object; [J 39 10008
64 ```