Title: Java Bytecode Verification for NonNull Types
1Java Bytecode Verification for _at_NonNull Types
- Chris Male, David J. Pearce,
- Alex Potanin and Constantine Dymnikov
-
- Victoria University of Wellington,
- New Zealand
2Introduction
- Suppose
- Bytecode verifier to enforce _at_NonNull
- NullPointerExceptions eliminated for good!
- Useful for optimising away null-checks
3Bytecode Verification
- Standard Bytecode Verifier
- Abstract Store Location ? Type
Local Variable Array
Stack
4Bytecode Verification
- Standard Bytecode Verifier
- Abstract Store Location ? Type
- Can we extend to _at_NonNull types ?
- Abstract Store Location ? _at_NonNull Type
Local Variable Array
Stack
5_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
6_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
7_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
8_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
9_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
Integer
10_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
Integer
11_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
Integer
12_at_NonNull Verification Problem
static int f(Integer,String) 0 aload_0
1 ifnull 8 4 aload_0 5 invokevirtual
8 return
1
0
Integer
Integer
13Type Aliasing
- IDEA add another level of indirection!
- Abstract store Location ? TypeObject ? Type
Local Var Array
Stack
2
0
1
0
String
1
_at_NN String
Integer
2
Abstract Meta Heap
14static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
15static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
16static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
17static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
18static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
19static int f(Integer,String) 0 aload_0 1
ifnull 8 4 aload_0 5 invokevirtual 8
return
20- Abstract Semantics expressed as transition
system
21Abstract Store Subtyping
- Store subtyping needed for termination
- For when stores are joined
astore 1
astore 2
aload 1
22- To show termination requires
- The Transfer Function to be Monotonic
- That the Abstract Stores form a Lattice
?
?
23Equivalence of Stores
- Type Objects have identity (like Java Objects)
- i.e. type objects with the same type can be
distinct - Thus, different abstract stores can be equivalent
24Equivalence of Stores
- Type Objects have identity (like Java Objects)
- i.e. type objects with the same type can be
distinct - Thus, different abstract stores can be equivalent
25(No Transcript)
26Field-Load Fix
- Consider the following Java code
- Can conclude no NullPointerException ?
27Field-Load Fix
- Consider the following Java code
- Now its OK!
28Context Fix
- When programmer knows reference cant be null,
but verifier doesnt! - To deal with these, we must add spurious null
check
29Experimental Results
- Annotated some benchmarks by hand
30(No Transcript)
31Experiences
32Experiences (contd)
33Experiences (contd)
Overall, found 83/1101 methods were misdocumented!
34Generics
- We allow _at_NonNull types in generics
- Some classes cause a problem
35Conclusion
- Bytecode Verification of _at_NonNull Types
- Must deal with aliasing between stack and locals
- Subtyping of Abstract Stores non-trivial
- Situations where programmer knows better
- Problem with generic collections like HashMap
- Contact david.pearce_at_mcs.vuw.ac.nz
36Equivalence of Stores
- Type Objects have identity (like Java Objects)
- i.e. type objects with the same type can be
distinct - Thus, different abstract stores can be equivalent
2
0
1
String
0
Integer
1
37Implementation Considerations
- Constructors
- Generics hash map problems
- Field Retyping
- Casting/Arrays
- New Operator
- Instance Of
- Static blocks
- Effect of interface limitation
38Graph Isomorphism