Dynamic Elimination of Overflow Tests in a Trace Compiler

  • Rodrigo Sol
  • Christophe Guillon
  • Fernando Magno Quintão Pereira
  • Mariza A. S. Bigonha
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6601)


Trace compilation is a technique used by just-in-time (JIT) compilers such as TraceMonkey, the JavaScript engine in the Mozilla Firefox browser. Contrary to traditional JIT machines, a trace compiler works on only part of the source program, normally a linear path inside a heavily executed loop. Because the trace is compiled during the interpretation of the source program the JIT compiler has access to runtime values. This observation gives the compiler the possibility of producing binary code specialized to these values. In this paper we explore such opportunity to provide an analysis that removes unnecessary overflow tests from JavaScript programs. Our optimization uses range analysis to show that some operations cannot produce overflows. The analysis is linear in size and space on the number of instructions present in the input trace, and it is more effective than traditional range analyses, because we have access to values known only at execution time. We have implemented our analysis on top of Firefox’s TraceMonkey, and have tested it on over 1000 scripts from several industrial strength benchmarks, including the scripts present in the top 100 most visited webpages in the Alexa index. We generate binaries to either x86 or the embedded microprocessor ST40-300. On the average, we eliminate 91.82% of the overflows in the programs present in the TraceMonkey test suite. This optimization provides an average code size reduction of 8.83% on ST40 and 6.63% on x86. Our optimization increases TraceMonkey’s runtime by 2.53%.


Partial Evaluation Range Analysis Source Program Range Propagation Constraint Graph 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Aycock, J.: A brief history of just-in-time. ACM Computing Surveys 35(2), 97–113 (2003)CrossRefGoogle Scholar
  2. 2.
    Bala, V., Duesterwald, E., Banerjia, S.: Dynamo: a transparent dynamic optimization system. In: PLDI, pp. 1–12. ACM, New York (2000)CrossRefGoogle Scholar
  3. 3.
    Bodik, R., Gupta, R., Sarkar, V.: ABCD: eliminating array bounds checks on demand. In: PLDI, pp. 321–333. ACM, New York (2000)CrossRefGoogle Scholar
  4. 4.
    Carette, J., Kucera, M.: Partial evaluation of maple. In: PEPM, pp. 41–50. ACM, New York (2007)CrossRefGoogle Scholar
  5. 5.
    Chambers, C., Ungar, D.: Customization: optimizing compiler technology for self, a dynamically-typed object-oriented programming language. SIGPLAN Not. 24(7), 146–160 (1989)CrossRefGoogle Scholar
  6. 6.
    Chang, M., Smith, E., Reitmaier, R., Bebenita, M., Gal, A., Wimmer, C., Eich, B., Franz, M.: Tracing for web 3.0: trace compilation for the next generation web applications. In: VEE, pp. 71–80. ACM, New York (2009)CrossRefGoogle Scholar
  7. 7.
    Chevalier-Boisvert, M., Hendren, L., Verbrugge, C.: Optimizing matlab through just-in-time specialization. In: Gupta, R. (ed.) CC 2010. LNCS, vol. 6011, pp. 46–65. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  8. 8.
    ECMA Committe. ECMAScript Language Specification. ECMA, 5th edn. (2009)Google Scholar
  9. 9.
    Cytron, R., Ferrante, J., Rosen, B.K., Wegman, M.N., Zadeck, F.K.: Efficiently computing static single assignment form and the control dependence graph. TOPLAS 13(4), 451–490 (1991)CrossRefGoogle Scholar
  10. 10.
    Elphick, D., Leuschel, M., Cox, S.: Partial evaluation of MATLAB. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 344–363. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  11. 11.
    Fisher, J.A.: Trace scheduling: A technique for global microcode compaction. Trans. Comput. 30, 478–490 (1981)CrossRefGoogle Scholar
  12. 12.
    Richards, G., Lebresne, S., Burg, B., Vitek, J.: An analysis of the dynamic behavior of javascript programs. In: PLDI, pp. 1–12 (2010)Google Scholar
  13. 13.
    Gal, A.: Efficient Bytecode Verification and Compilation in a Virtual Machine. PhD thesis, University of California, Irvine (2006)Google Scholar
  14. 14.
    Gal, A., Eich, B., Shaver, M., Anderson, D., Kaplan, B., Hoare, G., Mandelin, D., Zbarsky, B., Orendorff, J., Ruderman, J., Smith, E., Reitmair, R., Haghighat, M.R., Bebenita, M., Change, M., Franz, M.: Trace-based just-in-time type specialization for dynamic languages. In: PLDI, pp. 465–478. ACM, New York (2009)CrossRefGoogle Scholar
  15. 15.
    Gal, A., Probst, C.W., Franz, M.: Hotpathvm: an effective jit compiler for resource-constrained devices. In: VEE, pp. 144–153 (2006)Google Scholar
  16. 16.
    Goldberg, D.: What every computer scientist should know about floating-point arithmetic. Comput. Surv. 23, 5–48 (1991)CrossRefGoogle Scholar
  17. 17.
    Harrison, W.H.: Compiler analysis of the value ranges for variables. IEEE Trans. Softw. Eng. 3(3), 243–250 (1977)CrossRefzbMATHGoogle Scholar
  18. 18.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation, 1st edn. Prentice Hall, Englewood Cliffs (1993)zbMATHGoogle Scholar
  19. 19.
    McCarthy, J.: Recursive functions of symbolic expressions and their computation by machine, part i. Communications of ACM 3(4), 184–195 (1960)CrossRefzbMATHGoogle Scholar
  20. 20.
    Patterson, J.R.C.: Accurate static branch prediction by value range propagation. In: PLDI, pp. 67–78. ACM, New York (1995)Google Scholar
  21. 21.
    Rigo, A.: Representation-based just-in-time specialization and the psyco prototype for python. In: PEPM, pp. 15–26. ACM, New York (2004)Google Scholar
  22. 22.
    Schultz, U.P., Lawall, J.L., Consel, C.: Automatic program specialization for java. TOPLAS 25(4), 452–499 (2003)CrossRefGoogle Scholar
  23. 23.
    Shankar, A., Sastry, S.S., Bodík, R., Smith, J.E.: Runtime specialization with optimistic heap analysis. SIG. Not. 40(10), 327–343 (2005)CrossRefGoogle Scholar
  24. 24.
    Stephenson, M., Babb, J., Amarasinghe, S.: Bidwidth analysis with application to silicon compilation. In: PLDI, pp. 108–120. ACM, New York (2000)CrossRefGoogle Scholar
  25. 25.
    Su, Z., Wagner, D.: A class of polynomially solvable range constraints for interval analysis without widenings. Theoretical Computeter Science 345(1), 122–138 (2005)MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Guo, S.y., Palsberg, J.: The essence of compiling with traces. In: POPL. ACM, New York (2011) (page to appear)Google Scholar
  27. 27.
    Zaleski, M.: YETI: a gradually extensible trace interpreter. PhD thesis, University of Toronto (2007)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • Rodrigo Sol
    • 1
  • Christophe Guillon
    • 2
  • Fernando Magno Quintão Pereira
    • 1
  • Mariza A. S. Bigonha
    • 1
  1. 1.UFMGBelo HorizonteBrazil
  2. 2.STMicroelectronicsGrenobleFrance

Personalised recommendations