SlideShare a Scribd company logo
1 of 30
Pluggable Aspect Instantiation
           Models
        Victor Trakhtenberg
    The Open University of Israel

           Joint Work With
          David H. Lorenz
Aspect Instantiation Models (AIMs)
• What is an aspect?
  – Crosscutting behavior + crosscutting state
• What is an AIM?
  – 6 keyword in AspectJ: issingleton, pertarget, perthis,
    percflow, percflowbelow, pertypewithin.
  – Added incrementally to AspectJ
  – More AIMs in other AOP languages
• There is a need for custom AIMs
  – Challenge: decouple the definition of AIMs from the
    evolution of the language

                                                  The Open University of Israel
Contribution of this Work
• Pluggable Aspect Instantiation Models
    – Make AIMs pluggable!
❶   Language extension
    – We introduce a new keyword: ‘perscope’
       • Replaces the exiting 6 keywords
       • Eliminates need for new keywords (hopefully)
❷   Interface for defining AIMs
    – Third parties can design and implement new AIMs
❸   Library of AIM Implementations
    – Fully implemented in ajc
                                                 The Open University of Israel
Outline
•   Introduction
•   Requirements
•   Example
•   Pluggable Mechanism
•   Conclusion




                            The Open University of Israel
Motivation: “caching and auditing”
• Industrial Case Study
  – Web application development with AspectJ
  – Need for ‘persession’ and ‘perconversation’ AIMs

                                    Cache
                 Cache



                            Cache           Cache
                Cache




                                                    The Open University of Israel
Current Solution
• Wait for a new release of AspectJ
  – May take awhile…
• Modify the current ajc compiler
  – Sisyphean, complex task
• Manage the state manually
  – Tangled and scattered code




                                      The Open University of Israel
Desired Solution


    1.           Pluggable          5.
Extensible          AIM          Flexible
                 Mechanism

    2.
Declarative                            4.
                       3.          Efficient
                   Expressive



                                 The Open University of Israel
Requirement 1: Extensible
• New AIMs can be introduced
  – Perthread                                        Perthread
  – Persession
• Pre-defined AIMs can be refined
                                                     Per Recent
  – Perthread that was started in the last hour
                                                       Thread
• Generic AIMs can be offered by
  – Third-party providers
  – AspectJ developers



                                                  The Open University of Israel
Requirement 2: Declarative
• Easy to use
  – Like AspectJ
• AIMs implementation may vary
  independently of their use
  – Unlike AspectJ
                                      AspectJ
  public aspect MyAspect
        perthis(myPointcut()){
  }

                                     perscope
 public aspect MyAspect
       perscope(Perthis, myPointcut()){
 }
                                          The Open University of Israel
Requirement 2: Declarative
• Easy to use
  – Like AspectJ
• AIMs implementation may vary
  independently of their use
  – Unlike AspectJ



   New keyword       Class implements AIM

                                            perscope
 public aspect MyAspect
       perscope(Perthis, myPointcut()){
 }
                                               The Open University of Israel
Requirement 3: Expressive
• Practical
  – Realistically complex AIMs can be defined
  – E.g., perconversation
• AspectJ compatible
  – Can implement all 6 AspectJ AIMs




                                                The Open University of Israel
Requirement 4: Efficient
• Weaving
  – Implemented by bytecode weaving
• Runtime performance
  – Generate the same bytecode as AspectJ
    for the 6 AspectJ AIMs




                                            The Open University of Israel
Requirement 5: Flexible
• Static AIM implementation
  – Same woven performance as AspectJ
• Dynamic AIM implementation
  – Encourages experimenting with AIMs




                                         The Open University of Israel
Outline
•   Introduction
•   Requirements
•   Example
•   Pluggable Mechanism
•   Evaluation
•   Conclusion



                            The Open University of Israel
Example: Global Caching

                        Aspect




public aspect GlobalCaching      AspectJ and perscope
       extends SimpleCaching {
}


                                             The Open University of Israel
Example: Perclient Caching
              Aspect        Aspect        Aspect



             Aspect



                                          AspectJ
public aspect PerClientCaching extends SimpleCaching
       perthis (cachedOperation(Object)) {
}

                                          perscope
