Commit 1a07a71a by Arnaud Charlet

[multiple changes]

2011-08-29  Robert Dewar  <dewar@adacore.com>

	* frontend.adb, gnat1drv.adb: Minor reformatting.

2011-08-29  Tristan Gingold  <gingold@adacore.com>

	* s-pooglo.adb (Allocate, Deallocate): Take into account the alignment.
	* a-fihema.adb (Allocate, Deallocate): Ditto.  Possibly add padding
	space in front of the header.

From-SVN: r178181
parent 4bcd6411
2011-08-29 Robert Dewar <dewar@adacore.com>
* frontend.adb, gnat1drv.adb: Minor reformatting.
2011-08-29 Tristan Gingold <gingold@adacore.com>
* s-pooglo.adb (Allocate, Deallocate): Take into account the alignment.
* a-fihema.adb (Allocate, Deallocate): Ditto. Possibly add padding
space in front of the header.
2011-08-29 Johannes Kanig <kanig@adacore.com> 2011-08-29 Johannes Kanig <kanig@adacore.com>
* frontend.adb (Frontend): Exit after creating Standard package when * frontend.adb (Frontend): Exit after creating Standard package when
......
...@@ -51,10 +51,6 @@ package body Ada.Finalization.Heap_Management is ...@@ -51,10 +51,6 @@ package body Ada.Finalization.Heap_Management is
-- Allocate/Deallocate to determine the Storage_Size passed to the -- Allocate/Deallocate to determine the Storage_Size passed to the
-- underlying pool. -- underlying pool.
Header_Offset : constant Storage_Offset := Header_Size;
-- Offset from the header to the actual object. Used to get from the
-- address of a header to the address of the actual object, and vice-versa.
function Address_To_Node_Ptr is function Address_To_Node_Ptr is
new Ada.Unchecked_Conversion (Address, Node_Ptr); new Ada.Unchecked_Conversion (Address, Node_Ptr);
...@@ -136,10 +132,21 @@ package body Ada.Finalization.Heap_Management is ...@@ -136,10 +132,21 @@ package body Ada.Finalization.Heap_Management is
end if; end if;
declare declare
N_Addr : Address; Header_Offset : Storage_Offset;
N_Ptr : Node_Ptr; N_Addr : Address;
N_Ptr : Node_Ptr;
begin begin
-- Offset from the header to the actual object. The header is
-- just in front of the object. There may be padding space before
-- the header.
if Alignment > Header_Size then
Header_Offset := Alignment;
else
Header_Offset := Header_Size;
end if;
-- Use the underlying pool to allocate enough space for the object -- Use the underlying pool to allocate enough space for the object
-- and the list header. The returned address points to the list -- and the list header. The returned address points to the list
-- header. If locking is necessary, it will be done by the -- header. If locking is necessary, it will be done by the
...@@ -148,13 +155,14 @@ package body Ada.Finalization.Heap_Management is ...@@ -148,13 +155,14 @@ package body Ada.Finalization.Heap_Management is
Allocate Allocate
(Collection.Base_Pool.all, (Collection.Base_Pool.all,
N_Addr, N_Addr,
Storage_Size + Header_Size, Storage_Size + Header_Offset,
Alignment); Alignment);
-- Map the allocated memory into a Node record. This converts the -- Map the allocated memory into a Node record. This converts the
-- top of the allocated bits into a list header. -- top of the allocated bits into a list header.
N_Ptr := Address_To_Node_Ptr (N_Addr); N_Ptr := Address_To_Node_Ptr
(N_Addr + Header_Offset - Header_Size);
Attach (N_Ptr, Collection.Objects'Unchecked_Access); Attach (N_Ptr, Collection.Objects'Unchecked_Access);
-- Move the address from Prev to the start of the object. This -- Move the address from Prev to the start of the object. This
...@@ -224,19 +232,28 @@ package body Ada.Finalization.Heap_Management is ...@@ -224,19 +232,28 @@ package body Ada.Finalization.Heap_Management is
if Has_Header then if Has_Header then
declare declare
N_Addr : Address; Header_Offset : Storage_Offset;
N_Ptr : Node_Ptr; N_Addr : Address;
N_Ptr : Node_Ptr;
begin begin
-- Move address from the object to beginning of the list header -- Offset from the header to the actual object.
N_Addr := Addr - Header_Offset; if Alignment > Header_Size then
Header_Offset := Alignment;
else
Header_Offset := Header_Size;
end if;
-- Converts the bits preceding the object into a list header -- Converts from the object to the list header
N_Ptr := Address_To_Node_Ptr (N_Addr); N_Ptr := Address_To_Node_Ptr (Addr - Header_Size);
Detach (N_Ptr); Detach (N_Ptr);
-- Converts the bits preceding the object the block address.
N_Addr := Addr - Header_Offset;
-- Use the underlying pool to destroy the object along with the -- Use the underlying pool to destroy the object along with the
-- list header. -- list header.
...@@ -340,7 +357,7 @@ package body Ada.Finalization.Heap_Management is ...@@ -340,7 +357,7 @@ package body Ada.Finalization.Heap_Management is
if Collection.Finalize_Address /= null then if Collection.Finalize_Address /= null then
declare declare
Object_Address : constant Address := Object_Address : constant Address :=
Node.all'Address + Header_Offset; Node.all'Address + Header_Size;
-- Get address of object from address of header -- Get address of object from address of header
begin begin
......
...@@ -119,7 +119,8 @@ private ...@@ -119,7 +119,8 @@ private
-- full view of Limited_Controlled, which is NOT limited. Note that default -- full view of Limited_Controlled, which is NOT limited. Note that default
-- initialization does not happen for this type (the pointers will not be -- initialization does not happen for this type (the pointers will not be
-- automatically set to null), because of the games we're playing with -- automatically set to null), because of the games we're playing with
-- address arithmetic. -- address arithmetic. Code in the body assumes that the size of
-- this record is a power of 2 to deal with alignment.
type Node is record type Node is record
Prev : Node_Ptr; Prev : Node_Ptr;
......
...@@ -100,6 +100,7 @@ begin ...@@ -100,6 +100,7 @@ begin
-- If the -gnatd.H flag is present, we are only interested in the Standard -- If the -gnatd.H flag is present, we are only interested in the Standard
-- package, so the frontend has done its job here. -- package, so the frontend has done its job here.
if Debug_Flag_Dot_HH then if Debug_Flag_Dot_HH then
return; return;
end if; end if;
......
...@@ -770,12 +770,18 @@ begin ...@@ -770,12 +770,18 @@ begin
Original_Operating_Mode := Operating_Mode; Original_Operating_Mode := Operating_Mode;
Frontend; Frontend;
-- Exit with errors if the main source could not be parsed -- Exit with errors if the main source could not be parsed. Also, when
-- Also, when -gnatd.H is present, the source file is not set. -- -gnatd.H is present, the source file is not set.
if Sinput.Main_Source_File = No_Source_File then if Sinput.Main_Source_File = No_Source_File then
-- Handle -gnatd.H debug mode
if Debug_Flag_Dot_HH then if Debug_Flag_Dot_HH then
-- We lock all the tables to keep the convention that the backend
-- needs to unlock the tables it wants to touch. -- For -gnatd.H, lock all the tables to keep the convention that
-- the backend needs to unlock the tables it wants to touch.
Atree.Lock; Atree.Lock;
Elists.Lock; Elists.Lock;
Fname.UF.Lock; Fname.UF.Lock;
...@@ -786,8 +792,12 @@ begin ...@@ -786,8 +792,12 @@ begin
Sinput.Lock; Sinput.Lock;
Namet.Lock; Namet.Lock;
Stringt.Lock; Stringt.Lock;
-- And all we need to do is to call the back end
Back_End.Call_Back_End (Back_End.Generate_Object); Back_End.Call_Back_End (Back_End.Generate_Object);
end if; end if;
Errout.Finalize (Last_Call => True); Errout.Finalize (Last_Call => True);
Errout.Output_Messages; Errout.Output_Messages;
Exit_Program (E_Errors); Exit_Program (E_Errors);
......
...@@ -46,13 +46,19 @@ package body System.Pool_Global is ...@@ -46,13 +46,19 @@ package body System.Pool_Global is
Storage_Size : SSE.Storage_Count; Storage_Size : SSE.Storage_Count;
Alignment : SSE.Storage_Count) Alignment : SSE.Storage_Count)
is is
use SSE;
pragma Warnings (Off, Pool); pragma Warnings (Off, Pool);
pragma Warnings (Off, Alignment);
Allocated : System.Address; Aligned_Size : Storage_Count := Storage_Size;
Aligned_Address : System.Address;
Allocated : System.Address;
begin begin
Allocated := Memory.Alloc (Memory.size_t (Storage_Size)); if Alignment > Standard'System_Allocator_Alignment then
Aligned_Size := Aligned_Size + Alignment;
end if;
Allocated := Memory.Alloc (Memory.size_t (Aligned_Size));
-- The call to Alloc returns an address whose alignment is compatible -- The call to Alloc returns an address whose alignment is compatible
-- with the worst case alignment requirement for the machine; thus the -- with the worst case alignment requirement for the machine; thus the
...@@ -60,6 +66,24 @@ package body System.Pool_Global is ...@@ -60,6 +66,24 @@ package body System.Pool_Global is
if Allocated = Null_Address then if Allocated = Null_Address then
raise Storage_Error; raise Storage_Error;
end if;
if Alignment > Standard'System_Allocator_Alignment then
-- Realign the returned address.
Aligned_Address := To_Address
(To_Integer (Allocated) + Integer_Address (Alignment)
- (To_Integer (Allocated) mod Integer_Address (Alignment)));
-- Save the block address.
declare
Saved_Address : System.Address;
pragma Import (Ada, Saved_Address);
for Saved_Address'Address use
Aligned_Address
- Storage_Offset (System.Address'Size / Storage_Unit);
begin
Saved_Address := Allocated;
end;
Address := Aligned_Address;
else else
Address := Allocated; Address := Allocated;
end if; end if;
...@@ -75,12 +99,24 @@ package body System.Pool_Global is ...@@ -75,12 +99,24 @@ package body System.Pool_Global is
Storage_Size : SSE.Storage_Count; Storage_Size : SSE.Storage_Count;
Alignment : SSE.Storage_Count) Alignment : SSE.Storage_Count)
is is
use System.Storage_Elements;
pragma Warnings (Off, Pool); pragma Warnings (Off, Pool);
pragma Warnings (Off, Storage_Size); pragma Warnings (Off, Storage_Size);
pragma Warnings (Off, Alignment);
begin begin
Memory.Free (Address); if Alignment > Standard'System_Allocator_Alignment then
-- Retrieve the block address.
declare
Saved_Address : System.Address;
pragma Import (Ada, Saved_Address);
for Saved_Address'Address use
Address - Storage_Offset (System.Address'Size / Storage_Unit);
begin
Memory.Free (Saved_Address);
end;
else
Memory.Free (Address);
end if;
end Deallocate; end Deallocate;
------------------ ------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment