blob: 9a04f1f9cafa5e22bd058a9a3d04bf30ac323b16 [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
Calin Juravle98893e12015-10-02 21:05:03 +0100117 static public void testInstanceOf(Object o) {
118 if (o instanceof UnresolvedSuperClass) {
119 System.out.println("instanceof ok");
120 }
121 }
122
123 static public UnresolvedSuperClass testCheckCast(Object o) {
124 UnresolvedSuperClass c = (UnresolvedSuperClass) o;
125 System.out.println("checkcast ok");
126 return c;
127 }
Calin Juravle175dc732015-08-25 15:42:32 +0100128 /// CHECK-START: void Main.main(java.lang.String[]) register (before)
129 /// CHECK: InvokeUnresolved invoke_type:direct
130 static public void main(String[] args) {
131 UnresolvedClass c = new UnresolvedClass();
Calin Juravle98893e12015-10-02 21:05:03 +0100132 Main m = new Main();
Calin Juravle175dc732015-08-25 15:42:32 +0100133 callInvokeUnresolvedStatic();
134 callInvokeUnresolvedVirtual(c);
135 callInvokeUnresolvedInterface(c);
Calin Juravle98893e12015-10-02 21:05:03 +0100136 callInvokeUnresolvedSuper(m);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100137 callUnresolvedStaticFieldAccess();
138 callUnresolvedInstanceFieldAccess(c);
Calin Juravle98893e12015-10-02 21:05:03 +0100139 testInstanceOf(m);
140 testCheckCast(m);
Nicolas Geoffray0580d962016-01-06 17:40:20 +0000141 testLicm(2);
142 }
143
144 /// CHECK-START: void Main.testLicm(int) licm (before)
145 /// CHECK: <<Class:l\d+>> LoadClass loop:B2
146 /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:B2
147 /// CHECK-NEXT: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:i\d+>>] loop:B2
148 /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2
149
150 /// CHECK-START: void Main.testLicm(int) licm (after)
151 /// CHECK: <<Class:l\d+>> LoadClass loop:none
152 /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:none
153 /// CHECK: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:i\d+>>] loop:B2
154 /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2
155 static public void testLicm(int count) {
156 // Test to make sure we keep the initialization check after loading an unresolved class.
157 UnresolvedClass c;
158 int i = 0;
159 do {
160 c = new UnresolvedClass();
161 } while (i++ != count);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100162 }
163
164 public static void expectEquals(byte expected, byte result) {
165 if (expected != result) {
166 throw new Error("Expected: " + expected + ", found: " + result);
167 }
168 }
169
170 public static void expectEquals(char expected, char result) {
171 if (expected != result) {
172 throw new Error("Expected: " + expected + ", found: " + result);
173 }
174 }
175
176 public static void expectEquals(int expected, int result) {
177 if (expected != result) {
178 throw new Error("Expected: " + expected + ", found: " + result);
179 }
180 }
181
182 public static void expectEquals(long expected, long result) {
183 if (expected != result) {
184 throw new Error("Expected: " + expected + ", found: " + result);
185 }
186 }
187
188 public static void expectEquals(float expected, float result) {
189 if (expected != result) {
190 throw new Error("Expected: " + expected + ", found: " + result);
191 }
192 }
193
194 public static void expectEquals(double expected, double result) {
195 if (expected != result) {
196 throw new Error("Expected: " + expected + ", found: " + result);
197 }
198 }
199
200 public static void expectEquals(Object expected, Object result) {
201 if (expected != result) {
202 throw new Error("Expected: " + expected + ", found: " + result);
203 }
Calin Juravle175dc732015-08-25 15:42:32 +0100204 }
205}