Program Sharing: A New Implementation Approach for Prolog

Structure Sharing (SS) and Structure Copying (SC) are two commonly used term representation methods in various Prolog systems. SS was used in earlier Prolog implementations while SC has been accepted as the de facto standard in modern Prolog implementations. Most abstract machines dedicated to Prolog, such as the Warren Abstract Machine(WAM) and the Vienna Abstract Machine(VAM), adopt SC as the fundamental component to implement efficient unification. However, practical comparison of SS and SC shown that programs can be written which make any one method almost arbitrarily worse than the other. In this paper, I propose a new Prolog implementation approach — Program Sharing (PS). The major contribution of this work is that PS has the advantages of both SC (representing terms of different types to fit in the size of a machine word) and SS (low overhead in constructing a dynamic structure instance), and the concept of program sharing could be used to realize all special-case instruction-driven unification. This method has been adopted in the design of a new Prolog abstract machine — the LAM1/2. I have implemented an experimental LAM1/2-emulator in C. Benchmarks show that this new approach is at least as efficient as the WAM-based systems in general while exhibits much better performance to those tasks involving large, complex data structures.