SlideShare ist ein Scribd-Unternehmen logo
1 von 131
Downloaden Sie, um offline zu lesen
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright © 2019 Oracle and/or its affiliates.
Java Bytecode Crash Course [DEV4312]
Principal Member of Technical Staff
Java Platform Group
September 16, 2019
David Buck
Copyright © 2019 Oracle and/or its affiliates.
JVM Sustaining Engineer
OpenJDK 8 Update Project
Maintainer
JavaOne Rock Star
Co-author of Oracle WebLogic
Server 11g 構築・運用ガイド
@DavidBuckJP
https://blogs.oracle.com/buck/
Who am I? David Buck (left)
Agenda
Introduction
Foundational Concepts
Examples
Introduction
Why?
Why?
lingua franca of Java platform
Why?
lingua franca of Java platform
javap output
Why?
lingua franca of Java platform
javap output
foundation for future study
bridge methods
type eraser
debugging
javap
-v option to “disassemble” bytecode
-p option to see private methods
use latest version
Disclaimer
Foundational Concepts
What is bytecode?
byte-sized opcodes
Only 256 possible opcodes
operands can be 8 or 16 bit
stack machine
stack machine
push 1
1
stack machine
push 2
1
2
stack machine
add
3
stack machine
Convenient
abstract away CPU register details
free liveness analysis
stack machine
Not that rare
RPN notation
stack machine
Not that rare
RPN notation
PostScript
stack machine
Not that rare
RPN notation
PostScript
Forth
local variables
store / load commands
used to access method arguments
Examples
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
?
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
?
0
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
0
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
0
0
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
0
0
100
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
0
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
1
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
1
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
2
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
3
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
100
Let’s go for a spin!
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
100
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: return
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: return
data “categories”
Size 1
boolean
byte
char
short
int
float
reference
returnAddress
Size 2
long
double
int spin
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
i
int 1
int 0
Double Spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
constant pool loads
constant pool loads
Category 1
ldc
ldc_w
Category 2
ldc2_w
constant pool loads
Category 1
ldc
ldc_w
Category 2
ldc2_w
constant pool loads
Category 1
ldc
ldc_w
Category 2
ldc2_w
constant pool loads
Category 1
ldc
ldc_w
Category 2
ldc2_w
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
but some types are more equal than
others…opcode byte short int long float double char reference
Tipush bipush sipush
Tconst iconst lconst fconst dconst aconst
Tload iload lload fload dload aload
Tstore istore lstore fstore dstore astore
Tinc iinc
Taload baload saload iaload laload faload daload caload aaload
Tastore bastore sastore iastore lastore fastore dastore castore aastore
Tadd iadd ladd fadd dadd
Tsub isub lsub fsub dsub
Tmul imul lmul fmul dmul
Tdiv idiv ldiv fdiv ddiv
Trem irem lrem frem drem
Tneg ineg lneg fneg dneg
Tshl ishl lshl
Tshr ishr lshr
Tushr iushr lushr
Tand iand land
Tor ior lor
Txor ixor lxor
i2T i2b i2s i2l i2f i2d
l2T l2i l2f l2d
f2T f2i f2l f2d
d2T d2i d2l d2f
Tcmp lcmp
Tcmpl fcmpl dcmpl
Tcmpg fcmpg dcmpg
if_TcmpOP if_icmpOP if_acmpOP
Treturn ireturn lreturn freturn dreturn areturn
but some types are more equal than
others…
opcode byte short int long float double char reference
Tipush bipush sipush
Tconst iconst lconst fconst dconst aconst
Tload iload lload fload dload aload
Tstore istore lstore fstore dstore astore
Tinc iinc
Taload baload saload iaload laload faload daload caload aaload
Tastore bastore sastore iastore lastore fastore dastore castore aastore
Tadd iadd ladd fadd dadd
Tsub isub lsub fsub dsub
Tmul imul lmul fmul dmul
Tdiv idiv ldiv fdiv ddiv
Trem irem lrem frem drem
Tneg ineg lneg fneg dneg
Tshl ishl lshl
Tshr ishr lshr
Tushr iushr lushr
Tand iand land
Tor ior lor
Txor ixor lxor
i2T i2b i2s i2l i2f i2d
l2T l2i l2f l2d
f2T f2i f2l f2d
d2T d2i d2l d2f
Tcmp lcmp
Tcmpl fcmpl dcmpl
Tcmpg fcmpg dcmpg
if_TcmpOP if_icmpOP if_acmpOP
Treturn ireturn lreturn freturn dreturn areturn
but some types are more equal than
others…
Actual type
Computational
type
Category
Boolean int 1
byte int 1
char int 1
short int 1
int int 1
float float 1
reference reference 1
returnAddress returnAddress 1
long long 2
double double 2
int spin
void spin() {
int i;
for (i = 0; i < 100; i++) {
;// empty
}
}
void spin();
Code:
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
StackLocals
this
i
int 1
int 0
double spin
void dspin() {
double i;
for (i = 0.0; i < 100.0; i++) {
; //empty
}
}
void dspin();
stack=4, locals=3,
args_size=1
0: dconst_0
1: dstore_1
2: dload_1
3: ldc2_w #2
// double 100.0d
6: dcmpg
7: ifge 17
10: dload_1
11: dconst_1
12: dadd
13: dstore_1
14: goto 2
17: returnStackLocals
this
i (1 of 2)
d1 (2 of 2)
d1 (1 of 2)
i (2 of 2)
d0 (2 of 2)
d0 (1 of 2)
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
void sspin();
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 16
8: iload_1
9: iconst_1
10: iadd
11: i2s
12: istore_1
13: goto 2
16: returnStackLocals
this
i
int 1
int 0
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
void sspin();
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 16
8: iload_1
9: iconst_1
10: iadd
11: i2s
12: istore_1
13: goto 2
16: returnStackLocals
this
i
int 1
int 0
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
void sspin();
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 16
8: iload_1
9: iconst_1
10: iadd
11: i2s
12: istore_1
13: goto 2
16: returnStackLocals
this
i
int 1
int 0
short spin
void sspin() {
short i;
for (i = 0; i < 100; i++) {
; //empty
}
}
void sspin();
stack=2, locals=2,
args_size=1
0: iconst_0
1: istore_1
2: iload_1
3: bipush 100
5: if_icmpge 16
8: iload_1
9: iconst_1
10: iadd
11: i2s
12: istore_1
13: goto 2
16: returnStackLocals
this
i
int 1
int 0
constant pool fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
constant pool fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
constant pool fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
constant pool fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
constant pool fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
Constant Pool Fun
void useManyNumeric() {
int i = 100;
int j = 1000000;
long l1 = 1;
long l2 = 0xffffffff;
double d = 2.2;
// ...do some calculations...
}
void useManyNumeric();
0: bipush 100
2: istore_1
3: ldc #2
// int 1000000
5: istore_2
6: lconst_1
7: lstore_3
8: ldc2_w #3
// long -1l
11: lstore 5
13: ldc2_w #5
// double 2.2d
16: dstore 7
18: return
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
StackLocals
this
i
j
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
StackLocals
this
i
i
j
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
StackLocals
this
i
i
j j
argument passing (virtual)
int addTwo(int i, int j) {
return i + j;
}
int addTwo(int, int);
stack=2, locals=3,
args_size=3
0: iload_1
1: iload_2
2: iadd
3: ireturn
StackLocals
this
i
i+j
j
argument passing (static)
static int addTwoStatic(int i, int j)
{
return i + j;
}
argument passing (static)
static int addTwoStatic(int i, int j)
{
return i + j;
}
static int
addTwoStatic(int, int);
flags: ACC_STATIC
Code:
stack=2, locals=2,
args_size=2
0: iload_0
1: iload_1
2: iadd
3: ireturn
argument passing (static)
static int addTwoStatic(int i, int j)
{
return i + j;
}
static int
addTwoStatic(int, int);
flags: ACC_STATIC
Code:
stack=2, locals=2,
args_size=2
0: iload_0
1: iload_1
2: iadd
3: ireturn
argument passing (static)
static int addTwoStatic(int i, int j)
{
return i + j;
}
static int
addTwoStatic(int, int);
flags: ACC_STATIC
Code:
stack=2, locals=2,
args_size=2
0: iload_0
1: iload_1
2: iadd
3: ireturn
argument passing (static)
static int addTwoStatic(int i, int j)
{
return i + j;
}
static int
addTwoStatic(int, int);
flags: ACC_STATIC
Code:
stack=2, locals=2,
args_size=2
0: iload_0
1: iload_1
2: iadd
3: ireturn
StackLocals
i
j
int 1
int 0
method call (virtual)
int add12and13() {
return addTwo(12, 13);
}
int add12and13();
Code:
stack=3, locals=1,
args_size=1
0: aload_0
1: bipush 12
3: bipush 13
5: invokevirtual #2
// Method addTwo:(II)I
8: ireturn
StackLocals
this
method call (virtual)
int add12and13() {
return addTwo(12, 13);
}
int add12and13();
Code:
stack=3, locals=1,
args_size=1
0: aload_0
1: bipush 12
3: bipush 13
5: invokevirtual #2
// Method addTwo:(II)I
8: ireturn
StackLocals
this this
method call (virtual)
int add12and13() {
return addTwo(12, 13);
}
int add12and13();
Code:
stack=3, locals=1,
args_size=1
0: aload_0
1: bipush 12
3: bipush 13
5: invokevirtual #2
// Method addTwo:(II)I
8: ireturn
StackLocals
this this
12
method call (virtual)
int add12and13() {
return addTwo(12, 13);
}
int add12and13();
Code:
stack=3, locals=1,
args_size=1
0: aload_0
1: bipush 12
3: bipush 13
5: invokevirtual #2
// Method addTwo:(II)I
8: ireturn
StackLocals
this this
12
13
method call (virtual)
int add12and13() {
return addTwo(12, 13);
}
int add12and13();
Code:
stack=3, locals=1,
args_size=1
0: aload_0
1: bipush 12
3: bipush 13
5: invokevirtual #2
// Method addTwo:(II)I
8: ireturn
StackLocals
this 25
method call (static)
int add12and13_static() {
return addTwoStatic(12, 13);
}
int add12and13_static();
Code:
stack=2, locals=1,
args_size=1
0: bipush 12
2: bipush 13
4: invokestatic #3
// Method
addTwoStatic:(II)I
7: ireturn
StackLocals
25
method call (static)
int add12and13_static() {
return addTwoStatic(12, 13);
}
int add12and13_static();
Code:
stack=2, locals=1,
args_size=1
0: bipush 12
2: bipush 13
4: invokestatic #3
// Method
addTwoStatic:(II)I
7: ireturn
StackLocals
12
method call (static)
int add12and13_static() {
return addTwoStatic(12, 13);
}
int add12and13_static();
Code:
stack=2, locals=1,
args_size=1
0: bipush 12
2: bipush 13
4: invokestatic #3
// Method
addTwoStatic:(II)I
7: ireturn
StackLocals
12
13
method call (static)
int add12and13_static() {
return addTwoStatic(12, 13);
}
int add12and13_static();
Code:
stack=2, locals=1,
args_size=1
0: bipush 12
2: bipush 13
4: invokestatic #3
// Method
addTwoStatic:(II)I
7: ireturn
StackLocals
25
method call (private)
class Near {
int it;
public int getItNear() {
return getIt();
}
private int getIt() {
return it;
}
}
method call (private)
class Near {
int it;
public int getItNear() {
return getIt();
}
private int getIt() {
return it;
}
}
public int getItNear();
stack=1, locals=1,
args_size=1
0: aload_0
1: invokespecial #3
// Method getIt:()I
4: ireturn
method call (super class)
class Far extends Near {
int getItFar() {
return super.getItNear();
}
}
method call (private)
class Far extends Near {
int getItFar() {
return super.getItNear();
}
}
int getItFar();
Code:
stack=1, locals=1,
args_size=1
0: aload_0
1: invokespecial #3
// Method
Examples3_7$Near.getItNaer:
()I
4: ireturn
types of calls
invokevirtual
invokestatic
invokeinterface
invokespecial
invokedynamic
types of calls
invokevirtual
invokestatic
invokeinterface
invokespecial
invokedynamic
types of calls
types of calls
invokevirtual
instance method
this pointer
virtual lookup
types of calls
invokevirtual
instance method
this pointer
virtual lookup
invokestatic
class method
no this pointer
static linking
types of calls
invokevirtual
instance method
this pointer
virtual lookup
invokestatic
class method
no this pointer
static linking
invokeinterface
interface method
this pointer
virtual lookup
types of calls
invokevirtual
instance method
this pointer
virtual lookup
invokestatic
class method
no this pointer
static linking
invokeinterface
interface method
this pointer
virtual lookup
invokespecial
Everything else
constructors
super class
private
this pointer
static linking
When two Objects love each other very
much…
Object create() {
return new Object();
}
StackLocals
When two Objects love each other very
much…
Object create() {
return new Object();
}
java.lang.Object create();
stack=2, locals=1,
args_size=1
0: new #2
// class java/lang/Object
3: dup
4: invokespecial #1
// Method
java/lang/Object."<init>":(
)V
7: areturn
StackLocals
When two Objects love each other very
much…
Object create() {
return new Object();
}
java.lang.Object create();
stack=2, locals=1,
args_size=1
0: new #2
// class java/lang/Object
3: dup
4: invokespecial #1
// Method
java/lang/Object."<init>":(
)V
7: areturn
StackLocals
baby
When two Objects love each other very
much…
Object create() {
return new Object();
}
java.lang.Object create();
stack=2, locals=1,
args_size=1
0: new #2
// class java/lang/Object
3: dup
4: invokespecial #1
// Method
java/lang/Object."<init>":(
)V
7: areturn
StackLocals
baby
baby
When two Objects love each other very
much…
Object create() {
return new Object();
}
java.lang.Object create();
stack=2, locals=1,
args_size=1
0: new #2
// class java/lang/Object
3: dup
4: invokespecial #1
// Method
java/lang/Object."<init>":(
)V
7: areturn
StackLocals
baby
field access
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
StackLocals
field access (set)
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
void setIt(int);
stack=2, locals=2,
args_size=2
0: aload_0
1: iload_1
2: putfield #6
// Field i:I
5: return
StackLocals
field access (set)
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
void setIt(int);
stack=2, locals=2,
args_size=2
0: aload_0
1: iload_1
2: putfield #6
// Field i:I
5: return
StackLocals
this
field access (set)
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
void setIt(int);
stack=2, locals=2,
args_size=2
0: aload_0
1: iload_1
2: putfield #6
// Field i:I
5: return
StackLocals
this
value
field access (set)
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
void setIt(int);
stack=2, locals=2,
args_size=2
0: aload_0
1: iload_1
2: putfield #6
// Field i:I
5: return
StackLocals
field access (get)
int i
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
int getIt();
stack=1, locals=1,
args_size=1
0: aload_0
1: getfield #6
// Field i:I
4: ireturn
StackLocals
array opcodes
newarray (primitive type)
anewarray
multianewarray
Tastore (e.g. iastore)
Taload (e.g. faload)
switch statement (table)
int chooseNear(int i) {
switch (i) {
case 0: return 0;
case 1: return 1;
case 2: return 2;
default: return -1;
}
}
switch statement (table)
int chooseNear(int i) {
switch (i) {
case 0: return 0;
case 1: return 1;
case 2: return 2;
default: return -1;
}
}
int chooseNear(int);
0: iload_1
1: tableswitch { // 0 to 2
0: 28
1: 30
2: 32
default: 34
}
28: iconst_0
29: ireturn
30: iconst_1
31: ireturn
32: iconst_2
33: ireturn
34: iconst_m1
35: ireturn
switch statement (sparse)
int chooseFar(int i) {
switch (i) {
case -100: return -1;
case 0: return 0;
case 100: return 1;
default: return -1;
}
}
switch statement (sparse)
int chooseFar(int i) {
switch (i) {
case -100: return -1;
case 0: return 0;
case 100: return 1;
default: return -1;
}
}
int chooseFar(int);
0: iload_1
1: lookupswitch { // 3
-100: 36
0: 38
100: 40
default: 42
}
36: iconst_m1
37: ireturn
38: iconst_0
39: ireturn
40: iconst_1
41: ireturn
42: iconst_m1
43: ireturn
untyped stack operations
pop
pop2
dup
dup2
dup_x1
dup2_x1
dup_x2
dup2_x2
swap
Exceptions
void catchOne();
stack=2, locals=2, args_size=1
0: aload_0
1: invokevirtual #4 // Method tryItOut:()V
4: goto 13
7: astore_1
8: aload_0
9: aload_1
10: invokevirtual #5
// Method handleExc:(Ljava/lang/Exception;)V
13: return
Exception table:
from to target type
0 4 7 Class TestExc
Exceptions
void catchOne() {
try {
tryItOut();
} catch (TestExc e) {
handleExc(e);
}
}
Exceptions
void catchOne();
stack=2, locals=2, args_size=1
0: aload_0
1: invokevirtual #4 // Method tryItOut:()V
4: goto 13
7: astore_1
8: aload_0
9: aload_1
10: invokevirtual #5
// Method handleExc:(Ljava/lang/Exception;)V
13: return
Exception table:
from to target type
0 4 7 Class TestExc
Exceptions
void catchOne();
stack=2, locals=2, args_size=1
0: aload_0
1: invokevirtual #4 // Method tryItOut:()V
4: goto 13
7: astore_1
8: aload_0
9: aload_1
10: invokevirtual #5
// Method handleExc:(Ljava/lang/Exception;)V
13: return
Exception table:
from to target type
0 4 7 Class TestExc
Exceptions
void catchOne();
stack=2, locals=2, args_size=1
0: aload_0
1: invokevirtual #4 // Method tryItOut:()V
4: goto 13
7: astore_1
8: aload_0
9: aload_1
10: invokevirtual #5
// Method handleExc:(Ljava/lang/Exception;)V
13: return
Exception table:
from to target type
0 4 7 Class TestExc
about finally
jsr / ret removed in jdk7 (cass file ver. 51)
now finally block code is just copied to each possible exit point
Q&A
Thank You!!!
Session Survey
Help us make the content
even better. Please complete
the session survey in the
Mobile App.
Copyright © 2019 Oracle and/or its affiliates.
The preceding is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright © 2019 Oracle and/or its affiliates.

