Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/SuperCallTest.java
41159 views
1
/*
2
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
*
27
* @modules java.base/jdk.internal.org.objectweb.asm:+open java.base/jdk.internal.org.objectweb.asm.util:+open
28
* @library /vmTestbase /test/lib
29
*
30
* @comment build retransform.jar in current dir
31
* @run driver vm.runtime.defmeth.shared.BuildJar
32
*
33
* @run driver jdk.test.lib.FileInstaller . .
34
* @run main/othervm/native
35
* -agentlib:redefineClasses
36
* -javaagent:retransform.jar
37
* vm.runtime.defmeth.SuperCallTest
38
*/
39
package vm.runtime.defmeth;
40
41
import java.util.Set;
42
43
import vm.runtime.defmeth.shared.DefMethTest;
44
import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
45
import vm.runtime.defmeth.shared.data.*;
46
import vm.runtime.defmeth.shared.builder.TestBuilder;
47
48
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SYNCHRONIZED;
49
import static vm.runtime.defmeth.shared.ExecutionMode.*;
50
51
/*
52
* Tests on invoke-super-default.
53
*
54
* Invoke-super-default is used by a subclass to defer to a default method
55
* implementation or to disambiguate between conflicting inherited default
56
* methods.
57
*
58
* Invoke-super-default appears in the source code as
59
* "<interface-name>.super.<method-name>(<args>)". It is compiled into an
60
* invokespecial instruction whose target is <interface-name>.<method-name>,
61
* where the interface is a direct supertype of the current class (the current class
62
* must directly implement <interface-name>).
63
*
64
* Invokespecial on any superinterface method will run interface method
65
* resolution, and then the selected method will be set to the resolved method.
66
* super defaults no longer check for lack of shadowing, other languages
67
* want this capability.
68
*/
69
public class SuperCallTest extends DefMethTest {
70
71
public static void main(String[] args) {
72
DefMethTest.runTest(SuperCallTest.class,
73
/* majorVer */ Set.of(MAX_MAJOR_VER),
74
/* flags */ Set.of(0, ACC_SYNCHRONIZED),
75
/* redefine */ Set.of(false, true),
76
/* execMode */ Set.of(DIRECT, REFLECTION, INVOKE_EXACT, INVOKE_GENERIC, INVOKE_WITH_ARGS, INDY));
77
}
78
79
@Override
80
protected void configure() {
81
// Since invoke-super-default relies on new semantics of invokespecial,
82
// the tests are applicable only to class files of 52 version.
83
if (factory.getVer() < 52) {
84
getLog().warn("WARN: SuperCallTest is applicable only for class files w/ version >=52.");
85
getLog().warn("WARN: Overriding \"-ver " + factory.getVer() + "\" w/ \"-ver 52\".");
86
87
factory.setVer(52);
88
}
89
}
90
91
/*
92
* Basic case
93
*
94
* interface I { int m() default { return 1; } }
95
* interface J extends I { int m() default { return I.super.m(); } }
96
* class C implements J {}
97
*
98
* TEST: C c = new C(); c.m() == 88;
99
* TEST: I i = new C(); i.m() == 88;
100
*/
101
public void testSuperBasic1(TestBuilder b) {
102
Interface I = b.intf("I")
103
.defaultMethod("m", "()I").returns(1).build()
104
.build();
105
106
Interface J = b.intf("J").extend(I)
107
.defaultMethod("m", "()I").callSuper(I, "m", "()I").build()
108
.build();
109
110
ConcreteClass C = b.clazz("C").implement(J).build();
111
112
b.test().callSite(I, C, "m", "()I").returns(1).done()
113
.test().callSite(J, C, "m", "()I").returns(1).done()
114
.test().callSite(C, C, "m", "()I").returns(1).done();
115
}
116
117
/*
118
* Super Conflict Resolution
119
*
120
* interface K { int m() default { return 1; } }
121
* interface L { int m() default { return 2; } }
122
* interface I extends K,L { int m() default { K.super.m(); } }
123
* class C implements I {}
124
* class D implements K,L {}
125
*
126
* TEST: K k = new C(); k.m() == 1
127
* TEST: L l = new C(); l.m() == 1
128
* TEST: I i = new C(); i.m() == 1
129
* TEST: C c = new C(); c.m() == 1
130
*
131
* TEST: K k = new D(); k.m() == 1
132
* TEST: L l = new D(); l.m() == 1
133
* TEST: D d = new D(); d.m() == 1
134
*/
135
public void testSuperConflictResolution(TestBuilder b) {
136
Interface K = b.intf("K")
137
.defaultMethod("m", "()I").returns(1).build()
138
.build();
139
140
Interface L = b.intf("L")
141
.defaultMethod("m", "()I").returns(2).build()
142
.build();
143
144
Interface I = b.intf("I").extend(K, L)
145
.defaultMethod("m", "()I").callSuper(K, "m", "()I").build()
146
.build();
147
148
ConcreteClass C = b.clazz("C").implement(I).build();
149
150
ConcreteClass D = b.clazz("D").implement(K,L)
151
.concreteMethod("m", "()I").callSuper(K, "m", "()I").build()
152
.build();
153
154
155
b.test().callSite(K, C, "m", "()I").returns(1).done()
156
.test().callSite(L, C, "m", "()I").returns(1).done()
157
.test().callSite(I, C, "m", "()I").returns(1).done()
158
.test().callSite(C, C, "m", "()I").returns(1).done()
159
160
.test().callSite(K, D, "m", "()I").returns(1).done()
161
.test().callSite(L, D, "m", "()I").returns(1).done()
162
.test().callSite(D, D, "m", "()I").returns(1).done();
163
}
164
165
/*
166
* Super call of conflicting default method from different method name
167
*
168
* interface K {
169
* default public int m(int) { return 1; }
170
* }
171
* interface L {
172
* default public int m(int) { return 2; }
173
* }
174
* interface I extends K, L {
175
* default public int k() { return K.super.m((int)0); }
176
* default public int l() { return L.super.m((int)0); }
177
* }
178
* class C implements I {}
179
* class D implements K, L {
180
* public int k() { return K.super.m((int)0); }
181
* public int l() { return L.super.m((int)0); }
182
* }
183
*
184
* TEST: K o = new C(); o.m(I)I throws ICCE
185
* TEST: L o = new C(); o.m(I)I throws ICCE
186
* TEST: C o = new C(); o.m(I)I throws ICCE
187
* TEST: I o = new C(); o.k()I == 1
188
* TEST: C o = new C(); o.k()I == 1
189
* TEST: I o = new C(); o.l()I == 2
190
* TEST: C o = new C(); o.l()I == 2
191
* TEST: K o = new D(); o.m(I)I throws ICCE
192
* TEST: L o = new D(); o.m(I)I throws ICCE
193
* TEST: D o = new D(); o.m(I)I throws ICCE
194
* TEST: D o = new D(); o.k()I == 1
195
* TEST: D o = new D(); o.l()I == 2
196
*/
197
public void testSuperConflictDiffMethod(TestBuilder b) {
198
Interface K = b.intf("K")
199
.defaultMethod("m", "(I)I").returns(1).build()
200
.build();
201
202
Interface L = b.intf("L")
203
.defaultMethod("m", "(I)I").returns(2).build()
204
.build();
205
206
Interface I = b.intf("I").extend(K, L)
207
.defaultMethod("k", "()I").callSuper(K, "m", "(I)I").build()
208
.defaultMethod("l", "()I").callSuper(L, "m", "(I)I").build()
209
.build();
210
211
ConcreteClass C = b.clazz("C").implement(I).build();
212
213
ConcreteClass D = b.clazz("D").implement(K,L)
214
.concreteMethod("k", "()I").callSuper(K, "m", "(I)I").build()
215
.concreteMethod("l", "()I").callSuper(L, "m", "(I)I").build()
216
.build();
217
218
b.test().callSite(K, C, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
219
.test().callSite(L, C, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
220
.test().callSite(C, C, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
221
222
.test().callSite(I, C, "k", "()I").returns(1).done()
223
.test().callSite(C, C, "k", "()I").returns(1).done()
224
.test().callSite(I, C, "l", "()I").returns(2).done()
225
.test().callSite(C, C, "l", "()I").returns(2).done()
226
227
.test().callSite(K, D, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
228
.test().callSite(L, D, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
229
.test().callSite(D, D, "m", "(I)I").throws_(IncompatibleClassChangeError.class).done()
230
231
.test().callSite(D, D, "k", "()I").returns(1).done()
232
.test().callSite(D, D, "l", "()I").returns(2).done();
233
}
234
235
/*
236
* SuperConflict
237
*
238
* interface K { int m() default { return 1; } }
239
* interface L { int m() default { return 2; } }
240
* interface J extends K, L {}
241
* interface I extends J, K { int m() default { J.super.m(); } }
242
* class C implements I {}
243
*
244
* TEST: K k = new C(); k.m() ==> ICCE
245
* TEST: L l = new C(); l.m() ==> ICCE
246
* TEST: J j = new C(); j.m() ==> ICCE
247
* TEST: I i = new C(); i.m() ==> ICCE
248
* TEST: C c = new C(); c.m() ==> ICCE
249
*/
250
public void testSuperConflict(TestBuilder b) {
251
Interface K = b.intf("K")
252
.defaultMethod("m", "()I").returns(1).build()
253
.build();
254
255
Interface L = b.intf("L")
256
.defaultMethod("m", "()I").returns(2).build()
257
.build();
258
259
Interface J = b.intf("J").extend(K, L).build();
260
261
Interface I = b.intf("I").extend(K, J)
262
.defaultMethod("m", "()I").callSuper(J, "m", "()I").build()
263
.build();
264
265
ConcreteClass C = b.clazz("C").implement(I).build();
266
267
b.test().callSite(K, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
268
.test().callSite(L, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
269
.test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
270
.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
271
.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
272
}
273
274
/*
275
* SuperDisqual
276
*
277
* interface I { int m() default { return 1; } }
278
* interface J { int m() default { return 2; } }
279
* class C implements I, J { public int m() { return I.super.m(); } }
280
*
281
* TEST: C c = new C(); c.m() ==> 1
282
* TEST: J j = new C(); j.m() ==> 1
283
*/
284
public void testSuperDisqual(TestBuilder b) {
285
Interface I = b.intf("I")
286
.defaultMethod("m", "()I").returns(1).build()
287
.build();
288
289
Interface J = b.intf("J")
290
.defaultMethod("m", "()I").returns(2).build()
291
.build();
292
293
ConcreteClass C = b.clazz("C").implement(I, J)
294
.concreteMethod("m", "()I").callSuper(I, "m", "()I").build()
295
.build();
296
297
b.test().callSite(I, C, "m", "()I").returns(1).done()
298
.test().callSite(J, C, "m", "()I").returns(1).done()
299
.test().callSite(C, C, "m", "()I").returns(1).done();
300
}
301
302
/*
303
* SuperNull
304
*
305
* interface I { int m(); }
306
* interface J extends I { int m() default { return I.super.m(); } }
307
* interface K extends I { int m() default { return I.super.n(); } }
308
* class C implements J {}
309
* class D implements K {}
310
*
311
* TEST: I i = new C(); i.m() ==> AME
312
* TEST: J j = new C(); j.m() ==> AME
313
* TEST: C c = new C(); c.m() ==> AME
314
* TEST: K k = new D(); k.m() ==> NSME
315
*/
316
public void testSuperNull(TestBuilder b) {
317
Interface I = b.intf("I")
318
.abstractMethod("m", "()I").build()
319
.build();
320
321
Interface J = b.intf("J").extend(I)
322
.defaultMethod("m", "()I").callSuper(I, "m", "()I").build()
323
.build();
324
325
Interface K = b.intf("K").extend(I)
326
.defaultMethod("m", "()I").callSuper(I, "n", "()I").build()
327
.build();
328
329
ConcreteClass C = b.clazz("C").implement(J).build();
330
ConcreteClass D = b.clazz("D").implement(K).build();
331
332
b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
333
.test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
334
.test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
335
.test().callSite(K, D, "m", "()I").throws_(NoSuchMethodError.class).done();
336
}
337
338
/*
339
* SuperGeneric
340
*
341
* interface J<T> { int m(T t) default { return 1; } }
342
* interface I extends J<String> { int m(String s) default { return J.super.m(); } }
343
* class C implements I {}
344
*
345
* TEST: I i = new C(); i.m(new Object()) == 1;
346
* TESTL J j = new C(); j.m(new Object()) == 1;
347
* TEST: J j = new C(); j.m("") == 1;
348
* TEST: C c = new C(); c.m(new Object()) == 1;
349
* TEST: C c = new C(); c.m("") == 1;
350
*/
351
public void testSuperGeneric(TestBuilder b) {
352
// interface I<T> {
353
// default int m(T t) { return 1; }
354
// }
355
Interface I = b.intf("I")
356
.sig("<T:Ljava/lang/Object;>Ljava/lang/Object;")
357
.defaultMethod("m", "(Ljava/lang/Object;)I").sig("(TT;)I").returns(1).build()
358
.build();
359
360
// interface J extends I<String> {
361
// default int m(String s) { return I.super.m(); }
362
// }
363
Interface J = b.intf("J").extend(I)
364
.sig("Ljava/lang/Object;LI<Ljava/lang/String;>;")
365
.defaultMethod("m", "(Ljava/lang/String;)I").callSuper(I, "m", "(Ljava/lang/Object;)I").build()
366
.build();
367
368
ConcreteClass C = b.clazz("C").implement(J).build();
369
370
b.test().callSite(I, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
371
372
.test().callSite(J, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
373
.test().callSite(J, C, "m", "(Ljava/lang/String;)I").returns(1).done()
374
375
.test().callSite(C, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
376
.test().callSite(C, C, "m", "(Ljava/lang/String;)I").returns(1).done();
377
}
378
379
/*
380
* SuperGenericDisqual
381
*
382
* interface I<T> { int m(T t) default { return 1; } }
383
* interface J extends I<String> { int m(String s) default { return 2; } }
384
* class C implements I<String>, J { public int m(String s) { return I.super.m(s); } }
385
*
386
* TEST: C c = new C(); c.m("string") == 1
387
*/
388
public void testSuperGenericDisqual(TestBuilder b) {
389
Interface I = b.intf("I").sig("<T:Ljava/lang/Object;>Ljava/lang/Object;")
390
.defaultMethod("m", "(Ljava/lang/Object;)I").sig("(TT;)I").returns(1).build()
391
.build();
392
393
Interface J = b.intf("J").extend(I)
394
.sig("Ljava/lang/Object;LJ<Ljava/lang/String;>;")
395
.defaultMethod("m", "(Ljava/lang/String;)I").returns(2).build()
396
.build();
397
398
ConcreteClass C = b.clazz("C").implement(I,J)
399
.sig("Ljava/lang/Object;LI;LJ<Ljava/lang/String;>;")
400
.concreteMethod("m", "(Ljava/lang/String;)I").callSuper(I, "m", "(Ljava/lang/Object;)I").build()
401
.build();
402
403
b.test().callSite(I, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
404
405
.test().callSite(J, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
406
.test().callSite(J, C, "m", "(Ljava/lang/String;)I").returns(1).done()
407
408
.test().callSite(C, C, "m", "(Ljava/lang/Object;)I").returns(1).done()
409
.test().callSite(C, C, "m", "(Ljava/lang/String;)I").returns(1).done();
410
}
411
412
/*
413
* Super-call of non-default method
414
*
415
* class C { int m() { return 1; } }
416
* class D extends C { int m() { return C.super.m(); } }
417
*
418
* TEST: C d = new D(); d.m() == 1
419
* TEST: D d = new D(); d.m() == 1
420
*/
421
public void testSuperNonDefault(TestBuilder b) {
422
ConcreteClass C = b.clazz("C")
423
.concreteMethod("m", "()I").returns(1).build()
424
.build();
425
426
ConcreteClass D = b.clazz("D").extend(C)
427
.concreteMethod("m", "()I").callSuper(C, "m", "()I").build()
428
.build();
429
430
b.test().callSite(C, D, "m", "()I").returns(1).done()
431
.test().callSite(D, D, "m", "()I").returns(1).done();
432
}
433
434
/*
435
* Super-call of non-default method
436
*
437
* interface I { int m(); }
438
* class C { int m() { return 1; } }
439
* class D extends C implements I { int m() { return I.super.m(); } }
440
* class E extends C implements I { int m() { return C.super.m(); } }
441
*
442
* TEST: I d = new D(); d.m() ==> AME
443
* TEST: C d = new D(); d.m() ==> AME
444
* TEST: D d = new D(); d.m() ==> AME
445
* TEST: I e = new E(); e.m() == 1
446
* TEST: C e = new E(); e.m() == 1
447
* TEST: E e = new E(); e.m() == 1
448
*/
449
public void testSuperNonDefault1(TestBuilder b) {
450
Interface I = b.intf("I")
451
.abstractMethod("m", "()I").build()
452
.build();
453
454
ConcreteClass C = b.clazz("C")
455
.concreteMethod("m", "()I").returns(1).build()
456
.build();
457
458
ConcreteClass D = b.clazz("D").extend(C).implement(I)
459
.concreteMethod("m", "()I").callSuper(I, "m", "()I").build()
460
.build();
461
462
ConcreteClass E = b.clazz("E").extend(C).implement(I)
463
.concreteMethod("m", "()I").callSuper(C, "m", "()I").build()
464
.build();
465
466
b.test().callSite(I, D, "m", "()I").throws_(AbstractMethodError.class).done()
467
.test().callSite(C, D, "m", "()I").throws_(AbstractMethodError.class).done()
468
.test().callSite(D, D, "m", "()I").throws_(AbstractMethodError.class).done()
469
470
.test().callSite(I, E, "m", "()I").returns(1).done()
471
.test().callSite(C, E, "m", "()I").returns(1).done()
472
.test().callSite(E, E, "m", "()I").returns(1).done();
473
}
474
475
/*
476
* Super-call of non-default method
477
*
478
* interface I { int m() {return 1;} }
479
* class C { int m() { return 2; } }
480
* class D extends C implements I { int m() { return I.super.m(); } }
481
* class E extends C implements I { int m() { return C.super.m(); } }
482
*
483
* TEST: I d = new D(); d.m() == 1
484
* TEST: C d = new D(); d.m() == 1
485
* TEST: D d = new D(); d.m() == 1
486
*
487
* TEST: I e = new E(); e.m() == 2
488
* TEST: C e = new E(); e.m() == 2
489
* TEST: E e = new E(); e.m() == 2
490
*/
491
public void testSuperNonDefault2(TestBuilder b) {
492
Interface I = b.intf("I")
493
.defaultMethod("m", "()I").returns(1).build()
494
.build();
495
496
ConcreteClass C = b.clazz("C")
497
.concreteMethod("m", "()I").returns(2).build()
498
.build();
499
500
ConcreteClass D = b.clazz("D").extend(C).implement(I)
501
.concreteMethod("m", "()I").callSuper(I, "m", "()I").build()
502
.build();
503
504
ConcreteClass E = b.clazz("E").extend(C).implement(I)
505
.concreteMethod("m", "()I").callSuper(C, "m", "()I").build()
506
.build();
507
508
b.test().callSite(I, D, "m", "()I").returns(1).done()
509
.test().callSite(C, D, "m", "()I").returns(1).done()
510
.test().callSite(D, D, "m", "()I").returns(1).done()
511
512
.test().callSite(I, E, "m", "()I").returns(2).done()
513
.test().callSite(C, E, "m", "()I").returns(2).done()
514
.test().callSite(E, E, "m", "()I").returns(2).done();
515
}
516
517
/*
518
* Disambig
519
*
520
* interface I { int m() default { return 1; } }
521
* interface J { int m() default { return 2; } }
522
* class C implements I, J { int q() { return I.super.m(); }
523
* int r() { return J.super.m(); } }
524
*
525
* TEST: C c = new C(); c.m() == ICCE;
526
* TEST: C c = new C(); c.q() == 1;
527
* TEST: C c = new C(); c.r() == 2;
528
*/
529
public void testDisambig(TestBuilder b) {
530
Interface I = b.intf("I")
531
.defaultMethod("m", "()I").returns(1).build()
532
.build();
533
534
Interface J = b.intf("J")
535
.defaultMethod("m", "()I").returns(2).build()
536
.build();
537
538
ConcreteClass C = b.clazz("C").implement(I,J)
539
.concreteMethod("q", "()I").callSuper(I, "m", "()I").build()
540
.concreteMethod("r", "()I").callSuper(J, "m", "()I").build()
541
.build();
542
543
b.test().callSite(C, C, "q", "()I").returns(1).done()
544
.test().callSite(C, C, "r", "()I").returns(2).done()
545
.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
546
}
547
548
/*
549
* Disambig2
550
*
551
* interface I { int m() default { return 1; } }
552
* interface J { int m() default { return 2; } }
553
* interface K extends I
554
* interface L extends J
555
* class C implements K, L { int q() { return K.super.m(); }
556
* int r() { return L.super.m(); } }
557
*
558
* TEST: C c = new C(); c.m() == ICCE;
559
* TEST: C c = new C(); c.q() == 1;
560
* TEST: C c = new C(); c.r() == 2;
561
*/
562
public void testDisambig2(TestBuilder b) {
563
Interface I = b.intf("I")
564
.defaultMethod("m", "()I").returns(1).build()
565
.build();
566
567
Interface J = b.intf("J")
568
.defaultMethod("m", "()I").returns(2).build()
569
.build();
570
571
Interface K = b.intf("K").extend(I).build();
572
573
Interface L = b.intf("L").extend(J).build();
574
575
ConcreteClass C = b.clazz("C").implement(K,L)
576
.concreteMethod("q", "()I").callSuper(K, "m", "()I").build()
577
.concreteMethod("r", "()I").callSuper(L, "m", "()I").build()
578
.build();
579
580
b.test().callSite(C, C, "q", "()I").returns(1).done()
581
.test().callSite(C, C, "r", "()I").returns(2).done()
582
.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
583
}
584
585
/*
586
* testResolvedShadowed
587
*
588
* interface I { int m() default { return 1; } }
589
* interface K extends I { int m() default { return 2; } }
590
* interface J extends I { }
591
* class C implements J,K { int q { J.super.m(); } }
592
*
593
* TEST: C c = new C(); c.m() == 2
594
* TEST: C c = new C(); c.q() == 1
595
*/
596
public void testResolvedShadowed(TestBuilder b) {
597
Interface I = b.intf("I")
598
.defaultMethod("m", "()I").returns(1).build()
599
.build();
600
601
Interface K = b.intf("K").extend(I)
602
.defaultMethod("m", "()I").returns(2).build()
603
.build();
604
605
Interface J = b.intf("J").extend(I)
606
.build();
607
608
ConcreteClass C = b.clazz("C").implement(J,K)
609
.concreteMethod("q", "()I").callSuper(J, "m", "()I").build()
610
.build();
611
612
b.test().callSite(C, C, "m", "()I").returns(2).done()
613
.test().callSite(C, C, "q", "()I").returns(1).done();
614
}
615
616
/*
617
* testResolvedButSuperClass
618
*
619
* interface I { int m() default { return 1; } }
620
* interface J { }
621
* class A { public int m() { return 2; } }
622
* class C implements J extends A { int q { J.super.m(); } }
623
*
624
* TEST: C c = new C(); c.q() == 1
625
* TEST: C c = new C(); c.m() == 2
626
*/
627
public void testResolvedButSuperClass(TestBuilder b) {
628
Interface I = b.intf("I")
629
.defaultMethod("m", "()I").returns(1).build()
630
.build();
631
632
Interface J = b.intf("J").extend(I)
633
.build();
634
635
ConcreteClass A = b.clazz("A")
636
.concreteMethod("m", "()I").returns(2).build()
637
.build();
638
639
ConcreteClass C = b.clazz("C").implement(J).extend(A)
640
.concreteMethod("q", "()I").callSuper(J, "m", "()I").build()
641
.build();
642
643
b.test().callSite(C, C, "q", "()I").returns(1).done()
644
.test().callSite(C, C, "m", "()I").returns(2).done();
645
}
646
647
/*
648
* testResolved1Caller2NotShadowed
649
*
650
* interface I { int m() default { return 1; } }
651
* interface J extends I { }
652
* interface L { int m() default { return 2; } }
653
* interface K extends I, L { }
654
* class C implements J,K { int q { J.super.m(); } }
655
*
656
* TEST: C c = new C(); c.m() == ICCE
657
* TEST: C c = new C(); c.q() == 1
658
*/
659
public void testResolved1Caller2NotShadowed(TestBuilder b) {
660
Interface I = b.intf("I")
661
.defaultMethod("m", "()I").returns(1).build()
662
.build();
663
664
Interface J = b.intf("J").extend(I).build();
665
666
Interface L = b.intf("L")
667
.defaultMethod("m", "()I").returns(2).build()
668
.build();
669
670
Interface K = b.intf("K").extend(I,L)
671
.build();
672
673
ConcreteClass C = b.clazz("C").implement(J,K)
674
.concreteMethod("q", "()I").callSuper(J, "m", "()I").build()
675
.build();
676
677
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
678
.test().callSite(C, C, "q", "()I").returns(1).done();
679
}
680
681
/*
682
* Test validity of invokespecial on indirect superinterface's method,
683
* this test should receive a verification error.
684
*
685
* JVMS-4.9.2 Structural Constraints
686
* Each invokespecial instruction must name an instance initialization
687
* method (2.9), or must reference a method in the current class or interface,
688
* a method in a superclass of the current class or interface, or a method
689
* in a direct superinterface of the current class or interface
690
*
691
* Note: Normally javac would reject this test case complaining that,
692
* InDirectSuper.java:5: error: not an enclosing class: I
693
* interface K extends J { default public void m() { I.super.m(); } }
694
* ^
695
* However, the below test case allows us to check for this structural
696
* constraint on invokespecial in the JVM.
697
*
698
* interface I { int m() default { return 1; } }
699
* interface J extends I { }
700
* interface K extends J { int m() default { return I.super.m(); } }
701
* class C implements K {}
702
*
703
* TEST: K k = new C(); k.m() == VerifyError
704
*/
705
@NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets VerifyError
706
public void testSuperInvalidIndirectInterfaceMethodInvokeSpecial(TestBuilder b) {
707
Interface I = b.intf("I")
708
.defaultMethod("m", "()I").returns(1).build()
709
.build();
710
711
Interface J = b.intf("J").extend(I).build();
712
713
Interface K = b.intf("K").extend(J)
714
.defaultMethod("m", "()I").callSuper(I, "m", "()I").build()
715
.build();
716
717
ConcreteClass C = b.clazz("C").implement(K).build();
718
719
b.test().callSite(K, C, "m", "()I").throws_(VerifyError.class).done();
720
}
721
}
722
723