178 |
178 |
179 UNSAFE.putByte(base, offset, (byte)0x01); |
179 UNSAFE.putByte(base, offset, (byte)0x01); |
180 |
180 |
181 // Compare |
181 // Compare |
182 { |
182 { |
183 boolean r = UNSAFE.compareAndSwapByte(base, offset, (byte)0x01, (byte)0x23); |
183 boolean r = UNSAFE.compareAndSetByte(base, offset, (byte)0x01, (byte)0x23); |
184 assertEquals(r, true, "success compareAndSwap byte"); |
184 assertEquals(r, true, "success compareAndSet byte"); |
185 byte x = UNSAFE.getByte(base, offset); |
185 byte x = UNSAFE.getByte(base, offset); |
186 assertEquals(x, (byte)0x23, "success compareAndSwap byte value"); |
186 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
187 } |
187 } |
188 |
188 |
189 { |
189 { |
190 boolean r = UNSAFE.compareAndSwapByte(base, offset, (byte)0x01, (byte)0x45); |
190 boolean r = UNSAFE.compareAndSetByte(base, offset, (byte)0x01, (byte)0x45); |
191 assertEquals(r, false, "failing compareAndSwap byte"); |
191 assertEquals(r, false, "failing compareAndSet byte"); |
192 byte x = UNSAFE.getByte(base, offset); |
192 byte x = UNSAFE.getByte(base, offset); |
193 assertEquals(x, (byte)0x23, "failing compareAndSwap byte value"); |
193 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
194 } |
194 } |
195 |
195 |
196 // Advanced compare |
196 // Advanced compare |
197 { |
197 { |
198 byte r = UNSAFE.compareAndExchangeByteVolatile(base, offset, (byte)0x23, (byte)0x01); |
198 byte r = UNSAFE.compareAndExchangeByte(base, offset, (byte)0x23, (byte)0x01); |
199 assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
199 assertEquals(r, (byte)0x23, "success compareAndExchange byte"); |
200 byte x = UNSAFE.getByte(base, offset); |
200 byte x = UNSAFE.getByte(base, offset); |
201 assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
201 assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); |
202 } |
202 } |
203 |
203 |
204 { |
204 { |
205 byte r = UNSAFE.compareAndExchangeByteVolatile(base, offset, (byte)0x23, (byte)0x45); |
205 byte r = UNSAFE.compareAndExchangeByte(base, offset, (byte)0x23, (byte)0x45); |
206 assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
206 assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); |
207 byte x = UNSAFE.getByte(base, offset); |
207 byte x = UNSAFE.getByte(base, offset); |
208 assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
208 assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); |
209 } |
209 } |
210 |
210 |
211 { |
211 { |
212 byte r = UNSAFE.compareAndExchangeByteAcquire(base, offset, (byte)0x01, (byte)0x23); |
212 byte r = UNSAFE.compareAndExchangeByteAcquire(base, offset, (byte)0x01, (byte)0x23); |
213 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
213 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
237 } |
237 } |
238 |
238 |
239 { |
239 { |
240 boolean success = false; |
240 boolean success = false; |
241 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
241 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
242 success = UNSAFE.weakCompareAndSwapByte(base, offset, (byte)0x01, (byte)0x23); |
242 success = UNSAFE.weakCompareAndSetBytePlain(base, offset, (byte)0x01, (byte)0x23); |
243 } |
243 } |
244 assertEquals(success, true, "weakCompareAndSwap byte"); |
244 assertEquals(success, true, "weakCompareAndSetPlain byte"); |
245 byte x = UNSAFE.getByte(base, offset); |
245 byte x = UNSAFE.getByte(base, offset); |
246 assertEquals(x, (byte)0x23, "weakCompareAndSwap byte value"); |
246 assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value"); |
247 } |
247 } |
248 |
248 |
249 { |
249 { |
250 boolean success = false; |
250 boolean success = false; |
251 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
251 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
252 success = UNSAFE.weakCompareAndSwapByteAcquire(base, offset, (byte)0x23, (byte)0x01); |
252 success = UNSAFE.weakCompareAndSetByteAcquire(base, offset, (byte)0x23, (byte)0x01); |
253 } |
253 } |
254 assertEquals(success, true, "weakCompareAndSwapAcquire byte"); |
254 assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
255 byte x = UNSAFE.getByte(base, offset); |
255 byte x = UNSAFE.getByte(base, offset); |
256 assertEquals(x, (byte)0x01, "weakCompareAndSwapAcquire byte"); |
256 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
257 } |
257 } |
258 |
258 |
259 { |
259 { |
260 boolean success = false; |
260 boolean success = false; |
261 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
261 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
262 success = UNSAFE.weakCompareAndSwapByteRelease(base, offset, (byte)0x01, (byte)0x23); |
262 success = UNSAFE.weakCompareAndSetByteRelease(base, offset, (byte)0x01, (byte)0x23); |
263 } |
263 } |
264 assertEquals(success, true, "weakCompareAndSwapRelease byte"); |
264 assertEquals(success, true, "weakCompareAndSetRelease byte"); |
265 byte x = UNSAFE.getByte(base, offset); |
265 byte x = UNSAFE.getByte(base, offset); |
266 assertEquals(x, (byte)0x23, "weakCompareAndSwapRelease byte"); |
266 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
267 } |
267 } |
268 |
268 |
269 { |
269 { |
270 boolean success = false; |
270 boolean success = false; |
271 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
271 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
272 success = UNSAFE.weakCompareAndSwapByteVolatile(base, offset, (byte)0x23, (byte)0x01); |
272 success = UNSAFE.weakCompareAndSetByte(base, offset, (byte)0x23, (byte)0x01); |
273 } |
273 } |
274 assertEquals(success, true, "weakCompareAndSwapVolatile byte"); |
274 assertEquals(success, true, "weakCompareAndSet byte"); |
275 byte x = UNSAFE.getByte(base, offset); |
275 byte x = UNSAFE.getByte(base, offset); |
276 assertEquals(x, (byte)0x01, "weakCompareAndSwapVolatile byte"); |
276 assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); |
277 } |
277 } |
278 |
278 |
279 UNSAFE.putByte(base, offset, (byte)0x23); |
279 UNSAFE.putByte(base, offset, (byte)0x23); |
280 |
280 |
281 // Compare set and get |
281 // Compare set and get |