Abstract Semantics for Java 1.4 Programs

Part I of: Verification of LePUS3/Class-Z Specifications: Sample models and Abstract Semantics for Java 1.4

Technical Report CSM-471, ISSN 1744-8050

Print this document

Jonathan Nicholson, Amnon H Eden, Epameinondas Gasparis
Department of Computer Science, University of Essex, United Kingdom

31 December 2007

See also: Part II, Verification of LePUS3/Class-Z Specifications

Abstract

This document is a compendium of examples that describe the entities and relations that represent the abstract semantics (finite structures) of programs in the JavaTM programming language. It is designed to provide further explanation to the definitions given in the LePUS3 and Class-Z Reference manual [Eden et al. 2007].

To remind the reader, a finite structure is a simplified ('abstracted') picture of the program, which 'flattens' the knotty structure and syntax of the source code into a set of primitive entities (also called entities of dimension 0) and relations. Essentially, each finite structure can be viewed as a relational database, or a set of tables which contain tuples of entities ('records'). Below we list a few sample Java programs and the finite structure that represents them.

See also:

Classes

In the abstract semantics of the Java programming language, each entity in the unary relation (also called 'a class of dimension 0') stands for one of the static types mentioned in the program which, in Java, includes classes (java.lang.Object), interfaces (java.util.Collection), primitive types (int), and array types (int[]). Following are some examples that should demonstrate the correlation between types in Java programs and the entities which represent them.

Program Partial finite structure
								
public class A {
 int integer;
 int[] array = new int[5];
 class inner {
  class nestedInner { ... }
 }
}

public interface B { ... }
								
							

Methods and signatures

Each entity in the unary relation (also called 'a method of dimension 0') stands for exactly one method in a Java Program.

Each entity in the unary relation (also called 'a signature of dimension 0') stands for the signature (name and argument types) of one or more of the methods in a Java Program.

The pair in the binary relation indicates that the method has the signature . Since every method in a Java program has exactly one signature, each method is associated with exactly one signature.

The relation (see below) associates methods with classes, and the relation (see below) indicates that a method is accessible from subclasses.

The compiler adds the empty constructor if one has not been provided.

Program Complete finite structure
							
public class Cls {
 public void mth() { ... }
}								
							
Program Partial finite structure
							
public class A {
 public void t() { ... }
 public void z() { ... }
}

public interface B {
 public void s();
}

public class C
   extends A implements B {
 public void s() { ... }
 public void s(int i) { ... }
 public void t() { ... }
}
								
							

Abstract Relation

The contents of the unary (Definition VII) relation are (Definition III) and (Definition VI) entities. If an entity exists in this relation then the related section of program is abstract, for example an Interface is always abstract.
Program Partial finite structure
									
	public abstract class A {
	 public abstract void s();
	 public void t() { ... }
	}
	
	public interface B {
	 public void s();
	}
									
								

Inherit Relation

The binary (Definition VIII) relation represents inheritance, in terms of Javatm this means the keywords extend and implements, as well as the subtyping relation. In Javatm there is no inheritance between methods, and all classes which do not explicitly extend or implement from anything are taken to extend class java.lang.Object.

Program Partial finite structure
								
public class A extends B
   implements C { ... }

public class B { ... }

public interface C
   extends D { ... }

public interface D { ... }
								
							

Inheritable Relation

The contents of the unary (Definition VII) relation are entities (Definition VI) which were decorated with the public or protected access modifiers. Methods declared within final classes are not "inheritable" as the class its self cannot be inherited from.

Constructors are never .

Program Partial finite structure
								
public class A {
 public void x() { ... }
 protected void y() { ... }
 private void z() { ... }
}

public final class B {
 public void x() { ... }
 protected void y() { ... }
 private void z() { ... }
}
								
							

Member and Aggregate Relations

The binary (Definition VIII) relation represents the ownership one class has of its methods and fields. The domain is always the "owner", and the range is either the method or type of the field in question.

The binary (Definition VIII) relation shows that a class has a collection/array of a specified type. The domain is always the "owner", and the range is the basic type stored in the collection/array. An relation is added for any array, or for any field which inherits from java.util.Collection.

Program Partial finite structure
								
public class C {
 Object o1;
 Object o2;
 String[] stringArray;
 int[][] intArray;
 Set objectSet;
}
								
							

Call and Forward Relations

The binary (Definition VIII) and relations are very similar in that both indicate to a method call within the program. An invokation of a method with the same signature as the domain, using the same objects as defined by the domains arguments, is known as a forwarding method call.
Program Partial finite structure
								
public class A {
 public void s() {
  s();  // Forward
  t(1); // Call
 }
 public void t(int i) {
  t(i); // Forward
  t(1); // Call
 }
}

public class B extends A {
 public void t() {
  s();  // Call
  t(1); // Call
 }
 public void t(int i) { ... }
}
								
							

Create Relation

The binary (Definition VIII) relation most commonly represents the keyword new for class instantiation, however it also represents the initialisation of a primitive type. It is worth noting that a fields initialisation is actually performed within each the constructor(s) as in the following example.
Program Partial finite structure
								
public class C {
 public Object o = new Object();
 
 public void s() {
  int i = 0;
  new Object();
  Object s = new String();
  put(new Integer(1));
  int[][] array = new int[5][5];
 }
 public Object put(Integer i)
    { ... }
}
								
							

Return Relation

The binary (Definition VIII) represents return statements in the program. Statements such as "return;" break from further execution of the method, but does not return a value. Therefore these statements are ignored.
Program Partial finite structure
								
public class C {
 Object o = new Object();
 String s = new String("");
 int i = 5;
 
 public Object s1() {
  if (true)
   return o;
  if (true)
   return s;
  return null;
 }
 public int s2() {
  return i;
 }
}
								
							

Produce Relation

The binary (Definition VIII) relation identifies methods which "creates" and "returns" an object during execution of the method.
Program Partial finite structure
								
public class C {
 public Object s1() {
  String s = "str";
  if (true)
   return new Object();
  return s;
 }

 public int s2() {
  return 5;
  }
}
								
							

References