< prev index next >

test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestObject.java

Print this page
rev 12711 : 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
Reviewed-by: psandoz, dholmes, thartmann
Contributed-by: ron.pressler@oracle.com, claes.redestad@oracle.com

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 149,184 **** UNSAFE.putObject(base, offset, "foo"); // Compare { ! boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "bar"); ! assertEquals(r, true, "success compareAndSwap Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "success compareAndSwap Object value"); } { ! boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "baz"); ! assertEquals(r, false, "failing compareAndSwap Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "failing compareAndSwap Object value"); } // Advanced compare { ! Object r = UNSAFE.compareAndExchangeObjectVolatile(base, offset, "bar", "foo"); ! assertEquals(r, "bar", "success compareAndExchangeVolatile Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "success compareAndExchangeVolatile Object value"); } { ! Object r = UNSAFE.compareAndExchangeObjectVolatile(base, offset, "bar", "baz"); ! assertEquals(r, "foo", "failing compareAndExchangeVolatile Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "failing compareAndExchangeVolatile Object value"); } { Object r = UNSAFE.compareAndExchangeObjectAcquire(base, offset, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire Object"); --- 149,184 ---- UNSAFE.putObject(base, offset, "foo"); // Compare { ! boolean r = UNSAFE.compareAndSetObject(base, offset, "foo", "bar"); ! assertEquals(r, true, "success compareAndSet Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "success compareAndSet Object value"); } { ! boolean r = UNSAFE.compareAndSetObject(base, offset, "foo", "baz"); ! assertEquals(r, false, "failing compareAndSet Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "failing compareAndSet Object value"); } // Advanced compare { ! Object r = UNSAFE.compareAndExchangeObject(base, offset, "bar", "foo"); ! assertEquals(r, "bar", "success compareAndExchange Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "success compareAndExchange Object value"); } { ! Object r = UNSAFE.compareAndExchangeObject(base, offset, "bar", "baz"); ! assertEquals(r, "foo", "failing compareAndExchange Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "failing compareAndExchange Object value"); } { Object r = UNSAFE.compareAndExchangeObjectAcquire(base, offset, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire Object");
*** 208,252 **** } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSwapObject(base, offset, "foo", "bar"); } ! assertEquals(success, true, "weakCompareAndSwap Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "weakCompareAndSwap Object value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSwapObjectAcquire(base, offset, "bar", "foo"); } ! assertEquals(success, true, "weakCompareAndSwapAcquire Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "weakCompareAndSwapAcquire Object"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSwapObjectRelease(base, offset, "foo", "bar"); } ! assertEquals(success, true, "weakCompareAndSwapRelease Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "weakCompareAndSwapRelease Object"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSwapObjectVolatile(base, offset, "bar", "foo"); } ! assertEquals(success, true, "weakCompareAndSwapVolatile Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "weakCompareAndSwapVolatile Object"); } UNSAFE.putObject(base, offset, "bar"); // Compare set and get --- 208,252 ---- } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSetObjectPlain(base, offset, "foo", "bar"); } ! assertEquals(success, true, "weakCompareAndSetPlain Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "weakCompareAndSetPlain Object value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSetObjectAcquire(base, offset, "bar", "foo"); } ! assertEquals(success, true, "weakCompareAndSetAcquire Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "weakCompareAndSetAcquire Object"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSetObjectRelease(base, offset, "foo", "bar"); } ! assertEquals(success, true, "weakCompareAndSetRelease Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "bar", "weakCompareAndSetRelease Object"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = UNSAFE.weakCompareAndSetObject(base, offset, "bar", "foo"); } ! assertEquals(success, true, "weakCompareAndSet Object"); Object x = UNSAFE.getObject(base, offset); ! assertEquals(x, "foo", "weakCompareAndSet Object"); } UNSAFE.putObject(base, offset, "bar"); // Compare set and get
*** 258,263 **** } } } - --- 258,262 ----
< prev index next >