1 / 20

Retroactive API Extensions Through Bytecode Weaving

Retroactive API Extensions Through Bytecode Weaving . Jevgeni Kabanov PhD student, University of Tartu. WHAT?. API Extensions Application programming interface New APIs, changed APIs Bytecode Weaving Bytecode : stack-based Java-like language Weaving: runtime program rewriting

holly
Download Presentation

Retroactive API Extensions Through Bytecode Weaving

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Retroactive API Extensions Through Bytecode Weaving Jevgeni Kabanov PhD student, University of Tartu

  2. WHAT? • API Extensions • Application programming interface • New APIs, changed APIs • Bytecode Weaving • Bytecode: stack-based Java-like language • Weaving: runtime program rewriting • Retroactive • Abstraction after the fact • Without access to source code

  3. WHY? • Java EE is implemented by application containers each with specific extensions • Frameworks and applications need a unified access to container-specific features

  4. EXAMPLE • JavaScript, DOM, abstraction libraries • GWT • Prototype • jQuery • Ext JS • Spring (Java framework) • Abstraction over some common Java EE features for applications

  5. BEHIND THE SCENES MyClass MyClass’ MyClass_3 MyObject.class MyObject.class

  6. IDEs Servers Frameworks Open-Source API

  7. Class loader API publicabstractclassClassLoader { public Class loadClass(String name); protected Class defineClass(byte[] b); public URL getResource(String name); public Enumeration getResources(String name); publicClassLoadergetParent() }

  8. API Extensions • Change loadClass() to include the classes we provide to it • Add a method getChildResources() that returns the resources hierarchically

  9. Java Class Definition

  10. Java Execution Model Local variables Operand stack Throwing an exception Calling a method Frame Execution stack

  11. Instruction Example Instruction: opcode arguments Operands stack when applying the instruction: apply

  12. Hello, World! in Bytecode publicclassHelloWorld { public<init>()V ALOAD 0 INVOKESPECIAL Object.<init>()V RETURN publicstaticmain([LString;)V GETSTATIC System.out : LPrintStream; LDC "Hello, World!" INVOKEVIRTUAL PrintStream.println(LString;)V RETURN }

  13. REWRITING IS EASY • ASM • Visitor API • Low level • Javassist • String-embedded Java DSL • High-level, but adjustable

  14. PROBLEM 1: TRANSPARENCY • If the result of an API call is altered, how do we access the original from our framework? • E.g. ClassLoader.loadClass()

  15. PROBLEM 2: OPTIONAL • What if the features we want to support are optional or implemented differently among implementers? • E.g. ClassLoader.getChildResources()

  16. PROBLEM 3: VERSIONING • What if we have several versions of an implementation? • NB! In Java the class files are not versioned and detecting versions may be challenging

  17. PROBLEM 4: GLOBAL STATE • What if implementer state dictates that calls are legal in some states and illegal in others? • E.g. ClassLoaderclasspath is often constructed incrementally

  18. PROBLEM 5: SYNCHRONIZATION • What if implementer does synchronization? • Synchronized in Java is a reentrant mutex • ClassLoader.loadClass() is synchronized, ClassLoader.getResource() usually not

  19. Questions?

More Related