prefetch instructions in Hotspot
Vladimir Kozlov
vladimir.kozlov at oracle.com
Fri Apr 4 17:06:49 UTC 2014
Code looks fine. But you should know that such software prefetches only help when you access memory without patterns
otherwise hardware prefetches in modern cpus will give you much better results. You also need to prefetch far a head of
load instructions.
Regards,
Vladimir
On 4/4/14 4:24 AM, Mahmood Naderan wrote:
> OK guys. Thanks to Vladimir and others I added the declarations and compiled JDK6 successfully. Then based on the test example provided here (http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/d98807bff770/test/compiler/6968348/Test6968348.java) I wrote the following code to see if I am using the prefetchRead correctly.
>
> import sun.misc.Unsafe;
> import java.lang.reflect.*;
> public class Arr {
> static int [] a = new int[3];
> static Unsafe unsafe;
> static int baseOffset, indexScale;
> public static void main(String[] args) throws Exception {
> a[0] = 10;
> a[1] = 20;
> a[2] = 30;
>
> Class c = Arr.class.getClassLoader().loadClass("sun.misc.Unsafe");
> Field f = c.getDeclaredField("theUnsafe");
> f.setAccessible(true);
> unsafe = (Unsafe)f.get(c);
>
> baseOffset = unsafe.arrayBaseOffset(int[].class);
> indexScale = unsafe.arrayIndexScale(int[].class);
> for (int i = 0; i < 3; i++) {
> unsafe.prefetchReadStatic(a, baseOffset+indexScale*i);
> System.out.println(a[i]);
> }
> }
> }
>
>
>
> Running the code shows everything is fine and the values are printed on the screen.
> Just need a confirmation; is that a correct usage of prefetchRead()? Is that all?
>
>
> Regards,
> Mahmood
>
>
>
>
>
> On Thursday, April 3, 2014 6:36 PM, "dalibor.topic at oracle.com" <dalibor.topic at oracle.com> wrote:
>
>> See top level file Readme-build.html for instructions.
>>
>
>> -->Oracle <http://www.oracle.com>
>> Dalibor Topic | Principal Product Manager
>> Phone: +494089091214<tel:+494089091214> | Mobile:+491737185961<tel:+491737185961>
>> Oracle Java Platform Group
>>
>> ORACLE Deutschland B.V. & Co. KG | Kühnehöfe 5 | 22761 Hamburg
>>
>> ORACLE Deutschland B.V. & Co. KG
>> Hauptverwaltung: Riesstr. 25, D-80992 München
>> Registergericht: Amtsgericht München, HRA 95603
>> Geschäftsführer: Jürgen Kunz
>>
>> Komplementärin: ORACLE Deutschland Verwaltung B.V.
>> Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
>> Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
>> Geschäftsführer: Alexander van der Ven, Astrid Kepper, Val Maher
>>
>> Green Oracle <http://www.oracle.com/commitment> Oracle is committed to developing practices and products that help protect the environment
More information about the hotspot-dev
mailing list