inference of field initialization
play

Inference of Field Initialization Fausto Spoto and Michael D. Ernst - PowerPoint PPT Presentation

Inference of Field Initialization Fausto Spoto and Michael D. Ernst University of Verona, Italy & University of Washington, USA Honolulu, May 25, 2011, ICSE 1 / 8 Clever tracking of windows by name (from a real story) public class MyWindow


  1. Inference of Field Initialization Fausto Spoto and Michael D. Ernst University of Verona, Italy & University of Washington, USA Honolulu, May 25, 2011, ICSE 1 / 8

  2. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; setVisible(true); } public static void main(String[] args) { new MyWindow("first"); new MyWindow("second"); } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 2 / 8

  3. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; setVisible(true); } public static void main(String[] args) { new MyWindow("first"); new MyWindow("second"); } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 3 / 8

  4. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; setVisible(true); } public static void main(String[] args) { new MyWindow("first"); new MyWindow("second"); } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 4 / 8

  5. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; setVisible(true); } public static void main(String[] args) { new MyWindow("first"); new MyWindow("second"); } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 5 / 8

  6. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 6 / 8

  7. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 7 / 8

  8. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 8 / 8

  9. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 9 / 8

  10. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 10 / 8

  11. Clever tracking of windows by name (from a real story) public class MyWindow extends JWindow { private final String name; // never null private final static Map<String, MyWindow> map = new Hashtable<String, MyWindow>(); public MyWindow(String name) { this.name = name; Execution trace setVisible(true); NullPointerException } at Hashtable.put() public static void main(String[] args) { at MyWindow.windowInit() new MyWindow("first"); at JWindow.<init>() at MyWindow.<init>() new MyWindow("second"); at MyWindow.main() } @Override protected void windowInit() { super.windowInit(); map.put(name, this); } } 11 / 8

  12. The notion of rawness Definition (Raw object) An object is raw wrt. fields F iff some field in F is not initialized. Example Variable this is raw inside windowInit wrt. field name : @Override @Raw protected void windowInit() { ... map.put(name, this); } Hence there is no guarantee that name is already initialized there . Note: assigning null into a field makes it initialized 12 / 8

  13. The notion of rawness Definition (Raw object) An object is raw wrt. fields F iff some field in F is not initialized. Example Variable this is raw inside windowInit wrt. field name : @Override @Raw protected void windowInit() { ... map.put(name, this); } Hence there is no guarantee that name is already initialized there . Note: assigning null into a field makes it initialized 13 / 8

  14. Our goal: an automatic inference for initialization 1 define a concrete operational semantics of a Java-like language 2 define a constraint-based abstract interpretation of that semantics 3 prove them related by a correctness relation 4 use our abstract interpretation as an inference engine for initialization 5 measure its precision by using nullness analysis but any other analysis could be used instead 14 / 8

  15. Java bytecode as a graph of basic blocks load 0 of type MyWindow call javax.swing.JWindow.<init>():void load 0 of type MyWindow load 1 of type java.lang.String putfield MyWindow.name:java.lang.String load 0 of type MyWindow const 1 call MyWindow.setVisible(boolean):void catch return void throw java.lang.Throwable a graph for each constructor or method explicit, inferred types resolved field and method references (through class analysis) explicit exception handlers 15 / 8

  16. Bytecodes work over states A state is a triple � l | | s | | µ � of local variables , operand stack and heap , that binds locations to objects . An object o belongs to class o .κ ∈ K and maps field identifiers f into o . f , which can be a value or uninit . locals stack < [this,name], , > this µ this.name = name; ⇓ offset 0 String load 0 of type MyWindow count load 1 of type String 12 value putfield MyWindow.name char[] MyWindow name uninit 16 / 8

  17. Bytecodes work over states A state is a triple � l | | s | | µ � of local variables , operand stack and heap , that binds locations to objects . An object o belongs to class o .κ ∈ K and maps field identifiers f into o . f , which can be a value or uninit . locals stack < [this,name], this , > ::name µ this.name = name; ⇓ offset 0 String load 0 of type MyWindow count load 1 of type String 12 value putfield MyWindow.name char[] MyWindow name uninit 17 / 8

  18. Bytecodes work over states A state is a triple � l | | s | | µ � of local variables , operand stack and heap , that binds locations to objects . An object o belongs to class o .κ ∈ K and maps field identifiers f into o . f , which can be a value or uninit . locals stack < [this,name], , > ε µ this.name = name; ⇓ offset 0 String load 0 of type MyWindow count load 1 of type String 12 name value putfield MyWindow.name char[] MyWindow 18 / 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend