JVM Learning Note: Virtual machine performance monitoring

Source: Internet
Author: User
Tags jconsole

The JDK contains a lot of very useful tools in addition to the jar packages that are closely related to development. In addition to the command-line tools in the%java_home%\bin\ directory, several powerful visualizer tools are included. These tools can assist us in developing, debugging, and monitoring the state of virtual machines, so it is very important for developers to be familiar with these tools. The tools released with JDK1.8 are as follows:

In this article, you will use Jconsole and JVISUALVM to monitor the status of the virtual machine.

The use of a Javac,java,jar three commands

Use of the 1.javac command

C:\users\michael>javac usage: Javac<options> <source files>among the possible options are:-g generate all debug information-G:none does not generate any debug information-G:{lines,vars,source} only generates some debugging information-NoWarn does not generate any warnings-verbose output messages about the actions that the compiler is performing-deprecation output using outdated API source location-classpath < paths >specify where to find user class files and comment handlers-CP < paths >specify where to find user class files and comment handlers-sourcepath < paths >specify where to find the input source files-bootclasspath < paths >overwrite the location of the boot class file-extdirs < catalogue >overwrite the location of the installed extension-endorseddirs < catalogue >the location of the standard path that overrides the signature-proc:{none,only} Controls whether annotation processing is performed and/or compiled. -processor <class1>[,<class2>,<class3>...] The name of the comment handler to run; Bypassing the default search process-processorpath < paths >specifies where to find the comment handler-D < directories >specify where to place the generated class file-S < catalogue >specify where to place the generated source files-implicit:{none,class} Specifies whether to generate the class file for an implicit reference file-encoding < coding >Specify the character encoding used by the source file-source < release >provides source compatibility with a specified release version-target < release >to generate a class file for a specific VM version-Version Information-Summary of the Help output standard options-a keyword [=value] The option to pass to the comment handler-Summary of X-output non-standard options-j< tags > Direct < tags >passing to the runtime system-werror Stop compiling when warning occurs @< file name >read from File option and file name
c:\users\michael>javac-x output non-standard options : This option results in a slightly different output under different platforms. The output is omitted here.

Use of the 2.java command

C:\users\michael>java usage: Java [-options] class [args ...] (execution Class) or Java [-options]-jar Jarfile [args ...] (Execute JAR file) where the options are:-D32 use +bit data Model (if available)-d64 use -bit data Model (if available)-server selection"Server"The VM default VM is server. -CP< catalogue andZipClass search paths for/jar files >-classpath < directories andZipClass search path for/jar files >a delimited list of directories, JAR files, and ZIP archives used to search for class files. -d< name >=< value >Setting System Properties-verbose:[class|gc|jni] enable verbose output-Version output product versions and exit-version:< value >The specified version is required to run-showversion Output product version and Continue-jre-restrict-search | -no-jre-restrict-Search includes in version searches/exclude user-specific JRE-? -Help output this helper message-X output help for non-standard options-ea[:<packagename>...|:<classname>]    -enableassertions[:<packagename>...|:<classname>] To enable assertions by the specified granularity-da[:<packagename>...|:<classname>]    -disableassertions[:<packagename>...|:<classname>] Disables assertions with the specified granularity-esa | -enablesystemassertions Enable System assertion-DSA | -disablesystemassertions Disabling system assertions-agentlib:<libname>[=< Options >] Load the native agent library<libname>, for example-Agentlib:hprof See also-agentlib:jdwp=help and-agentlib:hprof= Help-agentpath:<pathname>[=< Options >] Load the native agent library by full path name-javaagent:<jarpath>[=< Options >] To load the Java programming language agent, see Java.lang.instrument-splash:<imagepath>Display the splash screen with the specified image for more information, see http://www.oracle.com/technetwork/java/javase/documentation/index.html. C:\Users\michael>java-X-xmixed Mixed Mode Execution (default)-xint Interpreting mode execution only-xbootclasspath:< use; Separated directories andZip/jar File >set the search path to guide classes and resources-xbootclasspath/a:< use; Separated directories andZip/jar File >append to the end of the bootstrap Classpath-xbootclasspath/p:< use; Separated directories andZip/jar File >before you place the bootstrap classpath-Xdiag displaying additional diagnostic messages-XNOCLASSGC Disabling class garbage collection-XINCGC Enable incremental garbage collection-xloggc:<file>record GC status in file (with timestamp)-Xbatch Disabling background compilation-xms<size> Setting the initial Java heap size-xmx<size> setting the maximum Java heap size-xss<size> setting up the Java thread stack Size-xprof Output CPU configuration file Data-Xfuture enable the most stringent checks, expected future default values-XRS reduced java/VM use of operating system signals (see documentation)-Xcheck:jni Perform additional checks on the JNI function-Xshare:off do not attempt to use shared class data-Xshare:auto using shared class data when possible (default)-Xshare:on requires shared class data, otherwise it will fail. -xshowsettings Show all settings and Continue-Xshowsettings:all Show all settings and Continue-XSHOWSETTINGS:VM Show all VM-related settings and Continue-xshowsettings:properties Show all property settings and Continue-Xshowsettings:locale Display all locale-related settings and ContinueThe-x option is a non-standard option and is subject to change without notice.