Weitere ähnliche Inhalte

Was ist angesagt?

Zend Studio Tips and Tricks
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and Tricks
Roy Ganor
 
Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me? Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me?
DVClub
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014
Antoine Sabot-Durand
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
Anton Arhipov
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 

Was ist angesagt? (20)

Zend Studio Tips and Tricks
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and Tricks
 
01 dll basics
01 dll basics01 dll basics
01 dll basics
 
The Ring programming language version 1.3 book - Part 62 of 88
The Ring programming language version 1.3 book - Part 62 of 88The Ring programming language version 1.3 book - Part 62 of 88
The Ring programming language version 1.3 book - Part 62 of 88
 
Log4 J
Log4 JLog4 J
Log4 J
 
New in php 7
New in php 7New in php 7
New in php 7
 
Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me? Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me?
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
 
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
 
Dependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony ContainerDependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony Container
 
PHP 7 Crash Course
PHP 7 Crash CoursePHP 7 Crash Course
PHP 7 Crash Course
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
 
Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional Explained
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
 
An Overview of Project Jigsaw
An Overview of Project JigsawAn Overview of Project Jigsaw
An Overview of Project Jigsaw
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 

Ähnlich wie Java Bytecode Crash Course [Code One 2019]

various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
CODE BLUE
 

Ähnlich wie Java Bytecode Crash Course [Code One 2019] (20)

