software verification for java 5
play

Software Verification for Java 5 KeY Symposium 2007 Mattias Ulbrich - PowerPoint PPT Presentation

KeY + Java 5 Enums Enhanced loops Generics Software Verification for Java 5 KeY Symposium 2007 Mattias Ulbrich June 14, 2007 KeY + Java 5 Enums Enhanced loops Generics Content KeY + Java 5 Typesafe Enumeration Datatypes Enhanced For


  1. KeY + Java 5 Enums Enhanced loops Generics Software Verification for Java 5 KeY Symposium 2007 Mattias Ulbrich June 14, 2007

  2. KeY + Java 5 Enums Enhanced loops Generics Content KeY + Java 5 Typesafe Enumeration Datatypes Enhanced For Loops Generic Classes

  3. KeY + Java 5 Enums Enhanced loops Generics 1. Keep pace with the progress of the industrial standard 2. Examine KeY’s flexibility and adaptibility 3. Do the new features support verification? 4. Do they need verification?

  4. KeY + Java 5 Enums Enhanced loops Generics Novelties in the language in Java 5 • Typesafe enumeration types • Covariant return types • Iteration loops • Static imports • Auto-Boxing of primitive types • Annotations • Generic classes • Variable arguments

  5. KeY + Java 5 Enums Enhanced loops Generics Novelties in the language in Java 5 • Typesafe enumeration types • Covariant return types • Iteration loops • Static imports • Auto-Boxing of primitive types • Annotations • Generic classes • Variable arguments No relevance for verification

  6. KeY + Java 5 Enums Enhanced loops Generics Novelties in the language in Java 5 • Typesafe enumeration types • Covariant return types • Iteration loops • Static imports • Auto-Boxing of primitive types • Annotations • Generic classes • Variable arguments No relevance for verification

  7. KeY + Java 5 Enums Enhanced loops Generics Typesafe Enumeration Datatypes

  8. KeY + Java 5 Enums Enhanced loops Generics Typesafe Enumeration Datatypes enum E { e 1 , e 2 , . . . , e n } • A new keyword to declare enumeration types: enum • followed by the name of the datatype • followed by the enum constants • enum declares reference types – not primitive types • the enum constants uniquely enumerate all (non-null) instances Example enum Season { SPRING, SUMMER, AUTUMN, WINTER }

  9. KeY + Java 5 Enums Enhanced loops Generics Using the object repository Enumerations are reference types (special classes in fact) = ⇒ Use the mechanisms available for reference types. The object repository C :: � get � () : Nat ֌ → C For every exact instance o of a class C there is an index i ∈ Nat · with o = C :: � get � ( i ).

  10. KeY + Java 5 Enums Enhanced loops Generics Using the object repository Enumerations are reference types (special classes in fact) = ⇒ Use the mechanisms available for reference types. The object repository C :: � get � () : Nat ֌ → C For every exact instance o of a class C there is an index i ∈ Nat · with o = C :: � get � ( i ). Repository access for Enums: · E . e 1 = E :: � get � (0) · E . e 2 = E :: � get � (1) . . . · E . e n = E :: � get � ( n − 1) · E :: � nextToCreate � = n

  11. KeY + Java 5 Enums Enhanced loops Generics Advantages Using the standard object repository is good: • Only few new rules in the calculus to handle enums • Use established techniques • Problems on enum instances are reduced to problems on their indexes, thus natural numbers • Scales well

  12. KeY + Java 5 Enums Enhanced loops Generics Enhanced For Loops

  13. KeY + Java 5 Enums Enhanced loops Generics Enhanced For Loops Purpose The enhanced for loop allows to iterate through a collection or an array without having to create an explicit Iterator or counter variable.

  14. KeY + Java 5 Enums Enhanced loops Generics Enhanced For Loops Purpose The enhanced for loop allows to iterate through a collection or an array without having to create an explicit Iterator or counter variable. Traditional Java for ( int i = 0; i < array.length; i++) { System.out. println (array [ i ]); }

  15. KeY + Java 5 Enums Enhanced loops Generics Enhanced For Loops Purpose The enhanced for loop allows to iterate through a collection or an array without having to create an explicit Iterator or counter variable. Traditional Java for ( int i = 0; i < array.length; i++) { System.out. println (array [ i ]); } Java 5 for ( int x : array) { System.out. println (x); }

  16. KeY + Java 5 Enums Enhanced loops Generics Equivalent loops for ( int x : array) { / ∗ body ∗ / } int a [ ] = array; for ( int i = 0; i < a .length; i ++) { int x = a [ i ]; / ∗ body ∗ / }

  17. KeY + Java 5 Enums Enhanced loops Generics Equivalent loops for ( int x : array) { / ∗ body ∗ / } int a [ ] = array; for ( int i = 0; i < a .length; i ++) { int x = a [ i ]; / ∗ body ∗ / } 1. a and i are new variables not accessible from within body 2. a.length is constant in this context 3. The counter i is incremented in every iteration = ⇒ There are finite many iterations = ⇒ The loop terminates if every iteration terminates.

  18. KeY + Java 5 Enums Enhanced loops Generics Invariant rules with termination Null Case Base Case Abnormal body termination Invariant preserved Use Case enhForArrayInv Γ ⊢ U � for( ty x : se ){ p } � ϕ, ∆ 1. uses the �·� -modality 2. the sequents contain more formulae: the encoded extra knowledge about the special loop.

  19. KeY + Java 5 Enums Enhanced loops Generics “Enhanced For = Enhanced Performance” Experimental results using this rule Verification of the “maximum in an array” loop. new rule while rule Nodes in the proof tree 374 1053 Branches in the proof tree 8 21 Additional manual instantiations 2 3 = ⇒ Complexity reduced to roughly a third. A syntactical entity that is specialised allows to retrieve more information and thereby shorten proofs.

  20. KeY + Java 5 Enums Enhanced loops Generics Generic Classes = Parametric Polymorphism

  21. KeY + Java 5 Enums Enhanced loops Generics Generics ∗ improve static typing and type safety ∗ if they were well-implemented

  22. KeY + Java 5 Enums Enhanced loops Generics Generics ∗ improve static typing and type safety Traditional Java Java 5 Vector v = new Vector(); Vector < String > v = new Vector < String > (); v.add(”String”); v.add(”String”); String s = (String)v.get(0); String s = v.get(0); ∗ if they were well-implemented

  23. KeY + Java 5 Enums Enhanced loops Generics Generics ∗ improve static typing and type safety Traditional Java Java 5 Vector v = new Vector(); Vector < String > v = new Vector < String > (); v.add(”String”); v.add(”String”); String s = (String)v.get(0); String s = v.get(0); • Type checking performed at • Type checking performed at run-time compile-time • failure must be taken into • no possible exception that account by verifier must be taken into account by verifier ∗ if they were well-implemented

  24. KeY + Java 5 Enums Enhanced loops Generics Polymorphic functions Attributes induce functions class Chain { Chain tail ; Object head; head : Chain → Object }

  25. KeY + Java 5 Enums Enhanced loops Generics Polymorphic functions Attributes induce functions class Chain { Chain tail ; Object head; head : Chain → Object } Polymorphic attributes induce polymorphic functions class Chain < T > { Chain < T > tail; T head; head : ∀ T . Chain � T � → T } This is a well-known concept in type-theory, but not in many-sorted logics.

  26. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” String is a valid type that can show up at run-time.

  27. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < String > is a valid type that can show up at run-time.

  28. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < Vector < String >> is a valid type that can show up at run-time.

  29. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < Vector < Vector < String >>> is a valid type that can show up at run-time.

  30. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < ...Vector < Vector < Vector < String >>> ... > is a valid type that can show up at run-time.

  31. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < ...Vector < Vector < Vector < String >>> ... > is a valid type that can show up at run-time. Problem Some rules need a finite type system to enumerate types (method dispatch, dynamic subtypes, . . . )

  32. KeY + Java 5 Enums Enhanced loops Generics Infinite type system “Parametric recursion” Vector < ...Vector < Vector < Vector < String >>> ... > is a valid type that can show up at run-time. Problem Some rules need a finite type system to enumerate types (method dispatch, dynamic subtypes, . . . ) Handle this in JavaDL ... ... with existentially quantified type variables ∃ X . object 1 Vector � X �

  33. KeY + Java 5 Enums Enhanced loops Generics Type Meta-types ⊤ ������ ������ D ❏ ������ ������ Object ������ ������ ❏ integers boolean ������ ������ ������ ������ ������ ������ • Add the “type of reference types” ❏ to the type hierarchy. • Add the reference types as new objects to the domain • Add appropriate function symbols to the signature = ⇒ Allow quantification over types class

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