hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestShort.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.putShort(base, offset, (short)0x0123);
   197         UNSAFE.putShort(base, offset, (short)0x0123);
   198 
   198 
   199         // Compare
   199         // Compare
   200         {
   200         {
   201             boolean r = UNSAFE.compareAndSwapShort(base, offset, (short)0x0123, (short)0x4567);
   201             boolean r = UNSAFE.compareAndSetShort(base, offset, (short)0x0123, (short)0x4567);
   202             assertEquals(r, true, "success compareAndSwap short");
   202             assertEquals(r, true, "success compareAndSet short");
   203             short x = UNSAFE.getShort(base, offset);
   203             short x = UNSAFE.getShort(base, offset);
   204             assertEquals(x, (short)0x4567, "success compareAndSwap short value");
   204             assertEquals(x, (short)0x4567, "success compareAndSet short value");
   205         }
   205         }
   206 
   206 
   207         {
   207         {
   208             boolean r = UNSAFE.compareAndSwapShort(base, offset, (short)0x0123, (short)0x89AB);
   208             boolean r = UNSAFE.compareAndSetShort(base, offset, (short)0x0123, (short)0x89AB);
   209             assertEquals(r, false, "failing compareAndSwap short");
   209             assertEquals(r, false, "failing compareAndSet short");
   210             short x = UNSAFE.getShort(base, offset);
   210             short x = UNSAFE.getShort(base, offset);
   211             assertEquals(x, (short)0x4567, "failing compareAndSwap short value");
   211             assertEquals(x, (short)0x4567, "failing compareAndSet short value");
   212         }
   212         }
   213 
   213 
   214         // Advanced compare
   214         // Advanced compare
   215         {
   215         {
   216             short r = UNSAFE.compareAndExchangeShortVolatile(base, offset, (short)0x4567, (short)0x0123);
   216             short r = UNSAFE.compareAndExchangeShort(base, offset, (short)0x4567, (short)0x0123);
   217             assertEquals(r, (short)0x4567, "success compareAndExchangeVolatile short");
   217             assertEquals(r, (short)0x4567, "success compareAndExchange short");
   218             short x = UNSAFE.getShort(base, offset);
   218             short x = UNSAFE.getShort(base, offset);
   219             assertEquals(x, (short)0x0123, "success compareAndExchangeVolatile short value");
   219             assertEquals(x, (short)0x0123, "success compareAndExchange short value");
   220         }
   220         }
   221 
   221 
   222         {
   222         {
   223             short r = UNSAFE.compareAndExchangeShortVolatile(base, offset, (short)0x4567, (short)0x89AB);
   223             short r = UNSAFE.compareAndExchangeShort(base, offset, (short)0x4567, (short)0x89AB);
   224             assertEquals(r, (short)0x0123, "failing compareAndExchangeVolatile short");
   224             assertEquals(r, (short)0x0123, "failing compareAndExchange short");
   225             short x = UNSAFE.getShort(base, offset);
   225             short x = UNSAFE.getShort(base, offset);
   226             assertEquals(x, (short)0x0123, "failing compareAndExchangeVolatile short value");
   226             assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
   227         }
   227         }
   228 
   228 
   229         {
   229         {
   230             short r = UNSAFE.compareAndExchangeShortAcquire(base, offset, (short)0x0123, (short)0x4567);
   230             short r = UNSAFE.compareAndExchangeShortAcquire(base, offset, (short)0x0123, (short)0x4567);
   231             assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
   231             assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
   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.weakCompareAndSwapShort(base, offset, (short)0x0123, (short)0x4567);
   260                 success = UNSAFE.weakCompareAndSetShortPlain(base, offset, (short)0x0123, (short)0x4567);
   261             }
   261             }
   262             assertEquals(success, true, "weakCompareAndSwap short");
   262             assertEquals(success, true, "weakCompareAndSetPlain short");
   263             short x = UNSAFE.getShort(base, offset);
   263             short x = UNSAFE.getShort(base, offset);
   264             assertEquals(x, (short)0x4567, "weakCompareAndSwap short value");
   264             assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short 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.weakCompareAndSwapShortAcquire(base, offset, (short)0x4567, (short)0x0123);
   270                 success = UNSAFE.weakCompareAndSetShortAcquire(base, offset, (short)0x4567, (short)0x0123);
   271             }
   271             }
   272             assertEquals(success, true, "weakCompareAndSwapAcquire short");
   272             assertEquals(success, true, "weakCompareAndSetAcquire short");
   273             short x = UNSAFE.getShort(base, offset);
   273             short x = UNSAFE.getShort(base, offset);
   274             assertEquals(x, (short)0x0123, "weakCompareAndSwapAcquire short");
   274             assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
   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.weakCompareAndSwapShortRelease(base, offset, (short)0x0123, (short)0x4567);
   280                 success = UNSAFE.weakCompareAndSetShortRelease(base, offset, (short)0x0123, (short)0x4567);
   281             }
   281             }
   282             assertEquals(success, true, "weakCompareAndSwapRelease short");
   282             assertEquals(success, true, "weakCompareAndSetRelease short");
   283             short x = UNSAFE.getShort(base, offset);
   283             short x = UNSAFE.getShort(base, offset);
   284             assertEquals(x, (short)0x4567, "weakCompareAndSwapRelease short");
   284             assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
   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.weakCompareAndSwapShortVolatile(base, offset, (short)0x4567, (short)0x0123);
   290                 success = UNSAFE.weakCompareAndSetShort(base, offset, (short)0x4567, (short)0x0123);
   291             }
   291             }
   292             assertEquals(success, true, "weakCompareAndSwapVolatile short");
   292             assertEquals(success, true, "weakCompareAndSet short");
   293             short x = UNSAFE.getShort(base, offset);
   293             short x = UNSAFE.getShort(base, offset);
   294             assertEquals(x, (short)0x0123, "weakCompareAndSwapVolatile short");
   294             assertEquals(x, (short)0x0123, "weakCompareAndSet short");
   295         }
   295         }
   296 
   296 
   297         UNSAFE.putShort(base, offset, (short)0x4567);
   297         UNSAFE.putShort(base, offset, (short)0x4567);
   298 
   298 
   299         // Compare set and get
   299         // Compare set and get
   322             short x = UNSAFE.getShort(address);
   322             short x = UNSAFE.getShort(address);
   323             assertEquals(x, (short)0x0123, "set short value");
   323             assertEquals(x, (short)0x0123, "set short value");
   324         }
   324         }
   325     }
   325     }
   326 }
   326 }
   327