Note to Users
Total Page:16
File Type:pdf, Size:1020Kb
NOTE TO USERS This reproduction is the best copy available. ® UMI Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. University of Alberta M u l t ip l e C o d e I n h e r it a n c e in J ava by Maria Cutumisu A thesis submitted to the Faculty of Graduate Studies and Research in partial fulfillment of the requirements for the degree of M aster of Science. Department of Computing Science Edmonton, Alberta Spring 2003 Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. National Library Bsbliotheque nationals of Canada du Canada Acquisitions and Acquisitions et Bibliographic Services services bibliographiques 395 Wellington Street 395, rue Wellington Ottawa ON K1A0N4 Ottawa ON K1A0N4 Canada Canada VourtSe Volm rMmnca Our Be NarmiiHtanet The author has granted a non V auteur a accorde une licence non exclusive licence allowing the exclusive pennettant a la National Libraryof Canada to Bibliotheque narionaledu Canada de reproduce, loan, distribute or sell reprodihre, prdter, distribuer ou copies of this thesis inmicroform, vendre descopies de cette these sous paper or electronic formats. la forme de microfiche/film, de reproduction sur papier ou sur format electronique. The author retains ownershipof the L’auteur conserve la proprietedu copyright in this thesis. Neither the droit d’auteur qui protege cette these. thesis nor substantial extracts from it Ni la these ni des extraits substantiels may be printed or otherwise de celle-cine doivent etreimprimes reproducedwithout the author’s ouautrement reproduits sans son permission. autorisation. 0-612-82266-4 Canada Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. University of Alberta Library Release Form Name of Author: Maria Cutumisu Title of Thesis: Multiple Code Inheritance in Java Degree: Master of Science Year this Degree Granted: 2003 Permission is hereby granted to the University of Alberta Library to reproduce single copies of this thesis and to lend or sell such copies for private, scholarly or scientific research purposes only. The author reserves all other publication and other rights in association with the copyright in the thesis, and except as herein before provided, neither the thesis nor any substantial portion thereof may be printed or otherwise re produced in any material form whatever without the author’s prior written permission. Maria Cutumisu 221 Athabasca Hall University of Alberta Edmonton, Alberta Canada T6G 2E8 D ate: W m / Z -,2.00b Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. University of Alberta Faculty of Graduate Studies and Research The undersigned certify that they have read, and recommend to the Faculty of Graduate Studies and Research for acceptance, a thesis entitled M ulti ple Code Inheritance in Java submitted by Maria Cutumisu in partial fulfillment of the requirements for the degree of M aster of Science. / 1 / V Duane Szafron i f Co-Supervisor Paul Lu Co-Supervisor JoseJNelson Amaral Dennis Ward D ate: A ^C O D J Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. A bstract Java has multiple inheritance of interfaces, but only single inheritance of code. This situation leads to code being duplicated in Java library classes and ap plications. We describe a generalization of a Java Virtual Machine (JVM) to support multiple inheritance of code. Our approach places code in interfaces, without requiring language syntax changes or compiler modifications. In our extended JVM, we use interfaces to represent either new types of interfaces with code or traditional interfaces in Java. We define and implement a super call mechanism resembling the one in C++, in which the programmer can specify an inheritance path to the desired superinterface implementation. We introduce a simple notation for super calls to interfaces. Furthermore, we develop scripts that allow a programmer to use multiple code inheritance with existing Java compilers. We have modified a JVM to support multiple code inheritance. Our imple mentation does not affect the running time or the semantics of standard single inheritance Java programs and executes correctly programs that use multiple inheritance. Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. Acknowledgements During my studies at the University of Alberta, I benefited from the help of my supervisors, colleagues, and friends. I would like to express my gratitude to my supervisors, Duane Szafron and Paul Lu, for the privilege of working with them and for the effort they invested in this research. Their support, enthusiasm, and constant encouragement re sulted in an excellent environment for my research, motivating me to strive towards meeting their standards and expectations. I would like to thank Nelson Amaral and Dennis Ward, also members of my examining committee, for their valuable suggestions that improved my dissertation. I am grateful for having the opportunity to study at the University of Al berta, which enabled me to meet my first friends in Canada in the Computing Science department. I would especially like to thank Steve MacDonald, Matt McNaughton, and Chris Dutchyn for being very helpful every time I needed advice during my research. I would like to acknowledge Anita Petrinjak, Adi Botea, and Akihiro Kishi- moto (Kishi), my friends from the Computing Science department, always with a great sense of humor and with whom I shared the experience of studying in a completely different environment than in our native countries. In the same department, I had the chance to meet Luiza Antonie and Alex Coman, my best friends, always helpful, cheerful, and optimistic. I would like to thank them for their care, understanding, and patience, especially during my thesis writing. I would also like to thank Leo Mocofan, Ernie Novillo, Adrian Driga, .John Anvik, Cam Macdonell, Kai Tan, Peng Zhao, James Redford, Calvin Chan, and Dominique Parker for creating a pleasant environment in the software systems laboratory. There are many other people who had a positive influence 0 1 1 this dissertation. I did not forget them and I would like to thank them all as well. Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. To my family, always supportive. Reproduced with permission of the copyright owner. Further reproduction prohibited without permission. C ontents 1 Introduction 1 1.0.1 A View of Object T y p e s ..................................................... 3 1.0.2 A View of Inheritance ........................................................ 4 1.0.3 Types in P ra c tic e................................................................... 6 1.1 Research Contributions ....................................................................... 7 1.2 Dissertation Organization ................................................................. 8 2 The State of Multiple Inheritance 9 2.1 Problems with Multiple Implementation Inheritance ................... 9 2.1.1 Problem 1: Operation Code Ambiguity .......................... 10 2.1.2 Problem 2: Data Naming Am biguity ............................... 12 2.1.3 Problem 3: Code Layout Ambiguity ................................... 14 2.1.4 Problem 4: Data Layout Ambiguity .................................. 15 2.1.5 Problem 5: Super Call Ambiguity ........................................ 17 2.2 Alternatives to Multiple Inheritance ................................................ 18 2.2.1 Code R ep etitio n...................................................................... 18 2.2.2 D elegation ................................................................................ 20 2.3 Advantages of Multiple Code Inheritance ...................................... 23 2.3.1 Facilitates Code R e-use ......................................................... 23 2.3.2 Supports Separation of Inheritance Concepts.................. 25 2.3.3 Improves Expressiveness and Clarity of Implementation 25 2.4 Existing Multiple Code Inheritance Languages ............................ 26 2.4.1 Ambiguous Name Resolution ........................................... 27 2.4.2 Ambiguous Super Call Resolution ..................................... 28 2.5 Concluding R e m a r k s ........................................................................... 30 3 Method Dispatch in the JVM 33 ■3.1 Overview ................................................................................................... 33 3.2 Method Invocation Mechanism .......................................................... 37 3.3 Object Representation ........................................................................ 39 3.4 The Method Table .............................................................................. 41 3.5 The Virtual Method T a b le ............................................ 43 3.6 The Interface Method T a b l e .............................................................. 46 3.7 Quick Bytecodes .................................................................................. 53 3.8. Concluding R e m a r k s ........................................................................... 56 Reproduced with permission of the copyright owner. Further reproduction prohibited