Semi-Automatic Program Partitioning
Total Page:16
File Type:pdf, Size:1020Kb
Instituto Tecnológico y de Estudios Superiores de Monterrey Campus Monterrey School of Engineering and Sciences Semi-Automatic Program Partitioning A dissertation presented by Priscila Angulo López Submitted to the School of Engineering and Sciences in partial fulfillment of the requirements for the degree of Doctor of Philosophy In Information Technologies and Communications Major in Computer Science Monterrey, Nuevo León, December 5th, 2017 Declaration of Authorship I, Priscila Angulo López, declare that this dissertation titled, Semi-Automatic Program Partitioning and the work presented in it are my own. I confirm that: • This work was done wholly or mainly while in candidature for a research degree at this University. • Where any part of this dissertation has previously been submitted for a degree or any other qualification at this University or any other institution, this has been clearly stated. • Where I have consulted the published work of others, this is always clearly attributed. • Where I have quoted from the work of others, the source is always given. With the exception of such quotations, this dissertation is entirely my own work. • I have acknowledged all main sources of help. • Where the dissertation is based on work done by myself jointly with others, I have made clear exactly what was done by others and what I have contributed myself. Priscila Angulo López Monterrey, Nuevo León, December 5th, 2017 ©2017 by Priscila Angulo López All rights reserved Dedication A mi amada madre. Acknowledgements This was a long endeavor, accompanied by added trials, as life usually goes. However, the best part is that it allowed me to be the recipient of exceptional encouragement, support and love from a large number of generous and kind persons. I would like to mention them in chronological order. Professor Guillermo Jiménez, who has been my supporter since before this endeavor and, planted this Ph. D. idea in my mind, thank you for opening my eyes to a world of oppor- tunities that I never thought were within my reach. Luis, thank you for pushing me to be brave and assertive. Mom and Dad, thank you for your unconditional love, for being my pillars, and for helping me to stand up after every fall, I love you both. Rosy Sandoval, thank you for your long and loyal friendship. You are my family, my home. Thank you for your unconditional love. Professor Lorena Gómez, thank you for being my mentor and my friend. You further set me in the right direction. Thank you Manuel Rodríguez, my dear friend. You are my example of endurance and resilience. Pablo Mazzucchi and Mónica Muñoz, thank you for every piece of advice, and for extending your home’s warmth to me. Marcel Váldez, you are a great example of quality and excellence. Thank you for teaching me how to be thorough. Rachel Lloyd, now Rachel Ahn, my best friend, thank you for your kindness, generosity and constant love. Carl W. Handlin, your friendship and support ar- rived at the most critical moment, thank you for being my friend and the best teammate. Néstor Vázquez, I admire you and deeply appreciate every perspective-giving conversation we have. José Luis Leal, thank you for listening to me and giving me strength every time I needed it. Eduardo González, thank you for your support and for always being full of em- pathy. Seth Beinhart, thank you for your constant support and endless encouragement. Mariel Mariscal, my dear cousin, confidant, my shoulder to lean on: You are irreplaceable. Fernando Reyes, thank you for your encouragement and your positivism. Don and Karen Batory, my Austin adoptive parents, thank you for embracing me, comforting me, bearing with me, and for making me the object of your warmth and kindness. Mireya Almaraz, my little sister I never had, thank you for your example of perseverance and your loving sup- port. Ana Rodríguez, thank you my friend for your generosity and our reassuring conver- sations. Fernando Sánchez, Pedro Pérez and Tiago Damasceno, thank you my friends for your support and company. Kennedy C. Brown, thank you for your support, your friend- ship, and being my affirmative company during stressful times. Vandana Gunupudi, thank you my friend for every time you gave me reassurance and inspired strength in me. Deven Desai, thank you for your friendship and constant words full of empathy and considera- tion. I regret that I can only list each of your names once, as you have each helped me not once, but a multitude of times. Thank you. Abstract Partitioning a program into features is a fundamental problem in both Software Product Line (SPL) and object-oriented framework research. An SPL is a family of related programs that are created and differentiated by features – incre- ments in program functionality. An extractive way to create an SPL is to refactor a legacy program into a stack of feature modules or layers. We developed BttF, a tool that infers the feature membership of all package, class, and member declarations of a Java program from facts given by a program expert. BttF recognizes hooks to be methods that defy clas- sical layering in that they reference declarations of layers/feature modules that are added in the future. The information collected by BttF is used to feature-annotate the program, giving it a feature-based design. Doing so enables optional or unnecessary features to be removed from the program’s codebase to produce subprograms, the beginnings of an SPL. Case studies validate BttF, the best result yielded by our experiments show that BttF is ca- pable of inferring the assignment of over 80% of a program’s declarations, this means that less than 20% of the assignments were provided as facts by an expert. An object-oriented framework is a two-tiered structure: a framework (consisting of many abstract classes) that encode common and shared behavior in a domain of applications, and a plug-in (having a concrete class for each framework abstract class) to complete an application. Refactoring a legacy application into a framework and plug-in is a common activity. Surprisingly, tools to perform this task are absent, even though frameworks have been in use for 25 years. After all this time, it remains a tedious, error-prone, and manual task. Two tools are needed: one that determines how classes of a legacy application and their members are partitioned across a framework and plug-in, and which methods are hooks. A second tool takes this partitioning information as input and runs a refactoring script that invokes refactorings programmatically to transform the legacy application into a framework and a plug-in. R3 is a new refactoring engine for Java that supports the writing of transformation scripts [51]. We present the integration of BttF and R3 to cover this need, and evaluate this integration by effectively transforming a set of six Java programs into a framework and plug-in structure. Furthermore, we use BttF as a tool to identify features in a non-object-oriented environ- ment: Multi-Agent Systems (MAS). This active research area has started to see some efforts to integrate SPL concepts and technologies, however, identifying features in existing MAS was a problem not being addressed. BttF was successfully used to identify features on six MAS simulators developed on GAMA platform. v List of Figures 2.1 Classical Software Layers. .4 2.2 Illustrates OO layering. .5 2.3 A Legacy Program Telescoped from Figure 2.2. .6 2.4 Differences between private and fprivate....................7 2.5 Differences between public and fprivate.....................8 2.6 Basic Framework and Plug-in Organization. 10 2.7 Two-Step Splitting of Class C1............................. 11 2.8 An R3 MoveAndDelegate Refactoring. 12 3.1 CRG of Java Complex Class . 15 3.2 BttF MainPath ..................................... 17 3.3 BttF’s Possibility Offerings for a Declaration e ................... 20 3.4 Hook Example . 22 3.5 A Field Initialization Expression . 22 3.6 Risk of wrong assignment . 23 3.7 fprivate possibilities. Case 1. 28 3.8 fprivate possibilities. Case 2. 28 3.9 fprivate possibilities. Case 3. 29 3.10 fprivate possibilities. Case 4. 30 3.11 Example: Assigning a method. 31 3.12 Inference 1. fprivate Propagation . 35 3.13 Inference 1. fprivate Propagation Caveats . 36 3.14 Inference 2. fprivate Container . 37 vii 3.15 Inference 3. References flow across features . 39 3.16 Simple CRG. 39 4.1 BttF as Eclipse’s plugin . 45 4.2 A .bttf file. ....................................... 45 4.3 A BttFcsv file....................................... 46 4.4 A BttF’s error log file. 47 4.5 Operations Java Program Source Code . 48 4.6 Operations Java Program . 49 4.7 Partition Operations Program . 49 4.8 BttF’s More Information about a Declaration. 50 4.9 Field Int.v’sCRG .................................... 51 4.10 The @Feature Annotation Type . 54 4.11 @Feature Annotations and an R4 Projection . 54 4.12 Operations Java program source code annotated. 55 4.13 Operations Java program structure with added R4Feature........... 56 5.1 RQ1. Correlation between Last feature size percentage and BttF’s Inference rate............................................. 63 5.2 Assignment Order vs. Number of Possibilities . 68 6.1 C1. Problem with partitioning superclasses. 77 6.2 Lift constructor calls. 86 6.3 Problem refactoring a hook method. 87 6.4 Framework+Plugin structure of a hook method. 88 6.5 Framework+Plugin structure for a public constructor. 88 7.1 GAMA IDE. 94 7.2 The @Feature Annotation Type . 95 7.3 GAMA refresh metadata option. 96 A.1 Refactoring process . 108 A.2 Transformation process . 109 C.1 Calc Java Program. Original class diagram. 117 C.2 Calc Java Program.