src/share/vm/opto/doCall.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/doCall.cpp

Print this page
rev 6579 : 8046542: [I.finalize() calls from methods compiled by C1 do not cause IllegalAccessError on Sparc
Summary: call to Object.finalize() sometimes allowed by compilers on array type
Reviewed-by:


 451   }
 452 
 453   // ---------------------
 454   // Does Class Hierarchy Analysis reveal only a single target of a v-call?
 455   // Then we may inline or make a static call, but become dependent on there being only 1 target.
 456   // Does the call-site type profile reveal only one receiver?
 457   // Then we may introduce a run-time check and inline on the path where it succeeds.
 458   // The other path may uncommon_trap, check for another receiver, or do a v-call.
 459 
 460   // Try to get the most accurate receiver type
 461   ciMethod* callee             = orig_callee;
 462   int       vtable_index       = Method::invalid_vtable_index;
 463   bool      call_does_dispatch = false;
 464 
 465   // Speculative type of the receiver if any
 466   ciKlass* speculative_receiver_type = NULL;
 467   if (is_virtual_or_interface) {
 468     Node* receiver_node             = stack(sp() - nargs);
 469     const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
 470     // call_does_dispatch and vtable_index are out-parameters.  They might be changed.
 471     callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type,
 472                                       is_virtual,
 473                                       call_does_dispatch, vtable_index);  // out-parameters
 474     speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
 475   }
 476 
 477   // Note:  It's OK to try to inline a virtual call.
 478   // The call generator will not attempt to inline a polymorphic call
 479   // unless it knows how to optimize the receiver dispatch.
 480   bool try_inline = (C->do_inlining() || InlineAccessors);
 481 
 482   // ---------------------
 483   dec_sp(nargs);              // Temporarily pop args for JVM state of call
 484   JVMState* jvms = sync_jvms();
 485 
 486   // ---------------------
 487   // Decide call tactic.
 488   // This call checks with CHA, the interpreter profile, intrinsics table, etc.
 489   // It decides whether inlining is desirable or not.
 490   CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type);
 491 
 492   // NOTE:  Don't use orig_callee and callee after this point!  Use cg->method() instead.


 923       case Bytecodes::_invokedynamic:
 924       case Bytecodes::_invokespecial:   increment_counter(SharedRuntime::nof_inlined_static_calls_addr()); break;
 925       default: fatal("unexpected call bytecode");
 926       }
 927     } else {
 928       switch (bc()) {
 929       case Bytecodes::_invokevirtual:   increment_counter(SharedRuntime::nof_normal_calls_addr()); break;
 930       case Bytecodes::_invokeinterface: increment_counter(SharedRuntime::nof_interface_calls_addr()); break;
 931       case Bytecodes::_invokestatic:
 932       case Bytecodes::_invokedynamic:
 933       case Bytecodes::_invokespecial:   increment_counter(SharedRuntime::nof_static_calls_addr()); break;
 934       default: fatal("unexpected call bytecode");
 935       }
 936     }
 937   }
 938 }
 939 #endif //PRODUCT
 940 
 941 
 942 ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
 943                                          ciMethod* callee, const TypeOopPtr* receiver_type,
 944                                          bool is_virtual,
 945                                          bool& call_does_dispatch, int& vtable_index) {
 946   // Set default values for out-parameters.
 947   call_does_dispatch = true;
 948   vtable_index       = Method::invalid_vtable_index;
 949 
 950   // Choose call strategy.
 951   ciMethod* optimized_virtual_method = optimize_inlining(caller, bci, klass, callee, receiver_type);
 952 
 953   // Have the call been sufficiently improved such that it is no longer a virtual?
 954   if (optimized_virtual_method != NULL) {
 955     callee             = optimized_virtual_method;
 956     call_does_dispatch = false;
 957   } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
 958     // We can make a vtable call at this site
 959     vtable_index = callee->resolve_vtable_index(caller->holder(), klass);
 960   }
 961   return callee;
 962 }
 963 
 964 // Identify possible target method and inlining style
 965 ciMethod* Compile::optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass,
 966                                      ciMethod* callee, const TypeOopPtr* receiver_type) {
 967   // only use for virtual or interface calls
 968 
 969   // If it is obviously final, do not bother to call find_monomorphic_target,
 970   // because the class hierarchy checks are not needed, and may fail due to
 971   // incompletely loaded classes.  Since we do our own class loading checks
 972   // in this module, we may confidently bind to any method.
 973   if (callee->can_be_statically_bound()) {
 974     return callee;
 975   }
 976 
 977   // Attempt to improve the receiver
 978   bool actual_receiver_is_exact = false;
 979   ciInstanceKlass* actual_receiver = klass;
 980   if (receiver_type != NULL) {
 981     // Array methods are all inherited from Object, and are monomorphic.
 982     if (receiver_type->isa_aryptr() &&
 983         callee->holder() == env()->Object_klass()) {

 984       return callee;
 985     }
 986 
 987     // All other interesting cases are instance klasses.
 988     if (!receiver_type->isa_instptr()) {
 989       return NULL;
 990     }
 991 
 992     ciInstanceKlass *ikl = receiver_type->klass()->as_instance_klass();
 993     if (ikl->is_loaded() && ikl->is_initialized() && !ikl->is_interface() &&
 994         (ikl == actual_receiver || ikl->is_subtype_of(actual_receiver))) {
 995       // ikl is a same or better type than the original actual_receiver,
 996       // e.g. static receiver from bytecodes.
 997       actual_receiver = ikl;
 998       // Is the actual_receiver exact?
 999       actual_receiver_is_exact = receiver_type->klass_is_exact();
1000     }
1001   }
1002 
1003   ciInstanceKlass*   calling_klass = caller->holder();




 451   }
 452 
 453   // ---------------------
 454   // Does Class Hierarchy Analysis reveal only a single target of a v-call?
 455   // Then we may inline or make a static call, but become dependent on there being only 1 target.
 456   // Does the call-site type profile reveal only one receiver?
 457   // Then we may introduce a run-time check and inline on the path where it succeeds.
 458   // The other path may uncommon_trap, check for another receiver, or do a v-call.
 459 
 460   // Try to get the most accurate receiver type
 461   ciMethod* callee             = orig_callee;
 462   int       vtable_index       = Method::invalid_vtable_index;
 463   bool      call_does_dispatch = false;
 464 
 465   // Speculative type of the receiver if any
 466   ciKlass* speculative_receiver_type = NULL;
 467   if (is_virtual_or_interface) {
 468     Node* receiver_node             = stack(sp() - nargs);
 469     const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
 470     // call_does_dispatch and vtable_index are out-parameters.  They might be changed.
 471     callee = C->optimize_virtual_call(method(), bci(), klass, holder, orig_callee,
 472                                       receiver_type, is_virtual,
 473                                       call_does_dispatch, vtable_index);  // out-parameters
 474     speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
 475   }
 476 
 477   // Note:  It's OK to try to inline a virtual call.
 478   // The call generator will not attempt to inline a polymorphic call
 479   // unless it knows how to optimize the receiver dispatch.
 480   bool try_inline = (C->do_inlining() || InlineAccessors);
 481 
 482   // ---------------------
 483   dec_sp(nargs);              // Temporarily pop args for JVM state of call
 484   JVMState* jvms = sync_jvms();
 485 
 486   // ---------------------
 487   // Decide call tactic.
 488   // This call checks with CHA, the interpreter profile, intrinsics table, etc.
 489   // It decides whether inlining is desirable or not.
 490   CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type);
 491 
 492   // NOTE:  Don't use orig_callee and callee after this point!  Use cg->method() instead.


 923       case Bytecodes::_invokedynamic:
 924       case Bytecodes::_invokespecial:   increment_counter(SharedRuntime::nof_inlined_static_calls_addr()); break;
 925       default: fatal("unexpected call bytecode");
 926       }
 927     } else {
 928       switch (bc()) {
 929       case Bytecodes::_invokevirtual:   increment_counter(SharedRuntime::nof_normal_calls_addr()); break;
 930       case Bytecodes::_invokeinterface: increment_counter(SharedRuntime::nof_interface_calls_addr()); break;
 931       case Bytecodes::_invokestatic:
 932       case Bytecodes::_invokedynamic:
 933       case Bytecodes::_invokespecial:   increment_counter(SharedRuntime::nof_static_calls_addr()); break;
 934       default: fatal("unexpected call bytecode");
 935       }
 936     }
 937   }
 938 }
 939 #endif //PRODUCT
 940 
 941 
 942 ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
 943                                          ciKlass* holder, ciMethod* callee,
 944                                          const TypeOopPtr* receiver_type, bool is_virtual,
 945                                          bool& call_does_dispatch, int& vtable_index) {
 946   // Set default values for out-parameters.
 947   call_does_dispatch = true;
 948   vtable_index       = Method::invalid_vtable_index;
 949 
 950   // Choose call strategy.
 951   ciMethod* optimized_virtual_method = optimize_inlining(caller, bci, klass, callee, receiver_type);
 952 
 953   // Have the call been sufficiently improved such that it is no longer a virtual?
 954   if (optimized_virtual_method != NULL) {
 955     callee             = optimized_virtual_method;
 956     call_does_dispatch = false;
 957   } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
 958     // We can make a vtable call at this site
 959     vtable_index = callee->resolve_vtable_index(caller->holder(), holder);
 960   }
 961   return callee;
 962 }
 963 
 964 // Identify possible target method and inlining style
 965 ciMethod* Compile::optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass,
 966                                      ciMethod* callee, const TypeOopPtr* receiver_type) {
 967   // only use for virtual or interface calls
 968 
 969   // If it is obviously final, do not bother to call find_monomorphic_target,
 970   // because the class hierarchy checks are not needed, and may fail due to
 971   // incompletely loaded classes.  Since we do our own class loading checks
 972   // in this module, we may confidently bind to any method.
 973   if (callee->can_be_statically_bound()) {
 974     return callee;
 975   }
 976 
 977   // Attempt to improve the receiver
 978   bool actual_receiver_is_exact = false;
 979   ciInstanceKlass* actual_receiver = klass;
 980   if (receiver_type != NULL) {
 981     // Array methods are all inherited from Object, and are monomorphic.
 982     if (receiver_type->isa_aryptr() &&
 983         callee->holder() == env()->Object_klass() &&
 984         callee->name() != ciSymbol::finalize_method_name()) {
 985       return callee;
 986     }
 987 
 988     // All other interesting cases are instance klasses.
 989     if (!receiver_type->isa_instptr()) {
 990       return NULL;
 991     }
 992 
 993     ciInstanceKlass *ikl = receiver_type->klass()->as_instance_klass();
 994     if (ikl->is_loaded() && ikl->is_initialized() && !ikl->is_interface() &&
 995         (ikl == actual_receiver || ikl->is_subtype_of(actual_receiver))) {
 996       // ikl is a same or better type than the original actual_receiver,
 997       // e.g. static receiver from bytecodes.
 998       actual_receiver = ikl;
 999       // Is the actual_receiver exact?
1000       actual_receiver_is_exact = receiver_type->klass_is_exact();
1001     }
1002   }
1003 
1004   ciInstanceKlass*   calling_klass = caller->holder();


src/share/vm/opto/doCall.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File