public aspect PerClientCaching extends SimpleCaching
       perscope(Perthis, cachedOperation(Object)) {
}
                                          The Open University of Israel
Example: Perconversation Caching
                                 Aspect
                 Aspect




               Aspect           Aspect



public aspect PerConversationCaching
       extends SimpleCaching              perscope
       perscope(Perconversation,
              cachedOperation(Object)){
}


                                           AspectJ



                                          The Open University of Israel
Outline
•   Introduction
•   Requirements
•   Example
•   Pluggable Mechanism
    – Dynamic
    – Static
• Evaluation
• Conclusion

                            The Open University of Israel
Dynamic Implementation
• Implement the DynamicPerscope interface
• Specify how the aspect instance should be
  bound, retrieved, and queried
 public interface DynamicPerscope {
        void bindAspect(Object aspekt, Object object);
        Object aspectOf(Class<?> aspectType, Object
 object);
        boolean hasAspect(Class<?> aspectType, Object
 object);
 }




                                             The Open University of Israel
DynamicPerscope: usage

public aspect PerThreadCaching extends SimpleCaching
       perscope(Perthread, cachedOperation(Object)) {
}




                                            The Open University of Israel
DynamicPerscope: implementation
public class Perthread implements DynamicPerscope {
  private static ThreadLocal<Object> theAspect =
       new ThreadLocal<Object>();

    public void bindAspect(Object aspekt, Object o) {
      if (theAspect.get() == null) {
        theAspect.set(aspekt);
    }
         }
    public Object aspectOf(Class<?> aspectType, Object o) {
         return theAspect.get();
    }

    public boolean hasAspect(Class<?> aspectType, Object o){
      return theAspect.get() != null;
    }
}


                                                 The Open University of Israel
Static Implementation
• Bytecode manipulation
  – Harder to implement
  – Capable of producing efficient code
• StaticPerscope interface
  – Hard-wired weaving code replaced with calls to the
    StaticPerscope interface




                                                The Open University of Israel
DynamicPerscope vs. StaticPerscope
• DynamicPerscope
  – Regular Java code
  – Intended for regular infrastructure programmers
• StaticPerscope
  – More complex
  – More efficient
  – Intended for advanced infrastructure programmers


Note: these trade-offs are transparent to the
end user of AIM
                                               The Open University of Israel
Outline
•   Introduction
•   Requirements
•   Example
•   Pluggable Mechanism
•   Evaluation
•   Conclusion



                            The Open University of Israel
Evaluation
• Implementing AspectJ built-in AIMs
  – Caching example
  – Law of Demeter (AspectBench compiler distribution)
• Implementing Non-AspectJ AIMs
  – AspectS cflow advice activations
  – JAsCo perthread AIM
  – persession and perconversation




                                               The Open University of Israel
Threats to Validity
• Implemented only for the ajc compiler
  – Language feature
• AspectJ AIMs were tested on two examples
  – Same bytecode is generated
•  AIMs that cannot be implemented using
  perscope
  – Always true
                       AspectJ       Other AOP
                                     Languages


                  perscope       Custom


                                                 The Open University of Israel
Outline
•   Introduction
•   Requirements
•   Example
•   Pluggable Mechanism
•   Evaluation
•   Conclusion



                            The Open University of Israel
Related Work
• Perscope vs. JAsCo
  – IAspectFactory is used at runtime for aspect instantiation
  – With perscope two choices: DynamicPerscope or
    StaticPerscope
• Perscope vs. Caesar
  – In Caesar aspect instantiated explicitly
  – With perscope – implicitly according to aspect declaration
    as in AspectJ




                                                  The Open University of Israel
Conclusion
• With perscope AIMs are pluggable
• New keyword ‘perscope’ is introduced
• Usage of AIMs is declarative
  – As in AspectJ
• AIMs may be provided by third-parties
  – Different than AspectJ




                                    The Open University of Israel
Thank You!
• Questions?

• Contact information:
  Software Engineering Research Lab
  Open University of Israel
  Email:
      • lorenz@openu.ac.il
      • victortr75@gmail.com
  URL:
      • http://aop.cslab.openu.ac.il/research/perscope/
                                                The Open University of Israel

More Related Content

Similar to Sc11 presentation 2001_06_28

