< prev index next >

test/compiler/unsafe/SunMiscUnsafeAccessTestChar.java

Print this page




 128     }
 129 
 130     @Test
 131     public void testArrayOffHeapDirect() {
 132         int size = 10;
 133         long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
 134         try {
 135             for (int c = 0; c < ITERS; c++) {
 136                 for (int i = 0; i < size; i++) {
 137                     testAccess((((long) i) << ARRAY_SHIFT) + address);
 138                 }
 139             }
 140         } finally {
 141             UNSAFE.freeMemory(address);
 142         }
 143     }
 144 
 145     static void testAccess(Object base, long offset) {
 146         // Plain
 147         {
 148             UNSAFE.putChar(base, offset, 'a');
 149             char x = UNSAFE.getChar(base, offset);
 150             assertEquals(x, 'a', "set char value");
 151         }
 152 
 153         // Volatile
 154         {
 155             UNSAFE.putCharVolatile(base, offset, 'b');
 156             char x = UNSAFE.getCharVolatile(base, offset);
 157             assertEquals(x, 'b', "putVolatile char value");
 158         }
 159 
 160 
 161 
 162 
 163 
 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putChar(address, 'a');
 170             char x = UNSAFE.getChar(address);
 171             assertEquals(x, 'a', "set char value");
 172         }
 173     }
 174 }
 175 


 128     }
 129 
 130     @Test
 131     public void testArrayOffHeapDirect() {
 132         int size = 10;
 133         long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
 134         try {
 135             for (int c = 0; c < ITERS; c++) {
 136                 for (int i = 0; i < size; i++) {
 137                     testAccess((((long) i) << ARRAY_SHIFT) + address);
 138                 }
 139             }
 140         } finally {
 141             UNSAFE.freeMemory(address);
 142         }
 143     }
 144 
 145     static void testAccess(Object base, long offset) {
 146         // Plain
 147         {
 148             UNSAFE.putChar(base, offset, '\u0123');
 149             char x = UNSAFE.getChar(base, offset);
 150             assertEquals(x, '\u0123', "set char value");
 151         }
 152 
 153         // Volatile
 154         {
 155             UNSAFE.putCharVolatile(base, offset, '\u4567');
 156             char x = UNSAFE.getCharVolatile(base, offset);
 157             assertEquals(x, '\u4567', "putVolatile char value");
 158         }
 159 
 160 
 161 
 162 
 163 
 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putChar(address, '\u0123');
 170             char x = UNSAFE.getChar(address);
 171             assertEquals(x, '\u0123', "set char value");
 172         }
 173     }
 174 }
 175 
< prev index next >