• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. HotSpot
  4. EscapeAnalysis

Page History

Versions Compared

Old Version 2

changes.mady.by.user J. Duke

Saved on May 15, 2009

compared with

New Version 3

changes.mady.by.user J. Duke

Saved on Oct 07, 2010

  • Previous Change: Difference between versions 1 and 2
  • Next Change: Difference between versions 3 and 4
  • View Page History

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

After escape analysis C2 eliminates scalar replaceable object allocations and associated locks. C2 also eliminates locks for all non globally escaping objects. C2 does NOT replace a heap allocation with a stack allocation for non globally escaping objects.

Some scenarios for escape analysis are described next.

  • The server compiler might eliminate certain object allocations. Consider the example where a method makes a defensive copy of an object and returns the copy to the caller.
No Format

      public class Person {
        private String name;
        private int age;
        public Person(String personName, int personAge) {
          name = personName;
                      age = personAge;
        }
              
        public Person(Person p) { this(p.getName(), p.getAge()); }
        public int getName() { return name; }
        public int getAge() { return age; }
      }

      public class Employee {
        private Person person;
        
              // makes a defensive copy to protect against modifications by caller
              public Person getPerson() { return new Person(person) };
              
              public void printEmployeeDetail(Employee emp) {
                Person person = emp.getPerson();
                // this caller does not modify the object, so defensive copy was unnecessary
                      System.out.println ("Employee's name: " + person.getName() + "; age: "  + person.getAge());     
              }
      }       

The method makes a copy to prevent modification of the original object by the caller. If the compiler determines that the getPerson method is being invoked in a loop, it will inline that method. In addition, through escape analysis, if the compiler determines that the original object is never modified, it might optimize and eliminate the call to make a copy.

  • The server compiler might eliminate synchronization blocks (lock elision) if it determines that an object is thread local. For example, methods of classes such as StringBuffer and Vector are synchronized because they can be accessed by different threads. However, in most scenarios, they are used in a thread local manner. In cases where the usage is thread local, the compiler might optimize and remove the synchronization blocks.
Overview
Content Tools
ThemeBuilder

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 311, "requestCorrelationId": "5377a756664c1a21"}