Skip to content
Permalink
Browse files
8270995: [lworld] G1BarrierSetC2::step_over_gc_barrier asserts with "…
…bad barrier shape"
  • Loading branch information
TobiHartmann committed Jul 27, 2021
1 parent ae5fc42 commit 616023843b10876dcd3b0e3dd49534b6e48b274f
Showing 3 changed files with 101 additions and 11 deletions.
@@ -2071,11 +2071,16 @@ void ConnectionGraph::optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklis
assert(storestore->is_MemBarStoreStore(), "");
Node* alloc = storestore->in(MemBarNode::Precedent)->in(0);
if (alloc->is_Allocate() && not_global_escape(alloc)) {
MemBarNode* mb = MemBarNode::make(C, Op_MemBarCPUOrder, Compile::AliasIdxBot);
mb->init_req(TypeFunc::Memory, storestore->in(TypeFunc::Memory));
mb->init_req(TypeFunc::Control, storestore->in(TypeFunc::Control));
igvn->register_new_node_with_optimizer(mb);
igvn->replace_node(storestore, mb);
if (alloc->in(AllocateNode::InlineTypeNode) != NULL) {
// Non-escaping inline type buffer allocations don't require a membar
storestore->as_MemBar()->remove(_igvn);
} else {
MemBarNode* mb = MemBarNode::make(C, Op_MemBarCPUOrder, Compile::AliasIdxBot);
mb->init_req(TypeFunc::Memory, storestore->in(TypeFunc::Memory));
mb->init_req(TypeFunc::Control, storestore->in(TypeFunc::Control));
igvn->register_new_node_with_optimizer(mb);
igvn->replace_node(storestore, mb);
}
}
}
}
@@ -1077,15 +1077,11 @@ void PhaseMacroExpand::process_users_of_allocation(CallNode *alloc, bool inline_
assert(init->outcnt() <= 2, "only a control and memory projection expected");
Node *ctrl_proj = init->proj_out_or_null(TypeFunc::Control);
if (ctrl_proj != NULL) {
// Inline type buffer allocations are followed by a membar
Node* membar_after = ctrl_proj->unique_ctrl_out();
if (inline_alloc && membar_after->Opcode() == Op_MemBarCPUOrder) {
membar_after->as_MemBar()->remove(&_igvn);
}
_igvn.replace_node(ctrl_proj, init->in(TypeFunc::Control));
#ifdef ASSERT
// If the InitializeNode has no memory out, it will die, and tmp will become NULL
Node* tmp = init->in(TypeFunc::Control);
assert(tmp == _callprojs->fallthrough_catchproj, "allocation control projection");
assert(tmp == NULL || tmp == _callprojs->fallthrough_catchproj, "allocation control projection");
#endif
}
Node *mem_proj = init->proj_out_or_null(TypeFunc::Memory);
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2021, 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 8270995
* @summary Membars of non-escaping inline type buffer allocations should be removed.
* @library /test/lib
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -XX:-TieredCompilation -XX:-ReduceInitialCardMarks
* -XX:+AlwaysIncrementalInline -Xbatch -XX:CompileCommand=compileonly,*TestUnexpectedMemBar::test*
* -XX:+StressIGVN -XX:+StressGCM -XX:+StressLCM -XX:StressSeed=851121348
* compiler.valhalla.inlinetypes.TestUnexpectedMemBar
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -XX:-TieredCompilation -XX:-ReduceInitialCardMarks -XX:+AlwaysIncrementalInline
* -Xbatch -XX:CompileCommand=compileonly,*TestUnexpectedMemBar::test*
* -XX:+StressIGVN -XX:+StressGCM -XX:+StressLCM
* compiler.valhalla.inlinetypes.TestUnexpectedMemBar
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -Xbatch -XX:CompileCommand=compileonly,*TestUnexpectedMemBar::test*
* -XX:+StressIGVN -XX:+StressGCM -XX:+StressLCM
* compiler.valhalla.inlinetypes.TestUnexpectedMemBar
*/

package compiler.valhalla.inlinetypes;

import jdk.test.lib.Asserts;

primitive class MyValue {
final int a = 0;
final int b = 0;
final int c = 0;
final int d = 0;
final int e = 0;

final Integer i;
final int[] array;

public MyValue(Integer i, int[] array) {
this.i = i;
this.array = array;
}
}

public class TestUnexpectedMemBar {

public static int test1(Integer i) {
int[] array = new int[1];
MyValue vt = new MyValue(i, array);
vt = new MyValue(vt.i, vt.array);
return vt.i + vt.array[0];
}

public static int test2(Integer i) {
int[] array = {i};
MyValue vt = new MyValue(i, array);
vt = new MyValue(vt.i, vt.array);
return vt.i + vt.array[0];
}

public static void main(String[] args) {
for (int i = 0; i < 100_000; ++i) {
int res = test1(i);
Asserts.assertEquals(res, i, "test1 failed");
res = test2(i);
Asserts.assertEquals(res, 2*i, "test2 failed");
}
}
}

0 comments on commit 6160238

Please sign in to comment.