Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
article
Open access

Escape analysis for JavaTM: Theory and practice

Published: 01 November 2003 Publication History

Abstract

Escape analysis is a static analysis that determines whether the lifetime of data may exceed its static scope.This paper first presents the design and correctness proof of an escape analysis for JavaTM. This analysis is interprocedural, context sensitive, and as flow-sensitive as the static single assignment form. So, assignments to object fields are analyzed in a flow-insensitive manner. Since Java is an imperative language, the effect of assignments must be precisely determined. This goal is achieved thanks to our technique using two interdependent analyses, one forward, one backward. We introduce a new method to prove the correctness of this analysis, using aliases as an intermediate step. We use integers to represent the escaping parts of values, which leads to a fast and precise analysis.Our implementation [Blanchet 1999], which applies to the whole Java language, is then presented. Escape analysis is applied to stack allocation and synchronization elimination. In our benchmarks, we stack allocate 13% to 95% of data, eliminate more than 20% of synchronizations on most programs (94% and 99% on two examples) and get up to 43% runtime decrease (21% on average). Our detailed experimental study on large programs shows that the improvement comes more from the decrease of the garbage collection and allocation times than from improvements on data locality, contrary to what happened for ML. This comes from the difference in the garbage collectors.

References

[1]
Agesen, O., Detlefs, D., Garthwaite, A., Knippel, R., Ramakrishna, Y. S., and White, D. 1999. An efficient meta-lock for implementing ubiquitous synchronization. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, 207--222.]]
[2]
Aiken, A., Fähndrich, M., and Levien, R. 1995. Better static memory management: Improving region-based analysis of higher-order languages. In SIGPLAN Conference on Programming Language Design and Implementation (PLDI'95, La Jolla, CA). ACM Press, New York, NY, 174--185.]]
[3]
Aldrich, J., Chambers, C., Sirer, E. G., and Eggers, S. 1999. Static analyses for eliminating unnecessary synchronization from Java programs. In Static Analysis Symposium (SAS'99, Venice, Italy). Lecture Notes on Computer Science, vol. 1694. Springer Verlag, Berlin, Germany, 19--38.]]
[4]
Bacon, D. F. 1997. Fast and efficient optimization of statically typed object-oriented languages. Ph.D. thesis. University of California, Berkeley, Berkeley, CA.]]
[5]
Bacon, D. F., Konuru, R., Murthy, C., and Serrano, M. 1998. Thin locks: Featherweight synchronization for Java. In Proceedings of the ACM SIGPLAN'98 Conference on Programming Language Design and Implementation (PLDI'98, Montreal, Canada). ACM Press, New York, NY, 258--268.]]
[6]
Birkedal, L., Tofte, M., and Vejlstrup, M. 1996. From region inference to von Neumann machines via region representation inference. In 23rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'96, St. Petersburg Beach, FL). ACM Press, New York, NY, 171--183.]]
[7]
Blanchet, B. 1998. Escape analysis: Correctness proof, implementation and experimental results. In 25th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL'98, San Diego, CA). ACM Press, New York, NY, 25--37.]]
[8]
Blanchet, B. 1999. Escape analysis for object oriented languages. Application to JavaTM. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, NY, 20--34.]]
[9]
Blanchet, B. 2000. Escape analysis. Applications to ML and JavaTM. Ph.D. thesis, École Polytechnique.]]
[10]
Bogda, J. and Hölzle, U. 1999. Removing unnecessary synchronization in Java. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, NY, 35--46.]]
[11]
Carr, S., McKinley, K. S., and Tseng, C.-W. 1994. Compiler optimizations for improving data locality. In 6th International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS'94). ACM Press, New York, NY, 252--262.]]
[12]
Chase, D. R. 1988. Safety considerations for storage allocation optimizations. In Proceedings of the SIGPLAN'88 Conference on Programming Language Design and Implementation (PLDI'88, Atlanta, GA). ACM Press, New York, NY, 1--10.]]
[13]
Choi, J.-D., Gupta, M., Serrano, M., Sreedhar, V. C., and Midkiff, S. 1999. Escape analysis for Java. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, NY, 1--19.]]
[14]
Cousot, P. and Cousot, R. 1977. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Conference Record of the 4th Annual ACM Symposium on Principles of Programming Languages (Los Angeles, CA.). ACM Press, New York, NY, 238--252.]]
[15]
Cousot, P. and Cousot, R. 1979. Systematic design of program analysis frameworks. In Conference Record of the 6th Annual ACM Symposium on Principles of Programming Languages (San Antonio, TX). ACM Press, New York, NY, 269--282.]]
[16]
Cytron, R., Ferrante, J., Rosen, B. K., Wegman, M. N., and Zadeck, F. K. 1991. Efficiently computing static single assignment form and the control dependance graph. ACM Trans. Program. Lang. Syst. 13, 4 (Oct.), 451--490.]]
[17]
Dean, J., Grove, D., and Chambers, C. 1995. Optimization of object-oriented programs using static class hierarchy analysis. In Proceedings of the 9th European Conference on Object-Oriented Programming. Lecture Notes on Computer Science, vol. 952. Springer Verlag, Berlin, Germany, 77--101.]]
[18]
Deutsch, A. 1990. On determining lifetime and aliasing of dynamically allocated data in higher-order functional specifications. In 17th Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages. (San Francisco, CA). ACM Press, New York, NY, 157--168.]]
[19]
Deutsch, A. 1994. Interprocedural may-alias analysis for pointers: Beyond k-limiting. In Proceedings of the SIGPLAN'94 Conference on Programming Language Design and Implementation (PLDI'94, Orlando, FL). ACM Press, New York, NY, 230--241.]]
[20]
Deutsch, A. 1997. On the complexity of escape analysis. In 24th Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL'97, Paris, France). ACM Press, New York, NY, 358--371.]]
[21]
Diniz, P. C. and Rinard, M. C. 1998. Lock coarsening: Eliminating lock overhead in automatically parallelized object-based programs. J. Parallel Distrib. Comput. 49, 2 (Mar.), 218--244.]]
[22]
Fitzgerald, R., Knoblock, T. B., Ruf, E., Steensgaard, B., and Tarditi, D. 2000. Marmot: An optimizing compiler for Java. Softw. Pract. Exper. 30, 3 (Mar.), 199--232.]]
[23]
Gay, D. and Steensgaard, B. 2000. Fast escape analysis and stack allocation for object-based programs. In Compiler Construction, 9th International Conference, CC'2000, D. A. Watt, Ed. Lecture Notes on Computer Science, vol. 1781. Springer Verlag, Berlin, Germany, 82--93.]]
[24]
Harrison, W. 1989. The interprocedural analysis and automatic parallelisation of Scheme programs. J. Lisp Symb. Comput. 2, 176--396.]]
[25]
Hederman, L. 1988. Compile time garbage collection using reference count analysis. Tech. rep. Rice COMP TR88-75, Rice University, Houston, TX.]]
[26]
Horwitz, S., Demers, A., and Teitelbaum, T. 1987. An efficient general iterative algorithm for dataflow analysis. Acta Inf. 24, 6, 679--694.]]
[27]
Hudak, P. 1986. A semantic model of reference counting and its abstraction (detailed summary). In Proceedings of the 1986 ACM Conference on LISP and Functional Programming (Cambridge, MA). ACM Press, New York, NY, 351--363.]]
[28]
Hughes, S. 1992. Compile-time garbage collection for higher-order functional languages. J. Logic Comput. 2, 4, 483--509.]]
[29]
Inoue, K., Seki, H., and Yagi, H. 1988. Analysis of functional programs to detect run-time garbage cells. ACM Trans. Program. Lang. Syst. 10, 4 (Oct.), 555--578.]]
[30]
Jones, N. D. and Muchnick, S. 1982. A flexible approach to interprocedural data flow analysis and programs with recursive data structures. In 9th Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (Albuquerque, NM). ACM Press, New York, NY, 66--74.]]
[31]
McDowell, C. E. 1998. Reducing garbage in Java. ACM Sigplan Not. 33, 9 (Sept.), 84--86.]]
[32]
Mohnen, M. 1995a. Efficient closure utilisation by higher-order inheritance analysis. In Static Analysis Symposium (SAS'95). Lecture Notes on Computer Science, vol. 983. Springer Verlag, Berlin, Germany, 261--278.]]
[33]
Mohnen, M. 1995b. Efficient compile-time garbage collection for arbitrary data structure. In Symposium on Programming Language Implementation and Logic Programming (PLILP'95). Lecture Notes on Computer Science, vol. 982. Springer Verlag, Berlin, Germany, 241--258.]]
[34]
Muller, G., Moura, B., Bellard, F., and Consel, C. 1997. Harissa: A flexible and efficient Java environment mixing bytecode and compiled code. In 3rd Usenix Conference on Object-Oriented Technologies and Systems (COOTS'97). Portland, OR, 1--20.]]
[35]
Onodera, T. and Kawachiya, K. 1999. A study of locking objects with bimodal fields. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, NY, 223--237.]]
[36]
Park, Y. G. and Goldberg, B. 1992. Escape analysis on lists. In Proceedings of the ACM SIGPLAN'92 Conference on Programming Language Design and Implementation (PLDI'92, San Francisco, CA). ACM Press, New York, NY, 116--127.]]
[37]
Qian, Z. 1998. A formal specification of JavaTM virtual machine instructions for objects, methods and subroutines. In Formal Syntax and Semantics of Java(tm), J. Alves-Foss, Ed. Lecture Notes on Computer Science, vol. 1523. Springer Verlag, Berlin, Germany.]]
[38]
Ruf, E. 2000. Effective synchronization removal for Java. In ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation (PLDI'00, Vancouver, Canada). ACM Press, New York, NY, 208--218.]]
[39]
Ruggieri, C. and Murtagh, T. P. 1988. Lifetime analysis of dynamically allocated objects. In Proceedings of the 15th Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL'88, San Diego, CA). ACM Press, New York, NY, 285--293.]]
[40]
Serrano, M. and Feeley, M. 1996. Storage use analysis and its applications. In 1996 ACM SIGPLAN International Conference on Functional Programming (ICFP, Philadelphia, PA). ACM Press, New York, NY, 50--61.]]
[41]
Shivers, O. 1988. Control flow analysis in Scheme. In Proceedings of the SIGPLAN'88 Conference on Programming Language Design and Implementation (PLDI'88, Atlanta, GA). ACM Press, New York, NY, 164--174.]]
[42]
Tofte, M. and Talpin, J.-P. 1993. A theory of stack allocation in polymorphically typed languages. Tech. rep. 93/15, Departement of Computer Science, Copenhagen University, Copenhagen, Denmark.]]
[43]
Weiss, M. et al. 1998. TurboJ: A Java bytecode-to-native compiler. In Proceedings of Workshop on Languages, Compilers and Tools for Embedded Systems. Lecture Notes on Computer Science, vol. 1474. Springer Verlag, Berlin, Germany, 119--130.]]
[44]
Whaley, J. and Rinard, M. 1999. Compositional pointer and escape analysis for Java programs. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA'99, Denver, CO). ACM Press, New York, NY, 187--206.]]

