JVM parameters and performance optimization

Source: Internet
Author: User

// At the invitation of "one skill per day" in the team, I wrote this summary post.

 

JVM parameters are used in many places. For example, if you run ant check-style and run it, an outofmemory error is thrown. When you search online, they will tell you that you should modify the ant_opts environment variable and add "-xmx512m ".

 

For example, both JBoss and tomcat have a STARTUP script (startup. BAT), which also uses JVM parameters. JVM parameters can also be added to eclipse. ini of Eclipse. Flexible use of these JVM parameters can improve the performance of our Java program.

=== Common parameters ===

 

-Server
Must be the first parameter, which slows down JVM startup, but significantly improves JVM performance.

 

-Xms64m
Set the initial heap size and the Minimum Memory Used

 

-Xmx1024m
Set the maximum heap size.

 

-Xss256k
Set the stack size for each thread

 

-XX: maxpermsize = 128 m
Sets the maximum permanent area size. The permanent storage area is used to store class information and metadata.

=== GC (garbage collection) parameter ===

 

Sun hotspot JVM generally uses the GC Algorithm for generational collection. That is, objects are divided into young and old generations by different lifecycles. The new object will be converted to the young area. After several GC operations, if it is not collected, it will be gradually upgraded to the tenured area.

 

The default collector of Sun JVM is serial collector, Which is serial collection. We can also use multi-thread concurrent collection to improve efficiency. Note that it may be better to use the default recycler on a single-core machine.

 

-XX: + useparnewgc
Concurrent collection of young generation objects can shorten the collection time of young generation objects.

 

-XX: + useconcmarksweepgc
Use concurrent recovery for older generations

 

-XX: + useparallelgc
This collector and useconcmarksweepgc are mutually exclusive. For the new generation, parallel cleanup is used, and the old generation uses the single-thread mark-sweep-compact garbage collector.

=== Other parameters ===

 

-XX: compilethreshold = 100
This value indicates the number of times the method must be called before compilation. Hotspot JVM uses JIT (just-in-time compilation, http://en.wikipedia.org/wiki/Just-in-time_compilation) technology to compile bytecode with a local code, default of 1000, that is, after a method is called for 1000 times, the JVM will compile it. Lowering this value may increase the performance of the program, but may slow down the startup speed.

 

-XX: + doescapeanalysis
Enable escape analysis. This option can only be used in Java 1.6. See: http://kenwublog.com/jvm-optimization-escape-analysis

=== JVM parameter settings ===

 

You can directly append the Java command, for example, Java-xmx512m-XX: + useparnewgc test.

 

You can also set it in environment variables, such as java_opts and ant_opts. You can also set it in eclipse. ini, which must be written after a line in-vmargs

=== References ===

 

* Java 6 JVM parameter option Daquan (Chinese version): http://kenwublog.com/docs/java6-jvm-options-chinese-edition.htm
* Garbage collection-Frequently Asked Questions: http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
* Tune the JVM switch for optimal performance: http://gceclub.sun.com.cn/NetBeans/tutorials/tuning/index.html

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.