skip to main content
research-article
Open Access

Dynamic dispatch of context-sensitive optimizations

Published:13 November 2020Publication History
Skip Abstract Section

Abstract

Academia has spent much effort into making context-sensitive analyses practical, with great profit. However, the implementation of context-sensitive optimizations, in contrast to analyses, is still not practical, due to code-size explosion. This growth happens because current technology requires the cloning of full paths in the Calling Context Tree. In this paper, we present a solution to this problem. We combine finite state machines and dynamic dispatching to allow fully context-sensitive specialization while cloning only functions that are effectively optimized. This technique makes it possible to apply very liberal optimizations, such as context-sensitive constant propagation, in large programs—something that could not have been easily done before. We demonstrate the viability of our idea by formalizing it in Prolog, and implementing it in LLVM. As a proof of concept, we have used our state machines to implement context-sensitive constant propagation in LLVM. The binaries produced by traditional full cloning are 2.63 times larger than the binaries that we generate with our state machines. When applied on Mozilla Firefox, our optimization increases binary size from 7.2MB to 9.2MB. Full cloning, in contrast, yields a binary of 34MB.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation video of my talk at OOPSLA 2020, on the paper "Dynamic Dispatch of Context-Sensitive Optimizations". In this work, we notice that the implementation of context-sensitive optimizations, in contrast to analyses, is still not practical, due to code-size explosion. This growth happens because current technology requires the cloning of full paths in the Calling Context Tree. In this paper, we present a solution to this problem. We combine finite state machines and dynamic dispatching to allow fully context-sensitive specialization while cloning only functions that are effectively optimized. This technique makes it possible to apply very liberal optimizations, such as context-sensitive constant propagation, in large programs—something that could not have been easily done before. When applied on Mozilla Firefox, our optimization increases binary size from 7.2MB to 9.2MB. Full cloning, in contrast, yields a binary of 34MB.

