< prev index next >

test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestFloat.java

Print this page




  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for float
  28  * @modules java.base/jdk.internal.misc
  29  * @run testng/othervm -Diters=100   -Xint                   JdkInternalMiscUnsafeAccessTestFloat
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestFloat
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  JdkInternalMiscUnsafeAccessTestFloat
  32  * @run testng/othervm -Diters=20000                         JdkInternalMiscUnsafeAccessTestFloat
  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 JdkInternalMiscUnsafeAccessTestFloat {
  42     static final int ITERS = Integer.getInteger("iters", 1);

  43 
  44     static final jdk.internal.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 = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
  59             f.setAccessible(true);
  60             UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
  61         } catch (Exception e) {
  62             throw new RuntimeException("Unable to get Unsafe instance.", e);


 167         // Opaque
 168         {
 169             UNSAFE.putFloatOpaque(base, offset, 2.0f);
 170             float x = UNSAFE.getFloatOpaque(base, offset);
 171             assertEquals(x, 2.0f, "putOpaque float value");
 172         }
 173 
 174 
 175 
 176     }
 177 
 178     static void testAccess(long address) {
 179         // Plain
 180         {
 181             UNSAFE.putFloat(address, 1.0f);
 182             float x = UNSAFE.getFloat(address);
 183             assertEquals(x, 1.0f, "set float value");
 184         }
 185     }
 186 }
 187 
 188 


  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for float
  28  * @modules java.base/jdk.internal.misc
  29  * @run testng/othervm -Diters=100   -Xint                   JdkInternalMiscUnsafeAccessTestFloat
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestFloat
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  JdkInternalMiscUnsafeAccessTestFloat
  32  * @run testng/othervm -Diters=20000                         JdkInternalMiscUnsafeAccessTestFloat
  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 JdkInternalMiscUnsafeAccessTestFloat {
  42     static final int ITERS = Integer.getInteger("iters", 1);
  43     static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
  44 
  45     static final jdk.internal.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 = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
  60             f.setAccessible(true);
  61             UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
  62         } catch (Exception e) {
  63             throw new RuntimeException("Unable to get Unsafe instance.", e);


 168         // Opaque
 169         {
 170             UNSAFE.putFloatOpaque(base, offset, 2.0f);
 171             float x = UNSAFE.getFloatOpaque(base, offset);
 172             assertEquals(x, 2.0f, "putOpaque float value");
 173         }
 174 
 175 
 176 
 177     }
 178 
 179     static void testAccess(long address) {
 180         // Plain
 181         {
 182             UNSAFE.putFloat(address, 1.0f);
 183             float x = UNSAFE.getFloat(address);
 184             assertEquals(x, 1.0f, "set float value");
 185         }
 186     }
 187 }

 188 
< prev index next >