This method doesn't return any value. Exit can be disabled by the SecurityManager class. The System. Return statement is usually used to return a value from a function incase the function returns any value , else it is used to terminate a function if it returns void.
Return would cause a program to exit , if it's present inside the main method of a class. If you add more code after return, the compiler will complain about unreachable code. What happens if we put some code after return? Let's see. Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running.
This class has various methods to interact with the environment in which the Java virtual Machine is Running. Few uses of this class include:. It is the halt method of this Runtime class that we're interested in. When you call the exit method , the Shutdown sequence is started , Shutdown Hooks or Exit finalizers are called. These Hooks are pieces of code to be executed when the JVM is shutting down. The Halt method forcibly terminates the JVM , hence no hooks are called.
In this Java tutorial, we will talk about the ways to terminate a Java Program with example. Normally, we use the return statement in the main method to exit the program. In this post, we will see how we can use the exit method to do the same. The declaration for java.
The status parameter is generally given as 0 for successful termination of the program and -1 or 1 or any other non-zero value for unsuccessful termination.
The VM normally determines the number of available processors from the operating system. This flag can be useful for partitioning CPU resources when running multiple Java processes in docker containers.
This flag is honored even if UseContainerSupport is not enabled. Takes a path to the file system and uses memory mapping to allocate the object heap on the memory device.
Alternative memory devices that have the same semantics as DRAM, including the semantics of atomic operations, can be used instead of DRAM for the object heap without changing the existing application code. All other memory structures such as the code heap, metaspace, and thread stacks continue to reside in DRAM.
Some operating systems expose non-DRAM memory through the file system. Memory-mapped files in these file systems bypass the page cache and provide a direct mapping of virtual memory to the physical memory on the device. The existing heap related flags such as -Xmx and -Xms and garbage-collection related flags continue to work as before. Disables the Compact Strings feature. By default, this option is enabled.
For Java Strings containing at least one multibyte character: these are represented and stored as 2 bytes per character using UTF encoding.
When it's known that an application overwhelmingly will be allocating multibyte character Strings. In the unexpected event where a performance regression is observed in migrating from Java SE 8 to Java SE 9 and an analysis shows that Compact Strings introduces the regression. Specifies the path and file name to which error data is written when an irrecoverable error occurs. If the file exists, and is writeable, then it will be overwritten.
Otherwise, if the file can't be created in the specified directory due to insufficient space, permission problem, or another issue , then the file is created in the temporary directory for the operating system:. Windows: The temporary directory is specified by the value of the TMP environment variable; if that environment variable isn't defined, then the value of the TEMP environment variable is used.
Sets the maximum size in bytes for large pages used for the Java heap. The size argument must be a power of 2 2, 4, 8, 16, and so on.
By default, the size is set to 0, meaning that the JVM chooses the size for large pages automatically. See Large Pages. Sets the maximum total size in bytes of the java. By default, the size is set to 0, meaning that the JVM chooses the size for NIO direct-buffer allocations automatically. Specifies the mode for tracking JVM native memory usage.
Possible mode arguments for this option include the following:. Sets the memory alignment of Java objects in bytes. By default, the value is set to 8 bytes. The specified value should be a power of 2, and must be within the range of 8 and inclusive. This option makes it possible to use compressed pointers with large Java heap sizes. Note: As the alignment value increases, the unused space between objects also increases.
As a result, you may not realize any benefits from using compressed pointers with large Java heap sizes. Sets a custom command or a series of semicolon-separated commands to run when an irrecoverable error occurs. If the string contains spaces, then it must be enclosed in quotation marks.
This example assumes that the path to the userdump. Specifies the text file that contains the names of the classes to store in the class data sharing CDS archive. For example, to specify the classes java. Object and hello. Main , create a text file that contains the following two lines:. The classes that you specify in this text file should include the classes that are commonly used by the application.
They may include any classes from the application, extension, or bootstrap class paths. Starts a JFR recording for the Java application. This option is equivalent to the JFR. Specifies the path and name of the file to which the recording is written when the recording is stopped, for example:.
Specifies whether to collect the path to garbage collection GC roots at the end of a recording. By default, this parameter is disabled. The path to GC roots is useful for finding memory leaks, but collecting it is time-consuming. Enable this option only when you start a recording for an application that you suspect has a memory leak.
If the settings parameter is set to profile , the stack trace from where the potential leaking object was allocated is included in the information collected. Specifies the path and name of the event settings file of type JFC. By default, the default. This default settings file collects a predefined set of information with low overhead, so it has minimal impact on performance and can be used with recordings that run continuously.
A second settings file is also provided, profile. Use this configuration for short periods of time when more information is needed. Sets the Java thread stack size in kilobytes. Disables the use of biased locking. Some applications with significant amounts of uncontended synchronization may attain significant speedups with this flag enabled, but applications with certain patterns of locking may see slowdowns.
Disables the use of compressed pointers. By default, this option is enabled, and compressed pointers are used. This will automatically limit the maximum ergonomically determined Java heap size to the maximum amount of memory that can be covered by compressed pointers. By default this range is 32 GB. With compressed oops enabled, object references are represented as bit offsets instead of bit pointers, which typically increases performance when running the application with Java heap sizes smaller than the compressed oops pointer range.
This option works only for bit JVMs. It's possible to use compressed pointers with Java heap sizes greater than 32 GB. The VM now provides automatic container detection support, which allows the VM to determine the amount of memory and number of processors that are available to a Java process running in docker containers.
It uses this information to allocate system resources. This support is only available on Linux x64 platforms. If supported, the default for this flag is?? This option is disabled by default. This option pre-allocates all large pages up-front, when memory is reserved; consequently the JVM can't dynamically grow or shrink large pages memory areas; see -XX:UseTransparentHugePages if you want this behavior.
Enables the use of large page memory. By default, this option is disabled and large page memory isn't used. Sets the number of lines to prefetch ahead of the instance allocation pointer. By default, the number of lines to prefetch is set to Sets the size in bytes of the prefetch distance for object allocation. Memory about to be written with the value of new objects is prefetched up to this distance starting from the address of the last allocated object.
Each Java thread has its own allocation point. Negative values denote that prefetch distance is chosen based on the platform. Positive values are bytes to prefetch. The default value is set to Sets the prefetch instruction to prefetch ahead of the allocation pointer.
Possible values are from 0 to 3. The actual instructions behind the values depend on the platform. By default, the prefetch instruction is set to Sets the number of cache lines to load after the last object allocation by using the prefetch instructions generated in compiled code. The default value is 1 if the last allocated object was an instance, and 3 if it was an array.
Sets the step size in bytes for sequential prefetch instructions. By default, the step size is set to 16 bytes:. Sets the generated code style for prefetch instructions.
The style argument is an integer from 0 to Sets the number of compiler threads to use for compilation. By default, the number of threads is set to 2 for the server JVM, to 1 for the client JVM, and it scales to the number of cores if tiered compilation is used.
The following example shows how to set the number of threads to Specifies a command to perform on a method. For example, to exclude the indexOf method of the String class from being compiled, use the following:. If the method is specified without the signature, then the command is applied to all methods with the specified name. However, you can also specify the signature of the method in the class file format.
In this case, you should enclose the arguments in quotation marks, because otherwise the shell treats the semicolon as a command end. For example, if you want to exclude only the indexOf String method of the String class from being compiled, use the following:. For example, to exclude all indexOf methods in all classes from being compiled, use the following:. The commas and periods are aliases for spaces, making it easier to pass compiler commands through a shell.
You can pass arguments to -XX:CompileCommand using spaces as separators by enclosing the argument in quotation marks:. Note that after parsing the commands passed on the command line using the -XX:CompileCommand options, the JIT compiler then reads commands from the.
You can add commands to this file or specify a different file using the -XX:CompileCommandFile option. The following commands are available:. Passes a JIT compilation option to the specified method in place of the last argument option. The compilation option is set at the end, after the method name.
For example, to enable the BlockLayoutByFrequency option for the append method of the StringBuffer class, use the following:. Instructs not to print the compile commands. By default, the commands that you specify with the -XX:CompileCommand option are printed; for example, if you exclude from compilation the indexOf method of the String class, then the following is printed to standard output:. Sets the file from which JIT compiler commands are read.
By default, the. Each line in the command file represents a command, a class name, and a method name for which the command is used. For example, this line prints assembly code for the toString method of the String class:.
Adds directives from a file to the directives stack when a program starts. See Compiler Control. Sets the list of methods separated by commas to which compilation should be restricted. Only the specified methods are compiled. Specify each method with the full class name including the packages and subpackages. For example, to compile only the length method of the String class and the size method of the List class, use the following:.
Although wildcards aren't supported, you can specify only the class or package name to compile all methods in that class or package, as well as specify just the method to compile methods with this name in any class:.
Sets the number of interpreted method invocations before compilation. By default, in the server JVM, the JIT compiler performs 10, interpreted method invocations to gather information for efficient compilation.
For the client JVM, the default setting is 1, invocations. This option is ignored when tiered compilation is enabled; see the option -XX:-TieredCompilation. The following example shows how to set the number of interpreted method invocations to 5, You can completely disable interpretation of Java methods before compilation by specifying the -Xcomp option. Sets the initial code cache size in bytes. The default value is set to KB. The initial code cache size shouldn't be less than the system's minimal memory page size.
The following example shows how to set the initial code cache size to 32 KB:. Sets the maximum code size in bytes for compiled methods that should be inlined. Only compiled methods with the size smaller than the specified size is inlined. By default, the maximum code size is set to bytes:. Enables logging of compilation activity to a file named hotspot. You can specify a different log file path and name using the -XX:LogFile option.
By default, this option is disabled and compilation activity isn't logged. Sets the maximum bytecode size in bytes of a method to be inlined. By default, the maximum bytecode size is set to 35 bytes:. Sets the maximum number of nodes to be used during single method compilation. By default, the maximum number of nodes is set to 65, A nonmethod code segment containing nonmethod code, such as compiler buffers and the bytecode interpreter.
This code type stays in the code cache forever. Sets the maximum bytecode size in bytes of a trivial method to be inlined. By default, the maximum bytecode size of a trivial method is set to 6 bytes:. For bit VM on Windows, it's hsdis-amd This lets you to see the generated code, which may help you to diagnose performance issues.
By default, this option is disabled and assembly code isn't printed. Enables verbose diagnostic output from the JVM by printing a message to the console every time a method is compiled. This lets you to see which methods actually get compiled. By default, this option is disabled and diagnostic output isn't printed. By default, this option is disabled and inlining information isn't printed. For example, to enable hardware AES, use the following flags:.
These flags aren't supported on Client VM. Generates Restricted Transactional Memory RTM locking code for all inflated locks, with the normal locking mechanism as the fallback handler. RTM is part of Intel's TSX, which is an x86 instruction set extension and facilitates the creation of multithreaded applications.
If no conflict is found when running the transaction, then the memory and register modifications are committed together at the XEND instruction.
A lock on a transaction is inflated when another thread tries to access the same transaction, thereby blocking the thread that didn't originally request access to the transaction. RTM requires that a fallback set of operations be specified in case a transaction aborts or fails. RTM improves performance for highly contended locks with low conflict in a critical region which is code that must not be accessed by more than one thread concurrently. RTM also improves the performance of coarse-grain locking, which typically doesn't perform well in multithreaded applications.
Coarse-grain locking is the strategy of holding locks for long periods to minimize the overhead of taking and releasing locks, while fine-grained locking is the strategy of trying to achieve maximum parallelism by locking only when necessary and unlocking as soon as possible. Also, for lightly contended locks that are used by different threads, RTM can reduce false cache line sharing, also known as cache line ping-pong. This occurs when multiple threads from different processors are accessing different resources, but the resources share the same cache line.
As a result, the processors repeatedly invalidate the cache lines of other processors, which forces them to read from main memory instead of their cache. This feature is applicable only when using the sun. Sun provider for SHA operations.
To disable only a particular SHA intrinsic, use the appropriate corresponding option. These java options provide the ability to gather system information and perform extensive debugging. Disables the mechanism that lets tools attach to the JVM. By default, this option is disabled, meaning that the attach mechanism is enabled and you can use diagnostics and troubleshooting tools such as jcmd , jstack , jmap , and jinfo.
Sets the path and file name to where log data is written. By default, the file is created in the current working directory, and it's named hotspot. Setting this option is equivalent to running the jmap -histo command, or the jcmd pid GC. Setting this option is equivalent to running the jstack -l command or the jcmd pid Thread. If enabled, saves jstat binary data when the Java application exits. Use the jstat command to display the performance data contained in this file as follows:.
Sets the percentage of time 0 to used to weight the current sample when computing exponential averages for the concurrent collection statistics. Sets the percentage of the old generation occupancy 0 to at which to start a CMS collection cycle.
Any negative value including the default implies that the option -XX:CMSTriggerRatio is used to define the value of the initiating occupancy fraction. Sets the number of threads used for concurrent GC. Sets the size of the regions into which the Java heap is subdivided when using the garbage-first G1 collector. The value is a power of 2 and can range from 1 MB to 32 MB. The default region size is determined ergonomically based on the heap size with a goal of approximately regions.
Sets the percentage of the heap size to use as the maximum for the young generation size. The default value is 60 percent of your Java heap.
This is an experimental flag. Sets the occupancy threshold for an old region to be included in a mixed garbage collection cycle. The default occupancy is 85 percent. Sets the percentage of the heap to use as the minimum for the young generation size. The default value is 5 percent of your Java heap. Sets the percentage of the heap 0 to 50 that's reserved as a false ceiling to reduce the possibility of promotion failure for the G1 collector.
When you increase or decrease the percentage, ensure that you adjust the total Java heap by the same amount.
Controls adaptive calculation of the old generation occupancy to start background work preparing for an old generation collection. Otherwise, the old generation collection process always starts at the old generation occupancy determined by -XX:InitiatingHeapOccupancyPercent. Sets the initial size in bytes of the memory allocation pool.
This value must be either 0, or a multiple of and greater than 1 MB. The default value is selected at run time based on the system configuration. If you set this option to 0, then the initial size is set as the sum of the sizes allocated for the old generation and the young generation. The size of the heap for the young generation can be set using the -XX:NewSize option. Sets the initial amount of memory that the JVM will use for the Java heap before applying ergonomics heuristics as a percentage of the maximum amount determined as described in the -XX:MaxRAM option.
The default value is 1. The following example shows how to set the percentage of the initial amount of memory used for the Java heap:.
If adaptive sizing is disabled using the -XX:-UseAdaptiveSizePolicy option , then the -XX:SurvivorRatio option should be used to set the size of the survivor space for the entire execution of the application. The following formula can be used to calculate the initial size of survivor space S based on the size of the young generation Y , and the initial survivor space ratio R :. The 2 in the equation denotes two survivor spaces.
The larger the value specified as the initial survivor space ratio, the smaller the initial survivor space size. By default, the initial survivor space ratio is set to 8. If the default value for the young generation space size is used 2 MB , then the initial size of the survivor space is 0. Sets the percentage of the old generation occupancy 0 to at which to start the first few concurrent marking cycles for the G1 garbage collector.
A value of 0 implies nonstop concurrent GC cycles from the beginning until G1 adaptively sets this value. Sets a target for the maximum GC pause time in milliseconds. This is a soft goal, and the JVM will make its best effort to achieve it. The specified value doesn't adapt to your heap size.
By default, for G1 the maximum pause time target is milliseconds. The other generational collectors do not use a pause time goal by default.
0コメント