Types of JVM parameters
1) Parameters which are specified with -X
Non-standard (These are not guaranteed to be supported on all JVM implementations)
2) Parameters which are specified with -XX
Not stable and not recommended for normal use.
Both of these are subject to change without notice in subsequent releases of the JDK.
Important Points about JVM options
1) Boolean JVM options can be turned on with -XX:+ and can be turned off with -XX:-
2) Numeric JVM Options can be set with -XX:=
Numbers can include 'm' or 'M' for megabytes, 'k' or 'K' for kilobytes, and 'g' or 'G' for gigabytes (for example, 32k is the same as 3276
3) String JVM options can be set by using -XX:= and usually used to specify a file, a path, or a list of commands.
If you wish to detect which JVM arguments your currently running Java application is using, you can use the -
ManagementFactory.getRuntimeMXBean().getInputArguments()
Common JVM parameters
1. Java heap size
Following JVM options are used to specify initial and max heap size and thread stack size while running Java programs.
-Xms Sets - Initial Java heap size
-Xmx Sets - Maximum Java heap size
-Xss> Sets - Java thread stack size
2. Specifying GC (Garbage collector)
-XX:+UseParallelGC Use parallel garbage collection for scavenges
-XX:-UseConcMarkSweepGC Use concurrent mark-sweep collection for the old generation.
-XX:-UseSerialGC Use serial garbage collection.
Note : When you use GC Parameters if you are working on time critical application, as GC is time consuming operation and its desired to create a balance.
3. Printing GC details
-verbose:gc Logs garbage collector runs and how long they're taking. I generally use this as my first tool to investigate if GC is a bottleneck for a given application.
-XX:+PrintGCDetails includes the data from -verbose:gc but also adds information about the size of the new generation and more accurate timings.
-XX:-PrintGCTimeStamps Print timestamps at garbage collection.
4. Change Perm Gen Size
These JVM options are quite useful to set size for PermGen (permanent generation) and to solve java.lang.OutOfMemoryError : Perm Gen Space.
-XX:PermSize Sets - Size of the Permanent Generation
-XX:MaxPermSize=64m Sets - Maximum size of the Permanent Generation
-XX:NewRatio=2 Sets - Ratio of new/old generation sizes
5. Java classpath
Xbootclasspath Specifies classpath entries you want loaded without verification.
Putting classes on the bootclasspath skips this cost, but should only be used when you know the classes have been verified many times before.
Putting classes on the bootclasspath skips this cost, but should only be used when you know the classes have been verified many times before.
The -Xbootclasspath option can be used to either prepend (/p) or append (/a) resources to the bootstrap classpath.
6. Class loading and unloading
-XX:+TraceClassLoading
and -XX:+TraceClassUnloading
These are two JVM options which we use to print logging information whenever classes loads into JVM or unloads from JVM.
These JVM flags are extremely useful if you have any memory leak related to classloader and or suspecting that classes are not unloading or garbage collected.
Useful for investigating if you have a class leak or if old classes are getting collected or not.
7. Logging
-XX:+PrintCompilation
Prints out the name of each Java method Hotspot decides to JIT compile. The list will usually show a bunch of core Java class methods initially, and then turn to methods in your application.
8. Profiling
-Xprof
-Xrunhprof
9. Debugging
-XX:HeapDumpPath=./java_pid.hprof Path to directory or file name for heap dump.
-XX:-PrintConcurrentLocks Print java.util.concurrent locks in Ctrl-Break thread dump.
-XX:-PrintCommandLineFlags Print flags that appeared on the command line.
10. Remote debugging
-Xdebug
-Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
No comments:
Post a Comment
Note: only a member of this blog may post a comment.