Dynamic AOP in Java - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Dynamic AOP in Java

Description:

2006 Roy Spenkelink / University of Twente. Dynamic AOP. Adding/removing aspects during runtime ... Enhancer Proxy. Inheritance instead of aggregation. 9 /16 ... – PowerPoint PPT presentation

Number of Views:247
Avg rating:3.0/5.0
Slides: 17
Provided by: Roy50
Category:
Tags: aop | dynamic | java

less

Transcript and Presenter's Notes

Title: Dynamic AOP in Java


1
Dynamic AOP in Java
2
Overview
  • Dynamic AOP
  • Domain Analysis
  • Proxy based
  • Bytecode manipulation
  • Interpreter based
  • Final Remarks

3
Dynamic AOP
  • Adding/removing aspects during runtime
  • Can help avoid
  • Re-compiling
  • Re-deployment
  • Re-start of an application
  • More flexible than static weaving

4
Domain Analysis
  • 3 main approaches
  • Proxy based
  • Nanning, Spring, Jeet, dynaop
  • Bytecode manipulation
  • AspectWerkz, JBossAOP, JAC, Wool
  • Bytecode manipulation tools
  • Javassist, BCEL, ASM
  • Interpreter based
  • Plugins/Extensions Prose, Axon
  • JVM-level AOP JRockit

5
Proxy-based (1/4)
  • Proxy
  • A proxy is a surrogate or placeholder for a
    target object to control access to it. (Proxy
    pattern)

6
Proxy based (2/4)
  • Creating proxies dynamically
  • JDK java.lang.reflect.Proxy

7
Proxy-based (3/4)
8
Proxy-based (4/4)
  • What if we want to advice classes that dont have
    interfaces?
  • CGLIB
  • Code Generation Library / API
  • Transforms classes into classes
  • ASM
  • Similar to JDK dynamic proxies
  • MethodInterceptor InvocationHandler
  • Enhancer Proxy
  • Inheritance instead of aggregation

9
Bytecode Manipulation (1/3)
  • Bytecode manipulation tools
  • BCEL, Javassist, ASM
  • Most popular of the 3 approaches
  • AspectWerkz, JBossAOP, JAC, Wool
  • Some drawbacks
  • Performance CPU-intensive
  • Scalability 64kb boundary for class files

10
Bytecode manipulation (2/3)
  • HotSwap
  • Changing method/constructor bodies of classes at
    runtime and inject them into a running JVM
  • Fixed schema
  • Preparation step is needed
  • Part of JVMTI since Java 5
  • java.lang.instrument

11
Bytecode manipulation (3/3)
  • Comparison BCEL, Javassist, ASM
  • ASM much faster
  • gt5 times faster than Javassist/BCEL
  • Javassist easiest to use
  • source code level instrumentation
  • lower learning curve than bytecode
    instrumentation

12
Interpreter-based
  • Based on intercepting execution events in the JVM
  • Adapting the JVM
  • Plugins/Extensions
  • Prose, Axon
  • New JVM
  • JRockit

13
Interpreter based Prose (1/2)
14
Interpreter-based Prose (2/2)
  • Limitations
  • No introductions (cannot change the original
    code)
  • Slow because of Debugger overhead
  • Small public

15
Interpreter-based
  • AOP support built in the JVM
  • JRockit
  • Prototype / not standardized
  • Advantages vs bytecode instrumentation
  • No startup-cost due to bytecode instrumentation
  • No double bookkeeping building a class DB
  • Support for intercepting reflective calls

16
Final Remarks
  • Some insight given in different techniques that
    can be used to handle dynamic AOP in Java
  • Proxy, bytecode manipulation / HotSwap,
    interpreter-based
  • Work this out
  • Probably using bytecode manipulation
  • Javassist , HotSwap
  • Also combinations are possible
Write a Comment
User Comments (0)
About PowerShow.com