8214862: assert(proj != __null) at compile.cpp:3251

Reviewed-by: kvn, thartmann
This commit is contained in:
Roland Westrelin 2018-12-07 17:56:51 +01:00
parent 0486227784
commit b68257174d
7 changed files with 100 additions and 16 deletions

View File

@ -1271,6 +1271,14 @@ uint SafePointNode::match_edge(uint idx) const {
return (TypeFunc::Parms == idx);
}
void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
int nb = igvn->C->root()->find_prec_edge(this);
if (nb != -1) {
igvn->C->root()->rm_prec(nb);
}
}
//============== SafePointScalarObjectNode ==============
SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,

View File

@ -462,6 +462,8 @@ public:
return !_replaced_nodes.is_empty();
}
void disconnect_from_root(PhaseIterGVN *igvn);
// Standard Node stuff
virtual int Opcode() const;
virtual bool pinned() const { return true; }

View File

@ -2184,6 +2184,23 @@ bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
return true;
}
// Remove edges from "root" to each SafePoint at a backward branch.
// They were inserted during parsing (see add_safepoint()) to make
// infinite loops without calls or exceptions visible to root, i.e.,
// useful.
void Compile::remove_root_to_sfpts_edges() {
Node *r = root();
if (r != NULL) {
for (uint i = r->req(); i < r->len(); ++i) {
Node *n = r->in(i);
if (n != NULL && n->is_SafePoint()) {
r->rm_prec(i);
--i;
}
}
}
}
//------------------------------Optimize---------------------------------------
// Given a graph, optimize it.
void Compile::Optimize() {
@ -2244,6 +2261,10 @@ void Compile::Optimize() {
if (failing()) return;
}
// Now that all inlining is over, cut edge from root to loop
// safepoints
remove_root_to_sfpts_edges();
// Remove the speculative part of types and clean up the graph from
// the extra CastPP nodes whose only purpose is to carry them. Do
// that early so that optimizations are not disrupted by the extra
@ -3248,8 +3269,10 @@ void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& f
break;
}
}
assert(proj != NULL, "must be found");
p->subsume_by(proj, this);
assert(proj != NULL || p->_con == TypeFunc::I_O, "io may be dropped at an infinite loop");
if (proj != NULL) {
p->subsume_by(proj, this);
}
}
}
break;

View File

@ -1088,6 +1088,7 @@ class Compile : public Phase {
void inline_string_calls(bool parse_time);
void inline_boxing_calls(PhaseIterGVN& igvn);
bool optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode);
void remove_root_to_sfpts_edges();
// Matching, CFG layout, allocation, code generation
PhaseCFG* cfg() { return _cfg; }

View File

@ -37,6 +37,7 @@
#include "opto/node.hpp"
#include "opto/opcodes.hpp"
#include "opto/regmask.hpp"
#include "opto/rootnode.hpp"
#include "opto/type.hpp"
#include "utilities/copy.hpp"
#include "utilities/macros.hpp"
@ -1310,6 +1311,9 @@ static void kill_dead_code( Node *dead, PhaseIterGVN *igvn ) {
while (nstack.size() > 0) {
dead = nstack.pop();
if (dead->Opcode() == Op_SafePoint) {
dead->as_SafePoint()->disconnect_from_root(igvn);
}
if (dead->outcnt() > 0) {
// Keep dead node on stack until all uses are processed.
nstack.push(dead);

View File

@ -430,20 +430,6 @@ PhaseRemoveUseless::PhaseRemoveUseless(PhaseGVN *gvn, Unique_Node_List *worklist
// Disconnect 'useless' nodes that are adjacent to useful nodes
C->remove_useless_nodes(_useful);
// Remove edges from "root" to each SafePoint at a backward branch.
// They were inserted during parsing (see add_safepoint()) to make infinite
// loops without calls or exceptions visible to root, i.e., useful.
Node *root = C->root();
if( root != NULL ) {
for( uint i = root->req(); i < root->len(); ++i ) {
Node *n = root->in(i);
if( n != NULL && n->is_SafePoint() ) {
root->rm_prec(i);
--i;
}
}
}
}
//=============================================================================
@ -1354,6 +1340,9 @@ void PhaseIterGVN::remove_globally_dead_node( Node *dead ) {
while (_stack.is_nonempty()) {
dead = _stack.node();
if (dead->Opcode() == Op_SafePoint) {
dead->as_SafePoint()->disconnect_from_root(this);
}
uint progress_state = _stack.index();
assert(dead != C->root(), "killing root, eh?");
assert(!dead->is_top(), "add check for top when pushing");
@ -1456,6 +1445,9 @@ void PhaseIterGVN::remove_globally_dead_node( Node *dead ) {
//------------------------------subsume_node-----------------------------------
// Remove users from node 'old' and add them to node 'nn'.
void PhaseIterGVN::subsume_node( Node *old, Node *nn ) {
if (old->Opcode() == Op_SafePoint) {
old->as_SafePoint()->disconnect_from_root(this);
}
assert( old != hash_find(old), "should already been removed" );
assert( old != C->top(), "cannot subsume top node");
// Copy debug or profile information to the new version:

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2018, Red Hat, Inc. 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 8214862
* @summary Multiple passes of PhaseRemoveUseless causes infinite loop to be optimized out
*
* @run main/othervm -XX:-TieredCompilation -Xcomp -XX:CompileOnly=StringConcatInfiniteLoop::test -XX:CompileCommand=dontinline,*StringBuilder::* StringConcatInfiniteLoop
*
*/
public class StringConcatInfiniteLoop {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
test(sb, "foo", "bar", true);
}
private static void test(Object v, String s1, String s2, boolean flag) {
if (flag) {
return;
}
int i = 0;
for (; i < 10; i++);
if (i == 10) {
v = null;
}
StringBuilder sb = new StringBuilder(s1);
sb.append(s2);
while (v == null);
}
private static class A {
}
}