Skip to content

Commit 3cc9ed0

Browse files
committedOct 23, 2019
8232873: Add missing test for 8220416
Adds a missing test which verifies the bug fix of 8220416. Reviewed-by: roland, thartmann
1 parent a2c5af4 commit 3cc9ed0

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2019, 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+
* @bug 8220416
27+
* @summary This test uses a class pointer comparison optimization which was not applied anymore since JDK-6964458 resulting in a better IR.
28+
*
29+
* @run main/othervm -Xbatch -XX:-TieredCompilation -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline
30+
* -XX:CompileOnly=compiler.c2.CompareKlassPointersTest::test compiler.c2.CompareKlassPointersTest
31+
*/
32+
33+
package compiler.c2;
34+
35+
36+
37+
public class CompareKlassPointersTest {
38+
39+
static A a;
40+
41+
public static void main(String[] args) {
42+
a = new C();
43+
for (int i = 0; i < 10_000; i++) {
44+
test();
45+
}
46+
}
47+
48+
public static int test() {
49+
Object a = getA();
50+
51+
/*
52+
* This check is now optimized away which was not the case before anymore since JDK-6964458:
53+
* The klass pointer comparison optimization sees that the check is always false since a and B are always unrelated klasses
54+
*/
55+
if (a instanceof B) {
56+
return 1;
57+
}
58+
return 0;
59+
}
60+
61+
private static Object getA() {
62+
return a;
63+
}
64+
}
65+
66+
class A { }
67+
68+
class B { }
69+
70+
class C extends A { }

0 commit comments

Comments
 (0)
Please sign in to comment.