Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 2a35bc5

Browse files
committedMar 11, 2020
8240854: [REDO] some jaotc failures of fastdebug build with specific flags
Reviewed-by: vlivanov, kvn, thartmann
1 parent a8b4801 commit 2a35bc5

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed
 

‎src/hotspot/share/opto/compile.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -4241,9 +4241,6 @@ int Compile::static_subtype_check(ciKlass* superk, ciKlass* subk) {
42414241
// Add a dependency if there is a chance of a later subclass.
42424242
dependencies()->assert_leaf_type(ik);
42434243
}
4244-
if (ik->is_abstract()) {
4245-
return SSC_always_false;
4246-
}
42474244
return SSC_easy_test; // (3) caller can do a simple ptr comparison
42484245
}
42494246
} else {

‎src/hotspot/share/opto/subtypenode.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const
3636

3737
bool xsubk = sub_t->isa_klassptr() ? sub_t->is_klassptr()->klass_is_exact() : sub_t->is_oopptr()->klass_is_exact();
3838

39+
40+
// Oop can't be a subtype of abstract type that has no subclass.
41+
if (sub_t->isa_oopptr() && superk->is_instance_klass() &&
42+
!superk->is_interface() && superk->is_abstract() &&
43+
!superk->as_instance_klass()->has_subklass()) {
44+
Compile::current()->dependencies()->assert_leaf_type(superk);
45+
return TypeInt::CC_GT;
46+
}
47+
3948
// Similar to logic in CmpPNode::sub()
4049

4150
// Interfaces can't be trusted unless the subclass is an exact
@@ -93,9 +102,6 @@ const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const
93102
}
94103

95104
Node *SubTypeCheckNode::Ideal(PhaseGVN *phase, bool can_reshape) {
96-
// Verify that optimizing the subtype check to a simple code pattern
97-
// when possible would not constant fold better
98-
#ifdef ASSERT
99105
Node* obj_or_subklass = in(ObjOrSubKlass);
100106
Node* superklass = in(SuperKlass);
101107

@@ -112,7 +118,28 @@ Node *SubTypeCheckNode::Ideal(PhaseGVN *phase, bool can_reshape) {
112118
return NULL;
113119
}
114120

121+
Node* addr = NULL;
122+
if (obj_or_subklass->is_DecodeNKlass()) {
123+
if (obj_or_subklass->in(1) != NULL &&
124+
obj_or_subklass->in(1)->Opcode() == Op_LoadNKlass) {
125+
addr = obj_or_subklass->in(1)->in(MemNode::Address);
126+
}
127+
} else if (obj_or_subklass->Opcode() == Op_LoadKlass) {
128+
addr = obj_or_subklass->in(MemNode::Address);
129+
}
130+
131+
if (addr != NULL) {
132+
intptr_t con = 0;
133+
Node* obj = AddPNode::Ideal_base_and_offset(addr, phase, con);
134+
if (con == oopDesc::klass_offset_in_bytes() && obj != NULL && phase->type(obj)->isa_oopptr()) {
135+
set_req(ObjOrSubKlass, obj);
136+
return this;
137+
}
138+
}
115139

140+
// Verify that optimizing the subtype check to a simple code pattern
141+
// when possible would not constant fold better
142+
#ifdef ASSERT
116143
ciKlass* superk = super_t->is_klassptr()->klass();
117144
ciKlass* subk = sub_t->isa_klassptr() ? sub_t->is_klassptr()->klass() : sub_t->is_oopptr()->klass();
118145

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2020, Red Hat, Inc. 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 8240195
27+
* @summary subtype check with abstract class that has no children classes can sometimes be constant folded
28+
* @requires vm.compiler2.enabled
29+
*
30+
* @run main/othervm -XX:-BackgroundCompilation TestSubTypeOfAsbtractClassWrongResult
31+
*
32+
*/
33+
34+
35+
public class TestSubTypeOfAsbtractClassWrongResult {
36+
public static void main(String[] args) {
37+
for (int i = 0; i < 20_000; i++) {
38+
if (!test1(A.class)) {
39+
throw new RuntimeException("Wrong result");
40+
}
41+
test2(new Object());
42+
test3(new Exception());
43+
}
44+
}
45+
46+
private static boolean test1(Class c) {
47+
return A.class.isAssignableFrom(c);
48+
}
49+
50+
private static boolean test2(Object o) {
51+
return o instanceof A;
52+
}
53+
54+
private static void test3(Exception e) {
55+
try {
56+
throw e;
57+
} catch (A ex1) {
58+
} catch (Exception ex2) {
59+
}
60+
}
61+
62+
static abstract class A extends Exception {
63+
}
64+
}

0 commit comments

Comments
 (0)
This repository has been archived.