DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion
  • Writing DTOs With Java8, Lombok, and Java14+
  • Graph API for Entra ID (Azure AD) Object Management
  • A Comprehensive Guide to IAM in Object Storage

Trending

  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 1
  • Kullback–Leibler Divergence: Theory, Applications, and Implications
  • Building Resilient Networks: Limiting the Risk and Scope of Cyber Attacks
  1. DZone
  2. Coding
  3. Languages
  4. Escape Analysis

Escape Analysis

This overview of Escape Analysis covers the various escape states and how Java's JIT compiler handles them as well as a few words on locking and synchronization.

By 
Grzegorz Mirek user avatar
Grzegorz Mirek
·
Jul. 28, 17 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
13.7K Views

Join the DZone community and get the full member experience.

Join For Free

Escape Analysis (EA) is a very important technique that the just-in-time Java compiler can use to analyze the scope of a new object and decide whether it might not be allocated to Java heap space.

Many resources available on the Internet say that EA allows objects to be allocated on the method stack. While, technically, they could be allocated on the stack, they are not in the current version of Java 8.

The official Java documentation says:

“It does not replace a heap allocation with a stack allocation for non-globally escaping objects.”

Fortunately, Escape Analysis allows the JIT compiler to replace a new object by unpacking its fields onto the stack, effectively performing kind of stack allocation. So, instead of creating every single object on Java heap space, some of them can be “exploded” and the fields kept on the method stack or even in CPU registers instead of Java heap space. This is a very important performance optimization because stack allocation and de-allocation are much faster than heap space allocation. But which objects can be kept like that?

Escape States

There are three escape states objects can be in:

  • NoEscape – when the object cannot be visible outside the current method and thread.
  • ArgEscape – when the object is passed as an argument to a method but cannot otherwise be visible outside the method or by other threads.
  • GlobalEscape – when the object can escape the method or the thread. What that basically means is that objects with the GlobalEscape state will be visible outside methods/threads, for instance, when the object is returned from the method or assigned to a static field.

The optimization mentioned before can be easily applied to objects that have been classified during Escape Analysis as NoEscape.

public String getCarDescription() {
    Car car = new Car();
    String description = car.generateDescription();
    return description;
}


In the snippet above, car is an example of object with NoEscape state – it is not visible nor accessible outside getCarDescription() method.


Locking and Synchronization

Additionally, the JIT compiler can remove some locking and memory synchronization overhead for NoEscape and ArgEscape objects because these objects are only visible from the calling thread. A good example is an old synchronized StringBuffer in which synchronization can be removed if a buffer object is classified as NoEscape or ArgEscape.

Escape Analysis is enabled by default with the server compiler. To disable it, use the -XX:-DoEscapeAnalysis JVM flag.

Object (computer science)

Published at DZone with permission of Grzegorz Mirek, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion
  • Writing DTOs With Java8, Lombok, and Java14+
  • Graph API for Entra ID (Azure AD) Object Management
  • A Comprehensive Guide to IAM in Object Storage

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: