Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler

  • Nurudeen Lameed
  • Laurie Hendren
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6601)


Matlab has gained widespread acceptance among scientists. Several dynamic aspects of the language contribute to its appeal, but also provide many challenges. One such problem is caused by the copy semantics of Matlab. Existing Matlab systems rely on reference-counting schemes to create copies only when a shared array representation is updated. This reduces array copies, but requires runtime checks.

We present a staged static analysis approach to determine when copies are not required. The first stage uses two simple, intraprocedural analyses, while the second stage combines a forward necessary copy analysis with a backward copy placement analysis. Our approach eliminates unneeded array copies without requiring reference counting or frequent runtime checks.

We have implemented our approach in the McVM JIT. Our results demonstrate that, for our benchmark set, there are significant overheads for both existing reference-counted and naive copy-insertion approaches, and that our staged approach is effective in avoiding unnecessary copies.


Reference Count Forward Analysis Copy Statement Quick Check Runtime Check 
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.
  2. 2.
  3. 3.
  4. 4.
    Anderson, E., Bai, Z., Bischof, C., Blackford, S., Demmel, J., Dongarra, J., Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A., Sorensen, D.: LAPACK Users’ Guide, 3rd edn. SIAM, Philadelphia (1999)CrossRefzbMATHGoogle Scholar
  5. 5.
    Aslam, T., Doherty, J., Dubrau, A., Hendren, L.: AspectMatlab: An Aspect-Oriented Scientific Programming Language. In: Proceedings of the 9th International Conference on Aspect-Oriented Software Development, pp. 181–192 (March 2010)Google Scholar
  6. 6.
    Boehm, H., Spertus, M.: N2310: Transparent Programmer-Directed Garbage Collection for C++ (June 2007),
  7. 7.
    Casey, A., Hendren, L.: MetaLexer: A Modular Lexical Specification Language. In: Proceedings of the 10th International Conference on Aspect-Oriented Software Development (March 2011)Google Scholar
  8. 8.
    Chevalier-Boisvert, M.: McVM: An Optimizing Virtual Machine for the MATLAB Programming Language. Master’s thesis, McGill University (August 2009)Google Scholar
  9. 9.
    Chevalier-Boisvert, M., Hendren, L., Verbrugge, C.: Optimizing MATLAB through Just-In-Time Specialization. In: International Conference on Compiler Construction, pp. 46–65 (March 2010)Google Scholar
  10. 10.
    Moler, C.: Numerical Computing with MATLAB. SIAM, Philadelphia (2004)CrossRefzbMATHGoogle Scholar
  11. 11.
    Ekman, T., Hedin, G.: The Jastadd Extensible Java Compiler. In: OOPSLA 2007: Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems and Applications, pp. 1–18. ACM, New York (2007)CrossRefGoogle Scholar
  12. 12.
    Gopinath, K., Hennessy, J.L.: Copy Elimination in Functional Languages. In: POPL 1989: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 303–314. ACM, New York (1989)Google Scholar
  13. 13.
    Goyal, D., Paige, R.: A New Solution to the Hidden Copy Problem. In: Levi, G. (ed.) SAS 1998. LNCS, vol. 1503, pp. 327–348. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  14. 14.
    Hudak, P., Bloss, A.: The Aggregate Update Problem in Functional Programming Systems. In: POPL 1985: Proceedings of the 12th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, pp. 300–314. ACM, New York (1985)Google Scholar
  15. 15.
    Iverson, K.E.: A Programming Language. John Wiley and Sons, Inc., Chichester (1962)CrossRefzbMATHGoogle Scholar
  16. 16.
    Lameed, N., Hendren, L.: Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. Technical Report SABLE-TR-2010-5, School of Computer Science, McGill University, Montréal, Canada (July 2010)Google Scholar
  17. 17.
    Lattner, C., Adve, V.: LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. In: CGO 2004: Proceedings of the International Symposium on Code Generation and Optimization, p. 75. IEEE Computer Society, Washington, DC, USA (2004)CrossRefGoogle Scholar
  18. 18.
    Li, J.: McFor: A MATLAB to FORTRAN 95 Compiler. Master’s thesis, McGill University (August 2009)Google Scholar
  19. 19.
    MathWorks. MATLAB Programming Fundamentals. The MathWorks, Inc. (2009)Google Scholar
  20. 20.
    Muchnick, S.: Advanced Compiler Design and Implementation. Morgan Kaufmann, San Francisco (1997)Google Scholar
  21. 21.
    Odersky, M.: How to Make Destructive Updates Less Destructive. In: POPL 1991: Proceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 25–36. ACM, New York (1991)Google Scholar
  22. 22.
    Press, H.W., Teukolsky, A.S., Vetterling, T.W., Flannery, P.B.: Numerical Recipes: the Art of Scientific Computing. Cambridge University Press, Cambridge (1986)zbMATHGoogle Scholar
  23. 23.
    Rose, L.D., Gallivan, K., Gallopoulos, E., Marsolf, B.A., Padua, D.A.: FALCON: A MATLAB Interactive Restructuring Compiler. In: Huang, C.-H., Sadayappan, P., Banerjee, U., Gelernter, D., Nicolau, A., Padua, D.A. (eds.) LCPC 1995. LNCS, vol. 1033, pp. 269–288. Springer, Heidelberg (1996)CrossRefGoogle Scholar
  24. 24.
    Sastry, A.V.S.: Efficient Array Update Analysis of Strict Functional Languages. PhD thesis, University of Oregon, Eugene, USA (1994)Google Scholar
  25. 25.
    Schwartz, J.T., Dewar, R.B., Schonberg, E., Dubinsky, E.: Programming with Sets; an Introduction to SETL. Springer, New York (1986)zbMATHGoogle Scholar
  26. 26.
    Wand, M., Clinger, W.D.: Set Constraints for Destructive Array Update Optimization. Journal of Functional Programming 11(3), 319–346 (2001)MathSciNetCrossRefzbMATHGoogle Scholar
  27. 27.
    Weigang, J.: An Introduction to STSC’s APL Compiler. SIGAPL APL Quote Quad 15(4), 231–238 (1985)CrossRefGoogle Scholar
  28. 28.
    Whaley, R.C., Petitet, A., Dongarra, J.J.: Automated Empirical Optimizations of Software and the ATLAS Project. Parallel Computing 27(1-2), 3–35 (2001)CrossRefzbMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • Nurudeen Lameed
    • 1
  • Laurie Hendren
    • 1
  1. 1.School of Computer ScienceMcGill UniversityMontréalCanada

Personalised recommendations