SlideShare a Scribd company logo
© 2015 IBM Corporation
Java Code to Machine Code
How to write highly optimizeable Java code
© 2015 IBM Corporation
Important Disclaimers
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION
CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED.
ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED
ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR
INFRASTRUCTURE DIFFERENCES.
ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT
PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE
USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
- CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR
SUPPLIERS AND/OR LICENSORS
2
© 2015 IBM Corporation3
3
Monitoring and Diagnostics Architect
@Chris__Bailey
@seabaylea
© 2015 IBM Corporation4
Goals of the talk
 Look at how Java code is executed
 Look at how Java code is optimized
 Learn how to enable optimizations to occur
© 2015 IBM Corporation5
> javac
© 2015 IBM Corporation6
Anatomy of a Java Class File
struct Class_File_Format {
u4 magic_number;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count – 1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
© 2015 IBM Corporation7
Anatomy of a Java Class File
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation8
Anatomy of a Java Class File
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Class #2
#2 = Utf8 MyObject
#3 = Class #4
#4 = Utf8 java/lang/Object
#5 = Utf8 myField
#6 = Utf8 I
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Methodref #4.#11
#11 = NameAndType #7:#8
#12 = Fieldref #1.#13
#13 = NameAndType #5:#6
#14 = Utf8 LineNumberTable
#15 = Utf8 LocalVariableTable
#16 = Utf8 this
#17 = Utf8 LmyObject;
#18 = Utf8 SourceFile
#19 = Utf8 MyObject.java
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
© 2015 IBM Corporation9
Anatomy of a Java Class File
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation10
Anatomy of a Java Class File
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Constant Pool
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation11
Anatomy of a Java Class File
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Constant Pool
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation12
Anatomy of a Java Class File
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Operand Stack
Constant Pool
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation13
Anatomy of a Java Class File
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation14
Executing Bytecode
© 2015 IBM Corporation15
Executing Bytecodes
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
© 2015 IBM Corporation16
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation17
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
push
Executing Bytecodes
© 2015 IBM Corporation18
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation19
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation20
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject #4 java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation21
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation22
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code #3.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation23
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation24
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation25
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 #7.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation26
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 <init>.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation27
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 <init>.#8 #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation28
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation29
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.#11 <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation30
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation31
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #10
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation32
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
Executing Bytecodes
© 2015 IBM Corporation33
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
MyObject
Executing Bytecodes
© 2015 IBM Corporation34
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation35
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation36
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
push
MyObject
Executing Bytecodes
© 2015 IBM Corporation37
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation38
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
push
MyObject
Executing Bytecodes
© 2015 IBM Corporation39
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation40
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation41
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation42
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
#2 MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation43
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation44
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V #1.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation45
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation46
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation47
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
#5.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation48
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
myField.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation49
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
myField.#6 LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation50
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation51
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.#13
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation52
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation53
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield #12
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation54
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield MyObject.myField.I
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
Executing Bytecodes
© 2015 IBM Corporation55
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield MyObject.myField.I
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
pop
Executing Bytecodes
© 2015 IBM Corporation56
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield MyObject.myField.I
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
48
pop
Executing Bytecodes
© 2015 IBM Corporation57
public int myField;
flags: ACC_PUBLIC
public MyObject();
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial Object.<init>.()V
4: aload_0
5: bipush 48
7: putfield MyObject.myField.I
10: return
LineNumberTable:
line 4: 0
line 2: 4
line 5: 10
LocalVariableTable:
0 11 0 this LmyObject;
this
Local Variables
48
this
Operand Stack
Constant Pool
Java Heap
MyObject MyObject java/lang/Object java/lang/Object
myField I <init> ()V
Code Object.<init>.()V <init>.()V MyObject.myField.I
myField.I LineNumberTable LocalVariableTable this
LmyObject SourceFile MyObject.java
public class MyObject() {
public int myField = 48;
public MyObject() {
}
}
>
MyObject
48
Executing Bytecodes
© 2015 IBM Corporation58
Local Variables
Operand Stack
Constant Pool
Java Heap
MyObject
48
Executing Bytecodes
© 2015 IBM Corporation59
Machine Code
© 2015 IBM Corporation60
Machine Code
public synchronized int sync1(){
return intArr[0];
}
© 2015 IBM Corporation61
Machine Code
public synchronized int sync1(){
return intArr[0];
}
public int sync2(){
synchronized (this){
return intArr[0];
}
}
© 2015 IBM Corporation62
public synchronized int sync1(){
return intArr[0];
}
public synchronized int sync1();
descriptor: ()I
flags: ACC_PUBLIC, ACC_SYNCHRONIZED
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: getfield #12
4: iconst_0
5: iaload
6: ireturn
public int sync2(){
synchronized (this){
return intArr[0];
}
}
Machine Code
© 2015 IBM Corporation63
public synchronized int sync1(){
return intArr[0];
}
public synchronized int sync1();
descriptor: ()I
flags: ACC_PUBLIC, ACC_SYNCHRONIZED
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: getfield #12
4: iconst_0
5: iaload
6: ireturn
public int sync2();
descriptor: ()I
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=1
0: aload_0
1: dup
2: astore_1
3: monitorenter
4: aload_0
5: getfield #12 // Field intArr:[I
8: iconst_0
9: iaload
10: aload_1
11: monitorexit
12: ireturn
13: aload_1
14: monitorexit
15: athrow
Exception table:
from to target type
4 12 13 any
13 15 13 any
StackMapTable: number_of_entries = 1
frame_type = 255 /* full_frame */
offset_delta = 13
locals = [ class test/SyncClass, class test/SyncClass ]
stack = [ class java/lang/Throwable ]
public int sync2(){
synchronized (this){
return intArr[0];
}
}
Machine Code
© 2015 IBM Corporation64
JIT Optimizations
© 2015 IBM Corporation65
JIT Generated Code
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h ;*iload_0
0x000000000f12156c: imul edx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
© 2015 IBM Corporation66
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h
0x000000000f12156c: imul edx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
JIT Generated Code
© 2015 IBM Corporation67
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h
0x000000000f12156c: imul edx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
JIT Generated Code
© 2015 IBM Corporation68
JIT Generated Code
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h
0x000000000f12156c: imul rdx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
© 2015 IBM Corporation69
JIT Generated Code
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h
0x000000000f12156c: imul rdx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
© 2015 IBM Corporation70
JIT Generated Code
public static int multiply(int a, int b){
return a * b;
}
public static int multiply(int, int);
descriptor: (II)I
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=2
0: iload_0
1: iload_1
2: imul
3: ireturn
LineNumberTable:
line 14: 0
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 a I
0 4 1 b I
# {method} {0x000000000d4408e0} 'multiply' '(II)I'
# parm0: rdx = int
# parm1: r8 = int
# [sp+0x40] (sp of caller)
0x000000000f121560: mov dword ptr
0x000000000f121567: push rbp
0x000000000f121568: sub rsp,30h
0x000000000f12156c: imul rdx,r8d
0x000000000f121570: mov rax,rdx
0x000000000f121573: add rsp,30h
0x000000000f121577: pop rbp
0x000000000f121578: test dword ptr
0x000000000f12157e: ret
© 2015 IBM Corporation71
Inlining
© 2015 IBM Corporation72
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = multiply(factorial, i);
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
© 2015 IBM Corporation73
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = multiply(factorial, i);
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
36 instructions
© 2015 IBM Corporation74
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = multiply(factorial, i);
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
36 instructions
9 instructions
© 2015 IBM Corporation75
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = multiply(factorial, i);
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
36 instructions
9 instructions
© 2015 IBM Corporation76
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial =
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
36 instructions
9 instructions
© 2015 IBM Corporation77
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial =
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
inline
36 instructions
9 instructions
© 2015 IBM Corporation78
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = factorial * i;
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
inline
36 instructions
9 instructions
© 2015 IBM Corporation79
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = factorial * i;
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
9 instructions
36 instructions
© 2015 IBM Corporation80
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = factorial * i;
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
29 instructions
9 instructions
36 instructions
© 2015 IBM Corporation81
Inlining
public static int factorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial = factorial * i;
}
return factorial;
}
public static int multiply(int a, int b){
return a * b;
}
29 instructions
9 instructions
36 instructions
Inlining increases performance by:
● Removing Prologue and Epilogue
● Removing need to set up arguments
© 2015 IBM Corporation82
Enabling Inlining
 Inlining increases performance by removing cost of calling conventions
