< prev index next >

test/compiler/unsafe/SunMiscUnsafeAccessTestBoolean.java

Print this page




  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for boolean
  28  * @modules jdk.unsupported/sun.misc
  29  * @run testng/othervm -Diters=100   -Xint                   SunMiscUnsafeAccessTestBoolean
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestBoolean
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  SunMiscUnsafeAccessTestBoolean
  32  * @run testng/othervm -Diters=20000                         SunMiscUnsafeAccessTestBoolean
  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 SunMiscUnsafeAccessTestBoolean {
  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);


 114 
 115     static void testAccess(Object base, long offset) {
 116         // Plain
 117         {
 118             UNSAFE.putBoolean(base, offset, true);
 119             boolean x = UNSAFE.getBoolean(base, offset);
 120             assertEquals(x, true, "set boolean value");
 121         }
 122 
 123         // Volatile
 124         {
 125             UNSAFE.putBooleanVolatile(base, offset, false);
 126             boolean x = UNSAFE.getBooleanVolatile(base, offset);
 127             assertEquals(x, false, "putVolatile boolean value");
 128         }
 129 
 130 
 131 
 132 
 133 
 134 
 135     }
 136 
 137 }
 138 
 139 


  23 
  24 /*
  25  * @test
  26  * @bug 8143628
  27  * @summary Test unsafe access for boolean
  28  * @modules jdk.unsupported/sun.misc
  29  * @run testng/othervm -Diters=100   -Xint                   SunMiscUnsafeAccessTestBoolean
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestBoolean
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  SunMiscUnsafeAccessTestBoolean
  32  * @run testng/othervm -Diters=20000                         SunMiscUnsafeAccessTestBoolean
  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 SunMiscUnsafeAccessTestBoolean {
  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);


 115 
 116     static void testAccess(Object base, long offset) {
 117         // Plain
 118         {
 119             UNSAFE.putBoolean(base, offset, true);
 120             boolean x = UNSAFE.getBoolean(base, offset);
 121             assertEquals(x, true, "set boolean value");
 122         }
 123 
 124         // Volatile
 125         {
 126             UNSAFE.putBooleanVolatile(base, offset, false);
 127             boolean x = UNSAFE.getBooleanVolatile(base, offset);
 128             assertEquals(x, false, "putVolatile boolean value");
 129         }
 130 
 131 
 132 
 133 
 134 

 135     }
 136 
 137 }

 138 
< prev index next >