Multiple Code Inheritance In Java - PowerPoint PPT Presentation

1 / 1
About This Presentation
Title:

Multiple Code Inheritance In Java

Description:

... at most one direct superclass, but more than one superinterface. ... alpha() found at offset 1 (local MT offset) in InterfaceC. 0. 1. Search. alpha() not found ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 2
Provided by: duanes
Category:

less

Transcript and Presenter's Notes

Title: Multiple Code Inheritance In Java


1
Multiple Code Inheritance In Java Maria Cutumisu,
Paul Lu, Duane Szafron University of Alberta
C Multiple Code Inheritance
Java Multiple Interface Inheritance
Object Inheritance in Java
Treating Ambiguous Situations Due to Multiple
Code Inheritance
InterfaceB
InterfaceA
InterfaceA
InterfaceB
InterfaceA
Interface
no alpha()
InterfaceB
no alpha()
We want separation of types.
A class can have more than one direct superclass.
A class can have at most one direct superclass,
but more than one superinterface.
Code-Type
no alpha()
DataOutput
DataInput
C Java Our Java
MI (class) MI (class)
MI (class) MI (interface) SI (class)
SI (class) MI (interface)
MI (code-type) SI (class)
Method alpha() appears in both InterfaceA and
InterfaceB, but it is not declared in ClassA. An
ambiguity is detected at load-time and an
exception is thrown.
The code of alpha() from InterfaceB is executed.
We want a relaxed definition of ambiguity so no
ambiguity is reported.
The super ambiguity is eliminated by specifying
the path to the desired implementation of alpha().
We think this is a good thing!
Problems
Why?
The Java language syntax and the compiler are not
modified, therefore we need preprocessing scripts.
We extend the JVM to support multiple code
inheritance by inserting code (method bodies)
into interfaces that support multiple
inheritance.
Implementation
The Scripting Process
no alpha()
InterfaceC
InterfaceB
InterfaceC
InterfaceB
InterfaceC
InterfaceB
no alpha()
no alpha()
readFloat () return Float. intBitsToFloat
(readInt())
DataInput
InterfaceA
InterfaceA
InterfaceA
InterfaceD
no alpha()
no alpha()
no alpha()
RandomAccessFile
DataInputStream
no alpha()
The user inserts code (method bodies) in
interface methods using a special labeled comment
(MI_CODE).
Current Java Dispatch
Modifications of the Java Virtual Machine (JVM)
Interface Method Table (IMT) of InterfaceA
(static type)
Script
Every super preceded by our MI.supercall marker
uses invokeinterface instead of invokespecial.
We preserve the semantics of the classic super
and we do not affect its dispatch. Resolution is
unchanged, but the executed method is just the
resolved one.
Even though there is no declaration of alpha()
in the class, we can find the code in the
superinterfaces and execute it. Resolution is
unchanged and steps 2.1 to 2.3 are the same. Step
2.4 is different!
Method Tables (MT)
MT of InterfaceA
Search
MT of InterfaceB
alpha() not found
alpha() not found
Search
Resolution is the same in all cases!
0 1
alpha() found at offset 1 (local MT offset) in
InterfaceC.
javac
javac
beta()abstract alpha()
Search
DataInput.class
DataInput.class
jasper
jasper
DataInput_MI.j
DataInput.j
The modified JVM re-directs the Virtual Method
Table (VMT) entry for alpha() to the code in an
interface at class load time.
Execute the resolved method in InterfaceC.
Match found at index 2 (guess).
Script
Search IMT for InterfaceC.
This new .class file contains code
inside interface methods.
DataInput.j
0 1
Virtual Method Table (VMT) of ClassA
0
beta() alpha()
3
InterfaceD
Code is here (in the class)!
Code is here (in the interface)!
DataInput.class
MT of InterfaceC
MT of ClassA
12
alpha()
alpha()
13
Write a Comment
User Comments (0)
About PowerShow.com