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.
- abc. The AspectBench Compiler. Home page with downloads, FAQ, documentation, support mailing lists, and bug database. http://aspectbench.org.Google Scholar
- 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 Scholar
Digital Library
- Ole Agesen. Concrete Type Inference: Delivering Object-Oriented Applications. PhD thesis, Stanford University, 1996. Sun Microsystems, Technical report TR-96-52. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Eric Bodden. A denial-of-service attack on the java bytecode verifier. http://www.bodden.de/research/javados/, 2008.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification Second Edition. Addison-Wesley, 2000. Google Scholar
Digital Library
- Justin Owen Graver. Type-Checking and Type Inference for Object-Oriented Programming Languages. PhD thesis, University of Illinois at Urbana-Champaign, 1989.Google Scholar
- 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 Scholar
Digital Library
- Andreas V. Hense. Polymorphic Type Inference for Object-Oriented Programming Languages. PhD thesis, Universität des Saarlandes, 1994.Google Scholar
- Eric J. Holstege. Type Inference in a Declarationless, Object-Oriented Language. PhD thesis, California Institute of Technology, 1982. Technical report 5035.Google Scholar
- Bronisłav Knaster. Un théorème sur les fonctions d'ensembles. Annales de la Societé Polonaise de Mathematique, 6:133--134, 1928.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Jens Palsberg. Efficient inference of object types. Information and Computation, 123(2):198--209, 1995. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Michael B. Smyth. Power domains. Journal of Computer and System Sciences, 16:23--96, 1978.Google Scholar
Cross Ref
- Steven Alexander Spoon. Demand-driven type inference with subgoal pruning. PhD thesis, Georgia Institute of Technology, 2005.Google Scholar
Digital Library
- Norihisa Suzuki. Inferring types in smalltalk. In Symposium on Principles of Programming Languages, pages 187--199. ACM Press, 1981. Google Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Efficient local type inference
Recommendations
Efficient local type inference
OOPSLA '08: Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applicationsInference 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 ...
Kinded type inference for parameteric overloading
AbstractParameteric overloading refers to the combination of parameteric polymorphism and overloading of polymorphic operators. The formal basis for parametric overloading, proposed by Kaes and extended by Wadler and Blott, is based on type predicates. In ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...









Comments