Multiple Code Inheritance Scenarios

Code in Interfaces



Download the scenario source files (scenarios.tar.gz).

Code in Interfaces Scenario Diagram:

Code in Interfaces Scenarios


The class Test contains a call-site where the static type of the receiver is any type (implementation or class) shown in this scenario, the dynamic type of the receiver is class C, and the method name is alpha(). A message alpha() is sent to an instance of class C and the result of the dispatch is printed.

COMPILATION:

The Java source files can be compiled with our modified Java compiler, mcijavac, as follows:
$ mcijavac *.java
Note: If your CLASSPATH is not set to include the directory mciJVM/build/linux/classes, you can use the following command instead:

mcijavac -bootclasspath jvmPath/mciJVM/build/linux/classes *.java

where jvmPath represents the absolute path that includes the mciJVM directory.

EXECUTION:

After the Java files are compiled, the Test is executed with our modified JVM, mcijava, as follows:
$ mcijava Test

Note: If your CLASSPATH is not set to include the directory mciJVM/build/linux/classes, you can use the following command instead:i

mcijava -Xbootclasspath/p:jvmPath/mciJVM/build/linux/classes Test where jvmPath represents the absolute path that includes the mciJVM directory.

To untar the tar.gz files:
tar -xzvf mciJVM.tar.gz
tar -xzvf scenarios.tar.gz


sc0

SCENARIO 0:

This scenario generates a compiler error. Type A contains an abstract method alpha() and type C, which is a subtype of type A, does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiler generates:

Found 1 semantic error compiling "C.java":

