RFR(m): 8220351: Cross-modifying code

Doerr, Martin martin.doerr at sap.com
Mon Jul 1 10:06:05 UTC 2019


Hi Florian,

sorry for breaking 32 bit linux. We don't build on this platform so we didn't notice.
I believe "Compiler version last used for testing: gcc 4.8.2" is still correct for 64 bit linux.

Andrew's proposal looks reasonable.

Best regards,
Martin


> -----Original Message-----
> From: Florian Weimer <fweimer at redhat.com>
> Sent: Mittwoch, 19. Juni 2019 19:16
> To: Doerr, Martin <martin.doerr at sap.com>
> Cc: hotspot-dev at openjdk.java.net; aph at redhat.com
> Subject: Re: RFR(m): 8220351: Cross-modifying code
> 
> * Florian Weimer:
> 
> > * Martin Doerr:
> >
> >> Not sure if the inline assembler code on x86 necessarily needs a "clobber
> memory" effect.
> >> I don't know what a C++ compiler is allowed to do if it doesn't know that
> the code has some kind of memory effect.
> >>
> >> For ebx...edx, you could also use clobber if you want to make it shorter.
> >> E.g. with "+a" to use eax as input and output:
> >>   int idx = 0;
> >>   __asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory");
> >
> > ebx clobbers are not supported on older GCC versions.
> > src/hotspot/os_cpu/linux_x86/orderAccess_linux_x86.hpp currently says
> > this:
> >
> > // Compiler version last used for testing: gcc 4.8.2
> >
> > But this is blatantly not true because GCC 4.8 cannot spill ebx in PIC
> > mode.
> 
> I got this patch from Andrew Haley, and the build works again with GCC
> 4.8.5 (the system compiler on Red Hat Enterprise Linux 7):
> 
> diff -r d7da94e6c169
> src/hotspot/os_cpu/linux_x86/orderAccess_linux_x86.hpp
> --- a/src/hotspot/os_cpu/linux_x86/orderAccess_linux_x86.hpp    Tue Jun 18
> 16:15:15 2019 +0100
> +++ b/src/hotspot/os_cpu/linux_x86/orderAccess_linux_x86.hpp    Wed Jun
> 19 17:52:26 2019 +0100
> @@ -57,7 +57,11 @@
> 
>  inline void OrderAccess::cross_modify_fence() {
>    int idx = 0;
> +#ifdef AMD64
>    __asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory");
> +#else
> +  __asm__ volatile ("xchg %%esi, %%ebx; cpuid; xchg %%esi, %%ebx " : "+a"
> (idx) : : "esi", "ecx", "edx", "memory");
> +#endif
>  }
> 
>  template<>
> 
> GCC can spill %esi without problems since forever, so this should work
> everywhere.
> 
> Thanks,
> Florian


More information about the hotspot-dev mailing list