skip to main content
article
Free Access

Efficient dynamic dispatching with type slicing

Published:01 November 2007Publication History
Skip Abstract Section

Abstract

A fundamental problem in the implementation of object-oriented languages is that of a frugal implementation of dynamic dispatching, that is, a small footprint data structure that supports quick response to runtime dispatching queries of the following format: which method should be executed in response to a certain message sent to a given object. Previous theoretical algorithms for this problem tend to be impractical due to their conceptual complexity and large hidden constants. In contrast, successful practical heuristics lack theoretical support.

The contribution of this article is in a novel type slicing technique, which results in two dispatching schemes: TS and CTd. We make the case for these schemes both practically and theoretically. The empirical findings on a corpus of 35 hierarchies totaling some 64 thousand types from eight different languages, demonstrate improvement over previous results in terms of the space required for the representation, and the time required for computing it.

The theoretical analysis is with respect to ι, the best possible compression factor of the dispatching matrix. The results are expressed as a function of a parameter κ, which can be thought of as a metric of the complexity of the topology of a multiple inheritance hierarchy. In single inheritance hierarchies κ = 1, but although κ can be in the order of the size of the hierarchy, it is typically a small constant in actual use of inheritance; in our corpus, the median value of κ is 5, while its average is 6.4.

The TS scheme generalizes the famous interval containment technique to multiple inheritance. TS achieves a compression factor of ι/κ, that is, our generalization comes with an increase to the space requirement by a small factor of κ. The pay is in the dispatching time, which is no longer constant as in a naive matrix implementation, but logarithmic in the number of different method implementations. In practice, dispatching uses one indirect branch and, on average, only 2.5 binary branches.

The CT schemes are a sequence of algorithms CT1, CT2, CT3, …, where CTd uses d memory dereferencing operations during dispatch, and achieves a compression factor of 1/dι1−1/d in a single inheritance setting. A generalization of these algorithms to a multiple inheritance setting, increases the space by a factor of (2κ)1−1/d. This trade-off represents the first bounds on the compression ratio of constant-time dispatching algorithms. We also present an incremental variant of the CTd suited for languages such as Java.

