Aspect-Oriented Extensions to HEP Frameworks ¡ P
Total Page:16
File Type:pdf, Size:1020Kb
Aspect-Oriented Extensions to HEP Frameworks ¡ P. Calafiura , C. E. Tull , LBNL, Berkeley, CA 94720, USA Abstract choose to use AspectC++[2], an aspect oriented extension to c++, modeled on the popular aspectJ language[3]. The In this paper we will discuss how Aspect-Oriented Pro- AspectC++ compiler, ac++, weaves aspect code into the gramming (AOP) can be used to implement and extend original c++ sources, and emits standard c++ with a struc- the functionality of HEP architectures in areas such as per- ture suitable for component-based software development. formance monitoring, constraint checking, debugging and ac++ is an open-source, actively developed and supported memory management. AOP is the latest evolution in the project which is near to its first production release1. line of technology for functional decomposition which in- cludes Structured Programming (SP) and Object-Oriented Programming (OOP). In AOP, an Aspect can contribute to Overview of ac++ syntax the implementation of a number of procedures and objects There are several excellent introductions to AOP and is used to capture a concern such as logging, memory concepts[4] and to AspectC++ in particular[5]. Here we allocation or thread synchronization that crosscuts multi- can only provide a quick overview of ac++ syntax, and in- ple modules and/or types. Since most HEP frameworks troduce its fundamental concepts: are currently implemented in c++, for our study we have ¤¦¥§¦©¦ used AspectC++, an extension to c++ that allows the use ¤¦¥¨§¦©¦ ¨ An captures a crosscutting concern. of AOP techniques without adversely affecting software Otherwise behaves very much like a c++ class, defining a performance. We integrated AspectC++ in the develop- scope with access control to its data members and methods ment environment of the Atlas experiment, and we will dis- that can be overloaded or virtual. cuss some of the configuration management issues that may arise in a mixed c++/AspectC++ environment. For each of ¤¦¥§¦©¦ ©¨©¦ ¨ ¦¥ ©¤¨ the concerns we have examined we will discuss how tradi- ¨ ¤!"§#¦!¦ %$¨&'(§¦© )+* tional programming techniques compare to the AOP solu- §¨¤ ©, tion we developed. We will conclude discussing the short $.-/ .0'¦ (¤( '1243! '¦ .¤ '65 and medium term feasibility of introducing AOP, and As- § #/!¦ 7 pectC++ in particular, in the complex software systems of ('(8¥ %9¥:- ©¤¨/;! ':,<>=% .'(8¥ 65 the LHC experiments. ? 5 ASPECT ORIENTED PROGRAMMING '/8 §¦'/8 ¤ .© ¤ (© Aspect Oriented Programming[1] is a methodology in- and @ : An adds behaviour #¦© A'(©CBD¤ A ©6B troduced by Xerox PARC in the late 90s to decom- to an aspect defining what to do and ¤'(8 '/E8§¦'/8 pose problems into functional components (e.g. Object- certain @ s in the control flow. A '¦8§¦'/E8 Oriented classes) and aspects that crosscut functional com- @ is the locus of the code where a certain ac- ponents, such as message logging, thread synchronization, tion occurs (a method is called, a function is executed, a execution tracing. AOP goal is to localize the implemen- variable is set,...). tation of these crosscutting concerns. This is of particu- lar interest to developers of large software systems, such ¤¦¥§¦©¦ ©¨©¦ ¨ ¦¥ ©¤¨F* as HENP frameworks, allowing framework developers to ¤ (© evolve the design of the framework explicit and implied in- .¤!!G<¨H'¦¥ © ¤¨%; terfaces without disrupting the work of component devel- '¦¥¨ ©¤¨I J'(§¦©(¤ 'LKKM<> ('(8¥¨ N ¨O¦¤/1;=H=P;; opers. ¤:/¥Q<JRO¦¤( =G ¤('(87<> ('(8¥¨ F ¨O¦¤(1;SRO¦¤( = * AspectC++ ! ':C<E=LKKTRO¦¤ 65 ? There are about ten actively supported tools available for ? aspect oriented software development. For this study we 5VUU¥¨ ©¤¨!¦8¦© T©W¤¦§/! © ¢ pcalafi[email protected] £ [email protected] 1for this study we used release 0.9pre1 §¦'/E8 ¨ §¦'¦8 ¨ '/8&'¦8 and X API: A is a set information e.g. to control job verbosity or, in on-line ap- '/E8§¦'/8 of logically related @ s that defines when a certain plications, to send messages to the relevant logging pro- ¨ ¤! ¤ .© will run. A pointcut is often allowing to cesses. abstract the definition of when a certain aspect (for example We experimented with a © /¨©¦ ¥ © ¤¨ aspect execution Tracing) will be applied. which intercepts all output to the standard library streams (© ('. and 2 . The aspect can be used in the devel- ¤¦¥¨§¦©¦ ¨ +Y ¤¦ (©%* opment stage to flag these illegal outputs, turning one im- §'/8 S¨ ¦¤!Z©( O¦' /¥[<E=]\F^C5 plicit contract requirement for Gaudi components into an §#/!¦ 7 explicitly enforced one. It can also be used in production ¤ (©]© O¦' ¦¥_<E=` a'/¨#© A'©b<>=* 9¥¨:- © ¤¨ to simply redirect ('( ¦U (© outputs to , us- §E8 Ac<¨H>#© A'©SdHe/¥d/Hd.8QH4B ing the joinpoint reflection API to add the required origin '/8&'¦8 f¥¨: 8¦¤( ©g<E= =Q5 X ? information to the message. ¤ (©]© O¦' ¦¥_<E=` a'/¨F¤A ©`<E=S* '8&'¦E8 ij(©¥/!( 7<E=[B §E8 ¤!¦©7<h O ¥ Interactive Job Configuration X '/E8&'/8 k©¥¨/!. ) §¦©M<E= =[5 X Gaudi allows to invoke a callback function whenever a ? property attribute of an object is set/modified. This al- ? 5 lows for example to modify interactively, from the python ¤¦¥¨§¦©¦ ¨ +Y ¤¦ (©/$E8l¦!(:¥_ a§ #/!¦ "Y ¤¦ (©%* prompt, a cut used by a reconstruction algorithm. To sup- §¦'/E8 ¨ ]© O¦'/¥Q<E=]\ port this, Gaudi requires these property attributes to inherit ©W©¦ ¨ .'(86<HeTe6 meC<¦n nno=HT=p;; from a &'(§¦© ) base class. Unfortunately the majority R4¨ O4E86<f©¨© C<H($¨l!(:'( O7H= =[5 of Gaudi objects does not yet use this &'(§¦© ) -based ? 5 attributes, preferring to use plain data types as !'(8: or '.#/! © as their properties. We tried to use the ¥(© pointcut function of ac++ to in- Y¤¦ (© The aspect above also illustrate part of troduce a callback to properties of arbitrary type using an the rich joinpoint API, which includes static reflec- ¤ A © '/8&'/8 q r¥¨:8¦¤ © advice, which would have been activated after the X tion information such as or value of the attribute is set or reset. Unfortunately the ¥(© '/8&'/8 k©¦¥¨¦!( )§© X as well as handles to active ob- O¤ O4 ¥ pointcut function is not yet supported by ac++. jects such as caller and called objects ( and ), ©¦¥/!( function parameters ( ¤(: ) and return values ( ). Object History Introductions: An aspect can introduce in c++ classes The athena/Gaudi History mechanism keeps track of new methods, data members and even base classes. For ex- which Algorithm component added a data object to the ample one can force a set of classes defined in the pointcut Event Transient Data Store[7]. We experimented with an YO©¤ t' ¤(§s©()¥ to inherit from the class : aspect that extends this mechanism, keeping a complete §¦'/8 / ¨ p¤(§s©)¥Q<>=\4H¨- 8:vuuxw8¥¨: 8¦© 0'(8:[H5 log of every component that created the object or modi- ¤¦¥¨§¦©¦ ¨ + O©¤ -¤ A©L* fied it. The pointcut for this aspect is defined as the union 3 §¨¤( ©6 of all non-const methods of a data object class (including ¤ (©]¤(§s©)¥Q<>=y a#¤¦¥(©¦ !¤¦¥¥Q<hYO©¤ (t'¦=[5 its constructors). ? 5 Reference Management EXAMPLES OF HEP CROSSCUTTING Gaudi allows to use plain c++ pointers to access most of CONCERNS the object managed by the framework, such as data object, services, tools. While using pointers keeps the interface We tried to apply AOP concepts and techniques to our efficient and simple to understand, it leaves the ownership problem domain: large scale HEP software systems. We of the returned objects ambiguous. The implied contract choose Gaudi[6] as a representative HEP component-based with the component developers is that they should never architecture because it has been successfully adopted by take ownership of a data object and that they should always several HEP experiments including the Atlas athena frame- release any tool or service they requested from Gaudi. Us- work [7] that we contributed to develop. ing ac++ it is possible to check these contract requirements Logging 2Unfortunately the ac++ release we used (0.9) did not allow to specify templated joinpoints. Since in recent c++ standard library implementa- In athena/Gaudi all messaging is supposed to happen via tions (e.g. the one that comes with g++ release 3.x) zr{h|~}>~zfro are tem- 9¥:- ©¤ a 9¥:-( ©¤¨ class. allows to classify mes- plate instantiations we were forced to compile our aspect using an older non-templated implementation that came with gcc 2.95. sages according to their origin and severity level. The un- 3this of course assumes that the implementation of the data object and derlying $¨9©¥¥(¤:© -© (© implementation will use this the codes modifying it are const-correct. explicitly, returning an error when a data object is acciden- the past about object-oriented encapsulation and message- tally deleted by a client. It is also possible to release all passing, abstract interfaces and pluggable components. We Gaudi tools and services requested by a component when think that a combination of better development environ- the component is finalized. ments and developer's experience will eventually alleviate this problem. Thread-aware Naming Service Can we Use AOP? All objects in Gaudi are identified by their type4 and by a user-defined instance name. This scheme had to be ex- One of the advantages of using c++ for HENP ap- tended to allow for multiple identical instances of certain plications is the language rich feature set7. Many as- objects (e.g. the Algorithm components) running in multi- pects can be implemented directly in c++ using techniques ple threads: a Gaudi helper class is used to attach the a nu- such as policy-based design using templated wrappers and meric thread identifier to the instance name and to handle namespaces[5]. There are classes of problems, for example it internally. While this works fine, the helper code clutters object references, where using policy templates is simpler, the original (non MT-aware) name-server code. More im- more expressive and just as flexible as using aspects.