The bytecode mumbo-jumbo
The bytecode mumbo-jumboThe bytecode mumbo-jumbo
The bytecode mumbo-jumbo
 
The bytecode hocus pocus - JavaOne 2016
The bytecode hocus pocus - JavaOne 2016The bytecode hocus pocus - JavaOne 2016
The bytecode hocus pocus - JavaOne 2016
 
The bytecode gobbledygook
The bytecode gobbledygookThe bytecode gobbledygook
The bytecode gobbledygook
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 
Common Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleCommon Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by Example
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack02 - Introduction to the cdecl ABI and the x86 stack
02 - Introduction to the cdecl ABI and the x86 stack
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 
3
33
3
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
 
Open bot
Open bot Open bot
Open bot
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and Scheduling
 

Mehr von David Buck

Mehr von David Buck (20)

JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
 
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
 
Z Garbage Collector
Z Garbage CollectorZ Garbage Collector
Z Garbage Collector
 
Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019
 
Var handles jjug_ccc_spring_2018
Var handles jjug_ccc_spring_2018Var handles jjug_ccc_spring_2018
Var handles jjug_ccc_spring_2018
 
JDK 10 へようこそ
JDK 10 へようこそJDK 10 へようこそ
JDK 10 へようこそ
 
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
 
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ  JVM 特集  2015年8月]HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ  JVM 特集  2015年8月]
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
 
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
 
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
 
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
 
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
 
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
 
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
 
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
 
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
 
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584] Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
 
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
 
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
 
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Java Bytecode Crash Course [Code One 2019]

  • 1. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright © 2019 Oracle and/or its affiliates.
  • 2. Java Bytecode Crash Course [DEV4312] Principal Member of Technical Staff Java Platform Group September 16, 2019 David Buck Copyright © 2019 Oracle and/or its affiliates.
  • 3. JVM Sustaining Engineer OpenJDK 8 Update Project Maintainer JavaOne Rock Star Co-author of Oracle WebLogic Server 11g 構築・運用ガイド @DavidBuckJP https://blogs.oracle.com/buck/ Who am I? David Buck (left)
  • 7. Why? lingua franca of Java platform
  • 8. Why? lingua franca of Java platform javap output
  • 9. Why? lingua franca of Java platform javap output foundation for future study bridge methods type eraser debugging
  • 10. javap -v option to “disassemble” bytecode -p option to see private methods use latest version
  • 13. What is bytecode? byte-sized opcodes Only 256 possible opcodes operands can be 8 or 16 bit
  • 18. stack machine Convenient abstract away CPU register details free liveness analysis
  • 19. stack machine Not that rare RPN notation
  • 20. stack machine Not that rare RPN notation PostScript
  • 21. stack machine Not that rare RPN notation PostScript Forth
  • 22. local variables store / load commands used to access method arguments
  • 24. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } }
  • 25. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return
  • 26. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return
  • 27. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return
  • 28. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this ?
  • 29. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this ? 0
  • 30. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 0
  • 31. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 0 0
  • 32. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 0 0 100
  • 33. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 0
  • 34. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 1
  • 35. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 1
  • 36. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 2
  • 37. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 3
  • 38. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 100
  • 39. Let’s go for a spin! void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this 100
  • 40. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } }
  • 41. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } }
  • 42. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: return
  • 43. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: return
  • 45. int spin void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this i int 1 int 0
  • 46. Double Spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 47. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 48. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 50. constant pool loads Category 1 ldc ldc_w Category 2 ldc2_w
  • 51. constant pool loads Category 1 ldc ldc_w Category 2 ldc2_w
  • 52. constant pool loads Category 1 ldc ldc_w Category 2 ldc2_w
  • 53. constant pool loads Category 1 ldc ldc_w Category 2 ldc2_w
  • 54. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 55. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 56. but some types are more equal than others…opcode byte short int long float double char reference Tipush bipush sipush Tconst iconst lconst fconst dconst aconst Tload iload lload fload dload aload Tstore istore lstore fstore dstore astore Tinc iinc Taload baload saload iaload laload faload daload caload aaload Tastore bastore sastore iastore lastore fastore dastore castore aastore Tadd iadd ladd fadd dadd Tsub isub lsub fsub dsub Tmul imul lmul fmul dmul Tdiv idiv ldiv fdiv ddiv Trem irem lrem frem drem Tneg ineg lneg fneg dneg Tshl ishl lshl Tshr ishr lshr Tushr iushr lushr Tand iand land Tor ior lor Txor ixor lxor i2T i2b i2s i2l i2f i2d l2T l2i l2f l2d f2T f2i f2l f2d d2T d2i d2l d2f Tcmp lcmp Tcmpl fcmpl dcmpl Tcmpg fcmpg dcmpg if_TcmpOP if_icmpOP if_acmpOP Treturn ireturn lreturn freturn dreturn areturn
  • 57. but some types are more equal than others… opcode byte short int long float double char reference Tipush bipush sipush Tconst iconst lconst fconst dconst aconst Tload iload lload fload dload aload Tstore istore lstore fstore dstore astore Tinc iinc Taload baload saload iaload laload faload daload caload aaload Tastore bastore sastore iastore lastore fastore dastore castore aastore Tadd iadd ladd fadd dadd Tsub isub lsub fsub dsub Tmul imul lmul fmul dmul Tdiv idiv ldiv fdiv ddiv Trem irem lrem frem drem Tneg ineg lneg fneg dneg Tshl ishl lshl Tshr ishr lshr Tushr iushr lushr Tand iand land Tor ior lor Txor ixor lxor i2T i2b i2s i2l i2f i2d l2T l2i l2f l2d f2T f2i f2l f2d d2T d2i d2l d2f Tcmp lcmp Tcmpl fcmpl dcmpl Tcmpg fcmpg dcmpg if_TcmpOP if_icmpOP if_acmpOP Treturn ireturn lreturn freturn dreturn areturn
  • 58. but some types are more equal than others… Actual type Computational type Category Boolean int 1 byte int 1 char int 1 short int 1 int int 1 float float 1 reference reference 1 returnAddress returnAddress 1 long long 2 double double 2
  • 59. int spin void spin() { int i; for (i = 0; i < 100; i++) { ;// empty } } void spin(); Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: return StackLocals this i int 1 int 0
  • 60. double spin void dspin() { double i; for (i = 0.0; i < 100.0; i++) { ; //empty } } void dspin(); stack=4, locals=3, args_size=1 0: dconst_0 1: dstore_1 2: dload_1 3: ldc2_w #2 // double 100.0d 6: dcmpg 7: ifge 17 10: dload_1 11: dconst_1 12: dadd 13: dstore_1 14: goto 2 17: returnStackLocals this i (1 of 2) d1 (2 of 2) d1 (1 of 2) i (2 of 2) d0 (2 of 2) d0 (1 of 2)
  • 61. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } }
  • 62. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } }
  • 63. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } } void sspin(); stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 16 8: iload_1 9: iconst_1 10: iadd 11: i2s 12: istore_1 13: goto 2 16: returnStackLocals this i int 1 int 0
  • 64. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } } void sspin(); stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 16 8: iload_1 9: iconst_1 10: iadd 11: i2s 12: istore_1 13: goto 2 16: returnStackLocals this i int 1 int 0
  • 65. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } } void sspin(); stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 16 8: iload_1 9: iconst_1 10: iadd 11: i2s 12: istore_1 13: goto 2 16: returnStackLocals this i int 1 int 0
  • 66. short spin void sspin() { short i; for (i = 0; i < 100; i++) { ; //empty } } void sspin(); stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 16 8: iload_1 9: iconst_1 10: iadd 11: i2s 12: istore_1 13: goto 2 16: returnStackLocals this i int 1 int 0
  • 67. constant pool fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 68. constant pool fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 69. constant pool fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 70. constant pool fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 71. constant pool fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 72. Constant Pool Fun void useManyNumeric() { int i = 100; int j = 1000000; long l1 = 1; long l2 = 0xffffffff; double d = 2.2; // ...do some calculations... } void useManyNumeric(); 0: bipush 100 2: istore_1 3: ldc #2 // int 1000000 5: istore_2 6: lconst_1 7: lstore_3 8: ldc2_w #3 // long -1l 11: lstore 5 13: ldc2_w #5 // double 2.2d 16: dstore 7 18: return
  • 73. argument passing (virtual) int addTwo(int i, int j) { return i + j; }
  • 74. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn
  • 75. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn
  • 76. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn StackLocals this i j
  • 77. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn StackLocals this i i j
  • 78. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn StackLocals this i i j j
  • 79. argument passing (virtual) int addTwo(int i, int j) { return i + j; } int addTwo(int, int); stack=2, locals=3, args_size=3 0: iload_1 1: iload_2 2: iadd 3: ireturn StackLocals this i i+j j
  • 80. argument passing (static) static int addTwoStatic(int i, int j) { return i + j; }
  • 81. argument passing (static) static int addTwoStatic(int i, int j) { return i + j; } static int addTwoStatic(int, int); flags: ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: iadd 3: ireturn
  • 82. argument passing (static) static int addTwoStatic(int i, int j) { return i + j; } static int addTwoStatic(int, int); flags: ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: iadd 3: ireturn
  • 83. argument passing (static) static int addTwoStatic(int i, int j) { return i + j; } static int addTwoStatic(int, int); flags: ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: iadd 3: ireturn
  • 84. argument passing (static) static int addTwoStatic(int i, int j) { return i + j; } static int addTwoStatic(int, int); flags: ACC_STATIC Code: stack=2, locals=2, args_size=2 0: iload_0 1: iload_1 2: iadd 3: ireturn StackLocals i j int 1 int 0
  • 85. method call (virtual) int add12and13() { return addTwo(12, 13); } int add12and13(); Code: stack=3, locals=1, args_size=1 0: aload_0 1: bipush 12 3: bipush 13 5: invokevirtual #2 // Method addTwo:(II)I 8: ireturn StackLocals this
  • 86. method call (virtual) int add12and13() { return addTwo(12, 13); } int add12and13(); Code: stack=3, locals=1, args_size=1 0: aload_0 1: bipush 12 3: bipush 13 5: invokevirtual #2 // Method addTwo:(II)I 8: ireturn StackLocals this this
  • 87. method call (virtual) int add12and13() { return addTwo(12, 13); } int add12and13(); Code: stack=3, locals=1, args_size=1 0: aload_0 1: bipush 12 3: bipush 13 5: invokevirtual #2 // Method addTwo:(II)I 8: ireturn StackLocals this this 12
  • 88. method call (virtual) int add12and13() { return addTwo(12, 13); } int add12and13(); Code: stack=3, locals=1, args_size=1 0: aload_0 1: bipush 12 3: bipush 13 5: invokevirtual #2 // Method addTwo:(II)I 8: ireturn StackLocals this this 12 13
  • 89. method call (virtual) int add12and13() { return addTwo(12, 13); } int add12and13(); Code: stack=3, locals=1, args_size=1 0: aload_0 1: bipush 12 3: bipush 13 5: invokevirtual #2 // Method addTwo:(II)I 8: ireturn StackLocals this 25
  • 90. method call (static) int add12and13_static() { return addTwoStatic(12, 13); } int add12and13_static(); Code: stack=2, locals=1, args_size=1 0: bipush 12 2: bipush 13 4: invokestatic #3 // Method addTwoStatic:(II)I 7: ireturn StackLocals 25
  • 91. method call (static) int add12and13_static() { return addTwoStatic(12, 13); } int add12and13_static(); Code: stack=2, locals=1, args_size=1 0: bipush 12 2: bipush 13 4: invokestatic #3 // Method addTwoStatic:(II)I 7: ireturn StackLocals 12
  • 92. method call (static) int add12and13_static() { return addTwoStatic(12, 13); } int add12and13_static(); Code: stack=2, locals=1, args_size=1 0: bipush 12 2: bipush 13 4: invokestatic #3 // Method addTwoStatic:(II)I 7: ireturn StackLocals 12 13
  • 93. method call (static) int add12and13_static() { return addTwoStatic(12, 13); } int add12and13_static(); Code: stack=2, locals=1, args_size=1 0: bipush 12 2: bipush 13 4: invokestatic #3 // Method addTwoStatic:(II)I 7: ireturn StackLocals 25
  • 94. method call (private) class Near { int it; public int getItNear() { return getIt(); } private int getIt() { return it; } }
  • 95. method call (private) class Near { int it; public int getItNear() { return getIt(); } private int getIt() { return it; } } public int getItNear(); stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #3 // Method getIt:()I 4: ireturn
  • 96. method call (super class) class Far extends Near { int getItFar() { return super.getItNear(); } }
  • 97. method call (private) class Far extends Near { int getItFar() { return super.getItNear(); } } int getItFar(); Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #3 // Method Examples3_7$Near.getItNaer: ()I 4: ireturn
  • 101. types of calls invokevirtual instance method this pointer virtual lookup
  • 102. types of calls invokevirtual instance method this pointer virtual lookup invokestatic class method no this pointer static linking
  • 103. types of calls invokevirtual instance method this pointer virtual lookup invokestatic class method no this pointer static linking invokeinterface interface method this pointer virtual lookup
  • 104. types of calls invokevirtual instance method this pointer virtual lookup invokestatic class method no this pointer static linking invokeinterface interface method this pointer virtual lookup invokespecial Everything else constructors super class private this pointer static linking
  • 105. When two Objects love each other very much… Object create() { return new Object(); } StackLocals
  • 106. When two Objects love each other very much… Object create() { return new Object(); } java.lang.Object create(); stack=2, locals=1, args_size=1 0: new #2 // class java/lang/Object 3: dup 4: invokespecial #1 // Method java/lang/Object."<init>":( )V 7: areturn StackLocals
  • 107. When two Objects love each other very much… Object create() { return new Object(); } java.lang.Object create(); stack=2, locals=1, args_size=1 0: new #2 // class java/lang/Object 3: dup 4: invokespecial #1 // Method java/lang/Object."<init>":( )V 7: areturn StackLocals baby
  • 108. When two Objects love each other very much… Object create() { return new Object(); } java.lang.Object create(); stack=2, locals=1, args_size=1 0: new #2 // class java/lang/Object 3: dup 4: invokespecial #1 // Method java/lang/Object."<init>":( )V 7: areturn StackLocals baby baby
  • 109. When two Objects love each other very much… Object create() { return new Object(); } java.lang.Object create(); stack=2, locals=1, args_size=1 0: new #2 // class java/lang/Object 3: dup 4: invokespecial #1 // Method java/lang/Object."<init>":( )V 7: areturn StackLocals baby
  • 110. field access int i void setIt(int value) { i = value; } int getIt() { return i; } StackLocals
  • 111. field access (set) int i void setIt(int value) { i = value; } int getIt() { return i; } void setIt(int); stack=2, locals=2, args_size=2 0: aload_0 1: iload_1 2: putfield #6 // Field i:I 5: return StackLocals
  • 112. field access (set) int i void setIt(int value) { i = value; } int getIt() { return i; } void setIt(int); stack=2, locals=2, args_size=2 0: aload_0 1: iload_1 2: putfield #6 // Field i:I 5: return StackLocals this
  • 113. field access (set) int i void setIt(int value) { i = value; } int getIt() { return i; } void setIt(int); stack=2, locals=2, args_size=2 0: aload_0 1: iload_1 2: putfield #6 // Field i:I 5: return StackLocals this value
  • 114. field access (set) int i void setIt(int value) { i = value; } int getIt() { return i; } void setIt(int); stack=2, locals=2, args_size=2 0: aload_0 1: iload_1 2: putfield #6 // Field i:I 5: return StackLocals
  • 115. field access (get) int i void setIt(int value) { i = value; } int getIt() { return i; } int getIt(); stack=1, locals=1, args_size=1 0: aload_0 1: getfield #6 // Field i:I 4: ireturn StackLocals
  • 116. array opcodes newarray (primitive type) anewarray multianewarray Tastore (e.g. iastore) Taload (e.g. faload)
  • 117. switch statement (table) int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: return -1; } }
  • 118. switch statement (table) int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: return -1; } } int chooseNear(int); 0: iload_1 1: tableswitch { // 0 to 2 0: 28 1: 30 2: 32 default: 34 } 28: iconst_0 29: ireturn 30: iconst_1 31: ireturn 32: iconst_2 33: ireturn 34: iconst_m1 35: ireturn
  • 119. switch statement (sparse) int chooseFar(int i) { switch (i) { case -100: return -1; case 0: return 0; case 100: return 1; default: return -1; } }
  • 120. switch statement (sparse) int chooseFar(int i) { switch (i) { case -100: return -1; case 0: return 0; case 100: return 1; default: return -1; } } int chooseFar(int); 0: iload_1 1: lookupswitch { // 3 -100: 36 0: 38 100: 40 default: 42 } 36: iconst_m1 37: ireturn 38: iconst_0 39: ireturn 40: iconst_1 41: ireturn 42: iconst_m1 43: ireturn
  • 122. Exceptions void catchOne(); stack=2, locals=2, args_size=1 0: aload_0 1: invokevirtual #4 // Method tryItOut:()V 4: goto 13 7: astore_1 8: aload_0 9: aload_1 10: invokevirtual #5 // Method handleExc:(Ljava/lang/Exception;)V 13: return Exception table: from to target type 0 4 7 Class TestExc
  • 123. Exceptions void catchOne() { try { tryItOut(); } catch (TestExc e) { handleExc(e); } }
  • 124. Exceptions void catchOne(); stack=2, locals=2, args_size=1 0: aload_0 1: invokevirtual #4 // Method tryItOut:()V 4: goto 13 7: astore_1 8: aload_0 9: aload_1 10: invokevirtual #5 // Method handleExc:(Ljava/lang/Exception;)V 13: return Exception table: from to target type 0 4 7 Class TestExc
  • 125. Exceptions void catchOne(); stack=2, locals=2, args_size=1 0: aload_0 1: invokevirtual #4 // Method tryItOut:()V 4: goto 13 7: astore_1 8: aload_0 9: aload_1 10: invokevirtual #5 // Method handleExc:(Ljava/lang/Exception;)V 13: return Exception table: from to target type 0 4 7 Class TestExc
  • 126. Exceptions void catchOne(); stack=2, locals=2, args_size=1 0: aload_0 1: invokevirtual #4 // Method tryItOut:()V 4: goto 13 7: astore_1 8: aload_0 9: aload_1 10: invokevirtual #5 // Method handleExc:(Ljava/lang/Exception;)V 13: return Exception table: from to target type 0 4 7 Class TestExc
  • 127. about finally jsr / ret removed in jdk7 (cass file ver. 51) now finally block code is just copied to each possible exit point
  • 128. Q&A
  • 130. Session Survey Help us make the content even better. Please complete the session survey in the Mobile App. Copyright © 2019 Oracle and/or its affiliates.
  • 131. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright © 2019 Oracle and/or its affiliates.