lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
public class Main extends UnresolvedSuperClass {
 
  /// CHECK-START: void Main.callInvokeUnresolvedStatic() register (before)
  /// CHECK:        InvokeUnresolved invoke_type:static
  static public void callInvokeUnresolvedStatic() {
    UnresolvedClass.staticMethod();
  }
 
  /// CHECK-START: void Main.callInvokeUnresolvedVirtual(UnresolvedClass) register (before)
  /// CHECK:        InvokeUnresolved invoke_type:virtual
  static public void callInvokeUnresolvedVirtual(UnresolvedClass c) {
    c.virtualMethod();
  }
 
  /// CHECK-START: void Main.callInvokeUnresolvedInterface(UnresolvedInterface) register (before)
  /// CHECK:        InvokeUnresolved invoke_type:interface
  static public void callInvokeUnresolvedInterface(UnresolvedInterface c) {
    c.interfaceMethod();
  }
 
  static public void callInvokeUnresolvedSuper(Main c) {
    c.superMethod();
  }
 
  /// CHECK-START: void Main.superMethod() register (before)
  /// CHECK:        InvokeUnresolved invoke_type:super
  public void superMethod() {
    super.superMethod();
  }
 
  /// CHECK-START: void Main.callUnresolvedStaticFieldAccess() register (before)
  /// CHECK:        UnresolvedStaticFieldSet field_type:Int8
  /// CHECK:        UnresolvedStaticFieldSet field_type:Uint16
  /// CHECK:        UnresolvedStaticFieldSet field_type:Int32
  /// CHECK:        UnresolvedStaticFieldSet field_type:Int64
  /// CHECK:        UnresolvedStaticFieldSet field_type:Float32
  /// CHECK:        UnresolvedStaticFieldSet field_type:Float64
  /// CHECK:        UnresolvedStaticFieldSet field_type:Reference
 
  /// CHECK:        UnresolvedStaticFieldGet field_type:Int8
  /// CHECK:        UnresolvedStaticFieldGet field_type:Uint16
  /// CHECK:        UnresolvedStaticFieldGet field_type:Int32
  /// CHECK:        UnresolvedStaticFieldGet field_type:Int64
  /// CHECK:        UnresolvedStaticFieldGet field_type:Float32
  /// CHECK:        UnresolvedStaticFieldGet field_type:Float64
  /// CHECK:        UnresolvedStaticFieldGet field_type:Reference
  static public void callUnresolvedStaticFieldAccess() {
    Object o = new Object();
    UnresolvedClass.staticByte = (byte)1;
    UnresolvedClass.staticChar = '1';
    UnresolvedClass.staticInt = 123456789;
    UnresolvedClass.staticLong = 123456789123456789l;
    UnresolvedClass.staticFloat = 123456789123456789f;
    UnresolvedClass.staticDouble = 123456789123456789d;
    UnresolvedClass.staticObject = o;
 
    expectEquals((byte)1, UnresolvedClass.staticByte);
    expectEquals('1', UnresolvedClass.staticChar);
    expectEquals(123456789, UnresolvedClass.staticInt);
    expectEquals(123456789123456789l, UnresolvedClass.staticLong);
    expectEquals(123456789123456789f, UnresolvedClass.staticFloat);
    expectEquals(123456789123456789d, UnresolvedClass.staticDouble);
    expectEquals(o, UnresolvedClass.staticObject);
 
    // Check "large" values.
 
    UnresolvedClass.staticByte = (byte)-1;
    UnresolvedClass.staticChar = (char)32768;
    UnresolvedClass.staticInt = -1;
 
    expectEquals((byte)-1, UnresolvedClass.staticByte);
    expectEquals((char)32768, UnresolvedClass.staticChar);
    expectEquals(-1, UnresolvedClass.staticInt);
  }
 
