prefetch instructions in Hotspot

Mahmood Naderan nt_mahmood at yahoo.com
Fri Apr 4 11:24:43 UTC 2014


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