skip to main content
research-article
Free Access

Expressive and modular predicate dispatch for Java

Authors Info & Claims
Published:20 February 2009Publication History
Skip Abstract Section

Abstract

Predicate dispatch is an object-oriented (OO) language mechanism for determining the method implementation to be invoked upon a message send. With predicate dispatch, each method implementation includes a predicate guard specifying the conditions under which the method should be invoked, and logical implication of predicates determines the method overriding relation. Predicate dispatch naturally unifies and generalizes several common forms of dynamic dispatch, including traditional OO dispatch, multimethod dispatch, and functional-style pattern matching. Unfortunately, prior languages supporting predicate dispatch have had several deficiencies that limit the practical utility of this language feature.

We describe JPred, a backward-compatible extension to Java supporting predicate dispatch. While prior languages with predicate dispatch have been extensions to toy or nonmainstream languages, we show how predicate dispatch can be naturally added to a traditional OO language. While prior languages with predicate dispatch have required the whole program to be available for typechecking and compilation, JPred retains Java's modular typechecking and compilation strategies. While prior languages with predicate dispatch have included special-purpose algorithms for reasoning about predicates, JPred employs general-purpose, off-the-shelf decision procedures. As a result, JPred's type system is more flexible, allowing several useful programming idioms that are spuriously rejected by those other languages. After describing the JPred language informally, we present an extension to Featherweight Java that formalizes the language and its modular type system, which we have proven sound. Finally, we discuss two case studies that illustrate the practical utility of JPred, including its use in the detection of several errors.