1. public class C utilizes A {
                        ^
*** Error: The abstract method "void alpha();", inherited from type "A", is not implemented in the non-abstract class "C".

However, if we could compile this scenario, our JVM, MCI-Java, would throw an AbstractMethodError when message alpha() is dispatched. A simple scenario that shows how the compiler is bypassed and how the JVM detects the error at run-time is the following:

1. Type A provides code for its method alpha(), therefore we can compile all the Java sources in this scenario.
2. Later on, only type A is recompiled without code for its method alpha(). This is possible because Java allows separate compilation.
3. When Test is executed, our JVM detects the error.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java generates:

An AbstractMethodError is thrown since A.alpha() is an abstract method. Exception in thread "main" java.lang.AbstractMethodError: A.alpha at Test.main(Test.java:5)

sc1

SCENARIO 1:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha() and type C, which is a subtype of type A, does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc2

SCENARIO 2:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B is a subtype of A and does not provide a method alpha(), type C is a subtype of type B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc3

SCENARIO 3:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of B and provides a method alpha() as well, type C is a subtype of type A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc4

SCENARIO 4:

This scenario generates a compiler error. Type B contains an abstract method alpha(), type A is a subtype of B and provides an abstract method alpha(), and type C, which is a subtype of type A, does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiler generates:

Found 1 semantic error compiling "C.java":

1. public class C utilizes A {
                        ^
*** Error: The abstract method "void alpha();", inherited from type "A", is not implemented in the non-abstract class "C".

However, if we could compile this scenario, our JVM, MCI-Java, would throw an AbstractMethodError when message alpha() is dispatched.

A simple scenario that shows how the compiler is bypassed and how the JVM detects the error at run-time is the following:

1. Type A provides code for its method alpha(), therefore we can compile all the Java sources in this scenario.
2. Later on, only type A is recompiled without code for its method alpha(). This is possible because Java allows separate compilation.
3. When Test is executed, our JVM detects the error.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java generates:

An AbstractMethodError is thrown since A.alpha() is an abstract method. Exception in thread "main" java.lang.AbstractMethodError: A.alpha at Test.main(Test.java:5)

sc5

SCENARIO 5:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B provides an abstract method alpha(), and type C is a subtype of types A and B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc6

SCENARIO 6:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B provides an abstract method alpha(), and type C is a subtype of types B and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc7a

SCENARIO 7a:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B provides an abstract method alpha(), and type C is a subtype of types B and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc7b

SCENARIO 7b:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B provides an abstract method alpha(), and type C is a subtype of types A and B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc8a

SCENARIO 8a:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B is a subtype of type A and provides an abstract method alpha(), and type C is a subtype of types B and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc8b

SCENARIO 8b:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B is a subtype of type A and provides an abstract method alpha(), and type C is a subtype of types A and B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc9

SCENARIO 9:

This scenario generates a compiler error. Both types A and B provide code for their method alpha(). Types A and B are not related (A is not a subtype of B and B is not a subtype of A) and type C is a subtype of both A and B, and does not provide a method alpha(). Unless C provides a method alpha(), an ambiguity is signaled by the MCI-Javac compiler.

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac generates:

Found 1 semantic error compiling "C.java":

1. public class C extends B utilizes A {
                         ^
*** Error: Ambiguous invocation of method "void alpha();". At least two methods are accessible from type "C". It is declared in type "B" and in type "A".

As in Scenario 0 and Scenario 4, with separate recompilation, we can achieve a situation where the compiler can be bypassed and our JVM detects the ambiguity when type C is loaded. Such a scenario can be obtained as follows:

1. Type A provides an abstract method alpha(), MCI-Javac compiles all the Java source files successfully.
2. Type A provides code for alpha() and only type A is recompiled with MCI-Javac.
3. Our JVM, MCI-Java, detects the ambiguity when type C is loaded.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

An ambiguity is detected when class C is loaded and an exception is thrown. Exception in thread "main" java.lang.Exception: Ambiguity detected when class C is loaded at Test.main(Test.java:3)

sc10

SCENARIO 10:

This scenario generates a compiler error. Both types A and B provide code for their method alpha(). Types A and B are not related (A is not a subtype of B and B is not a subtype of A) and type C is a subtype of both A and B, and does not provide a method alpha(). Unless C provides a method alpha(), an ambiguity is signaled by the MCI-Javac compiler.

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac generates:

Found 1 semantic error compiling "C.java":

1. public class C utilizes B, A {
                         ^
*** Error: Ambiguous invocation of method "void alpha();". At least two methods are accessible from type "C". It is declared in type "B" and in type "A".

As in Scenario 0 and Scenario 4, with separate recompilation, we can achieve a situation where the compiler can be bypassed and our JVM detects the ambiguity when type C is loaded. Such a scenario can be obtained as follows:

1. Type A provides an abstract method alpha(), MCI-Javac compiles all the Java source files successfully.
2. Type A provides code for alpha() and only type A is recompiled with MCI-Javac.
3. Our JVM, MCI-Java, detects the ambiguity when type C is loaded.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

An ambiguity is detected when class C is loaded and an exception is thrown. Exception in thread "main" java.lang.Exception: Ambiguity detected when class C is loaded at Test.main(Test.java:3)

sc11

SCENARIO 11:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, and type C is a subtype of types A and B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc12a

SCENARIO 12a:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, and type C is a subtype of types A and B and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc12b

SCENARIO 12b:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, and type C is a subtype of types B and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc13

SCENARIO 13:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, type D is a subtype of type B and does not provide a method alpha(), and type C is a subtype of types A and D and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc14

SCENARIO 14:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, type D is a subtype of type B and does not provide a method alpha(), and type C is a subtype of types D and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc15a

SCENARIO 15a:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, type D is a subtype of type B and does not provide a method alpha(), and type C is a subtype of types A and D and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc15b

SCENARIO 15b:

This scenario compiles successfully with MCI-Javac. Type B contains a concrete method alpha(), type A is a subtype of type B and provides a concrete method alpha() as well, type D is a subtype of type B and does not provide a method alpha(), and type C is a subtype of types D and A and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc16

SCENARIO 16:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B is a subtype of type A and does not provide a method alpha(), type D is a subtype of type A and does not provide a method alpha(), and type C is a subtype of types B and D and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().

sc17

SCENARIO 17:

This scenario compiles successfully with MCI-Javac. Type A contains a concrete method alpha(), type B is a subtype of type A and does not provide a method alpha(), type D is a subtype of type A and does not provide a method alpha(), and type C is a subtype of types B and D and does not provide a method alpha().

EXAMPLE OF COMPILATION:

$ mcijavac *.java

MCI-Javac compiles successfully.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

The executing method is A.alpha().