Abstract

Parametric polymorphism enables code reuse and type safety. Underneath the uniform interface exposed to programmers, however, its low level implementation has to cope with inherently non-uniform data: value types of different sizes and semantics (bytes, integers, floating point numbers) and reference types (pointers to heap objects). On the Java Virtual Machine, parametric polymorphism is currently translated to bytecode using two competing approaches: homogeneous and heterogeneous. Homogeneous translation requires boxing, and thus introduces indirect access delays. Heterogeneous translation duplicates and adapts code for each value type individually, producing more bytecode. Therefore bytecode speed and size are at odds with each other. This paper proposes a novel translation that significantly reduces the bytecode size without affecting the execution speed. The key insight is that larger value types (such as integers) can hold smaller ones (such as bytes) thus reducing the duplication necessary in heterogeneous translations. In our implementation, on the Scala compiler, we encode all primitive value types in long integers. The resulting bytecode approaches the performance of monomorphic code, matches the performance of the heterogeneous translation and obtains speedups of up to 22x over the homogeneous translation, all with modest increases in size.
- Ceylon Programming Language. URL http://ceylon-lang.org/.Google Scholar
- Kotlin Programming Language. URL http://kotlin.jetbrains.org/.Google Scholar
- Scala Programming Language. URL http://scala-lang.org/.Google Scholar
- X10 Programming Language. URL http://x10-lang.org/.Google Scholar
- ECMA International, Standard ECMA-335: Common Language Infrastructure, June 2006.Google Scholar
- O. Agesen, S. N. Freund, and J. C. Mitchell. Adding Type Parameterization to the Java Language. In ACM SIGPLAN Notices, volume 32. ACM, 1997. Google Scholar
Digital Library
- E. Allen, J. Bannet, and R. Cartwright. A First-Class Approach to Genericity. In ACM SIGPLAN Notices, volume 38. ACM, 2003. Google Scholar
Digital Library
- J. A. Bank, A. C. Myers, and B. Liskov. Parameterized Types for Java. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). ACM, 1997. Google Scholar
Digital Library
- L. Bourdev and J. Järvi. Efficient Run-Time Dispatching in Generic Programming with Minimal Code Bloat. Sci. Comput. Program., 76(4), Apr. 2011. ISSN 0167-6423. Google Scholar
Digital Library
- G. Bracha, M. Odersky, D. Stoutamire, and P. Wadler. Making the future safe for the past: Adding Genericity to the Java Programming Language. SIGPLAN Notices, 33(10), Oct. 1998. ISSN 0362-1340. Google Scholar
Digital Library
- A. Buckley. JSR 202: Java Class File Specification Update, 2006. URL http://www.jcp.org/en/jsr/detail?id=202.Google Scholar
- R. Cartwright and G. L. Steele Jr. Compatible Genericity with Run-time Types for the Java Programming Language. In ACM SIGPLAN Notices, volume 33. ACM, 1998. Google Scholar
Digital Library
- I. Dragos. Compiling Scala for Performance. PhD thesis, École Polytechnique Fédérale de Lausanne, 2010.Google Scholar
- A. Gal, B. Eich, M. Shaver, D. Anderson, D. Mandelin, M. R. Haghighat, B. Kaplan, G. Hoare, B. Zbarsky, J. Orendorff, et al. Trace-based Just-in-Time Type Specialization for Dynamic Languages. In ACM SIGPLAN Notices, volume 44. ACM, 2009. Google Scholar
Digital Library
- A. Georges, D. Buytaert, and L. Eeckhout. Statistically Rigorous Java Performance Evaluation. In Proceedings of the 22nd annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications, OOPSLA '07, 2007. Google Scholar
Digital Library
- R. Harper and G. Morrisett. Compiling Polymorphism Using Intensional Type Analysis. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 1995. Google Scholar
Digital Library
- R. Ierusalimschy, L. H. De Figueiredo, and W. Celes. The Implementation of Lua 5.0. Journal of Universal Computer Science, 11(7), 2005.Google Scholar
- Intel. Intel (R) 64 and IA-32 Architectures Software Developer's Manual. URL http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html.Google Scholar
- S. L. P. Jones and J. Launchbury. Unboxed Values as First Class Citizens in a Non-Strict Functional Language. In Functional Programming Languages and Computer Architecture. Springer, 1991. Google Scholar
Digital Library
- A. Kennedy and D. Syme. Design and Implementation of Generics for the .NET Common Language Runtime. In Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and implementation, PLDI '01, Snowbird, Utah, United States, 2001. Google Scholar
Digital Library
- T. Kotzmann, C. Wimmer, H. Mössenböck, T. Rodriguez, K. Russell, and D. Cox. Design of the Java HotSpot Client Compiler for Java 6. ACM Transactions on Architecture and Code Optimization (TACO), 5 (1), 2008. Google Scholar
Digital Library
- X. Leroy. Unboxed Objects and Polymorphic Typing. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 1992. Google Scholar
Digital Library
- T. Lindholm and F. Yellin. Java Virtual Machine Specification. Addison-Wesley Longman Publishing Co., Inc., 1999. Google Scholar
Digital Library
- V. Mikheev, N. Lipsky, D. Gurchenkov, P. Pavlov, V. Sukharev, A. Markov, S. Kuksenko, S. Fedoseev, D. Leskov, and A. Yeryomin. Overview of Excelsior JET, a High Performance Alternative to Java Virtual Machines. In Proceedings of the 3rd International Workshop on Software and Performance (WOSP). ACM, 2002. Google Scholar
Digital Library
- Y. Minamide. Full Lifting of Type Parameters. In Proceedings of Second Fuji International Workshop on Functional and Logic Programming, 1997.Google Scholar
- A. Moors. Type Constructor Polymorphism for Scala: Theory and Practice. PhD thesis, PhD thesis, Katholieke Universiteit Leuven, 2009.Google Scholar
- R. Morrison, A. Dearle, R. C. H. Connor, and A. L. Brown. An Ad Hoc Approach to the Implementation of Polymorphism. ACM Transactions on Programming Languages and Systems (TOPLAS), 13(3), 1991. Google Scholar
Digital Library
- M. Odersky and M. Zenger. Scalable Component Abstractions. In ACM SIGPLAN Notices, volume 40. ACM, 2005. Google Scholar
Digital Library
- M. Odersky, E. Runne, and P. Wadler. Two Ways to Bake Your Pizza-Translating Parameterised Types into Java. Springer, 2000.Google Scholar
Cross Ref
- Oracle. OpenJDK: Graal project. URL http://openjdk.java.net/projects/graal/.Google Scholar
- E. Osheim. Generic Numeric Programming Through Specialized Type Classes. ScalaDays, 2012.Google Scholar
- M. Paleczny, C. Vick, and C. Click. The Java HotSpot Server Compiler. In Proceedings of the 2001 Symposium on Java Virtual Machine Research and Technology Symposium-Volume 1. USENIX Association, 2001. Google Scholar
Digital Library
- A. Prokopec. ScalaMeter. URL http://axel22.github.com/scalameter/.Google Scholar
- A. Prokopec, P. Bagwell, T. Rompf, and M. Odersky. A Generic Parallel Collection Framework. In Euro-Par 2011 Parallel Processing. Springer, 2011. Google Scholar
Digital Library
- O. Sallenave and R. Ducournau. Lightweight Generics in Embedded Systems Through Static Analysis. SIGPLAN Notices, 47(5), June 2012. Google Scholar
Digital Library
- J. Sasitorn and R. Cartwright. Efficient First-Class Generics on Stock JavaVirtual Machines. In Proceedings of the 2006 ACM symposium on Applied computing. ACM, 2006. Google Scholar
Digital Library
- M. Schinz. Compiling Scala for the Java Virtual Machine. PhD thesis, École Polytechnique Fédérale de Lausanne, 2005.Google Scholar
- B. Stroustrup. The C++ Programming Language, Third Edition. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 3rd edition, 1997. Google Scholar
Digital Library
- N. Stucki and V. Ureche. Bridging islands of specialized code using macros and reified types. In Proceedings of the 4th Workshop on Scala, SCALA '13, 2013. Google Scholar
Digital Library
- M. Takeuchi, S. Zakirov, K. Kawachiya, and T. Onodera. Fast Method Dispatch and Effective Use of Primitives for Reified Generics in Managed X10. In Proceedings of the 2012 ACM SIGPLAN X10 Workshop. ACM, 2012. Google Scholar
Digital Library
- D. Tarditi, G. Morrisett, P. Cheng, C. Stone, R. Harper, and P. Lee. TIL: A Type-Directed Optimizing Compiler for ML. In Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, 1996. Google Scholar
Digital Library
- A. Tolmach. Tag-Free Garbage Collection Using Explicit Type Parameters. In ACM SIGPLAN Lisp Pointers, volume 7. ACM, 1994. Google Scholar
Digital Library
- M. Viroli and A. Natali. Parametric Polymorphism in Java: An Approach to Translation Based on Reflective Features. In ACMSIGPLAN Notices, volume 35. ACM, 2000. Google Scholar
Digital Library
- S. Wholey and S. E. Fahlman. The Design of an Instruction Set for Common Lisp. In Proceedings of the 1984 ACM Symposium on LISP and Functional Programming, LFP '84, 1984. Google Scholar
Digital Library
- T. Würthinger, A. Wöß, L. Stadler, G. Duboscq, D. Simon, and C. Wimmer. Self-Optimizing AST interpreters. In Proceedings of the 8th Symposium on Dynamic Languages. ACM, 2012. Google Scholar
Digital Library
Index Terms
Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations
Recommendations
Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations
OOPSLA '13: Proceedings of the 2013 ACM SIGPLAN international conference on Object oriented programming systems languages & applicationsParametric polymorphism enables code reuse and type safety. Underneath the uniform interface exposed to programmers, however, its low level implementation has to cope with inherently non-uniform data: value types of different sizes and semantics (bytes, ...
Bridging islands of specialized code using macros and reified types
SCALA '13: Proceedings of the 4th Workshop on ScalaParametric polymorphism in Scala suffers from the usual drawback of erasure on the Java Virtual Machine: primitive values are boxed, leading to indirect access, wasteful use of heap memory and lack of cache locality. For performance-critical parts of ...
Improving the Interoperation between Generics Translations
PPPJ '15: Proceedings of the Principles and Practices of Programming on The Java PlatformGenerics on the Java platform are compiled using the erasure transformation, which only supports by-reference values. This causes slowdowns when generics operate on primitive types, such as integers, as they have to be transformed into reference-based ...







Comments