Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8238723: yank_alloc_node must remove membar
Browse files Browse the repository at this point in the history
Reviewed-by: vlivanov, thartmann, roland
  • Loading branch information
Nils Eliasson committed Feb 24, 2020
1 parent aab0ce5 commit 38a57e8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
53 changes: 30 additions & 23 deletions src/hotspot/share/opto/macro.cpp
Expand Up @@ -1334,14 +1334,23 @@ void PhaseMacroExpand::expand_allocate_common(
if (!allocation_has_use) {
InitializeNode* init = alloc->initialization();
if (init != NULL) {
yank_initalize_node(init);
assert(init->outcnt() == 0, "all uses must be deleted");
_igvn.remove_dead_node(init);
init->remove(&_igvn);
}
if (expand_fast_path && (initial_slow_test == NULL)) {
// Remove allocation node and return.
// Size is a non-negative constant -> no initial check needed -> directly to fast path.
// Also, no usages -> empty fast path -> no fall out to slow path -> nothing left.
#ifndef PRODUCT
if (PrintEliminateAllocations) {
tty->print("NotUsed ");
Node* res = alloc->proj_out_or_null(TypeFunc::Parms);
if (res != NULL) {
res->dump();
} else {
alloc->dump();
}
}
#endif
yank_alloc_node(alloc);
return;
}
Expand Down Expand Up @@ -1579,6 +1588,16 @@ void PhaseMacroExpand::yank_alloc_node(AllocateNode* alloc) {
Node* i_o = alloc->in(TypeFunc::I_O);

extract_call_projections(alloc);
if (_resproj != NULL) {
for (DUIterator_Fast imax, i = _resproj->fast_outs(imax); i < imax; i++) {
Node* use = _resproj->fast_out(i);
use->isa_MemBar()->remove(&_igvn);
--imax;
--i; // back up iterator
}
assert(_resproj->outcnt() == 0, "all uses must be deleted");
_igvn.remove_dead_node(_resproj);
}
if (_fallthroughcatchproj != NULL) {
migrate_outs(_fallthroughcatchproj, ctrl);
_igvn.remove_dead_node(_fallthroughcatchproj);
Expand Down Expand Up @@ -1608,6 +1627,14 @@ void PhaseMacroExpand::yank_alloc_node(AllocateNode* alloc) {
_igvn.rehash_node_delayed(_ioproj_catchall);
_ioproj_catchall->set_req(0, top());
}
#ifndef PRODUCT
if (PrintEliminateAllocations) {
if (alloc->is_AllocateArray()) {}
tty->print_cr("++++ Eliminated: %d AllocateArray", alloc->_idx);
} else {
tty->print_cr("++++ Eliminated: %d Allocate", alloc->_idx);
}
#endif
_igvn.remove_dead_node(alloc);
}

Expand Down Expand Up @@ -1712,26 +1739,6 @@ void PhaseMacroExpand::expand_dtrace_alloc_probe(AllocateNode* alloc, Node* oop,
}
}

// Remove InitializeNode without use
void PhaseMacroExpand::yank_initalize_node(InitializeNode* initnode) {
assert(initnode->proj_out_or_null(TypeFunc::Parms) == NULL, "No uses allowed");

Node* ctrl_out = initnode->proj_out_or_null(TypeFunc::Control);
Node* mem_out = initnode->proj_out_or_null(TypeFunc::Memory);

// Move all uses of each to
if (ctrl_out != NULL ) {
migrate_outs(ctrl_out, initnode->in(TypeFunc::Control));
_igvn.remove_dead_node(ctrl_out);
}

// Move all uses of each to
if (mem_out != NULL ) {
migrate_outs(mem_out, initnode->in(TypeFunc::Memory));
_igvn.remove_dead_node(mem_out);
}
}

// Helper for PhaseMacroExpand::expand_allocate_common.
// Initializes the newly-allocated storage.
Node*
Expand Down
19 changes: 18 additions & 1 deletion test/hotspot/jtreg/compiler/allocation/TestAllocation.java
Expand Up @@ -25,7 +25,9 @@
* @test
* @bug 8237581
* @summary Testing allocation expansion when there is no use of the allocation
* @run main/othervm -Xbatch -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::
* @run main/othervm -Xbatch -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*
* compiler.allocation.TestAllocation
* @run main/othervm -Xbatch -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:-DoEscapeAnalysis -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*
* compiler.allocation.TestAllocation
*/

Expand All @@ -41,6 +43,12 @@ public int testUnknownPositiveArrayLength() {
return w.i + w.ba.length;
}

public int testStoreCapture() {
byte[] bs = new byte[1];
bs[0] = 1;
return bs.length;
}

public int testUnknownNegativeArrayLength() {
boolean success = false;
try {
Expand All @@ -61,6 +69,13 @@ public int testConstantPositiveArrayLength() {
return w.i + w.ba.length;
}

public int testConstantPositiveArrayLength2() {
Payload w = new Payload(173, 10);
w.i = 17;
w.ba = new byte[10];
return w.i + w.ba.length;
}

public int testConstantNegativeArrayLength() {
boolean success = false;
try {
Expand Down Expand Up @@ -91,7 +106,9 @@ public static void main(String[] strArr) {
test.testUnknownPositiveArrayLength();
test.testUnknownNegativeArrayLength();
test.testConstantPositiveArrayLength();
test.testConstantPositiveArrayLength2();
test.testConstantNegativeArrayLength();
test.testStoreCapture();
}
}
}
Expand Down

0 comments on commit 38a57e8

Please sign in to comment.