10.07.2015 Views

Enhancing Source-Level Programming Tools with An Awareness of ...

Enhancing Source-Level Programming Tools with An Awareness of ...

Enhancing Source-Level Programming Tools with An Awareness of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.1 Structural EnhancementsIntermediate code enhancement is concerned <strong>with</strong> structuralchanges, which are large scale program transformations. Thepurpose <strong>of</strong> SER is to document structural enhancements insufficient enough detail to improve the precision and utility<strong>of</strong> source-level programming tools that manipulate the originalsource code <strong>of</strong> an enhanced program. To ensure that SERprovides the requisite facilities for expressing common intermediatecode enhancements, we first catalog and classifycommon structural enhancements.To determine what constitutes a structural enhancement,we have reverse-engineered several industrial and researchsystems that use bytecode enhancement. 2 In addition, wehave also examined the capabilities <strong>of</strong> two major Java bytecodeengineering libraries Apache BCEL[2] and Javassist[38].Structural enhancements are the subset <strong>of</strong> general programtransformations that affect the structure <strong>of</strong> an objectorientedprogram, including classes, methods, and fields, aswell as limited changes to method bodies. Structural enhancementsto method bodies are primarily confined to replacingdirect field accesses <strong>with</strong> setter and getter methodsas well as <strong>with</strong> other wrapper methods.A more strict definition <strong>of</strong> structural enhancement is asfollows. Modify a program, confining the set <strong>of</strong> changes tothe following operations:• Adding a new class or interface.• Changing the type <strong>of</strong> a class or an interface (i.e., changingthe parent interfaces and/or classes)• Adding a new method or field• Removing a method or field• Changing the signature <strong>of</strong> a method (e.g., adding or removingparameters or changing the return type).• Changing the type <strong>of</strong> a field• Replacing direct field accesses <strong>with</strong> setter/getter methods3.2 Semantics <strong>of</strong> Structural EnhancementsNext we provide a more formal treatment <strong>of</strong> the programtransformations that constitute the structural enhancementoperations commonly applied to intermediate code.Figure 5 lists the symbols that we use in describing theenhancement operations, <strong>with</strong> the sets <strong>of</strong> transformed programconstructs appearing first. The original program consists<strong>of</strong> a set <strong>of</strong> classes. During the enhancement, new classescan be generated and added to the program. In the originalprogram, a class can implement some interfaces. <strong>An</strong> enhancercan add new interfaces to the set <strong>of</strong> implemented interfacesand can also change the super class. Methods and2 Reverse-engineering these systems is perfectly legal, as they follow anopen-source development model. Reverse- engineering enhanced bytecodeturned out to be more effective than understanding the source code <strong>of</strong> theenhancers.fields can be added to and removed from a class. Finally, existingmethods can serve as templates for other methods. Werefer to this operation as “replication.” For example, a newwrapper method could be created based on some existingmethod–the new method will have the same signature, but adifferent name. There are no explicit constructs for changinga field or a method–this transformation can be expressedby removing the old version and subsequently adding a newone.Figure 6 demonstrates the semantics <strong>of</strong> structural enhancementoperations using set operations. Adding new programelements to existing ones is described using ∪, the setunion operator. Removing program elements is described using\, the set difference operator. Replicating program elementsis described using ↦→ and ∪, which designate a newelement being created based on some existing element andadded to the set, but the existing element still remaining inthe set.A set <strong>of</strong> original classes, C = {c 1 , c 2 , . . . , c n }A set <strong>of</strong> added classes, C + = {c + 1 , c+ 2 , . . . , c+ n }A set <strong>of</strong> original interfaces, I = {i 1 , i 2 , . . . , i n }A set <strong>of</strong> added interfaces, I + = {i + 1 , i+ 2 , . . . , i+ n }A set <strong>of</strong> original methods, M = {m 1 , m 2 , . . . , m n }A set <strong>of</strong> replicated methods, M ′ = {m ′ 1, m ′ 2, . . . , m ′ n}A set <strong>of</strong> added methods, M + = {m + 1 , m+ 2 , . . . , m+ n }A set <strong>of</strong> removed methods, M − = {m − 1 , m− 2 , . . . , m− n }A set <strong>of</strong> original fields, F = {f 1 , f 2 , . . . , f n }A set <strong>of</strong> added fields, F + = {f + 1 , f + 2 , . . . , f + n }A set <strong>of</strong> removed fields, F − = {f − 1 , f − 2 , . . . , f − n }〈c〉p denotes a class c <strong>of</strong> program p〈C〉p denotes a set <strong>of</strong> classes C <strong>of</strong> program p〈i〉c denotes a interface i implemented by class c〈I〉c denotes a set <strong>of</strong> interfaces I implemented by class c〈m〉c denotes a method m <strong>of</strong> class c〈M〉c denotes a set <strong>of</strong> methods M <strong>of</strong> class c〈f〉c denotes a field f <strong>of</strong> class c〈F 〉c denotes a set <strong>of</strong> fields F <strong>of</strong> class cext denotes class inheritance relationshipimpl denotes interface inheritance relationship3.3 SER Language DesignFigure 5. Syntax definitionThe Structural Enhancement Rules (SER) language is adeclarative, domain-specific language that was designed tobe easy to learn, use, and understand. To show how SER canserve as an effective medium for expressing intermediatecode enhancements, we introduce it by example.Accepted to OOPSLA 2009 5 2009/5/14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!