Cited By

View all
  • (2024)Optimistic Stack Allocation and Dynamic Heapification for Managed RuntimesProceedings of the ACM on Programming Languages10.1145/36563898:PLDI(296-319)Online publication date: 20-Jun-2024
  • (2024)CodePlan: Repository-Level Coding using LLMs and PlanningProceedings of the ACM on Software Engineering10.1145/36437571:FSE(675-698)Online publication date: 12-Jul-2024
  • (2024)Partial program analysis for staged compilation systemsFormal Methods in System Design10.1007/s10703-024-00458-xOnline publication date: 13-Jun-2024
  • Show More Cited By

Recommendations

Reviews

Michael Zastre

Escape analysis is becoming increasingly important for those interested in constructing compilers for the Java programming language. An object is said to escape a subsystem when that object can be accessed from outside of the system; the analysis is actually an extension of traditional aliasing analysis. If we know that an object does not escape a subsystem, then we can use that information to optimize away some of the expense of using the object (namely, eliminate some locking/unlocking operations on the object, hence reducing runtime overhead). This paper on escape analysis is organized into three broad parts. The first part includes sections 1, 2, and 3, and describes the benefits obtained from escape analysis in Java, such as stack allocation and synchronization elimination. Also included in this part of the paper is a review of previous work in the area. Sections 4 through 7 make up the middle part of the paper, which is the most difficult to understand. Readers unfamiliar with abstract interpretation may wish to have a copy of Abstract interpretation of declarative languages [1] handy when reading it. Of particular interest here is a description of a less precise, but fast, escape analysis that approximates access paths by type height. This is where abstract interpretation comes into play, in that one kind of value (a list of fields, array indexes, and so on, used to obtain a value) is approximated by another, simpler kind of value (for example, we can infer relations between paths by their lengths, with lengths represented as integers). Sections 8 through 12 comprise the final part of the paper, and focus on an actual implementation of the analyses and optimizations. Papers applying abstract interpretation to imperative languages are relatively rare, and this paper has even greater relevance for compiler writers, given its description of an actual implementation. The paper is definitely not an easy read, but should be required reading for all those interested in applying static analyses to Java. Online Computing Reviews Service

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 25, Issue 6
November 2003
198 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/945885
Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 01 November 2003
Published in TOPLAS Volume 25, Issue 6

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Java
  2. optimization
  3. stack allocation
  4. static analysis
  5. synchronization elimination

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)154
  • Downloads (Last 6 weeks)43
