Copying Garbage Collection for the WAM: To Mark or Not to Mark?

  • Bart Demoen
  • Phuong-Lan Nguyen
  • Ruben Vandeginste
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2401)


Garbage collection by copying is becoming more and more popular for Prolog. Copying requires a marking phase in order to be safe: safeness means that the to-space is guaranteed not to overflow. However, some systems use a copying garbage collector without marking prior to copying, and instead postpone the copying of potentially unsafe cells. Such systems only collect small portions of the heap and it is not clear whether postponing works while collecting the whole heap. Moreover, it is shown here that postponing does not solve the problem in a fundamental way. Since marking takes time, it is worth studying the tradeoffs involved. These observations have prompted the experimentation with a series of garbage collectors based on copying without marking and without postponing. In particular, variants were implemented that are named dangerous, optimistic and cautious copying which exhibit various degrees of unsafeness. Versions of each have been implemented based on recursive copying as in most implementations of copy_term/2 and on the Cheney algorithm. Performance on benchmarks suggests that large performance gains can be obtained by skipping the marking phase, that dangerous copying is still relatively safe but can be costly, and that the additional effort of cautious copying over optimistic copying is not worth it. The optimistic collectors based on recursive copying perform best and slightly better than the ones based on Cheney. Cache performance measurements back up the benchmark results.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    H. Ait-Kaci. The WAM: a (real) tutorial. Technical Report 5, DEC Paris Research Report, 1990 See also:
  2. 2.
    K. Appleby, M. Carlsson, S. Haridi, and D. Sahlin. Garbage collection for Prolog based on WAM. Communications of the ACM, 31(6):719–741, June 1988.Google Scholar
  3. 3.
    Y. Bekkers, O. Ridoux, and L. Ungaro. Dynamic memory management for sequential logic programming languages. In Y. Bekkers and J. Cohen, editors, Proceedings of IWMM’92: International Workshop on Memory Management, number 637 in Lecture Notes in Computer Science, pages 82–102. Springer-Verlag, Sept. 1992.Google Scholar
  4. 4.
    J. Bevemyr and T. Lindgren. A simple and efficient copying garbage collector for Prolog. In M. Hermenegildo and J. Penjam, editors, Proceedings of the Sixth International Symposium on Programming Language Implementation and Logic Programming, number 844 in Lecture Notes in Computer Science, pages 88–101. Springer-Verlag, Sept. 1994.Google Scholar
  5. 5.
    M. Carlsson. Design and Implementation of an Or-Parallel Prolog Engine. PhD thesis, The Royal Institute of Technology (KTH), Stokholm, Sweden, Mar. 1990 See also:
  6. 6.
    L. F. Castro and V. S. Costa. Understanding Memory Management in Prolog Systems. In P. Codognet, editor, Proceedings of the 17th International Conference on Logic Programming, ICLP’2001, number 2237 in Lecture Notes in Computer Science, pages 11–26. Springer-Verlag, nov 2001.Google Scholar
  7. 7.
    C. J. Cheney. A nonrecursive list compacting algorithm. Communications of the ACM, 13(11):677–678, Nov. 1970.Google Scholar
  8. 8.
    V. S. Costa. Optimising Bytecode Emulation for Prolog. In Proceedings of PPDP’99, volume 1702 of LNCS, pages 261–277. Springer-Verlag, Sept. 1999 See also Scholar
  9. 9.
    B. Demoen, M. García de la Banda, W. Harvey, K. Mariott, and P. Stuckey. An overview of HAL. In J. Jaffar, editor, Proceedings of the International Conference on Principles and Practice of Constraint Programming, volume 1713 of LNCS, pages 174–188. Springer, 1999.Google Scholar
  10. 10.
    B. Demoen and P.-L. Nguyen. So many WAM variations, so little time. In J. Lloyd, V. Dahl, U. Furbach, M. Kerber, K.-K. Lau, C. Palamidessi, L. M. Pereira, Y. Sagiv, and P. J. Stuckey, editors, Computational Logic-CL2000, First International Conference, London, UK, July 2000, Proceedings, volume 1861 of Lecture Notes in Artificial Intelligence, pages 1240–1254. ALP, Springer, 2000.Google Scholar
  11. 11.
    B. Demoen, P.-L. Nguyen, and R. Vandeginste. Copy_term/2 and garbage collection. Report CW 329, Dept. of Comp. Sc., K. U. Leuven, Belgium, Jan. 2002.Google Scholar
  12. 12.
    R. Jones and R. Lins. Garbage Collection: Algorithms for automatic memory management. John Wiley, 1996 See also staff/rej/gcbook/gcbook.html.
  13. 13.
    X. Li. Efficient memory management in a merged heap/stack Prolog machine. In Proceedings of the 2nd ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP’00), pages 245–256. ACM Press, 2000.Google Scholar
  14. 14.
    F. L. Morris. A time-and space-efficient garbage compaction algorithm. Communications of the ACM, 21(8):662–665, Aug. 1978.Google Scholar
  15. 15.
    D. Sahlin and M. Carlsson. Variable Shunting for the WAM. Technical Report SICS/R-91/9107, SICS, 1991.Google Scholar
  16. 16.
    P. Tarau and U. Neumerkel. A novel term compression scheme and data representation in the binwam. In M. Hermenegildo and J. Penjam, editors, Proceedings of the Sixth International Symposium on Programming Language Implementation and Logic Programming, number 844 in Lecture Notes in Computer Science, pages 73–87. Springer-Verlag, Sept. 1994.Google Scholar
  17. 17.
    H. Touati and T. Hama. A light-weight Prolog garbage collector. In Proceedings of the International Conference on Fifth Generation Computer Systems (FGCS’88), pages 922–930. OHMSHA Ltd. Tokyo and Springer-Verlag, nov/dec 1988.Google Scholar
  18. 18.
    D. H. D. Warren. An abstract Prolog instruction set. Tech. Report 309, SRI, 1983.Google Scholar
  19. 19.
    N.-F. Zhou. Garbage Collection in B-Prolog. In B. Demoen, editor, Proceedings of the First Workshop on Memory Management in Logic Programming Implementations, co-located with CL2000, pages 1–10,, July 2000.

Copyright information

© Springer-Verlag Berlin Heidelberg 2002

Authors and Affiliations

  • Bart Demoen
    • 1
  • Phuong-Lan Nguyen
    • 2
  • Ruben Vandeginste
    • 1
  1. 1.Dept. of Computer ScienceK.U.LeuvenBelgium
  2. 2.Institut de Mathématiques AppliquéesUCOAngersFrance

Personalised recommendations