Multiple Code Inheritance Scenarios

Multi-Super



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

Multi-Super Scenario Diagram:

Multi-Super Scenarios


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

Note: In each scenario (sc0 to sc17) folder, there are two subfolders suffixed with C when C represents a class (sc0C) and I when C represents an implementation (sc0I). There are scenarios such as sc5, sc6, sc9, sc11, sc13, sc14, sc16, where C can only represent a class, therefore a subfolder with a suffix I cannot appear. All the Multi-Super Scenarios can be found here.

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:

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(). Type SC contains a super-call to alpha() in C.

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".

Found 1 semantic error compiling "SC.java":

     3.     super.alpha();
               <--------->
*** Error: An abstract method, "alpha", cannot be invoked.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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)

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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().

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. Type SC contains a super-call to alpha() in C.

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 method alpha() in type C is resolved. 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 method alpha()V in interface C is resolved.

EXAMPLE OF EXECUTION:

$ mcijava Test

MCI-Java executes successfully and displays:

An ambiguity is detected when method alpha()V in interface C is resolved and an exception is thrown. Exception in thread "main" java.lang.Exception: Ambiguity detected when method alpha()V in interface C is resolved.
     at
     at Test.main(Test.java:5)

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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 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(). Type SC contains a super-call to alpha() in C.

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(). Type SC contains a super-call to alpha() in C.

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().