Use of the 3.jar command

C:\users\michael>jar usage: jar {ctxui}[vfm0me] [jar-file] [manifest-file] [Entry-point] [-Cdir] Files ... Options include:-C Create a new archive file-T list archive directories-x Extract the specified (or all) files from the file-u update an existing archive file- v generates verbose output-F Specify archive file name in standard output-m contains inventory information from the specified manifest file-e Specifies the application entry point for a standalone application bundled into an executable jar file-0store only; no use case any ZIP compression-M do not create a manifest file for the entry-I generate index information for the specified jar file-C changes to the specified directory and contains files that are recursively processed if there are any catalog files. Manifest file name, the specified order of archive file name and entry point name, and'm','F'And'e'tags are specified in the same order. Example1: Archive Two class files into an archive named Classes.jar: Jar CVF classes.jar Foo.class bar.class Example2: Using an existing manifest file'mymanifest'and will fooAll files in the directory are archived to'Classes.jar'Medium: Jar CVFM Classes.jar mymanifest-C foo/ . C:\Users\michael>jar CVF Tp.jar Timeprinter.class "Note: The application portal was not specified, so the jar package could not be executed" added manifest is being added: Timeprinter.class (input=620) (output =433) (Compression of -%) C:\Users\michael>java-no master manifest attribute in jar Tp.jartp.jarC:\Users\michael>jar cvfe tp.jar timeprinter timeprinter.class "NOTE: option cvfe added E,timeprinter main class The added manifest is being added: Timeprinter.class (input=620) (output =433) (Compression of -%) C:\Users\michael>java-jar Tp.jarfri APRTen  the: the: +Cst -Fri APRTen  the: the: -Cst -

Two compile and run the test program

The function of the test program is to output the current time to the console every second,timeprinter. Java source code is as follows:

 Public class Timeprinter {    publicstaticvoidthrows  exception{          for (int i = 0;i< 1000;i++) {        System.out.println (new  java.util.Date ());            Thread.Sleep (+);     }}}

1. Compiling the source file

C:\users\michael>javac- milliseconds [source file search path:.] [Search path for class file: C:\Program files\java\jdk1. 7.0_51\jre\lib\resources.jar,c:\program files\ ... [Loading Zipfileindexfileobject[c:\program files\java\jdk1. 7.0_51\lib\ct.sym (meta-inf/sym/rt.jar/java/lang/string.  Class)]]
... [Checking timeprinter][is loading Zipfileindexfileobject[c:\program files\java\jdk1. 7.0_51\lib\ct.sym (meta-inf/sym/rt.jar/java/lang/autocloseable. Class)] ... [Regularfileobject[timeprinter is written. class 920 MS]

2. Set the VM parameters and run the program

(1) Class mode operation

C:\users\michael>: From: £ º     

(2) Jar mode operation

c:\users\michael>:ten : The following:

Note: Under Eclipse, select Run->run configurations to set the VM run parameters, such as:

Of course, you can also set more parameters, such as:

c:\users\michael>java-xms200m-xmx200m-xmn100m-xss100m-xx:permsize=100m-xx:maxpermsize=100m-xx:+ Printgcdetails-xx:survivorratio=8-xx:maxtenuringthreshold=1 Timeprinter
Note: There are options with values:-xx:survivorratio=8, or with a minus sign, such as-xx:+printgcdetails. (with the addition of a minus sign, the estimate is true or false meaning)

Three use Jconsole monitor the running state

1. We plan to set the total of the heap too small to 20M, the new generation and the old age of 10M. Because Survivor and Eden have a space ratio of 1:8 by default, Eden is about 8m,2 survivor each 1M. The following verifies that Jconsole's monitoring is consistent with our plans.

(1) Total size of the heap:

(2) Old age Size:

(3) Eden Size:

(4) Survivor size:

Result: The expected plan was met.

2. Other information

3. Cons: Jconsole will have an impact on the normal operation of the monitored program.

As far as this test procedure is concerned, when running the Jconsole program to monitor the Timeprinter program, it will be found that Timeprinter will output some additional class loading information, and from the side the Timeprinter will load some additional classes to support Jconsole's work.

Four use JVISUALVM to monitor the running status

JVISUALVM's thread visualization is doing well compared to jconsole. And JVISUALVM has a big advantage: The program doesn't need to be monitored to run on a special agent, so it has little impact on the actual performance of the application. JVISUALVM is the Oracle Force Push Tool, which is used in the future.

JVM Learning Note: Virtual machine performance monitoring

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.