Weitere ähnliche Inhalte Ähnlich wie Java Bytecode Crash Course [Code One 2019] (20) Kürzlich hochgeladen (20) 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)
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
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
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)
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)
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
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
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
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
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
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
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
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
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.