– Prologue, Eplilogue, Setting up parameters
 Inlining benefits from certainty:
– private, static and final methods are more easily inlined
– public methods can be, depending on morphism
 Inlining benefits from simplicity:
– Must be small: thresholds at ≤35 bytecodes and ≤325 bytecodes
– Simple is faster than complex
© 2015 IBM Corporation83
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
dataSet[i] = transformEntry(dataSet[i]);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
StringBuffer sb = new StringBuffer();
Date date = Calendar.getInstance().getTime();
sb.append(new SimpleDateFormat("yyyyMMdd_HHmmss").format(date));
sb.append(" Error as value at MAX_VALUE ");
data.setErrorMessage(sb.toString());
return data;
}
data.setValue(val + 1);
return data;
}
Too Large
© 2015 IBM Corporation84
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
dataSet[i] = transformEntry(dataSet[i]);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
StringBuffer sb = new StringBuffer();
Date date = Calendar.getInstance().getTime();
sb.append(new SimpleDateFormat("yyyyMMdd_HHmmss").format(date));
sb.append(" Error as value at MAX_VALUE ");
data.setErrorMessage(sb.toString());
return data;
}
data.setValue(val + 1);
return data;
}
Too Large
Exceptional
condition check
© 2015 IBM Corporation85
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
dataSet[i] = transformEntry(dataSet[i]);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
handleError(data);
return data;
}
data.setValue(val + 1);
return data;
}
Replace with
method call
© 2015 IBM Corporation86
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
dataSet[i] = transformEntry(dataSet[i]);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
handleError(data);
return data;
}
data.setValue(val + 1);
return data;
}
© 2015 IBM Corporation87
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
dataSet[i] = transformEntry(dataSet[i]);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
handleError(data);
return data;
}
data.setValue(val + 1);
return data;
}
Inline
© 2015 IBM Corporation88
Example of Enabling Inlining
public void transformData () {
for (int i = 0; i < dataSet.length; i ++) {
int val = dataSet[i].getValue();
if (val == Integer.MAX_VALUE) {
handleError(dataSet[i]);
}
dataSet[i] .setValue(val + 1);
}
}
private int transformEntry(int data){
int val = data.getValue();
if (val == Integer.MAX_VALUE) {
handleError(data);
return data;
}
data.setValue(val + 1);
return data;
}
Not inlined
© 2015 IBM Corporation89
Loop Unrolling
© 2015 IBM Corporation90
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
for (String num : numbers) {
result += parse(num);
}
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
© 2015 IBM Corporation91
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
for (String num : numbers) {
result += parse(num);
}
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
inline
© 2015 IBM Corporation92
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
for (String num : numbers) {
result += Integer.parseInt(num);
}
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
inline
© 2015 IBM Corporation93
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
for (String num : numbers) {
result += Integer.parseInt(num);
}
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
© 2015 IBM Corporation94
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
for (String num : numbers) {
result += Integer.parseInt(num);
}
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
unroll
© 2015 IBM Corporation95
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
result += Integer.parseInt("0");
result += Integer.parseInt("1");
result += Integer.parseInt("2");
result += Integer.parseInt("3");
result += Integer.parseInt("4");
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
© 2015 IBM Corporation96
Loop Unrolling
private static final String[] numbers = {"0", "1", "2", "3", "4"};
public static int total() {
int result = 0;
result += Integer.parseInt("0");
result += Integer.parseInt("1");
result += Integer.parseInt("2");
result += Integer.parseInt("3");
result += Integer.parseInt("4");
return result;
}
private static int parse(String num) {
return Integer.parseInt(num);
}
Possible because
collection is final
© 2015 IBM Corporation97
Enabling LoopUnrolling
 Loop unrolling increases performance by removing cost of:
– Iterating around loop
– Bounds checking
 Loop unrolling benefits from certainty:
– Know the size of the loop
 Loop unrolling benefits from simplicity:
– Loop must be inlinable
© 2015 IBM Corporation98
Synchronization
© 2015 IBM Corporation99
Synchronization approaches
public int[] intArr = {0, 1, 2};
public int sync2(){
synchronized (this){
return intArr[0];
}
}
© 2015 IBM Corporation100
Synchronization approaches
public int[] intArr = {0, 1, 2};
public synchronized int sync1(){
return intArr[0];
}
© 2015 IBM Corporation101
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
for (int i = 0; i < intArr.length; i++) {
result += getEntry(i);
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
© 2015 IBM Corporation102
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
for (int i = 0; i < intArr.length; i++) {
result += getEntry(i);
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
inline
© 2015 IBM Corporation103
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
for (int i = 0; i < intArr.length; i++) {
result += intArr[entry];
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
inline
© 2015 IBM Corporation104
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
for (int i = 0; i < intArr.length; i++) {
result += intArr[entry];
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
© 2015 IBM Corporation105
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
for (int i = 0; i < intArr.length; i++) {
result += intArr[entry];
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
© 2015 IBM Corporation106
Lock Coarsening
public int[] intArr = {0, 1, 2};
public int arrayCount() {
int result = 0;
synchronized {
for (int i = 0; i < intArr.length; i++) {
result += intArr[entry];
}
}
return result;
}
public synchronized int getEntry(int entry){
return intArr[entry];
}
Lock coarsen
© 2015 IBM Corporation107
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
synchronized (syncdList) {
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
}
© 2015 IBM Corporation108
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
synchronized (syncdList) {
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
}
© 2015 IBM Corporation109
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
synchronized (syncdList) {
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
}
© 2015 IBM Corporation110
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
synchronized (syncdList) {
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
}
© 2015 IBM Corporation111
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
synchronized (syncdList) {
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
}
© 2015 IBM Corporation112
Lock Elision
public String walkLockedList() {
List syncdList = new ArrayList();
for (int i = 0; i < 10; i++) {
syncdList.add(i);
}
return syncdList.toString();
}
Lock elision
© 2015 IBM Corporation113
Enabling Synchronization optimizations
 Synchronization optimizations increases performance by removing cost of:
– Unnecessary synchronization
– Repeated synchronization
 Synchronization optimizations from certainty:
– Scope of the object being locked
 Loop unrolling benefits from simplicity:
– Inlining enables removal of locks
© 2015 IBM Corporation114
Field Optimizations
© 2015 IBM Corporation115
Accessing Fields
public static int test = 10;
public static int getTest() {
return test;
}
private static int test = 10;
public static int getTest() {
return test;
}
private final static int test = 10;
public static int getTest() {
return test;
}
public static int getTest() {
return 10;
}
public int test = 10;
public int getTest() {
return test;
}
private int test = 10;
public int getTest() {
return test;
}
public final int test = 10;
public int getTest() {
return test;
}
public int getTest() {
return 10;
}
© 2015 IBM Corporation116
Static Final fields
public static final int test = 10;
public int getTest() {
return test;
}
© 2015 IBM Corporation117
Static Final fields
public static final int test = 10;
public int getTest() {
return test;
}
© 2015 IBM Corporation118
Static Final fields
public static final int test = 10;
public int getTest() {
return test;
}
inline
© 2015 IBM Corporation119
Static Final fields
public static final int test = 10;
public int getTest() {
return 10;
}
inline
© 2015 IBM Corporation120
Static Final fields
public static final int test;
static {
test = new Random().nextInt();
}
public int getTest() {
return test;
}
© 2015 IBM Corporation121
Static Final fields
public static final int test;
static {
test = 7;
}
public int getTest() {
return test;
}
© 2015 IBM Corporation122
Static Final fields
public static final int test = 7;
static {
test = 7;
}
public int getTest() {
return test;
}
© 2015 IBM Corporation123
Static Final fields
public static final int test = 7;
public int getTest() {
return test;
}
© 2015 IBM Corporation124
Static Final fields
public static final int test = 7;
public int getTest() {
return test;
}
inline
© 2015 IBM Corporation125
Static Final fields
public static final int test = 7;
public int getTest() {
return 7;
}
inline
© 2015 IBM Corporation126
Instance Final fields
public final int test = 10;
public FieldTest() {
}
public int getTest() {
return test;
}
© 2015 IBM Corporation127
Instance Final fields
public final int test = 10;
public FieldTest() {
}
public int getTest() {
return test;
}
inline
© 2015 IBM Corporation128
Instance Final fields
public final int test = 10;
public FieldTest() {
}
public int getTest() {
return 10;
}
inline
© 2015 IBM Corporation129
Instance Final fields
public final int test;
public FieldTest(int val) {
this.test = val;
}
public int getTest() {
return test;
}
© 2015 IBM Corporation130
Instance Final fields
public final int test = val;
public FieldTest(int val) {
this.test = val;
}
public int getTest() {
return test;
}
© 2015 IBM Corporation131
Instance Final fields
public final int test = val;
public FieldTest(int val) {
this.test = val;
}
public int getTest() {
return test;
}
Not possible
© 2015 IBM Corporation132
Enabling Field optimizations
 Field optimizations increases performance by:
– Enabling other optimizations
 Optimizations result from certainty:
– Constants (final) are faster than variables
– Locals (parameters and variables) are faster than fields
– private can be faster than public
© 2015 IBM Corporation133
Coding Guidelines
© 2015 IBM Corporation134
Coding Guidelines
 Follow good programming practices!
– Fields that can be final, should be final
– Fields that can be private, should be private
– Data that can be passed as a parameter, should be passed as a parameter
 Follow good object orientated design!
– If function can be delegated to another method, it should be delegated
 This results in short methods and well described data, allowing optimizations.
© 2015 IBM Corporation135
Defaulting to final and private
 Default all fields/variables to final:
– Compile time error:
 Default all fields/variables to private:
– Compile time error:
FieldTest2.java:14: error: cannot assign a value to final variable value
this.value = val;
FieldLauncher.java:14: error: test3 has private access in FieldTest
fieldTest.test3 = 10;
© 2015 IBM Corporation136
Analyzing the JIT
© 2015 IBM Corporation137
Digging into the generated assembler
 HotSpot JIT provides options to look at JIT behaviour:
– -XX:+UnlockDiagnosticVMOptions
– -XX:+TraceClassLoading
– -XX:+LogCompilation
– -XX:+PrintAssembly
 -XX:+PrintAssembly requires additional hdis library
– Installed into jre/bin/server
 Generates output to console and hotspot_pid<pid>.log file
© 2015 IBM Corporation138
Visualizing with JITWatch
 Open source JITWatch tool provides visualization of data:
 “Journal” tells you what optimizations have been applied, and which couldn't be
 Also attempts to make optimization suggestions
© 2015 IBM Corporation139
Summary
© 2015 IBM Corporation140
Certainty
 Locals are faster than globals
– Fields and statics are slow; parameters and locals are fast
 Constants are faster than variables
– final is your friend, especially final static
 private can be faster than public
– protected and package are always just as slow as public
 Small methods (≤100 bytecodes) are good
 Simple is faster than complex
© 2015 IBM Corporation141
Questions?
© 2015 IBM Corporation142
IBM Developer Kits for Java
http://www.ibm.com/java/jdk
IBM Developer Kits for Node.js
http://ibm.co/ibmnodejs
WebShere Liberty Profile
http://wasdev.net
IBM Bluemix
http://www.ibm.com/bluemix
© 2015 IBM Corporation143
Copyright and Trademarks
© IBM Corporation 2015. All Rights Reserved.
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International
Business Machines Corp., and registered in many jurisdictions worldwide.
Other product and service names might be trademarks of IBM or other companies.
A current list of IBM trademarks is available on the Web – see the IBM “Copyright and
trademark information” page at URL: www.ibm.com/legal/copytrade.shtml

More Related Content

PDF
IBM Monitoring and Diagnostics Tools - Health Center 3.0.2
PDF
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
PPTX
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
PDF
Puppet devops wdec
PDF
WebSocket in Enterprise Applications 2015
PPT
Reactive Java EE - Let Me Count the Ways!
PDF
The Play Framework at LinkedIn
PPTX
Top 50 java ee 7 best practices [con5669]
IBM Monitoring and Diagnostics Tools - Health Center 3.0.2
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
Puppet devops wdec
WebSocket in Enterprise Applications 2015
Reactive Java EE - Let Me Count the Ways!
The Play Framework at LinkedIn
Top 50 java ee 7 best practices [con5669]

What's hot (20)

PPTX
Expect the unexpected: Anticipate and prepare for failures in microservices b...
PDF
Modern web application development with java ee 7
PDF
Spring - CDI Interop
PDF
Fifty Features of Java EE 7 in 50 Minutes
PDF
JavaOne 2014 BOF4241 What's Next for JSF?
KEY
Enterprise Java Web Application Frameworks Sample Stack Implementation
PDF
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
PDF
Devoxx17 - Préparez-vous à la modularité selon Java 9
PPTX
Apic dc api deep dive
PPTX
JavaFX Versus HTML5 - JavaOne 2014
PDF
50 New Features of Java EE 7 in 50 minutes
PDF
Java fx smart code econ
PPTX
Custom Buildpacks and Data Services
PDF
02 servlet-basics
PDF
vJUG - The JavaFX Ecosystem
PPTX
Introduction to Spring Boot
PDF
jDays2015 - JavaEE vs. Spring Smackdown
PDF
JavaOne - The JavaFX Community and Ecosystem
PPTX
Preparing for java 9 modules upload
PDF
Head toward Java 14 and Java 15 #LINE_DM
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Modern web application development with java ee 7
Spring - CDI Interop
Fifty Features of Java EE 7 in 50 Minutes
JavaOne 2014 BOF4241 What's Next for JSF?
Enterprise Java Web Application Frameworks Sample Stack Implementation
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
Devoxx17 - Préparez-vous à la modularité selon Java 9
Apic dc api deep dive
JavaFX Versus HTML5 - JavaOne 2014
50 New Features of Java EE 7 in 50 minutes
Java fx smart code econ
Custom Buildpacks and Data Services
02 servlet-basics
vJUG - The JavaFX Ecosystem
Introduction to Spring Boot
jDays2015 - JavaEE vs. Spring Smackdown
JavaOne - The JavaFX Community and Ecosystem
Preparing for java 9 modules upload
Head toward Java 14 and Java 15 #LINE_DM
Ad

Similar to JavaOne 2015: From Java Code to Machine Code (20)

PDF
Introduction to JavaFX on Raspberry Pi
PDF
Batch Applications for the Java Platform
PPTX
Building Large Scale PHP Web Applications with Laravel 4
PPTX
Session - 1 Forms and Session management.pptx
PPT
Spring training
PPTX
Spring andspringboot training
PDF
Towards JVM Dynamic Languages Toolchain
PDF
Ane for 9ria_cn
PPTX
Future of Java EE with SE 8 (revised)
PDF
2015 JavaOne LAD JSF 2.3 & MVC 1.0
PPTX
Code Generation in Magento 2
PDF
How to code to code less
PDF
Salesforce meetup | Lightning Web Component
PDF
Part 2-Support Java 17 Certif Pr Youssfi V2.pdf
PDF
DevDays: Profiling With Java Flight Recorder
PDF
EclipseCon 2010 - JDT Fundamentals
PDF
JDT Fundamentals 2010
PPTX
Type Annotations in Java 8
PDF
ASML_FlightRecorderMeetsJava.pdf
PPT
Creating Custom Dojo Widgets Using WTP
Introduction to JavaFX on Raspberry Pi
Batch Applications for the Java Platform
Building Large Scale PHP Web Applications with Laravel 4
Session - 1 Forms and Session management.pptx
Spring training
Spring andspringboot training
Towards JVM Dynamic Languages Toolchain
Ane for 9ria_cn
Future of Java EE with SE 8 (revised)
2015 JavaOne LAD JSF 2.3 & MVC 1.0
Code Generation in Magento 2
How to code to code less
Salesforce meetup | Lightning Web Component
Part 2-Support Java 17 Certif Pr Youssfi V2.pdf
DevDays: Profiling With Java Flight Recorder
EclipseCon 2010 - JDT Fundamentals
JDT Fundamentals 2010
Type Annotations in Java 8
ASML_FlightRecorderMeetsJava.pdf
Creating Custom Dojo Widgets Using WTP
Ad

More from Chris Bailey (20)

PDF
NodeJS Interactive 2019: FaaS meets Frameworks
PDF
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
PDF
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
PDF
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
PDF
AltConf 2019: Server-Side Swift State of the Union
PDF
Server-side Swift with Swagger
PDF
Node Summit 2018: Cloud Native Node.js
PDF
Index - BFFs vs GraphQL
PDF
Swift Cloud Workshop - Swift Microservices
PDF
Swift Cloud Workshop - Codable, the key to Fullstack Swift
PDF
Try!Swift India 2017: All you need is Swift
PDF
Swift Summit 2017: Server Swift State of the Union
PDF
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
PDF
IBM Cloud University: Java, Node.js and Swift
PDF
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
PDF
FrenchKit 2017: Server(less) Swift
PDF
AltConf 2017: Full Stack Swift in 30 Minutes
PDF
InterConnect: Server Side Swift for Java Developers
PDF
InterConnect: Java, Node.js and Swift - Which, Why and When
PDF
Playgrounds: Mobile + Swift = BFF
NodeJS Interactive 2019: FaaS meets Frameworks
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
AltConf 2019: Server-Side Swift State of the Union
Server-side Swift with Swagger
Node Summit 2018: Cloud Native Node.js
Index - BFFs vs GraphQL
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Try!Swift India 2017: All you need is Swift
Swift Summit 2017: Server Swift State of the Union
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Java, Node.js and Swift
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
FrenchKit 2017: Server(less) Swift
AltConf 2017: Full Stack Swift in 30 Minutes
InterConnect: Server Side Swift for Java Developers
InterConnect: Java, Node.js and Swift - Which, Why and When
Playgrounds: Mobile + Swift = BFF

Recently uploaded (20)

PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
PDF
Build Multi-agent using Agent Development Kit
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
AI in Product Development-omnex systems
PDF
Digital Strategies for Manufacturing Companies
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PDF
medical staffing services at VALiNTRY
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PDF
Become an Agentblazer Champion Challenge Kickoff
The Role of Automation and AI in EHS Management for Data Centers.pdf
Build Multi-agent using Agent Development Kit
ManageIQ - Sprint 268 Review - Slide Deck
AIRLINE PRICE API | FLIGHT API COST |
Best Practices for Rolling Out Competency Management Software.pdf
System and Network Administraation Chapter 3
AI in Product Development-omnex systems
Digital Strategies for Manufacturing Companies
2025 Textile ERP Trends: SAP, Odoo & Oracle
A REACT POMODORO TIMER WEB APPLICATION.pdf
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
medical staffing services at VALiNTRY
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
PTS Company Brochure 2025 (1).pdf.......
Online Work Permit System for Fast Permit Processing
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Become an Agentblazer Champion Challenge Kickoff

JavaOne 2015: From Java Code to Machine Code

  • 1. © 2015 IBM Corporation Java Code to Machine Code How to write highly optimizeable Java code
  • 2. © 2015 IBM Corporation Important Disclaimers THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS 2
  • 3. © 2015 IBM Corporation3 3 Monitoring and Diagnostics Architect @Chris__Bailey @seabaylea
  • 4. © 2015 IBM Corporation4 Goals of the talk  Look at how Java code is executed  Look at how Java code is optimized  Learn how to enable optimizations to occur
  • 5. © 2015 IBM Corporation5 > javac
  • 6. © 2015 IBM Corporation6 Anatomy of a Java Class File struct Class_File_Format { u4 magic_number; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count – 1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
  • 7. © 2015 IBM Corporation7 Anatomy of a Java Class File public class MyObject() { public int myField = 48; public MyObject() { } }
  • 8. © 2015 IBM Corporation8 Anatomy of a Java Class File public class MyObject() { public int myField = 48; public MyObject() { } } flags: ACC_PUBLIC, ACC_SUPER Constant pool: #1 = Class #2 #2 = Utf8 MyObject #3 = Class #4 #4 = Utf8 java/lang/Object #5 = Utf8 myField #6 = Utf8 I #7 = Utf8 <init> #8 = Utf8 ()V #9 = Utf8 Code #10 = Methodref #4.#11 #11 = NameAndType #7:#8 #12 = Fieldref #1.#13 #13 = NameAndType #5:#6 #14 = Utf8 LineNumberTable #15 = Utf8 LocalVariableTable #16 = Utf8 this #17 = Utf8 LmyObject; #18 = Utf8 SourceFile #19 = Utf8 MyObject.java public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject;
  • 9. © 2015 IBM Corporation9 Anatomy of a Java Class File public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; public class MyObject() { public int myField = 48; public MyObject() { } }
  • 10. © 2015 IBM Corporation10 Anatomy of a Java Class File public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Constant Pool #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } }
  • 11. © 2015 IBM Corporation11 Anatomy of a Java Class File public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Constant Pool #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } }
  • 12. © 2015 IBM Corporation12 Anatomy of a Java Class File public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Operand Stack Constant Pool #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } }
  • 13. © 2015 IBM Corporation13 Anatomy of a Java Class File public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } }
  • 14. © 2015 IBM Corporation14 Executing Bytecode
  • 15. © 2015 IBM Corporation15 Executing Bytecodes public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } }
  • 16. © 2015 IBM Corporation16 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 17. © 2015 IBM Corporation17 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > push Executing Bytecodes
  • 18. © 2015 IBM Corporation18 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 19. © 2015 IBM Corporation19 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 20. © 2015 IBM Corporation20 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject #4 java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 21. © 2015 IBM Corporation21 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 22. © 2015 IBM Corporation22 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code #3.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 23. © 2015 IBM Corporation23 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 24. © 2015 IBM Corporation24 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 25. © 2015 IBM Corporation25 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 #7.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 26. © 2015 IBM Corporation26 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 <init>.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 27. © 2015 IBM Corporation27 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 <init>.#8 #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 28. © 2015 IBM Corporation28 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 29. © 2015 IBM Corporation29 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.#11 <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 30. © 2015 IBM Corporation30 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 31. © 2015 IBM Corporation31 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 32. © 2015 IBM Corporation32 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > Executing Bytecodes
  • 33. © 2015 IBM Corporation33 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } MyObject Executing Bytecodes
  • 34. © 2015 IBM Corporation34 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; Local Variables Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 35. © 2015 IBM Corporation35 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 36. © 2015 IBM Corporation36 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > push MyObject Executing Bytecodes
  • 37. © 2015 IBM Corporation37 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 38. © 2015 IBM Corporation38 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > push MyObject Executing Bytecodes
  • 39. © 2015 IBM Corporation39 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 40. © 2015 IBM Corporation40 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 41. © 2015 IBM Corporation41 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 42. © 2015 IBM Corporation42 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap #2 MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 43. © 2015 IBM Corporation43 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 44. © 2015 IBM Corporation44 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V #1.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 45. © 2015 IBM Corporation45 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 46. © 2015 IBM Corporation46 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 47. © 2015 IBM Corporation47 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 #5.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 48. © 2015 IBM Corporation48 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 myField.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 49. © 2015 IBM Corporation49 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 myField.#6 LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 50. © 2015 IBM Corporation50 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 51. © 2015 IBM Corporation51 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.#13 myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 52. © 2015 IBM Corporation52 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 53. © 2015 IBM Corporation53 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield #12 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 54. © 2015 IBM Corporation54 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield MyObject.myField.I 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject Executing Bytecodes
  • 55. © 2015 IBM Corporation55 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield MyObject.myField.I 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject pop Executing Bytecodes
  • 56. © 2015 IBM Corporation56 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield MyObject.myField.I 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject 48 pop Executing Bytecodes
  • 57. © 2015 IBM Corporation57 public int myField; flags: ACC_PUBLIC public MyObject(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial Object.<init>.()V 4: aload_0 5: bipush 48 7: putfield MyObject.myField.I 10: return LineNumberTable: line 4: 0 line 2: 4 line 5: 10 LocalVariableTable: 0 11 0 this LmyObject; this Local Variables 48 this Operand Stack Constant Pool Java Heap MyObject MyObject java/lang/Object java/lang/Object myField I <init> ()V Code Object.<init>.()V <init>.()V MyObject.myField.I myField.I LineNumberTable LocalVariableTable this LmyObject SourceFile MyObject.java public class MyObject() { public int myField = 48; public MyObject() { } } > MyObject 48 Executing Bytecodes
  • 58. © 2015 IBM Corporation58 Local Variables Operand Stack Constant Pool Java Heap MyObject 48 Executing Bytecodes
  • 59. © 2015 IBM Corporation59 Machine Code
  • 60. © 2015 IBM Corporation60 Machine Code public synchronized int sync1(){ return intArr[0]; }
  • 61. © 2015 IBM Corporation61 Machine Code public synchronized int sync1(){ return intArr[0]; } public int sync2(){ synchronized (this){ return intArr[0]; } }
  • 62. © 2015 IBM Corporation62 public synchronized int sync1(){ return intArr[0]; } public synchronized int sync1(); descriptor: ()I flags: ACC_PUBLIC, ACC_SYNCHRONIZED Code: stack=2, locals=1, args_size=1 0: aload_0 1: getfield #12 4: iconst_0 5: iaload 6: ireturn public int sync2(){ synchronized (this){ return intArr[0]; } } Machine Code
  • 63. © 2015 IBM Corporation63 public synchronized int sync1(){ return intArr[0]; } public synchronized int sync1(); descriptor: ()I flags: ACC_PUBLIC, ACC_SYNCHRONIZED Code: stack=2, locals=1, args_size=1 0: aload_0 1: getfield #12 4: iconst_0 5: iaload 6: ireturn public int sync2(); descriptor: ()I flags: ACC_PUBLIC Code: stack=2, locals=2, args_size=1 0: aload_0 1: dup 2: astore_1 3: monitorenter 4: aload_0 5: getfield #12 // Field intArr:[I 8: iconst_0 9: iaload 10: aload_1 11: monitorexit 12: ireturn 13: aload_1 14: monitorexit 15: athrow Exception table: from to target type 4 12 13 any 13 15 13 any StackMapTable: number_of_entries = 1 frame_type = 255 /* full_frame */ offset_delta = 13 locals = [ class test/SyncClass, class test/SyncClass ] stack = [ class java/lang/Throwable ] public int sync2(){ synchronized (this){ return intArr[0]; } } Machine Code
  • 64. © 2015 IBM Corporation64 JIT Optimizations
  • 65. © 2015 IBM Corporation65 JIT Generated Code public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h ;*iload_0 0x000000000f12156c: imul edx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret
  • 66. © 2015 IBM Corporation66 public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h 0x000000000f12156c: imul edx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret JIT Generated Code
  • 67. © 2015 IBM Corporation67 public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h 0x000000000f12156c: imul edx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret JIT Generated Code
  • 68. © 2015 IBM Corporation68 JIT Generated Code public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h 0x000000000f12156c: imul rdx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret
  • 69. © 2015 IBM Corporation69 JIT Generated Code public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h 0x000000000f12156c: imul rdx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret
  • 70. © 2015 IBM Corporation70 JIT Generated Code public static int multiply(int a, int b){ return a * b; } public static int multiply(int, int); descriptor: (II)I flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: imul 3: ireturn LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 4 0 a I 0 4 1 b I # {method} {0x000000000d4408e0} 'multiply' '(II)I' # parm0: rdx = int # parm1: r8 = int # [sp+0x40] (sp of caller) 0x000000000f121560: mov dword ptr 0x000000000f121567: push rbp 0x000000000f121568: sub rsp,30h 0x000000000f12156c: imul rdx,r8d 0x000000000f121570: mov rax,rdx 0x000000000f121573: add rsp,30h 0x000000000f121577: pop rbp 0x000000000f121578: test dword ptr 0x000000000f12157e: ret
  • 71. © 2015 IBM Corporation71 Inlining
  • 72. © 2015 IBM Corporation72 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = multiply(factorial, i); } return factorial; } public static int multiply(int a, int b){ return a * b; }
  • 73. © 2015 IBM Corporation73 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = multiply(factorial, i); } return factorial; } public static int multiply(int a, int b){ return a * b; } 36 instructions
  • 74. © 2015 IBM Corporation74 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = multiply(factorial, i); } return factorial; } public static int multiply(int a, int b){ return a * b; } 36 instructions 9 instructions
  • 75. © 2015 IBM Corporation75 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = multiply(factorial, i); } return factorial; } public static int multiply(int a, int b){ return a * b; } 36 instructions 9 instructions
  • 76. © 2015 IBM Corporation76 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = } return factorial; } public static int multiply(int a, int b){ return a * b; } 36 instructions 9 instructions
  • 77. © 2015 IBM Corporation77 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = } return factorial; } public static int multiply(int a, int b){ return a * b; } inline 36 instructions 9 instructions
  • 78. © 2015 IBM Corporation78 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = factorial * i; } return factorial; } public static int multiply(int a, int b){ return a * b; } inline 36 instructions 9 instructions
  • 79. © 2015 IBM Corporation79 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = factorial * i; } return factorial; } public static int multiply(int a, int b){ return a * b; } 9 instructions 36 instructions
  • 80. © 2015 IBM Corporation80 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = factorial * i; } return factorial; } public static int multiply(int a, int b){ return a * b; } 29 instructions 9 instructions 36 instructions
  • 81. © 2015 IBM Corporation81 Inlining public static int factorial(int num) { int factorial = 1; for (int i = 1; i <= num; i++) { factorial = factorial * i; } return factorial; } public static int multiply(int a, int b){ return a * b; } 29 instructions 9 instructions 36 instructions Inlining increases performance by: ● Removing Prologue and Epilogue ● Removing need to set up arguments
  • 82. © 2015 IBM Corporation82 Enabling Inlining  Inlining increases performance by removing cost of calling conventions – Prologue, Eplilogue, Setting up parameters  Inlining benefits from certainty: – private, static and final methods are more easily inlined – public methods can be, depending on morphism  Inlining benefits from simplicity: – Must be small: thresholds at ≤35 bytecodes and ≤325 bytecodes – Simple is faster than complex
  • 83. © 2015 IBM Corporation83 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { dataSet[i] = transformEntry(dataSet[i]); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { StringBuffer sb = new StringBuffer(); Date date = Calendar.getInstance().getTime(); sb.append(new SimpleDateFormat("yyyyMMdd_HHmmss").format(date)); sb.append(" Error as value at MAX_VALUE "); data.setErrorMessage(sb.toString()); return data; } data.setValue(val + 1); return data; } Too Large
  • 84. © 2015 IBM Corporation84 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { dataSet[i] = transformEntry(dataSet[i]); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { StringBuffer sb = new StringBuffer(); Date date = Calendar.getInstance().getTime(); sb.append(new SimpleDateFormat("yyyyMMdd_HHmmss").format(date)); sb.append(" Error as value at MAX_VALUE "); data.setErrorMessage(sb.toString()); return data; } data.setValue(val + 1); return data; } Too Large Exceptional condition check
  • 85. © 2015 IBM Corporation85 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { dataSet[i] = transformEntry(dataSet[i]); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { handleError(data); return data; } data.setValue(val + 1); return data; } Replace with method call
  • 86. © 2015 IBM Corporation86 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { dataSet[i] = transformEntry(dataSet[i]); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { handleError(data); return data; } data.setValue(val + 1); return data; }
  • 87. © 2015 IBM Corporation87 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { dataSet[i] = transformEntry(dataSet[i]); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { handleError(data); return data; } data.setValue(val + 1); return data; } Inline
  • 88. © 2015 IBM Corporation88 Example of Enabling Inlining public void transformData () { for (int i = 0; i < dataSet.length; i ++) { int val = dataSet[i].getValue(); if (val == Integer.MAX_VALUE) { handleError(dataSet[i]); } dataSet[i] .setValue(val + 1); } } private int transformEntry(int data){ int val = data.getValue(); if (val == Integer.MAX_VALUE) { handleError(data); return data; } data.setValue(val + 1); return data; } Not inlined
  • 89. © 2015 IBM Corporation89 Loop Unrolling
  • 90. © 2015 IBM Corporation90 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; for (String num : numbers) { result += parse(num); } return result; } private static int parse(String num) { return Integer.parseInt(num); }
  • 91. © 2015 IBM Corporation91 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; for (String num : numbers) { result += parse(num); } return result; } private static int parse(String num) { return Integer.parseInt(num); } inline
  • 92. © 2015 IBM Corporation92 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; for (String num : numbers) { result += Integer.parseInt(num); } return result; } private static int parse(String num) { return Integer.parseInt(num); } inline
  • 93. © 2015 IBM Corporation93 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; for (String num : numbers) { result += Integer.parseInt(num); } return result; } private static int parse(String num) { return Integer.parseInt(num); }
  • 94. © 2015 IBM Corporation94 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; for (String num : numbers) { result += Integer.parseInt(num); } return result; } private static int parse(String num) { return Integer.parseInt(num); } unroll
  • 95. © 2015 IBM Corporation95 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; result += Integer.parseInt("0"); result += Integer.parseInt("1"); result += Integer.parseInt("2"); result += Integer.parseInt("3"); result += Integer.parseInt("4"); return result; } private static int parse(String num) { return Integer.parseInt(num); }
  • 96. © 2015 IBM Corporation96 Loop Unrolling private static final String[] numbers = {"0", "1", "2", "3", "4"}; public static int total() { int result = 0; result += Integer.parseInt("0"); result += Integer.parseInt("1"); result += Integer.parseInt("2"); result += Integer.parseInt("3"); result += Integer.parseInt("4"); return result; } private static int parse(String num) { return Integer.parseInt(num); } Possible because collection is final
  • 97. © 2015 IBM Corporation97 Enabling LoopUnrolling  Loop unrolling increases performance by removing cost of: – Iterating around loop – Bounds checking  Loop unrolling benefits from certainty: – Know the size of the loop  Loop unrolling benefits from simplicity: – Loop must be inlinable
  • 98. © 2015 IBM Corporation98 Synchronization
  • 99. © 2015 IBM Corporation99 Synchronization approaches public int[] intArr = {0, 1, 2}; public int sync2(){ synchronized (this){ return intArr[0]; } }
  • 100. © 2015 IBM Corporation100 Synchronization approaches public int[] intArr = {0, 1, 2}; public synchronized int sync1(){ return intArr[0]; }
  • 101. © 2015 IBM Corporation101 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; for (int i = 0; i < intArr.length; i++) { result += getEntry(i); } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; }
  • 102. © 2015 IBM Corporation102 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; for (int i = 0; i < intArr.length; i++) { result += getEntry(i); } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; } inline
  • 103. © 2015 IBM Corporation103 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; for (int i = 0; i < intArr.length; i++) { result += intArr[entry]; } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; } inline
  • 104. © 2015 IBM Corporation104 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; for (int i = 0; i < intArr.length; i++) { result += intArr[entry]; } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; }
  • 105. © 2015 IBM Corporation105 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; for (int i = 0; i < intArr.length; i++) { result += intArr[entry]; } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; }
  • 106. © 2015 IBM Corporation106 Lock Coarsening public int[] intArr = {0, 1, 2}; public int arrayCount() { int result = 0; synchronized { for (int i = 0; i < intArr.length; i++) { result += intArr[entry]; } } return result; } public synchronized int getEntry(int entry){ return intArr[entry]; } Lock coarsen
  • 107. © 2015 IBM Corporation107 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); synchronized (syncdList) { for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } }
  • 108. © 2015 IBM Corporation108 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); synchronized (syncdList) { for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } }
  • 109. © 2015 IBM Corporation109 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); synchronized (syncdList) { for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } }
  • 110. © 2015 IBM Corporation110 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); synchronized (syncdList) { for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } }
  • 111. © 2015 IBM Corporation111 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); synchronized (syncdList) { for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } }
  • 112. © 2015 IBM Corporation112 Lock Elision public String walkLockedList() { List syncdList = new ArrayList(); for (int i = 0; i < 10; i++) { syncdList.add(i); } return syncdList.toString(); } Lock elision
  • 113. © 2015 IBM Corporation113 Enabling Synchronization optimizations  Synchronization optimizations increases performance by removing cost of: – Unnecessary synchronization – Repeated synchronization  Synchronization optimizations from certainty: – Scope of the object being locked  Loop unrolling benefits from simplicity: – Inlining enables removal of locks
  • 114. © 2015 IBM Corporation114 Field Optimizations
  • 115. © 2015 IBM Corporation115 Accessing Fields public static int test = 10; public static int getTest() { return test; } private static int test = 10; public static int getTest() { return test; } private final static int test = 10; public static int getTest() { return test; } public static int getTest() { return 10; } public int test = 10; public int getTest() { return test; } private int test = 10; public int getTest() { return test; } public final int test = 10; public int getTest() { return test; } public int getTest() { return 10; }
  • 116. © 2015 IBM Corporation116 Static Final fields public static final int test = 10; public int getTest() { return test; }
  • 117. © 2015 IBM Corporation117 Static Final fields public static final int test = 10; public int getTest() { return test; }
  • 118. © 2015 IBM Corporation118 Static Final fields public static final int test = 10; public int getTest() { return test; } inline
  • 119. © 2015 IBM Corporation119 Static Final fields public static final int test = 10; public int getTest() { return 10; } inline
  • 120. © 2015 IBM Corporation120 Static Final fields public static final int test; static { test = new Random().nextInt(); } public int getTest() { return test; }
  • 121. © 2015 IBM Corporation121 Static Final fields public static final int test; static { test = 7; } public int getTest() { return test; }
  • 122. © 2015 IBM Corporation122 Static Final fields public static final int test = 7; static { test = 7; } public int getTest() { return test; }
  • 123. © 2015 IBM Corporation123 Static Final fields public static final int test = 7; public int getTest() { return test; }
  • 124. © 2015 IBM Corporation124 Static Final fields public static final int test = 7; public int getTest() { return test; } inline
  • 125. © 2015 IBM Corporation125 Static Final fields public static final int test = 7; public int getTest() { return 7; } inline
  • 126. © 2015 IBM Corporation126 Instance Final fields public final int test = 10; public FieldTest() { } public int getTest() { return test; }
  • 127. © 2015 IBM Corporation127 Instance Final fields public final int test = 10; public FieldTest() { } public int getTest() { return test; } inline
  • 128. © 2015 IBM Corporation128 Instance Final fields public final int test = 10; public FieldTest() { } public int getTest() { return 10; } inline
  • 129. © 2015 IBM Corporation129 Instance Final fields public final int test; public FieldTest(int val) { this.test = val; } public int getTest() { return test; }
  • 130. © 2015 IBM Corporation130 Instance Final fields public final int test = val; public FieldTest(int val) { this.test = val; } public int getTest() { return test; }
  • 131. © 2015 IBM Corporation131 Instance Final fields public final int test = val; public FieldTest(int val) { this.test = val; } public int getTest() { return test; } Not possible
  • 132. © 2015 IBM Corporation132 Enabling Field optimizations  Field optimizations increases performance by: – Enabling other optimizations  Optimizations result from certainty: – Constants (final) are faster than variables – Locals (parameters and variables) are faster than fields – private can be faster than public
  • 133. © 2015 IBM Corporation133 Coding Guidelines
  • 134. © 2015 IBM Corporation134 Coding Guidelines  Follow good programming practices! – Fields that can be final, should be final – Fields that can be private, should be private – Data that can be passed as a parameter, should be passed as a parameter  Follow good object orientated design! – If function can be delegated to another method, it should be delegated  This results in short methods and well described data, allowing optimizations.
  • 135. © 2015 IBM Corporation135 Defaulting to final and private  Default all fields/variables to final: – Compile time error:  Default all fields/variables to private: – Compile time error: FieldTest2.java:14: error: cannot assign a value to final variable value this.value = val; FieldLauncher.java:14: error: test3 has private access in FieldTest fieldTest.test3 = 10;
  • 136. © 2015 IBM Corporation136 Analyzing the JIT
  • 137. © 2015 IBM Corporation137 Digging into the generated assembler  HotSpot JIT provides options to look at JIT behaviour: – -XX:+UnlockDiagnosticVMOptions – -XX:+TraceClassLoading – -XX:+LogCompilation – -XX:+PrintAssembly  -XX:+PrintAssembly requires additional hdis library – Installed into jre/bin/server  Generates output to console and hotspot_pid<pid>.log file
  • 138. © 2015 IBM Corporation138 Visualizing with JITWatch  Open source JITWatch tool provides visualization of data:  “Journal” tells you what optimizations have been applied, and which couldn't be  Also attempts to make optimization suggestions
  • 139. © 2015 IBM Corporation139 Summary
  • 140. © 2015 IBM Corporation140 Certainty  Locals are faster than globals – Fields and statics are slow; parameters and locals are fast  Constants are faster than variables – final is your friend, especially final static  private can be faster than public – protected and package are always just as slow as public  Small methods (≤100 bytecodes) are good  Simple is faster than complex
  • 141. © 2015 IBM Corporation141 Questions?
  • 142. © 2015 IBM Corporation142 IBM Developer Kits for Java http://www.ibm.com/java/jdk IBM Developer Kits for Node.js http://ibm.co/ibmnodejs WebShere Liberty Profile http://wasdev.net IBM Bluemix http://www.ibm.com/bluemix
  • 143. © 2015 IBM Corporation143 Copyright and Trademarks © IBM Corporation 2015. All Rights Reserved. IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., and registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web – see the IBM “Copyright and trademark information” page at URL: www.ibm.com/legal/copytrade.shtml