Elimination of Redundant Polymorphism Queries in Object-Oriented Design Patterns
Total Page:16
File Type:pdf, Size:1020Kb
Elimination of Redundant Polymorphism Queries in Object-Oriented Design Patterns by Rhodes Hart Fraser Brown B.Sc., McGill University, 2000 M.Sc., McGill University, 2003 A Dissertation Submitted in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy in the Department of Computer Science University of Victoria c Rhodes H. F. Brown, 2010 All rights reserved. This thesis may not be reproduced in whole or in part, by photocopy or other means, without the permission of the author. Library and Archives Bibliothèque et Canada Archives Canada Published Heritage Direction du Branch Patrimoine de l’édition 395 Wellington Street 395, rue Wellington Ottawa ON K1A 0N4 Ottawa ON K1A 0N4 Canada Canada Your file Votre référence ISBN: 978-0-494-66827-6 Our file Notre référence ISBN: 978-0-494-66827-6 NOTICE: AVIS: The author has granted a non- L’auteur a accordé une licence non exclusive exclusive license allowing Library and permettant à la Bibliothèque et Archives Archives Canada to reproduce, Canada de reproduire, publier, archiver, publish, archive, preserve, conserve, sauvegarder, conserver, transmettre au public communicate to the public by par télécommunication ou par l’Internet, prêter, telecommunication or on the Internet, distribuer et vendre des thèses partout dans le loan, distribute and sell theses monde, à des fins commerciales ou autres, sur worldwide, for commercial or non- support microforme, papier, électronique et/ou commercial purposes, in microform, autres formats. paper, electronic and/or any other formats. The author retains copyright L’auteur conserve la propriété du droit d’auteur ownership and moral rights in this et des droits moraux qui protège cette thèse. Ni thesis. Neither the thesis nor la thèse ni des extraits substantiels de celle-ci substantial extracts from it may be ne doivent être imprimés ou autrement printed or otherwise reproduced reproduits sans son autorisation. without the author’s permission. In compliance with the Canadian Conformément à la loi canadienne sur la Privacy Act some supporting forms protection de la vie privée, quelques may have been removed from this formulaires secondaires ont été enlevés de thesis. cette thèse. While these forms may be included Bien que ces formulaires aient inclus dans in the document page count, their la pagination, il n’y aura aucun contenu removal does not represent any loss manquant. of content from the thesis. ii Elimination of Redundant Polymorphism Queries in Object-Oriented Design Patterns by Rhodes Hart Fraser Brown B.Sc., McGill University, 2000 M.Sc., McGill University, 2003 Supervisory Committee Dr. R. Nigel Horspool, Supervisor (Department of Computer Science) Dr. Micaela Serra, Departmental Member (Department of Computer Science) Dr. Yvonne Coady, Departmental Member (Department of Computer Science) Dr. Kin F. Li, Outside Member (Department of Electrical and Computer Engineering) iii Supervisory Committee Dr. R. Nigel Horspool, Supervisor (Department of Computer Science) Dr. Micaela Serra, Departmental Member (Department of Computer Science) Dr. Yvonne Coady, Departmental Member (Department of Computer Science) Dr. Kin F. Li, Outside Member (Department of Electrical and Computer Engineering) Abstract This thesis presents an investigation of two new techniques for eliminating redundancy inherent in uses of dynamic polymorphism operations such as virtual dispatches and type tests. The novelty of both approaches derives from taking a subject-oriented perspective which considers multiple applications to the same run-time values, as opposed to previous site-oriented reductions which treat each operation independently. The first optimization (redundant polymorphism elimination { RPE) targets reuse over intraprocedural contexts, while the second (instance-specializing polymorphism elimination { ISPE) considers repeated uses of the same fields over the lifetime of individual object and class instances. In both cases, the specific formulations of the techniques are guided by a study of intentionally polymorphic constructions as seen in applications of common object-oriented design patterns. The techniques are implemented in Jikes RVM for the dynamic polymorphism operations supported by the Java programming language, namely virtual and interface dispatching, type tests, and type casts. In studying the complexities of Jikes RVM's adaptive optimization system and run- time environment, an improved evaluation methodology is derived for characterizing the performance of adaptive just-in-time compilation strategies. This methodology is applied to demonstrate that the proposed optimization techniques yield several significant improvements when applied to the DaCapo benchmarks. Moreover, dramatic improvements are observed for two programs designed to highlight the costs of redundant polymorphism. In the case of the intraprocedural RPE technique, a speed up of 14% is obtained for a program designed to focus on the costs of polymorphism in applications of the Iterator pattern. For the instance-specific technique, an improvement of 29% is obtained for a program designed to focus on the costs inherent in constructions similar to the Decorator pattern. Further analyses also point to several ways in which the results of this work may be used to complement and extend existing optimization techniques, and to provide clarification regarding the role of polymorphism in object-oriented design. iv Contents Supervisory Committee ii Abstract iii Contents iv List of Tables vii List of Figures viii Acknowledgements x Dedication xi 1 Introduction 1 1.1 Eliminating Redundancy in Branching Operations ................... 1 1.2 Redundancy in Polymorphism Queries .......................... 2 1.2.1 Contexts of Redundant Polymorphism ...................... 3 1.3 Simplified Thesis ...................................... 4 1.4 Document Organization .................................. 6 2 Conceptual Foundations 7 2.1 Varieties of Polymorphism ................................ 7 2.2 The Role of Polymorphism in Object-Oriented Design ................. 8 2.2.1 The Origins of Inclusion Polymorphism ..................... 9 2.2.2 The Rise of the Inheritance Paradigm ...................... 9 2.2.3 Polymorphism in Modern Software Design .................... 10 2.2.4 The Role of Polymorphism in Design Patterns . 10 2.3 Inclusion Polymorphism Implementations ........................ 12 2.3.1 The Run-Time Cost of Polymorphism ...................... 14 2.4 Current Approaches to Eliminating Redundant Polymorphism . 15 2.4.1 Static Devirtualization ............................... 16 2.4.2 Speculative Binding and Inlining ......................... 18 2.4.3 Specialization .................................... 20 2.5 Opportunities ........................................ 21 2.5.1 Four Contexts of Redundancy ........................... 21 2.5.2 Detailed Thesis ................................... 22 2.6 Summary .......................................... 26 2.6.1 Contributions .................................... 27 2.6.2 Directions ...................................... 28 v 3 Practical Foundations 30 3.1 Experimental Environment ................................ 30 3.1.1 Compilation and Execution: The Jikes RVM . 31 3.1.2 Evaluation Benchmarks .............................. 33 3.2 Performance Measurement ................................. 37 3.2.1 Measurement Methodology ............................ 39 3.2.2 Baseline Results .................................. 40 3.3 Polymorphism Characteristics ............................... 42 3.3.1 Devirtualization Potential ............................. 42 3.3.2 Polymorphism Query Profiles ........................... 43 3.3.3 Predictions ..................................... 50 3.4 Related Work ........................................ 51 3.5 Summary .......................................... 52 3.5.1 Contributions .................................... 53 3.5.2 Directions ...................................... 55 4 Intraprocedural Redundant Polymorphism Elimination 56 4.1 Problem ........................................... 57 4.1.1 Lessons from the Builder Pattern ........................ 58 4.1.2 Lessons from the Iterator Pattern ....................... 59 4.2 Proposed Solution ..................................... 61 4.2.1 Code Analysis and Transformation ........................ 62 4.2.2 Issues ........................................ 64 4.3 Evaluation .......................................... 67 4.3.1 Experimental Framework ............................. 68 4.3.2 Results ....................................... 69 4.3.3 Commentary .................................... 73 4.4 Related Work ........................................ 74 4.5 Summary .......................................... 77 4.5.1 Contributions .................................... 78 4.5.2 Directions ...................................... 79 5 Instance-Lifetime Redundant Polymorphism Elimination 81 5.1 Problem ........................................... 82 5.1.1 Lessons from the Decorator Pattern ...................... 84 5.1.2 Lessons from the Singleton Pattern ...................... 86 5.2 Proposed Solution ..................................... 87 5.2.1 Code Analysis and Transformation ........................ 87 5.2.2 Issues ........................................ 90 5.3 Evaluation .......................................... 92 vi 5.3.1 Experimental Framework ............................. 93 5.3.2 Results ....................................... 93 5.3.3 Commentary ...................................