Flush Cache from Within Hotspot

Andrew Haley aph at redhat.com
Thu Feb 18 11:35:54 UTC 2021


On 17/02/2021 21:55, Sam Thomas wrote:
> I am working on a project that explores different architecture 
> simulations using JDK14, and I am trying to flush the cache

Which cache? There is more than one.

> from the 
> source code. We are working with an aarch64 target and I have tried the 
> following to no avail:
> 
> 1. Use the clflush C++ built-in instruction (this is an x86 instruction)
> 
> 2. Dynamically allocate a large (2 MB) block of memory, and assign 
> random numbers to the array (Hotspot assertions do not allow for dynamic 
> memory allocation)
> 
> 3. Allocate a large (2 MB) block of memory on the stack, and assign 
> random numbers to the array (this properly compiles, but the stack 
> overflows and a segmentation fault is raised)
> 
> Has anyone done projects like this in the past, or is there a standard 
> for how to perform such a procedure? Thank you for your help!

GCC (and LLVM) have
__builtin___clear_cache (char *BEGIN, char *END)

... which clears all caches in the address space to the point
of unification.

Windows has FlushInstructionCache which does the same. I don't think there's
any builtin that flushes the data caches without flushing the
instruction caches too, to do that you need to use assembly
language.

   DC CVAU is what you need.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671




More information about the hotspot-gc-dev mailing list