Skip to content

Commit

Permalink
8316533: C2 compilation fails with assert(verify(phase)) failed: miss…
Browse files Browse the repository at this point in the history
…ing Value() optimization

Reviewed-by: rcastanedalo, thartmann, roland
  • Loading branch information
eme64 committed Nov 6, 2023
1 parent 377138c commit b5c863b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/hotspot/share/opto/subtypenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const
if (!superklass->is_interface() && superklass->is_abstract() &&
!superklass->as_instance_klass()->has_subklass()) {
Compile::current()->dependencies()->assert_leaf_type(superklass);
if (subk->is_same_java_type_as(superk) && !sub_t->maybe_null()) {
// The super_t has no subclasses, and sub_t has the same type and is not null,
// hence the check should always evaluate to EQ. However, this is an impossible
// situation since super_t is also abstract, and hence sub_t cannot have the
// same type and be non-null.
// Still, if the non-static method of an abstract class without subclasses is
// force-compiled, the Param0 has the self/this pointer with NotNull. This
// method would now never be called, because of the leaf-type dependency. Hence,
// just for consistency with verification, we return EQ.
return TypeInt::CC_EQ;
}
// subk is either a supertype of superk, or null. In either case, superk is a subtype.
return TypeInt::CC_GT;
}
}
Expand Down
64 changes: 64 additions & 0 deletions test/hotspot/jtreg/compiler/types/TestSubTypeOfAbstractClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8316533
* @summary Oop of abstract class A with no subclass is subtype checked after null-check
* @run driver compiler.types.TestSubTypeOfAbstractClass
*/

/**
* @test
* @bug 8316533
* @summary Oop of abstract class A is subtype checked after null-check
* @requires vm.compiler2.enabled
* @run main/othervm -XX:CompileCommand=compileonly,*A::test
* -Xcomp -XX:+IgnoreUnrecognizedVMOptions -XX:+StressReflectiveCode
* compiler.types.TestSubTypeOfAbstractClass
*/

package compiler.types;

public class TestSubTypeOfAbstractClass {

abstract class A {
public static A get_null() {
return null;
}

public static boolean test() {
// NullCheck -> CastPP with type A:NotNull
// But A is abstract with no subclass, hence this type is impossible
return get_null() instanceof A;
}
}

public static void main(String[] args) {
for (int i = 0; i < 10_000; i++ ) {
A.test();
}
}
}

1 comment on commit b5c863b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.