This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch modifies the creation of finalization masters for anonymous access- to-controlled types. Prior to this change, each compilation unit utilized a single heterogeneous finalization master to service all allocations where the associated type is anonymous access-to-controlled. This patch removes the use of the single heterogeneous finalization master and instead introduces multiple homogenous finalization masters. This leads to increase in performance because allocation no longer needs to maintain a mapping between allocated object and corresponding Finalize_Address primitive in a runtime hash data structure. As a result, anonymous access-to-controlled types are on par with named access-to- controlled types. ------------ -- Source -- ------------ -- types.ads with Ada.Finalization; use Ada.Finalization; package Types is type Ctrl is new Controlled with record Id : Natural; end record; -- Anonymous types type Anon_Discr (Discr : access Ctrl) is null record; type Anon_Comps is record Comp_1 : access Ctrl; Comp_2 : access Ctrl; end record; type Anon_Array is array (1 .. 5) of access Ctrl; -- Named types type Ctrl_Ptr is access all Ctrl; type Named_Discr (Discr : Ctrl_Ptr) is null record; type Named_Discr_Ptr is access all Named_Discr; type Named_Comps is record Comp_1 : Ctrl_Ptr; Comp_2 : Ctrl_Ptr; end record; end Types; -- performance.adb with Ada.Calendar; use Ada.Calendar; with Ada.Finalization; use Ada.Finalization; with Ada.Text_IO; use Ada.Text_IO; with Types; use Types; procedure Performance is Percentage : constant := 0.3; -- 30% Max_Iterations : constant := 50_000; Diff_A : Duration; Diff_N : Duration; Factor : Duration; Start_A : Time; Start_N : Time; begin Start_A := Clock; for Iteration in 1 .. Max_Iterations loop declare Anon_Discr_Obj : access Anon_Discr := new Anon_Discr'(Discr => new Ctrl'(Controlled with Id => 1)); Anon_Comps_Obj : constant Anon_Comps := (Comp_1 => new Ctrl'(Controlled with Id => 2), Comp_2 => new Ctrl'(Controlled with Id => 3)); begin null; end; end loop; Diff_A := Clock - Start_A; Start_N := Clock; for Iteration in 1 .. Max_Iterations loop declare Named_Discr_Obj : Named_Discr_Ptr := new Named_Discr'(Discr => new Ctrl'(Controlled with Id => 4)); Named_Comps_Obj : constant Named_Comps := (Comp_1 => new Ctrl'(Controlled with Id => 5), Comp_2 => new Ctrl'(Controlled with Id => 6)); begin null; end; end loop; Diff_N := Clock - Start_N; Factor := Diff_N * Percentage; if Diff_N - Factor < Diff_A and then Diff_A < Diff_N + Factor then Put_Line ("Anonymous vs Named within expected percentage"); else Put_Line ("ERROR"); end if; end Performance; ---------------------------- -- Compilation and output -- ---------------------------- $ gnatmake -q performance.adb $ ./performance Anonymous vs Named within expected percentage Tested on x86_64-pc-linux-gnu, committed on trunk 2016-05-02 Hristian Kirtchev <kirtchev@adacore.com> * einfo.adb Anonymous_Master now uses Node35. (Anonymous_Master): Update the assertion and node reference. (Set_Anonymous_Master): Update the assertion and node reference. (Write_Field35_Name): Add output for Anonymous_Master. (Write_Field36_Name): The output is now undefined. * einfo.ads Update the node and description of attribute Anonymous_Master. Remove prior occurrences in entities as this is now a type attribute. * exp_ch3.adb (Expand_Freeze_Array_Type): Remove local variable Ins_Node. Anonymous access- to-controlled component types no longer need finalization masters. The master is now built when a related allocator is expanded. (Expand_Freeze_Record_Type): Remove local variable Has_AACC. Do not detect whether the record type has at least one component of anonymous access-to- controlled type. These types no longer need finalization masters. The master is now built when a related allocator is expanded. * exp_ch4.adb Remove with and use clauses for Lib and Sem_Ch8. (Current_Anonymous_Master): Removed. (Expand_N_Allocator): Call Build_Anonymous_Master to create a finalization master for an anonymous access-to-controlled type. * exp_ch6.adb (Add_Finalization_Master_Actual_To_Build_In_Place_Call): Call routine Build_Anonymous_Master to create a finalization master for an anonymous access-to-controlled type. * exp_ch7.adb (Allows_Finalization_Master): New routine. (Build_Anonymous_Master): New routine. (Build_Finalization_Master): Remove formal parameter For_Anonymous. Use Allows_Finalization_Master to determine whether circumstances warrant a finalization master. This routine no longer creates masters for anonymous access-to-controlled types. (In_Deallocation_Instance): Removed. * exp_ch7.ads (Build_Anonymous_Master): New routine. (Build_Finalization_Master): Remove formal parameter For_Anonymous and update the comment on usage. * sem_util.adb (Get_Qualified_Name): New routines. (Output_Name): Reimplemented. (Output_Scope): Removed. * sem_util.ads (Get_Qualified_Name): New routines.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |