mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-22 11:28:11 +00:00
8287223: C1: Inlining attempt through MH::invokeBasic() with null receiver
Reviewed-by: kvn
This commit is contained in:
parent
0df4748216
commit
d3e781de08
@ -4145,20 +4145,28 @@ bool GraphBuilder::try_method_handle_inline(ciMethod* callee, bool ignore_return
|
||||
const int args_base = state()->stack_size() - callee->arg_size();
|
||||
ValueType* type = state()->stack_at(args_base)->type();
|
||||
if (type->is_constant()) {
|
||||
ciMethod* target = type->as_ObjectType()->constant_value()->as_method_handle()->get_vmtarget();
|
||||
// We don't do CHA here so only inline static and statically bindable methods.
|
||||
if (target->is_static() || target->can_be_statically_bound()) {
|
||||
if (ciMethod::is_consistent_info(callee, target)) {
|
||||
Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
|
||||
ignore_return = ignore_return || (callee->return_type()->is_void() && !target->return_type()->is_void());
|
||||
if (try_inline(target, /*holder_known*/ !callee->is_static(), ignore_return, bc)) {
|
||||
return true;
|
||||
ciObject* mh = type->as_ObjectType()->constant_value();
|
||||
if (mh->is_method_handle()) {
|
||||
ciMethod* target = mh->as_method_handle()->get_vmtarget();
|
||||
|
||||
// We don't do CHA here so only inline static and statically bindable methods.
|
||||
if (target->is_static() || target->can_be_statically_bound()) {
|
||||
if (ciMethod::is_consistent_info(callee, target)) {
|
||||
Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
|
||||
ignore_return = ignore_return || (callee->return_type()->is_void() && !target->return_type()->is_void());
|
||||
if (try_inline(target, /*holder_known*/ !callee->is_static(), ignore_return, bc)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
print_inlining(target, "signatures mismatch", /*success*/ false);
|
||||
}
|
||||
} else {
|
||||
print_inlining(target, "signatures mismatch", /*success*/ false);
|
||||
assert(false, "no inlining through MH::invokeBasic"); // missing optimization opportunity due to suboptimal LF shape
|
||||
print_inlining(target, "not static or statically bindable", /*success*/ false);
|
||||
}
|
||||
} else {
|
||||
print_inlining(target, "not static or statically bindable", /*success*/ false);
|
||||
assert(mh->is_null_object(), "not a null");
|
||||
print_inlining(callee, "receiver is always null", /*success*/ false);
|
||||
}
|
||||
} else {
|
||||
print_inlining(callee, "receiver not constant", /*success*/ false);
|
||||
|
||||
@ -1018,22 +1018,29 @@ CallGenerator* CallGenerator::for_method_handle_inline(JVMState* jvms, ciMethod*
|
||||
Node* receiver = kit.argument(0);
|
||||
if (receiver->Opcode() == Op_ConP) {
|
||||
input_not_const = false;
|
||||
const TypeOopPtr* oop_ptr = receiver->bottom_type()->is_oopptr();
|
||||
ciMethod* target = oop_ptr->const_oop()->as_method_handle()->get_vmtarget();
|
||||
const int vtable_index = Method::invalid_vtable_index;
|
||||
const TypeOopPtr* recv_toop = receiver->bottom_type()->isa_oopptr();
|
||||
if (recv_toop != NULL) {
|
||||
ciMethod* target = recv_toop->const_oop()->as_method_handle()->get_vmtarget();
|
||||
const int vtable_index = Method::invalid_vtable_index;
|
||||
|
||||
if (!ciMethod::is_consistent_info(callee, target)) {
|
||||
if (!ciMethod::is_consistent_info(callee, target)) {
|
||||
print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
|
||||
"signatures mismatch");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CallGenerator *cg = C->call_generator(target, vtable_index,
|
||||
false /* call_does_dispatch */,
|
||||
jvms,
|
||||
allow_inline,
|
||||
PROB_ALWAYS);
|
||||
return cg;
|
||||
} else {
|
||||
assert(receiver->bottom_type() == TypePtr::NULL_PTR, "not a null: %s",
|
||||
Type::str(receiver->bottom_type()));
|
||||
print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
|
||||
"signatures mismatch");
|
||||
return NULL;
|
||||
"receiver is always null");
|
||||
}
|
||||
|
||||
CallGenerator* cg = C->call_generator(target, vtable_index,
|
||||
false /* call_does_dispatch */,
|
||||
jvms,
|
||||
allow_inline,
|
||||
PROB_ALWAYS);
|
||||
return cg;
|
||||
} else {
|
||||
print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
|
||||
"receiver not constant");
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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 8287223
|
||||
* @library /test/lib / patches
|
||||
*
|
||||
* @build java.base/java.lang.invoke.MethodHandleHelper
|
||||
* @run main/bootclasspath/othervm -Xbatch -XX:CompileCommand=compileonly,*::test -XX:-TieredCompilation compiler.jsr292.NullConstantMHReceiver
|
||||
* @run main/bootclasspath/othervm -Xbatch -XX:CompileCommand=compileonly,*::test -XX:+TieredCompilation -XX:TieredStopAtLevel=1 compiler.jsr292.NullConstantMHReceiver
|
||||
*/
|
||||
|
||||
package compiler.jsr292;
|
||||
|
||||
import java.lang.invoke.MethodHandleHelper;
|
||||
|
||||
public class NullConstantMHReceiver {
|
||||
static void test() throws Throwable {
|
||||
MethodHandleHelper.invokeBasicL(null);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
for (int i = 0; i < 15000; i++) {
|
||||
try {
|
||||
test();
|
||||
} catch (NullPointerException e) {
|
||||
// expected
|
||||
continue;
|
||||
}
|
||||
throw new AssertionError("NPE wasn't thrown");
|
||||
}
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user