如何在dalvikVM中启用特定于垃圾收集器的日志

时间:2013-01-09 13:03:37

标签: android garbage-collection dalvik

如上所述,我正在尝试在dalvik虚拟机中启用GC特定日志。我怎么能这样做?

当我说GC特定日志时,我想监视GC中发生的所有函数调用(不仅仅是logcat中的gc fiter导致GC_EXPLIIT和GC_CONCURRENT以及GC_FOR_ALLOC),这样我就可以制作流程图(这个过程称为GC根据启发式等方法调用gc的算法。

我尝试使用adb shell dalvikvm [options] .

在Dalvik虚拟机中是否有像-XX:+ PrintGCDetails(jvm)这样的选择?

android框架代码库中是否有任何标志,如果设置将一直打印gc日志?

dalvikvm的以下选项有什么作用? (一个很好的在线参考可以工作)

-Xgc:[无]精确 -Xgc:[无]预验证 -Xgc:[无] postverify -Xgc:[无]的并发 -Xgc:[无] verifycardtable -XX:+ DisableExplicitGC。

1 个答案:

答案 0 :(得分:0)

我找不到这些选项的详细文档。

在查看源代码后,这些选项是:

  • 精确:VM线程堆栈每个项目可能只是整数或内部值或对象指针。并且为了注册这些信息,有一个堆栈线程的寄存器映射来标记项目的状态。如果它是打开的,则只标记对象,称为精确/无谨慎GC
  • xxx-verify:对于vm GC验证步骤
  • 并发:打开/关闭GC并发标记的步骤
  • ExplicitGC:打开/关闭java API Runtime.gc()或信号GC。

以下是详细信息:

在dalvik源代码中,这些选项用于配置dalvikvm GC:

} else if (strncmp(argv[i], "-Xgc:", 5) == 0) {
    //In VM thread, there is a register map for marking each stack item's status whether it is an object or internal value. And In GC step, only object item will be marked. If this value is OFF, all stack will be marked even if the item is only an integer.
    if (strcmp(argv[i] + 5, "precise") == 0)
        gDvm.preciseGc = true;
    else if (strcmp(argv[i] + 5, "noprecise") == 0)
        gDvm.preciseGc = false;
    //Only for GC verify check
    else if (strcmp(argv[i] + 5, "preverify") == 0)
        gDvm.preVerify = true;
    else if (strcmp(argv[i] + 5, "nopreverify") == 0)
        gDvm.preVerify = false;
    else if (strcmp(argv[i] + 5, "postverify") == 0)
        gDvm.postVerify = true;
    else if (strcmp(argv[i] + 5, "nopostverify") == 0)
        gDvm.postVerify = false;
    //Open/Close Dalvik vm GC markseep is concurrent or not
    else if (strcmp(argv[i] + 5, "concurrent") == 0)
        gDvm.concurrentMarkSweep = true;
    else if (strcmp(argv[i] + 5, "noconcurrent") == 0)
        gDvm.concurrentMarkSweep = false;
    //Only for GC verify cardtable which is used for marking the concurrent marksweep dirty field
    else if (strcmp(argv[i] + 5, "verifycardtable") == 0)
        gDvm.verifyCardTable = true;
    else if (strcmp(argv[i] + 5, "noverifycardtable") == 0)
        gDvm.verifyCardTable = false; 
    else {
        dvmFprintf(stderr, "Bad value for -Xgc");
        return -1;
    }
    ALOGV("Precise GC configured %s", gDvm.preciseGc ? "ON" : "OFF");
}

PS:

要获取Android dalvikvm命令选项,您可以输入命令adb shell dalvikvm -h以获取详细信息。

Android 4.3(yakju-user 4.3 JWR66Y 776638 release-keys)的结果是

dalvikvm: [options] class [argument ...]
dalvikvm: [options] -jar file.jar [argument ...]

The following standard options are recognized:
  -classpath classpath
  -Dproperty=value
  -verbose:tag  ('gc', 'jni', or 'class')
  -ea[:<package name>... |:<class name>]
  -da[:<package name>... |:<class name>]
   (-enableassertions, -disableassertions)
  -esa
  -dsa
   (-enablesystemassertions, -disablesystemassertions)
  -showversion
  -help

The following extended options are recognized:
  -Xrunjdwp:<options>
  -Xbootclasspath:bootclasspath
  -Xcheck:tag  (e.g. 'jni')
  -XmsN  (min heap, must be multiple of 1K, >= 1MB)
  -XmxN  (max heap, must be multiple of 1K, >= 2MB)
  -XssN  (stack size, >= 1KB, <= 256KB)
  -Xverify:{none,remote,all}
  -Xrs
  -Xint  (extended to accept ':portable', ':fast' and ':jit')

These are unique to Dalvik:
  -Xzygote
  -Xdexopt:{none,verified,all,full}
  -Xnoquithandler
  -Xjnigreflimit:N  (must be multiple of 100, >= 200)
  -Xjniopts:{warnonly,forcecopy}
  -Xjnitrace:substring (eg NativeClass or nativeMethod)
  -Xstacktracefile:<filename>
  -Xgc:[no]precise
  -Xgc:[no]preverify
  -Xgc:[no]postverify
  -Xgc:[no]concurrent
  -Xgc:[no]verifycardtable
  -XX:+DisableExplicitGC
  -X[no]genregmap
  -Xverifyopt:[no]checkmon
  -Xcheckdexsum
  -Xincludeselectedop
  -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*
  -Xincludeselectedmethod
  -Xjitthreshold:decimalvalue
  -Xjitblocking
  -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\;replace)
  -Xjitclass:classname[,classname]*
  -Xjitoffset:offset[,offset]
  -Xjitconfig:filename
  -Xjitcheckcg
  -Xjitverbose
  -Xjitprofile
  -Xjitdisableopt
  -Xjitsuspendpoll

Configured with: debugger profiler hprof jit(armv7-a-neon) smp show_exception=1