Detailed description of Java Virtual Machine Parameters

Source: Internet
Author: User
Tags bootstrap classes

When Java runs compiled classes, it is loaded and executed through the Java Virtual Machine. the Java Virtual Machine is started through the operating system command java_home/bin/Java-option. The-option parameter is the virtual machine parameter, java_home is the JDK installation path. With these parameters, you can adjust the running status of the virtual machine. You can have a deeper understanding of the running mode of the virtual machine.
Virtual Machine Parameters are classified into two types: basic and extension. Enter java_home/bin/Java in the command line to get the basic parameter list,
Enter java_home/bin/Java-X in the command line to obtain the list of extended parameters.

Basic parameter description:

-Client,-Server
These two parameters are used to set the running mode used by the virtual machine. The client mode is faster to start, but the runtime performance and memory management efficiency are not as good as the server mode, which is usually used for client applications. On the contrary, server mode is slower to start than client, but can achieve higher running performance.
In Windows, the default Virtual Machine Type is client mode. To use server mode, you need to add the-server parameter when starting the virtual machine to achieve higher performance and server-side applications, server mode is recommended, especially for multiple CPU Systems. In Linux, Solaris adopts the server mode by default.

-Hotspot
The meaning is the same as that of the client. The parameter jdk1.4 previously used is no longer used and replaced by the client.

-Classpath,-CP
When a virtual machine runs a class, it needs to be loaded into the memory. The method and sequence of the Virtual Machine search class are as follows:

Bootstrap classes, extension classes, and user classes.

The path in Bootstrap is the jar or ZIP file that comes with the VM. The VM first searches for these package files and uses the system. getproperty ("Sun. boot. class. path ") to obtain the package name searched by the virtual machine.

Extension is a jar file located in the JRE/lib/EXT directory. The VM searches for the jar files in this directory after searching for bootstrap. Use System. getproperty ("Java. Ext. dirs") to obtain the extension search path used by the VM.

The user classes search order is the current directory, environment variable classpath, and-classpath.

-Classpath informs the virtual machine to search for the directory name, JAR file name, and zip file name, separated by semicolons.

For example, if you develop a public class and package it into a common class. jar package, in the use of common. -classpath common is required for classes in jar. jar tells the virtual machine from common. find the class in jar, otherwise the virtual machine will throw Java. lang. noclassdeffounderror: the class definition is not found.

You can use system. getproperty ("Java. Class. Path") at runtime to obtain the path of the Virtual Machine search class.

After-classpath is used, the virtual machine no longer uses the Class search path in classpath. If-classpath and classpath are not set, the virtual machine uses the current path (.) as the class search path.

We recommend that you use-classpath to define the classpath to be searched by the virtual machine, instead of using the search path of the Environment Variable classpath, to reduce the potential conflicts when multiple projects use classpath at the same time. For example, application 1 must use Class G in a1.0.jar, Application 2 must use Class G in a2.0.jar, and a2.0.jar is the upgrade package of a1.0.jar. When a1.0.jar and a2.0.jar are both in classpath, when the Virtual Machine finds the class G in the first package, the search is stopped. If the Virtual Machine of Application 1 Application 2 searches from the classpath, a class G with the correct version of the application will not be available.

-D <propertyname> = Value

