Skip to content
Permalink
Browse files
8267791: [lworld][lw3] Support compiler blackholes for inline types
Reviewed-by: thartmann
  • Loading branch information
shipilev authored and TobiHartmann committed May 31, 2021
1 parent f1b3269 commit f931661b00c7d2fb88fd791a92b574f06cb5bf4e
Showing 4 changed files with 113 additions and 1 deletion.
@@ -1927,6 +1927,34 @@ void Compile::process_inline_types(PhaseIterGVN &igvn, bool remove) {
} else if (vt->is_InlineTypePtr()) {
igvn.replace_node(vt, vt->get_oop());
} else {
// Check if any users are blackholes. If so, rewrite them to use either the
// allocated buffer, or individual components, instead of the inline type node
// that goes away.
for (DUIterator i = vt->outs(); vt->has_out(i); i++) {
if (vt->out(i)->is_Blackhole()) {
BlackholeNode* bh = vt->out(i)->as_Blackhole();

// Unlink the old input
int idx = bh->find_edge(vt);
assert(idx != -1, "The edge should be there");
bh->del_req(idx);
--i;

if (vt->is_allocated(&igvn)) {
// Already has the allocated instance, blackhole that
bh->add_req(vt->get_oop());
} else {
// Not allocated yet, blackhole the components
for (uint c = 0; c < vt->field_count(); c++) {
bh->add_req(vt->field_value(c));
}
}

// Node modified, record for IGVN
igvn.record_for_igvn(bh);
}
}

#ifdef ASSERT
for (DUIterator_Fast imax, i = vt->fast_outs(imax); i < imax; i++) {
assert(vt->fast_out(i)->is_InlineTypeBase(), "Unexpected inline type user");
@@ -1354,7 +1354,9 @@ class OnSpinWaitNode: public MemBarNode {
class BlackholeNode : public MemBarNode {
public:
BlackholeNode(Compile* C, int alias_idx, Node* precedent)
: MemBarNode(C, alias_idx, precedent) {}
: MemBarNode(C, alias_idx, precedent) {
init_class_id(Class_Blackhole);
}
virtual int Opcode() const;
virtual uint ideal_reg() const { return 0; } // not matched in the AD file
const RegMask &in_RegMask(uint idx) const {
@@ -668,6 +668,7 @@ class Node {
DEFINE_CLASS_ID(MemBar, Multi, 3)
DEFINE_CLASS_ID(Initialize, MemBar, 0)
DEFINE_CLASS_ID(MemBarStoreStore, MemBar, 1)
DEFINE_CLASS_ID(Blackhole, MemBar, 2)

DEFINE_CLASS_ID(Mach, Node, 1)
DEFINE_CLASS_ID(MachReturn, Mach, 0)
@@ -845,6 +846,7 @@ class Node {
DEFINE_CLASS_QUERY(ArrayCopy)
DEFINE_CLASS_QUERY(BaseCountedLoop)
DEFINE_CLASS_QUERY(BaseCountedLoopEnd)
DEFINE_CLASS_QUERY(Blackhole)
DEFINE_CLASS_QUERY(Bool)
DEFINE_CLASS_QUERY(BoxLock)
DEFINE_CLASS_QUERY(Call)
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2021, 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.
*/

package compiler.valhalla.inlinetypes;

/*
* @test BlackholeTest
* @summary Check that blackholes work with inline types
* @run main/othervm
* -Xbatch
* -XX:+UnlockExperimentalVMOptions
* -XX:CompileCommand=blackhole,compiler/valhalla/inlinetypes/BlackholeTest.blackhole
* compiler.valhalla.inlinetypes.BlackholeTest
*/

public class BlackholeTest {
static primitive class MyValue {
int x = 0;
}

static MyValue v;
static volatile MyValue vv;

public static void main(String[] args) {
for (int c = 0; c < 5; c++) {
testNew();
testDefault();
testField();
testVolatileField();
}
}

private static void testNew() {
for (int c = 0; c < 100000; c++) {
blackhole(new MyValue());
}
}

private static void testDefault() {
for (int c = 0; c < 100000; c++) {
blackhole(MyValue.default);
}
}

private static void testField() {
for (int c = 0; c < 100000; c++) {
blackhole(v);
}
}

private static void testVolatileField() {
for (int c = 0; c < 100000; c++) {
blackhole(vv);
}
}

public static void blackhole(MyValue v) {
// Should be empty
}
}

0 comments on commit f931661

Please sign in to comment.