In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is java Escape Analysis". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what java escape analysis is.
What is escape analysis?
Definition of Java Escape Analysis:
Escape analysis (Escape Analysis) is simply a technique in which the Java Hotspot virtual machine can analyze the usage scope of newly created objects and decide whether to allocate memory on the Java heap.
The JVM parameters of escape analysis are as follows:
Turn on escape analysis:-XX:+DoEscapeAnalysis close escape analysis:-XX:-DoEscapeAnalysis display analysis results:-XX:+PrintEscapeAnalysis
Escape analysis technology is supported in Java SE 6u23 + and is enabled by default without adding this parameter.
Escape analysis algorithm
The Java Hotspot compiler implements the escape algorithm described in the following paper:
[Choi99] Jong-Deok Choi, Manish Gupta, Mauricio Seffano,Vugranam C. Sreedhar, Sam Midkiff, "Escape Analysis for Java", Procedings of ACM SIGPLANOOPSLA Conference, November 1, 1999
According to the algorithm described by Jong-Deok Choi, Manish Gupta, Mauricio Seffano,Vugranam C. Sreedhar and Sam Midkiff in the paper "Escape Analysis for Java", the escape analysis is carried out.
In this algorithm, connected graph is introduced, and the reachability relationship between object and object reference is constructed by connected graph. On the basis of this, a combined data flow analysis method is proposed. Because the algorithm is context-sensitive and flow-sensitive, and simulates the nesting relationship of any level of objects, the analysis accuracy is high, but the running time and memory consumption are relatively large.
Object escape state
We learned about the escape analysis techniques in Java, and then we learned about the escape state of the next object.
1. Global Escape (GlobalEscape)
That is, the scope of an object escapes from the current method or thread, and there are several scenarios:
Object is a static variable object is an object that has escaped as the return value of the current method
2. Parameter escape (ArgEscape)
That is, an object is passed as a method parameter or referenced by a parameter, but a global escape does not occur during the call, and this state is determined by the bytecode of the called method.
3. No escape
That is, the object in the method does not escape.
Optimization of escape analysis
For the third point above, when an object does not escape, the following virtual machines can be optimized.
1) Lock elimination
We know that thread synchronization locks are very performance-sacrificing, and when the compiler determines that the current object is only used by the current thread, it removes the synchronization lock for that object. For example, both StringBuffer and Vector decorate thread safety with synchronized, but in most cases they are only used in the current thread, so the compiler optimizes the removal of these locks.
The JVM parameters for lock elimination are as follows:
Open lock elimination:-XX:+EliminateLocks close lock elimination:-XX:-EliminateLocks
Lock elimination is on by default in JDK8, and lock elimination is based on escape analysis.
2) Scalar substitution
First of all, it is important to understand that scalars and aggregate quantities, references to base types and objects can be understood as scalars, and they cannot be further decomposed. The quantity that can be further decomposed is the aggregate quantity, such as the object.
An object is an aggregate quantity, which can be further decomposed into scalars, and its member variables can be decomposed into dispersed variables, which is called scalar substitution.
In this way, if an object does not escape, there is no need to create it at all, only the member scalars it uses will be created on the stack or register, saving memory space and improving application performance.
The JVM parameters replaced by scalars are as follows:
Enable scalar replacement:-XX:+EliminateAllocations turn off scalar replacement:-XX:-EliminateAllocations display scalar replacement details:-XX:+PrintEliminateAllocations
Scalar substitution is also enabled by default in JDK8 and is based on escape analysis.
3) allocation on stack
When the object does not escape, the object can be decomposed into member scalars by scalar substitution and allocated in the stack memory, which is consistent with the life cycle of the method. When the stack frame is destroyed when the stack frame is off the stack, the GC pressure is reduced and the application performance is improved.
At this point, I believe you have a deeper understanding of "what is java escape analysis". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.