  /// CHECK-START: void Main.callUnresolvedInstanceFieldAccess(UnresolvedClass) register (before)
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Int8
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Uint16
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Int32
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Int64
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Float32
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Float64
  /// CHECK:        UnresolvedInstanceFieldSet field_type:Reference
 
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Int8
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Uint16
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Int32
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Int64
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Float32
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Float64
  /// CHECK:        UnresolvedInstanceFieldGet field_type:Reference
  static public void callUnresolvedInstanceFieldAccess(UnresolvedClass c) {
    Object o = new Object();
    c.instanceByte = (byte)1;
    c.instanceChar = '1';
    c.instanceInt = 123456789;
    c.instanceLong = 123456789123456789l;
    c.instanceFloat = 123456789123456789f;
    c.instanceDouble = 123456789123456789d;
    c.instanceObject = o;
 
    expectEquals((byte)1, c.instanceByte);
    expectEquals('1', c.instanceChar);
    expectEquals(123456789, c.instanceInt);
    expectEquals(123456789123456789l, c.instanceLong);
    expectEquals(123456789123456789f, c.instanceFloat);
    expectEquals(123456789123456789d, c.instanceDouble);
    expectEquals(o, c.instanceObject);
 
    // Check "large" values.
 
    c.instanceByte = (byte)-1;
    c.instanceChar = (char)32768;
    c.instanceInt = -1;
 
    expectEquals((byte)-1, c.instanceByte);
    expectEquals((char)32768, c.instanceChar);
    expectEquals(-1, c.instanceInt);
  }
 
  /// CHECK-START: void Main.callUnresolvedNull(UnresolvedClass) register (before)
  /// CHECK-NOT: NullCheck
  static public void callUnresolvedNull(UnresolvedClass c) {
    int x = 0;
    try {
      x = c.instanceInt;
      throw new Error("Expected NPE");
    } catch (NullPointerException e) {
      x -= 1;
    }
    expectEquals(-1, x);
    try {
      c.instanceInt = -1;
      throw new Error("Expected NPE");
    } catch (NullPointerException e) {
      x -= 1;
    }
    expectEquals(-2, x);
    try {
      c.virtualMethod();
      throw new Error("Expected NPE");
    } catch (NullPointerException e) {
      x -= 1;
    }
    expectEquals(-3, x);
  }
 
  static public void testInstanceOf(Object o) {
    if (o instanceof UnresolvedSuperClass) {
      System.out.println("instanceof ok");
    }
  }
 
  static public UnresolvedSuperClass testCheckCast(Object o) {
    UnresolvedSuperClass c = (UnresolvedSuperClass) o;
    System.out.println("checkcast ok");
    return c;
  }
  /// CHECK-START: void Main.main(java.lang.String[]) register (before)
  /// CHECK:        InvokeUnresolved invoke_type:direct
  static public void main(String[] args) {
    UnresolvedClass c = new UnresolvedClass();
    Main m = new Main();
    callInvokeUnresolvedStatic();
    callInvokeUnresolvedVirtual(c);
    callInvokeUnresolvedInterface(c);
    callInvokeUnresolvedSuper(m);
    callUnresolvedStaticFieldAccess();
    callUnresolvedInstanceFieldAccess(c);
    callUnresolvedNull(null);
    testInstanceOf(m);
    testCheckCast(m);
    testLicm(2);
  }
 
  /// CHECK-START: void Main.testLicm(int) licm (before)
  /// CHECK:      <<Class:l\d+>>        LoadClass                                     loop:<<LoopLabel:B\d+>>
  /// CHECK-NEXT: <<Clinit:l\d+>>       ClinitCheck [<<Class>>]                       loop:<<LoopLabel>>
  /// CHECK-NEXT: <<New:l\d+>>          NewInstance [<<Clinit>>]                      loop:<<LoopLabel>>
  /// CHECK-NEXT:                       ConstructorFence [<<New>>]                    loop:<<LoopLabel>>
  /// CHECK-NEXT:                       InvokeUnresolved [<<New>>]                    loop:<<LoopLabel>>
 
  /// CHECK-START: void Main.testLicm(int) licm (after)
  /// CHECK:      <<Class:l\d+>>        LoadClass                                     loop:none
  /// CHECK-NEXT: <<Clinit:l\d+>>       ClinitCheck [<<Class>>]                       loop:none
  /// CHECK:      <<New:l\d+>>          NewInstance [<<Clinit>>]                      loop:<<LoopLabel:B\d+>>
  /// CHECK-NEXT:                       ConstructorFence [<<New>>]                    loop:<<LoopLabel>>
  /// CHECK-NEXT:                       InvokeUnresolved [<<New>>]                    loop:<<LoopLabel>>
  static public void testLicm(int count) {
    // Test to make sure we keep the initialization check after loading an unresolved class.
    UnresolvedClass c;
    int i = 0;
    do {
      c = new UnresolvedClass();
    } while (i++ != count);
  }
 
  public static void expectEquals(byte expected, byte result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(char expected, char result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(int expected, int result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(long expected, long result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(float expected, float result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(double expected, double result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void expectEquals(Object expected, Object result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
}