8285394: Compiler blackholes can be eliminated due to stale ciMethod::intrinsic_id()

Reviewed-by: kvn
Backport-of: ce8db2c40378de01ce35ca37ec315af47974d6d6
This commit is contained in:
Aleksey Shipilev 2022-05-04 15:27:04 +00:00
parent 2447d2fedf
commit f142228202
3 changed files with 108 additions and 3 deletions

View File

@ -82,7 +82,6 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
_max_stack = h_m->max_stack();
_max_locals = h_m->max_locals();
_code_size = h_m->code_size();
_intrinsic_id = h_m->intrinsic_id();
_handler_count = h_m->exception_table_length();
_size_of_parameters = h_m->size_of_parameters();
_uses_monitors = h_m->access_flags().has_monitor_bytecodes();
@ -102,6 +101,10 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
_bcea = NULL;
#endif // COMPILER2
// Check for blackhole intrinsic and then populate the intrinsic ID.
CompilerOracle::tag_blackhole_if_possible(h_m);
_intrinsic_id = h_m->intrinsic_id();
ciEnv *env = CURRENT_ENV;
if (env->jvmti_can_hotswap_or_post_breakpoint()) {
// 6328518 check hotswap conditions under the right lock.
@ -157,8 +160,6 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
ciReplay::initialize(this);
}
#endif
CompilerOracle::tag_blackhole_if_possible(h_m);
}

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2022, 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 8285394
* @requires vm.compiler2.enabled
* @summary Blackholes should work when hot inlined
* @library /test/lib /
* @run driver compiler.c2.irTests.blackhole.BlackholeHotInlineTest
*/
package compiler.c2.irTests.blackhole;
import compiler.lib.ir_framework.*;
import jdk.test.lib.Asserts;
public class BlackholeHotInlineTest {
public static void main(String[] args) {
TestFramework.runWithFlags(
"-XX:+UnlockExperimentalVMOptions",
"-XX:CompileThreshold=100",
"-XX:-TieredCompilation",
"-XX:CompileCommand=blackhole,compiler.c2.irTests.blackhole.BlackholeHotInlineTest::blackhole",
"-XX:CompileCommand=dontinline,compiler.c2.irTests.blackhole.BlackholeHotInlineTest::dontinline"
);
}
static long x, y;
/*
* Negative test: check that dangling expression is eliminated
*/
@Test
@IR(failOn = IRNode.MUL_L)
static void testNothing() {
long r = x * y;
}
@Run(test = "testNothing")
static void runNothing() {
testNothing();
}
/*
* Auxiliary test: check that dontinline method does not allow the elimination.
*/
@Test
@IR(counts = {IRNode.MUL_L, "1"})
static void testDontline() {
long r = x * y;
dontinline(r);
}
static void dontinline(long x) {}
@Run(test = "testDontline")
static void runDontinline() {
testDontline();
}
/*
* Positive test: check that blackhole method does not allow the elimination either.
*/
@Test
@IR(counts = {IRNode.MUL_L, "1"})
static void testBlackholed() {
long r = x * y;
blackhole(r);
}
static void blackhole(long x) {}
@Run(test = "testBlackholed")
static void runBlackholed() {
testBlackholed();
}
}

View File

@ -141,6 +141,7 @@ public class IRNode {
public static final String LSHIFT_L = START + "LShiftL" + MID + END;
public static final String ADD_I = START + "AddI" + MID + END;
public static final String ADD_L = START + "AddL" + MID + END;
public static final String MUL_L = START + "MulL" + MID + END;
public static final String CONV_I2L = START + "ConvI2L" + MID + END;
public static final String POPCOUNT_L = START + "PopCountL" + MID + END;