8227384: C2 compilation fails with "graph should be schedulable" when running with -XX:-EliminateLocks

Reviewed-by: thartmann, kvn
This commit is contained in:
Roland Westrelin 2019-07-16 08:56:08 +02:00
parent c127592320
commit 2f2ec624a2
7 changed files with 122 additions and 15 deletions

View File

@ -1397,6 +1397,18 @@ void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
_is_allocation_MemBar_redundant = true;
}
}
Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
Node* mark_node = NULL;
// For now only enable fast locking for non-array types
if (UseBiasedLocking && Opcode() == Op_Allocate) {
Node* klass_node = in(AllocateNode::KlassNode);
Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
} else {
mark_node = phase->MakeConX(markWord::prototype().value());
}
return mark_node;
}
//=============================================================================
Node* AllocateArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) {

View File

@ -936,6 +936,8 @@ public:
// allocation node.
void compute_MemBar_redundancy(ciMethod* initializer);
bool is_allocation_MemBar_redundant() { return _is_allocation_MemBar_redundant; }
Node* make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem);
};
//------------------------------AllocateArray---------------------------------

View File

@ -1652,14 +1652,11 @@ PhaseMacroExpand::initialize_object(AllocateNode* alloc,
Node* size_in_bytes) {
InitializeNode* init = alloc->initialization();
// Store the klass & mark bits
Node* mark_node = NULL;
// For now only enable fast locking for non-array types
if (UseBiasedLocking && (length == NULL)) {
mark_node = make_load(control, rawmem, klass_node, in_bytes(Klass::prototype_header_offset()), TypeRawPtr::BOTTOM, T_ADDRESS);
} else {
mark_node = makecon(TypeRawPtr::make((address)markWord::prototype().value()));
Node* mark_node = alloc->make_ideal_mark(&_igvn, object, control, rawmem);
if (!mark_node->is_Con()) {
transform_later(mark_node);
}
rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, T_ADDRESS);
rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, TypeX_X->basic_type());
rawmem = make_store(control, rawmem, object, oopDesc::klass_offset_in_bytes(), klass_node, T_METADATA);
int header_size = alloc->minimum_header_size(); // conservatively small
@ -2596,15 +2593,36 @@ bool PhaseMacroExpand::expand_macro_nodes() {
if (_igvn.type(n) == Type::TOP || (n->in(0) != NULL && n->in(0)->is_top())) {
// node is unreachable, so don't try to expand it
C->remove_macro_node(n);
} else if (n->is_ArrayCopy()){
int macro_count = C->macro_count();
continue;
}
int macro_count = C->macro_count();
switch (n->class_id()) {
case Node::Class_Lock:
expand_lock_node(n->as_Lock());
assert(C->macro_count() < macro_count, "must have deleted a node from macro list");
break;
case Node::Class_Unlock:
expand_unlock_node(n->as_Unlock());
assert(C->macro_count() < macro_count, "must have deleted a node from macro list");
break;
case Node::Class_ArrayCopy:
expand_arraycopy_node(n->as_ArrayCopy());
assert(C->macro_count() < macro_count, "must have deleted a node from macro list");
break;
}
if (C->failing()) return true;
macro_idx --;
}
// All nodes except Allocate nodes are expanded now. There could be
// new optimization opportunities (such as folding newly created
// load from a just allocated object). Run IGVN.
_igvn.set_delay_transform(false);
_igvn.optimize();
if (C->failing()) return true;
_igvn.set_delay_transform(true);
// expand "macro" nodes
// nodes are removed from the macro list as they are processed
while (C->macro_count() > 0) {
@ -2623,12 +2641,6 @@ bool PhaseMacroExpand::expand_macro_nodes() {
case Node::Class_AllocateArray:
expand_allocate_array(n->as_AllocateArray());
break;
case Node::Class_Lock:
expand_lock_node(n->as_Lock());
break;
case Node::Class_Unlock:
expand_unlock_node(n->as_Unlock());
break;
default:
assert(false, "unknown node type in macro list");
}

View File

@ -1555,6 +1555,22 @@ Node *LoadNode::split_through_phi(PhaseGVN *phase) {
return phi;
}
AllocateNode* LoadNode::is_new_object_mark_load(PhaseGVN *phase) const {
if (Opcode() == Op_LoadX) {
Node* address = in(MemNode::Address);
AllocateNode* alloc = AllocateNode::Ideal_allocation(address, phase);
Node* mem = in(MemNode::Memory);
if (alloc != NULL && mem->is_Proj() &&
mem->in(0) != NULL &&
mem->in(0) == alloc->initialization() &&
alloc->initialization()->proj_out_or_null(0) != NULL) {
return alloc;
}
}
return NULL;
}
//------------------------------Ideal------------------------------------------
// If the load is from Field memory and the pointer is non-null, it might be possible to
// zero out the control input.
@ -1683,6 +1699,13 @@ Node *LoadNode::Ideal(PhaseGVN *phase, bool can_reshape) {
}
}
AllocateNode* alloc = is_new_object_mark_load(phase);
if (alloc != NULL && alloc->Opcode() == Op_Allocate && UseBiasedLocking) {
InitializeNode* init = alloc->initialization();
Node* control = init->proj_out(0);
return alloc->make_ideal_mark(phase, address, control, mem);
}
return progress ? this : NULL;
}
@ -1941,6 +1964,12 @@ const Type* LoadNode::Value(PhaseGVN* phase) const {
return Type::get_zero_type(_type->basic_type());
}
}
Node* alloc = is_new_object_mark_load(phase);
if (alloc != NULL && !(alloc->Opcode() == Op_Allocate && UseBiasedLocking)) {
return TypeX::make(markWord::prototype().value());
}
return _type;
}

View File

@ -183,6 +183,8 @@ private:
uint _barrier; // Bit field with barrier information
AllocateNode* is_new_object_mark_load(PhaseGVN *phase) const;
protected:
virtual bool cmp(const Node &n) const;
virtual uint size_of() const; // Size is bigger

View File

@ -1791,6 +1791,7 @@ inline bool Type::is_ptr_to_boxing_obj() const {
#define Op_SubX Op_SubL
#define Op_XorX Op_XorL
#define Op_URShiftX Op_URShiftL
#define Op_LoadX Op_LoadL
// conversions
#define ConvI2X(x) ConvI2L(x)
#define ConvL2X(x) (x)
@ -1838,6 +1839,7 @@ inline bool Type::is_ptr_to_boxing_obj() const {
#define Op_SubX Op_SubI
#define Op_XorX Op_XorI
#define Op_URShiftX Op_URShiftI
#define Op_LoadX Op_LoadI
// conversions
#define ConvI2X(x) (x)
#define ConvL2X(x) ConvL2I(x)

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2019, 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 8227384
* @summary C2 compilation fails with "graph should be schedulable" when running with -XX:-EliminateLocks
*
* @run main/othervm -XX:-EliminateLocks TestEliminateLocksOffCrash
*/
public class TestEliminateLocksOffCrash {
public static void main(String[] args) {
for (int i = 0; i < 20_000; i++) {
try {
test();
} catch (Exception e) {
}
}
}
private static void test() throws Exception {
Object obj = new Object();
synchronized (obj) {
throw new Exception();
}
}
}