skip to main content
research-article

Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations

Published:29 October 2013Publication History
Skip Abstract Section

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.

References

  1. Ceylon Programming Language. URL http://ceylon-lang.org/.Google ScholarGoogle Scholar
  2. Kotlin Programming Language. URL http://kotlin.jetbrains.org/.Google ScholarGoogle Scholar
  3. Scala Programming Language. URL http://scala-lang.org/.Google ScholarGoogle Scholar
  4. X10 Programming Language. URL http://x10-lang.org/.Google ScholarGoogle Scholar
  5. ECMA International, Standard ECMA-335: Common Language Infrastructure, June 2006.Google ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. E. Allen, J. Bannet, and R. Cartwright. A First-Class Approach to Genericity. In ACM SIGPLAN Notices, volume 38. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. A. Buckley. JSR 202: Java Class File Specification Update, 2006. URL http://www.jcp.org/en/jsr/detail?id=202.Google ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. I. Dragos. Compiling Scala for Performance. PhD thesis, École Polytechnique Fédérale de Lausanne, 2010.Google ScholarGoogle Scholar
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. R. Ierusalimschy, L. H. De Figueiredo, and W. Celes. The Implementation of Lua 5.0. Journal of Universal Computer Science, 11(7), 2005.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. X. Leroy. Unboxed Objects and Polymorphic Typing. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. T. Lindholm and F. Yellin. Java Virtual Machine Specification. Addison-Wesley Longman Publishing Co., Inc., 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. Y. Minamide. Full Lifting of Type Parameters. In Proceedings of Second Fuji International Workshop on Functional and Logic Programming, 1997.Google ScholarGoogle Scholar
  26. A. Moors. Type Constructor Polymorphism for Scala: Theory and Practice. PhD thesis, PhD thesis, Katholieke Universiteit Leuven, 2009.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. Odersky and M. Zenger. Scalable Component Abstractions. In ACM SIGPLAN Notices, volume 40. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. M. Odersky, E. Runne, and P. Wadler. Two Ways to Bake Your Pizza-Translating Parameterised Types into Java. Springer, 2000.Google ScholarGoogle ScholarCross RefCross Ref
  30. Oracle. OpenJDK: Graal project. URL http://openjdk.java.net/projects/graal/.Google ScholarGoogle Scholar
  31. E. Osheim. Generic Numeric Programming Through Specialized Type Classes. ScalaDays, 2012.Google ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. A. Prokopec. ScalaMeter. URL http://axel22.github.com/scalameter/.Google ScholarGoogle Scholar
  34. A. Prokopec, P. Bagwell, T. Rompf, and M. Odersky. A Generic Parallel Collection Framework. In Euro-Par 2011 Parallel Processing. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. O. Sallenave and R. Ducournau. Lightweight Generics in Embedded Systems Through Static Analysis. SIGPLAN Notices, 47(5), June 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. M. Schinz. Compiling Scala for the Java Virtual Machine. PhD thesis, École Polytechnique Fédérale de Lausanne, 2005.Google ScholarGoogle Scholar
  38. B. Stroustrup. The C++ Programming Language, Third Edition. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 3rd edition, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. A. Tolmach. Tag-Free Garbage Collection Using Explicit Type Parameters. In ACM SIGPLAN Lisp Pointers, volume 7. ACM, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations

      Recommendations

      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

      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!