Amortised Memory Analysis Using the Depth of Data Structures

  • Brian Campbell
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5502)


Hofmann and Jost have presented a heap space analysis [1] that finds linear space bounds for many functional programs. It uses an amortised analysis: assigning hypothetical amounts of free space (called potential) to data structures in proportion to their sizes using type annotations. Constraints on these annotations in the type system ensure that the total potential assigned to the input is an upper bound on the total memory required to satisfy all allocations.

We describe a related system for bounding the stack space requirements which uses the depth of data structures, by expressing potential in terms of maxima as well as sums. This is achieved by adding extra structure to typing contexts (inspired by O’Hearn’s bunched typing [2]) to describe the form of the bounds. We will also present the extra steps that must be taken to construct a typing during the analysis.


Induction Hypothesis Type System Operational Semantic Functional Programming Structural Rule 
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.
    Hofmann, M., Jost, S.: Static prediction of heap space usage for first-order functional programs. In: POPL 2003: Proceedings of the 30th ACM Symposium on Principles of Programming Languages, New Orleans. ACM Press, New York (2003)Google Scholar
  2. 2.
    O’Hearn, P.: On bunched typing. Journal of Functional Programming 13(4), 747–796 (2003)MathSciNetCrossRefzbMATHGoogle Scholar
  3. 3.
    Aspinall, D., Gilmore, S., Hofmann, M., Sannella, D., Stark, I.: Mobile resource guarantees for smart devices. In: Barthe, G., Burdy, L., Huisman, M., Lanet, J.-L., Muntean, T. (eds.) CASSIS 2004. LNCS, vol. 3362, pp. 1–26. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  4. 4.
    Jost, S., Loidl, H.W., Hammond, K.: Report on stack-space analysis (revised). Deliverable D05, The Embounded Project (IST-510255) (2007)Google Scholar
  5. 5.
    Campbell, B.: Prediction of linear memory usage for first-order functional programs. In: Trends in Functional Programming, vol. 9 (2008) (to appear)Google Scholar
  6. 6.
    Tarjan, R.E.: Amortized computational complexity. SIAM Journal on Algebraic and Discrete Methods 6(2), 306–318 (1985)MathSciNetCrossRefzbMATHGoogle Scholar
  7. 7.
    Campbell, B.: Type-based amortized stack memory prediction. PhD thesis, University of Edinburgh (2008)Google Scholar
  8. 8.
    Jost, S., Loidl, H.W., Hammond, K.: Report on heap-space analysis. Deliverable D11, The Embounded Project (IST-510255 ) (2007)Google Scholar
  9. 9.
    Jost, S.: Amortised Analysis for Functional Programs. PhD thesis, Ludwig-Maximilians-University (forthcoming, provisional title) (2008)Google Scholar
  10. 10.
    Hofmann, M., Jost, S.: Type-based amortised heap-space analysis (for an object-oriented language). In: Sestoft, P. (ed.) ESOP 2006. LNCS, vol. 3924, pp. 22–37. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  11. 11.
    Reistad, B., Gifford, D.K.: Static dependent costs for estimating execution time. In: LFP 1994: Proceedings of the 1994 ACM conference on LISP and functional programming, pp. 65–78. ACM Press, New York (1994)CrossRefGoogle Scholar
  12. 12.
    Hughes, J., Pareto, L.: Recursion and dynamic data-structures in bounded space: towards embedded ML programming. In: ICFP 1999: Proceedings of the fourth ACM SIGPLAN International Conference on Functional Programming, pp. 70–81. ACM Press, New York (1999)CrossRefGoogle Scholar
  13. 13.
    Chin, W.N., Khoo, S.C.: Calculating sized types. Higher Order and Symbolic Computation 14(2-3), 261–300 (2001)CrossRefzbMATHGoogle Scholar
  14. 14.
    Chin, W.N., Khoo, S.C., Xu, D.N.: Extending sized type with collection analysis. In: PEPM 2003: Proceedings of the 2003 ACM SIGPLAN workshop on Partial Evaluation and Semantics-based Program Manipulation, pp. 75–84. ACM Press, New York (2003)Google Scholar
  15. 15.
    Chin, W.N., Khoo, S.C., Qin, S., Popeea, C., Nguyen, H.H.: Verifying safety policies with size properties and alias controls. In: ICSE 2005: Proceedings of the 27th International Conference on Software Engineering, pp. 186–195. ACM Press, New York (2005)Google Scholar
  16. 16.
    Chin, W.N., Nguyen, H.H., Qin, S., Rinard, M.: Memory usage verification for OO programs. In: Hankin, C., Siveroni, I. (eds.) SAS 2005. LNCS, vol. 3672, pp. 70–86. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  17. 17.
    Chin, W.N., Nguyen, H.H., Popeea, C., Qin, S.: Analysing memory resource bounds for low-level programs. In: ISMM 2008: Proceedings of the 7th international symposium on Memory management, pp. 151–160. ACM, New York (2008)Google Scholar
  18. 18.
    Vasconcelos, P.: Space Cost Analysis Using Sized Types. PhD thesis, University of St Andrews (2008)Google Scholar
  19. 19.
    Debray, S.K., Lin, N.W.: Cost analysis of logic programs. ACM Transactions on Programming Languages and Systems 15(5), 826–875 (1993)CrossRefGoogle Scholar
  20. 20.
    Vasconcelos, P.B., Hammond, K.: Inferring cost equations for recursive, polymorphic and higher-order functional programs. In: Trinder, P., Michaelson, G.J., Peña, R. (eds.) IFL 2003. LNCS, vol. 3145, pp. 86–101. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  21. 21.
    Albert, E., Arenas, P., Genaim, S., Puebla, G.: Automatic inference of upper bounds for recurrence relations in cost analysis. In: Alpuente, M., Vidal, G. (eds.) SAS 2008. LNCS, vol. 5079, pp. 221–237. Springer, Heidelberg (2008)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Brian Campbell
    • 1
  1. 1.School of InformaticsUniversity of EdinburghUK

Personalised recommendations