overview of the ibm java just-in-time compiler

24
OVERVIEW OF THE IBM JAVA JUST-IN-TIME COMPILER Presenters: Zhenhua Liu, Sanjeev Singh 1

Upload: odell

Post on 10-Feb-2016

23 views

Category:

Documents


1 download

DESCRIPTION

Overview of the IBM Java Just-in-Time Compiler . Presenters: Zhenhua Liu, Sanjeev Singh . Reference. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Overview of the IBM Java Just-in-Time Compiler

OVERVIEW OF THE IBM JAVA JUST-IN-TIME COMPILER Presenters: Zhenhua Liu, Sanjeev Singh

1

Page 2: Overview of the IBM Java Just-in-Time Compiler

REFERENCE “Overview of the IBM Java Just-in-Time”,

T. Suganuma, T. Ogasawara, M. Takeuchi, T. Yasue, M. Kawahito, K. Ishizaki, H. Komatsu, T. Nakatani IBM Systems Journal, Volume 39 , No. 1, Pages: 175 – 193, ISSN:0018-8670

2

Page 3: Overview of the IBM Java Just-in-Time Compiler

OUTLINEIntroduction to JVMModifications to JVM(IBM JIT compiler)

Optimization on extended bytecodeCode generation detailsExample

3

Page 4: Overview of the IBM Java Just-in-Time Compiler

INTRODUCTION TO JVM What’s JVM(Java Virtual Machine)?

Pros & Cons Advantage:

Platform-neutrality, flexibility, reusability Disadvantage:

Performance penalty Run-time overhead for bytecode instruction fetch &

decode

Source Code Bytecode Machine

CodeJVM

4

Page 5: Overview of the IBM Java Just-in-Time Compiler

WHY IS JAVA SLOW? Many relative small method can lead to more

frequent method invocation than other non-OOP languages

Requires run-time exception checking to ensure validity of accesses to objects and arrays

Synchronized methods or synchronized blocks cause run-time overhead by locking a given object for the duration of execution

5

Page 6: Overview of the IBM Java Just-in-Time Compiler

HOW TO SPEED UP JVM? Just-in-time (JIT) compiler

Converts the given bytecode instruction sequence at runtime before executing it natively

Pros & Cons of JIT compilerReduce overall Run-time overhead Introduce first-time Compilation overhead,

but not afterwards6

Page 7: Overview of the IBM Java Just-in-Time Compiler

STRUCTURE OF JIT COMPILER

Bytecode-level Optimization

7

Page 8: Overview of the IBM Java Just-in-Time Compiler

BASE JVM MODIFICATION (1/2) Object layout

8

Page 9: Overview of the IBM Java Just-in-Time Compiler

BASE JVM MODIFICATION (2/2) Execution of static initializer

Separate the resolution of a class from the execution of its static initializer

Before Change A class is resolved at run-time, together with the

execution of static initializer. After Change

A class is resolved at compile-time. The static initializer is executed upon run-time calls.

9

Page 10: Overview of the IBM Java Just-in-Time Compiler

SELECTIVE COMPILATION Mixed execution

Interpretation + Compiled Code(JIT-generated code)

Rules (using JIT or not?)

Yes Hot methods(frequently invoked methods) Hot branches (frequently traversed branches) Loops included

No Only executed once No loop included 10

Page 11: Overview of the IBM Java Just-in-Time Compiler

BYTECODE-LEVEL OPTIMIZATION Method inlining

11

Page 12: Overview of the IBM Java Just-in-Time Compiler

BYTECODE-LEVEL OPTIMIZATION Exception check elimination

12

Page 13: Overview of the IBM Java Just-in-Time Compiler

BYTECODE-LEVEL OPTIMIZATION Common sub-expression elimination

Scalar ReplacementReplace subscripted variables by local variable references and them available for register allocation

Common effective address generationReduce register pressure

Partial redundancy eliminationReduce the number of accesses to instance variables 13

Page 14: Overview of the IBM Java Just-in-Time Compiler

CODE GENERATION DETAILS

14

Page 15: Overview of the IBM Java Just-in-Time Compiler

The JIT Compiler uses a table with pointers to the methods in the class.

This internal table is used to compile the native code.

Whenever the method is called the address is called.

There is another table which maintains the addresses of the bytecode in case it is needed to be compiled.

15

Page 16: Overview of the IBM Java Just-in-Time Compiler

REGISTER ALLOCATION

The code is broken into tiles. Each loop is a tile and the code in between loops is another tile.

Local variable usage is collected within each tile and a local variable table is prepared.

3 types of registers Stack variable registers Permanent cached local variable registers Temporary cached local variable registers

Circular allocation policy Least recently used register 16

Page 17: Overview of the IBM Java Just-in-Time Compiler

IDIOMS IN BYTECODE SEQUENCES A table of frequently appearing bytecode

sequences as idioms. Reduce the stack height of expression evaluation. Exploits local variable cache registers by avoiding

unnecessary move instructions between local and stack variables.

17

Page 18: Overview of the IBM Java Just-in-Time Compiler

TYPE INCLUSION TEST (1/2) Checks whether two given types are related

by a subclass relationship. Runtime overhead. Cache mechanism for type inclusion testing. Given an object

Null check. Else, compared with the value of the cache that

holds the successful class from the previous test. Else , JVM runtime library is checked and cache

updated.

18

Page 19: Overview of the IBM Java Just-in-Time Compiler

TYPE INCLUSION TEST (2/2)

19

Page 20: Overview of the IBM Java Just-in-Time Compiler

EXCEPTION HANDLING (1/2) When an exception occurs, the JVM searches

for the handler of the current method. If not found, it pops the last frame off the

stack and searches for the handler of the next method on the stack

Till a handler is found or no more frames on the stack.

20

Page 21: Overview of the IBM Java Just-in-Time Compiler

EXCEPTION HANDLING (2/2) For known exceptions: Each method is registered in an exception

registration record. It is done for only those methods which have

a try/catch block. It maintains an exception chain. During exceptions,a conditional jump is

created to the bottom of the code.

21

Page 22: Overview of the IBM Java Just-in-Time Compiler

CODE SCHEDULING Most code scheduling algorithms for static

compilation, when the compilation time is not important.

A code scheduler works with the code generator for a basic block.

When a native code is generated, it is given to the scheduler with some attributes, like reference registers, exception flag, address of memory access etc.

The scheduler considers the dependencies and arranges the code.

Has to guarantee proper execution. Cannot reorder two instructions which may raise exceptions. 22

Page 23: Overview of the IBM Java Just-in-Time Compiler

EXAMPLE

23

Page 24: Overview of the IBM Java Just-in-Time Compiler

Questions

24