hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestLong.java
changeset 45514 0fc9cc73ce45
parent 42307 cefc81dc1d52
equal deleted inserted replaced
45513:5431282d8ce1 45514:0fc9cc73ce45
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   196 
   196 
   197         UNSAFE.putLong(base, offset, 0x0123456789ABCDEFL);
   197         UNSAFE.putLong(base, offset, 0x0123456789ABCDEFL);
   198 
   198 
   199         // Compare
   199         // Compare
   200         {
   200         {
   201             boolean r = UNSAFE.compareAndSwapLong(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   201             boolean r = UNSAFE.compareAndSetLong(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   202             assertEquals(r, true, "success compareAndSwap long");
   202             assertEquals(r, true, "success compareAndSet long");
   203             long x = UNSAFE.getLong(base, offset);
   203             long x = UNSAFE.getLong(base, offset);
   204             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSwap long value");
   204             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
   205         }
   205         }
   206 
   206 
   207         {
   207         {
   208             boolean r = UNSAFE.compareAndSwapLong(base, offset, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
   208             boolean r = UNSAFE.compareAndSetLong(base, offset, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
   209             assertEquals(r, false, "failing compareAndSwap long");
   209             assertEquals(r, false, "failing compareAndSet long");
   210             long x = UNSAFE.getLong(base, offset);
   210             long x = UNSAFE.getLong(base, offset);
   211             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSwap long value");
   211             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
   212         }
   212         }
   213 
   213 
   214         // Advanced compare
   214         // Advanced compare
   215         {
   215         {
   216             long r = UNSAFE.compareAndExchangeLongVolatile(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   216             long r = UNSAFE.compareAndExchangeLong(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   217             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeVolatile long");
   217             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
   218             long x = UNSAFE.getLong(base, offset);
   218             long x = UNSAFE.getLong(base, offset);
   219             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeVolatile long value");
   219             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
   220         }
   220         }
   221 
   221 
   222         {
   222         {
   223             long r = UNSAFE.compareAndExchangeLongVolatile(base, offset, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
   223             long r = UNSAFE.compareAndExchangeLong(base, offset, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
   224             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long");
   224             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
   225             long x = UNSAFE.getLong(base, offset);
   225             long x = UNSAFE.getLong(base, offset);
   226             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long value");
   226             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
   227         }
   227         }
   228 
   228 
   229         {
   229         {
   230             long r = UNSAFE.compareAndExchangeLongAcquire(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   230             long r = UNSAFE.compareAndExchangeLongAcquire(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   231             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
   231             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
   255         }
   255         }
   256 
   256 
   257         {
   257         {
   258             boolean success = false;
   258             boolean success = false;
   259             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   259             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   260                 success = UNSAFE.weakCompareAndSwapLong(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   260                 success = UNSAFE.weakCompareAndSetLongPlain(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   261             }
   261             }
   262             assertEquals(success, true, "weakCompareAndSwap long");
   262             assertEquals(success, true, "weakCompareAndSetPlain long");
   263             long x = UNSAFE.getLong(base, offset);
   263             long x = UNSAFE.getLong(base, offset);
   264             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSwap long value");
   264             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
   265         }
   265         }
   266 
   266 
   267         {
   267         {
   268             boolean success = false;
   268             boolean success = false;
   269             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   269             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   270                 success = UNSAFE.weakCompareAndSwapLongAcquire(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   270                 success = UNSAFE.weakCompareAndSetLongAcquire(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   271             }
   271             }
   272             assertEquals(success, true, "weakCompareAndSwapAcquire long");
   272             assertEquals(success, true, "weakCompareAndSetAcquire long");
   273             long x = UNSAFE.getLong(base, offset);
   273             long x = UNSAFE.getLong(base, offset);
   274             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSwapAcquire long");
   274             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
   275         }
   275         }
   276 
   276 
   277         {
   277         {
   278             boolean success = false;
   278             boolean success = false;
   279             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   279             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   280                 success = UNSAFE.weakCompareAndSwapLongRelease(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   280                 success = UNSAFE.weakCompareAndSetLongRelease(base, offset, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
   281             }
   281             }
   282             assertEquals(success, true, "weakCompareAndSwapRelease long");
   282             assertEquals(success, true, "weakCompareAndSetRelease long");
   283             long x = UNSAFE.getLong(base, offset);
   283             long x = UNSAFE.getLong(base, offset);
   284             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSwapRelease long");
   284             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
   285         }
   285         }
   286 
   286 
   287         {
   287         {
   288             boolean success = false;
   288             boolean success = false;
   289             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   289             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   290                 success = UNSAFE.weakCompareAndSwapLongVolatile(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   290                 success = UNSAFE.weakCompareAndSetLong(base, offset, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
   291             }
   291             }
   292             assertEquals(success, true, "weakCompareAndSwapVolatile long");
   292             assertEquals(success, true, "weakCompareAndSet long");
   293             long x = UNSAFE.getLong(base, offset);
   293             long x = UNSAFE.getLong(base, offset);
   294             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSwapVolatile long");
   294             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
   295         }
   295         }
   296 
   296 
   297         UNSAFE.putLong(base, offset, 0xCAFEBABECAFEBABEL);
   297         UNSAFE.putLong(base, offset, 0xCAFEBABECAFEBABEL);
   298 
   298 
   299         // Compare set and get
   299         // Compare set and get
   322             long x = UNSAFE.getLong(address);
   322             long x = UNSAFE.getLong(address);
   323             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
   323             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
   324         }
   324         }
   325     }
   325     }
   326 }
   326 }
   327