hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestBoolean.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.
   149 
   149 
   150         UNSAFE.putBoolean(base, offset, true);
   150         UNSAFE.putBoolean(base, offset, true);
   151 
   151 
   152         // Compare
   152         // Compare
   153         {
   153         {
   154             boolean r = UNSAFE.compareAndSwapBoolean(base, offset, true, false);
   154             boolean r = UNSAFE.compareAndSetBoolean(base, offset, true, false);
   155             assertEquals(r, true, "success compareAndSwap boolean");
   155             assertEquals(r, true, "success compareAndSet boolean");
   156             boolean x = UNSAFE.getBoolean(base, offset);
   156             boolean x = UNSAFE.getBoolean(base, offset);
   157             assertEquals(x, false, "success compareAndSwap boolean value");
   157             assertEquals(x, false, "success compareAndSet boolean value");
   158         }
   158         }
   159 
   159 
   160         {
   160         {
   161             boolean r = UNSAFE.compareAndSwapBoolean(base, offset, true, false);
   161             boolean r = UNSAFE.compareAndSetBoolean(base, offset, true, false);
   162             assertEquals(r, false, "failing compareAndSwap boolean");
   162             assertEquals(r, false, "failing compareAndSet boolean");
   163             boolean x = UNSAFE.getBoolean(base, offset);
   163             boolean x = UNSAFE.getBoolean(base, offset);
   164             assertEquals(x, false, "failing compareAndSwap boolean value");
   164             assertEquals(x, false, "failing compareAndSet boolean value");
   165         }
   165         }
   166 
   166 
   167         // Advanced compare
   167         // Advanced compare
   168         {
   168         {
   169             boolean r = UNSAFE.compareAndExchangeBooleanVolatile(base, offset, false, true);
   169             boolean r = UNSAFE.compareAndExchangeBoolean(base, offset, false, true);
   170             assertEquals(r, false, "success compareAndExchangeVolatile boolean");
   170             assertEquals(r, false, "success compareAndExchange boolean");
   171             boolean x = UNSAFE.getBoolean(base, offset);
   171             boolean x = UNSAFE.getBoolean(base, offset);
   172             assertEquals(x, true, "success compareAndExchangeVolatile boolean value");
   172             assertEquals(x, true, "success compareAndExchange boolean value");
   173         }
   173         }
   174 
   174 
   175         {
   175         {
   176             boolean r = UNSAFE.compareAndExchangeBooleanVolatile(base, offset, false, false);
   176             boolean r = UNSAFE.compareAndExchangeBoolean(base, offset, false, false);
   177             assertEquals(r, true, "failing compareAndExchangeVolatile boolean");
   177             assertEquals(r, true, "failing compareAndExchange boolean");
   178             boolean x = UNSAFE.getBoolean(base, offset);
   178             boolean x = UNSAFE.getBoolean(base, offset);
   179             assertEquals(x, true, "failing compareAndExchangeVolatile boolean value");
   179             assertEquals(x, true, "failing compareAndExchange boolean value");
   180         }
   180         }
   181 
   181 
   182         {
   182         {
   183             boolean r = UNSAFE.compareAndExchangeBooleanAcquire(base, offset, true, false);
   183             boolean r = UNSAFE.compareAndExchangeBooleanAcquire(base, offset, true, false);
   184             assertEquals(r, true, "success compareAndExchangeAcquire boolean");
   184             assertEquals(r, true, "success compareAndExchangeAcquire boolean");
   208         }
   208         }
   209 
   209 
   210         {
   210         {
   211             boolean success = false;
   211             boolean success = false;
   212             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   212             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   213                 success = UNSAFE.weakCompareAndSwapBoolean(base, offset, true, false);
   213                 success = UNSAFE.weakCompareAndSetBooleanPlain(base, offset, true, false);
   214             }
   214             }
   215             assertEquals(success, true, "weakCompareAndSwap boolean");
   215             assertEquals(success, true, "weakCompareAndSetPlain boolean");
   216             boolean x = UNSAFE.getBoolean(base, offset);
   216             boolean x = UNSAFE.getBoolean(base, offset);
   217             assertEquals(x, false, "weakCompareAndSwap boolean value");
   217             assertEquals(x, false, "weakCompareAndSetPlain boolean value");
   218         }
   218         }
   219 
   219 
   220         {
   220         {
   221             boolean success = false;
   221             boolean success = false;
   222             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   222             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   223                 success = UNSAFE.weakCompareAndSwapBooleanAcquire(base, offset, false, true);
   223                 success = UNSAFE.weakCompareAndSetBooleanAcquire(base, offset, false, true);
   224             }
   224             }
   225             assertEquals(success, true, "weakCompareAndSwapAcquire boolean");
   225             assertEquals(success, true, "weakCompareAndSetAcquire boolean");
   226             boolean x = UNSAFE.getBoolean(base, offset);
   226             boolean x = UNSAFE.getBoolean(base, offset);
   227             assertEquals(x, true, "weakCompareAndSwapAcquire boolean");
   227             assertEquals(x, true, "weakCompareAndSetAcquire boolean");
   228         }
   228         }
   229 
   229 
   230         {
   230         {
   231             boolean success = false;
   231             boolean success = false;
   232             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   232             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   233                 success = UNSAFE.weakCompareAndSwapBooleanRelease(base, offset, true, false);
   233                 success = UNSAFE.weakCompareAndSetBooleanRelease(base, offset, true, false);
   234             }
   234             }
   235             assertEquals(success, true, "weakCompareAndSwapRelease boolean");
   235             assertEquals(success, true, "weakCompareAndSetRelease boolean");
   236             boolean x = UNSAFE.getBoolean(base, offset);
   236             boolean x = UNSAFE.getBoolean(base, offset);
   237             assertEquals(x, false, "weakCompareAndSwapRelease boolean");
   237             assertEquals(x, false, "weakCompareAndSetRelease boolean");
   238         }
   238         }
   239 
   239 
   240         {
   240         {
   241             boolean success = false;
   241             boolean success = false;
   242             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   242             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
   243                 success = UNSAFE.weakCompareAndSwapBooleanVolatile(base, offset, false, true);
   243                 success = UNSAFE.weakCompareAndSetBoolean(base, offset, false, true);
   244             }
   244             }
   245             assertEquals(success, true, "weakCompareAndSwapVolatile boolean");
   245             assertEquals(success, true, "weakCompareAndSet boolean");
   246             boolean x = UNSAFE.getBoolean(base, offset);
   246             boolean x = UNSAFE.getBoolean(base, offset);
   247             assertEquals(x, true, "weakCompareAndSwapVolatile boolean");
   247             assertEquals(x, true, "weakCompareAndSet boolean");
   248         }
   248         }
   249 
   249 
   250         UNSAFE.putBoolean(base, offset, false);
   250         UNSAFE.putBoolean(base, offset, false);
   251 
   251 
   252         // Compare set and get
   252         // Compare set and get
   258         }
   258         }
   259 
   259 
   260     }
   260     }
   261 
   261 
   262 }
   262 }
   263