You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Oliver Deakin <ol...@googlemail.com> on 2009/06/15 17:40:03 UTC

Re: [classlib][misc] MemMacros.h get_unaligned and set_unaligned macros fail to compile on zLinux

Can anyone confirm that the change I appended for MemMacros.h does not 
cause any breakage on Linux x86_64? I'll give it a few days before I 
commit this change so there's some time to speak up.

Regards,
Oliver

Oliver Deakin wrote:
> The change I appended to my original mail fixes the build problem on 
> zLinux 31 now. Can anyone confirm that everything works as expected on 
> Linux x86_64 please? I think it is only that platform that is in 
> danger of being affected by this modification.
>
> Regards,
> Oliver
>
> Oliver Deakin wrote:
>> Hi all,
>>
>> I have a quick question about the macros get_unaligned() and 
>> set_unaligned() in MemMacros.h. When compiling on zSeries Linux 31 
>> bit systems we fall into the macros defines section for IPF machines 
>> because we are on linux and __386__ is not defined. Unfortunately the 
>> "(const void*) (ptr)" tries to cast a jlong (64 bit) to a 32 bit 
>> pointer here and we get a "cast to pointer from integer of different 
>> size" warning which is treated as an error.
>>
>> I'd like to fix the code to do the right thing here across all 
>> platforms. Does anyone know this code well? Does the IPF section 
>> (__linux__ && !__i386__) refer to Itanium machines only and not 
>> x86_64? If so, would it suffice to replace the code that is there 
>> with something like [1], so that only Itanium machines use the 
>> memmove() based macros and all the rest (linux, windows, zos, aix 
>> etc.) use the simpler cast based macros?
>>
>> Thanks for any help you can give!
>>
>> Regards,
>> Oliver
>>
>> [1]
>> #if defined(__ia64__) && defined(__linux__)
>>
>> #include <string.h>
>> #define get_unaligned(type, ptr)                                  \
>> ({                                                                \
>>    type __tmp;                                                   \
>>    memmove(&__tmp, (const void*) (ptr), sizeof(type));           \
>>    __tmp;                                                        \
>> })
>>
>> #define set_unaligned(type, ptr, val)                           \
>> ({                                                              \
>>    memmove((void*) (ptr), &val, sizeof(type));                 \
>>    (void)0;                                                    \
>> })
>>
>> #else
>>
>> #define get_unaligned(type, ptr) ( *((type *)((uintptr_t)(ptr))) )
>> #define set_unaligned(type, ptr, val) ( (void) (*((type 
>> *)((uintptr_t)(ptr))) = val) )
>>
>> #endif
>>
>

-- 
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Re: [classlib][misc] MemMacros.h get_unaligned and set_unaligned macros fail to compile on zLinux

Posted by Oliver Deakin <ol...@googlemail.com>.
Thanks - with that in mind I committed a fix at r785553 using the 
Harmony defines for the appropriate platforms.

Regards,
Oliver

Mark Hindess wrote:
> In message <4A...@googlemail.com>, Oliver Deakin writes:
>   
>> Can anyone confirm that the change I appended for MemMacros.h does not 
>> cause any breakage on Linux x86_64? I'll give it a few days before I 
>> commit this change so there's some time to speak up.
>>     
>
> Well it most likely wouldn't break since IIRC unaligned accesses are trapped
> and handled by the kernel.  However, the key thing is that __i386__ is *not*
> defined on x86_64 so the memmove case is used by both x86_64 and ia64.
>
> -Mark.
>
>   
>> Oliver Deakin wrote:
>>     
>>> The change I appended to my original mail fixes the build problem on 
>>> zLinux 31 now. Can anyone confirm that everything works as expected on 
>>> Linux x86_64 please? I think it is only that platform that is in 
>>> danger of being affected by this modification.
>>>
>>> Regards,
>>> Oliver
>>>
>>> Oliver Deakin wrote:
>>>       
>>>> Hi all,
>>>>
>>>> I have a quick question about the macros get_unaligned() and 
>>>> set_unaligned() in MemMacros.h. When compiling on zSeries Linux 31 
>>>> bit systems we fall into the macros defines section for IPF machines 
>>>> because we are on linux and __386__ is not defined. Unfortunately the 
>>>> "(const void*) (ptr)" tries to cast a jlong (64 bit) to a 32 bit 
>>>> pointer here and we get a "cast to pointer from integer of different 
>>>> size" warning which is treated as an error.
>>>>
>>>> I'd like to fix the code to do the right thing here across all 
>>>> platforms. Does anyone know this code well? Does the IPF section 
>>>> (__linux__ && !__i386__) refer to Itanium machines only and not 
>>>> x86_64? If so, would it suffice to replace the code that is there 
>>>> with something like [1], so that only Itanium machines use the 
>>>> memmove() based macros and all the rest (linux, windows, zos, aix 
>>>> etc.) use the simpler cast based macros?
>>>>
>>>> Thanks for any help you can give!
>>>>
>>>> Regards,
>>>> Oliver
>>>>
>>>> [1]
>>>> #if defined(__ia64__) && defined(__linux__)
>>>>
>>>> #include <string.h>
>>>> #define get_unaligned(type, ptr)                                  \
>>>> ({                                                                \
>>>>    type __tmp;                                                   \
>>>>    memmove(&__tmp, (const void*) (ptr), sizeof(type));           \
>>>>    __tmp;                                                        \
>>>> })
>>>>
>>>> #define set_unaligned(type, ptr, val)                           \
>>>> ({                                                              \
>>>>    memmove((void*) (ptr), &val, sizeof(type));                 \
>>>>    (void)0;                                                    \
>>>> })
>>>>
>>>> #else
>>>>
>>>> #define get_unaligned(type, ptr) ( *((type *)((uintptr_t)(ptr))) )
>>>> #define set_unaligned(type, ptr, val) ( (void) (*((type 
>>>> *)((uintptr_t)(ptr))) = val) )
>>>>
>>>> #endif
>>>>         
>
>
>
>   

