blob: a934377ddf280c2b8568d464eec4aca7817ec7a5 [file] [log] [blame]
Calin Juravle175dc732015-08-25 15:42:32 +01001/*
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
17public class Main extends UnresolvedSuperClass {
18
19 /// CHECK-START: void Main.callInvokeUnresolvedStatic() register (before)
20 /// CHECK: InvokeUnresolved invoke_type:static
21 static public void callInvokeUnresolvedStatic() {
22 UnresolvedClass.staticMethod();
23 }
24
25 /// CHECK-START: void Main.callInvokeUnresolvedVirtual(UnresolvedClass) register (before)
26 /// CHECK: InvokeUnresolved invoke_type:virtual
27 static public void callInvokeUnresolvedVirtual(UnresolvedClass c) {
28 c.virtualMethod();
29 }
30
31 /// CHECK-START: void Main.callInvokeUnresolvedInterface(UnresolvedInterface) register (before)
32 /// CHECK: InvokeUnresolved invoke_type:interface
33 static public void callInvokeUnresolvedInterface(UnresolvedInterface c) {
34 c.interfaceMethod();
35 }
36
37 static public void callInvokeUnresolvedSuper(Main c) {
38 c.superMethod();
39 }
40
41 /// CHECK-START: void Main.superMethod() register (before)
42 /// CHECK: InvokeUnresolved invoke_type:super
43 public void superMethod() {
44 super.superMethod();
45 }
46
Calin Juravlee460d1d2015-09-29 04:52:17 +010047 /// CHECK-START: void Main.callUnresolvedStaticFieldAccess() register (before)
48 /// CHECK: UnresolvedStaticFieldSet field_type:PrimByte
49 /// CHECK: UnresolvedStaticFieldSet field_type:PrimChar
50 /// CHECK: UnresolvedStaticFieldSet field_type:PrimInt
51 /// CHECK: UnresolvedStaticFieldSet field_type:PrimLong
52 /// CHECK: UnresolvedStaticFieldSet field_type:PrimFloat
53 /// CHECK: UnresolvedStaticFieldSet field_type:PrimDouble
54 /// CHECK: UnresolvedStaticFieldSet field_type:PrimNot
55
56 /// CHECK: UnresolvedStaticFieldGet field_type:PrimByte
57 /// CHECK: UnresolvedStaticFieldGet field_type:PrimChar
58 /// CHECK: UnresolvedStaticFieldGet field_type:PrimInt
59 /// CHECK: UnresolvedStaticFieldGet field_type:PrimLong
60 /// CHECK: UnresolvedStaticFieldGet field_type:PrimFloat
61 /// CHECK: UnresolvedStaticFieldGet field_type:PrimDouble
62 /// CHECK: UnresolvedStaticFieldGet field_type:PrimNot
63 static public void callUnresolvedStaticFieldAccess() {
64 Object o = new Object();
65 UnresolvedClass.staticByte = (byte)1;
66 UnresolvedClass.staticChar = '1';
67 UnresolvedClass.staticInt = 123456789;
68 UnresolvedClass.staticLong = 123456789123456789l;
69 UnresolvedClass.staticFloat = 123456789123456789f;
70 UnresolvedClass.staticDouble = 123456789123456789d;
71 UnresolvedClass.staticObject = o;
72
73 expectEquals((byte)1, UnresolvedClass.staticByte);
74 expectEquals('1', UnresolvedClass.staticChar);
75 expectEquals(123456789, UnresolvedClass.staticInt);
76 expectEquals(123456789123456789l, UnresolvedClass.staticLong);
77 expectEquals(123456789123456789f, UnresolvedClass.staticFloat);
78 expectEquals(123456789123456789d, UnresolvedClass.staticDouble);
79 expectEquals(o, UnresolvedClass.staticObject);
80 }
81
82 /// CHECK-START: void Main.callUnresolvedInstanceFieldAccess(UnresolvedClass) register (before)
83 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimByte
84 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimChar
85 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimInt
86 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimLong
87 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimFloat
88 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimDouble
89 /// CHECK: UnresolvedInstanceFieldSet field_type:PrimNot
90
91 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimByte
92 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimChar
93 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimInt
94 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimLong
95 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimFloat
96 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimDouble
97 /// CHECK: UnresolvedInstanceFieldGet field_type:PrimNot
98 static public void callUnresolvedInstanceFieldAccess(UnresolvedClass c) {
99 Object o = new Object();
100 c.instanceByte = (byte)1;
101 c.instanceChar = '1';
102 c.instanceInt = 123456789;
103 c.instanceLong = 123456789123456789l;
104 c.instanceFloat = 123456789123456789f;
105 c.instanceDouble = 123456789123456789d;
106 c.instanceObject = o;
107
108 expectEquals((byte)1, c.instanceByte);
109 expectEquals('1', c.instanceChar);
110 expectEquals(123456789, c.instanceInt);
111 expectEquals(123456789123456789l, c.instanceLong);
112 expectEquals(123456789123456789f, c.instanceFloat);
113 expectEquals(123456789123456789d, c.instanceDouble);
114 expectEquals(o, c.instanceObject);
115 }
116
Aart Bik14154132016-06-02 17:53:58 -0700117 static public void callUnresolvedNull(UnresolvedClass c) {
118 int x = 0;
119 try {
120 x = c.instanceInt;
121 throw new Error("Expected NPE");
122 } catch (NullPointerException e) {
123 }
124 expectEquals(0, x);
125 try {
126 c.instanceInt = -1;
127 throw new Error("Expected NPE");
128 } catch (NullPointerException e) {
129 }
130 }
131
Calin Juravle98893e12015-10-02 21:05:03 +0100132 static public void testInstanceOf(Object o) {
133 if (o instanceof UnresolvedSuperClass) {
134 System.out.println("instanceof ok");
135 }
136 }
137
138 static public UnresolvedSuperClass testCheckCast(Object o) {
139 UnresolvedSuperClass c = (UnresolvedSuperClass) o;
140 System.out.println("checkcast ok");
141 return c;
142 }
Calin Juravle175dc732015-08-25 15:42:32 +0100143 /// CHECK-START: void Main.main(java.lang.String[]) register (before)
144 /// CHECK: InvokeUnresolved invoke_type:direct
145 static public void main(String[] args) {
146 UnresolvedClass c = new UnresolvedClass();
Calin Juravle98893e12015-10-02 21:05:03 +0100147 Main m = new Main();
Calin Juravle175dc732015-08-25 15:42:32 +0100148 callInvokeUnresolvedStatic();
149 callInvokeUnresolvedVirtual(c);
150 callInvokeUnresolvedInterface(c);
Calin Juravle98893e12015-10-02 21:05:03 +0100151 callInvokeUnresolvedSuper(m);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100152 callUnresolvedStaticFieldAccess();
153 callUnresolvedInstanceFieldAccess(c);
Aart Bik14154132016-06-02 17:53:58 -0700154 callUnresolvedNull(null);
Calin Juravle98893e12015-10-02 21:05:03 +0100155 testInstanceOf(m);
156 testCheckCast(m);
Nicolas Geoffray0580d962016-01-06 17:40:20 +0000157 testLicm(2);
158 }
159
160 /// CHECK-START: void Main.testLicm(int) licm (before)
Nicolas Geoffray0243a742016-01-07 14:53:08 +0000161 /// CHECK: <<Class:l\d+>> LoadClass loop:B2
162 /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:B2
163 /// CHECK-NEXT: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:[i|j]\d+>>] loop:B2
164 /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2
Nicolas Geoffray0580d962016-01-06 17:40:20 +0000165
Nicolas Geoffray0243a742016-01-07 14:53:08 +0000166 /// CHECK-START: void Main.testLicm(int) licm (after)
167 /// CHECK: <<Class:l\d+>> LoadClass loop:none
168 /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:none
169 /// CHECK: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:[i|j]\d+>>] loop:B2
170 /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2
Nicolas Geoffray0580d962016-01-06 17:40:20 +0000171 static public void testLicm(int count) {
172 // Test to make sure we keep the initialization check after loading an unresolved class.
173 UnresolvedClass c;
174 int i = 0;
175 do {
176 c = new UnresolvedClass();
177 } while (i++ != count);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100178 }
179
180 public static void expectEquals(byte expected, byte result) {
181 if (expected != result) {
182 throw new Error("Expected: " + expected + ", found: " + result);
183 }
184 }
185
186 public static void expectEquals(char expected, char result) {
187 if (expected != result) {
188 throw new Error("Expected: " + expected + ", found: " + result);
189 }
190 }
191
192 public static void expectEquals(int expected, int result) {
193 if (expected != result) {
194 throw new Error("Expected: " + expected + ", found: " + result);
195 }
196 }
197
198 public static void expectEquals(long expected, long result) {
199 if (expected != result) {
200 throw new Error("Expected: " + expected + ", found: " + result);
201 }
202 }
203
Aart Bik14154132016-06-02 17:53:58 -0700204 public static void expectEquals(float expected, float result) {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100205 if (expected != result) {
206 throw new Error("Expected: " + expected + ", found: " + result);
207 }
208 }
209
210 public static void expectEquals(double expected, double result) {
211 if (expected != result) {
212 throw new Error("Expected: " + expected + ", found: " + result);
213 }
214 }
215
216 public static void expectEquals(Object expected, Object result) {
217 if (expected != result) {
218 throw new Error("Expected: " + expected + ", found: " + result);
219 }
Calin Juravle175dc732015-08-25 15:42:32 +0100220 }
221}