< prev index next >

test/compiler/unsafe/SunMiscUnsafeAccessTestFloat.java

Print this page




  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for float
  28  * @modules jdk.unsupported/sun.misc
  29  * @run testng/othervm -Diters=100   -Xint                   SunMiscUnsafeAccessTestFloat
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestFloat
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  SunMiscUnsafeAccessTestFloat
  32  * @run testng/othervm -Diters=20000                         SunMiscUnsafeAccessTestFloat
  33  */
  34 
  35 import org.testng.annotations.Test;
  36 
  37 import java.lang.reflect.Field;
  38 
  39 import static org.testng.Assert.*;
  40 
  41 public class SunMiscUnsafeAccessTestFloat {
  42     static final int ITERS = Integer.getInteger("iters", 1);

  43 
  44     static final sun.misc.Unsafe UNSAFE;
  45 
  46     static final long V_OFFSET;
  47 
  48     static final Object STATIC_V_BASE;
  49 
  50     static final long STATIC_V_OFFSET;
  51 
  52     static int ARRAY_OFFSET;
  53 
  54     static int ARRAY_SHIFT;
  55 
  56     static {
  57         try {
  58             Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
  59             f.setAccessible(true);
  60             UNSAFE = (sun.misc.Unsafe) f.get(null);
  61         } catch (Exception e) {
  62             throw new RuntimeException("Unable to get Unsafe instance.", e);


 143 
 144     static void testAccess(Object base, long offset) {
 145         // Plain
 146         {
 147             UNSAFE.putFloat(base, offset, 1.0f);
 148             float x = UNSAFE.getFloat(base, offset);
 149             assertEquals(x, 1.0f, "set float value");
 150         }
 151 
 152         // Volatile
 153         {
 154             UNSAFE.putFloatVolatile(base, offset, 2.0f);
 155             float x = UNSAFE.getFloatVolatile(base, offset);
 156             assertEquals(x, 2.0f, "putVolatile float value");
 157         }
 158 
 159 
 160 
 161 
 162 
 163 
 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putFloat(address, 1.0f);
 170             float x = UNSAFE.getFloat(address);
 171             assertEquals(x, 1.0f, "set float value");
 172         }
 173     }
 174 }
 175 
 176 


  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for float
  28  * @modules jdk.unsupported/sun.misc
  29  * @run testng/othervm -Diters=100   -Xint                   SunMiscUnsafeAccessTestFloat
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestFloat
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  SunMiscUnsafeAccessTestFloat
  32  * @run testng/othervm -Diters=20000                         SunMiscUnsafeAccessTestFloat
  33  */
  34 
  35 import org.testng.annotations.Test;
  36 
  37 import java.lang.reflect.Field;
  38 
  39 import static org.testng.Assert.*;
  40 
  41 public class SunMiscUnsafeAccessTestFloat {
  42     static final int ITERS = Integer.getInteger("iters", 1);
  43     static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
  44 
  45     static final sun.misc.Unsafe UNSAFE;
  46 
  47     static final long V_OFFSET;
  48 
  49     static final Object STATIC_V_BASE;
  50 
  51     static final long STATIC_V_OFFSET;
  52 
  53     static int ARRAY_OFFSET;
  54 
  55     static int ARRAY_SHIFT;
  56 
  57     static {
  58         try {
  59             Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
  60             f.setAccessible(true);
  61             UNSAFE = (sun.misc.Unsafe) f.get(null);
  62         } catch (Exception e) {
  63             throw new RuntimeException("Unable to get Unsafe instance.", e);


 144 
 145     static void testAccess(Object base, long offset) {
 146         // Plain
 147         {
 148             UNSAFE.putFloat(base, offset, 1.0f);
 149             float x = UNSAFE.getFloat(base, offset);
 150             assertEquals(x, 1.0f, "set float value");
 151         }
 152 
 153         // Volatile
 154         {
 155             UNSAFE.putFloatVolatile(base, offset, 2.0f);
 156             float x = UNSAFE.getFloatVolatile(base, offset);
 157             assertEquals(x, 2.0f, "putVolatile float value");
 158         }
 159 
 160 
 161 
 162 
 163 

 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putFloat(address, 1.0f);
 170             float x = UNSAFE.getFloat(address);
 171             assertEquals(x, 1.0f, "set float value");
 172         }
 173     }
 174 }

 175 
< prev index next >