Download presentation
Presentation is loading. Please wait.
Published byRichard Walsh Modified over 9 years ago
1
Multiple Code Inheritance in Java Maria Cutumisu Supervisors: Duane Szafron, Paul Lu
2
2 Outline Overview Motivation Implementation Validation Syntax Support for Compilation Conclusions
3
3 MI (class) MI (class) MI (class) MI (interface) SI (class) SI (class) MI (interface) MI (code-type) SI* (class) We want separation of types. *We do not support multiple data inheritance. C++ Java Our Java Interface-TypeCode-TypeData-Type InterfaceClass Type Type Separation Mechanisms in Java
4
4 Code Promotion Measurements - Methods ClassIdenticalAbstract Abstract and Super Total Method Decrease DataInputStream4/198/190/1912/1963% DataOutputStream2/170/176*/172+6*/1712% RandomAccessFile6/458/456/4520/4544% RandomAccessFile DataOutput DataOutputStreamDataInputStream DataInput … … readFloat() … … … … writeFloat() … …
5
5 Basic Implementation - I DataInput RandomAccessFile readFloat() readInt() DataOutput readInt MT DataInput MT RandomAccessFile InterfaceClass Code is now in the interface! Code was in the class! RandomAccessFile VMT 12 readFloat() 13 readInt() … Code Class Loader Changed.
6
6 Dispatch Scenarios - Ambiguities InterfaceB ClassB alpha() InterfaceC alpha() Scenario 3 InterfaceB ClassB alpha() InterfaceA alpha() ClassA Scenario 4 InterfaceA alpha() InterfaceA x; x = new ClassB(); x.alpha(); We detect ambiguities at load-time.
7
7 Basic Implementation - II DataInput RandomAccessFile readFloat() readInt() DataOutput writeFloat() DataOutput output; DataInput input; output = new RAF(); input = new RAF(); output.writeFloat(); this.readFloat(); input.readFloat(); hypothetical () in DataInput invokeinterface invokevirtual invokeinterface invokevirtualinvokeinterface
8
8 Super Call Implementation invokespecial #superclass/alpha() super(InterfaceA).alpha(); invokemulti-super #InterfaceA/alpha() invokeinterface #InterfaceA/alpha() compiler script Bytecode previously generated for super calls Bytecode proposed Bytecode used New syntax proposed for super calls to interfaces Execution-time change.
9
9 Summary of Changes to the JVM Small and localized changes: class loader algorithm (load-time) - 11 lines of pseudo-code. execution of invokeinterface_quick (execution-time) - 5 lines of code.
10
10 Validation Semantics and performance are preserved for single inheritance programs. The following single inheritance Java programs ran correctly with our JVM: javac, jasper, and javap. Multiple inheritance programs show correct answers with the re-factored java.io library. Traditional super calls generate the same results under both JVMs.
11
11 Validation - MI Programs java.io library Sun JVM Multiple Inheritance Test Program output
12
12 Validation - MI Programs java.io library Our JVM Multiple Inheritance Test Program output Tests the super call mechanism Uses the re-factored java.io library
13
13 Adding Code in Interfaces Script interface DataInput{ public float readFloat() throws IOException; /*MI_CODE { return Float.intBitsToFloat(readInt()); } MI_CODE*/ } abstract class DataInput{ public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); } ; } javac DataInput.class jasper javac jasper DataInput.class DataInput.j DataInput_MI.j DataInput.j DataInput.class Script jasmin
14
14 Conclusions - I The first implementation of multiple code inheritance in Java is provided by modifying Sun’s JVM. It is based on the novel concept of adding code to interfaces. Facilitates code re-use, supports separation of inheritance concepts, and improves clarity and expressiveness of implementation. Only small and localized changes are made to the JVM. Java syntax and compiler are not changed. A set of scripts allows a programmer to add code in interfaces.
15
15 Conclusions - II We defined a super call mechanism for super calls to interfaces, resembling the one in C++. Single inheritance programs achieve the same performance as with the original JVM. Single and multiple inheritance programs run correctly with our JVM, for both our basic and super call mechanism implementations. Multiple code inheritance measurements show significant code decrease.
16
16 Load-time Change if (imb.code <> null) //code in interface currentmb = class.vmt[vmtIndex]; if (currentmb.code == null) //no code in MT class.vmt[vmtIndex] = imb; //point VMT to imb else //potential code ambiguity if (!currentmb.class.imt.contains(imb) && !imb.class.imt.contains(currentmb)) throw ambiguous method exception end if
17
17 Execution-time Change case opc_invokeinterface_quick: imb = constant_pool[GET_INDEX(pc+1)].mb; interface = imb.class; offset = imb.offset; … //args_size = pc[3];//REMOVED args_size = imb.args_size;//ADDED optop -= args_size; … if (pc[3] == 255)//ADDED mb = interface.MT[offset];//ADDED goto callmethod;//ADDED end if//ADDED … end case
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.