Java bytecode manipulation

Slides:



Advertisements
Similar presentations
Saumya Debray The University of Arizona Tucson, AZ
Advertisements

Systems Software.
Intoduction First we’ll talk in general about Visual X-Toy Then we’ll input and run a program using switches Then we’ll look at the more advanced editor.
Executable XML Present by 吳昆澤. Outline  Introduction  Simkin  Jelly  o:XML  Conclusion.
University of Kansas Construction & Integration of Distributed Systems Jerry James Oct. 30, 2000.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
ASM: A Bytecode Manipulation Tool – A brief Overview Course : CSE 6329 Spring 2011 University of Texas at Arlington.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Introduction to High-Level Language Programming
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Introduction and Overview Questions answered in this lecture: What is an operating system? How have operating systems evolved? Why study operating systems?
CS266 Software Reverse Engineering (SRE) Reversing and Patching Java Bytecode Teodoro (Ted) Cipresso,
CSE 219 Computer Science III Program Design Principles.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
MNP1163/MANP1163 (Software Construction).  Minimizing complexity  Anticipating change  Constructing for verification  Reuse  Standards in software.
Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 24 Wrap Up.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Interaction and Animation on Geolocalization Based Network Topology by Engin Arslan.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
COMP Compilers Lecture 1: Introduction
Why don’t programmers have to program in machine code?
Algorithms and Problem Solving
The architecture of the P416 compiler
Today’s Agenda Exam 2 Part 2 (11:15am-12:30pm)
Software Architecture ATAM Process Presentation
Programming languages
Topics Introduction Hardware and Software How Computers Store Data
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
SE goes software engineering; (practically) managing the Compose
Introduction to Advanced Java Programming
Processes and Threads Processes and their scheduling
The heavyweight parts of lightweight languages
Microprocessor and Assembly Language
Excise Tasks CS 4640 Programming Languages for Web Applications
CS101 Introduction to Computing Lecture 19 Programming Languages
CPSC 315 – Programming Studio Spring 2012
History of compiler development
Introduction Enosis Learning.
CMPE419 Mobile Application Development
Lecture 5: GPU Compute Architecture
CS 240 – Lecture 11 Pseudocode.
Parallel and Distributed Computing
Introduction Enosis Learning.
Compiler Construction
Lecture 5: GPU Compute Architecture for the last time
Introduction to Computer Programming
COMP Compilers Lecture 1: Introduction
Chapter 11 Introduction to Programming in C
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Informatics 43 – May 26, 2016.
CSE 331 Software Design & Implementation
Portability CPSC 315 – Programming Studio
Programming Languages
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
Topics Introduction Hardware and Software How Computers Store Data
Jython Environment For Students (JES) Final Presentation
There are 10 types of people of people in this world…
Java for IOI.
CSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation
Introduction to Data Structure
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
SE goes software engineering; (practically) managing the Compose
Java Analysis Studio and the hep.lcd classes
Web Client Side Technologies Raneem Qaddoura
CMPE419 Mobile Application Development
08120: Programming 2: SoftwareTesting and Debugging
Presentation transcript:

Java bytecode manipulation with ObjectWeb ASM http://asm.ow2.org/current/asm-transformations.pdf

Java has the highest paying jobs Source: Previous lightning talk (circular reference)

Java Bytecode Manipulation Programming in hexadecimals Java Bytecode Manipulation

Not Really! The Java class file format is a bit convoluted So it is not fun to do it!

Introducing ObjectWeb ASM Eliminating headaches Introducing ObjectWeb ASM

What is it? A framework to manipulate Java class files ASM implements load-time bytecode weaving

Why use ASM? Easy to get started Uses an event driven approach Has an code generator Easy to get started

In particular, ASM uses the visitor pattern Getting started ASM uses an event driven model to hide the complexity of Java’s bytecode In particular, ASM uses the visitor pattern

Yet another pattern The Visitor Pattern

 Visitor pattern is the separation of an algorithm from an object structure on which it operates on.

Why use the pattern? It allows the capture of class data incrementally Avoids the repeated creation and destruction of short-lived objects

Visitors in ASM ClassVisitor ClassReader ClassWriter ClassNode

Typical flow Input ClassReader ClassWriter Output Visiting event producer ClassWriter consumer Output

Typical flow Load class Read class Modify class

Example final ClassReader classReader = new ClassReader(classByteArray); final ClassNode classNode = new ClassNode(); classReader.accept(classNode, 0); final MethodNode methodNode = findMethod(classNode, methodInfo);

Introducing the ASMifier The Code Generator

The code generator ASM also has a code generator ASMifier It converts complied java code into its equivalent ASM function calls

Why use ASM? Easy to get started Light Weight Uses an event driven approach Has an code generator Easy to get started Very small runtime JAR file Low memory footprint Light Weight

Light weight library

ASM is lightweight Its runtime JAR file is only about 50 KB By using the visitor pattern, its memory footprint is also kept low

Why use ASM? Easy to get started Light Weight Powerful Uses an event driven approach Has an code generator Easy to get started Very small runtime JAR file Low memory footprint Many possible utilities Light Weight Powerful

Uses of bytecode manipulation Yes, it has uses Uses of bytecode manipulation

ReflectASM vs Java’s Reflection Credits: https://github.com/EsotericSoftware/reflectasm ReflectASM vs Java’s Reflection

Other possible utilities Call trace generation New language semantics implementation

By the way, what is ASM? No official meaning

In conclusion Java bytecode manipulation is not all that scary with ASM ASM is lightweight and incurs little performance overhead Bytecode manipulation is very powerful with lots of uses

PUMA Key Points It is easy to get started Audience: fellow CS3281/2 students Objective: Inform about a tool to manipulate java’s bytecode easily PUNCH: Everyone is a Java programmer, but not all know how to manipulate java’s bytecode. WIIFY: Learn how to use ASM to manipulate bytecode easily. Call to action: Know about this tool and consider using it next time Know: You don’t need to program in hexadecimals to manipulate bytecode Believe: It is easy with ASM Do: Start experimentation with it Key Points It is easy to get started Don’t need to use a hex editor to manipulate class files ASMifier ASM uses the visitor pattern It is how ASM manipulates and changes behaviour of classes without modifying them It is fast and lightweight It has many uses High performance reflections Debugging information (call trace)