Hostname: page-component-78c5997874-fbnjt Total loading time: 0 Render date: 2024-11-10T15:20:17.507Z Has data issue: false hasContentIssue false

Description and Optimization of Abstract Machines in a Dialect of Prolog*

Published online by Cambridge University Press:  05 January 2015

JOSÉ F. MORALES
Affiliation:
IMDEA Software Institute, Madrid, Spain (e-mail: josef.morales@imdea.org, manuel.carro@imdea.org, manuel.hermenegildo@imdea.org)
MANUEL CARRO
Affiliation:
IMDEA Software Institute, Madrid, Spain (e-mail: josef.morales@imdea.org, manuel.carro@imdea.org, manuel.hermenegildo@imdea.org) School of Computer Science, Technical University of Madrid (UPM), Madrid, Spain (email: mcarro@fi.upm.es, herme@fi.upm.es)
MANUEL HERMENEGILDO
Affiliation:
IMDEA Software Institute, Madrid, Spain (e-mail: josef.morales@imdea.org, manuel.carro@imdea.org, manuel.hermenegildo@imdea.org) School of Computer Science, Technical University of Madrid (UPM), Madrid, Spain (email: mcarro@fi.upm.es, herme@fi.upm.es)

Abstract

In order to achieve competitive performance, abstract machines for Prolog and related languages end up being large and intricate, and incorporate sophisticated optimizations, both at the design and at the implementation levels. At the same time, efficiency considerations make it necessary to use low-level languages in their implementation. This makes them laborious to code, optimize, and, especially, maintain and extend. Writing the abstract machine (and ancillary code) in a higher-level language can help tame this inherent complexity. We show how the semantics of most basic components of an efficient virtual machine for Prolog can be described using (a variant of) Prolog. These descriptions are then compiled to C and assembled to build a complete bytecode emulator. Thanks to the high-level of the language used and its closeness to Prolog, the abstract machine description can be manipulated using standard Prolog compilation and optimization techniques with relative ease. We also show how, by applying program transformations selectively, we obtain abstract machine implementations whose performance can match and even exceed that of state-of-the-art, highly-tuned, hand-crafted emulators.

Type
Regular Papers
Copyright
Copyright © Cambridge University Press 2015 

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Footnotes

*