References

  1. Alpern, B., Cocchi, A., Fink, S., Grove, D., and Lieber, D. 2001. Efficient implementation of Java interfaces: invokeinterface considered harmless. In Proceedings of the 14th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA '01) (Tampa Bay, FL). ACM SINGLAN Notices 38, 11, ACM, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Arnold, P. and Gosling, J. 1996. The Java Programming Language. The Java Series. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Bobrow, D. G., DeMichiel, L. G., Gabriel, R. P., Keene, S. E., Kiczales, G., and Moon, D. A. 1988. Common LISP object system specification. X3J13 Document 88-002R.Google ScholarGoogle Scholar
  4. Bobrow, D. G., Kahn, K., Kiczales, G., Masinter, L., Stefik, M., and Zdybel, F. 1986. CommonLoops: Merging LISP and object-oriented programming. In Proceedings of the 1st Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'86) (Portland, OR), N. K. Meyrowitz, Ed. ACM SIGPLAN Notices 21, 11, ACM, New York, 17--29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Booth, K. S. and Leuker, G. S. 1976. Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms. J. Comput. Syst. Sci. 13, 3 (Dec.), 335--379.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Chambers, C. 1993. The Cecil language, specification and rationale. Tech. Rep. TR-93-03-05, University of Washington, Seattle, WA.Google ScholarGoogle Scholar
  7. Chambers, C. and Chen, W. 1999. Efficient multiple and predicate dispatching. In Proceedings of the 14th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA '99) (Denver, CD). ACM SIGPLAN Notices 34, 10, ACM, New York, 238--255. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Cohen, T. and Gil, J. 2000. Self-calibration of metrics of Java methods. In Proceedings of the 37th International Conference on Technology of Object-Oriented Languages and Systems (TOOLS'00 Pacific) (Sydney, Australia). Prentice-Hall, Englewood Cliffs, NJ, 94--106.Google ScholarGoogle Scholar
  9. Conroy, T. J. and Pelegri-Llopart, E. 1983. An assessment of method-lookup caches for Smalltalk-80 implementations. In Smalltalk-80: Bits of History, Words of Advice. Addison-Wesley, Reading, MA.Google ScholarGoogle Scholar
  10. Cox, B. J. 1986. Object-Oriented Programming---An Evolutionary Approach. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Deutsch, P. and Schiffman, A. 1984. Efficient implementation of the Smalltalk-80 system. In Proceedings of the 11th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'84) (Salt Lake City, VT). ACM, New York, 297--302. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Dietz, P. F. and Sleator, D. D. 1987. Two algorithms for maintaining order in a list. In Proceedings of the 19th Annual ACM Symposium on Theory of Computing (STOC'87), (New York, NY). ACM, New York, 365--372. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Dietzfelbinger, M., Karlin, A. R., Mehlhorn, K., Meyer auf der Heide, F., Rohnert, H., and Tarjan, R. E. 1994. Dynamic perfect hashing: Upper and lower bounds. SIAM J. Comput. 23, 4 (Aug.), 738--761. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Dixon, R., McKee, T., Vaughan, M., and Schweizer, P. 1989. A fast method dispatcher for compiled languages with multiple inheritance. In Proceedings of the 4th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'89), N. K. Meyrowitz, Ed., New Orleans, ACM SIGPLAN Notices 24, 10, ACM, New York, 211--214. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Driesen, K. 1993. Selector table indexing & sparse arrays. In Proceedings of the 8th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'93), A. Paepcke, Ed., (Washington, DC). ACM SIGPLAN Notices 28, 10. ACM, New York, 259--270. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Driesen, K. 1999. Software and hardware techniques for efficient polymorphic calls. Tech. Rep. TRCS99-24, Computer Sciences Department, University of California, Santa Barbara, CA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Driesen, K. and Hölzle, U. 1995. Minimizing row displacement dispatch tables. In Proceedings of the 10th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'95) (Austin, TX). ACM SIGPLAN Notices 30, 10, ACM, New York, 141--155. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Driesen, K. and Hölzle, U. 1996. The direct cost of virtual functions calls in C++. In Proceedings of the 11th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'96) (San Jose, CA). ACM SIGPLAN Notices 31, 10, ACM, New York, 306--323. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Driesen, K., Hölzle, U., and Vitek, J. 1995a. Message dispatch on modern computer architectures. Technical Report TRCS94-20, University of California, Santa Barbara, CA. Comput. Sci,. Feb. 9. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Driesen, K., Hölzle, U., and Vitek, J. 1995b. Message dispatch on pipelined processors. In Proceedings of the 9th European Conference on Object-Oriented Programming (ECOOP'95), W. G. Olthoff, Ed. (Åarhus, Denmark). Lecture Notes in Computer Science, vol. 952. Springer Verlag, New York, 253--282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Dujardin, E. 1996. Efficient dispatch of multimethods in constant time using dispatch trees. Tech. Rep. RR-2892. Inria, Institut National de Recherche en Informatique et en Automatique.Google ScholarGoogle Scholar
  22. Dujardin, E., Amiel, E., and Simon, E. 1998. Fast algorithms for compressed multimethod dispatch table generation. ACM Trans. Prog. Lang. Syst. 20, 1 (Jan.), 116--165. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Eckel, N. and Gil, J. 2000. Empirical study of object-layout strategies and optimization techniques. In Proceedings of the 14th European Conference on Object-Oriented Programming (ECOOP'00) E. Bertino, Ed. (Sophia Antipolis and Cannes, France). Lecture Notes in Computer Science, vol. 1850. Springer Verlag, New York, 394--421. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Ellis, M. A. and Stroustrup, B. 1994. The Annotated C++ Reference Manual. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Ferragina, P. and Muthukrishnan, S. 1996. Efficient dynamic method-lookup for object oriented languages (extended abstract). In Proceedings of the 4th Annual European Symposium on Algorithms (ESA'96) (Barcelona, Spain), J. Díaz and M. J. Serna, Eds. Lecture Notes in Computer Science, vol. 1136. Springer Verlag, New York, 107--120. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Gabow, H. N., Bentley, J. L., and Tarjan, R. E. 1984. Scaling and related techniques for geometry problems. In Proceedings of the 16th Annual ACM Symposium on Theory of Computing (STOC'84) (Washington, DC). ACM Press, New York, 135--143. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Gil, J. and Itai, A. 1998. The complexity of type analysis of object oriented programs. In Proceedings of the 12th European Conference on Object-Oriented Programming (ECOOP'98) E. Jul, Ed. (Brussels, Belgium), Lecture Notes in Computer Science, vol. 1445. Springer Verlag, New York, 601--634. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Gil, J. and Sweeney, P. F. 1999. Space- and time-efficient memory layout for multiple inheritance. In Proceedings of the 14th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA '99) (Denver, CO). ACM SIGPLAN Notices 14, 10. ACM, New York, 256--275. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Goldberg, A. 1984. Smalltalk-80: The Interactive Programming Environment. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Holst, W., Szafron, D., Leontiev, Y., and Pang, C. 1998. Multi-method dispatch using single-receiver projections. Tech. Rep. TR-98-03, University of Alberta, Edmonton, Alb., Canada.Google ScholarGoogle Scholar
  31. Hölzle, U., Chambers, C., and Ungar, D. 1991. Optimizing dynamically-typed object-oriented languages with polymorphic inline caches. In Proceedings of the 5th European Conference on Object-Oriented Programming (ECOOP'91), P. America, Ed. (Geneva, Switzerland). Lecture Notes in Computer Science, vol. 512. Springer Verlag, New York, 21--38. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. ISE. 1997. ISE EIFFEL The Language Reference. ISE, Santa Barbara, CA.Google ScholarGoogle Scholar
  33. Kiczales, G. and Rodriguez, L. 1990. Efficient method dispatch in PCL. In Proceedings of the ACM Conference on LISP and Functional Programming (Nice, France). ACM Press, New York, 99--105. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Muthukrishnan, S. and Müller, M. 1996. Time and space efficient method-lookup for object-oriented programs. In Proceedings of the 7th Soda, Giovanni (SODA'96). Society for Industrial and Applied Mathematics, New York/Philadelphia, 42--51. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Naik, M. and Kumar, R. 2000. Efficient message dispatch in object-oriented systems. ACM SIGPLAN Notices 35, 3 (Mar.), 49--58. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Pang, C., Holst, W., Leontiev, Y., and Szafron, D. 1999. Multi-method dispatch using multiple row displacement. In Proceedings of the 13th European Conference on Object-Oriented Programming (ECOOP'99), R. Guerraoui, Ed. (Lisbon, Portugal). Lecture Notes in Computer Science, vol. 1628. Springer Verlag, New York, 304--328. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Pascal, A. and Royer, J. 1992. Optimizing method search with lookup caches and incremental coloring. In Proceedings of the 7th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'92), A. Paepcke, Ed. (Vancouver, BC, Canada), ACM SIGPLAN Notices 27, 10. ACM, New York, 110--126. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Shalit, A. 1997. The Dylan Reference Manual: The Definitive Guide to the New Object-Oriented Dynamic Language. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Sleator, D. and Tarjan, R. 1985. Self-adjusting binary search trees. J. ACM 32, 3 (July), 652--686. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Stroustrup, B. 1994. The Design and Evolution of C++. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Stroustrup, B. 1997. The C++ Programming Language, 3rd Ed. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. van Emde Boas, P. E. 1977. Preserving order in a forest in less than logarithmic time and linear space. Inf. Proc. Lett. 6, 3, 80--82.Google ScholarGoogle ScholarCross RefCross Ref
  43. van Emde Boas, P. E., Kaas, R., and Zijlstra, E. 1977. Design and implementation of an efficient priority queue. Math. Syst. Theory 10, 99--127.Google ScholarGoogle ScholarCross RefCross Ref
  44. Vitek, J. 1995. Compact dispatch tables for dynamically typed programming languages. M.S. thesis, University of Victoria, Victoria, BC, Canada.Google ScholarGoogle Scholar
  45. Vitek, J. and Horspool, R. N. 1994. Taming message passing: Efficient method look-up for dynamically typed languages. In Proceedings of the 8th European Conference on Object-Oriented Programming (ECOOP'94), M. Tokoro and R. Pareschi, Eds. (Bologna, Italy). Lecture Notes in Computer Science, vol. 821. Springer Verlag, New York, 432--449. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Vitek, J. and Horspool, R. N. 1996. Compact dispatch tables for dynamically typed object oriented languages. In Proceedings of the 6th International Conference on Compiler Construction (CC'96), T. Gyimothy, Ed. (Linköping, Sweden), Lecture Notes in Computer Science, vol. 1060. Springer Verlag, New York, 309--325. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Willard, D. E. 1984. New trie data structures which support very fast search operations. J. Comput. Syst. Sci. 28, 379--394. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Zendra, O., Colnet, D., and Collin, S. 1997. Efficient dynamic dispatch without virtual function tables: The SmallEiffel compiler. In Proceedings of the 12th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'97) (Atlanta, GA). ACM SIGPLAN Notices 32, 10, ACM, New York, 125--141. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Zibin, Y. and Gil, J. 2001. Efficient subtyping tests with PQ-encoding. In Proceedings of the 14th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA '99) (Tampa Bay, FL). ACM SIGPLAN Notices. 36, 11, ACM, New York, 96--107. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Zibin, Y. and Gil, J. 2002. Fast algorithm for creating space efficient dispatching tables with application to multi-dispatching. In Proceedings of the 17th Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA'02) (Seattle, WA). ACM SIGPLAN Notices 37, 11, ACM, New York, 142--160. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Zibin, Y. and Gil, J. 2003. Incremental algorithms for dispatching in dynamically typed languages. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'03) (New Orleans, LA). ACM, New York, 126--138. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Efficient dynamic dispatching with type slicing

        Recommendations

        Reviews

        Chenglie Hu

        In executing an object-oriented program, a data structure needs to be maintained to support a quick response to runtime dispatching queries about which method should be executed when a certain message is sent to a given object. More specifically, given a set of types (for example, a type hierarchy in Java) and a partial order (for example, the transitive closure of the "extends" and "implements" in Java), a dispatching query takes a message and a given type, and returns the smallest type among the types that are smaller than the given type (measured by the partial order). A null result is returned if such a smallest type doesn't exist, or if there are multiple ones. The former would result in a runtime error, whereas, for the latter, a type resolution mechanism has to be provided. A dispatching problem is to encode the type hierarchy in a data structure supporting dispatching queries for every possible message and every type in the type hierarchy. The quality of an algorithm-solving dispatching problem is then measured by the space consumption of the dispatching matrix, the time required to process the query, and the time for generating the data structure from an input type hierarchy. The most obvious solution to the dispatching problem is to form a dispatching matrix where rows and columns are represented by available types and methods (although the order may affect the performance when such a matrix is compressed). The matrix is then used to store the outcomes of all possible dispatching queries. For such a representation, queries are answered by quick indexing operations. However, such dispatching matrices are typically sparse and have a large number of null cells, thus requiring large space consumption at runtime (for example, 8800 types with about 14600 methods can result in a dispatching matrix that needs roughly 500 megabytes of memory). There are two practical ways to compress a dispatching matrix: null (cell) elimination and duplicates elimination (by storing only distinct entries of the matrix). Despite some successful implementations, such as the use of a virtual function table to eliminate null cells, previous algorithms for the dispatching problem are described as either being impractical, due to their complexity and large number of hidden constants, or as having a lack of theoretical foundation. Using type slicing (TS), this paper presents two dispatching techniques for duplicates elimination. The two approaches are close to the optimal compression factor, namely t=(number of rows × number of columns)/(number of different method implementations). The TS algorithm is based on a previously published method known as the linear space containment algorithm. It is capable of dealing with multiple inheritance with an increase in space requirement by a small factor with a varied logarithmic dispatching time of the number of different method implementations. The CTD algorithm uses d steps to achieve a compression rate of 1/(d × t1/d). The advantages of these methods are simple to implement and bear no hidden constants. Finally, empirical studies are reported, and directions for future research are suggested. Dynamic dispatching is one of the fundamental problems that designers of an object-oriented programming language have to address in order to enhance language performance. It will be interesting to see whether the techniques presented in this paper are soon adopted (if ever) in future revisions of popular languages such as Java and C#. Online Computing Reviews Service

        Access critical reviews of Computing literature here

        Become a reviewer for Computing Reviews.

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!