1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)doCall.cpp 1.207 07/07/19 19:08:29 JVM"
3 #endif
4 /*
5 * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
376 // Only one fall-back, so if an intrinsic fails, ignore any bytecodes.
377 if (cg->is_intrinsic() && call_method->code_size() > 0) {
378 tty->print("Bailed out of intrinsic, will not inline: ");
379 call_method->print_name(); tty->cr();
380 }
381 }
382 #endif
383 // This can happen if a library intrinsic is available, but refuses
384 // the call site, perhaps because it did not match a pattern the
385 // intrinsic was expecting to optimize. The fallback position is
386 // to call out-of-line.
387 try_inline = false; // Inline tactic bailed out.
388 cg = C->call_generator(call_method, vtable_index, call_is_virtual, jvms, try_inline, prof_factor());
389 if ((new_jvms = cg->generate(jvms)) == NULL) {
390 guarantee(failing(), "call failed to generate: calls should work");
391 return;
392 }
393 }
394
395 if (cg->is_inline()) {
396 C->env()->notice_inlined_method(call_method);
397 }
398
399 // Reset parser state from [new_]jvms, which now carries results of the call.
400 // Return value (if any) is already pushed on the stack by the cg.
401 add_exception_states_from(new_jvms);
402 if (new_jvms->map()->control() == top()) {
403 stop_and_kill_map();
404 } else {
405 assert(new_jvms->same_calls_as(jvms), "method/bci left unchanged");
406 set_jvms(new_jvms);
407 }
408
409 if (!stopped()) {
410 // This was some sort of virtual call, which did a null check for us.
411 // Now we can assert receiver-not-null, on the normal return path.
412 if (receiver != NULL && cg->is_virtual()) {
413 Node* cast = cast_not_null(receiver);
414 // %%% assert(receiver == cast, "should already have cast the receiver");
415 }
564 return;
565 }
566 const TypeInstPtr* ex_type = _gvn.type(ex_node)->isa_instptr();
567 NOT_PRODUCT(if (ex_type==NULL) tty->print_cr("*** Exception not InstPtr"));
568 if (ex_type == NULL)
569 ex_type = TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr();
570
571 // determine potential exception handlers
572 ciExceptionHandlerStream handlers(method(), bci(),
573 ex_type->klass()->as_instance_klass(),
574 ex_type->klass_is_exact());
575
576 // Start executing from the given throw state. (Keep its stack, for now.)
577 // Get the exception oop as known at compile time.
578 ex_node = use_exception_state(ex_map);
579
580 // Get the exception oop klass from its header
581 Node* ex_klass_node = NULL;
582 if (has_ex_handler() && !ex_type->klass_is_exact()) {
583 Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
584 ex_klass_node = _gvn.transform(new (C, 3) LoadKlassNode(NULL, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT));
585
586 // Compute the exception klass a little more cleverly.
587 // Obvious solution is to simple do a LoadKlass from the 'ex_node'.
588 // However, if the ex_node is a PhiNode, I'm going to do a LoadKlass for
589 // each arm of the Phi. If I know something clever about the exceptions
590 // I'm loading the class from, I can replace the LoadKlass with the
591 // klass constant for the exception oop.
592 if( ex_node->is_Phi() ) {
593 ex_klass_node = new (C, ex_node->req()) PhiNode( ex_node->in(0), TypeKlassPtr::OBJECT );
594 for( uint i = 1; i < ex_node->req(); i++ ) {
595 Node* p = basic_plus_adr( ex_node->in(i), ex_node->in(i), oopDesc::klass_offset_in_bytes() );
596 Node* k = _gvn.transform(new (C, 3) LoadKlassNode(0, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT));
597 ex_klass_node->init_req( i, k );
598 }
599 _gvn.set_type(ex_klass_node, TypeKlassPtr::OBJECT);
600
601 }
602 }
603
604 // Scan the exception table for applicable handlers.
605 // If none, we can call rethrow() and be done!
606 // If precise (loaded with no subklasses), insert a D.S. style
607 // pointer compare to the correct handler and loop back.
608 // If imprecise, switch to the Rethrow VM-call style handling.
609
610 int remaining = handlers.count_remaining();
611
612 // iterate through all entries sequentially
613 for (;!handlers.is_done(); handlers.next()) {
614 // Do nothing if turned off
615 if( !DeutschShiffmanExceptions ) break;
616 ciExceptionHandler* handler = handlers.handler();
779 return dest_method;
780 }
781
782 // Attempt to improve the receiver
783 bool actual_receiver_is_exact = false;
784 ciInstanceKlass* actual_receiver = klass;
785 if (receiver_type != NULL) {
786 // Array methods are all inherited from Object, and are monomorphic.
787 if (receiver_type->isa_aryptr() &&
788 dest_method->holder() == env()->Object_klass()) {
789 return dest_method;
790 }
791
792 // All other interesting cases are instance klasses.
793 if (!receiver_type->isa_instptr()) {
794 return NULL;
795 }
796
797 ciInstanceKlass *ikl = receiver_type->klass()->as_instance_klass();
798 if (ikl->is_loaded() && ikl->is_initialized() && !ikl->is_interface() &&
799 (ikl == actual_receiver || ikl->is_subclass_of(actual_receiver))) {
800 // ikl is a same or better type than the original actual_receiver,
801 // e.g. static receiver from bytecodes.
802 actual_receiver = ikl;
803 // Is the actual_receiver exact?
804 actual_receiver_is_exact = receiver_type->klass_is_exact();
805 }
806 }
807
808 ciInstanceKlass* calling_klass = caller->holder();
809 ciMethod* cha_monomorphic_target = dest_method->find_monomorphic_target(calling_klass, klass, actual_receiver);
810 if (cha_monomorphic_target != NULL) {
811 assert(!cha_monomorphic_target->is_abstract(), "");
812 // Look at the method-receiver type. Does it add "too much information"?
813 ciKlass* mr_klass = cha_monomorphic_target->holder();
814 const Type* mr_type = TypeInstPtr::make(TypePtr::BotPTR, mr_klass);
815 if (receiver_type == NULL || !receiver_type->higher_equal(mr_type)) {
816 // Calling this method would include an implicit cast to its holder.
817 // %%% Not yet implemented. Would throw minor asserts at present.
818 // %%% The most common wins are already gained by +UseUniqueSubclasses.
819 // To fix, put the higher_equal check at the call of this routine,
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)doCall.cpp 1.207 07/07/19 19:08:29 JVM"
3 #endif
4 /*
5 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
376 // Only one fall-back, so if an intrinsic fails, ignore any bytecodes.
377 if (cg->is_intrinsic() && call_method->code_size() > 0) {
378 tty->print("Bailed out of intrinsic, will not inline: ");
379 call_method->print_name(); tty->cr();
380 }
381 }
382 #endif
383 // This can happen if a library intrinsic is available, but refuses
384 // the call site, perhaps because it did not match a pattern the
385 // intrinsic was expecting to optimize. The fallback position is
386 // to call out-of-line.
387 try_inline = false; // Inline tactic bailed out.
388 cg = C->call_generator(call_method, vtable_index, call_is_virtual, jvms, try_inline, prof_factor());
389 if ((new_jvms = cg->generate(jvms)) == NULL) {
390 guarantee(failing(), "call failed to generate: calls should work");
391 return;
392 }
393 }
394
395 if (cg->is_inline()) {
396 // Accumulate has_loops estimate
397 C->set_has_loops(C->has_loops() || call_method->has_loops());
398 C->env()->notice_inlined_method(call_method);
399 }
400
401 // Reset parser state from [new_]jvms, which now carries results of the call.
402 // Return value (if any) is already pushed on the stack by the cg.
403 add_exception_states_from(new_jvms);
404 if (new_jvms->map()->control() == top()) {
405 stop_and_kill_map();
406 } else {
407 assert(new_jvms->same_calls_as(jvms), "method/bci left unchanged");
408 set_jvms(new_jvms);
409 }
410
411 if (!stopped()) {
412 // This was some sort of virtual call, which did a null check for us.
413 // Now we can assert receiver-not-null, on the normal return path.
414 if (receiver != NULL && cg->is_virtual()) {
415 Node* cast = cast_not_null(receiver);
416 // %%% assert(receiver == cast, "should already have cast the receiver");
417 }
566 return;
567 }
568 const TypeInstPtr* ex_type = _gvn.type(ex_node)->isa_instptr();
569 NOT_PRODUCT(if (ex_type==NULL) tty->print_cr("*** Exception not InstPtr"));
570 if (ex_type == NULL)
571 ex_type = TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr();
572
573 // determine potential exception handlers
574 ciExceptionHandlerStream handlers(method(), bci(),
575 ex_type->klass()->as_instance_klass(),
576 ex_type->klass_is_exact());
577
578 // Start executing from the given throw state. (Keep its stack, for now.)
579 // Get the exception oop as known at compile time.
580 ex_node = use_exception_state(ex_map);
581
582 // Get the exception oop klass from its header
583 Node* ex_klass_node = NULL;
584 if (has_ex_handler() && !ex_type->klass_is_exact()) {
585 Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
586 ex_klass_node = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
587
588 // Compute the exception klass a little more cleverly.
589 // Obvious solution is to simple do a LoadKlass from the 'ex_node'.
590 // However, if the ex_node is a PhiNode, I'm going to do a LoadKlass for
591 // each arm of the Phi. If I know something clever about the exceptions
592 // I'm loading the class from, I can replace the LoadKlass with the
593 // klass constant for the exception oop.
594 if( ex_node->is_Phi() ) {
595 ex_klass_node = new (C, ex_node->req()) PhiNode( ex_node->in(0), TypeKlassPtr::OBJECT );
596 for( uint i = 1; i < ex_node->req(); i++ ) {
597 Node* p = basic_plus_adr( ex_node->in(i), ex_node->in(i), oopDesc::klass_offset_in_bytes() );
598 Node* k = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
599 ex_klass_node->init_req( i, k );
600 }
601 _gvn.set_type(ex_klass_node, TypeKlassPtr::OBJECT);
602
603 }
604 }
605
606 // Scan the exception table for applicable handlers.
607 // If none, we can call rethrow() and be done!
608 // If precise (loaded with no subklasses), insert a D.S. style
609 // pointer compare to the correct handler and loop back.
610 // If imprecise, switch to the Rethrow VM-call style handling.
611
612 int remaining = handlers.count_remaining();
613
614 // iterate through all entries sequentially
615 for (;!handlers.is_done(); handlers.next()) {
616 // Do nothing if turned off
617 if( !DeutschShiffmanExceptions ) break;
618 ciExceptionHandler* handler = handlers.handler();
781 return dest_method;
782 }
783
784 // Attempt to improve the receiver
785 bool actual_receiver_is_exact = false;
786 ciInstanceKlass* actual_receiver = klass;
787 if (receiver_type != NULL) {
788 // Array methods are all inherited from Object, and are monomorphic.
789 if (receiver_type->isa_aryptr() &&
790 dest_method->holder() == env()->Object_klass()) {
791 return dest_method;
792 }
793
794 // All other interesting cases are instance klasses.
795 if (!receiver_type->isa_instptr()) {
796 return NULL;
797 }
798
799 ciInstanceKlass *ikl = receiver_type->klass()->as_instance_klass();
800 if (ikl->is_loaded() && ikl->is_initialized() && !ikl->is_interface() &&
801 (ikl == actual_receiver || ikl->is_subtype_of(actual_receiver))) {
802 // ikl is a same or better type than the original actual_receiver,
803 // e.g. static receiver from bytecodes.
804 actual_receiver = ikl;
805 // Is the actual_receiver exact?
806 actual_receiver_is_exact = receiver_type->klass_is_exact();
807 }
808 }
809
810 ciInstanceKlass* calling_klass = caller->holder();
811 ciMethod* cha_monomorphic_target = dest_method->find_monomorphic_target(calling_klass, klass, actual_receiver);
812 if (cha_monomorphic_target != NULL) {
813 assert(!cha_monomorphic_target->is_abstract(), "");
814 // Look at the method-receiver type. Does it add "too much information"?
815 ciKlass* mr_klass = cha_monomorphic_target->holder();
816 const Type* mr_type = TypeInstPtr::make(TypePtr::BotPTR, mr_klass);
817 if (receiver_type == NULL || !receiver_type->higher_equal(mr_type)) {
818 // Calling this method would include an implicit cast to its holder.
819 // %%% Not yet implemented. Would throw minor asserts at present.
820 // %%% The most common wins are already gained by +UseUniqueSubclasses.
821 // To fix, put the higher_equal check at the call of this routine,
|