1 / 12

Synthesis, Analysis, and Verification Lecture 13

Synthesis, Analysis, and Verification Lecture 13. Dynamic Allocation. Linked List Example. class List { List next; } public static void main(){ // alloc ={}, next=  x.null List first = new List(); // alloc ={o1}, next=  x.null

mills
Télécharger la présentation

Synthesis, Analysis, and Verification Lecture 13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synthesis, Analysis, and VerificationLecture 13 Dynamic Allocation

  2. Linked List Example class List{ List next; } public static void main(){ //alloc={}, next=x.null List first = new List(); //alloc={o1}, next=x.null List second = new List();//alloc={o1,o2}, next=x.null first.next = second; //alloc={o1,o2}, next=x.if(x==o1) o2 else null second.next = first; //alloc={o1,o2}, next=x.if(x==o2) o1 else if (x==o1) o2 else null } null next next o1 o2 o3 next ... AllObjects \ alloc

  3. Linked List Example class List{ List next; } public static void main(){ //alloc={}, next=x.null List first = new List(); //alloc={o1}, next=x.null List second = new List();//alloc={o1,o2}, next=x.null first.next = second; //alloc={o1,o2}, next=x.if(x==o1) o2 else null second.next = first; //alloc={o1,o2}, next=x.if(x==o2) o1 else if (x==o1) o2 else null } null next next next o1 o2 o3 ... AllObjects \ alloc first second

  4. Linked List Example class List{ List next; } public static void main(){ //alloc={}, next=x.null List first = new List(); //alloc={o1}, next=x.null List second = new List();//alloc={o1,o2}, next=x.null first.next = second; //alloc={o1,o2}, next=x.if(x==o1) o2 else null second.next = first; //alloc={o1,o2}, next=x.if(x==o2) o1 else if (x==o1) o2 else null } null next next o1 o2 o3 ... next AllObjects \ alloc first second

  5. Memory Allocation in Java x = new C(); y = new C(); assert(x != y); // fresh object references-distinct Why should this assertion hold? How to give meaning to ‘new’ so we can prove it?

  6. A View of the World Everything exists, and will always exist.(It is just waiting for its time to become allocated.) It will never die (but may become unreachable). alloc : Obj Boolean i.e. alloc : Set[Obj] x = new C();  ^defult constructor

  7. New Objects Point Nowhere class C { int f; C next; C prev; } this should work: x = new C(); assert(x.f==0 && x.next==null && x.prev==null) x = new C(); 

  8. If you are new, you are known by few class C { int f; C next; C prev; } Assume C is the only class in the program Lonely object: no other object points to it. Newly allocated objects are lonely! x = new C(); 

  9. Remember our Model of Java Arrays length : Array -> int data : Array -> (Int -> Int) or simply: Array x Int -> Int • assertassert data= data( (a,i):= x) class Array { int length; data : int[]} a[i] = x y = a[i]

  10. Allocating New Array of Objects class oArray{ int length; data : Object[]} x = new oArray[100] 

  11. D-Linked List assume P; if (first == null) { first = n; n.next = null; n.prev = null; } else { n.next = first; first.prev = n; n.prev = null; first = n; } assert Q;

  12. How to prove such verification conditions automatically?

More Related