-- 
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Re: [classlib][misc] MemMacros.h get_unaligned and set_unaligned macros fail to compile on zLinux

Posted by Mark Hindess <ma...@googlemail.com>.
In message <4A...@googlemail.com>, Oliver Deakin writes:
>
> Can anyone confirm that the change I appended for MemMacros.h does not 
> cause any breakage on Linux x86_64? I'll give it a few days before I 
> commit this change so there's some time to speak up.

Well it most likely wouldn't break since IIRC unaligned accesses are trapped
and handled by the kernel.  However, the key thing is that __i386__ is *not*
defined on x86_64 so the memmove case is used by both x86_64 and ia64.

-Mark.

> Oliver Deakin wrote:
> > The change I appended to my original mail fixes the build problem on 
> > zLinux 31 now. Can anyone confirm that everything works as expected on 
> > Linux x86_64 please? I think it is only that platform that is in 
> > danger of being affected by this modification.
> >
> > Regards,
> > Oliver
> >
> > Oliver Deakin wrote:
> >> Hi all,
> >>
> >> I have a quick question about the macros get_unaligned() and 
> >> set_unaligned() in MemMacros.h. When compiling on zSeries Linux 31 
> >> bit systems we fall into the macros defines section for IPF machines 
> >> because we are on linux and __386__ is not defined. Unfortunately the 
> >> "(const void*) (ptr)" tries to cast a jlong (64 bit) to a 32 bit 
> >> pointer here and we get a "cast to pointer from integer of different 
> >> size" warning which is treated as an error.
> >>
> >> I'd like to fix the code to do the right thing here across all 
> >> platforms. Does anyone know this code well? Does the IPF section 
> >> (__linux__ && !__i386__) refer to Itanium machines only and not 
> >> x86_64? If so, would it suffice to replace the code that is there 
> >> with something like [1], so that only Itanium machines use the 
> >> memmove() based macros and all the rest (linux, windows, zos, aix 
> >> etc.) use the simpler cast based macros?
> >>
> >> Thanks for any help you can give!
> >>
> >> Regards,
> >> Oliver
> >>
> >> [1]
> >> #if defined(__ia64__) && defined(__linux__)
> >>
> >> #include <string.h>
> >> #define get_unaligned(type, ptr)                                  \
> >> ({                                                                \
> >>    type __tmp;                                                   \
> >>    memmove(&__tmp, (const void*) (ptr), sizeof(type));           \
> >>    __tmp;                                                        \
> >> })
> >>
> >> #define set_unaligned(type, ptr, val)                           \
> >> ({                                                              \
> >>    memmove((void*) (ptr), &val, sizeof(type));                 \
> >>    (void)0;                                                    \
> >> })
> >>
> >> #else
> >>
> >> #define get_unaligned(type, ptr) ( *((type *)((uintptr_t)(ptr))) )
> >> #define set_unaligned(type, ptr, val) ( (void) (*((type 
> >> *)((uintptr_t)(ptr))) = val) )
> >>
> >> #endif