Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 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 | public 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 Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 47 | /// 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 Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 117 | /// CHECK-START: void Main.callUnresolvedNull(UnresolvedClass) register (before) |
| 118 | /// CHECK-NOT: NullCheck |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 119 | static public void callUnresolvedNull(UnresolvedClass c) { |
| 120 | int x = 0; |
| 121 | try { |
| 122 | x = c.instanceInt; |
| 123 | throw new Error("Expected NPE"); |
| 124 | } catch (NullPointerException e) { |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 125 | x -= 1; |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 126 | } |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 127 | expectEquals(-1, x); |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 128 | try { |
| 129 | c.instanceInt = -1; |
| 130 | throw new Error("Expected NPE"); |
| 131 | } catch (NullPointerException e) { |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 132 | x -= 1; |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 133 | } |
Aart Bik | 296fbb4 | 2016-06-07 13:49:12 -0700 | [diff] [blame] | 134 | expectEquals(-2, x); |
| 135 | try { |
| 136 | c.virtualMethod(); |
| 137 | throw new Error("Expected NPE"); |
| 138 | } catch (NullPointerException e) { |
| 139 | x -= 1; |
| 140 | } |
| 141 | expectEquals(-3, x); |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 144 | static public void testInstanceOf(Object o) { |
| 145 | if (o instanceof UnresolvedSuperClass) { |
| 146 | System.out.println("instanceof ok"); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static public UnresolvedSuperClass testCheckCast(Object o) { |
| 151 | UnresolvedSuperClass c = (UnresolvedSuperClass) o; |
| 152 | System.out.println("checkcast ok"); |
| 153 | return c; |
| 154 | } |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 155 | /// CHECK-START: void Main.main(java.lang.String[]) register (before) |
| 156 | /// CHECK: InvokeUnresolved invoke_type:direct |
| 157 | static public void main(String[] args) { |
| 158 | UnresolvedClass c = new UnresolvedClass(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 159 | Main m = new Main(); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 160 | callInvokeUnresolvedStatic(); |
| 161 | callInvokeUnresolvedVirtual(c); |
| 162 | callInvokeUnresolvedInterface(c); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 163 | callInvokeUnresolvedSuper(m); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 164 | callUnresolvedStaticFieldAccess(); |
| 165 | callUnresolvedInstanceFieldAccess(c); |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 166 | callUnresolvedNull(null); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 167 | testInstanceOf(m); |
| 168 | testCheckCast(m); |
Nicolas Geoffray | 0580d96 | 2016-01-06 17:40:20 +0000 | [diff] [blame] | 169 | testLicm(2); |
| 170 | } |
| 171 | |
| 172 | /// CHECK-START: void Main.testLicm(int) licm (before) |
Nicolas Geoffray | 0243a74 | 2016-01-07 14:53:08 +0000 | [diff] [blame] | 173 | /// CHECK: <<Class:l\d+>> LoadClass loop:B2 |
| 174 | /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:B2 |
| 175 | /// CHECK-NEXT: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:[i|j]\d+>>] loop:B2 |
| 176 | /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2 |
Nicolas Geoffray | 0580d96 | 2016-01-06 17:40:20 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | 0243a74 | 2016-01-07 14:53:08 +0000 | [diff] [blame] | 178 | /// CHECK-START: void Main.testLicm(int) licm (after) |
| 179 | /// CHECK: <<Class:l\d+>> LoadClass loop:none |
| 180 | /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:none |
| 181 | /// CHECK: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:[i|j]\d+>>] loop:B2 |
| 182 | /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2 |
Nicolas Geoffray | 0580d96 | 2016-01-06 17:40:20 +0000 | [diff] [blame] | 183 | static public void testLicm(int count) { |
| 184 | // Test to make sure we keep the initialization check after loading an unresolved class. |
| 185 | UnresolvedClass c; |
| 186 | int i = 0; |
| 187 | do { |
| 188 | c = new UnresolvedClass(); |
| 189 | } while (i++ != count); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | public static void expectEquals(byte expected, byte result) { |
| 193 | if (expected != result) { |
| 194 | throw new Error("Expected: " + expected + ", found: " + result); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | public static void expectEquals(char expected, char result) { |
| 199 | if (expected != result) { |
| 200 | throw new Error("Expected: " + expected + ", found: " + result); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | public static void expectEquals(int expected, int result) { |
| 205 | if (expected != result) { |
| 206 | throw new Error("Expected: " + expected + ", found: " + result); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | public static void expectEquals(long expected, long result) { |
| 211 | if (expected != result) { |
| 212 | throw new Error("Expected: " + expected + ", found: " + result); |
| 213 | } |
| 214 | } |
| 215 | |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 216 | public static void expectEquals(float expected, float result) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 217 | if (expected != result) { |
| 218 | throw new Error("Expected: " + expected + ", found: " + result); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | public static void expectEquals(double expected, double result) { |
| 223 | if (expected != result) { |
| 224 | throw new Error("Expected: " + expected + ", found: " + result); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | public static void expectEquals(Object expected, Object result) { |
| 229 | if (expected != result) { |
| 230 | throw new Error("Expected: " + expected + ", found: " + result); |
| 231 | } |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 232 | } |
| 233 | } |