< prev index next >

test/compiler/unsafe/SunMiscUnsafeAccessTestByte.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.putByte(base, offset, (byte)1);
 149             byte x = UNSAFE.getByte(base, offset);
 150             assertEquals(x, (byte)1, "set byte value");
 151         }
 152 
 153         // Volatile
 154         {
 155             UNSAFE.putByteVolatile(base, offset, (byte)2);
 156             byte x = UNSAFE.getByteVolatile(base, offset);
 157             assertEquals(x, (byte)2, "putVolatile byte value");
 158         }
 159 
 160 
 161 
 162 
 163 
 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putByte(address, (byte)1);
 170             byte x = UNSAFE.getByte(address);
 171             assertEquals(x, (byte)1, "set byte 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.putByte(base, offset, (byte)0x01);
 149             byte x = UNSAFE.getByte(base, offset);
 150             assertEquals(x, (byte)0x01, "set byte value");
 151         }
 152 
 153         // Volatile
 154         {
 155             UNSAFE.putByteVolatile(base, offset, (byte)0x23);
 156             byte x = UNSAFE.getByteVolatile(base, offset);
 157             assertEquals(x, (byte)0x23, "putVolatile byte value");
 158         }
 159 
 160 
 161 
 162 
 163 
 164     }
 165 
 166     static void testAccess(long address) {
 167         // Plain
 168         {
 169             UNSAFE.putByte(address, (byte)0x01);
 170             byte x = UNSAFE.getByte(address);
 171             assertEquals(x, (byte)0x01, "set byte value");
 172         }
 173     }
 174 }
 175 
< prev index next >