Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 public class Main {
     18   static volatile long long_volatile;
     19   static volatile double double_volatile;
     20 
     21   public static void main(String[] args) {
     22     checkVolatileUpdate(0L);
     23     checkVolatileUpdate(Long.MAX_VALUE);
     24     checkVolatileUpdate(Long.MIN_VALUE);
     25 
     26     checkVolatileUpdate(0.0);
     27     checkVolatileUpdate(Double.MAX_VALUE);
     28     checkVolatileUpdate(-Double.MAX_VALUE);
     29   }
     30 
     31   public static long $opt$update(long a) {
     32      long_volatile = a;
     33      return long_volatile;
     34   }
     35 
     36   public static double $opt$update(double a) {
     37      double_volatile = a;
     38      return double_volatile;
     39   }
     40 
     41   public static void checkVolatileUpdate(long value) {
     42     if (value != $opt$update(value)) {
     43       throw new RuntimeException("Volatile update failed for long:" + value);
     44     }
     45   }
     46 
     47   public static void checkVolatileUpdate(double value) {
     48     if (value != $opt$update(value)) {
     49       throw new RuntimeException("Volatile update failed for double:" + value);
     50     }
     51   }
     52 
     53 }
     54