blob: 9c77acc4d120d37e5be6c2c9f1f86327f71929c2 [file] [log] [blame]
Nicolas Geoffraya0466e12015-03-27 15:00:40 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * 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 */
Nicolas Geoffraya0466e12015-03-27 15:00:40 +000016
17class OtherClass {
18 static {
19 a = 42;
20 b = 54;
21 }
22
23 static int a;
24 static int b;
25}
26
27public final class Main {
28
David Brazdila06d66a2015-05-28 11:14:54 +010029 /// CHECK-START: int Main.accessTwoStatics() GVN (before)
30 /// CHECK-DAG: <<Class1:l\d+>> LoadClass
31 /// CHECK-DAG: ClinitCheck [<<Class1>>]
32 /// CHECK-DAG: <<Class2:l\d+>> LoadClass
33 /// CHECK-DAG: ClinitCheck [<<Class2>>]
Nicolas Geoffraya0466e12015-03-27 15:00:40 +000034
David Brazdila06d66a2015-05-28 11:14:54 +010035 /// CHECK-START: int Main.accessTwoStatics() GVN (after)
36 /// CHECK-DAG: <<Class:l\d+>> LoadClass
37 /// CHECK-DAG: ClinitCheck [<<Class>>]
38 /// CHECK-NOT: ClinitCheck
Nicolas Geoffraya0466e12015-03-27 15:00:40 +000039
40 public static int accessTwoStatics() {
41 return OtherClass.b - OtherClass.a;
42 }
43
David Brazdila06d66a2015-05-28 11:14:54 +010044 /// CHECK-START: int Main.accessTwoStaticsCallInBetween() GVN (before)
45 /// CHECK-DAG: <<Class1:l\d+>> LoadClass
46 /// CHECK-DAG: ClinitCheck [<<Class1>>]
47 /// CHECK-DAG: <<Class2:l\d+>> LoadClass
48 /// CHECK-DAG: ClinitCheck [<<Class2>>]
Nicolas Geoffraya0466e12015-03-27 15:00:40 +000049
David Brazdila06d66a2015-05-28 11:14:54 +010050 /// CHECK-START: int Main.accessTwoStaticsCallInBetween() GVN (after)
51 /// CHECK-DAG: <<Class:l\d+>> LoadClass
52 /// CHECK-DAG: ClinitCheck [<<Class>>]
53 /// CHECK-NOT: ClinitCheck
Nicolas Geoffraya0466e12015-03-27 15:00:40 +000054
55 public static int accessTwoStaticsCallInBetween() {
56 int b = OtherClass.b;
57 foo();
58 return b - OtherClass.a;
59 }
60
61 public static void foo() {
62 try {
63 Thread.sleep(0);
64 } catch (Exception e) {
65 throw new Error(e);
66 }
67 }
68
69 public static void main(String[] args) {
70 if (accessTwoStatics() != 12) {
71 throw new Error("Expected 12");
72 }
73
74 if (accessTwoStaticsCallInBetween() != 12) {
75 throw new Error("Expected 12");
76 }
77 }
78}