Skip to content

Commit

Permalink
8309266: C2: assert(final_con == (jlong)final_int) failed: final valu…
Browse files Browse the repository at this point in the history
…e should be integer

Reviewed-by: roland
Backport-of: 4a9cc8a000cafb3ad77a33710054b567e8553652
  • Loading branch information
GoeLin committed Jul 14, 2023
1 parent a6ef655 commit 97cf4fe
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/hotspot/share/opto/connode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ConNode : public TypeNode {
ConNode( const Type *t ) : TypeNode(t->remove_speculative(),1) {
init_req(0, (Node*)Compile::current()->root());
init_flags(Flag_is_Con);
init_class_id(Class_Con);
}
virtual int Opcode() const;
virtual uint hash() const;
Expand All @@ -53,7 +54,9 @@ class ConNode : public TypeNode {
// Simple integer constants
class ConINode : public ConNode {
public:
ConINode( const TypeInt *t ) : ConNode(t) {}
ConINode(const TypeInt *t) : ConNode(t) {
init_class_id(Class_ConI);
}
virtual int Opcode() const;

// Factory method:
Expand Down
10 changes: 8 additions & 2 deletions src/hotspot/share/opto/loopnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,8 +1891,14 @@ const Type* LoopLimitNode::Value(PhaseGVN* phase) const {
int final_int = (int)final_con;
// The final value should be in integer range since the loop
// is counted and the limit was checked for overflow.
assert(final_con == (jlong)final_int, "final value should be integer");
return TypeInt::make(final_int);
// Assert checks for overflow only if all input nodes are ConINodes, as during CCP
// there might be a temporary overflow from PhiNodes see JDK-8309266
assert((in(Init)->is_ConI() && in(Limit)->is_ConI() && in(Stride)->is_ConI()) ? final_con == (jlong)final_int : true, "final value should be integer");
if (final_con == (jlong)final_int) {
return TypeInt::make(final_int);
} else {
return bottom_type();
}
}

return bottom_type(); // TypeInt::INT
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/opto/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CmpNode;
class CodeBuffer;
class ConstraintCastNode;
class ConNode;
class ConINode;
class CompareAndSwapNode;
class CompareAndExchangeNode;
class CountedLoopNode;
Expand Down Expand Up @@ -707,6 +708,8 @@ class Node {
DEFINE_CLASS_ID(EncodePKlass, EncodeNarrowPtr, 1)
DEFINE_CLASS_ID(Vector, Type, 7)
DEFINE_CLASS_ID(VectorMaskCmp, Vector, 0)
DEFINE_CLASS_ID(Con, Type, 8)
DEFINE_CLASS_ID(ConI, Con, 0)

DEFINE_CLASS_ID(Proj, Node, 3)
DEFINE_CLASS_ID(CatchProj, Proj, 0)
Expand Down Expand Up @@ -854,6 +857,7 @@ class Node {
DEFINE_CLASS_QUERY(CheckCastPP)
DEFINE_CLASS_QUERY(CastII)
DEFINE_CLASS_QUERY(CastLL)
DEFINE_CLASS_QUERY(ConI)
DEFINE_CLASS_QUERY(ConstraintCast)
DEFINE_CLASS_QUERY(ClearArray)
DEFINE_CLASS_QUERY(CMove)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.
*
* 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 8309266
* @summary Integer overflow in LoopLimit::Value during PhaseCCP::analyze, triggered by the Phi Node from "flag ? Integer.MAX_VALUE : 1000"
* @run main/othervm -Xbatch -XX:CompileOnly=compiler.loopopts.TestLoopLimitOverflowDuringCCP::* compiler.loopopts.TestLoopLimitOverflowDuringCCP
*/

package compiler.loopopts;

public class TestLoopLimitOverflowDuringCCP {
static boolean flag;

public static void main(String[] strArr) {
for (int i = 0; i < 10000; i++) {
flag = !flag;
test();
}
}

public static void test() {
int limit = flag ? Integer.MAX_VALUE : 1000;
int i = 0;
while (i < limit) {
i += 3;
if (flag) {
return;
}
}
}
}

1 comment on commit 97cf4fe

@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.