• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2015 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 
18 class ClassWithoutFinals {
19   // CHECK-START: void ClassWithoutFinals.<init>() register (after)
20   // CHECK-NOT: MemoryBarrier {{StoreStore}}
ClassWithoutFinals()21   public ClassWithoutFinals() {}
22 }
23 
24 class ClassWithFinals {
25   public final int x;
26   public ClassWithFinals obj;
27 
28   // CHECK-START: void ClassWithFinals.<init>(boolean) register (after)
29   // CHECK:     MemoryBarrier {{StoreStore}}
30   // CHECK-NOT: {{.*}}
31   // CHECK:     ReturnVoid
ClassWithFinals(boolean cond)32   public ClassWithFinals(boolean cond) {
33     x = 0;
34     if (cond) {
35       // avoid inlining
36       throw new RuntimeException();
37     }
38   }
39 
40   // CHECK-START: void ClassWithFinals.<init>() register (after)
41   // CHECK:     MemoryBarrier {{StoreStore}}
42   // CHECK-NOT: {{.*}}
43   // CHECK:     ReturnVoid
ClassWithFinals()44   public ClassWithFinals() {
45     x = 0;
46   }
47 
48   // CHECK-START: void ClassWithFinals.<init>(int) register (after)
49   // CHECK:     MemoryBarrier {{StoreStore}}
50   // CHECK:     MemoryBarrier {{StoreStore}}
51   // CHECK-NOT: {{.*}}
52   // CHECK:     ReturnVoid
ClassWithFinals(int x)53   public ClassWithFinals(int x) {
54     // This should have two barriers:
55     //   - one for the constructor
56     //   - one for the `new` which should be inlined.
57     obj = new ClassWithFinals();
58     this.x = x;
59   }
60 }
61 
62 class InheritFromClassWithFinals extends ClassWithFinals {
63   // CHECK-START: void InheritFromClassWithFinals.<init>() register (after)
64   // CHECK:     MemoryBarrier {{StoreStore}}
65   // CHECK-NOT: {{.*}}
66   // CHECK:     ReturnVoid
67 
68   // CHECK-START: void InheritFromClassWithFinals.<init>() register (after)
69   // CHECK-NOT: InvokeStaticOrDirect
InheritFromClassWithFinals()70   public InheritFromClassWithFinals() {
71     // Should inline the super constructor.
72   }
73 
74   // CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after)
75   // CHECK:     InvokeStaticOrDirect
76 
77   // CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after)
78   // CHECK-NOT: MemoryBarrier {{StoreStore}}
InheritFromClassWithFinals(boolean cond)79   public InheritFromClassWithFinals(boolean cond) {
80     super(cond);
81     // should not inline the super constructor
82   }
83 }
84 
85 class HaveFinalsAndInheritFromClassWithFinals extends ClassWithFinals {
86   final int y;
87 
88   // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after)
89   // CHECK:     MemoryBarrier {{StoreStore}}
90   // CHECK:     MemoryBarrier {{StoreStore}}
91   // CHECK-NOT: {{.*}}
92   // CHECK:     ReturnVoid
93 
94   // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after)
95   // CHECK-NOT: InvokeStaticOrDirect
HaveFinalsAndInheritFromClassWithFinals()96   public HaveFinalsAndInheritFromClassWithFinals() {
97     // Should inline the super constructor.
98     y = 0;
99   }
100 
101   // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(boolean) register (after)
102   // CHECK:     InvokeStaticOrDirect
103   // CHECK:     MemoryBarrier {{StoreStore}}
104   // CHECK-NOT: {{.*}}
105   // CHECK:     ReturnVoid
HaveFinalsAndInheritFromClassWithFinals(boolean cond)106   public HaveFinalsAndInheritFromClassWithFinals(boolean cond) {
107     super(cond);
108     // should not inline the super constructor
109     y = 0;
110   }
111 }
112 
113 public class Main {
114 
115   // CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after)
116   // CHECK:     InvokeStaticOrDirect
117 
118   // CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after)
119   // CHECK-NOT: MemoryBarrier {{StoreStore}}
noInlineNoConstructorBarrier()120   public static ClassWithFinals noInlineNoConstructorBarrier() {
121     return new ClassWithFinals(false);
122   }
123 
124   // CHECK-START: ClassWithFinals Main.inlineConstructorBarrier() register (after)
125   // CHECK:     MemoryBarrier {{StoreStore}}
126   // CHECK-NOT: {{.*}}
127   // CHECK:     Return
128 
129   // CHECK-START: ClassWithFinals Main.inlineConstructorBarrier() register (after)
130   // CHECK-NOT: InvokeStaticOrDirect
inlineConstructorBarrier()131   public static ClassWithFinals inlineConstructorBarrier() {
132     return new ClassWithFinals();
133   }
134 
135   // CHECK-START: InheritFromClassWithFinals Main.doubleInlineConstructorBarrier() register (after)
136   // CHECK:     MemoryBarrier {{StoreStore}}
137   // CHECK-NOT: {{.*}}
138   // CHECK:     Return
139 
140   // CHECK-START: InheritFromClassWithFinals Main.doubleInlineConstructorBarrier() register (after)
141   // CHECK-NOT: InvokeStaticOrDirect
doubleInlineConstructorBarrier()142   public static InheritFromClassWithFinals doubleInlineConstructorBarrier() {
143     return new InheritFromClassWithFinals();
144   }
145 
main(String[] args)146   public static void main(String[] args) {  }
147 }
148