1 / 17

Multiple Code Inheritance in Java

Multiple Code Inheritance in Java. Maria Cutumisu Supervisors: Duane Szafron, Paul Lu. Outline. Overview Motivation Implementation Validation Syntax Support for Compilation Conclusions. Type Separation Mechanisms in Java. Type. Interface. Class. We want separation of types.

maegan
Download Presentation

Multiple Code Inheritance in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multiple Code Inheritance in Java Maria Cutumisu Supervisors: Duane Szafron, Paul Lu

  2. Outline • Overview • Motivation • Implementation • Validation • Syntax Support for Compilation • Conclusions

  3. Type Separation Mechanisms in Java Type Interface Class We want separation of types. Interface-Type Code-Type Data-Type C++ Java Our Java MI (class) MI (class) MI (class) MI (interface) SI (class) SI (class) MI (interface) MI (code-type) SI* (class) *We do not support multiple data inheritance.

  4. … … … … … … … writeFloat() readFloat() readFloat() writeFloat() Code Promotion Measurements - Methods DataInput DataOutput DataInputStream RandomAccessFile DataOutputStream

  5. Basic Implementation - I RandomAccessFile VMT DataOutput DataInput readFloat() readInt() … MT DataInput MT RandomAccessFile 12 readFloat() readInt readInt 13 readInt() Interface Class RandomAccessFile Code Code Class Loader Changed. Code was in the class! Code is now in the interface!

  6. Dispatch Scenarios - Ambiguities We detect ambiguities at load-time. InterfaceA x; x = new ClassB(); x.alpha(); Scenario 3 Scenario 4 InterfaceA InterfaceA alpha() alpha() InterfaceB InterfaceC InterfaceB ClassA alpha() alpha() alpha() ClassB ClassB

  7. Basic Implementation - II writeFloat() DataOutput DataInput readFloat() readInt() RandomAccessFile hypothetical () in DataInput DataOutput output; DataInput input; output = new RAF(); input = new RAF(); output.writeFloat(); this.readFloat(); input.readFloat(); invokeinterface invokeinterface invokevirtual invokevirtual invokeinterface

  8. Super Call Implementation New syntax proposed for super calls to interfaces Bytecode proposed invokemulti-super #InterfaceA/alpha() Execution-time change. super(InterfaceA).alpha(); Bytecode previously generated for super calls Bytecode used invokespecial #superclass/alpha() invokeinterface #InterfaceA/alpha() compiler script

  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. 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. Validation - MI Programs Multiple Inheritance Test Program Sun JVM java.io library output

  12. Multiple Inheritance Test Program Tests the super call mechanism Our JVM java.io library Uses the re-factored java.io library output  Validation - MI Programs

  13. Adding Code in Interfaces 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()); } ; } Script javac javac DataInput.class DataInput.class Script jasper jasper DataInput_MI.j DataInput.j DataInput.j jasmin DataInput.class

  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. 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. 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 end if end if

  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

More Related