Usage:
This flag allows you to perform escape analysis.
Since:
Starting from JDK 6.
Examples:
This will instruct JVM to disable performing escape analysis:
-XX:-DoEscapeAnalysis
Description:
Escape analysis is a technique by which the Java Hotspot Server Compiler can analyze the scope of a new object's uses and decide whether to allocate it on the Java heap. The are three types of escape states which objects can be in:
- GlobalEscape - The object is accessible from other threads and from other methods, for instance, when the object is returned from the method or assigned to a static field.
- ArgEscape - An object was passed as an argument, or is referenced from the argument object, but does not itself escape the scope of the stream in which it was created.
- NoEscape - the object does not leave the scope of the method and its creation can be pushed onto the stack.
The option “DoEscapeAnalysis” enables you the use of escape analysis. To disable the use of escape analysis, specify “-XX:-DoEscapeAnalysis“.
Let us look at the following code snippet:
public class Java {
private String version;
public String getVersion() {
String ver = “v”;
return ver.concat(this.version);
}
}
The variables “version” and “ver” are examples of objects with the state “NoEscape”.
Moreover, the JIT compiler can decide to remove memory synchronization and locking for the two states “ArgEscape” and “NoEscape” objects for the simple reason that these objects are hidden and only visible from the calling thread. An ideal example, is the old synchronized “StringBuffer” in which case the synchronization can be disposed of if a buffer object is classified as “ArgEscape” or “NoEscape”.
Default Value:
By default, the flag is enabled.
Errors:
An exception is thrown if the flag is not supported.
Related Posts:
Note:
Only the Java HotSpot Server VM supports this option.
Edit your Comment