Java comes with commands in a detailed

Source: Internet
Author: User

Background

The knowledge and experience is the key foundation for a system to locate the problem, the data (run log, exception stack, GC log, thread snapshot [Threaddump/javacore file], heap dump snapshot [heapdump/hprof]) is the basis, the tool is the method that uses the knowledge to process the data.

Frequent use of appropriate virtual machine monitoring and analysis tools can accelerate our ability to analyze data and pinpoint problem resolution.

JPs

The JPS (JVM process Status Tool) lists the running virtual machine processes and displays the name of the virtual machine execution main class (the class where the main Class,main () function resides) and the local virtual machine unique ID for those processes Machine Identifier,lvmid). For on-premises virtual machine processes, the LVMID is consistent with the operating system's process ID (processes Identifier, PID).

Usage

Main options

Options Role Note
-Q Output only Lvmid, omit the name of the main class
-M Parameters passed to the main class main () function when the output virtual machine process starts
-L Output the full name of the main class, if the process is executing a jar package, the output jar path
-V JVM parameters when the output virtual machine process starts

Jstat

The Jstat (JVM Statistics monitoring tool) is a command-line utility for monitoring the various health state information of a virtual machine.

It can display runtime data such as class loading, memory, garbage Collection, JIT compilation, and so on in a local or remote virtual machine process.

jstat [Option Vmid [Interval][s|ms] [count]]

Option represents the virtual machine information that the user wants to query, mainly divided into 3 categories: class loading, garbage collection, run-time compilation status. Specifically, the following table:

Options Role
-class

Monitor class load, unload quantity, total space, and time spent on class loading.

-gc

Monitor Java heap status, including the Eden Zone, two survivor zones, old age area, permanent generation capacity, used frames, GC time totals, and more.

-gccapacity

The monitoring content is basically the same as-GC, but the output focuses on the maximum and minimum space used by each area of the Java heap.

-gcutil

The monitoring content is basically the same as-GC, but the output focuses on the percentage of space that has been used for the total space.

-gccause

As with the-gcutil function, but additional output causes the last GC to occur.

-gcnew

Monitor new generation GC status.

-gcnewcapacity
-gcold
-gcoldcapacity
-gcpermcapacity
-compiler
-printcompilation

In the case of a local virtual machine process, the vmid is consistent with lvmid, and if it is a remote virtual machine process, the VMID format is:

[Protocal:] [//]vmid[@hostname [:p Ort]/servername]

Interval represents the query interval

Count represents the number of queries

If you omit these two arguments, the description is queried only once.

Javap

The JAVAP is the JDK's own disassembler, and you can see the bytecode that the Java compiler generated for us. It allows us to understand the internal work of many compilers against source code and bytecode.

Usage

Grammar:
JAVAP [command options] class ...
The JAVAP command is used to parse the class file. Its output depends on the command options used. Without the command option, JAVAP outputs the public domain and method of the class passed to it. The JAVAP outputs it to the standard output device.
Command options:
-help The Help information for the output JAVAP.
-L output rows and local variable tables.
-B ensures backward compatibility with JDK 1.1 JAVAP.
-public displays only public classes and members.
-protected displays only the protected and public classes and members.
-package only displays packages, protected, and public classes and members. This is the default setting.
-private displays all classes and members.
-j[flag] Direct flag to the runtime system.
-S output internal type signature.
The unresolved code for each method in the-C output class, which is the instruction that constitutes the Java bytecode.
-verbose output stack size, locals and args of each method, and compiled version of class file
-classpath[Path] Specifies the path that JAVAP uses to find the class. If this option is set, it overrides the default value or CLASSPATH environment variable. Directories are separated by colons.
-bootclasspath[Path] Specifies the path used to load the bootstrap class. By default, the bootstrap class is the class that implements the core Java platform, located under Jrelib.

-extdirs[dirs] Overrides the location of the search installation mode extension. The default location for the extension is jrelibext.

Instance
Package Com.huawei.thread;public class Test44 {public static volatile int race = 0;public static void increase () {race++;} private static final int threads_count = 20;public static void Main (string[] args) {thread[] THREADS = new Thread[threads_  count];for (int i = 0; i < Threads_count; i++) {threads[i] = new Thread (new Runnable () {@Overridepublic void Run () {for (int i = 0; i < 10000; i++) {increase ();}}); Threads[i].start ();} while (Thread.activecount () > 1) {Thread.yield ();} System.out.println (race);}}

The bytecode generated by Javap-c Test44 is:

D:\workspace\thread\bin\com\huawei\thread>javap-c Test44 Warning: Binary file Test44 contains com.huawei.thread.Test44Compiled from  "Test44.java" public class Com.huawei.thread.Test44 {public static volatile int race;    static {};       code:0: Iconst_0 1:putstatic #13//Field race:i    4:return public Com.huawei.thread.Test44 (); code:0: Aload_0 1:invokespecial #18//Method java/lang/object. "    <init> ":() V 4:return public static void increase ();       code:0: getstatic #13//Field race:i       3:iconst_1 4:iadd 5:putstatic #13//Field race:i    8:return public static void Main (java.lang.string[]);       code:0: Bipush 2:anewarray #25//class Java/lang/thread 5:astore_1                 6:iconst_0 7:istore_2 8:goto notoginseng 11:aload_1 12:iload_2 13:new #25 //Class Java/lang/thread 16:dup 17:new #27//class com/huawei/thread/test44$1 20 : DUP 21:invokespecial #29//Method com/huawei/thread/test44$1. " <init> ":() V 24:invokespecial #30//Method java/lang/thread." <init> ":(ljava/lang/runnable;) V 27:aastore 28:aload_1 29:iload_2 30:aaload 31:invokevi Rtual #33//Method Java/lang/thread.start: () V
34:iinc 2, 1 37:iload_2 38:bipush 40:if_icmplt 43:goto 49 46:invokestatic #36//Method Java/lang/thread.yield: () V 49:invokestatic #39// Method Java/lang/thread.activecount: () I 52:iconst_1 53:if_icmpgt 56:getstatic #43 Field Java/lang/system.out:ljava/io/printstream; 59:getstatic #13//Field race:i 62:invokevirtual #49//Method java/io/printstream.println: (I) V 65:return}

  

Java comes with commands in a detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.