skip to main content
research-article

Efficient local type inference

Published:19 October 2008Publication History
Skip Abstract Section

Abstract

Inference of static types for local variables in Java bytecode is the first step of any serious tool that manipulates bytecode, be it for decompilation, transformation or analysis. It is important, therefore, to perform that step as accurately and efficiently as possible. Previous work has sought to give solutions with good worst-case complexity.

We present a novel algorithm, which is optimised for the common case rather than worst-case performance. It works by first finding a set of minimal typings that are valid for all assignments, and then checking whether these minimal typings satisfy all uses. Unlike previous algorithms, it does not explicitly build a data structure of type constraints, and it is easy to implement efficiently. We prove that the algorithm produces a typing that is both sound (obeying the rules of the language) and as tight as possible.

We then go on to present extensive experiments, comparing the results of the new algorithm against the previously best known method. The experiments include bytecode that is generated in other ways than compilation of Java source. The new algorithm is always faster, typically by a factor 6, but on some real benchmarks the gain is as high as a factor of 92. Furthermore, whereas that previous method is sometimes suboptimal, our algorithm always returns a tightest possible type.

We also discuss in detail how we handle primitive types, which is a difficult issue due to the discrepancy in their treatment between Java bytecode and Java source. For the application to decompilation, however, it is very important to handle this correctly.

References

  1. abc. The AspectBench Compiler. Home page with downloads, FAQ, documentation, support mailing lists, and bug database. http://aspectbench.org.Google ScholarGoogle Scholar
  2. Ole Agesen. The Cartesian Product Algorithm: Simple and precise type inference of parametric polymorphism. In Walter G. Olthoff, editor, European Conference on Object-Oriented Programming (ECOOP), volume 952 of Lecture Notes in Computer Science, pages 2--26. Springer, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Ole Agesen. Concrete Type Inference: Delivering Object-Oriented Applications. PhD thesis, Stanford University, 1996. Sun Microsystems, Technical report TR-96-52. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Ole Agesen, Jens Palsberg, and Michael I. Schwartzbach. Type inference of SELF: Analysis of objects with dynamic and multiple inheritance. Software Practice and Experience, 25(9):975--995, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Ben Bellamy, Pavel Avgustinov, Oege de Moor, and Damien Sereni. Implementation of our local type inference algorithm (including experiments). http://musketeer.comlab.ox.ac.uk/typeinference/, 2008.Google ScholarGoogle Scholar
  6. Eric Bodden. A denial-of-service attack on the java bytecode verifier. http://www.bodden.de/research/javados/, 2008.Google ScholarGoogle Scholar
  7. Alan Donovan, Adam Kiezun, Matthew S. Tschantz, and Michael D. Ernst. Converting java programs to use generic libraries. In Object-Oriented Programming, Systems and Languages, pages 15--34, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Etienne Gagnon, Laurie J. Hendren, and Guillaume Marceau. Efficient inference of static types for Java bytecode. In Static Analysis Symposium, volume 1824 of Lecture Notes in Computer Science, pages 199--219, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification Second Edition. Addison-Wesley, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Justin Owen Graver. Type-Checking and Type Inference for Object-Oriented Programming Languages. PhD thesis, University of Illinois at Urbana-Champaign, 1989.Google ScholarGoogle Scholar
  11. Justin Owen Graver and Ralph E. Johnson. A type system for Smalltalk. In Symposium on Principles of Programming Languages (POPL), pages 136--150. ACM Press, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Andreas V. Hense. Polymorphic Type Inference for Object-Oriented Programming Languages. PhD thesis, Universität des Saarlandes, 1994.Google ScholarGoogle Scholar
  13. Eric J. Holstege. Type Inference in a Declarationless, Object-Oriented Language. PhD thesis, California Institute of Technology, 1982. Technical report 5035.Google ScholarGoogle Scholar
  14. Bronisłav Knaster. Un théorème sur les fonctions d'ensembles. Annales de la Societé Polonaise de Mathematique, 6:133--134, 1928.Google ScholarGoogle Scholar
  15. Todd B. Knoblock and Jakob Rehof. Type elaboration and subtype completion for java bytecode. ACM Transactions on Programming Languages and Systems (TOPLAS), 23(2):243--272, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Dexter Kozen, Jens Palsberg, and Michael I. Schwartzbach. Efficient inference of partial types. Journal of Computer and System Sciences, 49(2):306--324, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Miecnikowski and L. J. Hendren. Decompiling java bytecode: problems, traps and pitfalls. In R. N. Horspool, editor, Compiler Construction, volume 2304 of Lecture Notes in Computer Science, pages 111--127. Springer Verlag, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Nicholas Oxhøj, Jens Palsberg, and Michael I. Schwartzbach. Making type inference practical. In Ole Lehrmann Madsen, editor, European Conference on Object-Oriented Programming (ECOOP), volume 615 of Lecture Notes in Computer Science, pages 329--349, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Jens Palsberg. Efficient inference of object types. Information and Computation, 123(2):198--209, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Jens Palsberg and Michael I. Schwartzbach. Object-oriented type inference. In Andreas Paepcke, editor, Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA), pages 146--161. ACM Press, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. John Plevyak and Andrew A. Chien. Precise concrete type inference for object-oriented languages. In Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), pages 324--340. ACM Press, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Todd A. Proebsting and Scott A. Watterson. Krakatoa: Decompilation in java (does bytecode reveal source?). In Conference on Object-Oriented Technologies (COOTS), pages 185--198, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Michael B. Smyth. Power domains. Journal of Computer and System Sciences, 16:23--96, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  24. Steven Alexander Spoon. Demand-driven type inference with subgoal pruning. PhD thesis, Georgia Institute of Technology, 2005.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Norihisa Suzuki. Inferring types in smalltalk. In Symposium on Principles of Programming Languages, pages 187--199. ACM Press, 1981. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Raja Vallée-Rai, Etienne Gagnon, Laurie J. Hendren, Patrick Lam, Patrice Pominville, and Vijay Sundaresan. Optimizing Java bytecode using the Soot framework: Is it feasible? In Compiler Construction, 9th International Conference (CC 2000), pages 18--34, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Efficient local type inference

    Recommendations

    Reviews

    William M. Waite

    A Java class file contains no explicit type information about local variables; those properties must be obtained by analyzing the method body. The authors develop an efficient algorithm for this analysis, and prove that its result delivers the strictest possible type for each variable. Its measured performance improvement over previous algorithms is typically a factor of six, but has reached a high of 92 on some real benchmarks. Before the algorithm begins, the structure of the method body must be determined and the dependencies among the local variables extracted. All local variables are assumed to have an unknown type, and a worklist is built containing all of the assignments to local variables. Then, the algorithm repeatedly removes one assignment, checking whether the type of value delivered by the expression is a subtype of the current variable type. If not, the type of the variable is updated, and any assignments depending on that variable are added to the worklist if they aren't already there. When the worklist is exhausted, the variable types are checked against all uses. The description of the algorithm is clear and precise, and the experiment is convincing. It is obviously useful in a variety of scenarios involving class file analysis. I also recommend the paper to anyone with an interest in type inference in object-oriented languages. Online Computing Reviews Service

    Access critical reviews of Computing literature here

    Become a reviewer for Computing Reviews.

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 43, Issue 10
      September 2008
      613 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1449955
      Issue’s Table of Contents
      • cover image ACM Conferences
        OOPSLA '08: Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applications
        October 2008
        654 pages
        ISBN:9781605582153
        DOI:10.1145/1449764

      Copyright © 2008 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 19 October 2008

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!