010203040506070809101112131415161718Program SPLIT_CLASSBegin-- field to be split.Var Pattern _tmpBeginname = “y”EndVar Iterator field2SplitIter= OrgClass.Fields(_tmp)Module SPLIT_MAIN_PARTITIONBeginEnhClass.Name = OrgClass.Name-- add all fields from the original classVar fieldIter1 = OrgClass.Fields()EnhClass.AddField(fieldIter1)-- remove the fields that’ll go to-- the secondary partition.EnhClass.RemoveField(field2SplitIter).......Figure 10. SER script for ‘split a class to minimize theamount <strong>of</strong> network transfer’ enhancement.01 Program REMOTING02 Beginwhich creates a new iterator by applying a pattern, nameP,03 Module REMOTING_PROXYto an iterator, methodIter. In effect, the one-liner on line04 Begin21 declaratively expresses that the public methods in the05 Var Pattern fieldPnewly-generated EnhClass will have names that start <strong>with</strong>06 Begin“CGLIB”, followed by some random number, and ending07modifiers = "private"<strong>with</strong> the corresponding method’s name in the OrgClass.08type = REMOTING_IFACE.EnhClass.NameFor example, <strong>of</strong> a persistent class has a method named foo,09name = "obj"the generated proxy’s corresponding method could be named10EndCGLIB123foo.11 EnhClass.AddField(fieldP)In essence, SER provides programming support for manipulatingsets <strong>of</strong> methods, constructors, and fields. <strong>An</strong> it-12 .......13 Enderator14representing a set <strong>of</strong> class constructs can be obtainedbased15onModule a pattern.REMOTING_IFACESER has a functional feel in that SERdoes16notBeginallow changing iterators, but rather makes it possibleto derive.......new iterators by applying a pattern to an existingiterator. Also, program constructs can only be added toor removed from EnhClass, thus simplifying the API.SER language summaryFigure 11 summarizes the SER programming constructs.The language follows a minimalistic design, introducingnew constructs only if necessary, <strong>with</strong> the goal <strong>of</strong> makingit easier to learn and understand. SER conveys the enhancementsdeclaratively and does not have explicit conditionalor looping constructs. As a result, a SER script does notcontain a sufficient level <strong>of</strong> detail to be used as input for abytecode enhancer, but it is descriptive enough to documentthe enhancements for source-level programming tools as wediscuss in Section 4.In validating the usability <strong>of</strong> SER, we have documentedfour enhancements used in production and research systems:JDO [37], Hibernate [6], Remoting [46], and Split Class[8, 47]. The scripts describing these enhancements in theirentirety can be downloaded from the project’s website [40].In the discussion above, we have presented only fragments<strong>of</strong> these scripts to demonstrate various language features <strong>of</strong>SER. SER is an interpreted language, and its interpreter canbe integrated into existing programming tools. We discussthe SER interpreter’s design In Section 3.4, and how weused the interpreter to enhance two existing source-levelprogramming tools in Sections 4.2 and 4.3.3.4 SER language interpretationThe purpose <strong>of</strong> documenting enhancements <strong>with</strong> a SERscript is to provide a bi-directional mapping between thesource code <strong>of</strong> a class and its enhanced bytecode representation.The SER interpreter can take either a Java source fileor a bytecode class file as parameters, corresponding to theoriginal or enhanced versions <strong>of</strong> a class, respectively. <strong>An</strong>otherrequired parameter is the SER script associated <strong>with</strong>the input file. Although it would be possible for the interpreterto search for SER scripts based on the input files’names, in the current implementation it uses a configurationfile that specifies which SER files work <strong>with</strong> which Java orSERScriptDescribing the Split Class enhancementSER Script ParserConsider the script depicted in Figure 10, which describes Org.Enh.one <strong>of</strong> the enhancements required to split a class into partitions,01 soProgram that only JDO theUsing fieldsSUPER_JDO_SERused by a remote computation SrcProcessor ProcessorcodeJavaSrc. code BytecodeByte‐be 02 transferred Begin across the network. This enhancement entailsselecting 03 EnhClass.Name a subset <strong>of</strong> fields= <strong>of</strong> OrgClass.Namethe original class and placingthem04intoEnhClass.AddInterfacea newly created class, representing the primarypartition, which("javax.jdo.spi.PersistenceCapable")will be sent across the network. In SER,Enh.Byte‐CodeSymbolTableSymbolicUndoOrg.SrcCodethe05selectionVar<strong>of</strong>Patternthe requiredtmpfields is accomplished by first InfoInfo06 BeginSER Interpreteradding to EnhClass all the fields contained in the originalclass07(Line 15).modifiers<strong>An</strong>d then= the"private"fields intended for the secondarypartition are removed (Line 18).08 EndFigure 12. SER Interpreter.09 Var Itererator fieldIter =OrgClass.Fields(tmp)Accepted 10 to -- OOPSLA add method 2009 that’ll have prefix,8 2009/5/141112-- ‘jdoSet’ or ‘jdoGet’.EnhClass.AddMethod(FieldSetReplacer("jdoSet", fieldIter))
Program script-name1 [Using script-name2]Begin[Module module-name Begin...End]...EndA SER script can include other scripts and can be divided into modules.OrgClass / EnhClassReflective class objects: original and enhanced class.Var Pattern pattern-nameBeginproperty=‘‘value’’...EndPatterns for matching program constructs, based on their properties.Var Iterator iterator-name<strong>An</strong> iterator for a collection <strong>of</strong> program constructs.Constructors/Methods/Fields([pattern-name])Return a collection <strong>of</strong> program constructs, [possibly matching pattern-name]Field[Get/Set]Replacer(prefix, iterator-name)Replace direct accesses to the fields specified by iterator-name<strong>with</strong> getter/setter methods starting <strong>with</strong> prefix, and return them as an iteratoriter-name.CreateNewIterator(pattern-name)Create a new iterator by applying pattern-name to iter-name[Add|Remove]Interface/Superclass/Method/Field([iterator-name|pattern-name])Add or remove program elements specified by iterator-name or pattern-name to or from EnhClassFigure 11. SER language constructs.class files. If the SER file cannot be located, the interpretersignals an error.When processing a SER script, the interpreter parses themain script and all the included scripts specified <strong>with</strong> theUsing keyword. Figure 12 demonstrates the interpreter’sprocess flow, which differs depending on the type <strong>of</strong> theinput file used to parameterize the interpreter.If a Java source file, containing the original source code,is passed to the interpreter, the file is processed using theEclipse JDT API [15]. Then the enhancement informationprocessed by the SER parser is combined <strong>with</strong> the one <strong>of</strong> theoriginal Java source. The result is stored into a symbol tablemodule that implements a quick lookup mechanism capable<strong>of</strong> retrieving, in constant time, all the enhancements appliedto a given program construct. Finally, an external API to thesymbol table makes it possible to retrieve the enhancementinformation. In summary, the API uses JDT AST constructsas lookup keys to retrieve the enhancements associated <strong>with</strong>them. For example, sending a class object as a parameter willreturn a list <strong>of</strong> lists, containing the methods, constructors,and fields that the bytecode enhancer adds to this class. Ofcourse, some <strong>of</strong> these lists could be empty.If a binary class file, containing the enhanced bytecode,is passed to the interpreter, the file is processed using theJavassist library [38]. Then the enhancement informationprocessed by the SER parser is combined <strong>with</strong> the one <strong>of</strong> theenhanced bytecode. The result is stored in a format that wecall Symbolic Undo, which is a collection <strong>of</strong> instructions thatcan be used to map every enhancement back to the originalsource code. We will detail the exact format <strong>of</strong> SymbolicUndo when we discuss a symbolic debugger for enhancedprograms that we implemented as a case study.4. Case Studies: Enhancements-Aware<strong>Programming</strong> <strong>Tools</strong>To evaluate the applicability <strong>of</strong> our approach, we have augmentedtwo existing source-level programming tools <strong>with</strong> anawareness <strong>of</strong> bytecode enhancements. Specifically, we haveadded a new browsing view to a widely-used source codeeditor to present the bytecode enhancements applied to theprogram constructs <strong>of</strong> the displayed compilation unit. Wehave also created a new debugging architecture that enablesa symbolic debugger running an enhanced program to dis-Accepted to OOPSLA 2009 9 2009/5/14