• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 import java.lang.invoke.VarHandle;
18 
19 /**
20  * Checker test on the 1.8 unsafe operations. Note, this is by no means an
21  * exhaustive unit test for these CAS (compare-and-swap) and fence operations.
22  * Instead, this test ensures the methods are recognized as intrinsic and behave
23  * as expected.
24  */
25 public class Main {
26 
27   //
28   // Fences (native).
29   //
30 
31   /// CHECK-START: void Main.fullFence() builder (after)
32   /// CHECK-DAG: InvokeStaticOrDirect intrinsic:VarHandleFullFence
33   //
34   /// CHECK-START: void Main.fullFence() instruction_simplifier (after)
35   /// CHECK-NOT: InvokeStaticOrDirect intrinsic:VarHandleFullFence
36   //
37   /// CHECK-START: void Main.fullFence() instruction_simplifier (after)
38   /// CHECK-DAG: MemoryBarrier kind:AnyAny
fullFence()39   private static void fullFence() {
40       VarHandle.fullFence();
41   }
42 
43   /// CHECK-START: void Main.acquireFence() builder (after)
44   /// CHECK-DAG: InvokeStaticOrDirect intrinsic:VarHandleAcquireFence
45   //
46   /// CHECK-START: void Main.acquireFence() instruction_simplifier (after)
47   /// CHECK-NOT: InvokeStaticOrDirect intrinsic:VarHandleAcquireFence
48   //
49   /// CHECK-START: void Main.acquireFence() instruction_simplifier (after)
50   /// CHECK-DAG: MemoryBarrier kind:LoadAny
acquireFence()51   private static void acquireFence() {
52       VarHandle.acquireFence();
53   }
54 
55   /// CHECK-START: void Main.releaseFence() builder (after)
56   /// CHECK-DAG: InvokeStaticOrDirect intrinsic:VarHandleReleaseFence
57   //
58   /// CHECK-START: void Main.releaseFence() instruction_simplifier (after)
59   /// CHECK-NOT: InvokeStaticOrDirect intrinsic:VarHandleReleaseFence
60   //
61   /// CHECK-START: void Main.releaseFence() instruction_simplifier (after)
62   /// CHECK-DAG: MemoryBarrier kind:AnyStore
releaseFence()63   private static void releaseFence() {
64       VarHandle.releaseFence();
65   }
66 
67   /// CHECK-START: void Main.loadLoadFence() builder (after)
68   /// CHECK-DAG: InvokeStaticOrDirect intrinsic:VarHandleLoadLoadFence
69   //
70   /// CHECK-START: void Main.loadLoadFence() instruction_simplifier (after)
71   /// CHECK-NOT: InvokeStaticOrDirect intrinsic:VarHandleLoadLoadFence
72   //
73   /// CHECK-START: void Main.loadLoadFence() instruction_simplifier (after)
74   /// CHECK-DAG: MemoryBarrier kind:LoadAny
loadLoadFence()75   private static void loadLoadFence() {
76       VarHandle.loadLoadFence();
77   }
78 
79   /// CHECK-START: void Main.storeStoreFence() builder (after)
80   /// CHECK-DAG: InvokeStaticOrDirect intrinsic:VarHandleStoreStoreFence
81   //
82   /// CHECK-START: void Main.storeStoreFence() instruction_simplifier (after)
83   /// CHECK-NOT: InvokeStaticOrDirect intrinsic:VarHandleStoreStoreFence
84   //
85   /// CHECK-START: void Main.storeStoreFence() instruction_simplifier (after)
86   /// CHECK-DAG: MemoryBarrier kind:StoreStore
storeStoreFence()87   private static void storeStoreFence() {
88       VarHandle.storeStoreFence();
89   }
90 
91   //
92   // Driver.
93   //
94 
main(String[] args)95   public static void main(String[] args) {
96     System.out.println("starting");
97     acquireFence();
98     releaseFence();
99     loadLoadFence();
100     storeStoreFence();
101     fullFence();
102     System.out.println("passed");
103   }
104 }
105