Nashorn in the future (English)
Nashorn in the future (English)Nashorn in the future (English)
Nashorn in the future (English)Logico
 
DAWN and Scientific Workflows
DAWN and Scientific WorkflowsDAWN and Scientific Workflows
DAWN and Scientific WorkflowsMatthew Gerring
 
Machine Learning for Everyone
Machine Learning for EveryoneMachine Learning for Everyone
Machine Learning for EveryoneAly Abdelkareem
 
Java Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertJava Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertEclipse Day India
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAhmed Abbadi
 
JAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptJAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptTrinity Dwarka
 
Eclipse e4 - Google Eclipse Day
Eclipse e4 - Google Eclipse DayEclipse e4 - Google Eclipse Day
Eclipse e4 - Google Eclipse DayLars Vogel
 
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...mfrancis
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptxmadan r
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-finalMarcus Lagergren
 
Wf4Ever: Work!ows for Methodology and Science Preservation
Wf4Ever: Work!ows for Methodology and Science PreservationWf4Ever: Work!ows for Methodology and Science Preservation
Wf4Ever: Work!ows for Methodology and Science PreservationJoint ALMA Observatory
 
Usability_Presentation
Usability_PresentationUsability_Presentation
Usability_PresentationXuan Guo
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
Practical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint ProgrammingPractical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint Programminged271828
 
Generating NoSQL from SQL
Generating NoSQL from SQLGenerating NoSQL from SQL
Generating NoSQL from SQLPeter Milne
 
Introduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-SeqIntroduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-SeqEnis Afgan
 

Similar to Sc11 presentation 2001_06_28 (20)

Nashorn in the future (English)
Nashorn in the future (English)Nashorn in the future (English)
Nashorn in the future (English)
 
DAWN and Scientific Workflows
DAWN and Scientific WorkflowsDAWN and Scientific Workflows
DAWN and Scientific Workflows
 
Machine Learning for Everyone
Machine Learning for EveryoneMachine Learning for Everyone
Machine Learning for Everyone
 
CS3391 OOP UT-I T2 OBJECT ORIENTED PROGRAMMING PARADIGM.pptx
CS3391 OOP UT-I T2 OBJECT ORIENTED PROGRAMMING PARADIGM.pptxCS3391 OOP UT-I T2 OBJECT ORIENTED PROGRAMMING PARADIGM.pptx
CS3391 OOP UT-I T2 OBJECT ORIENTED PROGRAMMING PARADIGM.pptx
 
Core Java Presentation
Core Java PresentationCore Java Presentation
Core Java Presentation
 
Java Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertJava Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley Lambert
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
JAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptJAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP Concept
 
Eclipse e4 - Google Eclipse Day
Eclipse e4 - Google Eclipse DayEclipse e4 - Google Eclipse Day
Eclipse e4 - Google Eclipse Day
 
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...
Town Hall - Business Implications of Open Source OSGi Implementations - BJ Ha...
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptx
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-final
 
Wf4Ever: Work!ows for Methodology and Science Preservation
Wf4Ever: Work!ows for Methodology and Science PreservationWf4Ever: Work!ows for Methodology and Science Preservation
Wf4Ever: Work!ows for Methodology and Science Preservation
 
Usability_Presentation
Usability_PresentationUsability_Presentation
Usability_Presentation
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
AOP
AOPAOP
AOP
 
Practical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint ProgrammingPractical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint Programming
 
Generating NoSQL from SQL
Generating NoSQL from SQLGenerating NoSQL from SQL
Generating NoSQL from SQL
 
Introduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-SeqIntroduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-Seq
 

More from Victor Trakhtenberg

WeCode IL: Confessions of a java developer that fell in love with the groovy...
WeCode IL:  Confessions of a java developer that fell in love with the groovy...WeCode IL:  Confessions of a java developer that fell in love with the groovy...
WeCode IL: Confessions of a java developer that fell in love with the groovy...Victor Trakhtenberg
 
Java.il - Confessions of a java developer that fell in love with the groovy l...
Java.il - Confessions of a java developer that fell in love with the groovy l...Java.il - Confessions of a java developer that fell in love with the groovy l...
Java.il - Confessions of a java developer that fell in love with the groovy l...Victor Trakhtenberg
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessibleVictor Trakhtenberg
 