References

  1. Abelson, H., Dybvig, R. K., Haynes, C. T., Rozas, G. J., IV, N. I. A., Friedman, D. P., Kohlbecker, E., Steele Jr., G. L., Bartley, D. H., Halstead, R., Oxley, D., Sussman, G. J., Brooks, G., Hanson, C., Pitman, K. M., and Wand, M. 1998. Revised report on the algorithmic language Scheme. Higher-Order Symbolic Comput. 11, 1, 7--105. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Agrawal, R., DeMichiel, L. G., and Lindsay, B. G. 1991. Static type checking of multi-methods. In Proceedings of the (OOPSLA'91) Conference on Object-Oriented Programming Systems, Languages and Applications, 113--128. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Arnold, K., Gosling, J., and Holmes, D. 2005. The Java Programming Language, 4th ed. Prentice Hall. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Assaad, M. G. and Leavens, G. T. 2001. Alias-Free parameters in C for better reasoning and optimization. Tech. Rep. 01-11, Department of Computer Science, Iowa State University, Ames, Iowa. November.Google ScholarGoogle Scholar
  5. Barrett, C. and Berezin, S. 2004. CVC Lite: A new implementation of the cooperating validity checker. In Proceedings of the 16th International Conference on Computer Aided Verification (CAV'04), R. Alur and D. A. Peled, Eds. Lecture Notes in Computer Science, vol. 3114. Springer, 515--518.Google ScholarGoogle Scholar
  6. Baumgartner, G., Jansche, M., and Laufer, K. revised March 2002. Half & Half: Multiple dispatch and retroactive abstraction for Java. Tech. rep. OSU-CISRC-5/01-TR08, Department of Computer and Information Science, The Ohio State University.Google ScholarGoogle Scholar
  7. Benzaken, V., Castagna, G., and Frisch, A. 2003. CDuce: An XML-centric general-purpose language. In Proceedings of the 8th ACM SIGPLAN International Conference on Functional Programming. ACM Press, 51--63. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 Conference on Object-oriented Programming Systems, Languages and Applications. ACM Press, 17--29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Boyland, J. and Castagna, G. 1997. Parasitic methods: Implementation of multi-methods for Java. In Proceedings of the OOPSLA'97. ACM SIGPLAN Not. 32, 10, 66--76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Bray, T., Paoli, J., Sperberg-McQueen, C. M., Maler, E., and Yergeau, F. 2006. eXtensible markup language (XML) 1.0 (4th Edition). World Wide Web Consortium recommendation, http://www.w3.org/TR/REC-xml.Google ScholarGoogle Scholar
  11. Castagna, G. 1995. Covariance and contravariance: Conflict without a cause. ACM Trans. Program. Lang. Syst. 17, 3, 431--447. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Castagna, G. 1997. Object-Oriented Programming: A Unified Foundation. Progress in Theoretical Computer Science. Birkhauser, Boston. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Castagna, G., Ghelli, G., and Longo, G. 1995. A calculus for overloaded functions with subtyping. Inf. Comput. 117, 1, 115--135. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Chambers, C. 1992. Object-Oriented multi-methods in Cecil. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP'92), O. L. Madsen, Ed. LNCS 615. Springer-Verlag, 33--56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Chambers, C. 1993. Predicate classes. In Proceedings of the 7th European Conference on Object-Oriented Programming, 268--296. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Chambers, C. 1997. The Cecil language specification and rationale: Version 2.1. www.cs.washington.edu/research/projects/cecil/pubs/cecil-spec.html.Google ScholarGoogle Scholar
  17. Chambers, C. and Chen, W. 1999. Efficient multiple and predicate dispatching. In Proceedings of the 14th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications. ACM Press, 238--255. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Clifton, C. 2001. MultiJava: Design, implementation, and evaluation of a Java-compatible language supporting modular open classes and symmetric multiple dispatch. Tech. rep. 01-10, Department of Computer Science, Iowa State University, Ames, Iowa. November.Google ScholarGoogle Scholar
  19. Clifton, C., Leavens, G. T., Chambers, C., and Millstein, T. 2000. MultiJava: Modular open classes and symmetric multiple dispatch for Java. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'00). ACM SIGPLAN Notices, 35, 10, 130--145. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Clifton, C., Millstein, T., Leavens, G. T., and Chambers, C. 2006. Multijava: Design rationale, compiler implementation, and applications. ACM Trans. Program. Lang. Syst. 28, 3, 517--575. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. CVC3. 2009. The CVC3 home page. http://www.cs.nyu.edu/acsys/cvc3.Google ScholarGoogle Scholar
  22. Detlefs, D., Nelson, G., and Saxe, J. B. 2005. Simplify: A theorem prover for program checking. J. ACM 52, 3, 365--473. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Eclipse. 2007. Eclipse home page. http://www.eclipse.org.Google ScholarGoogle Scholar
  24. Emir, B., Odersky, M., and Williams, J. 2007. Matching objects with patterns. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP), E. Ernst, Ed. Lecture Notes in Computer Science, vol. 4609. Springer, 273--298. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Ernst, M., Kaplan, C., and Chambers, C. 1998. Predicate dispatching: A unified theory of dispatch. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP'98), E. Jul, Ed. Lecture Notes in Computer Science, vol. 1445. Springer, 186--211. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Flanagan, C., Joshi, R., Ou, X., and Saxe, J. B. 2003. Theorem proving using lazy proof explication. In the International Conference on Computer Aided Verification (CAV).Google ScholarGoogle Scholar
  27. Frost, C. and Millstein, T. 2005. Featherweight JPred. Tech. rep. CSD-TR-050038, UCLA Computer Science Department. ftp://ftp.cs.ucla.edu/tech-report/2005-reports/050038.pdf.Google ScholarGoogle Scholar
  28. Frost, C. and Millstein, T. 2006. Modularly typesafe interface dispatch in JPred. In the International Workshop on Foundations and Developments of Object-Oriented Languages(FOOL/WOOD).Google ScholarGoogle Scholar
  29. Gabriel, R. P., White, J. L., and Bobrow, D. G. 1991. CLOS: Integrating object-oriented and functional programming. Commun. ACM 34, 9, 28--38. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Gamma, E., Helm, R., Johnson, R. E., and Vlissides, J. 1995. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Gapeyev, V. and Pierce, B. C. 2003. Regular object types. In Proceedings of the European Conference on Object-Oriented Programming. Lecture Notes in Computer Science, vol. 2743. Springer.Google ScholarGoogle Scholar
  32. Gay, D., Levis, P., von Behren, R., Welsh, M., Brewer, E., and Culler, D. 2003. The NesC language: A holistic approach to networked embedded systems. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM Press, 1--11. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Gosling, J., Joy, B., Steele, G., and Bracha, G. 2005. The Java Language Specification 3rd Ed. Prentice Hall. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Grimm, R. 2002. System support for pervasive applications. Ph.D. thesis, Department of Computer Science and Engineering, University of Washington. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Grimm, R., Davis, J., Lemar, E., Macbeth, A., Swanson, S., Anderson, T., Bershad, B., Borriello, G., Gribble, S., and Wetherall, D. 2004. System support for pervasive applications. ACM Trans. Comput. Syst. 22, 4, 421--486. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Hill, J., Szewczyk, R., Woo, A., Hollar, S., Culler, D. E., and Pister, K. S. J. 2000. System architecture directions for networked sensors. In Proceedings of the Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS'00). 93--104. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Hosking, J. G., Hamer, J., and Mugridge, W. 1990. Integrating functional and object-oriented programming. In Proceedings of the International Conference on Technology of Obeject-Oriented Languages and Systems TOOLS Pacific, 345--355.Google ScholarGoogle Scholar
  38. Igarashi, A., Pierce, B. C., and Wadler, P. 2001. Featherweight Java: a minimal core calculus for Java and GJ. ACM Trans. Program, Lang. Syst. 23, 3, 396--450. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Ingalls, D. H. H. 1986. A simple technique for handling multiple polymorphism. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages and Applications. ACM Press, 347--349. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Kiczales, G., Lamping, J., Menhdhekar, A., Maeda, C., Lopes, C., Loingtier, J.-M., and Irwin, J. 1997. Aspect-Oriented programming. In Proceedings of the 11th European Conference on Object-Oriented (ECOOP'97), M. Akşit and S. Matsuoka, Eds. Lecture Notes on Computer Science, vol. 1241. Springer, 220--242.Google ScholarGoogle Scholar
  41. Leavens, G. T. and Antropova, O. 1999. ACL — Eliminating parameter aliasing with dynamic dispatch. Tech. rep. 98-08a, Department of Computer Science, Iowa State University, Ames, Iowa. February.Google ScholarGoogle Scholar
  42. Lee, K., LaMarca, A., and Chambers, C. 2003. HydroJ: Object-Oriented pattern matching for evolvable distributed systems. In Proceedings of the ACM Conference on Object-Oriented Programming Systems, Languages, and Applications. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Liu, J. and Myers, A. C. 2003. JMatch: Iterable abstract pattern matching for Java. In Proceedings of the International Symposium on Practical Aspects of Declarative Languages (PADL), V. Dahl and P. Wadler, Eds. Lecture Notes in Computer Science, vol. 2562. Springer, 110--127. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Millstein, T. 2003. Reconciling software extensibility with modular program reasoning. Ph.D. thesis, Department of Computer Science and Engineering, University of Washington. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Millstein, T. 2004. Practical predicate dispatch. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'04). Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Millstein, T., Bleckner, C., and Chambers, C. 2002. Modular typechecking for hierarchically extensible datatypes and functions. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP'02). ACM SIGPLAN Not. 37, 9, 110--122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Millstein, T., Bleckner, C., and Chambers, C. 2004. Modular typechecking for hierarchically extensible datatypes and functions. ACM Trans. Program. Lang. Syst. 26, 5, 836--889. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Millstein, T. and Chambers, C. 2002. Modular statically typed multimethods. Inf. Comput. 175, 1, 76--118.Google ScholarGoogle ScholarCross RefCross Ref
  49. Milner, R., Tofte, M., Harper, R., and MacQueen, D. 1997. The Definition of Standard ML (Revised). The MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Moon, D. A. 1986. Object-Oriented programming with Flavors. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages and Applications. ACM Press, 1--8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Nelson, G. and Oppen, D. C. 1979. Simplification by cooperating decision procedures. ACM Trans. Program. Lang. Syst. 1, 2, 245--257. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Nystrom, N., Clarkson, M. R., and Myers, A. C. 2003. Polyglot: An extensible compiler framework for Java. In Proceedings of the 12th International Conference on Compiler Construction (CC). Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. oneworld. 2008. one.world home page. http://cs.nyu.edu/rgrimm/one.world.Google ScholarGoogle Scholar
  54. Orleans, D. 2002. Incremental programming with extensible decisions. In Proceedings of the 1st International Conference on Aspect-Oriented Software Development. ACM Press, 56--64. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Pai, V. S., Druschel, P., and Zwaenepoel, W. 1999. Flash: An efficient and portable Web server. In Proceedings of the USENIX Annual Technical Conference (USENIX-99). USENIX Association, 199--212. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Polyglot for Java 5. Polyglot for Java 5 homepage. http://www.cs.ucla.edu/~milanst/projects/polyglot5.Google ScholarGoogle Scholar
  57. Rémy, D. and Vouillon, J. 1998. Objective ML: An effective object-oriented extension of ML. Theory Practice Object Syst. 4, 1, 27--52. Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. Richard, A. and Lhotak, O. 2008. OOMatch: Pattern matching as dispatch in Java. In International Workshop on Foundations of Object-Oriented Languages.Google ScholarGoogle Scholar
  59. Salcianu, A. and Rinard, M. 2005. Purity and side effect analysis for Java programs. In Proceedings of the 6th International Conference on Verification, Model Checking and Abstract Interpretation. Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. Steele Jr., G. L. 1990. Common Lisp: The Language, 2nd Ed. Digital Press, Bedford, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. Stroustrup, B. 1997. The C++ Programming Language: Third Edition. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. Ucko, A. M. 2001. Predicate dispatching in the common lisp object system. Tech. rep. 2001-006, MIT Artificial Intelligence Laboratory.Google ScholarGoogle Scholar
  63. Welsh, M., Culler, D., and Brewer, E. 2001. SEDA: An Architecture for well-conditioned, scalable internet services. In Proceedings of the 18th ACM Symposium on Operating Systems Principles, G. Ganger, Ed. 230--243. Google ScholarGoogle ScholarDigital LibraryDigital Library
  64. Wright, A. K. and Felleisen, M. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1, 38--94. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Expressive and modular predicate dispatch for Java

                  Recommendations

                  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

                  • Published in

                    cover image ACM Transactions on Programming Languages and Systems
                    ACM Transactions on Programming Languages and Systems  Volume 31, Issue 2
                    February 2009
                    128 pages
                    ISSN:0164-0925
                    EISSN:1558-4593
                    DOI:10.1145/1462166
                    Issue’s Table of Contents

                    Copyright © 2009 ACM

                    Publisher

                    Association for Computing Machinery

                    New York, NY, United States

                    Publication History

                    • Published: 20 February 2009
                    • Accepted: 1 April 2008
                    • Revised: 1 January 2008
                    • Received: 1 April 2007
                    Published in toplas Volume 31, Issue 2

                    Permissions

                    Request permissions about this article.

                    Request Permissions

                    Check for updates

                    Qualifiers

                    • research-article
                    • Research
                    • Refereed

                  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!