Reflects downloads up to 04 Oct 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Optimistic Stack Allocation and Dynamic Heapification for Managed RuntimesProceedings of the ACM on Programming Languages10.1145/36563898:PLDI(296-319)Online publication date: 20-Jun-2024
  • (2024)CodePlan: Repository-Level Coding using LLMs and PlanningProceedings of the ACM on Software Engineering10.1145/36437571:FSE(675-698)Online publication date: 12-Jul-2024
  • (2024)Partial program analysis for staged compilation systemsFormal Methods in System Design10.1007/s10703-024-00458-xOnline publication date: 13-Jun-2024
  • (2022)Inlining-Benefit Prediction with Interprocedural Partial Escape AnalysisProceedings of the 14th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages10.1145/3563838.3567677(13-24)Online publication date: 29-Nov-2022
  • (2022)Principles of Staged Static+Dynamic Partial AnalysisStatic Analysis10.1007/978-3-031-22308-2_4(44-73)Online publication date: 5-Dec-2022
  • (2022)Programming Transactional MemoryTransactional Memory10.1007/978-3-031-01719-3_2(15-52)Online publication date: 17-Oct-2022
  • (2020)How (not) to write Java pointer analyses after 2020Proceedings of the 2020 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3426428.3426923(134-145)Online publication date: 18-Nov-2020
  • (2020)Escape from escape analysis of GolangProceedings of the ACM/IEEE 42nd International Conference on Software Engineering: Software Engineering in Practice10.1145/3377813.3381368(142-151)Online publication date: 27-Jun-2020
  • (2020)Design and Implementation of an Escape Analysis in the Context of Safety-Critical Embedded SystemsACM Transactions on Embedded Computing Systems10.1145/337213319:1(1-20)Online publication date: 6-Feb-2020
  • (2019)PYEACM Transactions on Programming Languages and Systems10.1145/333779441:3(1-37)Online publication date: 2-Jul-2019
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media