1 / 27

The Implementation of Ada 2005 Synchronized Interfaces in the GNAT Compiler

Presentation cover page EU. Javier Miranda Hristian Kirtchev Edmond Schonberg. www.adacore.com. The Implementation of Ada 2005 Synchronized Interfaces in the GNAT Compiler. Interfaces Types. Interfaces in Ada 2005 Implementation of regular interfaces

silver
Download Presentation

The Implementation of Ada 2005 Synchronized Interfaces in the GNAT Compiler

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. Presentation cover page EU Javier Miranda Hristian Kirtchev Edmond Schonberg www.adacore.com The Implementation of Ada 2005 Synchronized Interfaces in the GNAT Compiler

  2. Interfaces Types • Interfaces in Ada 2005 • Implementation of regular interfaces • Limited, Synchronized, Protected, and Task interfaces in Ada 2005 • Basic implementation model: Corresponding records • Dispatching calls in selective waits • Status

  3. Interface Types in Ada 2005 type Root is tagged record ... ; . . . type DT_1 is new Root and I1 and I2with record . . . ; -- Must provide the implementation of P and R typeDT_2is new DT_1with record . . . ; -- Inherits all the primitives and interfaces of the ancestor type I1 is interface; function P (X : I1) return Natural is abstract; type I2 is interface and I1; procedure Q (X : I2) is null; procedure R (X : I2) is abstract;

  4. procedure Dispatch_I1_Call (Obj : I1'Class) is begin -- Dispatch call to user -- defined subprogram . . := P (Obj); -- Dispatch call to predefined -- stream operation I1'Write (Stream, Obj); end Dispatch_I1_Call; procedure Dispatch_Call (Obj : Root'Class) is begin -- Membership test ifObj in I2'Classthen R (I2'Class (Obj)); end if; end Dispatch_Call; Interface Types in Ada 2005 type I1 is interface; function P (X : I1) return Natural is abstract; type I2 is interface and I1; procedure Q (X : I2) is null; procedure R (X : I2) is abstract;

  5. Main features: Constant-time dispatching calls through interfaces Compatible with the C++ ABI Layout http://www.codesourcery.com/cxx-abi J.Miranda, E.Schonberg, G.Dismukes. The Implementation of Ada 2005 Interfaces Types in the GNAT Compiler. AdaEurope’2005, York. Lecture Notes in Computer Science. Eds: T.Vardanega, A.Wellings. Vol. 3555, pages 208-219. June, 2005. Springer-Verlag. ISSN 0302-9743 ISBN 3-540-26286-5 GNAT Implementation

  6. GNAT Object Layout: Example

  7. Primary and secondary dispatch tables

  8. C++ structure with abstract classes

  9. Interface Dispatching Call

  10. Thunk Code procedure P (Obj : DT; << formals >>) is ... . . . end P; procedure I1_P_Thunk (Obj_Addr : Address; << formals>>) is M : constant := DT.I1'Position; Obj_Base : constant := Obj_Addr – Storage_Offset (M); begin P (Obj_Base, << formals >>); -- In practice not a call but a jump end I1_P_Thunk;

  11. Interface categories • Regular interfaces • Implemented by tagged record types • Task interfaces • Implemented by task types • Protected interfaces • Implemented by protected types • Synchronized interfaces • Implemented by tasks or protected types • Limited interfaces • Implemented by record, task, or protected types.

  12. Run-time representation of Synchronized types • Similar discriminated records • Protected types • Private data • Lock structure • Entry queues (discriminated component) • Finalization queues • Task types • Pointer to task control block • Lock structures • Size, priority • Task info • Target-independent layout • Simpler structure for Ravenscar profile

  13. Implementing a synchronized interface with a task type I1 is limited interface; procedure P (Obj : in out I1) is abstract; procedure Q (Obj : in out I1) is null; type I2 is synchronized interface and I1; procedure R (Obj : in out I2; Data : Integer) is abstract; task type Tsk is new I2 with entry P; -- Implements P of I1 entry R (Data : Integer);-- Implements R of I2 end Tsk; procedure Q (T : in out Tsk);-- Implements Q of I1

  14. Implementation steps • Make corresponding records tagged (they are already limited) • Interface dispatching data structures are as for regular interfaces • Conformance rules must handle first argument specially • Create wrappers for entries and protected operations • Wrappers are primitive operations of the corresponding record • Interface dispatching calls require one additional call • For entries, wrapper contains an entry call • For protected operations, wrapper contains a call to the protected operation • Protected operation locks object, calls unprotected version • Unprotected subprog contains code of operation (direct use in internal calls) • Dispatching calls on a synchronized interface handle tasks and protected types uniformly

  15. Interface dispatching in selective wait and ATC type I1 is limited interface; procedure P (X in out I1) is abstract; protectedtype Prot1 is I1 with… type Lim is new I1 with record … end record; procedure Dispatch (X: in out I1’class) is begin select X.P; -- protected or regular operation? else delay 0.1; end select; end Dispatch;

  16. Need additional Run-Time operationsto determine kind of target • Operations on all types that implement limited interfaces: • Get_Prim_Op_Kind • Record, task, or protected type operation? Procedure or entry? • Get_Entry_Index • If entry-call, position of entry queue in object • Could be combined with previous operation • Get_Offset_Index • Index in primary table corresponding to interface operation in secondary table • Corresponding information must be added to the Run-Time Type-Specific Data • Operations are not dispatching

  17. New Dispatching Operations • Expansion of selective waits depends critically on whether trigger is task or protected operation: no possible factorization • Primitive operations for selective waits • Dispatching_Timed_Select • Dispatching_Conditional_Select • Primitive operations for ATC • Dispatching_Asynchronous_Select • Dispatching_Get_Prim_Op_Kind • Primitive operations for task interfaces • Dispatching_Get_Task_Id (for task abortion and attributes ‘Callable and ‘Terminated)

  18. Primary DT Offset_To_Top TSD_Ptr : Predefined : primitives : table A’address B’address P Type Specific Data Select Specific Data _Tag _DT1 _DT2 … Queues Inheritance depth Access level Expanded name External tag . . . SSD_Ptr Ancestor tags Interface tags A Prot.Proc - B Prot.Entry 1 Secondary DT Offset_To_Top OSD_Ptr : Predefined : thunks : table Thunk_A’address Secondary DT Offset_To_Top OSD_Ptr : Predefined : thunks : table Thunk_B’address Offset Specific Data Offset Specific Data A’Pos in the Primary DT B’Pos in the Primary DT Dispatch Table Structure type Lim_Iface is limited interface; procedure A (Obj : in out Lim_Iface) is abstract; type Synch_Iface is synchronized interface; procedure B (Obj : in out Synch_Iface) is abstract; protected type Prot_Typ is new Lim_IfaceandSynch_Iface with procedure A; entry B; end Prot_Typ; P : Prot_Typ;

  19. Interface dispatching call Primary DT with DT_Pkg; use DT_Pkg; procedure Simple_Dispatching is procedure Dispatch_On_A (Obj : in out Lim_Iface’Class) is begin end Dispatch_On_A; P : Prot_Typ; begin end Simple_Dispatching; P Type Specific Data Select Specific Data Offset_To_Top TSD_Ptr : Predefined : primitives : table A’address B’address P _Tag _DT1 _DT2 … Queues Inheritance depth Access level Expanded name External tag . . . SSD_Ptr Ancestor tags Interface tags A Prot_Proc - B Prot_Entry 1 P._DT1 Obj Obj.A; declare Temp_Tag : Tag := Tag (Obj); Temp_Addr : Address := Temp_Tag.all.prim_tbl (A’Pos); begin Temp_Addr (Obj); end; Secondary DT Offset_To_Top OSD_Ptr : Predefined : thunks : table Thunk_A’address Offset Specific Data A’Pos in the primary DT Dispatch_On_A (Lim_Iface (P._DT1)); Dispatch_On_A (P); Secondary DT Offset_To_Top OSD_Ptr : Predefined : thunks : table Thunk_B’address Offset Specific Data B’Pos in the primary DT

  20. Dispatching in Selective waits with Ada.Text_IO; use Ada.Text_IO; with DT_Pkg; use DT_Pkg; procedure Select_Dispatching is procedure Select_On_B (Obj : in out Synch_Iface’Class) is begin declare B : Boolean := False; C : Prim_Op_Kind; D : Duration := To_Duration (1.0); K : Tagged_Kind := Get_Tagged_Kind (Tag (Obj)); M : Integer := 1; P : Parameters := (Param1 … ParamN); S : Integer; begin if K = TK_Limited_Tagged then Obj.B; else S := Get_Offset_Index ( Tag (Obj), DT_Position (B)); _DTS (Obj, S, P’Address, D, M, C, B); if C = POK_Protected_Entry orelse C = POK_Task_Entry then with Ada.Text_IO; use Ada.Text_IO; with DT_Pkg; use DT_Pkg; procedure Select_Dispatching is procedure Select_On_B (Obj : in out Synch_Iface’Class) is begin select Obj.B; or delay 1.0; Put_Line (“Delayed”); end select; end Select_On_A; P : Prot_Typ; begin Select_On_B (P); end Select_Dispatching; Param1 := P.Param1; . . . ParamN := P.ParamN; endif; if B then if C = POK_Proc orelse C = POK_Protected_Proc orelse C = POK_Task_Proc then Obj.B; endif; <triggering-statements> else <delay-statements> endif; end if; end; end Select_On_B; P : Prot_Typ; procedure _DTS (T : Prot_TypV; S : Integer; P : System.Address; D : Duration; M : Integer; C : out Prim_Op_Kind; B : out Boolean) is I : Integer; begin C := Get_Prim_Op_Kind (T._Tag, S); if C = POK_Proc orelse C = POK_Protected_Proc orelse C = POK_Task_Proc then B := True; return; endif; I := Get_Entry_Index (T._Tag, S); -- If Prot_Typ is a task type, the -- following expansion has a call -- to Timed_Task_Entry_Call System.Timed_Protected_Entry_Call (T._Object’Unchecked_Access, Protected_Entry_Index (I), P, D, M, B); end _DTS; begin Select_On_B (Synch_Iface (P._DT2)); end Select_Dispatching;

  21. Dispatching in Selective waits: Example Primary DT with Ada.Text_IO; use Ada.Text_IO; with DT_Pkg; use DT_Pkg; procedure Select_Dispatching is procedure Select_On_B (Obj : in out Synch_Iface’Class) is begin declare B : Boolean := False; C : Prim_Op_Kind; D : Duration := To_Duration (1.0); K : Tagged_Kind := Get_Tagged_Kind (Tag (Obj)); M : Integer := 1; P : Parameters := (Param1 … ParamN); S : Integer ; begin if K = TK_Limited_Tagged then Obj.B; else S := Get_Offset_Index ( Tag (Obj), DT_Position (B)); _DTS (Obj, S, P’Address, D, M, C, B); is I : Integer; begin C := Get_Prim_Op_Kind (T._Tag, S); if C = POK_Proc orelse C = POK_Protected_Proc orelse C = POK_Task_Proc then B := True; return; endif; I := Get_Entry_Index (T._Tag, S); System.Timed_Protected_Entry_Call (T._Object’Unchecked_Access, Protected_Entry_Index (I), P, D, M, B); end _DTS; begin Select_On_B (Synch_Iface (P._DT2)); end Select_Dispatching; Prot_TypV Type Specific Data Select Specific Data Offset_To_Top TSD_Ptr 01 Predefined : primitives : table 16 A’address 17 B’address _Tag _DT1 _DT2 … Queues Inheritance depth Access level Expanded name External tag . . . SSD_Ptr Ancestor tags Interface tags A Prot_Proc - B Prot_Entr 1 Secondary DT Offset_To_Top OSD_Ptr 01 Predefined : thunks : table 16 Thunk of A Offset Specific Data A’Pos = 16 Secondary DT Offset_To_Top OSD_Ptr 01 Predefined : thunks : table 16 Thunk of B Offset Specific Data B’Pos = 17

  22. GAP 2005 Release Abstract Interface Types (including task, protected and synchronized interfaces) available in GAP-2005 All 2005 enhancements available to GNAT Pro users under -gnat05 switch.

  23. Presentation cover page EU Javier Miranda Hristian Kirtchev Edmond Schonberg End of talk www.adacore.com The Implementation of Ada 2005 synchronized Interfaces in the GNAT Compiler

  24. GNAT Implementation ApproachesPermutation Maps versus C++ Model • Constant-time dispatching calls through interfaces • Compatibility with the C++ ABI Layout

  25. Basic dispatch table structure

  26. Primary dispatch table

More Related