More from Victor Trakhtenberg (6)

We codeil save kermit
We codeil   save kermitWe codeil   save kermit
We codeil save kermit
 
WeCode IL: Confessions of a java developer that fell in love with the groovy...
WeCode IL:  Confessions of a java developer that fell in love with the groovy...WeCode IL:  Confessions of a java developer that fell in love with the groovy...
WeCode IL: Confessions of a java developer that fell in love with the groovy...
 
WeCode IL: Save Kermit
WeCode IL:  Save KermitWeCode IL:  Save Kermit
WeCode IL: Save Kermit
 
Java.il - Confessions of a java developer that fell in love with the groovy l...
Java.il - Confessions of a java developer that fell in love with the groovy l...Java.il - Confessions of a java developer that fell in love with the groovy l...
Java.il - Confessions of a java developer that fell in love with the groovy l...
 
Swagger code motion talk
Swagger code motion talkSwagger code motion talk
Swagger code motion talk
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 

Sc11 presentation 2001_06_28

  • 1. Pluggable Aspect Instantiation Models Victor Trakhtenberg The Open University of Israel Joint Work With David H. Lorenz
  • 2. Aspect Instantiation Models (AIMs) • What is an aspect? – Crosscutting behavior + crosscutting state • What is an AIM? – 6 keyword in AspectJ: issingleton, pertarget, perthis, percflow, percflowbelow, pertypewithin. – Added incrementally to AspectJ – More AIMs in other AOP languages • There is a need for custom AIMs – Challenge: decouple the definition of AIMs from the evolution of the language The Open University of Israel
  • 3. Contribution of this Work • Pluggable Aspect Instantiation Models – Make AIMs pluggable! ❶ Language extension – We introduce a new keyword: ‘perscope’ • Replaces the exiting 6 keywords • Eliminates need for new keywords (hopefully) ❷ Interface for defining AIMs – Third parties can design and implement new AIMs ❸ Library of AIM Implementations – Fully implemented in ajc The Open University of Israel
  • 4. Outline • Introduction • Requirements • Example • Pluggable Mechanism • Conclusion The Open University of Israel
  • 5. Motivation: “caching and auditing” • Industrial Case Study – Web application development with AspectJ – Need for ‘persession’ and ‘perconversation’ AIMs Cache Cache Cache Cache Cache The Open University of Israel
  • 6. Current Solution • Wait for a new release of AspectJ – May take awhile… • Modify the current ajc compiler – Sisyphean, complex task • Manage the state manually – Tangled and scattered code The Open University of Israel
  • 7. Desired Solution 1. Pluggable 5. Extensible AIM Flexible Mechanism 2. Declarative 4. 3. Efficient Expressive The Open University of Israel
  • 8. Requirement 1: Extensible • New AIMs can be introduced – Perthread Perthread – Persession • Pre-defined AIMs can be refined Per Recent – Perthread that was started in the last hour Thread • Generic AIMs can be offered by – Third-party providers – AspectJ developers The Open University of Israel
  • 9. Requirement 2: Declarative • Easy to use – Like AspectJ • AIMs implementation may vary independently of their use – Unlike AspectJ AspectJ public aspect MyAspect perthis(myPointcut()){ } perscope public aspect MyAspect perscope(Perthis, myPointcut()){ } The Open University of Israel
  • 10. Requirement 2: Declarative • Easy to use – Like AspectJ • AIMs implementation may vary independently of their use – Unlike AspectJ New keyword Class implements AIM perscope public aspect MyAspect perscope(Perthis, myPointcut()){ } The Open University of Israel
  • 11. Requirement 3: Expressive • Practical – Realistically complex AIMs can be defined – E.g., perconversation • AspectJ compatible – Can implement all 6 AspectJ AIMs The Open University of Israel
  • 12. Requirement 4: Efficient • Weaving – Implemented by bytecode weaving • Runtime performance – Generate the same bytecode as AspectJ for the 6 AspectJ AIMs The Open University of Israel
  • 13. Requirement 5: Flexible • Static AIM implementation – Same woven performance as AspectJ • Dynamic AIM implementation – Encourages experimenting with AIMs The Open University of Israel
  • 14. Outline • Introduction • Requirements • Example • Pluggable Mechanism • Evaluation • Conclusion The Open University of Israel
  • 15. Example: Global Caching Aspect public aspect GlobalCaching AspectJ and perscope extends SimpleCaching { } The Open University of Israel
  • 16. Example: Perclient Caching Aspect Aspect Aspect Aspect AspectJ public aspect PerClientCaching extends SimpleCaching perthis (cachedOperation(Object)) { } perscope public aspect PerClientCaching extends SimpleCaching perscope(Perthis, cachedOperation(Object)) { } The Open University of Israel
  • 17. Example: Perconversation Caching Aspect Aspect Aspect Aspect public aspect PerConversationCaching extends SimpleCaching perscope perscope(Perconversation, cachedOperation(Object)){ } AspectJ The Open University of Israel
  • 18. Outline • Introduction • Requirements • Example • Pluggable Mechanism – Dynamic – Static • Evaluation • Conclusion The Open University of Israel
  • 19. Dynamic Implementation • Implement the DynamicPerscope interface • Specify how the aspect instance should be bound, retrieved, and queried public interface DynamicPerscope { void bindAspect(Object aspekt, Object object); Object aspectOf(Class<?> aspectType, Object object); boolean hasAspect(Class<?> aspectType, Object object); } The Open University of Israel
  • 20. DynamicPerscope: usage public aspect PerThreadCaching extends SimpleCaching perscope(Perthread, cachedOperation(Object)) { } The Open University of Israel
  • 21. DynamicPerscope: implementation public class Perthread implements DynamicPerscope { private static ThreadLocal<Object> theAspect = new ThreadLocal<Object>(); public void bindAspect(Object aspekt, Object o) { if (theAspect.get() == null) { theAspect.set(aspekt); } } public Object aspectOf(Class<?> aspectType, Object o) { return theAspect.get(); } public boolean hasAspect(Class<?> aspectType, Object o){ return theAspect.get() != null; } } The Open University of Israel
  • 22. Static Implementation • Bytecode manipulation – Harder to implement – Capable of producing efficient code • StaticPerscope interface – Hard-wired weaving code replaced with calls to the StaticPerscope interface The Open University of Israel
  • 23. DynamicPerscope vs. StaticPerscope • DynamicPerscope – Regular Java code – Intended for regular infrastructure programmers • StaticPerscope – More complex – More efficient – Intended for advanced infrastructure programmers Note: these trade-offs are transparent to the end user of AIM The Open University of Israel
  • 24. Outline • Introduction • Requirements • Example • Pluggable Mechanism • Evaluation • Conclusion The Open University of Israel
  • 25. Evaluation • Implementing AspectJ built-in AIMs – Caching example – Law of Demeter (AspectBench compiler distribution) • Implementing Non-AspectJ AIMs – AspectS cflow advice activations – JAsCo perthread AIM – persession and perconversation The Open University of Israel
  • 26. Threats to Validity • Implemented only for the ajc compiler – Language feature • AspectJ AIMs were tested on two examples – Same bytecode is generated •  AIMs that cannot be implemented using perscope – Always true AspectJ Other AOP Languages perscope Custom The Open University of Israel
  • 27. Outline • Introduction • Requirements • Example • Pluggable Mechanism • Evaluation • Conclusion The Open University of Israel
  • 28. Related Work • Perscope vs. JAsCo – IAspectFactory is used at runtime for aspect instantiation – With perscope two choices: DynamicPerscope or StaticPerscope • Perscope vs. Caesar – In Caesar aspect instantiated explicitly – With perscope – implicitly according to aspect declaration as in AspectJ The Open University of Israel
  • 29. Conclusion • With perscope AIMs are pluggable • New keyword ‘perscope’ is introduced • Usage of AIMs is declarative – As in AspectJ • AIMs may be provided by third-parties – Different than AspectJ The Open University of Israel
  • 30. Thank You! • Questions? • Contact information: Software Engineering Research Lab Open University of Israel Email: • lorenz@openu.ac.il • victortr75@gmail.com URL: • http://aop.cslab.openu.ac.il/research/perscope/ The Open University of Israel