background preloader

JVM

Facebook Twitter

My Favorite Hotspot JVM Flags. I probably start up a JVM a thousand times a day.

My Favorite Hotspot JVM Flags

Test runs, benchmark runs, bug confirmation, API exploration, or running actual apps. And in many of these runs, I use various JVM switches to tweak performance or investigate runtime metrics. Here's a short list of my favorite JVM switches (note these are Hotspot/OpenJDK/SunJDK switches, and may or may not work on yours.

Apple JVM is basically the same, so these work). The Basics Most runs will want to tweak a few simple flags: -server turns on the optimizing JIT along with a few other "server-class" settings. Eventually you may want to tweak deeper details of the JVM: -XX:+UseParallelGC turns on the parallel young-generation garbage collector. Finally here's a list of the deepest options we use to investigate performance. Also, some of these may require you also pass -XX:+UnlockDiagnosticVMOptions to enable them. -XX:MaxInlineSize=# sets the maximum size method Hotspot will consider for inlining.

Java HotSpot VM Options. Please note that this page only applies to JDK 7 and earlier releases.

Java HotSpot VM Options

For JDK 8 please see the Windows, Solaris, Linux and Mac OS X reference pages. This document provides information on typical command-line options and environment variables that can affect the performance characteristics of the Java HotSpot Virtual Machine. Unless otherwise noted, all information in this document pertains to both the Java HotSpot Client VM and the Java HotSpot Server VM. Categories of Java HotSpot VM Options Standard options recognized by the Java HotSpot VM are described on the Java Application Launcher reference pages for Windows and Solaris & Linux. Options that begin with -X are non-standard (not guaranteed to be supported on all VM implementations), and are subject to change without notice in subsequent releases of the JDK.

Some Useful -XX Options Default values are listed for Java SE 6 for Solaris Sparc with -server. The options below are loosely grouped into categories. Behavioral Options. 6 Common Errors in Setting Java Heap Size. Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size.

6 Common Errors in Setting Java Heap Size

Here are some common mistakes I have seen when using them: Missing m, M, g or G at the end (they are case insensitive). For example,java -Xmx128 BigAppjava.lang.OutOfMemoryError: Java heap spaceThe correct command should be: java -Xmx128m BigApp. To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld.

But in real life, I guess you really mean -Xmx128mExtra space in JVM options, or incorrectly use =. How to set java heap size in Tomcat? Set CATALINA_OPTS=-Xms512m -Xmx512m (Windows, no "" around the value)export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash, "" around the value)setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh, "" around the value) In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. How to set java heap size in JBoss?

JAVA_OPTS="-server -Xms128m -Xmx128m" 2.