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.
Supplemental Material
Available for Download
- 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 Scholar
- 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 Scholar
Digital Library
- Giorgio Ausiello, Camil Demetrescu, Irene Finocchi, and Donatella Firmani. 2012. k-Calling Context Profiling. In OOPSLA. ACM, New York, NY, USA, 867-878.Google Scholar
- Thomas Ball and James R. Larus. 1996. Eficient Path Profiling. In MICRO. IEEE Computer Society, USA, 46-57.Google Scholar
- 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 Scholar
- Michael D. Bond and Kathryn S. McKinley. 2007. Probabilistic Calling Context. In OOPSLA. ACM, New York, NY, USA, 97-112.Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Keith D Cooper, Mary W Hall, and Ken Kennedy. 1993. A Methodology for Procedure Cloning. Comput. Lang. 19, 2 ( 1993 ), 105-117.Google Scholar
- Dibyendu Das. 2003. Function inlining versus function cloning. ACM SIGPLAN Notices 38, 6 ( 2003 ), 23-29.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- Iulian Dragos and Martin Odersky. 2009. Compiling Generics Through User-directed Type Specialization. In ICOOOLPS. ACM, New York, NY, USA, 42-47.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Mary Wolcott Hall. 1991. Managing interprocedural optimization. Ph.D. Dissertation. Rice University, Houston, TX, USA. UMI Order No. GAX91-36029.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Uday Khedker, Amitabha Sanyal, and Bageshri Karkare. 2009. Data Flow Analysis: Theory and Practice (1st ed.). CRC Press, Inc., Boca Raton, FL, USA.Google Scholar
- Anton Korobeynikov. 2007. Improving Switch Lowering for the LLVM Compiler System. In SYRCoSE. RAS, Innopolis, Russia, A.I-A.V.Google Scholar
- Chris Lattner and Vikram S. Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. In CGO. IEEE, Washington DC, 75-88.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- Robert Metzger and Sean Stroud. 1993. Interprocedural constant propagation: an empirical study. ACM Lett. Program. Lang. Syst. 2, 1-4 ( 1993 ), 213-232.Google Scholar
Digital Library
- 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 Scholar
- Ana Milanova. 2007. Light Context-sensitive Points-to Analysis for Java. In PASTE. ACM, New York, NY, USA, 25-30.Google Scholar
- 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 Scholar
- 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 Scholar
- Flemming Nielson, Hanne R. Nielson, and Chris Hankin. 1999. Principles of Program Analysis. Springer-Verlag New York, Inc., Secaucus, NJ, USA.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Gabriel Poesia. 2017. Dispatch of Context-Sensitive Optimizations. Master's thesis. Federal University of Minas Gerais.Google Scholar
- 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 Scholar
Digital Library
- Thomas Reps. 1997. Program Analysis via Graph Reachability. In ILPS. MIT Press, Cambridge, MA, USA, 5-19.Google Scholar
- Thomas Reps. 2000. Undecidability of Context-sensitive Data-dependence Analysis. TOPLAS 22, 1 (Jan. 2000 ), 162-186.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Olivier Sallenave and Roland Ducournau. 2012. Lightweight Generics in Embedded Systems Through Static Analysis. In LCTES. ACM, New York, NY, USA, 11-20.Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- O. Shivers. 1988. Control Flow Analysis in Scheme. In PLDI. ACM, New York, NY, USA, 164-174.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- Shiyi Wei and Barbara G. Ryder. 2015. Adaptive Context-sensitive Analysis for JavaScript. In ECOOP. Springer, London, UK, UK, 712-734.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Jianwen Zhu and Silvian Calman. 2004. Symbolic Pointer Analysis Revisited. In PLDI. ACM, New York, NY, USA, 145-157.Google Scholar
Index Terms
Dynamic dispatch of context-sensitive optimizations
Recommendations
Demand-driven context-sensitive alias analysis for Java
ISSTA '11: Proceedings of the 2011 International Symposium on Software Testing and AnalysisSoftware tools for program understanding, transformation, verification, and testing often require an efficient yet highly-precise alias analysis. Typically this is done by computing points-to information, from which alias queries can be answered. This ...
Refinement-based context-sensitive points-to analysis for Java
Proceedings of the 2006 PLDI ConferenceWe present a scalable and precise context-sensitive points-to analysis with three key properties: (1) filtering out of unrealizable paths, (2) a context-sensitive heap abstraction, and (3) a context-sensitive call graph. Previous work [21] has shown ...
Context-Sensitive points-to analysis: is it worth it?
CC'06: Proceedings of the 15th international conference on Compiler ConstructionWe present the results of an empirical study evaluating the precision of subset-based points-to analysis with several variations of context sensitivity on Java benchmarks of significant size. We compare the use of call site strings as the context ...






Comments