JDK-8178489 : Make align functions more type safe and consistent
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-04-11
  • Updated: 2017-08-25
  • Resolved: 2017-07-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10 b21Fixed
Related Reports
Blocks :  
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Currently, the align functions forces the user to often explicitly cast either the input parameters, or the return type, or both.

Two examples of the current API:
inline intptr_t align_size_up(intptr_t size, intptr_t alignment);
inline void* align_ptr_up(const void* ptr, size_t alignment);

I propose that we change the API to use templates to return the aligned value as the same type as the type of the unaligned input.

The proposed API would look like this:

template <typename T, typename A>
inline T align_size_up(T size, A alignment);

template <typename T, typename A>
inline T* align_ptr_up(T* ptr, A alignment);

and a follow-up RFE would get rid of _size_ and _ptr_ from the names. 

Usages of these align functions would then look like:

size_t aligned_size = align_up(alloc_size, os::vm_page_size())
HeapWord* aligned_top = align_up(top, region_size)