Load Time Structural Reflection in Java Shigeru Chiba Institute of Information Science and Electronics University of Tsukuba.

Slides:



Advertisements
Similar presentations
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Advertisements

JavAssist X.java X.class Class Loader My Loader X compile load JavAssist enables preload byte code modification.
Chapter FourModern Programming Languages1 Language Systems.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
JAVA Processors and JIT Scheduling. Overview & Literature n Formulation of the problem n JAVA introduction n Description of Caffeine * Literature: “Java.
Lab#1 (14/3/1431h) Introduction To java programming cs425
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
1 © 1999 Citrix Systems Inc Java on Nemesis Tim Harris.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Adaptive Optimization in the Jalapeño JVM M. Arnold, S. Fink, D. Grove, M. Hind, P. Sweeney Presented by Andrew Cove Spring 2006.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Language Systems Chapter FourModern Programming Languages 1.
SALSA: Language and Architecture for Widely Distributed Actor Systems. Carlos Varela, Abe Stephens, Department of.
J-OCM is a system for monitoring distributed Java applications conforming to OMIS specification with J-OMIS extensions. It is used to: gather information.
Lecture 10 : Introduction to Java Virtual Machine
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Java Virtual Machine Case Study on the Design of JikesRVM.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Introduction to C++ Programming Language
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Java 2 security model Valentina Casola. Components of Java the development environment –development lifecycle –Java language features –class files and.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Object Oriented Software Development 4. C# data types, objects and references.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Introduction to OOP CPS235: Introduction.
On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
Duke CPS Java: make it run, make it right, make it fast (see Byte, May 1998, for more details) l “Java isn’t fast enough for ‘real’ applications”
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
RealTimeSystems Lab Jong-Koo, Lim
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
1. Presentation Agenda  Identify Java Card Technology  Identify Elements of Java Card applications  Communicating with a Java Card Applet  Java Card.
Concepts of Programming Languages Lecturer: Dr. Emad Nabil Lecture # 2.
Advanced Computer Systems
Visit for more Learning Resources
Chapter 1 Introduction to Computers, Programs, and Java
Java Primer 1: Types, Classes and Operators
Java programming lecture one
(Computer fundamental Lab)
Lecture 1 Runtime environments.
CSc 453 Interpreters & Interpretation
JIT Compiler Design Maxine Virtual Machine Dhwani Pandya
Presentation transcript:

Load Time Structural Reflection in Java Shigeru Chiba Institute of Information Science and Electronics University of Tsukuba

Introduction Reflection in java –Behavioral reflection –Structural reflection Javassist, a class library enabling structural reflection in java

Properties of Javassist Portable Provides source level abstraction Does byte code transformation at compile time

BCA class Calendar implements Writable { public void write(PrintStream s) {... } } class Calendar implements Printable { public void write(PrintStream s) {... } public void print() { write(System.out); } } Implementation of BCA with behavioral reflection is not straightforward

Javassist Translates alterations by structural reflection into equivalent bytecode It is used with a user class loader class MyLoader extends ClassLoader { public Class loadClass(String name) { byte[] bytecode = readClassFile(name); return resolveClass(defineClass(bytecode)); } private byte[] readClassFile(String name) { // read a class file from a resource. }

Javassist API A CtClass object has to be created CtClass c = new CtClass(stream or string); To obtain bytecode of altered class byte[] bytecode = c.toBytecode(); Javassist allows to dynamically define a new class CtClass c2 = new CtNewClass();

Introspection This part of Javassist is compatible with Java reflection API with the difference that Javassist does not provide methods for creating an instance or invoking a method because these are meaningless at load time

Methods in CtClass for introspecting classes

Alteration by Javassist Principles governing alteration in Javassist –Source level abstraction for programmers –Execution of structural reflection efficiently –Type safety while performing Structural reflection

Adding a new member void addMethod(CtMethod m, String name, ClassMap map) void addWrapper(int modifiers, CtClass returnType, String name,CtClass[] parameters, CtClass[] exceptions,CtMethod body, ConstParameter constParam)

Replacing a Class name in the method body public class XVector extends java.util.Vector { public void add(X e) { super.addElement(e);}} CtMethod m = /* method add() in XVector */; CtClass c = /* class StringVector */; ClassMap map = new ClassMap(); map.put("X", "java.lang.String"); c.addMethod(m, "addString", map); public void addString(java.lang.String e) { super.addElement(e);}

Altering a Method body void setBody(CtMethod m, ClassMap map) void setWrapper(CtMethod m, ConstParameter param)

Reflective class loader Javassist provides a reflective class loader which can be used to self-reflectively modify the bytecode

Using Javassist with a Web server for (;;) { receive an http request from a web browser. CtClass c = new CtClass ( the requested clas s); do structural reflection on c if needed. byte[] bytecode = c.toBytecode(); send the bytecode to the web browser. }

Using Javassist Off line CtClass c =newCtClass("Rectangle"); do structural reflection on c if needed. c.compile(); writes bytecode on the original class file. Now the over written class file can be loaded in the JVM without user class loader

Use of Javassist Binary Code Adaption Remote Method Invocation

Comparison of OpenJava and Javassist Openjava needs source file of every processed class whereas Javassist needs just the class files of the classes Javassist is much faster as it can move compilation penalties to an earlier stage

Conclusion Javassist is portable Provides source level abstraction in a safe manner Does not need source code Can be extended to other object oriented languages with individually designed API for each language

The Jalapeno Dynamic Optimizing Compiler for java Thomas J.Watson Research Center IBM

Project overview Jalapeno is a JVM built by IBM Research (initiated in December 1997) It takes a compile-only approach to program execution Three different compilers to provide translations: – A “baseline” compiler that makes it easier to mix execution of un-optimized and optimized methods in the JVM – A “quick” compiler for a low level of code optimization – An optimizing compiler for computationally intensive code

Motivation of the Project To deliver high performance and scalability ofJava applications on SMP server machines To support all Java features and semantics with respect to exceptions, garbage collection and threads

Jalapeno JVM Jalapeno JVM includes the following subsystems: - Dynamic Class Loader - Dynamic Linker - Object Allocator - Garbage Collector - Thread Scheduler - Profiler - Three dynamic compilers

Jalapeno JVM All subsystems implemented in Java Self-bootstrapping Can dynamically self-optimize the JVM itself

Structure of Jalapeno Optimization system Unlike traditional JVMs, Jalapeno is adaptive and dynamic – Automatically select a set of methods to optimize – Generate the best possible code for selected methods for a given compile-time budget – Reduce synchronization and other thread primitive

Structure of Jalapeno adaptive Optimization system Jalapeno Adaptive Optimization System includes: – On-Line Measurement (OLM) subsystem – Controller subsystem – Optimizing Compiler subsystem

Online Measurment OLM – Collect application and hardware performance information – Maintain Calling Context Graph (CCG) to keep track of context-sensitive information – Continuously monitor the methods, including those previously “optimized”

Controller – Detect if certain performance threshold is reached – Use information collected from OLM to build an optimization plan (e.g. which methods need to be compiled and the optimization levels)

Optimizing Compiler The Optimizing Compiler can be used either as a static or dynamic compiler. When used as a static compiler or a bytecode -to- bytecode optimizer, it generates file for later execution,used to bootstrap Jalapeno JVM

Optimizing Compiler When used as a dynamic compiler, it generates the best possible code given compile - time budget The Jalapeno Optimizing Compiler consists of an optimizer front-end and an optimizer backend

Intermediate Representation (IR) The Optimizing Compiler uses register-based intermediate representations IR consists of an operator and some number of operands Jalapeno uses 3 different types of IRs: – HIR (High-Level IR) – LIR (Low-Level IR) – MIR (Machine-Specific IR)

IR Operators such as NULL_CHECK and BOUNDS_CHECK operators are used to facilitate optimization Control Flow Graph (CFG) and Basic Blocks (BB) are constructed as a by-product of BC2IR(Byte Code to Intermediate Representation)

Front end of Optimizing compiler The Front-End contains two parts: – BC2IR algorithm to translate byte code to HIR and perform on the fly optimizations – Additional optimization performed on the generated HIR

Back end of Optimizer Compiler The Back-End of the compiler translates – HIR to LIR – LIR to MIR – MIR to the final binary code Different optimizations are performed during each phase

HIR to LIR HIR is lowered to low-level IR (LIR) LIR expands instructions into operations that are specific to the Jalapeno JVM (such as object layouts or parameter-passing mechanism) The expanded LIR may expose more opportunities for low-level optimizations

Final Assembly Emit the binary executable code into an instruction array Convert offsets in the IR to offsets in the machine code Store the instruction array (a Java array reference) into a field of the object instance for that method

Inlining Method Calls During BC2IR phase: – Static and final methods can be safely inlined. – “Inlining plan” is based on static code size and depth heuristics

Implementation Status OLM is in prototype stage, and the controller is in design phase The Optimizing compiler can only be invoked as a static compiler or dynamically by the Jalapeno class loader to optimize all methods

Performance Benchmark Enviroments Four Java Environments: – IBM JDK w/o JIT – IBM JDK w IBM JIT v3.0 – Jalapeno Baseline – Use Jalapeno Baseline Compiler as a JIT for all classes dynamically loaded – Jalapeno Optimizer – Use Jalapeno Optimizing as JIT for all classes dynamically loaded

Benchmark Programs Benchmark Programs: – 9 “Micro-benchmark” Programs from Symantec – 4 “Macro-benchmark” programs from SPECjvm98suite

Performance Results Micro-Benchmark: – 3 of the 9 tests run faster with the Jalapeno Optimizing Compiler – Remaining cases are within 1.6 times slower of the standard IBM JIT compiler

Performance Results Macro-Benchmark: – 1.3 to 3.3 times slower than the “best” current commercial JVM" – With further improvements, Jalapeno (a pure Java JVM) may achieve performance competitive to a state-of-the-art JVM implemented in C

Conclusion First dynamic optimizing compiler for Java that is being used in JVM with a compile –only approach to program execution – Validated the “compile-only” approach to program execution – Demonstrated that a JVM implemented in Java can deliver performance comparable to a standard JIT compiler