1 /*
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
488 bool call_does_dispatch = false;
489
490 // Speculative type of the receiver if any
491 ciKlass* speculative_receiver_type = NULL;
492 if (is_virtual_or_interface) {
493 Node* receiver_node = stack(sp() - nargs);
494 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
495 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
496 // For arrays, klass below is Object. When vtable calls are used,
497 // resolving the call with Object would allow an illegal call to
498 // finalize() on an array. We use holder instead: illegal calls to
499 // finalize() won't be compiled as vtable calls (IC call
500 // resolution will catch the illegal call) and the few legal calls
501 // on array types won't be either.
502 callee = C->optimize_virtual_call(method(), bci(), klass, holder, orig_callee,
503 receiver_type, is_virtual,
504 call_does_dispatch, vtable_index); // out-parameters
505 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
506 }
507
508 // invoke-super-special
509 if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_initializer()) {
510 ciInstanceKlass* calling_klass = method()->holder();
511 ciInstanceKlass* sender_klass =
512 calling_klass->is_anonymous() ? calling_klass->host_klass() :
513 calling_klass;
514 if (sender_klass->is_interface()) {
515 Node* receiver_node = stack(sp() - nargs);
516 Node* cls_node = makecon(TypeKlassPtr::make(sender_klass));
517 Node* bad_type_ctrl = NULL;
518 Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl);
519 if (bad_type_ctrl != NULL) {
520 PreserveJVMState pjvms(this);
521 set_control(bad_type_ctrl);
522 uncommon_trap(Deoptimization::Reason_class_check,
523 Deoptimization::Action_none);
524 }
525 if (stopped()) {
526 return; // MUST uncommon-trap?
527 }
528 set_stack(sp() - nargs, casted_receiver);
529 }
530 }
531
532 // Note: It's OK to try to inline a virtual call.
533 // The call generator will not attempt to inline a polymorphic call
534 // unless it knows how to optimize the receiver dispatch.
535 bool try_inline = (C->do_inlining() || InlineAccessors);
536
537 // ---------------------
538 dec_sp(nargs); // Temporarily pop args for JVM state of call
539 JVMState* jvms = sync_jvms();
540
541 // ---------------------
542 // Decide call tactic.
543 // This call checks with CHA, the interpreter profile, intrinsics table, etc.
544 // It decides whether inlining is desirable or not.
545 CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type);
546
547 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead.
548 orig_callee = callee = NULL;
549
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
488 bool call_does_dispatch = false;
489
490 // Speculative type of the receiver if any
491 ciKlass* speculative_receiver_type = NULL;
492 if (is_virtual_or_interface) {
493 Node* receiver_node = stack(sp() - nargs);
494 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
495 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
496 // For arrays, klass below is Object. When vtable calls are used,
497 // resolving the call with Object would allow an illegal call to
498 // finalize() on an array. We use holder instead: illegal calls to
499 // finalize() won't be compiled as vtable calls (IC call
500 // resolution will catch the illegal call) and the few legal calls
501 // on array types won't be either.
502 callee = C->optimize_virtual_call(method(), bci(), klass, holder, orig_callee,
503 receiver_type, is_virtual,
504 call_does_dispatch, vtable_index); // out-parameters
505 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
506 }
507
508 // Additional receiver subtype checks for interface calls via invokespecial or invokeinterface.
509 ciKlass* receiver_constraint = NULL;
510 if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_initializer()) {
511 ciInstanceKlass* calling_klass = method()->holder();
512 ciInstanceKlass* sender_klass =
513 calling_klass->is_anonymous() ? calling_klass->host_klass() :
514 calling_klass;
515 if (sender_klass->is_interface()) {
516 receiver_constraint = sender_klass;
517 }
518 } else if (iter().cur_bc_raw() == Bytecodes::_invokeinterface && orig_callee->is_private()) {
519 assert(holder->is_interface(), "How did we get a non-interface method here!");
520 receiver_constraint = holder;
521 }
522
523 if (receiver_constraint != NULL) {
524 Node* receiver_node = stack(sp() - nargs);
525 Node* cls_node = makecon(TypeKlassPtr::make(receiver_constraint));
526 Node* bad_type_ctrl = NULL;
527 Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl);
528 if (bad_type_ctrl != NULL) {
529 PreserveJVMState pjvms(this);
530 set_control(bad_type_ctrl);
531 uncommon_trap(Deoptimization::Reason_class_check,
532 Deoptimization::Action_none);
533 }
534 if (stopped()) {
535 return; // MUST uncommon-trap?
536 }
537 set_stack(sp() - nargs, casted_receiver);
538 }
539
540 // Note: It's OK to try to inline a virtual call.
541 // The call generator will not attempt to inline a polymorphic call
542 // unless it knows how to optimize the receiver dispatch.
543 bool try_inline = (C->do_inlining() || InlineAccessors);
544
545 // ---------------------
546 dec_sp(nargs); // Temporarily pop args for JVM state of call
547 JVMState* jvms = sync_jvms();
548
549 // ---------------------
550 // Decide call tactic.
551 // This call checks with CHA, the interpreter profile, intrinsics table, etc.
552 // It decides whether inlining is desirable or not.
553 CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type);
554
555 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead.
556 orig_callee = callee = NULL;
557
|