Skip to content

Commit

Permalink
8240795: [REDO] 8238384 CTW: C2 compilation fails with "assert(store …
Browse files Browse the repository at this point in the history
…!= load->find_exact_control(load->in(0))) failed: dependence cycle found"

Reviewed-by: kvn, thartmann
  • Loading branch information
rwestrel committed Mar 13, 2020
1 parent 136a157 commit c9faf88
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/hotspot/share/opto/compile.cpp
Expand Up @@ -1700,8 +1700,9 @@ bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {
bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {
if (alias_idx == AliasIdxTop) return false; // the empty category
if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP
if (alias_idx == AliasIdxBot) return true; // the universal category
if (adr_type->base() == Type::AnyPtr) return true; // TypePtr::BOTTOM or its twins
// Known instance doesn't alias with bottom memory
if (alias_idx == AliasIdxBot) return !adr_type->is_known_instance(); // the universal category
if (adr_type->base() == Type::AnyPtr) return !C->get_adr_type(alias_idx)->is_known_instance(); // TypePtr::BOTTOM or its twins

// the only remaining possible overlap is identity
int adr_idx = get_alias_index(adr_type);
Expand Down
13 changes: 0 additions & 13 deletions src/hotspot/share/opto/gcm.cpp
Expand Up @@ -707,19 +707,6 @@ Block* PhaseCFG::insert_anti_dependences(Block* LCA, Node* load, bool verify) {
// instead of control + memory.
if (mstore->ideal_Opcode() == Op_SafePoint)
continue;

// Check if the store is a membar on which the load is control dependent.
// Inserting an anti-dependency between that membar and the load would
// create a cycle that causes local scheduling to fail.
if (mstore->isa_MachMemBar()) {
Node* dom = load->find_exact_control(load->in(0));
while (dom != NULL && dom != dom->in(0) && dom != mstore) {
dom = dom->in(0);
}
if (dom == mstore) {
continue;
}
}
} else {
// Some raw memory, such as the load of "top" at an allocation,
// can be control dependent on the previous safepoint. See
Expand Down
11 changes: 10 additions & 1 deletion src/hotspot/share/opto/loopnode.cpp
Expand Up @@ -31,6 +31,7 @@
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "opto/addnode.hpp"
#include "opto/arraycopynode.hpp"
#include "opto/callnode.hpp"
#include "opto/connode.hpp"
#include "opto/convertnode.hpp"
Expand Down Expand Up @@ -4089,8 +4090,16 @@ Node *PhaseIdealLoop::get_late_ctrl( Node *n, Node *early ) {
}
} else {
Node *sctrl = has_ctrl(s) ? get_ctrl(s) : s->in(0);
const TypePtr* adr_type = s->adr_type();
if (s->is_ArrayCopy()) {
// Copy to known instance needs destination type to test for aliasing
const TypePtr* dest_type = s->as_ArrayCopy()->_dest_type;
if (dest_type != TypeOopPtr::BOTTOM) {
adr_type = dest_type;
}
}
assert(sctrl != NULL || !s->is_reachable_from_root(), "must have control");
if (sctrl != NULL && !sctrl->is_top() && C->can_alias(s->adr_type(), load_alias_idx) && is_dominator(early, sctrl)) {
if (sctrl != NULL && !sctrl->is_top() && C->can_alias(adr_type, load_alias_idx) && is_dominator(early, sctrl)) {
LCA = dom_lca_for_get_late_ctrl(LCA, sctrl, n);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/opto/type.hpp
Expand Up @@ -452,6 +452,7 @@ class Type {
const Type* maybe_remove_speculative(bool include_speculative) const;

virtual bool maybe_null() const { return true; }
virtual bool is_known_instance() const { return false; }

private:
// support arrays
Expand Down Expand Up @@ -1397,6 +1398,10 @@ class TypeNarrowPtr : public Type {
return _ptrtype;
}

bool is_known_instance() const {
return _ptrtype->is_known_instance();
}

#ifndef PRODUCT
virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
#endif
Expand Down
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, 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
* @bug 8238384
* @summary CTW: C2 compilation fails with "assert(store != load->find_exact_control(load->in(0))) failed: dependence cycle found"
*
* @run main/othervm -XX:-BackgroundCompilation TestCopyOfBrokenAntiDependency
*
*/

import java.util.Arrays;

public class TestCopyOfBrokenAntiDependency {

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

private static Object test(int length) {
Object[] src = new Object[length]; // non escaping
final Object[] dst = Arrays.copyOf(src, 10); // can't be removed
final Object[] dst2 = Arrays.copyOf(dst, 100);
// load is control dependent on membar from previous copyOf
// but has memory edge to first copyOf.
final Object v = dst[0];
return v;
}
}

0 comments on commit c9faf88

Please sign in to comment.