zoukankan      html  css  js  c++  java
  • 【10-26】java调试技术学习笔记

    调试工具

    jdk自带的工具

    • jmap
    • jconsole
    • VisualVM

    jmap

    • jmap -histo:live pid 列出该进程的所有活动实例统计信息
    • jmap -dump:live,file=test.map pid 转储到文件
    • jmap -J-Xms256m -dump:live,file=test.map pid 指定内存,防止内存不足
    • jmap -dump:format=b,file=test.map pid 转储堆快照
    C:>jmap
    Usage:
        jmap [option] <pid>
            (to connect to running process)
        jmap [option] <executable <core>
            (to connect to a core file)
        jmap [option] [server_id@]<remote server IP or hostname>
            (to connect to remote debug server)
    
    where <option> is one of:
        <none>               to print same info as Solaris pmap
        -heap                to print java heap summary
        -histo[:live]        to print histogram of java object heap; if the "live"
                             suboption is specified, only count live objects
        -clstats             to print class loader statistics
        -finalizerinfo       to print information on objects awaiting finalization
        -dump:<dump-options> to dump java heap in hprof binary format
                             dump-options:
                               live         dump only live objects; if not specified,
                                            all objects in the heap are dumped.
                               format=b     binary format
                               file=<file>  dump heap to <file>
                             Example: jmap -dump:live,format=b,file=heap.bin <pid>
        -F                   force. Use with -dump:<dump-options> <pid> or -histo
                             to force a heap dump or histogram when <pid> does not
                             respond. The "live" suboption is not supported
                             in this mode.
        -h | -help           to print this help message
        -J<flag>             to pass <flag> directly to the runtime system
    
    

    mat (Memory Analysis Tool)

    • 内存分析工具

    jhat (Java Heap Analysis Tool)

    • 堆内存分析工具
    • jhat test.map 分析堆快照,并生成html文件
    • jhat -J-Xmx512m test.map 指定内存,防止内存不足
    C:>jhat
    ERROR: No arguments supplied
    Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>
            -J<flag>          Pass <flag> directly to the runtime system. For
                              example, -J-mx512m to use a maximum heap size of 512MB
            -stack false:     Turn off tracking object allocation call stack.
            -refs false:      Turn off tracking of references to objects
            -port <port>:     Set the port for the HTTP server.  Defaults to 7000
            -exclude <file>:  Specify a file that lists data members that should
                              be excluded from the reachableFrom query.
            -baseline <file>: Specify a baseline object dump.  Objects in
                              both heap dumps with the same ID and same class will
                              be marked as not being "new".
            -debug <int>:     Set debug level.
                                0:  No debug output
                                1:  Debug hprof file parsing
                                2:  Debug hprof file parsing, no server
            -version          Report version number
            -h|-help          Print this help and exit
            <file>            The file to read
    For a dump file that contains multiple heap dumps,
    you may specify which dump in the file
    by appending "#<number>" to the file name, i.e. "foo.hprof#3".
    
    All boolean options default to "true"
    
    

    tips

    • jps(Java Virtual Machine Process Status Tool )
    • jps命令可以查看当前使用java虚拟机的进程

    jstack

    jstack可以用来查看Java进程里的线程都在干什么,这通常对于应用没反应,非常慢等等场景都有不小的帮助,jstack默认只能看到Java栈,而jstack -m则可以看到线程的Java栈和native栈,但如果Java方法被编译过,则看不到(然而大部分经常访问的Java方法其实都被编译过)。

    C:>jstack
    Usage:
        jstack [-l] <pid>
            (to connect to running process)
        jstack -F [-m] [-l] <pid>
            (to connect to a hung process)
        jstack [-m] [-l] <executable> <core>
            (to connect to a core file)
        jstack [-m] [-l] [server_id@]<remote server IP or hostname>
            (to connect to a remote debug server)
    
    Options:
        -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
        -m  to print both java and native frames (mixed mode)
        -l  long listing. Prints additional information about locks
        -h or -help to print this help message
    

    jinfo

    可以输出并修改运行时的java进程的opts。用处比较简单,用于输出JAVA系统参数及命令行参数。用法是jinfo -opt pid 如:查看2788的MaxPerm大小可以用 jinfo -flag MaxPermSize 2788

    where <option> is one of:
        -flag <name>         to print the value of the named VM flag
        -flag [+|-]<name>    to enable or disable the named VM flag
        -flag <name>=<value> to set the named VM flag to the given value
        -flags               to print VM flags
        -sysprops            to print Java system properties
        <no option>          to print both of the above
        -h | -help           to print this help message
    

    javah

    生成本地方法的头文件

  • 相关阅读:
    Java源码赏析(四)Java常见注解
    Java源码赏析(三)初识 String 类
    Java源码赏析(二)Java常见接口
    Java源码赏析(一)Object 类
    Java随谈(二)对空指针异常的碎碎念
    Java随谈(一)魔术数字、常量和枚举
    jquery.validate 使用--验证表单隐藏域
    jquery.validate使用
    jquery.validate使用
    jquery.validate使用
  • 原文地址:https://www.cnblogs.com/achievec/p/6028760.html
Copyright © 2011-2022 走看看