Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin.

Similar presentations


Presentation on theme: "ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin."— Presentation transcript:

1 ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin Li University of waterloo

2 Paper Overview

3 Contents: Overview Existing reflection facilities in Java - Standard Java Reflection API - Extensions to the reflection ability of Java Javassist – an intercession extension to Java - Implementation technique - Introduction to load-time structural reflection - Javassist API Three applications of Javassist

4 Contents: Detail Existing reflection facilities in Java - Standard Java Reflection API Restricted to introspection Behavior reflection is very limited - Extensions to Java Reflection API Enable restricted behavior reflection Modify runtime systems or compilers Use hook-insertion technique and metaobjects Runtime overheads can be low Limitation to some language extensions(e.g. BCA)

5 Contents: Detail Novel reflection architecture – Javassist - An extension to the Java reflection API Enables structural reflection in Java at load time - Is portable Runs with a standard JVM - Provides source-level abstraction for programmers Can be used without knowledge of the Java byte code - Never needs source code Performs structural reflection by instrumenting byte code of a loaded class

6 Contents: Detail Javassist API - Reification CtClass object and its reflective methods - Introspection Almost compatible with the Java reflection API - Alteration Three design goals and their achievements - Adding a new member Two approaches for adding a new method to a class

7 Contents: Detail Javassist API cont'd - Altering a method body - Reflective class loader Allows a loaded program to control the class loading - Three ways to use Javassist With a user class loader With a web server Off line

8 Contents: Detail Application examples of Javasssist - Binary Code Adaptation(BCA) - Behavioral reflection - Remote method invocation Generating stub code for RMI

9 Related Work Reflection in Java - Behavioral reflection examples: MetaXa, Kava, Java reflection API - Structural reflection example: Linguistic reflection Compile-time metaobject protocol - Source-code basis example: OpenJava Byte code translator - Examples: JOIE, JavaClass API Others - OpenJIT, CLOS MOP, BCA

10 Contributions and Novelties Architecture for performing structural refection in Java based on byte code - No need for source code - Used with a standard JVM and Java compiler - Source-level abstraction Practical structural reflection API Three application examples - Show implementing some language extensions with Javassist is much easier than other reflection architectures

11 What I like Javassist does not break security guarantees given by Java Javassist is easy to used - Without knowledge of the Java byte code - Can be used with a user class loader, web server, and offline Javassist architecture can be applied to other object-oriented languages - as long as the compiled binary includes enough symbolic information to construct a class object

12 Questions

13 Question 1 What is structural reflection?

14 Answer Structural reflection is the ability to allow a program to alter the definitions of data structures such as classes and methods.

15 Question 2 Some languages(e.g. Smalltalk,CLOS) implement structural reflection with support mechanisms embedded in runtime systems. What problems would the application of this implementation technique to Java cause?

16 Answer Invalidation of portability of Java due to modification of JVM Performance degradation of JVM due to difficulty to employ optimization at runtime Extra runtime type checks or restrictions on the structural reflection Less security

17 Question 3 What is load-time structural reflection?

18 Answer Structural reflection is performed only before a program is loaded into a runtime system, that is, at load time.

19 Question 4 How does Javassist perform structural reflection?

20 Answer Javassist implementation based on load- time structural reflection architecture Javassist performs structural reflection by translating alteration into equivalent bytecode transformation of the class files After the transformation, the modified class files are loaded into the JVM and then no alteration are allowed after that

21 Question 5 How does Javassist reify the class needed to be reflected?

22 Answer Javassist creates a CtClass(compile-time class) object CtClass represents the byte code of the class need to be reflected Then the class is accessible from a program by invocating the methods on CtClass object

23 Question 6 How is the introspecting facilities of Javassist?

24 Answer The introspection part of Javassist API is compatible with the Java reflection API But, Javassist does not provide methods for creating an instance or invoking a method

25 Question 7 What is the main features of the alteration methods in Javassist API?

26 Answer Provides source-level abstraction for users - Approach to specify a method body is in source level Executes structural reflection efficiently - Copy pre-compiled method body from a class to another Performs structural reflection in a safe manner in terms of types - No methods to remove a method or a field from a class - New superclass must be a subclass of the original superclass - No methods to change the parameters of a method

27 Question 8 What is the difference between the class loader provided by Javassist and the Java’s standard class loader?

28 Answer The Javassist class loader allows a loaded program to control the class loading (see Figure 1) - If a program is loaded by Javassist’s class loader L and it includes a class C, then it can intercept the loading of C by L to self-reflectively modify the byte code of C - For avoiding infinite recursion, while the loading of a class is intercepted, further interception is not allowed ∙ Java’s class loader never allows this self-reflective class loading

29 Question 9 Why Javassist does not break security guarantees given by Java?

30 Answer Javassist uses the standard JVM The classes processed by Javassist are subject to the bytecode verifier and the SecurityManager of Java

31 Question 10 Can Javassist and OpenJava both deal with syntax extensions of Java?

32 Answer OpenJava can deal with syntax extensions. Because OpenJava is source-code basis. It reads source code for creating an object representing a class, a method, or a field, and alteration on the object is translated into corresponding transformation of the source code Javassist can not deal with syntax extensions since Javassist is byte-code basis

33 Question 11 Can the architecture applied by Javassist be applied to other object-oriented language?

34 Answer Yes, as long as the compiled binary program contains enough symbolic information to construct a class object. However the API needs to be individually designed for each language to perform structural reflection in a safe manner in terms of types


Download ppt "ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin."

Similar presentations


Ads by Google