References

  1. Péricles Alves, Fabian Gruber, Johannes Doerfert, Alexandros Lamprineas, Tobias Grosser, Fabrice Rastello, and Fernando Magno Quintão Pereira. 2015. Runtime Pointer Disambiguation. In OOPSLA. ACM, New York, NY, USA, 589-606.Google ScholarGoogle Scholar
  2. Steven Arzt, Siegfried Rasthofer, Christian Fritz, Eric Bodden, Alexandre Bartel, Jacques Klein, Yves Le Traon, Damien Octeau, and Patrick McDaniel. 2014. FlowDroid: Precise Context, Flow, Field, Object-sensitive and Lifecycle-aware Taint Analysis for Android Apps. In PLDI. ACM, New York, NY, USA, 259-269.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Giorgio Ausiello, Camil Demetrescu, Irene Finocchi, and Donatella Firmani. 2012. k-Calling Context Profiling. In OOPSLA. ACM, New York, NY, USA, 867-878.Google ScholarGoogle Scholar
  4. Thomas Ball and James R. Larus. 1996. Eficient Path Profiling. In MICRO. IEEE Computer Society, USA, 46-57.Google ScholarGoogle Scholar
  5. Michael D. Bond, Graham Z. Baker, and Samuel Z. Guyer. 2010. Breadcrumbs: Eficient Context Sensitivity for Dynamic Bug Detection Analyses. In PLDI. ACM, New York, NY, USA, 13-24.Google ScholarGoogle Scholar
  6. Michael D. Bond and Kathryn S. McKinley. 2007. Probabilistic Calling Context. In OOPSLA. ACM, New York, NY, USA, 97-112.Google ScholarGoogle Scholar
  7. Matt Brown and Jens Palsberg. 2017. Jones-optimal Partial Evaluation by Specialization-safe Normalization. Proc. ACM Program. Lang. 2, POPL (Dec. 2017 ), 14 : 1-14 : 28.Google ScholarGoogle Scholar
  8. James Bucek, Klaus-Dieter Lange, and Jóakim v. Kistowski. 2018. SPEC CPU2017: Next-Generation Compute Benchmark. In ICPE. Association for Computing Machinery, New York, NY, USA, 41-42. https://doi.org/10.1145/3185768.3185771 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Keith D Cooper, Mary W Hall, and Ken Kennedy. 1993. A Methodology for Procedure Cloning. Comput. Lang. 19, 2 ( 1993 ), 105-117.Google ScholarGoogle Scholar
  10. Dibyendu Das. 2003. Function inlining versus function cloning. ACM SIGPLAN Notices 38, 6 ( 2003 ), 23-29.Google ScholarGoogle Scholar
  11. Jefrey Dean, Craig Chambers, and David Grove. 1995a. Selective Specialization for Object-Oriented Languages. In PLDI. ACM, New York, NY, USA, 93-102. https://doi.org/10.1145/207110.207119 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Jefrey Dean, David Grove, and Craig Chambers. 1995b. Optimization of Object-Oriented Programs Using Static Class Hierarchy Analysis. In ECOOP. Springer-Verlag, London, UK, UK, 77-101.Google ScholarGoogle Scholar
  13. Iulian Dragos and Martin Odersky. 2009. Compiling Generics Through User-directed Type Specialization. In ICOOOLPS. ACM, New York, NY, USA, 42-47.Google ScholarGoogle Scholar
  14. Maryam Emami, Rakesh Ghiya, and Laurie J. Hendren. 1994. Context-sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers. In PLDI. ACM, New York, NY, USA, 242-256.Google ScholarGoogle Scholar
  15. Manuel Fähndrich, Jakob Rehof, and Manuvir Das. 2000. Scalable Context-sensitive Flow Analysis Using Instantiation Constraints. In PLDI. ACM, New York, NY, USA, 253-263.Google ScholarGoogle Scholar
  16. Yu Feng, Saswat Anand, Isil Dillig, and Alex Aiken. 2014. Apposcopy: Semantics-based Detection of Android Malware Through Static Analysis. In FSE. ACM, New York, NY, USA, 576-587.Google ScholarGoogle Scholar
  17. Olivier Fluckiger, Guido Chari, Ming-Ho Yee, Jan Jecmen, Jakob Hain, and Jan Vitek. 2020. Contextual Dispatch for Function Specialization. Proc. ACM Program. Lang. 4, OOPSLA, Article 1 ( 2020 ), 36 pages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Andreas Gal, Brendan Eich, Mike Shaver, David Anderson, David Mandelin, Mohammad R. Haghighat, Blake Kaplan, Graydon Hoare, Boris Zbarsky, Jason Orendorf, Jesse Ruderman, Edwin W. Smith, Rick Reitmaier, Michael Bebenita, Mason Chang, and Michael Franz. 2009. Trace-based Just-in-time Type Specialization for Dynamic Languages. In PLDI. ACM, New York, NY, USA, 465-478.Google ScholarGoogle Scholar
  19. Rakesh Ghiya and Laurie J. Hendren. 1996. Is It a Tree, a DAG, or a Cyclic Graph? A Shape Analysis for Heap-directed Pointers in C. In POPL. ACM, New York, NY, USA, 1-15.Google ScholarGoogle Scholar
  20. Nikola Grcevski, Allan Kielstra, Kevin Stoodley, Mark Stoodley, and Vijay Sundaresan. 2004. JavaTM Just-in-Time Compiler and Virtual Machine Improvements for Server and Middleware Applications. In VM. USENIX Association, USA, 12.Google ScholarGoogle Scholar
  21. David Grove, Greg DeFouw, Jefrey Dean, and Craig Chambers. 1997. Call Graph Construction in Object-Oriented Languages. In OOPSLA. ACM, New York, NY, USA, 108-124. https://doi.org/10.1145/263698.264352 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Dick Grune, Kees van Reeuwijk, Henri E. Baland Ceriel J. H. Jacobs, and Koen Langendoen. 2012. Modern Compiler Design (2nd ed.). Springer, London, UK, UK.Google ScholarGoogle Scholar
  23. Brian Hackett and Shu-yu Guo. 2012. Fast and Precise Hybrid Type Inference for JavaScript. In PLDI. ACM, New York, NY, USA, 239-250.Google ScholarGoogle Scholar
  24. Mary Wolcott Hall. 1991. Managing interprocedural optimization. Ph.D. Dissertation. Rice University, Houston, TX, USA. UMI Order No. GAX91-36029.Google ScholarGoogle Scholar
  25. Michael Hind, Michael Burke, Paul Carini, and Jong-Deok Choi. 1999. Interprocedural Pointer Alias Analysis. ACM Trans. Program. Lang. Syst. 21, 4 ( 1999 ), 848-894.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Urs Hölzle, Craig Chambers, and David Ungar. 1991. Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches. In ECOOP. Springer-Verlag, London, UK, UK, 21-38.Google ScholarGoogle Scholar
  27. Jipeng Huang and Michael D. Bond. 2013. Eficient Context Sensitivity for Dynamic Analyses via Calling Context Uptrees and Customized Memory Management. In OOPSLA. ACM, New York, NY, USA, 53-72.Google ScholarGoogle Scholar
  28. Hiroshi Inoue, Hiroshige Hayashizaki, Peng Wu, and Toshio Nakatani. 2011. A Trace-Based Java JIT Compiler Retrofitted from a Method-Based Compiler. In CGO. IEEE Computer Society, USA, 246-256.Google ScholarGoogle Scholar
  29. Sehun Jeong, Minseok Jeon, Sungdeok Cha, and Hakjoo Oh. 2017. Data-Driven Context-Sensitivity for Points-to Analysis. Proc. ACM Program. Lang. 1, OOPSLA, Article 100 ( 2017 ), 28 pages. https://doi.org/10.1145/3133924 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Ken Kennedy and John R. Allen. 2002. Optimizing compilers for modern architectures: a dependence-based approach. Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Uday Khedker, Amitabha Sanyal, and Bageshri Karkare. 2009. Data Flow Analysis: Theory and Practice (1st ed.). CRC Press, Inc., Boca Raton, FL, USA.Google ScholarGoogle Scholar
  32. Anton Korobeynikov. 2007. Improving Switch Lowering for the LLVM Compiler System. In SYRCoSE. RAS, Innopolis, Russia, A.I-A.V.Google ScholarGoogle Scholar
  33. Chris Lattner and Vikram S. Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. In CGO. IEEE, Washington DC, 75-88.Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Chris Lattner, Andrew Lenharth, and Vikram Adve. 2007. Making Context-sensitive Points-to Analysis with Heap Cloning Practical for the Real World. In PLDI. ACM, New York, NY, USA, 278-289.Google ScholarGoogle Scholar
  35. David Leopoldseder, Lukas Stadler, Thomas Würthinger, Josef Eisl, Doug Simon, and Hanspeter Mössenböck. 2018. Dominance-based Duplication Simulation (DBDS): Code Duplication to Enable Compiler Optimizations. In CGO. ACM, New York, NY, USA, 126-137.Google ScholarGoogle Scholar
  36. Ondřej Lhoták and Laurie Hendren. 2006. Context-Sensitive Points-to Analysis: Is It Worth It?. In CC. Springer, Berlin, Heidelberg, 47-64.Google ScholarGoogle Scholar
  37. Lian Li, Cristina Cifuentes, and Nathan Keynes. 2013. Precise and Scalable Context-sensitive Pointer Analysis via Value Flow Graph. In ISMM. ACM, New York, NY, USA, 85-96.Google ScholarGoogle Scholar
  38. Yue Li, Tian Tan, Anders Moller, and Yannis Smaragdakis. 2020. A Principled Approach to Selective Context Sensitivityfor Pointer Analysis. TOPLAS To-Appear, 1 ( 2020 ), 1-40.Google ScholarGoogle Scholar
  39. Caio Lima, Junio Cezar R. da Silva, Guilherme V. Leobas, Erven Rohou, and Fernando Magno Quintão Pereira. 2020. Guided just-in-time specialization. Sci. Comput. Program. 185, Article 2 ( 2020 ), 39 pages.Google ScholarGoogle Scholar
  40. Robert Metzger and Sean Stroud. 1993. Interprocedural constant propagation: an empirical study. ACM Lett. Program. Lang. Syst. 2, 1-4 ( 1993 ), 213-232.Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Matthew Might, Yannis Smaragdakis, and David Van Horn. 2010. Resolving and Exploiting the k-CFA Paradox: Illuminating Functional vs. Object-oriented Program Analysis. In PLDI. ACM, New York, NY, USA, 305-315.Google ScholarGoogle Scholar
  42. Ana Milanova. 2007. Light Context-sensitive Points-to Analysis for Java. In PASTE. ACM, New York, NY, USA, 25-30.Google ScholarGoogle Scholar
  43. Ana Milanova, Wei Huang, and Yao Dong. 2014. CFL-reachability and Context-sensitive Integrity Types. In PPPJ. ACM, New York, NY, USA, 99-109.Google ScholarGoogle Scholar
  44. Ana Milanova, Atanas Rountev, and Barbara G. Ryder. 2004. Precise Call Graphs for C Programs with Function Pointers. Automated Software Engg. 11, 1 ( 2004 ), 7-26.Google ScholarGoogle Scholar
  45. Flemming Nielson, Hanne R. Nielson, and Chris Hankin. 1999. Principles of Program Analysis. Springer-Verlag New York, Inc., Secaucus, NJ, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Hakjoo Oh, Wonchan Lee, Kihong Heo, Hongseok Yang, and Kwangkeun Yi. 2014. Selective Context-sensitivity Guided by Impact Pre-analysis. In PLDI. ACM, New York, NY, USA, 475-484.Google ScholarGoogle Scholar
  47. Dmitry Petrashko, Vlad Ureche, Ondřej Lhoták, and Martin Odersky. 2016. Call Graphs for Languages with Parametric Polymorphism. In OOPSLA. ACM, New York, NY, USA, 394-409.Google ScholarGoogle Scholar
  48. Gabriel Poesia. 2017. Dispatch of Context-Sensitive Optimizations. Master's thesis. Federal University of Minas Gerais.Google ScholarGoogle Scholar
  49. Gabriel Poesia, Breno Guimarães, Fabrício Ferracioli, and Fernando Magno Quintão Pereira. 2017. Static Placement of Computation on Heterogeneous Devices. Proc. ACM Program. Lang. 1, OOPSLA (Oct. 2017 ), 50 : 1-50 : 28.Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Thomas Reps. 1997. Program Analysis via Graph Reachability. In ILPS. MIT Press, Cambridge, MA, USA, 5-19.Google ScholarGoogle Scholar
  51. Thomas Reps. 2000. Undecidability of Context-sensitive Data-dependence Analysis. TOPLAS 22, 1 (Jan. 2000 ), 162-186.Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Silvius Rus, Lawrence Rauchwerger, and Jay Hoeflinger. 2002. Hybrid Analysis: Static & Dynamic Memory Reference Analysis. In ICS. ACM, New York, NY, USA, 274-284.Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Olivier Sallenave and Roland Ducournau. 2012. Lightweight Generics in Embedded Systems Through Static Analysis. In LCTES. ACM, New York, NY, USA, 11-20.Google ScholarGoogle Scholar
  54. Mehrzad Samadi, Amir Hormati, Mojtaba Mehrara, Janghaeng Lee, and Scott Mahlke. 2012. Adaptive Input-aware Compilation for Graphics Engines. In PLDI. ACM, New York, NY, USA, 13-22.Google ScholarGoogle Scholar
  55. Henrique Nazare Santos, Pericles Alves, Igor Costa, and Fernando Magno Quintao Pereira. 2013. Just-in-time Value Specialization. In CGO. IEEE Computer Society, Washington, DC, USA, 1-11. https://doi.org/10.1109/CGO. 2013.6495006 Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. O. Shivers. 1988. Control Flow Analysis in Scheme. In PLDI. ACM, New York, NY, USA, 164-174.Google ScholarGoogle Scholar
  57. Rodrigo Sol, Christophe Guillon, Fernando Magno Quintão Pereira, and Mariza Andrade da Silva Bigonha. 2011. Dynamic Elimination of Overflow Tests in a Trace Compiler. In CC. Springer-Verlag, London, UK, UK, 2-21. https://doi.org/10. 1007/978-3-642-19861-8_2 Google ScholarGoogle ScholarCross RefCross Ref
  58. Johannes Späth, Karim Ali, and Eric Bodden. 2019. Context-, flow-, and field-sensitive data-flow analysis using synchronized Pushdown systems. Proc. ACM Program. Lang. 3, POPL ( 2019 ), 48 : 1-48 : 29. https://doi.org/10.1145/3290361 Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Johannes Späth, Lisa Nguyen Quang Do, Karim Ali, and Eric Bodden. 2016. Boomerang: Demand-Driven Flow-and Context-Sensitive Pointer Analysis for Java. In ECOOP. Springer, London, UK, UK, 22 : 1-22 : 26. https://doi.org/10.4230/ LIPIcs.ECOOP. 2016.22 Google ScholarGoogle ScholarCross RefCross Ref
  60. Victor Hugo Sperle Campos, Péricles Rafael Alves, Henrique Nazaré Santos, and Fernando Magno Quintão Pereira. 2016. Restrictification of Function Arguments. In CC. ACM, New York, NY, USA, 163-173.Google ScholarGoogle Scholar
  61. Manu Sridharan and Rastislav Bodík. 2006. Refinement-based Context-sensitive Points-to Analysis for Java. In PLDI. ACM, New York, NY, USA, 387-400.Google ScholarGoogle Scholar
  62. Lukas Stadler, Adam Welc, Christian Humer, and Mick Jordan. 2016. Optimizing R Language Execution via Aggressive Speculation. In DLS. ACM, New York, NY, USA, 84-95. https://doi.org/10.1145/2989225.2989236 Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. Nicolas Stucki and Vlad Ureche. 2013. Bridging Islands of Specialized Code Using Macros and Reified Types. In SCALA. ACM, New York, NY, USA, 10 : 1-10 : 4.Google ScholarGoogle Scholar
  64. William N. Sumner, Yunhui Zheng, Dasarath Weeratunge, and Xiangyu Zhang. 2010. Precise Calling Context Encoding. In ICSE. ACM, New York, NY, USA, 525-534. https://doi.org/10.1145/1806799.1806875 Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. William N. Sumner, Yunhui Zheng, Dasarath Weeratunge, and Xiangyu Zhang. 2012. Precise Calling Context Encoding. IEEE Trans. Software Eng. 38, 5 ( 2012 ), 1160-1177. https://doi.org/10.1109/TSE. 2011.70 Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. Manas Thakur and V. Krishna Nandivada. 2019. Compare Less, Defer More: Scaling Value-Contexts Based Whole-Program Heap Analyses. In Compiler Construction. ACM, New York, NY, USA, 135-146.Google ScholarGoogle Scholar
  67. Manas Thakur and V. Krishna Nandivada. 2020. Mix Your Contexts Well: Opportunities Unleashed by Recent Advances in Scaling Context-Sensitivity. In Compiler Construction. ACM, New York, NY, USA, 27-38. https://doi.org/10.1145/3377555. 3377902 Google ScholarGoogle ScholarDigital LibraryDigital Library
  68. Rei Thiessen and Ondřej Lhoták. 2017. Context Transformations for Pointer Analysis. SIGPLAN Not. 52, 6 ( 2017 ), 263-277. https://doi.org/10.1145/3140587.3062359 Google ScholarGoogle ScholarDigital LibraryDigital Library
  69. Kai Tian, Eddy Zhang, and Xipeng Shen. 2011. A Step Towards Transparent Integration of Input-consciousness into Dynamic Program Optimizations. In OOPSLA. ACM, New York, NY, USA, 445-462.Google ScholarGoogle Scholar
  70. Vlad Vergu and Eelco Visser. 2018. Specializing a Meta-Interpreter: JIT Compilation of Dynsem Specifications on the Graal VM. In ManLang. ACM, New York, NY, USA, 1-14. https://doi.org/10.1145/3237009.3237018 Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. Haichuan Wang, Peng Wu, and David Padua. 2014. Optimizing R VM: Allocation Removal and Path Length Reduction via Interpreter-level Specialization. In CGO. ACM, New York, NY, USA, 295 : 295-295 : 305.Google ScholarGoogle Scholar
  72. Shiyi Wei and Barbara G. Ryder. 2015. Adaptive Context-sensitive Analysis for JavaScript. In ECOOP. Springer, London, UK, UK, 712-734.Google ScholarGoogle Scholar
  73. John Whaley and Monica S. Lam. 2004. Cloning-based Context-sensitive Pointer Alias Analysis Using Binary Decision Diagrams. In PLDI. ACM, New York, NY, USA, 131-144.Google ScholarGoogle Scholar
  74. Robert P. Wilson and Monica S. Lam. 1995. Eficient Context-sensitive Pointer Analysis for C Programs. In PLDI. ACM, New York, NY, USA, 1-12.Google ScholarGoogle Scholar
  75. Hongtao Yu, Jingling Xue, Wei Huo, Xiaobing Feng, and Zhaoqing Zhang. 2010. Level by Level: Making Flow-and Context-Sensitive Pointer Analysis Scalable for Millions of Lines of Code. In CGO. ACM, New York, NY, USA, 218-229. https://doi.org/10.1145/1772954.1772985 Google ScholarGoogle ScholarDigital LibraryDigital Library
  76. Jianwen Zhu and Silvian Calman. 2004. Symbolic Pointer Analysis Revisited. In PLDI. ACM, New York, NY, USA, 145-157.Google ScholarGoogle Scholar

Index Terms

  1. Dynamic dispatch of context-sensitive optimizations

          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

          • Published in

            cover image Proceedings of the ACM on Programming Languages
            Proceedings of the ACM on Programming Languages  Volume 4, Issue OOPSLA
            November 2020
            3108 pages
            EISSN:2475-1421
            DOI:10.1145/3436718
            Issue’s Table of Contents

            Copyright © 2020 Owner/Author

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 13 November 2020
            Published in pacmpl Volume 4, Issue OOPSLA

            Permissions

            Request permissions about this article.

            Request Permissions

            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!