< prev index next >

test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestChar.java

Print this page




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


 185         }
 186 
 187         {
 188             UNSAFE.putCharUnaligned(base, offset, 'b', false);
 189             char x = UNSAFE.getCharUnaligned(base, offset, false);
 190             assertEquals(x, 'b', "putUnaligned little endian char value");
 191         }
 192 
 193 
 194     }
 195 
 196     static void testAccess(long address) {
 197         // Plain
 198         {
 199             UNSAFE.putChar(address, 'a');
 200             char x = UNSAFE.getChar(address);
 201             assertEquals(x, 'a', "set char value");
 202         }
 203     }
 204 }
 205 
 206 


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


 186         }
 187 
 188         {
 189             UNSAFE.putCharUnaligned(base, offset, 'b', false);
 190             char x = UNSAFE.getCharUnaligned(base, offset, false);
 191             assertEquals(x, 'b', "putUnaligned little endian char value");
 192         }
 193 
 194 
 195     }
 196 
 197     static void testAccess(long address) {
 198         // Plain
 199         {
 200             UNSAFE.putChar(address, 'a');
 201             char x = UNSAFE.getChar(address);
 202             assertEquals(x, 'a', "set char value");
 203         }
 204     }
 205 }

 206 
< prev index next >