Set the attribute name/value pair in the system attribute of the Virtual Machine. applications running on the virtual machine can obtain the value of system. getproperty ("propertyname.
If the value contains spaces, double quotation marks are required to enclose the value, such as-dname = "Space string ".
This parameter is usually used to set system-level global variable values. For example, the configuration file path should be accessible from anywhere in the program.

-Verbose [: Class | GC | JNI]

Displays the virtual machine running information on the output device.
Verbose and verbose: the meaning of the class is the same. The output information of the class loaded by the virtual machine is as follows:
[Loaded java. Io. filepermission $1 from shared objects file]
This parameter can be used to diagnose the situation of loading a virtual machine from a class if the reporting class of the virtual machine cannot be found or the class conflict occurs.

-Verbose: GC displays information on the output device when memory is recycled from the VM. The format is as follows:
[Full GC 268 K-> 168 K (1984 K), 0.0187390 secs]
This parameter is used to monitor the recovery of VM memory.

-Verbose: JNI outputs the device display information when the virtual machine calls the native method. The format is as follows:
[Dynamic-linking native method hellonative. Sum... JNI]
This parameter is used to monitor Virtual Machine calls to local methods. It can be conveniently diagnosed when a JNI error occurs.

-Version
Display the version of the virtual machine that can be run and exit. When a machine is installed with JDK of different versions

-Showversion
Displays version information and help information.

-Ea [: <packagename>... |: <classname>]
-Enableassertions [: <packagename>... |: <classname>]

JAVA supports the assertion mechanism from jdk1.4 to diagnose runtime problems. Usually, assertions are valid in the test phase and do not need to be run during formal operation. The expression value after assertion is a logical value. If it is true, the assertion does not run. If it is false, the assertionerror java. Lang. assertionerror is thrown.
The above parameters are used to set whether the VM starts the assertion mechanism. If there is a shortage of time-saving VMS, the assertion mechanism is disabled and the-EA can be used to enable the assertion mechanism, when <packagename> and classname are not added, assertions in all packages and classes are run. If you want to run only assertions in some packages or classes, you can add the package name or class name to-ea. For example, to start the assertions in the com. Foo. util package, run the command-Ea: COM. Foo. util.

-Da [: <packagename>... |: <classname>]
-Disableassertions [: <packagename>... |: <classname>]
Set the VM to disable assertion processing. packagename and classname are used in the same way as-ea.

-ESA |-enablesystemassertions
Sets the virtual machine to display system-class assertions.

-DSA |-disablesystemassertions
Set the VM to disable system-class assertions.

-Agentlib: <libname> [= <Options>]
This parameter is newly introduced by jdk5. it is used to load the local proxy library on a virtual machine.

Libname is the name of the local agent library, and the virtual machine search path is the path in the environment variable path. options is the parameter passed to the local database for startup. Multiple parameters are separated by commas. Search for the local database name libname on Windows. DLL file. The local library name is libname searched on the Unix virtual machine. so files, search PATH environment variables vary on different systems, Linux, SunOS, IRIX for LD_LIBRARY_PATH, Aix for libpath, HP-UX for shlib_path.

For example, you can use-agentlib: hprof to obtain the running status of a virtual machine, including running data such as CPU, memory, and thread, and output data to a specified file.-agentlib is available: hprof = help to get the help list. You can find the hprof. dll file in the JRE/bin directory.

-Agentpath: <pathname> [= <Options>]
Set the VM to load the local database in full path without searching the path in path. Other functions are the same as those of agentlib.

-Javaagent: <jarpath> [= <Options>]
When the virtual machine is started, the Java language device proxy is entered. The mainfest file in the jarpath file must have the agent-class attribute. The proxy class must implement the public static void premain (string agentargs, instrumentation insT) method. When the VM is initialized, The premain method is called in the order described by the proxy class.
See java. Lang. Instrument

 

Extended parameter description
-Xmixed
In setup-client mode, the VM compiles and executes just-in-time for frequently used methods, and interprets other methods for execution. This is the default virtual machine mode.

-Xint
Set-the virtual machine running in client mode executes the class bytecode in interpreted mode, and does not compile the bytecode as the local code.

-Xbootclasspath: Path

-Xbootclasspath/A: Path

-Xbootclasspath/P: Path
Change the virtual machine to load the default system running package Rt. jar and load the system running class from the search path set in-xbootclasspath. This parameter is not used unless you can write a runtime.
/A: add the search path in path to the default search path.
/P: Search for the search path in path before the default search path.

-Xnoclassgc
Disable the class garbage collection function of the virtual machine.

-Xincgc
Start the incremental garbage collector, Which is disabled by default. The incremental garbage collector can reduce the pause time caused by accidental long-time garbage collection. However, the incremental garbage collector and the application execute concurrently, so it occupies part of the CPU's functions on the application.

-Xloggc: <File>
Write the garbage collection information of the virtual machine to the log file. The file name is specified by the file. The file format is a flat file, and the content is the same as that output by-verbose: GC.

-Xbatch
The default running mode of the VM is to compile the class code in the background, and then execute the code in the foreground. Using the-xbatch parameter, the VM background compilation will be disabled and then executed after the foreground compilation is complete.

-XMS <size>
Set the initial size of the available memory heap of the VM. The default unit is byte. The size is an integer multiple of 1024 and must be greater than 1 MB. The available size is K or M (m) to set a large memory size. The initial heap size is 2 MB.
Example:-xms6400k,-xms256m

-Xmx <size>
Sets the maximum available size of the VM memory heap. The default unit is byte. The value must be an integer multiple of 1024 and greater than 2 MB. You can set a large memory size in the unit of K (k) or M (m. The maximum heap size is 64 MB by default.
Example:-xmx81920k,-xmx80m
When the application requests a large memory runtime, the VM throws a java. Lang. outofmemoryerror: Java heap space error, you need to use-xmx to set a large available memory heap.

-XSS <size>
Sets the size of the thread stack. The default unit is byte. Similar to-xmx, you can use K or m to set a large value. Generally, the default size allocated by the operating system to the thread stack is 1 MB.
You can also set the stack size when creating a thread object in Java. The prototype of the constructor is thread (threadgroup group, runnable target, string name, long stacksize ).

-Xprof
Outputs the diagnostic information when the CPU is running.

-Xfuture
Perform a strict format check on the class files to ensure that the class Code complies with the class code specifications. To maintain backward compatibility, virtual machines do not perform strict format checks by default.

-Xrs
Reduce the use of Operating System signals (singals) in virtual machines. This parameter is usually used when a virtual machine is running in a later service mode (such as servlet ).

-Xcheck: JNI
An additional check is performed when the JNI function is called. In particular, the virtual machine will pass the verification to the JNI function parameter for validity. In the case of illegal data in the local code, the virtual machine will end with a fatal error. Using this parameter will cause performance degradation.

Related Article

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.