This is a significantly extended and revised version of the paper “Towards Description and Optimization of Abstract Machines in an Extension of Prolog” published in the proceedings of the 2006 International Symposium on Logic-based Program Synthesis and Transformation (LOPSTR'06) (Morales et al.2007).

References

Ait-Kaci, H. 1991. Warren's Abstract Machine, A Tutorial Reconstruction. MIT, Cambridge, MA.Google Scholar
Bueno, F., Deransart, P., Drabent, W., Ferrand, G., Hermenegildo, M., Maluszynski, J. and Puebla, G. 1997. On the role of semantic approximations in validation and diagnosis of constraint logic programs. In Proc. of 3rd International Workshop on Automated Debugging–AADEBUG'97. University of Linköping, Sweden, 155–170.Google Scholar
Carlsson, M. 1991. The SICStus Emulator. SICS Technical Report T91:15, Swedish Institute of Computer Science.Google Scholar
Carro, M., Morales, J., Muller, H., Puebla, G. and Hermenegildo, M. 2006. High-level languages for small devices: A case study. In Compilers, Architecture, and Synthesis for Embedded Systems, Flautner, K. and Kim, T., Eds. ACM Press/Sheridan, New York, NY, USA, 271281.Google Scholar
Casas, A., Cabeza, D. and Hermenegildo, M. 2006. A syntactic approach to combining functional notation, lazy evaluation and higher-order in LP systems. In Proc. of 8th International Symposium on Functional and Logic Programming (FLOPS'06). Fuji Susono, Japan, 142–162.Google Scholar
Codognet, P. and Diaz, D. 1995. WAMCC: Compiling Prolog to C. In Proc. of 12th International Conference on Logic Programming, Sterling, L., Ed. MIT, Cambridge, MA, 317331.Google Scholar
Damas, L. and Milner, R. 1982. Principal type-schemes for functional programs. In Proc. of 9th Annual Symposium on Principles of Programming Languages, New York, NY, USA, 207–212.Google Scholar
Dart, P. and Zobel, J. 1992. A regular type language for logic programs. In Types in Logic Programming. MIT, Cambridge, MA, 157187.Google Scholar
Debray, S., López-García, P. and Hermenegildo, M. 1997. Non-failure analysis for logic programs. In Proc. of International Conference on Logic Programming. MIT, Cambridge, MA, 4862.Google Scholar
Demoen, B., de la Banda, M. G., Marriott, K., Schachte, P. and Stuckey, P. 1998. Global variables in HAL, a logic implementation. CW Reports, CW271. Department of Computer Science, K.U. Leuven, Leuven, Belgium.Google Scholar
Demoen, B. and Nguyen, P.-L. 2000. So many WAM variations, So little time. In Proc. of Computational Logic, Springer-Verlag, 12401254.Google Scholar
Dorward, S., Pike, R., Presotto, D. L., Ritchie, D., Trickey, H. and Winterbottom, P. 1997. Inferno. In Proc. of 42nd IEEE International Computer Conference, IEEE, Washington, DC, USA.Google Scholar
Gallagher, J. and de Waal, D. 1994. Fast and precise regular approximations of logic programs. In Proc. of the 11th International Conference on Logic Programming, Van Hentenryck, P., Ed. MIT, Cambridge, MA, 599613.Google Scholar
Giannesini, F., Kanoui, H., Pasero, R. and Caneghem, M. V. 1985. Prolog. InterEditions, 87 Avenue du Maine, 75014, Paris. ISBN 2-7296-0076-0.Google Scholar
Gosling, J., Joy, B., Steele, G. and Bracha, G. 2005. Java(TM) Language Specification, The (3rd Edition). Addison-Wesley Professional, Boston, MA, USA.Google Scholar
Gudeman, D., Bosschere, K. D. and Debray, S. 1992. jc: An efficient and portable sequential implementation of Janus. In Proc. of Joint International Conference and Symposium on Logic Programming, MIT, Cambridge, MA, 399–413.Google Scholar
Henderson, F., Conway, T. and Somogyi, Z. 1995. Compiling logic programs to C using GNU C as a portable assembler. In Proc. of ILPS 1995 Postconference Workshop on Sequential Implementation Technologies for Logic Programming, Portland, Oregon, 1–15.Google Scholar
Henderson, F. and Somogyi, Z. 2002. Compiling mercury to high-level C code. In Proc. of Compiler Construction, Nigel Horspool, R., Ed. Lecture Notes in Computer Science, vol. 2304. Springer-Verlag, Berlin Heidelberg, 197212.Google Scholar
Hermenegildo, M., Puebla, G. and Bueno, F. 1999. Using global analysis, partial specifications, and an extensible assertion language for program validation and debugging. In The Logic Programming Paradigm: a 25–Year Perspective, Apt, K. R., Marek, V., Truszczynski, M. and Warren, D. S., Eds. Springer-Verlag, Berlin Heidelberg, 161192.Google Scholar
Hermenegildo, M., Puebla, G., Bueno, F. and López-García, P. 2005. Integrated program debugging, verification, and optimization using abstract interpretation (and The Ciao system preprocessor). Science of Computer Programming 58, 12, 115140.CrossRefGoogle Scholar
Hermenegildo, M. V., Bueno, F., Carro, M., López, P., Mera, E., Morales, J. and Puebla, G. 2012. An overview of Ciao and its design philosophy. Theory and Practice of Logic Programming 12, 1–2, 219252. URL: http://arxiv.org/abs/1102.5497.Google Scholar
Hind, M. and Pioli, A. 2000. Which pointer analysis should I use? In Proc. of International Symposium on Software Testing and Analysis, ACM, New York, NY, USA, 113123.Google Scholar
Holmer, B. K. 1993. Automatic design of computer instruction sets. Ph.D. thesis, University of California, Berkeley, CA.Google Scholar
Lattner, C. and Adve, V. 2004. LLVM: A compilation framework for lifelong program analysis & transformation. In Proc. of International Symposium on Code Generation and Optimization (CGO'04), Palo Alto, California.Google Scholar
Morales, J., Carro, M. and Hermenegildo, M. 2004. Improving the compilation of prolog to C using moded types and determinism information. In Proceedings of the 6th International Symposium on Practical Aspects of Declarative Languages, Lecture Notes in Computer Science, vol. 3057. Springer-Verlag, Heidelberg, Germany, 86103.Google Scholar
Morales, J., Carro, M. and Hermenegildo, M. 2007. Towards description and optimization of abstract machines in an extension of prolog. In Logic-Based Program Synthesis and Transformation (LOPSTR'06), Puebla, G., Ed. Lecture Notes in Computer Science, Springer, Berlin, Heidelberg, vol. 4407. 7793.Google Scholar
Morales, J., Carro, M. and Hermenegildo, M. 2008. Comparing tag scheme variations using an abstract machine generator. In 10th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming (PPDP'08), ACM Press, New York, NY, USA, 3243.Google Scholar
Morales, J., Carro, M., Puebla, G. and Hermenegildo, M. 2005. A generator of efficient abstract machine implementations and its application to emulator minimization. In International Conference on Logic Programming, Gabbrielli, M. and Gupta, G., Eds. Lecture Notes in Computer Science, vol. 3668. Springer-Verlag, Berlin Heidelberg, 2136.Google Scholar
Nässén, H., Carlsson, M. and Sagonas, K. 2001. Instruction merging and specialization in the SICStus prolog virtual machine. In Proc. of the 3rd ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, ACM, New York, NY, USA, 4960.Google Scholar
Nori, K. V., Ammann, U., Jensen, K., Nageli, H. H. and Jacobi, C. 1981. Pascal-p implementation notes. In Pascal - The Language and its Implementation, Barron, D. W., Ed. John Wiley, London, UK, 125170.Google Scholar
Paleczny, M., Vick, C. and Click, C. 2001. The Java hotspotTM Server Compiler. Proceedings of the 2001 Symposium on JavaTM Virtual Machine Research and Technology Symposium – Volume 1. JVM'01. USENIX Association. Berkeley, CA, USA.Google Scholar
Puebla, G., Bueno, F. and Hermenegildo, M. 2000a. An assertion language for constraint logic programs. In Analysis and Visualization Tools for Constraint Programming, Deransart, P., Hermenegildo, M. and Maluszynski, J., Eds. Lecture Notes in Computer Science, vol. 1870. Springer-Verlag, Berlin Heidelberg, 2361.Google Scholar
Puebla, G., Bueno, F. and Hermenegildo, M. 2000b. Combined static and dynamic assertion-based debugging of constraint logic programs. In Logic-based Program Synthesis and Transformation (LOPSTR'99). Lecture Notes in Computer Science, vol. 1817. Springer-Verlag, 273292.Google Scholar
Rigo, A. 2004. Representation-based just-in-time specialization and the psyco prototype for python. In PEPM '04: Proc. of the 2004 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, ACM, New York, USA, 1526.Google Scholar
Rigo, A. and Pedroni, S. 2006. PyPy's approach to virtual machine construction. In Dynamic Languages Symposium, ACM, New York, NY, USA.Google Scholar
Santos-Costa, V., Damas, L. and Rocha, R. 2011. The YAP prolog system. Theory and Practice of Logic Programming. URL: http://arxiv.org/abs/1102.3896v1.Google Scholar
Santos-Costa, V., Sagonas, K. and Lopes, R. 2007. Demand-driven indexing of prolog clauses. In Proc. of International Conference on Logic Programming. Lecture Notes in Computer Science, vol. 4670. Springer-Verlag, Berlin Heidelberg, 395409.Google Scholar
Schachte, P. 1997. Global variables in logic programming. In Proc. of International Conference on Logic Programming, MIT, Cambridge, MA, 317.CrossRefGoogle Scholar
Schrijvers, T. and Frühwirth, T. W. 2006. Optimal union-find in constraint handling rules. TPLP 6, 1–2, 213224.Google Scholar
Somogyi, Z., Henderson, F. and Conway, T. 1996. The execution algorithm of Mercury: An efficient purely declarative logic programming language. Journal of Logic Programming 29, 1–3, 1764.Google Scholar
Taivalsaari, A. 1998. Implementing a Java Virtual Machine in the Java Programming Language. Technical Report, Sun Microsystems. Mar. Technical report SMLI TR-98-64.Google Scholar
Tarau, P. 2006. BinProlog 2006 version 11.x Professional Edition User Guide. BinNet Corporation. URL: http://www.binnetcorp.com/.Google Scholar
Taylor, A. 1991. High performance prolog implementation through global analysis. Slides of the invited talk at PDK'91, Kaiserslautern, Germany.Google Scholar
Van Roy, P. 1994. 1983–1993: The wonder years of sequential Prolog implementation. Journal of Logic Programming 19–20, 385441.Google Scholar
Van Roy, P. and Despain, A. 1992. High-performance logic programming with the aquarius prolog compiler. IEEE Computer Magazine, 54–68.Google Scholar
Vaucheret, C. and Bueno, F. 2002. More precise yet efficient type inference for logic programs. In International Static Analysis Symposium, Lecture Notes in Computer Science, vol. 2477. Springer-Verlag, Berlin Heidelberg, 102116.Google Scholar
Warren, D. 1977. Applied logic–-its use and implementation as programming tool. Ph.D. thesis, University of Edinburgh, UK. Also available as SRI Technical Note 290.Google Scholar
Warren, D. H. D. 1983. An abstract prolog instruction set. Technical Report 309, Artificial Intelligence Center, SRI International, 333 Ravenswood Ave, Menlo Park CA 94025.Google Scholar
Wielemaker, J. 2010. The SWI-Prolog User's Manual 5.9.9. URL: http://www.swi-prolog.org.Google Scholar
Zhou, N.-F. 2007. A register-free abstract prolog machine with jumbo instructions. In Proc. of 23rd International Conference on Logic Programming, Dahl, V. and Niemelä, I., Eds. Lecture Notes in Computer Science, vol. 4670. Springer, Berlin Heidelberg, 455457.Google Scholar